1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2019
9 * ice_sched_add_root_node - Insert the Tx scheduler root node in SW DB
10 * @pi: port information structure
11 * @info: Scheduler element information from firmware
13 * This function inserts the root node of the scheduling tree topology
16 static enum ice_status
17 ice_sched_add_root_node(struct ice_port_info *pi,
18 struct ice_aqc_txsched_elem_data *info)
20 struct ice_sched_node *root;
28 root = (struct ice_sched_node *)ice_malloc(hw, sizeof(*root));
30 return ICE_ERR_NO_MEMORY;
32 /* coverity[suspicious_sizeof] */
33 root->children = (struct ice_sched_node **)
34 ice_calloc(hw, hw->max_children[0], sizeof(*root));
35 if (!root->children) {
37 return ICE_ERR_NO_MEMORY;
40 ice_memcpy(&root->info, info, sizeof(*info), ICE_DMA_TO_NONDMA);
46 * ice_sched_find_node_by_teid - Find the Tx scheduler node in SW DB
47 * @start_node: pointer to the starting ice_sched_node struct in a sub-tree
48 * @teid: node TEID to search
50 * This function searches for a node matching the TEID in the scheduling tree
51 * from the SW DB. The search is recursive and is restricted by the number of
52 * layers it has searched through; stopping at the max supported layer.
54 * This function needs to be called when holding the port_info->sched_lock
56 struct ice_sched_node *
57 ice_sched_find_node_by_teid(struct ice_sched_node *start_node, u32 teid)
61 /* The TEID is same as that of the start_node */
62 if (ICE_TXSCHED_GET_NODE_TEID(start_node) == teid)
65 /* The node has no children or is at the max layer */
66 if (!start_node->num_children ||
67 start_node->tx_sched_layer >= ICE_AQC_TOPO_MAX_LEVEL_NUM ||
68 start_node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF)
71 /* Check if TEID matches to any of the children nodes */
72 for (i = 0; i < start_node->num_children; i++)
73 if (ICE_TXSCHED_GET_NODE_TEID(start_node->children[i]) == teid)
74 return start_node->children[i];
76 /* Search within each child's sub-tree */
77 for (i = 0; i < start_node->num_children; i++) {
78 struct ice_sched_node *tmp;
80 tmp = ice_sched_find_node_by_teid(start_node->children[i],
90 * ice_aqc_send_sched_elem_cmd - send scheduling elements cmd
91 * @hw: pointer to the HW struct
92 * @cmd_opc: cmd opcode
93 * @elems_req: number of elements to request
94 * @buf: pointer to buffer
95 * @buf_size: buffer size in bytes
96 * @elems_resp: returns total number of elements response
97 * @cd: pointer to command details structure or NULL
99 * This function sends a scheduling elements cmd (cmd_opc)
101 static enum ice_status
102 ice_aqc_send_sched_elem_cmd(struct ice_hw *hw, enum ice_adminq_opc cmd_opc,
103 u16 elems_req, void *buf, u16 buf_size,
104 u16 *elems_resp, struct ice_sq_cd *cd)
106 struct ice_aqc_sched_elem_cmd *cmd;
107 struct ice_aq_desc desc;
108 enum ice_status status;
110 cmd = &desc.params.sched_elem_cmd;
111 ice_fill_dflt_direct_cmd_desc(&desc, cmd_opc);
112 cmd->num_elem_req = CPU_TO_LE16(elems_req);
113 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
114 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
115 if (!status && elems_resp)
116 *elems_resp = LE16_TO_CPU(cmd->num_elem_resp);
122 * ice_aq_query_sched_elems - query scheduler elements
123 * @hw: pointer to the HW struct
124 * @elems_req: number of elements to query
125 * @buf: pointer to buffer
126 * @buf_size: buffer size in bytes
127 * @elems_ret: returns total number of elements returned
128 * @cd: pointer to command details structure or NULL
130 * Query scheduling elements (0x0404)
133 ice_aq_query_sched_elems(struct ice_hw *hw, u16 elems_req,
134 struct ice_aqc_get_elem *buf, u16 buf_size,
135 u16 *elems_ret, struct ice_sq_cd *cd)
137 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_get_sched_elems,
138 elems_req, (void *)buf, buf_size,
143 * ice_sched_add_node - Insert the Tx scheduler node in SW DB
144 * @pi: port information structure
145 * @layer: Scheduler layer of the node
146 * @info: Scheduler element information from firmware
148 * This function inserts a scheduler node to the SW DB.
151 ice_sched_add_node(struct ice_port_info *pi, u8 layer,
152 struct ice_aqc_txsched_elem_data *info)
154 struct ice_sched_node *parent;
155 struct ice_aqc_get_elem elem;
156 struct ice_sched_node *node;
157 enum ice_status status;
161 return ICE_ERR_PARAM;
165 /* A valid parent node should be there */
166 parent = ice_sched_find_node_by_teid(pi->root,
167 LE32_TO_CPU(info->parent_teid));
169 ice_debug(hw, ICE_DBG_SCHED,
170 "Parent Node not found for parent_teid=0x%x\n",
171 LE32_TO_CPU(info->parent_teid));
172 return ICE_ERR_PARAM;
175 /* query the current node information from FW before additing it
178 status = ice_sched_query_elem(hw, LE32_TO_CPU(info->node_teid), &elem);
181 node = (struct ice_sched_node *)ice_malloc(hw, sizeof(*node));
183 return ICE_ERR_NO_MEMORY;
184 if (hw->max_children[layer]) {
185 /* coverity[suspicious_sizeof] */
186 node->children = (struct ice_sched_node **)
187 ice_calloc(hw, hw->max_children[layer], sizeof(*node));
188 if (!node->children) {
190 return ICE_ERR_NO_MEMORY;
195 node->parent = parent;
196 node->tx_sched_layer = layer;
197 parent->children[parent->num_children++] = node;
198 node->info = elem.generic[0];
203 * ice_aq_delete_sched_elems - delete scheduler elements
204 * @hw: pointer to the HW struct
205 * @grps_req: number of groups to delete
206 * @buf: pointer to buffer
207 * @buf_size: buffer size in bytes
208 * @grps_del: returns total number of elements deleted
209 * @cd: pointer to command details structure or NULL
211 * Delete scheduling elements (0x040F)
213 static enum ice_status
214 ice_aq_delete_sched_elems(struct ice_hw *hw, u16 grps_req,
215 struct ice_aqc_delete_elem *buf, u16 buf_size,
216 u16 *grps_del, struct ice_sq_cd *cd)
218 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_delete_sched_elems,
219 grps_req, (void *)buf, buf_size,
224 * ice_sched_remove_elems - remove nodes from HW
225 * @hw: pointer to the HW struct
226 * @parent: pointer to the parent node
227 * @num_nodes: number of nodes
228 * @node_teids: array of node teids to be deleted
230 * This function remove nodes from HW
232 static enum ice_status
233 ice_sched_remove_elems(struct ice_hw *hw, struct ice_sched_node *parent,
234 u16 num_nodes, u32 *node_teids)
236 struct ice_aqc_delete_elem *buf;
237 u16 i, num_groups_removed = 0;
238 enum ice_status status;
241 buf_size = sizeof(*buf) + sizeof(u32) * (num_nodes - 1);
242 buf = (struct ice_aqc_delete_elem *)ice_malloc(hw, buf_size);
244 return ICE_ERR_NO_MEMORY;
246 buf->hdr.parent_teid = parent->info.node_teid;
247 buf->hdr.num_elems = CPU_TO_LE16(num_nodes);
248 for (i = 0; i < num_nodes; i++)
249 buf->teid[i] = CPU_TO_LE32(node_teids[i]);
251 status = ice_aq_delete_sched_elems(hw, 1, buf, buf_size,
252 &num_groups_removed, NULL);
253 if (status != ICE_SUCCESS || num_groups_removed != 1)
254 ice_debug(hw, ICE_DBG_SCHED, "remove node failed FW error %d\n",
255 hw->adminq.sq_last_status);
262 * ice_sched_get_first_node - get the first node of the given layer
263 * @pi: port information structure
264 * @parent: pointer the base node of the subtree
265 * @layer: layer number
267 * This function retrieves the first node of the given layer from the subtree
269 static struct ice_sched_node *
270 ice_sched_get_first_node(struct ice_port_info *pi,
271 struct ice_sched_node *parent, u8 layer)
273 return pi->sib_head[parent->tc_num][layer];
277 * ice_sched_get_tc_node - get pointer to TC node
278 * @pi: port information structure
281 * This function returns the TC node pointer
283 struct ice_sched_node *ice_sched_get_tc_node(struct ice_port_info *pi, u8 tc)
287 if (!pi || !pi->root)
289 for (i = 0; i < pi->root->num_children; i++)
290 if (pi->root->children[i]->tc_num == tc)
291 return pi->root->children[i];
296 * ice_free_sched_node - Free a Tx scheduler node from SW DB
297 * @pi: port information structure
298 * @node: pointer to the ice_sched_node struct
300 * This function frees up a node from SW DB as well as from HW
302 * This function needs to be called with the port_info->sched_lock held
304 void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node)
306 struct ice_sched_node *parent;
307 struct ice_hw *hw = pi->hw;
310 /* Free the children before freeing up the parent node
311 * The parent array is updated below and that shifts the nodes
312 * in the array. So always pick the first child if num children > 0
314 while (node->num_children)
315 ice_free_sched_node(pi, node->children[0]);
317 /* Leaf, TC and root nodes can't be deleted by SW */
318 if (node->tx_sched_layer >= hw->sw_entry_point_layer &&
319 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_TC &&
320 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_ROOT_PORT &&
321 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_LEAF) {
322 u32 teid = LE32_TO_CPU(node->info.node_teid);
324 ice_sched_remove_elems(hw, node->parent, 1, &teid);
326 parent = node->parent;
327 /* root has no parent */
329 struct ice_sched_node *p;
331 /* update the parent */
332 for (i = 0; i < parent->num_children; i++)
333 if (parent->children[i] == node) {
334 for (j = i + 1; j < parent->num_children; j++)
335 parent->children[j - 1] =
337 parent->num_children--;
341 p = ice_sched_get_first_node(pi, node, node->tx_sched_layer);
343 if (p->sibling == node) {
344 p->sibling = node->sibling;
350 /* update the sibling head if head is getting removed */
351 if (pi->sib_head[node->tc_num][node->tx_sched_layer] == node)
352 pi->sib_head[node->tc_num][node->tx_sched_layer] =
356 /* leaf nodes have no children */
358 ice_free(hw, node->children);
363 * ice_aq_get_dflt_topo - gets default scheduler topology
364 * @hw: pointer to the HW struct
365 * @lport: logical port number
366 * @buf: pointer to buffer
367 * @buf_size: buffer size in bytes
368 * @num_branches: returns total number of queue to port branches
369 * @cd: pointer to command details structure or NULL
371 * Get default scheduler topology (0x400)
373 static enum ice_status
374 ice_aq_get_dflt_topo(struct ice_hw *hw, u8 lport,
375 struct ice_aqc_get_topo_elem *buf, u16 buf_size,
376 u8 *num_branches, struct ice_sq_cd *cd)
378 struct ice_aqc_get_topo *cmd;
379 struct ice_aq_desc desc;
380 enum ice_status status;
382 cmd = &desc.params.get_topo;
383 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_dflt_topo);
384 cmd->port_num = lport;
385 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
386 if (!status && num_branches)
387 *num_branches = cmd->num_branches;
393 * ice_aq_add_sched_elems - adds scheduling element
394 * @hw: pointer to the HW struct
395 * @grps_req: the number of groups that are requested to be added
396 * @buf: pointer to buffer
397 * @buf_size: buffer size in bytes
398 * @grps_added: returns total number of groups added
399 * @cd: pointer to command details structure or NULL
401 * Add scheduling elements (0x0401)
403 static enum ice_status
404 ice_aq_add_sched_elems(struct ice_hw *hw, u16 grps_req,
405 struct ice_aqc_add_elem *buf, u16 buf_size,
406 u16 *grps_added, struct ice_sq_cd *cd)
408 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_add_sched_elems,
409 grps_req, (void *)buf, buf_size,
414 * ice_aq_cfg_sched_elems - configures scheduler elements
415 * @hw: pointer to the HW struct
416 * @elems_req: number of elements to configure
417 * @buf: pointer to buffer
418 * @buf_size: buffer size in bytes
419 * @elems_cfgd: returns total number of elements configured
420 * @cd: pointer to command details structure or NULL
422 * Configure scheduling elements (0x0403)
424 static enum ice_status
425 ice_aq_cfg_sched_elems(struct ice_hw *hw, u16 elems_req,
426 struct ice_aqc_conf_elem *buf, u16 buf_size,
427 u16 *elems_cfgd, struct ice_sq_cd *cd)
429 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_cfg_sched_elems,
430 elems_req, (void *)buf, buf_size,
435 * ice_aq_move_sched_elems - move scheduler elements
436 * @hw: pointer to the HW struct
437 * @grps_req: number of groups to move
438 * @buf: pointer to buffer
439 * @buf_size: buffer size in bytes
440 * @grps_movd: returns total number of groups moved
441 * @cd: pointer to command details structure or NULL
443 * Move scheduling elements (0x0408)
445 static enum ice_status
446 ice_aq_move_sched_elems(struct ice_hw *hw, u16 grps_req,
447 struct ice_aqc_move_elem *buf, u16 buf_size,
448 u16 *grps_movd, struct ice_sq_cd *cd)
450 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_move_sched_elems,
451 grps_req, (void *)buf, buf_size,
456 * ice_aq_suspend_sched_elems - suspend scheduler elements
457 * @hw: pointer to the HW struct
458 * @elems_req: number of elements to suspend
459 * @buf: pointer to buffer
460 * @buf_size: buffer size in bytes
461 * @elems_ret: returns total number of elements suspended
462 * @cd: pointer to command details structure or NULL
464 * Suspend scheduling elements (0x0409)
466 static enum ice_status
467 ice_aq_suspend_sched_elems(struct ice_hw *hw, u16 elems_req,
468 struct ice_aqc_suspend_resume_elem *buf,
469 u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd)
471 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_suspend_sched_elems,
472 elems_req, (void *)buf, buf_size,
477 * ice_aq_resume_sched_elems - resume scheduler elements
478 * @hw: pointer to the HW struct
479 * @elems_req: number of elements to resume
480 * @buf: pointer to buffer
481 * @buf_size: buffer size in bytes
482 * @elems_ret: returns total number of elements resumed
483 * @cd: pointer to command details structure or NULL
485 * resume scheduling elements (0x040A)
487 static enum ice_status
488 ice_aq_resume_sched_elems(struct ice_hw *hw, u16 elems_req,
489 struct ice_aqc_suspend_resume_elem *buf,
490 u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd)
492 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_resume_sched_elems,
493 elems_req, (void *)buf, buf_size,
498 * ice_aq_query_sched_res - query scheduler resource
499 * @hw: pointer to the HW struct
500 * @buf_size: buffer size in bytes
501 * @buf: pointer to buffer
502 * @cd: pointer to command details structure or NULL
504 * Query scheduler resource allocation (0x0412)
506 static enum ice_status
507 ice_aq_query_sched_res(struct ice_hw *hw, u16 buf_size,
508 struct ice_aqc_query_txsched_res_resp *buf,
509 struct ice_sq_cd *cd)
511 struct ice_aq_desc desc;
513 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_sched_res);
514 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
518 * ice_sched_suspend_resume_elems - suspend or resume HW nodes
519 * @hw: pointer to the HW struct
520 * @num_nodes: number of nodes
521 * @node_teids: array of node teids to be suspended or resumed
522 * @suspend: true means suspend / false means resume
524 * This function suspends or resumes HW nodes
526 static enum ice_status
527 ice_sched_suspend_resume_elems(struct ice_hw *hw, u8 num_nodes, u32 *node_teids,
530 struct ice_aqc_suspend_resume_elem *buf;
531 u16 i, buf_size, num_elem_ret = 0;
532 enum ice_status status;
534 buf_size = sizeof(*buf) * num_nodes;
535 buf = (struct ice_aqc_suspend_resume_elem *)
536 ice_malloc(hw, buf_size);
538 return ICE_ERR_NO_MEMORY;
540 for (i = 0; i < num_nodes; i++)
541 buf->teid[i] = CPU_TO_LE32(node_teids[i]);
544 status = ice_aq_suspend_sched_elems(hw, num_nodes, buf,
545 buf_size, &num_elem_ret,
548 status = ice_aq_resume_sched_elems(hw, num_nodes, buf,
549 buf_size, &num_elem_ret,
551 if (status != ICE_SUCCESS || num_elem_ret != num_nodes)
552 ice_debug(hw, ICE_DBG_SCHED, "suspend/resume failed\n");
559 * ice_alloc_lan_q_ctx - allocate LAN queue contexts for the given VSI and TC
560 * @hw: pointer to the HW struct
561 * @vsi_handle: VSI handle
563 * @new_numqs: number of queues
565 static enum ice_status
566 ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs)
568 struct ice_vsi_ctx *vsi_ctx;
569 struct ice_q_ctx *q_ctx;
571 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
573 return ICE_ERR_PARAM;
574 /* allocate LAN queue contexts */
575 if (!vsi_ctx->lan_q_ctx[tc]) {
576 vsi_ctx->lan_q_ctx[tc] = (struct ice_q_ctx *)
577 ice_calloc(hw, new_numqs, sizeof(*q_ctx));
578 if (!vsi_ctx->lan_q_ctx[tc])
579 return ICE_ERR_NO_MEMORY;
580 vsi_ctx->num_lan_q_entries[tc] = new_numqs;
583 /* num queues are increased, update the queue contexts */
584 if (new_numqs > vsi_ctx->num_lan_q_entries[tc]) {
585 u16 prev_num = vsi_ctx->num_lan_q_entries[tc];
587 q_ctx = (struct ice_q_ctx *)
588 ice_calloc(hw, new_numqs, sizeof(*q_ctx));
590 return ICE_ERR_NO_MEMORY;
591 ice_memcpy(q_ctx, vsi_ctx->lan_q_ctx[tc],
592 prev_num * sizeof(*q_ctx), ICE_DMA_TO_NONDMA);
593 ice_free(hw, vsi_ctx->lan_q_ctx[tc]);
594 vsi_ctx->lan_q_ctx[tc] = q_ctx;
595 vsi_ctx->num_lan_q_entries[tc] = new_numqs;
601 * ice_aq_rl_profile - performs a rate limiting task
602 * @hw: pointer to the HW struct
603 * @opcode:opcode for add, query, or remove profile(s)
604 * @num_profiles: the number of profiles
605 * @buf: pointer to buffer
606 * @buf_size: buffer size in bytes
607 * @num_processed: number of processed add or remove profile(s) to return
608 * @cd: pointer to command details structure
610 * Rl profile function to add, query, or remove profile(s)
612 static enum ice_status
613 ice_aq_rl_profile(struct ice_hw *hw, enum ice_adminq_opc opcode,
614 u16 num_profiles, struct ice_aqc_rl_profile_generic_elem *buf,
615 u16 buf_size, u16 *num_processed, struct ice_sq_cd *cd)
617 struct ice_aqc_rl_profile *cmd;
618 struct ice_aq_desc desc;
619 enum ice_status status;
621 cmd = &desc.params.rl_profile;
623 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
624 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
625 cmd->num_profiles = CPU_TO_LE16(num_profiles);
626 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
627 if (!status && num_processed)
628 *num_processed = LE16_TO_CPU(cmd->num_processed);
633 * ice_aq_add_rl_profile - adds rate limiting profile(s)
634 * @hw: pointer to the HW struct
635 * @num_profiles: the number of profile(s) to be add
636 * @buf: pointer to buffer
637 * @buf_size: buffer size in bytes
638 * @num_profiles_added: total number of profiles added to return
639 * @cd: pointer to command details structure
641 * Add RL profile (0x0410)
643 static enum ice_status
644 ice_aq_add_rl_profile(struct ice_hw *hw, u16 num_profiles,
645 struct ice_aqc_rl_profile_generic_elem *buf,
646 u16 buf_size, u16 *num_profiles_added,
647 struct ice_sq_cd *cd)
649 return ice_aq_rl_profile(hw, ice_aqc_opc_add_rl_profiles,
651 buf_size, num_profiles_added, cd);
655 * ice_aq_query_rl_profile - query rate limiting profile(s)
656 * @hw: pointer to the HW struct
657 * @num_profiles: the number of profile(s) to query
658 * @buf: pointer to buffer
659 * @buf_size: buffer size in bytes
660 * @cd: pointer to command details structure
662 * Query RL profile (0x0411)
665 ice_aq_query_rl_profile(struct ice_hw *hw, u16 num_profiles,
666 struct ice_aqc_rl_profile_generic_elem *buf,
667 u16 buf_size, struct ice_sq_cd *cd)
669 return ice_aq_rl_profile(hw, ice_aqc_opc_query_rl_profiles,
670 num_profiles, buf, buf_size, NULL, cd);
674 * ice_aq_remove_rl_profile - removes RL profile(s)
675 * @hw: pointer to the HW struct
676 * @num_profiles: the number of profile(s) to remove
677 * @buf: pointer to buffer
678 * @buf_size: buffer size in bytes
679 * @num_profiles_removed: total number of profiles removed to return
680 * @cd: pointer to command details structure or NULL
682 * Remove RL profile (0x0415)
684 static enum ice_status
685 ice_aq_remove_rl_profile(struct ice_hw *hw, u16 num_profiles,
686 struct ice_aqc_rl_profile_generic_elem *buf,
687 u16 buf_size, u16 *num_profiles_removed,
688 struct ice_sq_cd *cd)
690 return ice_aq_rl_profile(hw, ice_aqc_opc_remove_rl_profiles,
692 buf_size, num_profiles_removed, cd);
696 * ice_sched_del_rl_profile - remove RL profile
697 * @hw: pointer to the HW struct
698 * @rl_info: rate limit profile information
700 * If the profile ID is not referenced anymore, it removes profile ID with
701 * its associated parameters from HW DB,and locally. The caller needs to
702 * hold scheduler lock.
704 static enum ice_status
705 ice_sched_del_rl_profile(struct ice_hw *hw,
706 struct ice_aqc_rl_profile_info *rl_info)
708 struct ice_aqc_rl_profile_generic_elem *buf;
709 u16 num_profiles_removed;
710 enum ice_status status;
711 u16 num_profiles = 1;
713 if (rl_info->prof_id_ref != 0)
714 return ICE_ERR_IN_USE;
716 /* Safe to remove profile ID */
717 buf = (struct ice_aqc_rl_profile_generic_elem *)
719 status = ice_aq_remove_rl_profile(hw, num_profiles, buf, sizeof(*buf),
720 &num_profiles_removed, NULL);
721 if (status || num_profiles_removed != num_profiles)
724 /* Delete stale entry now */
725 LIST_DEL(&rl_info->list_entry);
726 ice_free(hw, rl_info);
731 * ice_sched_clear_rl_prof - clears RL prof entries
732 * @pi: port information structure
734 * This function removes all RL profile from HW as well as from SW DB.
736 static void ice_sched_clear_rl_prof(struct ice_port_info *pi)
740 for (ln = 0; ln < pi->hw->num_tx_sched_layers; ln++) {
741 struct ice_aqc_rl_profile_info *rl_prof_elem;
742 struct ice_aqc_rl_profile_info *rl_prof_tmp;
744 LIST_FOR_EACH_ENTRY_SAFE(rl_prof_elem, rl_prof_tmp,
745 &pi->rl_prof_list[ln],
746 ice_aqc_rl_profile_info, list_entry) {
747 struct ice_hw *hw = pi->hw;
748 enum ice_status status;
750 rl_prof_elem->prof_id_ref = 0;
751 status = ice_sched_del_rl_profile(hw, rl_prof_elem);
753 ice_debug(hw, ICE_DBG_SCHED,
754 "Remove rl profile failed\n");
755 /* On error, free mem required */
756 LIST_DEL(&rl_prof_elem->list_entry);
757 ice_free(hw, rl_prof_elem);
764 * ice_sched_clear_agg - clears the aggregator related information
765 * @hw: pointer to the hardware structure
767 * This function removes aggregator list and free up aggregator related memory
768 * previously allocated.
770 void ice_sched_clear_agg(struct ice_hw *hw)
772 struct ice_sched_agg_info *agg_info;
773 struct ice_sched_agg_info *atmp;
775 LIST_FOR_EACH_ENTRY_SAFE(agg_info, atmp, &hw->agg_list,
778 struct ice_sched_agg_vsi_info *agg_vsi_info;
779 struct ice_sched_agg_vsi_info *vtmp;
781 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, vtmp,
782 &agg_info->agg_vsi_list,
783 ice_sched_agg_vsi_info, list_entry) {
784 LIST_DEL(&agg_vsi_info->list_entry);
785 ice_free(hw, agg_vsi_info);
787 LIST_DEL(&agg_info->list_entry);
788 ice_free(hw, agg_info);
793 * ice_sched_clear_tx_topo - clears the schduler tree nodes
794 * @pi: port information structure
796 * This function removes all the nodes from HW as well as from SW DB.
798 static void ice_sched_clear_tx_topo(struct ice_port_info *pi)
802 /* remove RL profiles related lists */
803 ice_sched_clear_rl_prof(pi);
805 ice_free_sched_node(pi, pi->root);
811 * ice_sched_clear_port - clear the scheduler elements from SW DB for a port
812 * @pi: port information structure
814 * Cleanup scheduling elements from SW DB
816 void ice_sched_clear_port(struct ice_port_info *pi)
818 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
821 pi->port_state = ICE_SCHED_PORT_STATE_INIT;
822 ice_acquire_lock(&pi->sched_lock);
823 ice_sched_clear_tx_topo(pi);
824 ice_release_lock(&pi->sched_lock);
825 ice_destroy_lock(&pi->sched_lock);
829 * ice_sched_cleanup_all - cleanup scheduler elements from SW DB for all ports
830 * @hw: pointer to the HW struct
832 * Cleanup scheduling elements from SW DB for all the ports
834 void ice_sched_cleanup_all(struct ice_hw *hw)
839 if (hw->layer_info) {
840 ice_free(hw, hw->layer_info);
841 hw->layer_info = NULL;
845 ice_sched_clear_port(hw->port_info);
847 hw->num_tx_sched_layers = 0;
848 hw->num_tx_sched_phys_layers = 0;
849 hw->flattened_layers = 0;
854 * ice_aq_cfg_l2_node_cgd - configures L2 node to CGD mapping
855 * @hw: pointer to the HW struct
856 * @num_l2_nodes: the number of L2 nodes whose CGDs to configure
857 * @buf: pointer to buffer
858 * @buf_size: buffer size in bytes
859 * @cd: pointer to command details structure or NULL
861 * Configure L2 Node CGD (0x0414)
864 ice_aq_cfg_l2_node_cgd(struct ice_hw *hw, u16 num_l2_nodes,
865 struct ice_aqc_cfg_l2_node_cgd_data *buf,
866 u16 buf_size, struct ice_sq_cd *cd)
868 struct ice_aqc_cfg_l2_node_cgd *cmd;
869 struct ice_aq_desc desc;
871 cmd = &desc.params.cfg_l2_node_cgd;
872 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_cfg_l2_node_cgd);
873 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
875 cmd->num_l2_nodes = CPU_TO_LE16(num_l2_nodes);
876 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
881 * ice_sched_add_elems - add nodes to HW and SW DB
882 * @pi: port information structure
883 * @tc_node: pointer to the branch node
884 * @parent: pointer to the parent node
885 * @layer: layer number to add nodes
886 * @num_nodes: number of nodes
887 * @num_nodes_added: pointer to num nodes added
888 * @first_node_teid: if new nodes are added then return the TEID of first node
890 * This function add nodes to HW as well as to SW DB for a given layer
892 static enum ice_status
893 ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node,
894 struct ice_sched_node *parent, u8 layer, u16 num_nodes,
895 u16 *num_nodes_added, u32 *first_node_teid)
897 struct ice_sched_node *prev, *new_node;
898 struct ice_aqc_add_elem *buf;
899 u16 i, num_groups_added = 0;
900 enum ice_status status = ICE_SUCCESS;
901 struct ice_hw *hw = pi->hw;
905 buf_size = sizeof(*buf) + sizeof(*buf->generic) * (num_nodes - 1);
906 buf = (struct ice_aqc_add_elem *)ice_malloc(hw, buf_size);
908 return ICE_ERR_NO_MEMORY;
910 buf->hdr.parent_teid = parent->info.node_teid;
911 buf->hdr.num_elems = CPU_TO_LE16(num_nodes);
912 for (i = 0; i < num_nodes; i++) {
913 buf->generic[i].parent_teid = parent->info.node_teid;
914 buf->generic[i].data.elem_type = ICE_AQC_ELEM_TYPE_SE_GENERIC;
915 buf->generic[i].data.valid_sections =
916 ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
917 ICE_AQC_ELEM_VALID_EIR;
918 buf->generic[i].data.generic = 0;
919 buf->generic[i].data.cir_bw.bw_profile_idx =
920 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
921 buf->generic[i].data.cir_bw.bw_alloc =
922 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
923 buf->generic[i].data.eir_bw.bw_profile_idx =
924 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
925 buf->generic[i].data.eir_bw.bw_alloc =
926 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
929 status = ice_aq_add_sched_elems(hw, 1, buf, buf_size,
930 &num_groups_added, NULL);
931 if (status != ICE_SUCCESS || num_groups_added != 1) {
932 ice_debug(hw, ICE_DBG_SCHED, "add node failed FW Error %d\n",
933 hw->adminq.sq_last_status);
938 *num_nodes_added = num_nodes;
939 /* add nodes to the SW DB */
940 for (i = 0; i < num_nodes; i++) {
941 status = ice_sched_add_node(pi, layer, &buf->generic[i]);
942 if (status != ICE_SUCCESS) {
943 ice_debug(hw, ICE_DBG_SCHED,
944 "add nodes in SW DB failed status =%d\n",
949 teid = LE32_TO_CPU(buf->generic[i].node_teid);
950 new_node = ice_sched_find_node_by_teid(parent, teid);
952 ice_debug(hw, ICE_DBG_SCHED,
953 "Node is missing for teid =%d\n", teid);
957 new_node->sibling = NULL;
958 new_node->tc_num = tc_node->tc_num;
960 /* add it to previous node sibling pointer */
961 /* Note: siblings are not linked across branches */
962 prev = ice_sched_get_first_node(pi, tc_node, layer);
963 if (prev && prev != new_node) {
964 while (prev->sibling)
965 prev = prev->sibling;
966 prev->sibling = new_node;
969 /* initialize the sibling head */
970 if (!pi->sib_head[tc_node->tc_num][layer])
971 pi->sib_head[tc_node->tc_num][layer] = new_node;
974 *first_node_teid = teid;
982 * ice_sched_add_nodes_to_layer - Add nodes to a given layer
983 * @pi: port information structure
984 * @tc_node: pointer to TC node
985 * @parent: pointer to parent node
986 * @layer: layer number to add nodes
987 * @num_nodes: number of nodes to be added
988 * @first_node_teid: pointer to the first node TEID
989 * @num_nodes_added: pointer to number of nodes added
991 * This function add nodes to a given layer.
993 static enum ice_status
994 ice_sched_add_nodes_to_layer(struct ice_port_info *pi,
995 struct ice_sched_node *tc_node,
996 struct ice_sched_node *parent, u8 layer,
997 u16 num_nodes, u32 *first_node_teid,
998 u16 *num_nodes_added)
1000 u32 *first_teid_ptr = first_node_teid;
1001 u16 new_num_nodes, max_child_nodes;
1002 enum ice_status status = ICE_SUCCESS;
1003 struct ice_hw *hw = pi->hw;
1007 *num_nodes_added = 0;
1012 if (!parent || layer < hw->sw_entry_point_layer)
1013 return ICE_ERR_PARAM;
1015 /* max children per node per layer */
1016 max_child_nodes = hw->max_children[parent->tx_sched_layer];
1018 /* current number of children + required nodes exceed max children ? */
1019 if ((parent->num_children + num_nodes) > max_child_nodes) {
1020 /* Fail if the parent is a TC node */
1021 if (parent == tc_node)
1024 /* utilize all the spaces if the parent is not full */
1025 if (parent->num_children < max_child_nodes) {
1026 new_num_nodes = max_child_nodes - parent->num_children;
1027 /* this recursion is intentional, and wouldn't
1028 * go more than 2 calls
1030 status = ice_sched_add_nodes_to_layer(pi, tc_node,
1035 if (status != ICE_SUCCESS)
1038 *num_nodes_added += num_added;
1040 /* Don't modify the first node TEID memory if the first node was
1041 * added already in the above call. Instead send some temp
1042 * memory for all other recursive calls.
1045 first_teid_ptr = &temp;
1047 new_num_nodes = num_nodes - num_added;
1049 /* This parent is full, try the next sibling */
1050 parent = parent->sibling;
1052 /* this recursion is intentional, for 1024 queues
1053 * per VSI, it goes max of 16 iterations.
1054 * 1024 / 8 = 128 layer 8 nodes
1055 * 128 /8 = 16 (add 8 nodes per iteration)
1057 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent,
1058 layer, new_num_nodes,
1061 *num_nodes_added += num_added;
1065 status = ice_sched_add_elems(pi, tc_node, parent, layer, num_nodes,
1066 num_nodes_added, first_node_teid);
1071 * ice_sched_get_qgrp_layer - get the current queue group layer number
1072 * @hw: pointer to the HW struct
1074 * This function returns the current queue group layer number
1076 static u8 ice_sched_get_qgrp_layer(struct ice_hw *hw)
1078 /* It's always total layers - 1, the array is 0 relative so -2 */
1079 return hw->num_tx_sched_layers - ICE_QGRP_LAYER_OFFSET;
1083 * ice_sched_get_vsi_layer - get the current VSI layer number
1084 * @hw: pointer to the HW struct
1086 * This function returns the current VSI layer number
1088 static u8 ice_sched_get_vsi_layer(struct ice_hw *hw)
1090 /* Num Layers VSI layer
1093 * 5 or less sw_entry_point_layer
1095 /* calculate the VSI layer based on number of layers. */
1096 if (hw->num_tx_sched_layers > ICE_VSI_LAYER_OFFSET + 1) {
1097 u8 layer = hw->num_tx_sched_layers - ICE_VSI_LAYER_OFFSET;
1099 if (layer > hw->sw_entry_point_layer)
1102 return hw->sw_entry_point_layer;
1106 * ice_sched_get_agg_layer - get the current aggregator layer number
1107 * @hw: pointer to the HW struct
1109 * This function returns the current aggregator layer number
1111 static u8 ice_sched_get_agg_layer(struct ice_hw *hw)
1113 /* Num Layers aggregator layer
1115 * 7 or less sw_entry_point_layer
1117 /* calculate the aggregator layer based on number of layers. */
1118 if (hw->num_tx_sched_layers > ICE_AGG_LAYER_OFFSET + 1) {
1119 u8 layer = hw->num_tx_sched_layers - ICE_AGG_LAYER_OFFSET;
1121 if (layer > hw->sw_entry_point_layer)
1124 return hw->sw_entry_point_layer;
1128 * ice_rm_dflt_leaf_node - remove the default leaf node in the tree
1129 * @pi: port information structure
1131 * This function removes the leaf node that was created by the FW
1132 * during initialization
1134 static void ice_rm_dflt_leaf_node(struct ice_port_info *pi)
1136 struct ice_sched_node *node;
1140 if (!node->num_children)
1142 node = node->children[0];
1144 if (node && node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF) {
1145 u32 teid = LE32_TO_CPU(node->info.node_teid);
1146 enum ice_status status;
1148 /* remove the default leaf node */
1149 status = ice_sched_remove_elems(pi->hw, node->parent, 1, &teid);
1151 ice_free_sched_node(pi, node);
1156 * ice_sched_rm_dflt_nodes - free the default nodes in the tree
1157 * @pi: port information structure
1159 * This function frees all the nodes except root and TC that were created by
1160 * the FW during initialization
1162 static void ice_sched_rm_dflt_nodes(struct ice_port_info *pi)
1164 struct ice_sched_node *node;
1166 ice_rm_dflt_leaf_node(pi);
1168 /* remove the default nodes except TC and root nodes */
1171 if (node->tx_sched_layer >= pi->hw->sw_entry_point_layer &&
1172 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_TC &&
1173 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_ROOT_PORT) {
1174 ice_free_sched_node(pi, node);
1178 if (!node->num_children)
1180 node = node->children[0];
1185 * ice_sched_init_port - Initialize scheduler by querying information from FW
1186 * @pi: port info structure for the tree to cleanup
1188 * This function is the initial call to find the total number of Tx scheduler
1189 * resources, default topology created by firmware and storing the information
1192 enum ice_status ice_sched_init_port(struct ice_port_info *pi)
1194 struct ice_aqc_get_topo_elem *buf;
1195 enum ice_status status;
1202 return ICE_ERR_PARAM;
1205 /* Query the Default Topology from FW */
1206 buf = (struct ice_aqc_get_topo_elem *)ice_malloc(hw,
1207 ICE_AQ_MAX_BUF_LEN);
1209 return ICE_ERR_NO_MEMORY;
1211 /* Query default scheduling tree topology */
1212 status = ice_aq_get_dflt_topo(hw, pi->lport, buf, ICE_AQ_MAX_BUF_LEN,
1213 &num_branches, NULL);
1217 /* num_branches should be between 1-8 */
1218 if (num_branches < 1 || num_branches > ICE_TXSCHED_MAX_BRANCHES) {
1219 ice_debug(hw, ICE_DBG_SCHED, "num_branches unexpected %d\n",
1221 status = ICE_ERR_PARAM;
1225 /* get the number of elements on the default/first branch */
1226 num_elems = LE16_TO_CPU(buf[0].hdr.num_elems);
1228 /* num_elems should always be between 1-9 */
1229 if (num_elems < 1 || num_elems > ICE_AQC_TOPO_MAX_LEVEL_NUM) {
1230 ice_debug(hw, ICE_DBG_SCHED, "num_elems unexpected %d\n",
1232 status = ICE_ERR_PARAM;
1236 /* If the last node is a leaf node then the index of the queue group
1237 * layer is two less than the number of elements.
1239 if (num_elems > 2 && buf[0].generic[num_elems - 1].data.elem_type ==
1240 ICE_AQC_ELEM_TYPE_LEAF)
1241 pi->last_node_teid =
1242 LE32_TO_CPU(buf[0].generic[num_elems - 2].node_teid);
1244 pi->last_node_teid =
1245 LE32_TO_CPU(buf[0].generic[num_elems - 1].node_teid);
1247 /* Insert the Tx Sched root node */
1248 status = ice_sched_add_root_node(pi, &buf[0].generic[0]);
1252 /* Parse the default tree and cache the information */
1253 for (i = 0; i < num_branches; i++) {
1254 num_elems = LE16_TO_CPU(buf[i].hdr.num_elems);
1256 /* Skip root element as already inserted */
1257 for (j = 1; j < num_elems; j++) {
1258 /* update the sw entry point */
1259 if (buf[0].generic[j].data.elem_type ==
1260 ICE_AQC_ELEM_TYPE_ENTRY_POINT)
1261 hw->sw_entry_point_layer = j;
1263 status = ice_sched_add_node(pi, j, &buf[i].generic[j]);
1269 /* Remove the default nodes. */
1271 ice_sched_rm_dflt_nodes(pi);
1273 /* initialize the port for handling the scheduler tree */
1274 pi->port_state = ICE_SCHED_PORT_STATE_READY;
1275 ice_init_lock(&pi->sched_lock);
1276 for (i = 0; i < ICE_AQC_TOPO_MAX_LEVEL_NUM; i++)
1277 INIT_LIST_HEAD(&pi->rl_prof_list[i]);
1280 if (status && pi->root) {
1281 ice_free_sched_node(pi, pi->root);
1290 * ice_sched_get_node - Get the struct ice_sched_node for given TEID
1291 * @pi: port information structure
1292 * @teid: Scheduler node TEID
1294 * This function retrieves the ice_sched_node struct for given TEID from
1295 * the SW DB and returns it to the caller.
1297 struct ice_sched_node *ice_sched_get_node(struct ice_port_info *pi, u32 teid)
1299 struct ice_sched_node *node;
1304 /* Find the node starting from root */
1305 ice_acquire_lock(&pi->sched_lock);
1306 node = ice_sched_find_node_by_teid(pi->root, teid);
1307 ice_release_lock(&pi->sched_lock);
1310 ice_debug(pi->hw, ICE_DBG_SCHED,
1311 "Node not found for teid=0x%x\n", teid);
1317 * ice_sched_query_res_alloc - query the FW for num of logical sched layers
1318 * @hw: pointer to the HW struct
1320 * query FW for allocated scheduler resources and store in HW struct
1322 enum ice_status ice_sched_query_res_alloc(struct ice_hw *hw)
1324 struct ice_aqc_query_txsched_res_resp *buf;
1325 enum ice_status status = ICE_SUCCESS;
1332 buf = (struct ice_aqc_query_txsched_res_resp *)
1333 ice_malloc(hw, sizeof(*buf));
1335 return ICE_ERR_NO_MEMORY;
1337 status = ice_aq_query_sched_res(hw, sizeof(*buf), buf, NULL);
1339 goto sched_query_out;
1341 hw->num_tx_sched_layers = LE16_TO_CPU(buf->sched_props.logical_levels);
1342 hw->num_tx_sched_phys_layers =
1343 LE16_TO_CPU(buf->sched_props.phys_levels);
1344 hw->flattened_layers = buf->sched_props.flattening_bitmap;
1345 hw->max_cgds = buf->sched_props.max_pf_cgds;
1347 /* max sibling group size of current layer refers to the max children
1348 * of the below layer node.
1349 * layer 1 node max children will be layer 2 max sibling group size
1350 * layer 2 node max children will be layer 3 max sibling group size
1351 * and so on. This array will be populated from root (index 0) to
1352 * qgroup layer 7. Leaf node has no children.
1354 for (i = 0; i < hw->num_tx_sched_layers - 1; i++) {
1355 max_sibl = buf->layer_props[i + 1].max_sibl_grp_sz;
1356 hw->max_children[i] = LE16_TO_CPU(max_sibl);
1359 hw->layer_info = (struct ice_aqc_layer_props *)
1360 ice_memdup(hw, buf->layer_props,
1361 (hw->num_tx_sched_layers *
1362 sizeof(*hw->layer_info)),
1364 if (!hw->layer_info) {
1365 status = ICE_ERR_NO_MEMORY;
1366 goto sched_query_out;
1376 * ice_sched_find_node_in_subtree - Find node in part of base node subtree
1377 * @hw: pointer to the HW struct
1378 * @base: pointer to the base node
1379 * @node: pointer to the node to search
1381 * This function checks whether a given node is part of the base node
1385 ice_sched_find_node_in_subtree(struct ice_hw *hw, struct ice_sched_node *base,
1386 struct ice_sched_node *node)
1390 for (i = 0; i < base->num_children; i++) {
1391 struct ice_sched_node *child = base->children[i];
1396 if (child->tx_sched_layer > node->tx_sched_layer)
1399 /* this recursion is intentional, and wouldn't
1400 * go more than 8 calls
1402 if (ice_sched_find_node_in_subtree(hw, child, node))
1409 * ice_sched_get_free_qparent - Get a free LAN or RDMA queue group node
1410 * @pi: port information structure
1411 * @vsi_handle: software VSI handle
1412 * @tc: branch number
1413 * @owner: LAN or RDMA
1415 * This function retrieves a free LAN or RDMA queue group node
1417 struct ice_sched_node *
1418 ice_sched_get_free_qparent(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
1421 struct ice_sched_node *vsi_node, *qgrp_node = NULL;
1422 struct ice_vsi_ctx *vsi_ctx;
1426 qgrp_layer = ice_sched_get_qgrp_layer(pi->hw);
1427 max_children = pi->hw->max_children[qgrp_layer];
1429 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
1432 vsi_node = vsi_ctx->sched.vsi_node[tc];
1433 /* validate invalid VSI ID */
1437 /* get the first queue group node from VSI sub-tree */
1438 qgrp_node = ice_sched_get_first_node(pi, vsi_node, qgrp_layer);
1440 /* make sure the qgroup node is part of the VSI subtree */
1441 if (ice_sched_find_node_in_subtree(pi->hw, vsi_node, qgrp_node))
1442 if (qgrp_node->num_children < max_children &&
1443 qgrp_node->owner == owner)
1445 qgrp_node = qgrp_node->sibling;
1453 * ice_sched_get_vsi_node - Get a VSI node based on VSI ID
1454 * @pi: pointer to the port information structure
1455 * @tc_node: pointer to the TC node
1456 * @vsi_handle: software VSI handle
1458 * This function retrieves a VSI node for a given VSI ID from a given
1461 struct ice_sched_node *
1462 ice_sched_get_vsi_node(struct ice_port_info *pi, struct ice_sched_node *tc_node,
1465 struct ice_sched_node *node;
1468 vsi_layer = ice_sched_get_vsi_layer(pi->hw);
1469 node = ice_sched_get_first_node(pi, tc_node, vsi_layer);
1471 /* Check whether it already exists */
1473 if (node->vsi_handle == vsi_handle)
1475 node = node->sibling;
1482 * ice_sched_get_agg_node - Get an aggregator node based on aggregator ID
1483 * @pi: pointer to the port information structure
1484 * @tc_node: pointer to the TC node
1485 * @agg_id: aggregator ID
1487 * This function retrieves an aggregator node for a given aggregator ID from
1490 static struct ice_sched_node *
1491 ice_sched_get_agg_node(struct ice_port_info *pi, struct ice_sched_node *tc_node,
1494 struct ice_sched_node *node;
1495 struct ice_hw *hw = pi->hw;
1500 agg_layer = ice_sched_get_agg_layer(hw);
1501 node = ice_sched_get_first_node(pi, tc_node, agg_layer);
1503 /* Check whether it already exists */
1505 if (node->agg_id == agg_id)
1507 node = node->sibling;
1514 * ice_sched_check_node - Compare node parameters between SW DB and HW DB
1515 * @hw: pointer to the HW struct
1516 * @node: pointer to the ice_sched_node struct
1518 * This function queries and compares the HW element with SW DB node parameters
1520 static bool ice_sched_check_node(struct ice_hw *hw, struct ice_sched_node *node)
1522 struct ice_aqc_get_elem buf;
1523 enum ice_status status;
1526 node_teid = LE32_TO_CPU(node->info.node_teid);
1527 status = ice_sched_query_elem(hw, node_teid, &buf);
1528 if (status != ICE_SUCCESS)
1531 if (memcmp(buf.generic, &node->info, sizeof(*buf.generic))) {
1532 ice_debug(hw, ICE_DBG_SCHED, "Node mismatch for teid=0x%x\n",
1541 * ice_sched_calc_vsi_child_nodes - calculate number of VSI child nodes
1542 * @hw: pointer to the HW struct
1543 * @num_qs: number of queues
1544 * @num_nodes: num nodes array
1546 * This function calculates the number of VSI child nodes based on the
1550 ice_sched_calc_vsi_child_nodes(struct ice_hw *hw, u16 num_qs, u16 *num_nodes)
1555 qgl = ice_sched_get_qgrp_layer(hw);
1556 vsil = ice_sched_get_vsi_layer(hw);
1558 /* calculate num nodes from queue group to VSI layer */
1559 for (i = qgl; i > vsil; i--) {
1560 /* round to the next integer if there is a remainder */
1561 num = DIVIDE_AND_ROUND_UP(num, hw->max_children[i]);
1563 /* need at least one node */
1564 num_nodes[i] = num ? num : 1;
1569 * ice_sched_add_vsi_child_nodes - add VSI child nodes to tree
1570 * @pi: port information structure
1571 * @vsi_handle: software VSI handle
1572 * @tc_node: pointer to the TC node
1573 * @num_nodes: pointer to the num nodes that needs to be added per layer
1574 * @owner: node owner (LAN or RDMA)
1576 * This function adds the VSI child nodes to tree. It gets called for
1577 * LAN and RDMA separately.
1579 static enum ice_status
1580 ice_sched_add_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle,
1581 struct ice_sched_node *tc_node, u16 *num_nodes,
1584 struct ice_sched_node *parent, *node;
1585 struct ice_hw *hw = pi->hw;
1586 enum ice_status status;
1587 u32 first_node_teid;
1591 qgl = ice_sched_get_qgrp_layer(hw);
1592 vsil = ice_sched_get_vsi_layer(hw);
1593 parent = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1594 for (i = vsil + 1; i <= qgl; i++) {
1598 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
1602 if (status != ICE_SUCCESS || num_nodes[i] != num_added)
1605 /* The newly added node can be a new parent for the next
1609 parent = ice_sched_find_node_by_teid(tc_node,
1613 node->owner = owner;
1614 node = node->sibling;
1617 parent = parent->children[0];
1625 * ice_sched_calc_vsi_support_nodes - calculate number of VSI support nodes
1626 * @pi: pointer to the port info structure
1627 * @tc_node: pointer to TC node
1628 * @num_nodes: pointer to num nodes array
1630 * This function calculates the number of supported nodes needed to add this
1631 * VSI into Tx tree including the VSI, parent and intermediate nodes in below
1635 ice_sched_calc_vsi_support_nodes(struct ice_port_info *pi,
1636 struct ice_sched_node *tc_node, u16 *num_nodes)
1638 struct ice_sched_node *node;
1642 vsil = ice_sched_get_vsi_layer(pi->hw);
1643 for (i = vsil; i >= pi->hw->sw_entry_point_layer; i--)
1644 /* Add intermediate nodes if TC has no children and
1645 * need at least one node for VSI
1647 if (!tc_node->num_children || i == vsil) {
1650 /* If intermediate nodes are reached max children
1651 * then add a new one.
1653 node = ice_sched_get_first_node(pi, tc_node, (u8)i);
1654 /* scan all the siblings */
1656 if (node->num_children <
1657 pi->hw->max_children[i])
1659 node = node->sibling;
1662 /* tree has one intermediate node to add this new VSI.
1663 * So no need to calculate supported nodes for below
1668 /* all the nodes are full, allocate a new one */
1674 * ice_sched_add_vsi_support_nodes - add VSI supported nodes into Tx tree
1675 * @pi: port information structure
1676 * @vsi_handle: software VSI handle
1677 * @tc_node: pointer to TC node
1678 * @num_nodes: pointer to num nodes array
1680 * This function adds the VSI supported nodes into Tx tree including the
1681 * VSI, its parent and intermediate nodes in below layers
1683 static enum ice_status
1684 ice_sched_add_vsi_support_nodes(struct ice_port_info *pi, u16 vsi_handle,
1685 struct ice_sched_node *tc_node, u16 *num_nodes)
1687 struct ice_sched_node *parent = tc_node;
1688 enum ice_status status;
1689 u32 first_node_teid;
1694 return ICE_ERR_PARAM;
1696 vsil = ice_sched_get_vsi_layer(pi->hw);
1697 for (i = pi->hw->sw_entry_point_layer; i <= vsil; i++) {
1698 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent,
1702 if (status != ICE_SUCCESS || num_nodes[i] != num_added)
1705 /* The newly added node can be a new parent for the next
1709 parent = ice_sched_find_node_by_teid(tc_node,
1712 parent = parent->children[0];
1718 parent->vsi_handle = vsi_handle;
1725 * ice_sched_add_vsi_to_topo - add a new VSI into tree
1726 * @pi: port information structure
1727 * @vsi_handle: software VSI handle
1730 * This function adds a new VSI into scheduler tree
1732 static enum ice_status
1733 ice_sched_add_vsi_to_topo(struct ice_port_info *pi, u16 vsi_handle, u8 tc)
1735 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
1736 struct ice_sched_node *tc_node;
1738 tc_node = ice_sched_get_tc_node(pi, tc);
1740 return ICE_ERR_PARAM;
1742 /* calculate number of supported nodes needed for this VSI */
1743 ice_sched_calc_vsi_support_nodes(pi, tc_node, num_nodes);
1745 /* add VSI supported nodes to TC subtree */
1746 return ice_sched_add_vsi_support_nodes(pi, vsi_handle, tc_node,
1751 * ice_sched_update_vsi_child_nodes - update VSI child nodes
1752 * @pi: port information structure
1753 * @vsi_handle: software VSI handle
1755 * @new_numqs: new number of max queues
1756 * @owner: owner of this subtree
1758 * This function updates the VSI child nodes based on the number of queues
1760 static enum ice_status
1761 ice_sched_update_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle,
1762 u8 tc, u16 new_numqs, u8 owner)
1764 u16 new_num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
1765 struct ice_sched_node *vsi_node;
1766 struct ice_sched_node *tc_node;
1767 struct ice_vsi_ctx *vsi_ctx;
1768 enum ice_status status = ICE_SUCCESS;
1769 struct ice_hw *hw = pi->hw;
1772 tc_node = ice_sched_get_tc_node(pi, tc);
1776 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1780 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
1782 return ICE_ERR_PARAM;
1784 prev_numqs = vsi_ctx->sched.max_lanq[tc];
1785 /* num queues are not changed or less than the previous number */
1786 if (new_numqs <= prev_numqs)
1788 status = ice_alloc_lan_q_ctx(hw, vsi_handle, tc, new_numqs);
1793 ice_sched_calc_vsi_child_nodes(hw, new_numqs, new_num_nodes);
1794 /* Keep the max number of queue configuration all the time. Update the
1795 * tree only if number of queues > previous number of queues. This may
1796 * leave some extra nodes in the tree if number of queues < previous
1797 * number but that wouldn't harm anything. Removing those extra nodes
1798 * may complicate the code if those nodes are part of SRL or
1799 * individually rate limited.
1801 status = ice_sched_add_vsi_child_nodes(pi, vsi_handle, tc_node,
1802 new_num_nodes, owner);
1805 vsi_ctx->sched.max_lanq[tc] = new_numqs;
1811 * ice_sched_cfg_vsi - configure the new/existing VSI
1812 * @pi: port information structure
1813 * @vsi_handle: software VSI handle
1815 * @maxqs: max number of queues
1816 * @owner: LAN or RDMA
1817 * @enable: TC enabled or disabled
1819 * This function adds/updates VSI nodes based on the number of queues. If TC is
1820 * enabled and VSI is in suspended state then resume the VSI back. If TC is
1821 * disabled then suspend the VSI if it is not already.
1824 ice_sched_cfg_vsi(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 maxqs,
1825 u8 owner, bool enable)
1827 struct ice_sched_node *vsi_node, *tc_node;
1828 struct ice_vsi_ctx *vsi_ctx;
1829 enum ice_status status = ICE_SUCCESS;
1830 struct ice_hw *hw = pi->hw;
1832 ice_debug(pi->hw, ICE_DBG_SCHED, "add/config VSI %d\n", vsi_handle);
1833 tc_node = ice_sched_get_tc_node(pi, tc);
1835 return ICE_ERR_PARAM;
1836 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
1838 return ICE_ERR_PARAM;
1839 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1841 /* suspend the VSI if TC is not enabled */
1843 if (vsi_node && vsi_node->in_use) {
1844 u32 teid = LE32_TO_CPU(vsi_node->info.node_teid);
1846 status = ice_sched_suspend_resume_elems(hw, 1, &teid,
1849 vsi_node->in_use = false;
1854 /* TC is enabled, if it is a new VSI then add it to the tree */
1856 status = ice_sched_add_vsi_to_topo(pi, vsi_handle, tc);
1860 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1864 vsi_ctx->sched.vsi_node[tc] = vsi_node;
1865 vsi_node->in_use = true;
1866 /* invalidate the max queues whenever VSI gets added first time
1867 * into the scheduler tree (boot or after reset). We need to
1868 * recreate the child nodes all the time in these cases.
1870 vsi_ctx->sched.max_lanq[tc] = 0;
1873 /* update the VSI child nodes */
1874 status = ice_sched_update_vsi_child_nodes(pi, vsi_handle, tc, maxqs,
1879 /* TC is enabled, resume the VSI if it is in the suspend state */
1880 if (!vsi_node->in_use) {
1881 u32 teid = LE32_TO_CPU(vsi_node->info.node_teid);
1883 status = ice_sched_suspend_resume_elems(hw, 1, &teid, false);
1885 vsi_node->in_use = true;
1892 * ice_sched_rm_agg_vsi_entry - remove aggregator related VSI info entry
1893 * @pi: port information structure
1894 * @vsi_handle: software VSI handle
1896 * This function removes single aggregator VSI info entry from
1900 ice_sched_rm_agg_vsi_info(struct ice_port_info *pi, u16 vsi_handle)
1902 struct ice_sched_agg_info *agg_info;
1903 struct ice_sched_agg_info *atmp;
1905 LIST_FOR_EACH_ENTRY_SAFE(agg_info, atmp, &pi->hw->agg_list,
1908 struct ice_sched_agg_vsi_info *agg_vsi_info;
1909 struct ice_sched_agg_vsi_info *vtmp;
1911 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, vtmp,
1912 &agg_info->agg_vsi_list,
1913 ice_sched_agg_vsi_info, list_entry)
1914 if (agg_vsi_info->vsi_handle == vsi_handle) {
1915 LIST_DEL(&agg_vsi_info->list_entry);
1916 ice_free(pi->hw, agg_vsi_info);
1923 * ice_sched_is_leaf_node_present - check for a leaf node in the sub-tree
1924 * @node: pointer to the sub-tree node
1926 * This function checks for a leaf node presence in a given sub-tree node.
1928 static bool ice_sched_is_leaf_node_present(struct ice_sched_node *node)
1932 for (i = 0; i < node->num_children; i++)
1933 if (ice_sched_is_leaf_node_present(node->children[i]))
1935 /* check for a leaf node */
1936 return (node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF);
1940 * ice_sched_rm_vsi_cfg - remove the VSI and its children nodes
1941 * @pi: port information structure
1942 * @vsi_handle: software VSI handle
1943 * @owner: LAN or RDMA
1945 * This function removes the VSI and its LAN or RDMA children nodes from the
1948 static enum ice_status
1949 ice_sched_rm_vsi_cfg(struct ice_port_info *pi, u16 vsi_handle, u8 owner)
1951 enum ice_status status = ICE_ERR_PARAM;
1952 struct ice_vsi_ctx *vsi_ctx;
1955 ice_debug(pi->hw, ICE_DBG_SCHED, "removing VSI %d\n", vsi_handle);
1956 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
1958 ice_acquire_lock(&pi->sched_lock);
1959 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
1961 goto exit_sched_rm_vsi_cfg;
1963 ice_for_each_traffic_class(i) {
1964 struct ice_sched_node *vsi_node, *tc_node;
1967 tc_node = ice_sched_get_tc_node(pi, i);
1971 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1975 if (ice_sched_is_leaf_node_present(vsi_node)) {
1976 ice_debug(pi->hw, ICE_DBG_SCHED,
1977 "VSI has leaf nodes in TC %d\n", i);
1978 status = ICE_ERR_IN_USE;
1979 goto exit_sched_rm_vsi_cfg;
1981 while (j < vsi_node->num_children) {
1982 if (vsi_node->children[j]->owner == owner) {
1983 ice_free_sched_node(pi, vsi_node->children[j]);
1985 /* reset the counter again since the num
1986 * children will be updated after node removal
1993 /* remove the VSI if it has no children */
1994 if (!vsi_node->num_children) {
1995 ice_free_sched_node(pi, vsi_node);
1996 vsi_ctx->sched.vsi_node[i] = NULL;
1998 /* clean up aggregator related VSI info if any */
1999 ice_sched_rm_agg_vsi_info(pi, vsi_handle);
2001 if (owner == ICE_SCHED_NODE_OWNER_LAN)
2002 vsi_ctx->sched.max_lanq[i] = 0;
2004 status = ICE_SUCCESS;
2006 exit_sched_rm_vsi_cfg:
2007 ice_release_lock(&pi->sched_lock);
2012 * ice_rm_vsi_lan_cfg - remove VSI and its LAN children nodes
2013 * @pi: port information structure
2014 * @vsi_handle: software VSI handle
2016 * This function clears the VSI and its LAN children nodes from scheduler tree
2019 enum ice_status ice_rm_vsi_lan_cfg(struct ice_port_info *pi, u16 vsi_handle)
2021 return ice_sched_rm_vsi_cfg(pi, vsi_handle, ICE_SCHED_NODE_OWNER_LAN);
2026 * ice_sched_is_tree_balanced - Check tree nodes are identical or not
2027 * @hw: pointer to the HW struct
2028 * @node: pointer to the ice_sched_node struct
2030 * This function compares all the nodes for a given tree against HW DB nodes
2031 * This function needs to be called with the port_info->sched_lock held
2033 bool ice_sched_is_tree_balanced(struct ice_hw *hw, struct ice_sched_node *node)
2037 /* start from the leaf node */
2038 for (i = 0; i < node->num_children; i++)
2039 /* Fail if node doesn't match with the SW DB
2040 * this recursion is intentional, and wouldn't
2041 * go more than 9 calls
2043 if (!ice_sched_is_tree_balanced(hw, node->children[i]))
2046 return ice_sched_check_node(hw, node);
2050 * ice_aq_query_node_to_root - retrieve the tree topology for a given node TEID
2051 * @hw: pointer to the HW struct
2052 * @node_teid: node TEID
2053 * @buf: pointer to buffer
2054 * @buf_size: buffer size in bytes
2055 * @cd: pointer to command details structure or NULL
2057 * This function retrieves the tree topology from the firmware for a given
2058 * node TEID to the root node.
2061 ice_aq_query_node_to_root(struct ice_hw *hw, u32 node_teid,
2062 struct ice_aqc_get_elem *buf, u16 buf_size,
2063 struct ice_sq_cd *cd)
2065 struct ice_aqc_query_node_to_root *cmd;
2066 struct ice_aq_desc desc;
2068 cmd = &desc.params.query_node_to_root;
2069 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_node_to_root);
2070 cmd->teid = CPU_TO_LE32(node_teid);
2071 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2075 * ice_get_agg_info - get the aggregator ID
2076 * @hw: pointer to the hardware structure
2077 * @agg_id: aggregator ID
2079 * This function validates aggregator ID. The function returns info if
2080 * aggregator ID is present in list otherwise it returns null.
2082 static struct ice_sched_agg_info*
2083 ice_get_agg_info(struct ice_hw *hw, u32 agg_id)
2085 struct ice_sched_agg_info *agg_info;
2087 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
2089 if (agg_info->agg_id == agg_id)
2096 * ice_sched_get_free_vsi_parent - Find a free parent node in aggregator subtree
2097 * @hw: pointer to the HW struct
2098 * @node: pointer to a child node
2099 * @num_nodes: num nodes count array
2101 * This function walks through the aggregator subtree to find a free parent
2104 static struct ice_sched_node *
2105 ice_sched_get_free_vsi_parent(struct ice_hw *hw, struct ice_sched_node *node,
2108 u8 l = node->tx_sched_layer;
2111 vsil = ice_sched_get_vsi_layer(hw);
2113 /* Is it VSI parent layer ? */
2115 return (node->num_children < hw->max_children[l]) ? node : NULL;
2117 /* We have intermediate nodes. Let's walk through the subtree. If the
2118 * intermediate node has space to add a new node then clear the count
2120 if (node->num_children < hw->max_children[l])
2122 /* The below recursive call is intentional and wouldn't go more than
2123 * 2 or 3 iterations.
2126 for (i = 0; i < node->num_children; i++) {
2127 struct ice_sched_node *parent;
2129 parent = ice_sched_get_free_vsi_parent(hw, node->children[i],
2139 * ice_sched_update_parent - update the new parent in SW DB
2140 * @new_parent: pointer to a new parent node
2141 * @node: pointer to a child node
2143 * This function removes the child from the old parent and adds it to a new
2147 ice_sched_update_parent(struct ice_sched_node *new_parent,
2148 struct ice_sched_node *node)
2150 struct ice_sched_node *old_parent;
2153 old_parent = node->parent;
2155 /* update the old parent children */
2156 for (i = 0; i < old_parent->num_children; i++)
2157 if (old_parent->children[i] == node) {
2158 for (j = i + 1; j < old_parent->num_children; j++)
2159 old_parent->children[j - 1] =
2160 old_parent->children[j];
2161 old_parent->num_children--;
2165 /* now move the node to a new parent */
2166 new_parent->children[new_parent->num_children++] = node;
2167 node->parent = new_parent;
2168 node->info.parent_teid = new_parent->info.node_teid;
2172 * ice_sched_move_nodes - move child nodes to a given parent
2173 * @pi: port information structure
2174 * @parent: pointer to parent node
2175 * @num_items: number of child nodes to be moved
2176 * @list: pointer to child node teids
2178 * This function move the child nodes to a given parent.
2180 static enum ice_status
2181 ice_sched_move_nodes(struct ice_port_info *pi, struct ice_sched_node *parent,
2182 u16 num_items, u32 *list)
2184 struct ice_aqc_move_elem *buf;
2185 struct ice_sched_node *node;
2186 enum ice_status status = ICE_SUCCESS;
2193 if (!parent || !num_items)
2194 return ICE_ERR_PARAM;
2196 /* Does parent have enough space */
2197 if (parent->num_children + num_items >=
2198 hw->max_children[parent->tx_sched_layer])
2199 return ICE_ERR_AQ_FULL;
2201 buf = (struct ice_aqc_move_elem *)ice_malloc(hw, sizeof(*buf));
2203 return ICE_ERR_NO_MEMORY;
2205 for (i = 0; i < num_items; i++) {
2206 node = ice_sched_find_node_by_teid(pi->root, list[i]);
2208 status = ICE_ERR_PARAM;
2212 buf->hdr.src_parent_teid = node->info.parent_teid;
2213 buf->hdr.dest_parent_teid = parent->info.node_teid;
2214 buf->teid[0] = node->info.node_teid;
2215 buf->hdr.num_elems = CPU_TO_LE16(1);
2216 status = ice_aq_move_sched_elems(hw, 1, buf, sizeof(*buf),
2218 if (status && grps_movd != 1) {
2219 status = ICE_ERR_CFG;
2223 /* update the SW DB */
2224 ice_sched_update_parent(parent, node);
2233 * ice_sched_move_vsi_to_agg - move VSI to aggregator node
2234 * @pi: port information structure
2235 * @vsi_handle: software VSI handle
2236 * @agg_id: aggregator ID
2239 * This function moves a VSI to an aggregator node or its subtree.
2240 * Intermediate nodes may be created if required.
2242 static enum ice_status
2243 ice_sched_move_vsi_to_agg(struct ice_port_info *pi, u16 vsi_handle, u32 agg_id,
2246 struct ice_sched_node *vsi_node, *agg_node, *tc_node, *parent;
2247 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
2248 u32 first_node_teid, vsi_teid;
2249 enum ice_status status;
2250 u16 num_nodes_added;
2253 tc_node = ice_sched_get_tc_node(pi, tc);
2257 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2259 return ICE_ERR_DOES_NOT_EXIST;
2261 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
2263 return ICE_ERR_DOES_NOT_EXIST;
2265 aggl = ice_sched_get_agg_layer(pi->hw);
2266 vsil = ice_sched_get_vsi_layer(pi->hw);
2268 /* set intermediate node count to 1 between aggregator and VSI layers */
2269 for (i = aggl + 1; i < vsil; i++)
2272 /* Check if the aggregator subtree has any free node to add the VSI */
2273 for (i = 0; i < agg_node->num_children; i++) {
2274 parent = ice_sched_get_free_vsi_parent(pi->hw,
2275 agg_node->children[i],
2283 for (i = aggl + 1; i < vsil; i++) {
2284 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
2288 if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added)
2291 /* The newly added node can be a new parent for the next
2294 if (num_nodes_added)
2295 parent = ice_sched_find_node_by_teid(tc_node,
2298 parent = parent->children[0];
2305 vsi_teid = LE32_TO_CPU(vsi_node->info.node_teid);
2306 return ice_sched_move_nodes(pi, parent, 1, &vsi_teid);
2310 * ice_move_all_vsi_to_dflt_agg - move all VSI(s) to default aggregator
2311 * @pi: port information structure
2312 * @agg_info: aggregator info
2313 * @tc: traffic class number
2314 * @rm_vsi_info: true or false
2316 * This function move all the VSI(s) to the default aggregator and delete
2317 * aggregator VSI info based on passed in boolean parameter rm_vsi_info. The
2318 * caller holds the scheduler lock.
2320 static enum ice_status
2321 ice_move_all_vsi_to_dflt_agg(struct ice_port_info *pi,
2322 struct ice_sched_agg_info *agg_info, u8 tc,
2325 struct ice_sched_agg_vsi_info *agg_vsi_info;
2326 struct ice_sched_agg_vsi_info *tmp;
2327 enum ice_status status = ICE_SUCCESS;
2329 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, tmp, &agg_info->agg_vsi_list,
2330 ice_sched_agg_vsi_info, list_entry) {
2331 u16 vsi_handle = agg_vsi_info->vsi_handle;
2333 /* Move VSI to default aggregator */
2334 if (!ice_is_tc_ena(agg_vsi_info->tc_bitmap[0], tc))
2337 status = ice_sched_move_vsi_to_agg(pi, vsi_handle,
2338 ICE_DFLT_AGG_ID, tc);
2342 ice_clear_bit(tc, agg_vsi_info->tc_bitmap);
2343 if (rm_vsi_info && !agg_vsi_info->tc_bitmap[0]) {
2344 LIST_DEL(&agg_vsi_info->list_entry);
2345 ice_free(pi->hw, agg_vsi_info);
2353 * ice_sched_is_agg_inuse - check whether the aggregator is in use or not
2354 * @pi: port information structure
2355 * @node: node pointer
2357 * This function checks whether the aggregator is attached with any VSI or not.
2360 ice_sched_is_agg_inuse(struct ice_port_info *pi, struct ice_sched_node *node)
2364 vsil = ice_sched_get_vsi_layer(pi->hw);
2365 if (node->tx_sched_layer < vsil - 1) {
2366 for (i = 0; i < node->num_children; i++)
2367 if (ice_sched_is_agg_inuse(pi, node->children[i]))
2371 return node->num_children ? true : false;
2376 * ice_sched_rm_agg_cfg - remove the aggregator node
2377 * @pi: port information structure
2378 * @agg_id: aggregator ID
2381 * This function removes the aggregator node and intermediate nodes if any
2384 static enum ice_status
2385 ice_sched_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc)
2387 struct ice_sched_node *tc_node, *agg_node;
2388 struct ice_hw *hw = pi->hw;
2390 tc_node = ice_sched_get_tc_node(pi, tc);
2394 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2396 return ICE_ERR_DOES_NOT_EXIST;
2398 /* Can't remove the aggregator node if it has children */
2399 if (ice_sched_is_agg_inuse(pi, agg_node))
2400 return ICE_ERR_IN_USE;
2402 /* need to remove the whole subtree if aggregator node is the
2405 while (agg_node->tx_sched_layer > hw->sw_entry_point_layer) {
2406 struct ice_sched_node *parent = agg_node->parent;
2411 if (parent->num_children > 1)
2417 ice_free_sched_node(pi, agg_node);
2422 * ice_rm_agg_cfg_tc - remove aggregator configuration for TC
2423 * @pi: port information structure
2424 * @agg_info: aggregator ID
2426 * @rm_vsi_info: bool value true or false
2428 * This function removes aggregator reference to VSI of given TC. It removes
2429 * the aggregator configuration completely for requested TC. The caller needs
2430 * to hold the scheduler lock.
2432 static enum ice_status
2433 ice_rm_agg_cfg_tc(struct ice_port_info *pi, struct ice_sched_agg_info *agg_info,
2434 u8 tc, bool rm_vsi_info)
2436 enum ice_status status = ICE_SUCCESS;
2438 /* If nothing to remove - return success */
2439 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
2440 goto exit_rm_agg_cfg_tc;
2442 status = ice_move_all_vsi_to_dflt_agg(pi, agg_info, tc, rm_vsi_info);
2444 goto exit_rm_agg_cfg_tc;
2446 /* Delete aggregator node(s) */
2447 status = ice_sched_rm_agg_cfg(pi, agg_info->agg_id, tc);
2449 goto exit_rm_agg_cfg_tc;
2451 ice_clear_bit(tc, agg_info->tc_bitmap);
2457 * ice_save_agg_tc_bitmap - save aggregator TC bitmap
2458 * @pi: port information structure
2459 * @agg_id: aggregator ID
2460 * @tc_bitmap: 8 bits TC bitmap
2462 * Save aggregator TC bitmap. This function needs to be called with scheduler
2465 static enum ice_status
2466 ice_save_agg_tc_bitmap(struct ice_port_info *pi, u32 agg_id,
2467 ice_bitmap_t *tc_bitmap)
2469 struct ice_sched_agg_info *agg_info;
2471 agg_info = ice_get_agg_info(pi->hw, agg_id);
2473 return ICE_ERR_PARAM;
2474 ice_cp_bitmap(agg_info->replay_tc_bitmap, tc_bitmap,
2475 ICE_MAX_TRAFFIC_CLASS);
2480 * ice_sched_add_agg_cfg - create an aggregator node
2481 * @pi: port information structure
2482 * @agg_id: aggregator ID
2485 * This function creates an aggregator node and intermediate nodes if required
2488 static enum ice_status
2489 ice_sched_add_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc)
2491 struct ice_sched_node *parent, *agg_node, *tc_node;
2492 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
2493 enum ice_status status = ICE_SUCCESS;
2494 struct ice_hw *hw = pi->hw;
2495 u32 first_node_teid;
2496 u16 num_nodes_added;
2499 tc_node = ice_sched_get_tc_node(pi, tc);
2503 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2504 /* Does Agg node already exist ? */
2508 aggl = ice_sched_get_agg_layer(hw);
2510 /* need one node in Agg layer */
2511 num_nodes[aggl] = 1;
2513 /* Check whether the intermediate nodes have space to add the
2514 * new aggregator. If they are full, then SW needs to allocate a new
2515 * intermediate node on those layers
2517 for (i = hw->sw_entry_point_layer; i < aggl; i++) {
2518 parent = ice_sched_get_first_node(pi, tc_node, i);
2520 /* scan all the siblings */
2522 if (parent->num_children < hw->max_children[i])
2524 parent = parent->sibling;
2527 /* all the nodes are full, reserve one for this layer */
2532 /* add the aggregator node */
2534 for (i = hw->sw_entry_point_layer; i <= aggl; i++) {
2538 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
2542 if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added)
2545 /* The newly added node can be a new parent for the next
2548 if (num_nodes_added) {
2549 parent = ice_sched_find_node_by_teid(tc_node,
2551 /* register aggregator ID with the aggregator node */
2552 if (parent && i == aggl)
2553 parent->agg_id = agg_id;
2555 parent = parent->children[0];
2563 * ice_sched_cfg_agg - configure aggregator node
2564 * @pi: port information structure
2565 * @agg_id: aggregator ID
2566 * @agg_type: aggregator type queue, VSI, or aggregator group
2567 * @tc_bitmap: bits TC bitmap
2569 * It registers a unique aggregator node into scheduler services. It
2570 * allows a user to register with a unique ID to track it's resources.
2571 * The aggregator type determines if this is a queue group, VSI group
2572 * or aggregator group. It then creates the aggregator node(s) for requested
2573 * TC(s) or removes an existing aggregator node including its configuration
2574 * if indicated via tc_bitmap. Call ice_rm_agg_cfg to release aggregator
2575 * resources and remove aggregator ID.
2576 * This function needs to be called with scheduler lock held.
2578 static enum ice_status
2579 ice_sched_cfg_agg(struct ice_port_info *pi, u32 agg_id,
2580 enum ice_agg_type agg_type, ice_bitmap_t *tc_bitmap)
2582 struct ice_sched_agg_info *agg_info;
2583 enum ice_status status = ICE_SUCCESS;
2584 struct ice_hw *hw = pi->hw;
2587 agg_info = ice_get_agg_info(hw, agg_id);
2589 /* Create new entry for new aggregator ID */
2590 agg_info = (struct ice_sched_agg_info *)
2591 ice_malloc(hw, sizeof(*agg_info));
2593 status = ICE_ERR_NO_MEMORY;
2596 agg_info->agg_id = agg_id;
2597 agg_info->agg_type = agg_type;
2598 agg_info->tc_bitmap[0] = 0;
2600 /* Initialize the aggregator VSI list head */
2601 INIT_LIST_HEAD(&agg_info->agg_vsi_list);
2603 /* Add new entry in aggregator list */
2604 LIST_ADD(&agg_info->list_entry, &hw->agg_list);
2606 /* Create aggregator node(s) for requested TC(s) */
2607 ice_for_each_traffic_class(tc) {
2608 if (!ice_is_tc_ena(*tc_bitmap, tc)) {
2609 /* Delete aggregator cfg TC if it exists previously */
2610 status = ice_rm_agg_cfg_tc(pi, agg_info, tc, false);
2616 /* Check if aggregator node for TC already exists */
2617 if (ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
2620 /* Create new aggregator node for TC */
2621 status = ice_sched_add_agg_cfg(pi, agg_id, tc);
2625 /* Save aggregator node's TC information */
2626 ice_set_bit(tc, agg_info->tc_bitmap);
2633 * ice_cfg_agg - config aggregator node
2634 * @pi: port information structure
2635 * @agg_id: aggregator ID
2636 * @agg_type: aggregator type queue, VSI, or aggregator group
2637 * @tc_bitmap: bits TC bitmap
2639 * This function configures aggregator node(s).
2642 ice_cfg_agg(struct ice_port_info *pi, u32 agg_id, enum ice_agg_type agg_type,
2645 ice_bitmap_t bitmap = tc_bitmap;
2646 enum ice_status status;
2648 ice_acquire_lock(&pi->sched_lock);
2649 status = ice_sched_cfg_agg(pi, agg_id, agg_type,
2650 (ice_bitmap_t *)&bitmap);
2652 status = ice_save_agg_tc_bitmap(pi, agg_id,
2653 (ice_bitmap_t *)&bitmap);
2654 ice_release_lock(&pi->sched_lock);
2659 * ice_get_agg_vsi_info - get the aggregator ID
2660 * @agg_info: aggregator info
2661 * @vsi_handle: software VSI handle
2663 * The function returns aggregator VSI info based on VSI handle. This function
2664 * needs to be called with scheduler lock held.
2666 static struct ice_sched_agg_vsi_info*
2667 ice_get_agg_vsi_info(struct ice_sched_agg_info *agg_info, u16 vsi_handle)
2669 struct ice_sched_agg_vsi_info *agg_vsi_info;
2671 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
2672 ice_sched_agg_vsi_info, list_entry)
2673 if (agg_vsi_info->vsi_handle == vsi_handle)
2674 return agg_vsi_info;
2680 * ice_get_vsi_agg_info - get the aggregator info of VSI
2681 * @hw: pointer to the hardware structure
2682 * @vsi_handle: Sw VSI handle
2684 * The function returns aggregator info of VSI represented via vsi_handle. The
2685 * VSI has in this case a different aggregator than the default one. This
2686 * function needs to be called with scheduler lock held.
2688 static struct ice_sched_agg_info*
2689 ice_get_vsi_agg_info(struct ice_hw *hw, u16 vsi_handle)
2691 struct ice_sched_agg_info *agg_info;
2693 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
2695 struct ice_sched_agg_vsi_info *agg_vsi_info;
2697 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2705 * ice_save_agg_vsi_tc_bitmap - save aggregator VSI TC bitmap
2706 * @pi: port information structure
2707 * @agg_id: aggregator ID
2708 * @vsi_handle: software VSI handle
2709 * @tc_bitmap: TC bitmap of enabled TC(s)
2711 * Save VSI to aggregator TC bitmap. This function needs to call with scheduler
2714 static enum ice_status
2715 ice_save_agg_vsi_tc_bitmap(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle,
2716 ice_bitmap_t *tc_bitmap)
2718 struct ice_sched_agg_vsi_info *agg_vsi_info;
2719 struct ice_sched_agg_info *agg_info;
2721 agg_info = ice_get_agg_info(pi->hw, agg_id);
2723 return ICE_ERR_PARAM;
2724 /* check if entry already exist */
2725 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2727 return ICE_ERR_PARAM;
2728 ice_cp_bitmap(agg_vsi_info->replay_tc_bitmap, tc_bitmap,
2729 ICE_MAX_TRAFFIC_CLASS);
2734 * ice_sched_assoc_vsi_to_agg - associate/move VSI to new/default aggregator
2735 * @pi: port information structure
2736 * @agg_id: aggregator ID
2737 * @vsi_handle: software VSI handle
2738 * @tc_bitmap: TC bitmap of enabled TC(s)
2740 * This function moves VSI to a new or default aggregator node. If VSI is
2741 * already associated to the aggregator node then no operation is performed on
2742 * the tree. This function needs to be called with scheduler lock held.
2744 static enum ice_status
2745 ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
2746 u16 vsi_handle, ice_bitmap_t *tc_bitmap)
2748 struct ice_sched_agg_vsi_info *agg_vsi_info;
2749 struct ice_sched_agg_info *agg_info;
2750 enum ice_status status = ICE_SUCCESS;
2751 struct ice_hw *hw = pi->hw;
2754 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
2755 return ICE_ERR_PARAM;
2756 agg_info = ice_get_agg_info(hw, agg_id);
2758 return ICE_ERR_PARAM;
2759 /* check if entry already exist */
2760 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2761 if (!agg_vsi_info) {
2762 /* Create new entry for VSI under aggregator list */
2763 agg_vsi_info = (struct ice_sched_agg_vsi_info *)
2764 ice_malloc(hw, sizeof(*agg_vsi_info));
2766 return ICE_ERR_PARAM;
2768 /* add VSI ID into the aggregator list */
2769 agg_vsi_info->vsi_handle = vsi_handle;
2770 LIST_ADD(&agg_vsi_info->list_entry, &agg_info->agg_vsi_list);
2772 /* Move VSI node to new aggregator node for requested TC(s) */
2773 ice_for_each_traffic_class(tc) {
2774 if (!ice_is_tc_ena(*tc_bitmap, tc))
2777 /* Move VSI to new aggregator */
2778 status = ice_sched_move_vsi_to_agg(pi, vsi_handle, agg_id, tc);
2782 if (agg_id != ICE_DFLT_AGG_ID)
2783 ice_set_bit(tc, agg_vsi_info->tc_bitmap);
2785 ice_clear_bit(tc, agg_vsi_info->tc_bitmap);
2787 /* If VSI moved back to default aggregator, delete agg_vsi_info. */
2788 if (!ice_is_any_bit_set(agg_vsi_info->tc_bitmap,
2789 ICE_MAX_TRAFFIC_CLASS)) {
2790 LIST_DEL(&agg_vsi_info->list_entry);
2791 ice_free(hw, agg_vsi_info);
2797 * ice_sched_rm_unused_rl_prof - remove unused RL profile
2798 * @pi: port information structure
2800 * This function removes unused rate limit profiles from the HW and
2801 * SW DB. The caller needs to hold scheduler lock.
2803 static void ice_sched_rm_unused_rl_prof(struct ice_port_info *pi)
2807 for (ln = 0; ln < pi->hw->num_tx_sched_layers; ln++) {
2808 struct ice_aqc_rl_profile_info *rl_prof_elem;
2809 struct ice_aqc_rl_profile_info *rl_prof_tmp;
2811 LIST_FOR_EACH_ENTRY_SAFE(rl_prof_elem, rl_prof_tmp,
2812 &pi->rl_prof_list[ln],
2813 ice_aqc_rl_profile_info, list_entry) {
2814 if (!ice_sched_del_rl_profile(pi->hw, rl_prof_elem))
2815 ice_debug(pi->hw, ICE_DBG_SCHED,
2816 "Removed rl profile\n");
2822 * ice_sched_update_elem - update element
2823 * @hw: pointer to the HW struct
2824 * @node: pointer to node
2825 * @info: node info to update
2827 * It updates the HW DB, and local SW DB of node. It updates the scheduling
2828 * parameters of node from argument info data buffer (Info->data buf) and
2829 * returns success or error on config sched element failure. The caller
2830 * needs to hold scheduler lock.
2832 static enum ice_status
2833 ice_sched_update_elem(struct ice_hw *hw, struct ice_sched_node *node,
2834 struct ice_aqc_txsched_elem_data *info)
2836 struct ice_aqc_conf_elem buf;
2837 enum ice_status status;
2841 buf.generic[0] = *info;
2842 /* Parent TEID is reserved field in this aq call */
2843 buf.generic[0].parent_teid = 0;
2844 /* Element type is reserved field in this aq call */
2845 buf.generic[0].data.elem_type = 0;
2846 /* Flags is reserved field in this aq call */
2847 buf.generic[0].data.flags = 0;
2850 /* Configure element node */
2851 status = ice_aq_cfg_sched_elems(hw, num_elems, &buf, sizeof(buf),
2853 if (status || elem_cfgd != num_elems) {
2854 ice_debug(hw, ICE_DBG_SCHED, "Config sched elem error\n");
2858 /* Config success case */
2859 /* Now update local SW DB */
2860 /* Only copy the data portion of info buffer */
2861 node->info.data = info->data;
2866 * ice_sched_cfg_node_bw_alloc - configure node BW weight/alloc params
2867 * @hw: pointer to the HW struct
2868 * @node: sched node to configure
2869 * @rl_type: rate limit type CIR, EIR, or shared
2870 * @bw_alloc: BW weight/allocation
2872 * This function configures node element's BW allocation.
2874 static enum ice_status
2875 ice_sched_cfg_node_bw_alloc(struct ice_hw *hw, struct ice_sched_node *node,
2876 enum ice_rl_type rl_type, u8 bw_alloc)
2878 struct ice_aqc_txsched_elem_data buf;
2879 struct ice_aqc_txsched_elem *data;
2880 enum ice_status status;
2884 if (rl_type == ICE_MIN_BW) {
2885 data->valid_sections |= ICE_AQC_ELEM_VALID_CIR;
2886 data->cir_bw.bw_alloc = CPU_TO_LE16(bw_alloc);
2887 } else if (rl_type == ICE_MAX_BW) {
2888 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
2889 data->eir_bw.bw_alloc = CPU_TO_LE16(bw_alloc);
2891 return ICE_ERR_PARAM;
2894 /* Configure element */
2895 status = ice_sched_update_elem(hw, node, &buf);
2900 * ice_move_vsi_to_agg - moves VSI to new or default aggregator
2901 * @pi: port information structure
2902 * @agg_id: aggregator ID
2903 * @vsi_handle: software VSI handle
2904 * @tc_bitmap: TC bitmap of enabled TC(s)
2906 * Move or associate VSI to a new or default aggregator node.
2909 ice_move_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle,
2912 ice_bitmap_t bitmap = tc_bitmap;
2913 enum ice_status status;
2915 ice_acquire_lock(&pi->sched_lock);
2916 status = ice_sched_assoc_vsi_to_agg(pi, agg_id, vsi_handle,
2917 (ice_bitmap_t *)&bitmap);
2919 status = ice_save_agg_vsi_tc_bitmap(pi, agg_id, vsi_handle,
2920 (ice_bitmap_t *)&bitmap);
2921 ice_release_lock(&pi->sched_lock);
2926 * ice_rm_agg_cfg - remove aggregator configuration
2927 * @pi: port information structure
2928 * @agg_id: aggregator ID
2930 * This function removes aggregator reference to VSI and delete aggregator ID
2931 * info. It removes the aggregator configuration completely.
2933 enum ice_status ice_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id)
2935 struct ice_sched_agg_info *agg_info;
2936 enum ice_status status = ICE_SUCCESS;
2939 ice_acquire_lock(&pi->sched_lock);
2940 agg_info = ice_get_agg_info(pi->hw, agg_id);
2942 status = ICE_ERR_DOES_NOT_EXIST;
2943 goto exit_ice_rm_agg_cfg;
2946 ice_for_each_traffic_class(tc) {
2947 status = ice_rm_agg_cfg_tc(pi, agg_info, tc, true);
2949 goto exit_ice_rm_agg_cfg;
2952 if (ice_is_any_bit_set(agg_info->tc_bitmap, ICE_MAX_TRAFFIC_CLASS)) {
2953 status = ICE_ERR_IN_USE;
2954 goto exit_ice_rm_agg_cfg;
2957 /* Safe to delete entry now */
2958 LIST_DEL(&agg_info->list_entry);
2959 ice_free(pi->hw, agg_info);
2961 /* Remove unused RL profile IDs from HW and SW DB */
2962 ice_sched_rm_unused_rl_prof(pi);
2964 exit_ice_rm_agg_cfg:
2965 ice_release_lock(&pi->sched_lock);
2970 * ice_set_clear_cir_bw_alloc - set or clear CIR BW alloc information
2971 * @bw_t_info: bandwidth type information structure
2972 * @bw_alloc: Bandwidth allocation information
2974 * Save or clear CIR BW alloc information (bw_alloc) in the passed param
2978 ice_set_clear_cir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc)
2980 bw_t_info->cir_bw.bw_alloc = bw_alloc;
2981 if (bw_t_info->cir_bw.bw_alloc)
2982 ice_set_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap);
2984 ice_clear_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap);
2988 * ice_set_clear_eir_bw_alloc - set or clear EIR BW alloc information
2989 * @bw_t_info: bandwidth type information structure
2990 * @bw_alloc: Bandwidth allocation information
2992 * Save or clear EIR BW alloc information (bw_alloc) in the passed param
2996 ice_set_clear_eir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc)
2998 bw_t_info->eir_bw.bw_alloc = bw_alloc;
2999 if (bw_t_info->eir_bw.bw_alloc)
3000 ice_set_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap);
3002 ice_clear_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap);
3006 * ice_sched_save_vsi_bw_alloc - save VSI node's BW alloc information
3007 * @pi: port information structure
3008 * @vsi_handle: sw VSI handle
3009 * @tc: traffic class
3010 * @rl_type: rate limit type min or max
3011 * @bw_alloc: Bandwidth allocation information
3013 * Save BW alloc information of VSI type node for post replay use.
3015 static enum ice_status
3016 ice_sched_save_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3017 enum ice_rl_type rl_type, u16 bw_alloc)
3019 struct ice_vsi_ctx *vsi_ctx;
3021 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3022 return ICE_ERR_PARAM;
3023 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3025 return ICE_ERR_PARAM;
3028 ice_set_clear_cir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc],
3032 ice_set_clear_eir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc],
3036 return ICE_ERR_PARAM;
3042 * ice_set_clear_cir_bw - set or clear CIR BW
3043 * @bw_t_info: bandwidth type information structure
3044 * @bw: bandwidth in Kbps - Kilo bits per sec
3046 * Save or clear CIR bandwidth (BW) in the passed param bw_t_info.
3049 ice_set_clear_cir_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3051 if (bw == ICE_SCHED_DFLT_BW) {
3052 ice_clear_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap);
3053 bw_t_info->cir_bw.bw = 0;
3055 /* Save type of BW information */
3056 ice_set_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap);
3057 bw_t_info->cir_bw.bw = bw;
3062 * ice_set_clear_eir_bw - set or clear EIR BW
3063 * @bw_t_info: bandwidth type information structure
3064 * @bw: bandwidth in Kbps - Kilo bits per sec
3066 * Save or clear EIR bandwidth (BW) in the passed param bw_t_info.
3069 ice_set_clear_eir_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3071 if (bw == ICE_SCHED_DFLT_BW) {
3072 ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3073 bw_t_info->eir_bw.bw = 0;
3075 /* EIR BW and Shared BW profiles are mutually exclusive and
3076 * hence only one of them may be set for any given element.
3077 * First clear earlier saved shared BW information.
3079 ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3080 bw_t_info->shared_bw = 0;
3081 /* save EIR BW information */
3082 ice_set_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3083 bw_t_info->eir_bw.bw = bw;
3088 * ice_set_clear_shared_bw - set or clear shared BW
3089 * @bw_t_info: bandwidth type information structure
3090 * @bw: bandwidth in Kbps - Kilo bits per sec
3092 * Save or clear shared bandwidth (BW) in the passed param bw_t_info.
3095 ice_set_clear_shared_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3097 if (bw == ICE_SCHED_DFLT_BW) {
3098 ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3099 bw_t_info->shared_bw = 0;
3101 /* EIR BW and Shared BW profiles are mutually exclusive and
3102 * hence only one of them may be set for any given element.
3103 * First clear earlier saved EIR BW information.
3105 ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3106 bw_t_info->eir_bw.bw = 0;
3107 /* save shared BW information */
3108 ice_set_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3109 bw_t_info->shared_bw = bw;
3114 * ice_sched_save_vsi_bw - save VSI node's BW information
3115 * @pi: port information structure
3116 * @vsi_handle: sw VSI handle
3117 * @tc: traffic class
3118 * @rl_type: rate limit type min, max, or shared
3119 * @bw: bandwidth in Kbps - Kilo bits per sec
3121 * Save BW information of VSI type node for post replay use.
3123 static enum ice_status
3124 ice_sched_save_vsi_bw(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3125 enum ice_rl_type rl_type, u32 bw)
3127 struct ice_vsi_ctx *vsi_ctx;
3129 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3130 return ICE_ERR_PARAM;
3131 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3133 return ICE_ERR_PARAM;
3136 ice_set_clear_cir_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3139 ice_set_clear_eir_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3142 ice_set_clear_shared_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3145 return ICE_ERR_PARAM;
3151 * ice_set_clear_prio - set or clear priority information
3152 * @bw_t_info: bandwidth type information structure
3153 * @prio: priority to save
3155 * Save or clear priority (prio) in the passed param bw_t_info.
3158 ice_set_clear_prio(struct ice_bw_type_info *bw_t_info, u8 prio)
3160 bw_t_info->generic = prio;
3161 if (bw_t_info->generic)
3162 ice_set_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap);
3164 ice_clear_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap);
3168 * ice_sched_save_vsi_prio - save VSI node's priority information
3169 * @pi: port information structure
3170 * @vsi_handle: Software VSI handle
3171 * @tc: traffic class
3172 * @prio: priority to save
3174 * Save priority information of VSI type node for post replay use.
3176 static enum ice_status
3177 ice_sched_save_vsi_prio(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3180 struct ice_vsi_ctx *vsi_ctx;
3182 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3183 return ICE_ERR_PARAM;
3184 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3186 return ICE_ERR_PARAM;
3187 if (tc >= ICE_MAX_TRAFFIC_CLASS)
3188 return ICE_ERR_PARAM;
3189 ice_set_clear_prio(&vsi_ctx->sched.bw_t_info[tc], prio);
3194 * ice_sched_save_agg_bw_alloc - save aggregator node's BW alloc information
3195 * @pi: port information structure
3196 * @agg_id: node aggregator ID
3197 * @tc: traffic class
3198 * @rl_type: rate limit type min or max
3199 * @bw_alloc: bandwidth alloc information
3201 * Save BW alloc information of AGG type node for post replay use.
3203 static enum ice_status
3204 ice_sched_save_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3205 enum ice_rl_type rl_type, u16 bw_alloc)
3207 struct ice_sched_agg_info *agg_info;
3209 agg_info = ice_get_agg_info(pi->hw, agg_id);
3211 return ICE_ERR_PARAM;
3212 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
3213 return ICE_ERR_PARAM;
3216 ice_set_clear_cir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc);
3219 ice_set_clear_eir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc);
3222 return ICE_ERR_PARAM;
3228 * ice_sched_save_agg_bw - save aggregator node's BW information
3229 * @pi: port information structure
3230 * @agg_id: node aggregator ID
3231 * @tc: traffic class
3232 * @rl_type: rate limit type min, max, or shared
3233 * @bw: bandwidth in Kbps - Kilo bits per sec
3235 * Save BW information of AGG type node for post replay use.
3237 static enum ice_status
3238 ice_sched_save_agg_bw(struct ice_port_info *pi, u32 agg_id, u8 tc,
3239 enum ice_rl_type rl_type, u32 bw)
3241 struct ice_sched_agg_info *agg_info;
3243 agg_info = ice_get_agg_info(pi->hw, agg_id);
3245 return ICE_ERR_PARAM;
3246 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
3247 return ICE_ERR_PARAM;
3250 ice_set_clear_cir_bw(&agg_info->bw_t_info[tc], bw);
3253 ice_set_clear_eir_bw(&agg_info->bw_t_info[tc], bw);
3256 ice_set_clear_shared_bw(&agg_info->bw_t_info[tc], bw);
3259 return ICE_ERR_PARAM;
3265 * ice_cfg_vsi_bw_lmt_per_tc - configure VSI BW limit per TC
3266 * @pi: port information structure
3267 * @vsi_handle: software VSI handle
3268 * @tc: traffic class
3269 * @rl_type: min or max
3270 * @bw: bandwidth in Kbps
3272 * This function configures BW limit of VSI scheduling node based on TC
3276 ice_cfg_vsi_bw_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3277 enum ice_rl_type rl_type, u32 bw)
3279 enum ice_status status;
3281 status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle,
3285 ice_acquire_lock(&pi->sched_lock);
3286 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw);
3287 ice_release_lock(&pi->sched_lock);
3293 * ice_cfg_dflt_vsi_bw_lmt_per_tc - configure default VSI BW limit per TC
3294 * @pi: port information structure
3295 * @vsi_handle: software VSI handle
3296 * @tc: traffic class
3297 * @rl_type: min or max
3299 * This function configures default BW limit of VSI scheduling node based on TC
3303 ice_cfg_vsi_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3304 enum ice_rl_type rl_type)
3306 enum ice_status status;
3308 status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle,
3313 ice_acquire_lock(&pi->sched_lock);
3314 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type,
3316 ice_release_lock(&pi->sched_lock);
3322 * ice_cfg_agg_bw_lmt_per_tc - configure aggregator BW limit per TC
3323 * @pi: port information structure
3324 * @agg_id: aggregator ID
3325 * @tc: traffic class
3326 * @rl_type: min or max
3327 * @bw: bandwidth in Kbps
3329 * This function applies BW limit to aggregator scheduling node based on TC
3333 ice_cfg_agg_bw_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3334 enum ice_rl_type rl_type, u32 bw)
3336 enum ice_status status;
3338 status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG,
3341 ice_acquire_lock(&pi->sched_lock);
3342 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw);
3343 ice_release_lock(&pi->sched_lock);
3349 * ice_cfg_agg_bw_dflt_lmt_per_tc - configure aggregator BW default limit per TC
3350 * @pi: port information structure
3351 * @agg_id: aggregator ID
3352 * @tc: traffic class
3353 * @rl_type: min or max
3355 * This function applies default BW limit to aggregator scheduling node based
3356 * on TC information.
3359 ice_cfg_agg_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3360 enum ice_rl_type rl_type)
3362 enum ice_status status;
3364 status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG,
3368 ice_acquire_lock(&pi->sched_lock);
3369 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type,
3371 ice_release_lock(&pi->sched_lock);
3377 * ice_cfg_vsi_bw_shared_lmt - configure VSI BW shared limit
3378 * @pi: port information structure
3379 * @vsi_handle: software VSI handle
3380 * @bw: bandwidth in Kbps
3382 * This function Configures shared rate limiter(SRL) of all VSI type nodes
3383 * across all traffic classes for VSI matching handle.
3386 ice_cfg_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle, u32 bw)
3388 return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle, bw);
3392 * ice_cfg_vsi_bw_no_shared_lmt - configure VSI BW for no shared limiter
3393 * @pi: port information structure
3394 * @vsi_handle: software VSI handle
3396 * This function removes the shared rate limiter(SRL) of all VSI type nodes
3397 * across all traffic classes for VSI matching handle.
3400 ice_cfg_vsi_bw_no_shared_lmt(struct ice_port_info *pi, u16 vsi_handle)
3402 return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle,
3407 * ice_cfg_agg_bw_shared_lmt - configure aggregator BW shared limit
3408 * @pi: port information structure
3409 * @agg_id: aggregator ID
3410 * @bw: bandwidth in Kbps
3412 * This function configures the shared rate limiter(SRL) of all aggregator type
3413 * nodes across all traffic classes for aggregator matching agg_id.
3416 ice_cfg_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw)
3418 return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, bw);
3422 * ice_cfg_agg_bw_no_shared_lmt - configure aggregator BW for no shared limiter
3423 * @pi: port information structure
3424 * @agg_id: aggregator ID
3426 * This function removes the shared rate limiter(SRL) of all aggregator type
3427 * nodes across all traffic classes for aggregator matching agg_id.
3430 ice_cfg_agg_bw_no_shared_lmt(struct ice_port_info *pi, u32 agg_id)
3432 return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, ICE_SCHED_DFLT_BW);
3436 * ice_config_vsi_queue_priority - config VSI queue priority of node
3437 * @pi: port information structure
3438 * @num_qs: number of VSI queues
3439 * @q_ids: queue IDs array
3440 * @q_ids: queue IDs array
3441 * @q_prio: queue priority array
3443 * This function configures the queue node priority (Sibling Priority) of the
3444 * passed in VSI's queue(s) for a given traffic class (TC).
3447 ice_cfg_vsi_q_priority(struct ice_port_info *pi, u16 num_qs, u32 *q_ids,
3450 enum ice_status status = ICE_ERR_PARAM;
3453 ice_acquire_lock(&pi->sched_lock);
3455 for (i = 0; i < num_qs; i++) {
3456 struct ice_sched_node *node;
3458 node = ice_sched_find_node_by_teid(pi->root, q_ids[i]);
3459 if (!node || node->info.data.elem_type !=
3460 ICE_AQC_ELEM_TYPE_LEAF) {
3461 status = ICE_ERR_PARAM;
3464 /* Configure Priority */
3465 status = ice_sched_cfg_sibl_node_prio(pi, node, q_prio[i]);
3470 ice_release_lock(&pi->sched_lock);
3475 * ice_cfg_agg_vsi_priority_per_tc - config aggregator's VSI priority per TC
3476 * @pi: port information structure
3477 * @agg_id: Aggregator ID
3478 * @num_vsis: number of VSI(s)
3479 * @vsi_handle_arr: array of software VSI handles
3480 * @node_prio: pointer to node priority
3481 * @tc: traffic class
3483 * This function configures the node priority (Sibling Priority) of the
3484 * passed in VSI's for a given traffic class (TC) of an Aggregator ID.
3487 ice_cfg_agg_vsi_priority_per_tc(struct ice_port_info *pi, u32 agg_id,
3488 u16 num_vsis, u16 *vsi_handle_arr,
3489 u8 *node_prio, u8 tc)
3491 struct ice_sched_agg_vsi_info *agg_vsi_info;
3492 struct ice_sched_node *tc_node, *agg_node;
3493 enum ice_status status = ICE_ERR_PARAM;
3494 struct ice_sched_agg_info *agg_info;
3495 bool agg_id_present = false;
3496 struct ice_hw *hw = pi->hw;
3499 ice_acquire_lock(&pi->sched_lock);
3500 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
3502 if (agg_info->agg_id == agg_id) {
3503 agg_id_present = true;
3506 if (!agg_id_present)
3507 goto exit_agg_priority_per_tc;
3509 tc_node = ice_sched_get_tc_node(pi, tc);
3511 goto exit_agg_priority_per_tc;
3513 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
3515 goto exit_agg_priority_per_tc;
3517 if (num_vsis > hw->max_children[agg_node->tx_sched_layer])
3518 goto exit_agg_priority_per_tc;
3520 for (i = 0; i < num_vsis; i++) {
3521 struct ice_sched_node *vsi_node;
3522 bool vsi_handle_valid = false;
3525 status = ICE_ERR_PARAM;
3526 vsi_handle = vsi_handle_arr[i];
3527 if (!ice_is_vsi_valid(hw, vsi_handle))
3528 goto exit_agg_priority_per_tc;
3529 /* Verify child nodes before applying settings */
3530 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
3531 ice_sched_agg_vsi_info, list_entry)
3532 if (agg_vsi_info->vsi_handle == vsi_handle) {
3533 /* cppcheck-suppress unreadVariable */
3534 vsi_handle_valid = true;
3538 if (!vsi_handle_valid)
3539 goto exit_agg_priority_per_tc;
3541 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
3543 goto exit_agg_priority_per_tc;
3545 if (ice_sched_find_node_in_subtree(hw, agg_node, vsi_node)) {
3546 /* Configure Priority */
3547 status = ice_sched_cfg_sibl_node_prio(pi, vsi_node,
3551 status = ice_sched_save_vsi_prio(pi, vsi_handle, tc,
3558 exit_agg_priority_per_tc:
3559 ice_release_lock(&pi->sched_lock);
3564 * ice_cfg_vsi_bw_alloc - config VSI BW alloc per TC
3565 * @pi: port information structure
3566 * @vsi_handle: software VSI handle
3567 * @ena_tcmap: enabled TC map
3568 * @rl_type: Rate limit type CIR/EIR
3569 * @bw_alloc: Array of BW alloc
3571 * This function configures the BW allocation of the passed in VSI's
3572 * node(s) for enabled traffic class.
3575 ice_cfg_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 ena_tcmap,
3576 enum ice_rl_type rl_type, u8 *bw_alloc)
3578 enum ice_status status = ICE_SUCCESS;
3581 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3582 return ICE_ERR_PARAM;
3584 ice_acquire_lock(&pi->sched_lock);
3586 /* Return success if no nodes are present across TC */
3587 ice_for_each_traffic_class(tc) {
3588 struct ice_sched_node *tc_node, *vsi_node;
3590 if (!ice_is_tc_ena(ena_tcmap, tc))
3593 tc_node = ice_sched_get_tc_node(pi, tc);
3597 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
3601 status = ice_sched_cfg_node_bw_alloc(pi->hw, vsi_node, rl_type,
3605 status = ice_sched_save_vsi_bw_alloc(pi, vsi_handle, tc,
3606 rl_type, bw_alloc[tc]);
3611 ice_release_lock(&pi->sched_lock);
3616 * ice_cfg_agg_bw_alloc - config aggregator BW alloc
3617 * @pi: port information structure
3618 * @agg_id: aggregator ID
3619 * @ena_tcmap: enabled TC map
3620 * @rl_type: rate limit type CIR/EIR
3621 * @bw_alloc: array of BW alloc
3623 * This function configures the BW allocation of passed in aggregator for
3624 * enabled traffic class(s).
3627 ice_cfg_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 ena_tcmap,
3628 enum ice_rl_type rl_type, u8 *bw_alloc)
3630 struct ice_sched_agg_info *agg_info;
3631 bool agg_id_present = false;
3632 enum ice_status status = ICE_SUCCESS;
3633 struct ice_hw *hw = pi->hw;
3636 ice_acquire_lock(&pi->sched_lock);
3637 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
3639 if (agg_info->agg_id == agg_id) {
3640 agg_id_present = true;
3643 if (!agg_id_present) {
3644 status = ICE_ERR_PARAM;
3645 goto exit_cfg_agg_bw_alloc;
3648 /* Return success if no nodes are present across TC */
3649 ice_for_each_traffic_class(tc) {
3650 struct ice_sched_node *tc_node, *agg_node;
3652 if (!ice_is_tc_ena(ena_tcmap, tc))
3655 tc_node = ice_sched_get_tc_node(pi, tc);
3659 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
3663 status = ice_sched_cfg_node_bw_alloc(hw, agg_node, rl_type,
3667 status = ice_sched_save_agg_bw_alloc(pi, agg_id, tc, rl_type,
3673 exit_cfg_agg_bw_alloc:
3674 ice_release_lock(&pi->sched_lock);
3679 * ice_sched_calc_wakeup - calculate RL profile wakeup parameter
3680 * @bw: bandwidth in Kbps
3682 * This function calculates the wakeup parameter of RL profile.
3684 static u16 ice_sched_calc_wakeup(s32 bw)
3686 s64 bytes_per_sec, wakeup_int, wakeup_a, wakeup_b, wakeup_f;
3690 /* Get the wakeup integer value */
3691 bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE);
3692 wakeup_int = DIV_64BIT(ICE_RL_PROF_FREQUENCY, bytes_per_sec);
3693 if (wakeup_int > 63) {
3694 wakeup = (u16)((1 << 15) | wakeup_int);
3696 /* Calculate fraction value up to 4 decimals
3697 * Convert Integer value to a constant multiplier
3699 wakeup_b = (s64)ICE_RL_PROF_MULTIPLIER * wakeup_int;
3700 wakeup_a = DIV_64BIT((s64)ICE_RL_PROF_MULTIPLIER *
3701 ICE_RL_PROF_FREQUENCY, bytes_per_sec);
3703 /* Get Fraction value */
3704 wakeup_f = wakeup_a - wakeup_b;
3706 /* Round up the Fractional value via Ceil(Fractional value) */
3707 if (wakeup_f > DIV_64BIT(ICE_RL_PROF_MULTIPLIER, 2))
3710 wakeup_f_int = (s32)DIV_64BIT(wakeup_f * ICE_RL_PROF_FRACTION,
3711 ICE_RL_PROF_MULTIPLIER);
3712 wakeup |= (u16)(wakeup_int << 9);
3713 wakeup |= (u16)(0x1ff & wakeup_f_int);
3720 * ice_sched_bw_to_rl_profile - convert BW to profile parameters
3721 * @bw: bandwidth in Kbps
3722 * @profile: profile parameters to return
3724 * This function converts the BW to profile structure format.
3726 static enum ice_status
3727 ice_sched_bw_to_rl_profile(u32 bw, struct ice_aqc_rl_profile_elem *profile)
3729 enum ice_status status = ICE_ERR_PARAM;
3730 s64 bytes_per_sec, ts_rate, mv_tmp;
3736 /* Bw settings range is from 0.5Mb/sec to 100Gb/sec */
3737 if (bw < ICE_SCHED_MIN_BW || bw > ICE_SCHED_MAX_BW)
3740 /* Bytes per second from Kbps */
3741 bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE);
3743 /* encode is 6 bits but really useful are 5 bits */
3744 for (i = 0; i < 64; i++) {
3745 u64 pow_result = BIT_ULL(i);
3747 ts_rate = DIV_64BIT((s64)ICE_RL_PROF_FREQUENCY,
3748 pow_result * ICE_RL_PROF_TS_MULTIPLIER);
3752 /* Multiplier value */
3753 mv_tmp = DIV_64BIT(bytes_per_sec * ICE_RL_PROF_MULTIPLIER,
3756 /* Round to the nearest ICE_RL_PROF_MULTIPLIER */
3757 mv = round_up_64bit(mv_tmp, ICE_RL_PROF_MULTIPLIER);
3759 /* First multiplier value greater than the given
3762 if (mv > ICE_RL_PROF_ACCURACY_BYTES) {
3771 wm = ice_sched_calc_wakeup(bw);
3772 profile->rl_multiply = CPU_TO_LE16(mv);
3773 profile->wake_up_calc = CPU_TO_LE16(wm);
3774 profile->rl_encode = CPU_TO_LE16(encode);
3775 status = ICE_SUCCESS;
3777 status = ICE_ERR_DOES_NOT_EXIST;
3784 * ice_sched_add_rl_profile - add RL profile
3785 * @pi: port information structure
3786 * @rl_type: type of rate limit BW - min, max, or shared
3787 * @bw: bandwidth in Kbps - Kilo bits per sec
3788 * @layer_num: specifies in which layer to create profile
3790 * This function first checks the existing list for corresponding BW
3791 * parameter. If it exists, it returns the associated profile otherwise
3792 * it creates a new rate limit profile for requested BW, and adds it to
3793 * the HW DB and local list. It returns the new profile or null on error.
3794 * The caller needs to hold the scheduler lock.
3796 static struct ice_aqc_rl_profile_info *
3797 ice_sched_add_rl_profile(struct ice_port_info *pi,
3798 enum ice_rl_type rl_type, u32 bw, u8 layer_num)
3800 struct ice_aqc_rl_profile_generic_elem *buf;
3801 struct ice_aqc_rl_profile_info *rl_prof_elem;
3802 u16 profiles_added = 0, num_profiles = 1;
3803 enum ice_status status = ICE_ERR_PARAM;
3809 profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR;
3812 profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR;
3815 profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL;
3824 LIST_FOR_EACH_ENTRY(rl_prof_elem, &pi->rl_prof_list[layer_num],
3825 ice_aqc_rl_profile_info, list_entry)
3826 if (rl_prof_elem->profile.flags == profile_type &&
3827 rl_prof_elem->bw == bw)
3828 /* Return existing profile ID info */
3829 return rl_prof_elem;
3831 /* Create new profile ID */
3832 rl_prof_elem = (struct ice_aqc_rl_profile_info *)
3833 ice_malloc(hw, sizeof(*rl_prof_elem));
3838 status = ice_sched_bw_to_rl_profile(bw, &rl_prof_elem->profile);
3839 if (status != ICE_SUCCESS)
3840 goto exit_add_rl_prof;
3842 rl_prof_elem->bw = bw;
3843 /* layer_num is zero relative, and fw expects level from 1 to 9 */
3844 rl_prof_elem->profile.level = layer_num + 1;
3845 rl_prof_elem->profile.flags = profile_type;
3846 rl_prof_elem->profile.max_burst_size = CPU_TO_LE16(hw->max_burst_size);
3848 /* Create new entry in HW DB */
3849 buf = (struct ice_aqc_rl_profile_generic_elem *)
3850 &rl_prof_elem->profile;
3851 status = ice_aq_add_rl_profile(hw, num_profiles, buf, sizeof(*buf),
3852 &profiles_added, NULL);
3853 if (status || profiles_added != num_profiles)
3854 goto exit_add_rl_prof;
3856 /* Good entry - add in the list */
3857 rl_prof_elem->prof_id_ref = 0;
3858 LIST_ADD(&rl_prof_elem->list_entry, &pi->rl_prof_list[layer_num]);
3859 return rl_prof_elem;
3862 ice_free(hw, rl_prof_elem);
3867 * ice_sched_cfg_node_bw_lmt - configure node sched params
3868 * @hw: pointer to the HW struct
3869 * @node: sched node to configure
3870 * @rl_type: rate limit type CIR, EIR, or shared
3871 * @rl_prof_id: rate limit profile ID
3873 * This function configures node element's BW limit.
3875 static enum ice_status
3876 ice_sched_cfg_node_bw_lmt(struct ice_hw *hw, struct ice_sched_node *node,
3877 enum ice_rl_type rl_type, u16 rl_prof_id)
3879 struct ice_aqc_txsched_elem_data buf;
3880 struct ice_aqc_txsched_elem *data;
3886 data->valid_sections |= ICE_AQC_ELEM_VALID_CIR;
3887 data->cir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id);
3890 /* EIR BW and Shared BW profiles are mutually exclusive and
3891 * hence only one of them may be set for any given element
3893 if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED)
3895 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
3896 data->eir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id);
3899 /* Check for removing shared BW */
3900 if (rl_prof_id == ICE_SCHED_NO_SHARED_RL_PROF_ID) {
3901 /* remove shared profile */
3902 data->valid_sections &= ~ICE_AQC_ELEM_VALID_SHARED;
3903 data->srl_id = 0; /* clear SRL field */
3905 /* enable back EIR to default profile */
3906 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
3907 data->eir_bw.bw_profile_idx =
3908 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
3911 /* EIR BW and Shared BW profiles are mutually exclusive and
3912 * hence only one of them may be set for any given element
3914 if ((data->valid_sections & ICE_AQC_ELEM_VALID_EIR) &&
3915 (LE16_TO_CPU(data->eir_bw.bw_profile_idx) !=
3916 ICE_SCHED_DFLT_RL_PROF_ID))
3918 /* EIR BW is set to default, disable it */
3919 data->valid_sections &= ~ICE_AQC_ELEM_VALID_EIR;
3920 /* Okay to enable shared BW now */
3921 data->valid_sections |= ICE_AQC_ELEM_VALID_SHARED;
3922 data->srl_id = CPU_TO_LE16(rl_prof_id);
3925 /* Unknown rate limit type */
3926 return ICE_ERR_PARAM;
3929 /* Configure element */
3930 return ice_sched_update_elem(hw, node, &buf);
3934 * ice_sched_get_node_rl_prof_id - get node's rate limit profile ID
3936 * @rl_type: rate limit type
3938 * If existing profile matches, it returns the corresponding rate
3939 * limit profile ID, otherwise it returns an invalid ID as error.
3942 ice_sched_get_node_rl_prof_id(struct ice_sched_node *node,
3943 enum ice_rl_type rl_type)
3945 u16 rl_prof_id = ICE_SCHED_INVAL_PROF_ID;
3946 struct ice_aqc_txsched_elem *data;
3948 data = &node->info.data;
3951 if (data->valid_sections & ICE_AQC_ELEM_VALID_CIR)
3952 rl_prof_id = LE16_TO_CPU(data->cir_bw.bw_profile_idx);
3955 if (data->valid_sections & ICE_AQC_ELEM_VALID_EIR)
3956 rl_prof_id = LE16_TO_CPU(data->eir_bw.bw_profile_idx);
3959 if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED)
3960 rl_prof_id = LE16_TO_CPU(data->srl_id);
3970 * ice_sched_get_rl_prof_layer - selects rate limit profile creation layer
3971 * @pi: port information structure
3972 * @rl_type: type of rate limit BW - min, max, or shared
3973 * @layer_index: layer index
3975 * This function returns requested profile creation layer.
3978 ice_sched_get_rl_prof_layer(struct ice_port_info *pi, enum ice_rl_type rl_type,
3981 struct ice_hw *hw = pi->hw;
3983 if (layer_index >= hw->num_tx_sched_layers)
3984 return ICE_SCHED_INVAL_LAYER_NUM;
3987 if (hw->layer_info[layer_index].max_cir_rl_profiles)
3991 if (hw->layer_info[layer_index].max_eir_rl_profiles)
3995 /* if current layer doesn't support SRL profile creation
3996 * then try a layer up or down.
3998 if (hw->layer_info[layer_index].max_srl_profiles)
4000 else if (layer_index < hw->num_tx_sched_layers - 1 &&
4001 hw->layer_info[layer_index + 1].max_srl_profiles)
4002 return layer_index + 1;
4003 else if (layer_index > 0 &&
4004 hw->layer_info[layer_index - 1].max_srl_profiles)
4005 return layer_index - 1;
4010 return ICE_SCHED_INVAL_LAYER_NUM;
4014 * ice_sched_get_srl_node - get shared rate limit node
4016 * @srl_layer: shared rate limit layer
4018 * This function returns SRL node to be used for shared rate limit purpose.
4019 * The caller needs to hold scheduler lock.
4021 static struct ice_sched_node *
4022 ice_sched_get_srl_node(struct ice_sched_node *node, u8 srl_layer)
4024 if (srl_layer > node->tx_sched_layer)
4025 return node->children[0];
4026 else if (srl_layer < node->tx_sched_layer)
4027 /* Node can't be created without a parent. It will always
4028 * have a valid parent except root node.
4030 return node->parent;
4036 * ice_sched_rm_rl_profile - remove RL profile ID
4037 * @pi: port information structure
4038 * @layer_num: layer number where profiles are saved
4039 * @profile_type: profile type like EIR, CIR, or SRL
4040 * @profile_id: profile ID to remove
4042 * This function removes rate limit profile from layer 'layer_num' of type
4043 * 'profile_type' and profile ID as 'profile_id'. The caller needs to hold
4046 static enum ice_status
4047 ice_sched_rm_rl_profile(struct ice_port_info *pi, u8 layer_num, u8 profile_type,
4050 struct ice_aqc_rl_profile_info *rl_prof_elem;
4051 enum ice_status status = ICE_SUCCESS;
4053 /* Check the existing list for RL profile */
4054 LIST_FOR_EACH_ENTRY(rl_prof_elem, &pi->rl_prof_list[layer_num],
4055 ice_aqc_rl_profile_info, list_entry)
4056 if (rl_prof_elem->profile.flags == profile_type &&
4057 LE16_TO_CPU(rl_prof_elem->profile.profile_id) ==
4059 if (rl_prof_elem->prof_id_ref)
4060 rl_prof_elem->prof_id_ref--;
4062 /* Remove old profile ID from database */
4063 status = ice_sched_del_rl_profile(pi->hw, rl_prof_elem);
4064 if (status && status != ICE_ERR_IN_USE)
4065 ice_debug(pi->hw, ICE_DBG_SCHED,
4066 "Remove rl profile failed\n");
4069 if (status == ICE_ERR_IN_USE)
4070 status = ICE_SUCCESS;
4075 * ice_sched_set_node_bw_dflt - set node's bandwidth limit to default
4076 * @pi: port information structure
4077 * @node: pointer to node structure
4078 * @rl_type: rate limit type min, max, or shared
4079 * @layer_num: layer number where RL profiles are saved
4081 * This function configures node element's BW rate limit profile ID of
4082 * type CIR, EIR, or SRL to default. This function needs to be called
4083 * with the scheduler lock held.
4085 static enum ice_status
4086 ice_sched_set_node_bw_dflt(struct ice_port_info *pi,
4087 struct ice_sched_node *node,
4088 enum ice_rl_type rl_type, u8 layer_num)
4090 enum ice_status status;
4099 profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR;
4100 rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID;
4103 profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR;
4104 rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID;
4107 profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL;
4108 /* No SRL is configured for default case */
4109 rl_prof_id = ICE_SCHED_NO_SHARED_RL_PROF_ID;
4112 return ICE_ERR_PARAM;
4114 /* Save existing RL prof ID for later clean up */
4115 old_id = ice_sched_get_node_rl_prof_id(node, rl_type);
4116 /* Configure BW scheduling parameters */
4117 status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id);
4121 /* Remove stale RL profile ID */
4122 if (old_id == ICE_SCHED_DFLT_RL_PROF_ID ||
4123 old_id == ICE_SCHED_INVAL_PROF_ID)
4126 return ice_sched_rm_rl_profile(pi, layer_num, profile_type, old_id);
4130 * ice_sched_set_eir_srl_excl - set EIR/SRL exclusiveness
4131 * @pi: port information structure
4132 * @node: pointer to node structure
4133 * @layer_num: layer number where rate limit profiles are saved
4134 * @rl_type: rate limit type min, max, or shared
4135 * @bw: bandwidth value
4137 * This function prepares node element's bandwidth to SRL or EIR exclusively.
4138 * EIR BW and Shared BW profiles are mutually exclusive and hence only one of
4139 * them may be set for any given element. This function needs to be called
4140 * with the scheduler lock held.
4142 static enum ice_status
4143 ice_sched_set_eir_srl_excl(struct ice_port_info *pi,
4144 struct ice_sched_node *node,
4145 u8 layer_num, enum ice_rl_type rl_type, u32 bw)
4147 if (rl_type == ICE_SHARED_BW) {
4148 /* SRL node passed in this case, it may be different node */
4149 if (bw == ICE_SCHED_DFLT_BW)
4150 /* SRL being removed, ice_sched_cfg_node_bw_lmt()
4151 * enables EIR to default. EIR is not set in this
4152 * case, so no additional action is required.
4156 /* SRL being configured, set EIR to default here.
4157 * ice_sched_cfg_node_bw_lmt() disables EIR when it
4160 return ice_sched_set_node_bw_dflt(pi, node, ICE_MAX_BW,
4162 } else if (rl_type == ICE_MAX_BW &&
4163 node->info.data.valid_sections & ICE_AQC_ELEM_VALID_SHARED) {
4164 /* Remove Shared profile. Set default shared BW call
4165 * removes shared profile for a node.
4167 return ice_sched_set_node_bw_dflt(pi, node,
4175 * ice_sched_set_node_bw - set node's bandwidth
4176 * @pi: port information structure
4178 * @rl_type: rate limit type min, max, or shared
4179 * @bw: bandwidth in Kbps - Kilo bits per sec
4180 * @layer_num: layer number
4182 * This function adds new profile corresponding to requested BW, configures
4183 * node's RL profile ID of type CIR, EIR, or SRL, and removes old profile
4184 * ID from local database. The caller needs to hold scheduler lock.
4186 static enum ice_status
4187 ice_sched_set_node_bw(struct ice_port_info *pi, struct ice_sched_node *node,
4188 enum ice_rl_type rl_type, u32 bw, u8 layer_num)
4190 struct ice_aqc_rl_profile_info *rl_prof_info;
4191 enum ice_status status = ICE_ERR_PARAM;
4192 struct ice_hw *hw = pi->hw;
4193 u16 old_id, rl_prof_id;
4195 rl_prof_info = ice_sched_add_rl_profile(pi, rl_type, bw, layer_num);
4199 rl_prof_id = LE16_TO_CPU(rl_prof_info->profile.profile_id);
4201 /* Save existing RL prof ID for later clean up */
4202 old_id = ice_sched_get_node_rl_prof_id(node, rl_type);
4203 /* Configure BW scheduling parameters */
4204 status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id);
4208 /* New changes has been applied */
4209 /* Increment the profile ID reference count */
4210 rl_prof_info->prof_id_ref++;
4212 /* Check for old ID removal */
4213 if ((old_id == ICE_SCHED_DFLT_RL_PROF_ID && rl_type != ICE_SHARED_BW) ||
4214 old_id == ICE_SCHED_INVAL_PROF_ID || old_id == rl_prof_id)
4217 return ice_sched_rm_rl_profile(pi, layer_num,
4218 rl_prof_info->profile.flags,
4223 * ice_sched_set_node_bw_lmt - set node's BW limit
4224 * @pi: port information structure
4226 * @rl_type: rate limit type min, max, or shared
4227 * @bw: bandwidth in Kbps - Kilo bits per sec
4229 * It updates node's BW limit parameters like BW RL profile ID of type CIR,
4230 * EIR, or SRL. The caller needs to hold scheduler lock.
4232 static enum ice_status
4233 ice_sched_set_node_bw_lmt(struct ice_port_info *pi, struct ice_sched_node *node,
4234 enum ice_rl_type rl_type, u32 bw)
4236 struct ice_sched_node *cfg_node = node;
4237 enum ice_status status;
4243 return ICE_ERR_PARAM;
4245 /* Remove unused RL profile IDs from HW and SW DB */
4246 ice_sched_rm_unused_rl_prof(pi);
4247 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
4248 node->tx_sched_layer);
4249 if (layer_num >= hw->num_tx_sched_layers)
4250 return ICE_ERR_PARAM;
4252 if (rl_type == ICE_SHARED_BW) {
4253 /* SRL node may be different */
4254 cfg_node = ice_sched_get_srl_node(node, layer_num);
4258 /* EIR BW and Shared BW profiles are mutually exclusive and
4259 * hence only one of them may be set for any given element
4261 status = ice_sched_set_eir_srl_excl(pi, cfg_node, layer_num, rl_type,
4265 if (bw == ICE_SCHED_DFLT_BW)
4266 return ice_sched_set_node_bw_dflt(pi, cfg_node, rl_type,
4268 return ice_sched_set_node_bw(pi, cfg_node, rl_type, bw, layer_num);
4272 * ice_sched_set_node_bw_dflt_lmt - set node's BW limit to default
4273 * @pi: port information structure
4274 * @node: pointer to node structure
4275 * @rl_type: rate limit type min, max, or shared
4277 * This function configures node element's BW rate limit profile ID of
4278 * type CIR, EIR, or SRL to default. This function needs to be called
4279 * with the scheduler lock held.
4281 static enum ice_status
4282 ice_sched_set_node_bw_dflt_lmt(struct ice_port_info *pi,
4283 struct ice_sched_node *node,
4284 enum ice_rl_type rl_type)
4286 return ice_sched_set_node_bw_lmt(pi, node, rl_type,
4291 * ice_sched_validate_srl_node - Check node for SRL applicability
4292 * @node: sched node to configure
4293 * @sel_layer: selected SRL layer
4295 * This function checks if the SRL can be applied to a selceted layer node on
4296 * behalf of the requested node (first argument). This function needs to be
4297 * called with scheduler lock held.
4299 static enum ice_status
4300 ice_sched_validate_srl_node(struct ice_sched_node *node, u8 sel_layer)
4302 /* SRL profiles are not available on all layers. Check if the
4303 * SRL profile can be applied to a node above or below the
4304 * requested node. SRL configuration is possible only if the
4305 * selected layer's node has single child.
4307 if (sel_layer == node->tx_sched_layer ||
4308 ((sel_layer == node->tx_sched_layer + 1) &&
4309 node->num_children == 1) ||
4310 ((sel_layer == node->tx_sched_layer - 1) &&
4311 (node->parent && node->parent->num_children == 1)))
4318 * ice_sched_save_q_bw - save queue node's BW information
4319 * @q_ctx: queue context structure
4320 * @rl_type: rate limit type min, max, or shared
4321 * @bw: bandwidth in Kbps - Kilo bits per sec
4323 * Save BW information of queue type node for post replay use.
4325 static enum ice_status
4326 ice_sched_save_q_bw(struct ice_q_ctx *q_ctx, enum ice_rl_type rl_type, u32 bw)
4330 ice_set_clear_cir_bw(&q_ctx->bw_t_info, bw);
4333 ice_set_clear_eir_bw(&q_ctx->bw_t_info, bw);
4336 ice_set_clear_shared_bw(&q_ctx->bw_t_info, bw);
4339 return ICE_ERR_PARAM;
4345 * ice_sched_set_q_bw_lmt - sets queue BW limit
4346 * @pi: port information structure
4347 * @vsi_handle: sw VSI handle
4348 * @tc: traffic class
4349 * @q_handle: software queue handle
4350 * @rl_type: min, max, or shared
4351 * @bw: bandwidth in Kbps
4353 * This function sets BW limit of queue scheduling node.
4355 static enum ice_status
4356 ice_sched_set_q_bw_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4357 u16 q_handle, enum ice_rl_type rl_type, u32 bw)
4359 enum ice_status status = ICE_ERR_PARAM;
4360 struct ice_sched_node *node;
4361 struct ice_q_ctx *q_ctx;
4363 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4364 return ICE_ERR_PARAM;
4365 ice_acquire_lock(&pi->sched_lock);
4366 q_ctx = ice_get_lan_q_ctx(pi->hw, vsi_handle, tc, q_handle);
4369 node = ice_sched_find_node_by_teid(pi->root, q_ctx->q_teid);
4371 ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong q_teid\n");
4375 /* Return error if it is not a leaf node */
4376 if (node->info.data.elem_type != ICE_AQC_ELEM_TYPE_LEAF)
4379 /* SRL bandwidth layer selection */
4380 if (rl_type == ICE_SHARED_BW) {
4381 u8 sel_layer; /* selected layer */
4383 sel_layer = ice_sched_get_rl_prof_layer(pi, rl_type,
4384 node->tx_sched_layer);
4385 if (sel_layer >= pi->hw->num_tx_sched_layers) {
4386 status = ICE_ERR_PARAM;
4389 status = ice_sched_validate_srl_node(node, sel_layer);
4394 if (bw == ICE_SCHED_DFLT_BW)
4395 status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type);
4397 status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw);
4400 status = ice_sched_save_q_bw(q_ctx, rl_type, bw);
4403 ice_release_lock(&pi->sched_lock);
4408 * ice_cfg_q_bw_lmt - configure queue BW limit
4409 * @pi: port information structure
4410 * @vsi_handle: sw VSI handle
4411 * @tc: traffic class
4412 * @q_handle: software queue handle
4413 * @rl_type: min, max, or shared
4414 * @bw: bandwidth in Kbps
4416 * This function configures BW limit of queue scheduling node.
4419 ice_cfg_q_bw_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4420 u16 q_handle, enum ice_rl_type rl_type, u32 bw)
4422 return ice_sched_set_q_bw_lmt(pi, vsi_handle, tc, q_handle, rl_type,
4427 * ice_cfg_q_bw_dflt_lmt - configure queue BW default limit
4428 * @pi: port information structure
4429 * @vsi_handle: sw VSI handle
4430 * @tc: traffic class
4431 * @q_handle: software queue handle
4432 * @rl_type: min, max, or shared
4434 * This function configures BW default limit of queue scheduling node.
4437 ice_cfg_q_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4438 u16 q_handle, enum ice_rl_type rl_type)
4440 return ice_sched_set_q_bw_lmt(pi, vsi_handle, tc, q_handle, rl_type,
4445 * ice_sched_save_tc_node_bw - save TC node BW limit
4446 * @pi: port information structure
4448 * @rl_type: min or max
4449 * @bw: bandwidth in Kbps
4451 * This function saves the modified values of bandwidth settings for later
4452 * replay purpose (restore) after reset.
4454 static enum ice_status
4455 ice_sched_save_tc_node_bw(struct ice_port_info *pi, u8 tc,
4456 enum ice_rl_type rl_type, u32 bw)
4458 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4459 return ICE_ERR_PARAM;
4462 ice_set_clear_cir_bw(&pi->tc_node_bw_t_info[tc], bw);
4465 ice_set_clear_eir_bw(&pi->tc_node_bw_t_info[tc], bw);
4468 ice_set_clear_shared_bw(&pi->tc_node_bw_t_info[tc], bw);
4471 return ICE_ERR_PARAM;
4477 * ice_sched_set_tc_node_bw_lmt - sets TC node BW limit
4478 * @pi: port information structure
4480 * @rl_type: min or max
4481 * @bw: bandwidth in Kbps
4483 * This function configures bandwidth limit of TC node.
4485 static enum ice_status
4486 ice_sched_set_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc,
4487 enum ice_rl_type rl_type, u32 bw)
4489 enum ice_status status = ICE_ERR_PARAM;
4490 struct ice_sched_node *tc_node;
4492 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4494 ice_acquire_lock(&pi->sched_lock);
4495 tc_node = ice_sched_get_tc_node(pi, tc);
4497 goto exit_set_tc_node_bw;
4498 if (bw == ICE_SCHED_DFLT_BW)
4499 status = ice_sched_set_node_bw_dflt_lmt(pi, tc_node, rl_type);
4501 status = ice_sched_set_node_bw_lmt(pi, tc_node, rl_type, bw);
4503 status = ice_sched_save_tc_node_bw(pi, tc, rl_type, bw);
4505 exit_set_tc_node_bw:
4506 ice_release_lock(&pi->sched_lock);
4511 * ice_cfg_tc_node_bw_lmt - configure TC node BW limit
4512 * @pi: port information structure
4514 * @rl_type: min or max
4515 * @bw: bandwidth in Kbps
4517 * This function configures BW limit of TC node.
4518 * Note: The minimum guaranteed reservation is done via DCBX.
4521 ice_cfg_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc,
4522 enum ice_rl_type rl_type, u32 bw)
4524 return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, bw);
4528 * ice_cfg_tc_node_bw_dflt_lmt - configure TC node BW default limit
4529 * @pi: port information structure
4531 * @rl_type: min or max
4533 * This function configures BW default limit of TC node.
4536 ice_cfg_tc_node_bw_dflt_lmt(struct ice_port_info *pi, u8 tc,
4537 enum ice_rl_type rl_type)
4539 return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, ICE_SCHED_DFLT_BW);
4543 * ice_sched_save_tc_node_bw_alloc - save TC node's BW alloc information
4544 * @pi: port information structure
4545 * @tc: traffic class
4546 * @rl_type: rate limit type min or max
4547 * @bw_alloc: Bandwidth allocation information
4549 * Save BW alloc information of VSI type node for post replay use.
4551 static enum ice_status
4552 ice_sched_save_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4553 enum ice_rl_type rl_type, u16 bw_alloc)
4555 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4556 return ICE_ERR_PARAM;
4559 ice_set_clear_cir_bw_alloc(&pi->tc_node_bw_t_info[tc],
4563 ice_set_clear_eir_bw_alloc(&pi->tc_node_bw_t_info[tc],
4567 return ICE_ERR_PARAM;
4573 * ice_sched_set_tc_node_bw_alloc - set TC node BW alloc
4574 * @pi: port information structure
4576 * @rl_type: min or max
4577 * @bw_alloc: bandwidth alloc
4579 * This function configures bandwidth alloc of TC node, also saves the
4580 * changed settings for replay purpose, and return success if it succeeds
4581 * in modifying bandwidth alloc setting.
4583 static enum ice_status
4584 ice_sched_set_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4585 enum ice_rl_type rl_type, u8 bw_alloc)
4587 enum ice_status status = ICE_ERR_PARAM;
4588 struct ice_sched_node *tc_node;
4590 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4592 ice_acquire_lock(&pi->sched_lock);
4593 tc_node = ice_sched_get_tc_node(pi, tc);
4595 goto exit_set_tc_node_bw_alloc;
4596 status = ice_sched_cfg_node_bw_alloc(pi->hw, tc_node, rl_type,
4599 goto exit_set_tc_node_bw_alloc;
4600 status = ice_sched_save_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc);
4602 exit_set_tc_node_bw_alloc:
4603 ice_release_lock(&pi->sched_lock);
4608 * ice_cfg_tc_node_bw_alloc - configure TC node BW alloc
4609 * @pi: port information structure
4611 * @rl_type: min or max
4612 * @bw_alloc: bandwidth alloc
4614 * This function configures BW limit of TC node.
4615 * Note: The minimum guaranteed reservation is done via DCBX.
4618 ice_cfg_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4619 enum ice_rl_type rl_type, u8 bw_alloc)
4621 return ice_sched_set_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc);
4625 * ice_sched_set_agg_bw_dflt_lmt - set aggregator node's BW limit to default
4626 * @pi: port information structure
4627 * @vsi_handle: software VSI handle
4629 * This function retrieves the aggregator ID based on VSI ID and TC,
4630 * and sets node's BW limit to default. This function needs to be
4631 * called with the scheduler lock held.
4634 ice_sched_set_agg_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle)
4636 struct ice_vsi_ctx *vsi_ctx;
4637 enum ice_status status = ICE_SUCCESS;
4640 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4641 return ICE_ERR_PARAM;
4642 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
4644 return ICE_ERR_PARAM;
4646 ice_for_each_traffic_class(tc) {
4647 struct ice_sched_node *node;
4649 node = vsi_ctx->sched.ag_node[tc];
4653 /* Set min profile to default */
4654 status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MIN_BW);
4658 /* Set max profile to default */
4659 status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MAX_BW);
4663 /* Remove shared profile, if there is one */
4664 status = ice_sched_set_node_bw_dflt_lmt(pi, node,
4674 * ice_sched_get_node_by_id_type - get node from ID type
4675 * @pi: port information structure
4677 * @agg_type: type of aggregator
4678 * @tc: traffic class
4680 * This function returns node identified by ID of type aggregator, and
4681 * based on traffic class (TC). This function needs to be called with
4682 * the scheduler lock held.
4684 static struct ice_sched_node *
4685 ice_sched_get_node_by_id_type(struct ice_port_info *pi, u32 id,
4686 enum ice_agg_type agg_type, u8 tc)
4688 struct ice_sched_node *node = NULL;
4689 struct ice_sched_node *child_node;
4692 case ICE_AGG_TYPE_VSI: {
4693 struct ice_vsi_ctx *vsi_ctx;
4694 u16 vsi_handle = (u16)id;
4696 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4698 /* Get sched_vsi_info */
4699 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
4702 node = vsi_ctx->sched.vsi_node[tc];
4706 case ICE_AGG_TYPE_AGG: {
4707 struct ice_sched_node *tc_node;
4709 tc_node = ice_sched_get_tc_node(pi, tc);
4711 node = ice_sched_get_agg_node(pi, tc_node, id);
4715 case ICE_AGG_TYPE_Q:
4716 /* The current implementation allows single queue to modify */
4717 node = ice_sched_get_node(pi, id);
4720 case ICE_AGG_TYPE_QG:
4721 /* The current implementation allows single qg to modify */
4722 child_node = ice_sched_get_node(pi, id);
4725 node = child_node->parent;
4736 * ice_sched_set_node_bw_lmt_per_tc - set node BW limit per TC
4737 * @pi: port information structure
4738 * @id: ID (software VSI handle or AGG ID)
4739 * @agg_type: aggregator type (VSI or AGG type node)
4740 * @tc: traffic class
4741 * @rl_type: min or max
4742 * @bw: bandwidth in Kbps
4744 * This function sets BW limit of VSI or Aggregator scheduling node
4745 * based on TC information from passed in argument BW.
4748 ice_sched_set_node_bw_lmt_per_tc(struct ice_port_info *pi, u32 id,
4749 enum ice_agg_type agg_type, u8 tc,
4750 enum ice_rl_type rl_type, u32 bw)
4752 enum ice_status status = ICE_ERR_PARAM;
4753 struct ice_sched_node *node;
4758 if (rl_type == ICE_UNKNOWN_BW)
4761 ice_acquire_lock(&pi->sched_lock);
4762 node = ice_sched_get_node_by_id_type(pi, id, agg_type, tc);
4764 ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong id, agg type, or tc\n");
4765 goto exit_set_node_bw_lmt_per_tc;
4767 if (bw == ICE_SCHED_DFLT_BW)
4768 status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type);
4770 status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw);
4772 exit_set_node_bw_lmt_per_tc:
4773 ice_release_lock(&pi->sched_lock);
4778 * ice_sched_validate_vsi_srl_node - validate VSI SRL node
4779 * @pi: port information structure
4780 * @vsi_handle: software VSI handle
4782 * This function validates SRL node of the VSI node if available SRL layer is
4783 * different than the VSI node layer on all TC(s).This function needs to be
4784 * called with scheduler lock held.
4786 static enum ice_status
4787 ice_sched_validate_vsi_srl_node(struct ice_port_info *pi, u16 vsi_handle)
4789 u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM;
4792 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4793 return ICE_ERR_PARAM;
4795 /* Return success if no nodes are present across TC */
4796 ice_for_each_traffic_class(tc) {
4797 struct ice_sched_node *tc_node, *vsi_node;
4798 enum ice_rl_type rl_type = ICE_SHARED_BW;
4799 enum ice_status status;
4801 tc_node = ice_sched_get_tc_node(pi, tc);
4805 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
4809 /* SRL bandwidth layer selection */
4810 if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) {
4811 u8 node_layer = vsi_node->tx_sched_layer;
4814 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
4816 if (layer_num >= pi->hw->num_tx_sched_layers)
4817 return ICE_ERR_PARAM;
4818 sel_layer = layer_num;
4821 status = ice_sched_validate_srl_node(vsi_node, sel_layer);
4829 * ice_sched_set_vsi_bw_shared_lmt - set VSI BW shared limit
4830 * @pi: port information structure
4831 * @vsi_handle: software VSI handle
4832 * @bw: bandwidth in Kbps
4834 * This function Configures shared rate limiter(SRL) of all VSI type nodes
4835 * across all traffic classes for VSI matching handle. When BW value of
4836 * ICE_SCHED_DFLT_BW is passed, it removes the SRL from the node.
4839 ice_sched_set_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle,
4842 enum ice_status status = ICE_SUCCESS;
4846 return ICE_ERR_PARAM;
4848 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4849 return ICE_ERR_PARAM;
4851 ice_acquire_lock(&pi->sched_lock);
4852 status = ice_sched_validate_vsi_srl_node(pi, vsi_handle);
4854 goto exit_set_vsi_bw_shared_lmt;
4855 /* Return success if no nodes are present across TC */
4856 ice_for_each_traffic_class(tc) {
4857 struct ice_sched_node *tc_node, *vsi_node;
4858 enum ice_rl_type rl_type = ICE_SHARED_BW;
4860 tc_node = ice_sched_get_tc_node(pi, tc);
4864 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
4868 if (bw == ICE_SCHED_DFLT_BW)
4869 /* It removes existing SRL from the node */
4870 status = ice_sched_set_node_bw_dflt_lmt(pi, vsi_node,
4873 status = ice_sched_set_node_bw_lmt(pi, vsi_node,
4877 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw);
4882 exit_set_vsi_bw_shared_lmt:
4883 ice_release_lock(&pi->sched_lock);
4888 * ice_sched_validate_agg_srl_node - validate AGG SRL node
4889 * @pi: port information structure
4890 * @agg_id: aggregator ID
4892 * This function validates SRL node of the AGG node if available SRL layer is
4893 * different than the AGG node layer on all TC(s).This function needs to be
4894 * called with scheduler lock held.
4896 static enum ice_status
4897 ice_sched_validate_agg_srl_node(struct ice_port_info *pi, u32 agg_id)
4899 u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM;
4900 struct ice_sched_agg_info *agg_info;
4901 bool agg_id_present = false;
4902 enum ice_status status = ICE_SUCCESS;
4905 LIST_FOR_EACH_ENTRY(agg_info, &pi->hw->agg_list, ice_sched_agg_info,
4907 if (agg_info->agg_id == agg_id) {
4908 agg_id_present = true;
4911 if (!agg_id_present)
4912 return ICE_ERR_PARAM;
4913 /* Return success if no nodes are present across TC */
4914 ice_for_each_traffic_class(tc) {
4915 struct ice_sched_node *tc_node, *agg_node;
4916 enum ice_rl_type rl_type = ICE_SHARED_BW;
4918 tc_node = ice_sched_get_tc_node(pi, tc);
4922 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
4925 /* SRL bandwidth layer selection */
4926 if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) {
4927 u8 node_layer = agg_node->tx_sched_layer;
4930 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
4932 if (layer_num >= pi->hw->num_tx_sched_layers)
4933 return ICE_ERR_PARAM;
4934 sel_layer = layer_num;
4937 status = ice_sched_validate_srl_node(agg_node, sel_layer);
4945 * ice_sched_set_agg_bw_shared_lmt - set aggregator BW shared limit
4946 * @pi: port information structure
4947 * @agg_id: aggregator ID
4948 * @bw: bandwidth in Kbps
4950 * This function configures the shared rate limiter(SRL) of all aggregator type
4951 * nodes across all traffic classes for aggregator matching agg_id. When
4952 * BW value of ICE_SCHED_DFLT_BW is passed, it removes SRL from the
4956 ice_sched_set_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw)
4958 struct ice_sched_agg_info *agg_info;
4959 struct ice_sched_agg_info *tmp;
4960 bool agg_id_present = false;
4961 enum ice_status status = ICE_SUCCESS;
4965 return ICE_ERR_PARAM;
4967 ice_acquire_lock(&pi->sched_lock);
4968 status = ice_sched_validate_agg_srl_node(pi, agg_id);
4970 goto exit_agg_bw_shared_lmt;
4972 LIST_FOR_EACH_ENTRY_SAFE(agg_info, tmp, &pi->hw->agg_list,
4973 ice_sched_agg_info, list_entry)
4974 if (agg_info->agg_id == agg_id) {
4975 agg_id_present = true;
4979 if (!agg_id_present) {
4980 status = ICE_ERR_PARAM;
4981 goto exit_agg_bw_shared_lmt;
4984 /* Return success if no nodes are present across TC */
4985 ice_for_each_traffic_class(tc) {
4986 enum ice_rl_type rl_type = ICE_SHARED_BW;
4987 struct ice_sched_node *tc_node, *agg_node;
4989 tc_node = ice_sched_get_tc_node(pi, tc);
4993 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
4997 if (bw == ICE_SCHED_DFLT_BW)
4998 /* It removes existing SRL from the node */
4999 status = ice_sched_set_node_bw_dflt_lmt(pi, agg_node,
5002 status = ice_sched_set_node_bw_lmt(pi, agg_node,
5006 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw);
5011 exit_agg_bw_shared_lmt:
5012 ice_release_lock(&pi->sched_lock);
5017 * ice_sched_cfg_sibl_node_prio - configure node sibling priority
5018 * @pi: port information structure
5019 * @node: sched node to configure
5020 * @priority: sibling priority
5022 * This function configures node element's sibling priority only. This
5023 * function needs to be called with scheduler lock held.
5026 ice_sched_cfg_sibl_node_prio(struct ice_port_info *pi,
5027 struct ice_sched_node *node, u8 priority)
5029 struct ice_aqc_txsched_elem_data buf;
5030 struct ice_aqc_txsched_elem *data;
5031 struct ice_hw *hw = pi->hw;
5032 enum ice_status status;
5035 return ICE_ERR_PARAM;
5038 data->valid_sections |= ICE_AQC_ELEM_VALID_GENERIC;
5039 priority = (priority << ICE_AQC_ELEM_GENERIC_PRIO_S) &
5040 ICE_AQC_ELEM_GENERIC_PRIO_M;
5041 data->generic &= ~ICE_AQC_ELEM_GENERIC_PRIO_M;
5042 data->generic |= priority;
5044 /* Configure element */
5045 status = ice_sched_update_elem(hw, node, &buf);
5050 * ice_cfg_rl_burst_size - Set burst size value
5051 * @hw: pointer to the HW struct
5052 * @bytes: burst size in bytes
5054 * This function configures/set the burst size to requested new value. The new
5055 * burst size value is used for future rate limit calls. It doesn't change the
5056 * existing or previously created RL profiles.
5058 enum ice_status ice_cfg_rl_burst_size(struct ice_hw *hw, u32 bytes)
5060 u16 burst_size_to_prog;
5062 if (bytes < ICE_MIN_BURST_SIZE_ALLOWED ||
5063 bytes > ICE_MAX_BURST_SIZE_ALLOWED)
5064 return ICE_ERR_PARAM;
5065 if (ice_round_to_num(bytes, 64) <=
5066 ICE_MAX_BURST_SIZE_64_BYTE_GRANULARITY) {
5067 /* 64 byte granularity case */
5068 /* Disable MSB granularity bit */
5069 burst_size_to_prog = ICE_64_BYTE_GRANULARITY;
5070 /* round number to nearest 64 byte granularity */
5071 bytes = ice_round_to_num(bytes, 64);
5072 /* The value is in 64 byte chunks */
5073 burst_size_to_prog |= (u16)(bytes / 64);
5075 /* k bytes granularity case */
5076 /* Enable MSB granularity bit */
5077 burst_size_to_prog = ICE_KBYTE_GRANULARITY;
5078 /* round number to nearest 1024 granularity */
5079 bytes = ice_round_to_num(bytes, 1024);
5080 /* check rounding doesn't go beyond allowed */
5081 if (bytes > ICE_MAX_BURST_SIZE_KBYTE_GRANULARITY)
5082 bytes = ICE_MAX_BURST_SIZE_KBYTE_GRANULARITY;
5083 /* The value is in k bytes */
5084 burst_size_to_prog |= (u16)(bytes / 1024);
5086 hw->max_burst_size = burst_size_to_prog;
5091 * ice_sched_replay_node_prio - re-configure node priority
5092 * @hw: pointer to the HW struct
5093 * @node: sched node to configure
5094 * @priority: priority value
5096 * This function configures node element's priority value. It
5097 * needs to be called with scheduler lock held.
5099 static enum ice_status
5100 ice_sched_replay_node_prio(struct ice_hw *hw, struct ice_sched_node *node,
5103 struct ice_aqc_txsched_elem_data buf;
5104 struct ice_aqc_txsched_elem *data;
5105 enum ice_status status;
5109 data->valid_sections |= ICE_AQC_ELEM_VALID_GENERIC;
5110 data->generic = priority;
5112 /* Configure element */
5113 status = ice_sched_update_elem(hw, node, &buf);
5118 * ice_sched_replay_node_bw - replay node(s) BW
5119 * @hw: pointer to the HW struct
5120 * @node: sched node to configure
5121 * @bw_t_info: BW type information
5123 * This function restores node's BW from bw_t_info. The caller needs
5124 * to hold the scheduler lock.
5126 static enum ice_status
5127 ice_sched_replay_node_bw(struct ice_hw *hw, struct ice_sched_node *node,
5128 struct ice_bw_type_info *bw_t_info)
5130 struct ice_port_info *pi = hw->port_info;
5131 enum ice_status status = ICE_ERR_PARAM;
5136 if (!ice_is_any_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CNT))
5138 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_PRIO)) {
5139 status = ice_sched_replay_node_prio(hw, node,
5140 bw_t_info->generic);
5144 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CIR)) {
5145 status = ice_sched_set_node_bw_lmt(pi, node, ICE_MIN_BW,
5146 bw_t_info->cir_bw.bw);
5150 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CIR_WT)) {
5151 bw_alloc = bw_t_info->cir_bw.bw_alloc;
5152 status = ice_sched_cfg_node_bw_alloc(hw, node, ICE_MIN_BW,
5157 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_EIR)) {
5158 status = ice_sched_set_node_bw_lmt(pi, node, ICE_MAX_BW,
5159 bw_t_info->eir_bw.bw);
5163 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_EIR_WT)) {
5164 bw_alloc = bw_t_info->eir_bw.bw_alloc;
5165 status = ice_sched_cfg_node_bw_alloc(hw, node, ICE_MAX_BW,
5170 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_SHARED))
5171 status = ice_sched_set_node_bw_lmt(pi, node, ICE_SHARED_BW,
5172 bw_t_info->shared_bw);
5177 * ice_sched_replay_agg_bw - replay aggregator node(s) BW
5178 * @hw: pointer to the HW struct
5179 * @agg_info: aggregator data structure
5181 * This function re-creates aggregator type nodes. The caller needs to hold
5182 * the scheduler lock.
5184 static enum ice_status
5185 ice_sched_replay_agg_bw(struct ice_hw *hw, struct ice_sched_agg_info *agg_info)
5187 struct ice_sched_node *tc_node, *agg_node;
5188 enum ice_status status = ICE_SUCCESS;
5192 return ICE_ERR_PARAM;
5193 ice_for_each_traffic_class(tc) {
5194 if (!ice_is_any_bit_set(agg_info->bw_t_info[tc].bw_t_bitmap,
5197 tc_node = ice_sched_get_tc_node(hw->port_info, tc);
5199 status = ICE_ERR_PARAM;
5202 agg_node = ice_sched_get_agg_node(hw->port_info, tc_node,
5205 status = ICE_ERR_PARAM;
5208 status = ice_sched_replay_node_bw(hw, agg_node,
5209 &agg_info->bw_t_info[tc]);
5217 * ice_sched_get_ena_tc_bitmap - get enabled TC bitmap
5218 * @pi: port info struct
5219 * @tc_bitmap: 8 bits TC bitmap to check
5220 * @ena_tc_bitmap: 8 bits enabled TC bitmap to return
5222 * This function returns enabled TC bitmap in variable ena_tc_bitmap. Some TCs
5223 * may be missing, it returns enabled TCs. This function needs to be called with
5224 * scheduler lock held.
5227 ice_sched_get_ena_tc_bitmap(struct ice_port_info *pi, ice_bitmap_t *tc_bitmap,
5228 ice_bitmap_t *ena_tc_bitmap)
5232 /* Some TC(s) may be missing after reset, adjust for replay */
5233 ice_for_each_traffic_class(tc)
5234 if (ice_is_tc_ena(*tc_bitmap, tc) &&
5235 (ice_sched_get_tc_node(pi, tc)))
5236 ice_set_bit(tc, ena_tc_bitmap);
5240 * ice_sched_replay_agg - recreate aggregator node(s)
5241 * @hw: pointer to the HW struct
5243 * This function recreate aggregator type nodes which are not replayed earlier.
5244 * It also replay aggregator BW information. These aggregator nodes are not
5245 * associated with VSI type node yet.
5247 void ice_sched_replay_agg(struct ice_hw *hw)
5249 struct ice_port_info *pi = hw->port_info;
5250 struct ice_sched_agg_info *agg_info;
5252 ice_acquire_lock(&pi->sched_lock);
5253 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
5255 /* replay aggregator (re-create aggregator node) */
5256 if (!ice_cmp_bitmap(agg_info->tc_bitmap,
5257 agg_info->replay_tc_bitmap,
5258 ICE_MAX_TRAFFIC_CLASS)) {
5259 ice_declare_bitmap(replay_bitmap,
5260 ICE_MAX_TRAFFIC_CLASS);
5261 enum ice_status status;
5263 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5264 ice_sched_get_ena_tc_bitmap(pi,
5265 agg_info->replay_tc_bitmap,
5267 status = ice_sched_cfg_agg(hw->port_info,
5272 ice_info(hw, "Replay agg id[%d] failed\n",
5274 /* Move on to next one */
5277 /* Replay aggregator node BW (restore aggregator BW) */
5278 status = ice_sched_replay_agg_bw(hw, agg_info);
5280 ice_info(hw, "Replay agg bw [id=%d] failed\n",
5284 ice_release_lock(&pi->sched_lock);
5288 * ice_sched_replay_agg_vsi_preinit - Agg/VSI replay pre initialization
5289 * @hw: pointer to the HW struct
5291 * This function initialize aggregator(s) TC bitmap to zero. A required
5292 * preinit step for replaying aggregators.
5294 void ice_sched_replay_agg_vsi_preinit(struct ice_hw *hw)
5296 struct ice_port_info *pi = hw->port_info;
5297 struct ice_sched_agg_info *agg_info;
5299 ice_acquire_lock(&pi->sched_lock);
5300 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
5302 struct ice_sched_agg_vsi_info *agg_vsi_info;
5304 agg_info->tc_bitmap[0] = 0;
5305 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
5306 ice_sched_agg_vsi_info, list_entry)
5307 agg_vsi_info->tc_bitmap[0] = 0;
5309 ice_release_lock(&pi->sched_lock);
5313 * ice_sched_replay_tc_node_bw - replay TC node(s) BW
5314 * @pi: port information structure
5316 * This function replay TC nodes.
5319 ice_sched_replay_tc_node_bw(struct ice_port_info *pi)
5321 enum ice_status status = ICE_SUCCESS;
5325 return ICE_ERR_PARAM;
5326 ice_acquire_lock(&pi->sched_lock);
5327 ice_for_each_traffic_class(tc) {
5328 struct ice_sched_node *tc_node;
5330 tc_node = ice_sched_get_tc_node(pi, tc);
5332 continue; /* TC not present */
5333 status = ice_sched_replay_node_bw(pi->hw, tc_node,
5334 &pi->tc_node_bw_t_info[tc]);
5338 ice_release_lock(&pi->sched_lock);
5343 * ice_sched_replay_vsi_bw - replay VSI type node(s) BW
5344 * @hw: pointer to the HW struct
5345 * @vsi_handle: software VSI handle
5346 * @tc_bitmap: 8 bits TC bitmap
5348 * This function replays VSI type nodes bandwidth. This function needs to be
5349 * called with scheduler lock held.
5351 static enum ice_status
5352 ice_sched_replay_vsi_bw(struct ice_hw *hw, u16 vsi_handle,
5353 ice_bitmap_t *tc_bitmap)
5355 struct ice_sched_node *vsi_node, *tc_node;
5356 struct ice_port_info *pi = hw->port_info;
5357 struct ice_bw_type_info *bw_t_info;
5358 struct ice_vsi_ctx *vsi_ctx;
5359 enum ice_status status = ICE_SUCCESS;
5362 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
5364 return ICE_ERR_PARAM;
5365 ice_for_each_traffic_class(tc) {
5366 if (!ice_is_tc_ena(*tc_bitmap, tc))
5368 tc_node = ice_sched_get_tc_node(pi, tc);
5371 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
5374 bw_t_info = &vsi_ctx->sched.bw_t_info[tc];
5375 status = ice_sched_replay_node_bw(hw, vsi_node, bw_t_info);
5383 * ice_sched_replay_vsi_agg - replay aggregator & VSI to aggregator node(s)
5384 * @hw: pointer to the HW struct
5385 * @vsi_handle: software VSI handle
5387 * This function replays aggregator node, VSI to aggregator type nodes, and
5388 * their node bandwidth information. This function needs to be called with
5389 * scheduler lock held.
5391 static enum ice_status
5392 ice_sched_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle)
5394 ice_declare_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5395 struct ice_sched_agg_vsi_info *agg_vsi_info;
5396 struct ice_port_info *pi = hw->port_info;
5397 struct ice_sched_agg_info *agg_info;
5398 enum ice_status status;
5400 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5401 if (!ice_is_vsi_valid(hw, vsi_handle))
5402 return ICE_ERR_PARAM;
5403 agg_info = ice_get_vsi_agg_info(hw, vsi_handle);
5405 return ICE_SUCCESS; /* Not present in list - default Agg case */
5406 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
5408 return ICE_SUCCESS; /* Not present in list - default Agg case */
5409 ice_sched_get_ena_tc_bitmap(pi, agg_info->replay_tc_bitmap,
5411 /* Replay aggregator node associated to vsi_handle */
5412 status = ice_sched_cfg_agg(hw->port_info, agg_info->agg_id,
5413 ICE_AGG_TYPE_AGG, replay_bitmap);
5416 /* Replay aggregator node BW (restore aggregator BW) */
5417 status = ice_sched_replay_agg_bw(hw, agg_info);
5421 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5422 ice_sched_get_ena_tc_bitmap(pi, agg_vsi_info->replay_tc_bitmap,
5424 /* Move this VSI (vsi_handle) to above aggregator */
5425 status = ice_sched_assoc_vsi_to_agg(pi, agg_info->agg_id, vsi_handle,
5429 /* Replay VSI BW (restore VSI BW) */
5430 return ice_sched_replay_vsi_bw(hw, vsi_handle,
5431 agg_vsi_info->tc_bitmap);
5435 * ice_replay_vsi_agg - replay VSI to aggregator node
5436 * @hw: pointer to the HW struct
5437 * @vsi_handle: software VSI handle
5439 * This function replays association of VSI to aggregator type nodes, and
5440 * node bandwidth information.
5443 ice_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle)
5445 struct ice_port_info *pi = hw->port_info;
5446 enum ice_status status;
5448 ice_acquire_lock(&pi->sched_lock);
5449 status = ice_sched_replay_vsi_agg(hw, vsi_handle);
5450 ice_release_lock(&pi->sched_lock);
5455 * ice_sched_replay_q_bw - replay queue type node BW
5456 * @pi: port information structure
5457 * @q_ctx: queue context structure
5459 * This function replays queue type node bandwidth. This function needs to be
5460 * called with scheduler lock held.
5463 ice_sched_replay_q_bw(struct ice_port_info *pi, struct ice_q_ctx *q_ctx)
5465 struct ice_sched_node *q_node;
5467 /* Following also checks the presence of node in tree */
5468 q_node = ice_sched_find_node_by_teid(pi->root, q_ctx->q_teid);
5470 return ICE_ERR_PARAM;
5471 return ice_sched_replay_node_bw(pi->hw, q_node, &q_ctx->bw_t_info);