1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
8 * ice_sched_add_root_node - Insert the Tx scheduler root node in SW DB
9 * @pi: port information structure
10 * @info: Scheduler element information from firmware
12 * This function inserts the root node of the scheduling tree topology
15 static enum ice_status
16 ice_sched_add_root_node(struct ice_port_info *pi,
17 struct ice_aqc_txsched_elem_data *info)
19 struct ice_sched_node *root;
27 root = (struct ice_sched_node *)ice_malloc(hw, sizeof(*root));
29 return ICE_ERR_NO_MEMORY;
31 /* coverity[suspicious_sizeof] */
32 root->children = (struct ice_sched_node **)
33 ice_calloc(hw, hw->max_children[0], sizeof(*root));
34 if (!root->children) {
36 return ICE_ERR_NO_MEMORY;
39 ice_memcpy(&root->info, info, sizeof(*info), ICE_DMA_TO_NONDMA);
45 * ice_sched_find_node_by_teid - Find the Tx scheduler node in SW DB
46 * @start_node: pointer to the starting ice_sched_node struct in a sub-tree
47 * @teid: node TEID to search
49 * This function searches for a node matching the TEID in the scheduling tree
50 * from the SW DB. The search is recursive and is restricted by the number of
51 * layers it has searched through; stopping at the max supported layer.
53 * This function needs to be called when holding the port_info->sched_lock
55 struct ice_sched_node *
56 ice_sched_find_node_by_teid(struct ice_sched_node *start_node, u32 teid)
60 /* The TEID is same as that of the start_node */
61 if (ICE_TXSCHED_GET_NODE_TEID(start_node) == teid)
64 /* The node has no children or is at the max layer */
65 if (!start_node->num_children ||
66 start_node->tx_sched_layer >= ICE_AQC_TOPO_MAX_LEVEL_NUM ||
67 start_node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF)
70 /* Check if TEID matches to any of the children nodes */
71 for (i = 0; i < start_node->num_children; i++)
72 if (ICE_TXSCHED_GET_NODE_TEID(start_node->children[i]) == teid)
73 return start_node->children[i];
75 /* Search within each child's sub-tree */
76 for (i = 0; i < start_node->num_children; i++) {
77 struct ice_sched_node *tmp;
79 tmp = ice_sched_find_node_by_teid(start_node->children[i],
89 * ice_aqc_send_sched_elem_cmd - send scheduling elements cmd
90 * @hw: pointer to the HW struct
91 * @cmd_opc: cmd opcode
92 * @elems_req: number of elements to request
93 * @buf: pointer to buffer
94 * @buf_size: buffer size in bytes
95 * @elems_resp: returns total number of elements response
96 * @cd: pointer to command details structure or NULL
98 * This function sends a scheduling elements cmd (cmd_opc)
100 static enum ice_status
101 ice_aqc_send_sched_elem_cmd(struct ice_hw *hw, enum ice_adminq_opc cmd_opc,
102 u16 elems_req, void *buf, u16 buf_size,
103 u16 *elems_resp, struct ice_sq_cd *cd)
105 struct ice_aqc_sched_elem_cmd *cmd;
106 struct ice_aq_desc desc;
107 enum ice_status status;
109 cmd = &desc.params.sched_elem_cmd;
110 ice_fill_dflt_direct_cmd_desc(&desc, cmd_opc);
111 cmd->num_elem_req = CPU_TO_LE16(elems_req);
112 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
113 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
114 if (!status && elems_resp)
115 *elems_resp = LE16_TO_CPU(cmd->num_elem_resp);
121 * ice_aq_query_sched_elems - query scheduler elements
122 * @hw: pointer to the HW struct
123 * @elems_req: number of elements to query
124 * @buf: pointer to buffer
125 * @buf_size: buffer size in bytes
126 * @elems_ret: returns total number of elements returned
127 * @cd: pointer to command details structure or NULL
129 * Query scheduling elements (0x0404)
132 ice_aq_query_sched_elems(struct ice_hw *hw, u16 elems_req,
133 struct ice_aqc_txsched_elem_data *buf, u16 buf_size,
134 u16 *elems_ret, struct ice_sq_cd *cd)
136 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_get_sched_elems,
137 elems_req, (void *)buf, buf_size,
142 * ice_sched_add_node - Insert the Tx scheduler node in SW DB
143 * @pi: port information structure
144 * @layer: Scheduler layer of the node
145 * @info: Scheduler element information from firmware
147 * This function inserts a scheduler node to the SW DB.
150 ice_sched_add_node(struct ice_port_info *pi, u8 layer,
151 struct ice_aqc_txsched_elem_data *info)
153 struct ice_aqc_txsched_elem_data elem;
154 struct ice_sched_node *parent;
155 struct ice_sched_node *node;
156 enum ice_status status;
160 return ICE_ERR_PARAM;
164 /* A valid parent node should be there */
165 parent = ice_sched_find_node_by_teid(pi->root,
166 LE32_TO_CPU(info->parent_teid));
168 ice_debug(hw, ICE_DBG_SCHED, "Parent Node not found for parent_teid=0x%x\n",
169 LE32_TO_CPU(info->parent_teid));
170 return ICE_ERR_PARAM;
173 /* query the current node information from FW before adding it
176 status = ice_sched_query_elem(hw, LE32_TO_CPU(info->node_teid), &elem);
179 node = (struct ice_sched_node *)ice_malloc(hw, sizeof(*node));
181 return ICE_ERR_NO_MEMORY;
182 if (hw->max_children[layer]) {
183 /* coverity[suspicious_sizeof] */
184 node->children = (struct ice_sched_node **)
185 ice_calloc(hw, hw->max_children[layer], sizeof(*node));
186 if (!node->children) {
188 return ICE_ERR_NO_MEMORY;
193 node->parent = parent;
194 node->tx_sched_layer = layer;
195 parent->children[parent->num_children++] = node;
201 * ice_aq_delete_sched_elems - delete scheduler elements
202 * @hw: pointer to the HW struct
203 * @grps_req: number of groups to delete
204 * @buf: pointer to buffer
205 * @buf_size: buffer size in bytes
206 * @grps_del: returns total number of elements deleted
207 * @cd: pointer to command details structure or NULL
209 * Delete scheduling elements (0x040F)
211 static enum ice_status
212 ice_aq_delete_sched_elems(struct ice_hw *hw, u16 grps_req,
213 struct ice_aqc_delete_elem *buf, u16 buf_size,
214 u16 *grps_del, struct ice_sq_cd *cd)
216 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_delete_sched_elems,
217 grps_req, (void *)buf, buf_size,
222 * ice_sched_remove_elems - remove nodes from HW
223 * @hw: pointer to the HW struct
224 * @parent: pointer to the parent node
225 * @num_nodes: number of nodes
226 * @node_teids: array of node teids to be deleted
228 * This function remove nodes from HW
230 static enum ice_status
231 ice_sched_remove_elems(struct ice_hw *hw, struct ice_sched_node *parent,
232 u16 num_nodes, u32 *node_teids)
234 struct ice_aqc_delete_elem *buf;
235 u16 i, num_groups_removed = 0;
236 enum ice_status status;
239 buf_size = ice_struct_size(buf, teid, num_nodes);
240 buf = (struct ice_aqc_delete_elem *)ice_malloc(hw, buf_size);
242 return ICE_ERR_NO_MEMORY;
244 buf->hdr.parent_teid = parent->info.node_teid;
245 buf->hdr.num_elems = CPU_TO_LE16(num_nodes);
246 for (i = 0; i < num_nodes; i++)
247 buf->teid[i] = CPU_TO_LE32(node_teids[i]);
249 status = ice_aq_delete_sched_elems(hw, 1, buf, buf_size,
250 &num_groups_removed, NULL);
251 if (status != ICE_SUCCESS || num_groups_removed != 1)
252 ice_debug(hw, ICE_DBG_SCHED, "remove node failed FW error %d\n",
253 hw->adminq.sq_last_status);
260 * ice_sched_get_first_node - get the first node of the given layer
261 * @pi: port information structure
262 * @parent: pointer the base node of the subtree
263 * @layer: layer number
265 * This function retrieves the first node of the given layer from the subtree
267 static struct ice_sched_node *
268 ice_sched_get_first_node(struct ice_port_info *pi,
269 struct ice_sched_node *parent, u8 layer)
271 return pi->sib_head[parent->tc_num][layer];
275 * ice_sched_get_tc_node - get pointer to TC node
276 * @pi: port information structure
279 * This function returns the TC node pointer
281 struct ice_sched_node *ice_sched_get_tc_node(struct ice_port_info *pi, u8 tc)
285 if (!pi || !pi->root)
287 for (i = 0; i < pi->root->num_children; i++)
288 if (pi->root->children[i]->tc_num == tc)
289 return pi->root->children[i];
294 * ice_free_sched_node - Free a Tx scheduler node from SW DB
295 * @pi: port information structure
296 * @node: pointer to the ice_sched_node struct
298 * This function frees up a node from SW DB as well as from HW
300 * This function needs to be called with the port_info->sched_lock held
302 void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node)
304 struct ice_sched_node *parent;
305 struct ice_hw *hw = pi->hw;
308 /* Free the children before freeing up the parent node
309 * The parent array is updated below and that shifts the nodes
310 * in the array. So always pick the first child if num children > 0
312 while (node->num_children)
313 ice_free_sched_node(pi, node->children[0]);
315 /* Leaf, TC and root nodes can't be deleted by SW */
316 if (node->tx_sched_layer >= hw->sw_entry_point_layer &&
317 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_TC &&
318 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_ROOT_PORT &&
319 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_LEAF) {
320 u32 teid = LE32_TO_CPU(node->info.node_teid);
322 ice_sched_remove_elems(hw, node->parent, 1, &teid);
324 parent = node->parent;
325 /* root has no parent */
327 struct ice_sched_node *p;
329 /* update the parent */
330 for (i = 0; i < parent->num_children; i++)
331 if (parent->children[i] == node) {
332 for (j = i + 1; j < parent->num_children; j++)
333 parent->children[j - 1] =
335 parent->num_children--;
339 p = ice_sched_get_first_node(pi, node, node->tx_sched_layer);
341 if (p->sibling == node) {
342 p->sibling = node->sibling;
348 /* update the sibling head if head is getting removed */
349 if (pi->sib_head[node->tc_num][node->tx_sched_layer] == node)
350 pi->sib_head[node->tc_num][node->tx_sched_layer] =
354 /* leaf nodes have no children */
356 ice_free(hw, node->children);
361 * ice_aq_get_dflt_topo - gets default scheduler topology
362 * @hw: pointer to the HW struct
363 * @lport: logical port number
364 * @buf: pointer to buffer
365 * @buf_size: buffer size in bytes
366 * @num_branches: returns total number of queue to port branches
367 * @cd: pointer to command details structure or NULL
369 * Get default scheduler topology (0x400)
371 static enum ice_status
372 ice_aq_get_dflt_topo(struct ice_hw *hw, u8 lport,
373 struct ice_aqc_get_topo_elem *buf, u16 buf_size,
374 u8 *num_branches, struct ice_sq_cd *cd)
376 struct ice_aqc_get_topo *cmd;
377 struct ice_aq_desc desc;
378 enum ice_status status;
380 cmd = &desc.params.get_topo;
381 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_dflt_topo);
382 cmd->port_num = lport;
383 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
384 if (!status && num_branches)
385 *num_branches = cmd->num_branches;
391 * ice_aq_add_sched_elems - adds scheduling element
392 * @hw: pointer to the HW struct
393 * @grps_req: the number of groups that are requested to be added
394 * @buf: pointer to buffer
395 * @buf_size: buffer size in bytes
396 * @grps_added: returns total number of groups added
397 * @cd: pointer to command details structure or NULL
399 * Add scheduling elements (0x0401)
401 static enum ice_status
402 ice_aq_add_sched_elems(struct ice_hw *hw, u16 grps_req,
403 struct ice_aqc_add_elem *buf, u16 buf_size,
404 u16 *grps_added, struct ice_sq_cd *cd)
406 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_add_sched_elems,
407 grps_req, (void *)buf, buf_size,
412 * ice_aq_cfg_sched_elems - configures scheduler elements
413 * @hw: pointer to the HW struct
414 * @elems_req: number of elements to configure
415 * @buf: pointer to buffer
416 * @buf_size: buffer size in bytes
417 * @elems_cfgd: returns total number of elements configured
418 * @cd: pointer to command details structure or NULL
420 * Configure scheduling elements (0x0403)
422 static enum ice_status
423 ice_aq_cfg_sched_elems(struct ice_hw *hw, u16 elems_req,
424 struct ice_aqc_txsched_elem_data *buf, u16 buf_size,
425 u16 *elems_cfgd, struct ice_sq_cd *cd)
427 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_cfg_sched_elems,
428 elems_req, (void *)buf, buf_size,
433 * ice_aq_move_sched_elems - move scheduler elements
434 * @hw: pointer to the HW struct
435 * @grps_req: number of groups to move
436 * @buf: pointer to buffer
437 * @buf_size: buffer size in bytes
438 * @grps_movd: returns total number of groups moved
439 * @cd: pointer to command details structure or NULL
441 * Move scheduling elements (0x0408)
443 static enum ice_status
444 ice_aq_move_sched_elems(struct ice_hw *hw, u16 grps_req,
445 struct ice_aqc_move_elem *buf, u16 buf_size,
446 u16 *grps_movd, struct ice_sq_cd *cd)
448 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_move_sched_elems,
449 grps_req, (void *)buf, buf_size,
454 * ice_aq_suspend_sched_elems - suspend scheduler elements
455 * @hw: pointer to the HW struct
456 * @elems_req: number of elements to suspend
457 * @buf: pointer to buffer
458 * @buf_size: buffer size in bytes
459 * @elems_ret: returns total number of elements suspended
460 * @cd: pointer to command details structure or NULL
462 * Suspend scheduling elements (0x0409)
464 static enum ice_status
465 ice_aq_suspend_sched_elems(struct ice_hw *hw, u16 elems_req, __le32 *buf,
466 u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd)
468 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_suspend_sched_elems,
469 elems_req, (void *)buf, buf_size,
474 * ice_aq_resume_sched_elems - resume scheduler elements
475 * @hw: pointer to the HW struct
476 * @elems_req: number of elements to resume
477 * @buf: pointer to buffer
478 * @buf_size: buffer size in bytes
479 * @elems_ret: returns total number of elements resumed
480 * @cd: pointer to command details structure or NULL
482 * resume scheduling elements (0x040A)
484 static enum ice_status
485 ice_aq_resume_sched_elems(struct ice_hw *hw, u16 elems_req, __le32 *buf,
486 u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd)
488 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_resume_sched_elems,
489 elems_req, (void *)buf, buf_size,
494 * ice_aq_query_sched_res - query scheduler resource
495 * @hw: pointer to the HW struct
496 * @buf_size: buffer size in bytes
497 * @buf: pointer to buffer
498 * @cd: pointer to command details structure or NULL
500 * Query scheduler resource allocation (0x0412)
502 static enum ice_status
503 ice_aq_query_sched_res(struct ice_hw *hw, u16 buf_size,
504 struct ice_aqc_query_txsched_res_resp *buf,
505 struct ice_sq_cd *cd)
507 struct ice_aq_desc desc;
509 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_sched_res);
510 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
514 * ice_sched_suspend_resume_elems - suspend or resume HW nodes
515 * @hw: pointer to the HW struct
516 * @num_nodes: number of nodes
517 * @node_teids: array of node teids to be suspended or resumed
518 * @suspend: true means suspend / false means resume
520 * This function suspends or resumes HW nodes
522 static enum ice_status
523 ice_sched_suspend_resume_elems(struct ice_hw *hw, u8 num_nodes, u32 *node_teids,
526 u16 i, buf_size, num_elem_ret = 0;
527 enum ice_status status;
530 buf_size = sizeof(*buf) * num_nodes;
531 buf = (__le32 *)ice_malloc(hw, buf_size);
533 return ICE_ERR_NO_MEMORY;
535 for (i = 0; i < num_nodes; i++)
536 buf[i] = CPU_TO_LE32(node_teids[i]);
539 status = ice_aq_suspend_sched_elems(hw, num_nodes, buf,
540 buf_size, &num_elem_ret,
543 status = ice_aq_resume_sched_elems(hw, num_nodes, buf,
544 buf_size, &num_elem_ret,
546 if (status != ICE_SUCCESS || num_elem_ret != num_nodes)
547 ice_debug(hw, ICE_DBG_SCHED, "suspend/resume failed\n");
554 * ice_alloc_lan_q_ctx - allocate LAN queue contexts for the given VSI and TC
555 * @hw: pointer to the HW struct
556 * @vsi_handle: VSI handle
558 * @new_numqs: number of queues
560 static enum ice_status
561 ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs)
563 struct ice_vsi_ctx *vsi_ctx;
564 struct ice_q_ctx *q_ctx;
566 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
568 return ICE_ERR_PARAM;
569 /* allocate LAN queue contexts */
570 if (!vsi_ctx->lan_q_ctx[tc]) {
571 vsi_ctx->lan_q_ctx[tc] = (struct ice_q_ctx *)
572 ice_calloc(hw, new_numqs, sizeof(*q_ctx));
573 if (!vsi_ctx->lan_q_ctx[tc])
574 return ICE_ERR_NO_MEMORY;
575 vsi_ctx->num_lan_q_entries[tc] = new_numqs;
578 /* num queues are increased, update the queue contexts */
579 if (new_numqs > vsi_ctx->num_lan_q_entries[tc]) {
580 u16 prev_num = vsi_ctx->num_lan_q_entries[tc];
582 q_ctx = (struct ice_q_ctx *)
583 ice_calloc(hw, new_numqs, sizeof(*q_ctx));
585 return ICE_ERR_NO_MEMORY;
586 ice_memcpy(q_ctx, vsi_ctx->lan_q_ctx[tc],
587 prev_num * sizeof(*q_ctx), ICE_DMA_TO_NONDMA);
588 ice_free(hw, vsi_ctx->lan_q_ctx[tc]);
589 vsi_ctx->lan_q_ctx[tc] = q_ctx;
590 vsi_ctx->num_lan_q_entries[tc] = new_numqs;
596 * ice_aq_rl_profile - performs a rate limiting task
597 * @hw: pointer to the HW struct
598 * @opcode: opcode for add, query, or remove profile(s)
599 * @num_profiles: the number of profiles
600 * @buf: pointer to buffer
601 * @buf_size: buffer size in bytes
602 * @num_processed: number of processed add or remove profile(s) to return
603 * @cd: pointer to command details structure
605 * RL profile function to add, query, or remove profile(s)
607 static enum ice_status
608 ice_aq_rl_profile(struct ice_hw *hw, enum ice_adminq_opc opcode,
609 u16 num_profiles, struct ice_aqc_rl_profile_elem *buf,
610 u16 buf_size, u16 *num_processed, struct ice_sq_cd *cd)
612 struct ice_aqc_rl_profile *cmd;
613 struct ice_aq_desc desc;
614 enum ice_status status;
616 cmd = &desc.params.rl_profile;
618 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
619 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
620 cmd->num_profiles = CPU_TO_LE16(num_profiles);
621 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
622 if (!status && num_processed)
623 *num_processed = LE16_TO_CPU(cmd->num_processed);
628 * ice_aq_add_rl_profile - adds rate limiting profile(s)
629 * @hw: pointer to the HW struct
630 * @num_profiles: the number of profile(s) to be add
631 * @buf: pointer to buffer
632 * @buf_size: buffer size in bytes
633 * @num_profiles_added: total number of profiles added to return
634 * @cd: pointer to command details structure
636 * Add RL profile (0x0410)
638 static enum ice_status
639 ice_aq_add_rl_profile(struct ice_hw *hw, u16 num_profiles,
640 struct ice_aqc_rl_profile_elem *buf, u16 buf_size,
641 u16 *num_profiles_added, struct ice_sq_cd *cd)
643 return ice_aq_rl_profile(hw, ice_aqc_opc_add_rl_profiles, num_profiles,
644 buf, buf_size, num_profiles_added, cd);
648 * ice_aq_query_rl_profile - query rate limiting profile(s)
649 * @hw: pointer to the HW struct
650 * @num_profiles: the number of profile(s) to query
651 * @buf: pointer to buffer
652 * @buf_size: buffer size in bytes
653 * @cd: pointer to command details structure
655 * Query RL profile (0x0411)
658 ice_aq_query_rl_profile(struct ice_hw *hw, u16 num_profiles,
659 struct ice_aqc_rl_profile_elem *buf, u16 buf_size,
660 struct ice_sq_cd *cd)
662 return ice_aq_rl_profile(hw, ice_aqc_opc_query_rl_profiles,
663 num_profiles, buf, buf_size, NULL, cd);
667 * ice_aq_remove_rl_profile - removes RL profile(s)
668 * @hw: pointer to the HW struct
669 * @num_profiles: the number of profile(s) to remove
670 * @buf: pointer to buffer
671 * @buf_size: buffer size in bytes
672 * @num_profiles_removed: total number of profiles removed to return
673 * @cd: pointer to command details structure or NULL
675 * Remove RL profile (0x0415)
677 static enum ice_status
678 ice_aq_remove_rl_profile(struct ice_hw *hw, u16 num_profiles,
679 struct ice_aqc_rl_profile_elem *buf, u16 buf_size,
680 u16 *num_profiles_removed, struct ice_sq_cd *cd)
682 return ice_aq_rl_profile(hw, ice_aqc_opc_remove_rl_profiles,
683 num_profiles, buf, buf_size,
684 num_profiles_removed, cd);
688 * ice_sched_del_rl_profile - remove RL profile
689 * @hw: pointer to the HW struct
690 * @rl_info: rate limit profile information
692 * If the profile ID is not referenced anymore, it removes profile ID with
693 * its associated parameters from HW DB,and locally. The caller needs to
694 * hold scheduler lock.
696 static enum ice_status
697 ice_sched_del_rl_profile(struct ice_hw *hw,
698 struct ice_aqc_rl_profile_info *rl_info)
700 struct ice_aqc_rl_profile_elem *buf;
701 u16 num_profiles_removed;
702 enum ice_status status;
703 u16 num_profiles = 1;
705 if (rl_info->prof_id_ref != 0)
706 return ICE_ERR_IN_USE;
708 /* Safe to remove profile ID */
709 buf = &rl_info->profile;
710 status = ice_aq_remove_rl_profile(hw, num_profiles, buf, sizeof(*buf),
711 &num_profiles_removed, NULL);
712 if (status || num_profiles_removed != num_profiles)
715 /* Delete stale entry now */
716 LIST_DEL(&rl_info->list_entry);
717 ice_free(hw, rl_info);
722 * ice_sched_clear_rl_prof - clears RL prof entries
723 * @pi: port information structure
725 * This function removes all RL profile from HW as well as from SW DB.
727 static void ice_sched_clear_rl_prof(struct ice_port_info *pi)
730 struct ice_hw *hw = pi->hw;
732 for (ln = 0; ln < hw->num_tx_sched_layers; ln++) {
733 struct ice_aqc_rl_profile_info *rl_prof_elem;
734 struct ice_aqc_rl_profile_info *rl_prof_tmp;
736 LIST_FOR_EACH_ENTRY_SAFE(rl_prof_elem, rl_prof_tmp,
737 &hw->rl_prof_list[ln],
738 ice_aqc_rl_profile_info, list_entry) {
739 enum ice_status status;
741 rl_prof_elem->prof_id_ref = 0;
742 status = ice_sched_del_rl_profile(hw, rl_prof_elem);
744 ice_debug(hw, ICE_DBG_SCHED, "Remove rl profile failed\n");
745 /* On error, free mem required */
746 LIST_DEL(&rl_prof_elem->list_entry);
747 ice_free(hw, rl_prof_elem);
754 * ice_sched_clear_agg - clears the aggregator related information
755 * @hw: pointer to the hardware structure
757 * This function removes aggregator list and free up aggregator related memory
758 * previously allocated.
760 void ice_sched_clear_agg(struct ice_hw *hw)
762 struct ice_sched_agg_info *agg_info;
763 struct ice_sched_agg_info *atmp;
765 LIST_FOR_EACH_ENTRY_SAFE(agg_info, atmp, &hw->agg_list,
768 struct ice_sched_agg_vsi_info *agg_vsi_info;
769 struct ice_sched_agg_vsi_info *vtmp;
771 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, vtmp,
772 &agg_info->agg_vsi_list,
773 ice_sched_agg_vsi_info, list_entry) {
774 LIST_DEL(&agg_vsi_info->list_entry);
775 ice_free(hw, agg_vsi_info);
777 LIST_DEL(&agg_info->list_entry);
778 ice_free(hw, agg_info);
783 * ice_sched_clear_tx_topo - clears the scheduler tree nodes
784 * @pi: port information structure
786 * This function removes all the nodes from HW as well as from SW DB.
788 static void ice_sched_clear_tx_topo(struct ice_port_info *pi)
792 /* remove RL profiles related lists */
793 ice_sched_clear_rl_prof(pi);
795 ice_free_sched_node(pi, pi->root);
801 * ice_sched_clear_port - clear the scheduler elements from SW DB for a port
802 * @pi: port information structure
804 * Cleanup scheduling elements from SW DB
806 void ice_sched_clear_port(struct ice_port_info *pi)
808 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
811 pi->port_state = ICE_SCHED_PORT_STATE_INIT;
812 ice_acquire_lock(&pi->sched_lock);
813 ice_sched_clear_tx_topo(pi);
814 ice_release_lock(&pi->sched_lock);
815 ice_destroy_lock(&pi->sched_lock);
819 * ice_sched_cleanup_all - cleanup scheduler elements from SW DB for all ports
820 * @hw: pointer to the HW struct
822 * Cleanup scheduling elements from SW DB for all the ports
824 void ice_sched_cleanup_all(struct ice_hw *hw)
829 if (hw->layer_info) {
830 ice_free(hw, hw->layer_info);
831 hw->layer_info = NULL;
834 ice_sched_clear_port(hw->port_info);
836 hw->num_tx_sched_layers = 0;
837 hw->num_tx_sched_phys_layers = 0;
838 hw->flattened_layers = 0;
843 * ice_aq_cfg_l2_node_cgd - configures L2 node to CGD mapping
844 * @hw: pointer to the HW struct
845 * @num_l2_nodes: the number of L2 nodes whose CGDs to configure
846 * @buf: pointer to buffer
847 * @buf_size: buffer size in bytes
848 * @cd: pointer to command details structure or NULL
850 * Configure L2 Node CGD (0x0414)
853 ice_aq_cfg_l2_node_cgd(struct ice_hw *hw, u16 num_l2_nodes,
854 struct ice_aqc_cfg_l2_node_cgd_elem *buf,
855 u16 buf_size, struct ice_sq_cd *cd)
857 struct ice_aqc_cfg_l2_node_cgd *cmd;
858 struct ice_aq_desc desc;
860 cmd = &desc.params.cfg_l2_node_cgd;
861 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_cfg_l2_node_cgd);
862 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
864 cmd->num_l2_nodes = CPU_TO_LE16(num_l2_nodes);
865 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
869 * ice_sched_add_elems - add nodes to HW and SW DB
870 * @pi: port information structure
871 * @tc_node: pointer to the branch node
872 * @parent: pointer to the parent node
873 * @layer: layer number to add nodes
874 * @num_nodes: number of nodes
875 * @num_nodes_added: pointer to num nodes added
876 * @first_node_teid: if new nodes are added then return the TEID of first node
878 * This function add nodes to HW as well as to SW DB for a given layer
880 static enum ice_status
881 ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node,
882 struct ice_sched_node *parent, u8 layer, u16 num_nodes,
883 u16 *num_nodes_added, u32 *first_node_teid)
885 struct ice_sched_node *prev, *new_node;
886 struct ice_aqc_add_elem *buf;
887 u16 i, num_groups_added = 0;
888 enum ice_status status = ICE_SUCCESS;
889 struct ice_hw *hw = pi->hw;
893 buf_size = ice_struct_size(buf, generic, num_nodes);
894 buf = (struct ice_aqc_add_elem *)ice_malloc(hw, buf_size);
896 return ICE_ERR_NO_MEMORY;
898 buf->hdr.parent_teid = parent->info.node_teid;
899 buf->hdr.num_elems = CPU_TO_LE16(num_nodes);
900 for (i = 0; i < num_nodes; i++) {
901 buf->generic[i].parent_teid = parent->info.node_teid;
902 buf->generic[i].data.elem_type = ICE_AQC_ELEM_TYPE_SE_GENERIC;
903 buf->generic[i].data.valid_sections =
904 ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
905 ICE_AQC_ELEM_VALID_EIR;
906 buf->generic[i].data.generic = 0;
907 buf->generic[i].data.cir_bw.bw_profile_idx =
908 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
909 buf->generic[i].data.cir_bw.bw_alloc =
910 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
911 buf->generic[i].data.eir_bw.bw_profile_idx =
912 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
913 buf->generic[i].data.eir_bw.bw_alloc =
914 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
917 status = ice_aq_add_sched_elems(hw, 1, buf, buf_size,
918 &num_groups_added, NULL);
919 if (status != ICE_SUCCESS || num_groups_added != 1) {
920 ice_debug(hw, ICE_DBG_SCHED, "add node failed FW Error %d\n",
921 hw->adminq.sq_last_status);
926 *num_nodes_added = num_nodes;
927 /* add nodes to the SW DB */
928 for (i = 0; i < num_nodes; i++) {
929 status = ice_sched_add_node(pi, layer, &buf->generic[i]);
930 if (status != ICE_SUCCESS) {
931 ice_debug(hw, ICE_DBG_SCHED, "add nodes in SW DB failed status =%d\n",
936 teid = LE32_TO_CPU(buf->generic[i].node_teid);
937 new_node = ice_sched_find_node_by_teid(parent, teid);
939 ice_debug(hw, ICE_DBG_SCHED, "Node is missing for teid =%d\n", teid);
943 new_node->sibling = NULL;
944 new_node->tc_num = tc_node->tc_num;
946 /* add it to previous node sibling pointer */
947 /* Note: siblings are not linked across branches */
948 prev = ice_sched_get_first_node(pi, tc_node, layer);
949 if (prev && prev != new_node) {
950 while (prev->sibling)
951 prev = prev->sibling;
952 prev->sibling = new_node;
955 /* initialize the sibling head */
956 if (!pi->sib_head[tc_node->tc_num][layer])
957 pi->sib_head[tc_node->tc_num][layer] = new_node;
960 *first_node_teid = teid;
968 * ice_sched_add_nodes_to_layer - Add nodes to a given layer
969 * @pi: port information structure
970 * @tc_node: pointer to TC node
971 * @parent: pointer to parent node
972 * @layer: layer number to add nodes
973 * @num_nodes: number of nodes to be added
974 * @first_node_teid: pointer to the first node TEID
975 * @num_nodes_added: pointer to number of nodes added
977 * This function add nodes to a given layer.
979 static enum ice_status
980 ice_sched_add_nodes_to_layer(struct ice_port_info *pi,
981 struct ice_sched_node *tc_node,
982 struct ice_sched_node *parent, u8 layer,
983 u16 num_nodes, u32 *first_node_teid,
984 u16 *num_nodes_added)
986 u32 *first_teid_ptr = first_node_teid;
987 u16 new_num_nodes, max_child_nodes;
988 enum ice_status status = ICE_SUCCESS;
989 struct ice_hw *hw = pi->hw;
993 *num_nodes_added = 0;
998 if (!parent || layer < hw->sw_entry_point_layer)
999 return ICE_ERR_PARAM;
1001 /* max children per node per layer */
1002 max_child_nodes = hw->max_children[parent->tx_sched_layer];
1004 /* current number of children + required nodes exceed max children ? */
1005 if ((parent->num_children + num_nodes) > max_child_nodes) {
1006 /* Fail if the parent is a TC node */
1007 if (parent == tc_node)
1010 /* utilize all the spaces if the parent is not full */
1011 if (parent->num_children < max_child_nodes) {
1012 new_num_nodes = max_child_nodes - parent->num_children;
1013 /* this recursion is intentional, and wouldn't
1014 * go more than 2 calls
1016 status = ice_sched_add_nodes_to_layer(pi, tc_node,
1021 if (status != ICE_SUCCESS)
1024 *num_nodes_added += num_added;
1026 /* Don't modify the first node TEID memory if the first node was
1027 * added already in the above call. Instead send some temp
1028 * memory for all other recursive calls.
1031 first_teid_ptr = &temp;
1033 new_num_nodes = num_nodes - num_added;
1035 /* This parent is full, try the next sibling */
1036 parent = parent->sibling;
1038 /* this recursion is intentional, for 1024 queues
1039 * per VSI, it goes max of 16 iterations.
1040 * 1024 / 8 = 128 layer 8 nodes
1041 * 128 /8 = 16 (add 8 nodes per iteration)
1043 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent,
1044 layer, new_num_nodes,
1047 *num_nodes_added += num_added;
1051 status = ice_sched_add_elems(pi, tc_node, parent, layer, num_nodes,
1052 num_nodes_added, first_node_teid);
1057 * ice_sched_get_qgrp_layer - get the current queue group layer number
1058 * @hw: pointer to the HW struct
1060 * This function returns the current queue group layer number
1062 static u8 ice_sched_get_qgrp_layer(struct ice_hw *hw)
1064 /* It's always total layers - 1, the array is 0 relative so -2 */
1065 return hw->num_tx_sched_layers - ICE_QGRP_LAYER_OFFSET;
1069 * ice_sched_get_vsi_layer - get the current VSI layer number
1070 * @hw: pointer to the HW struct
1072 * This function returns the current VSI layer number
1074 static u8 ice_sched_get_vsi_layer(struct ice_hw *hw)
1076 /* Num Layers VSI layer
1079 * 5 or less sw_entry_point_layer
1081 /* calculate the VSI layer based on number of layers. */
1082 if (hw->num_tx_sched_layers > ICE_VSI_LAYER_OFFSET + 1) {
1083 u8 layer = hw->num_tx_sched_layers - ICE_VSI_LAYER_OFFSET;
1085 if (layer > hw->sw_entry_point_layer)
1088 return hw->sw_entry_point_layer;
1092 * ice_sched_get_agg_layer - get the current aggregator layer number
1093 * @hw: pointer to the HW struct
1095 * This function returns the current aggregator layer number
1097 static u8 ice_sched_get_agg_layer(struct ice_hw *hw)
1099 /* Num Layers aggregator layer
1101 * 7 or less sw_entry_point_layer
1103 /* calculate the aggregator layer based on number of layers. */
1104 if (hw->num_tx_sched_layers > ICE_AGG_LAYER_OFFSET + 1) {
1105 u8 layer = hw->num_tx_sched_layers - ICE_AGG_LAYER_OFFSET;
1107 if (layer > hw->sw_entry_point_layer)
1110 return hw->sw_entry_point_layer;
1114 * ice_rm_dflt_leaf_node - remove the default leaf node in the tree
1115 * @pi: port information structure
1117 * This function removes the leaf node that was created by the FW
1118 * during initialization
1120 static void ice_rm_dflt_leaf_node(struct ice_port_info *pi)
1122 struct ice_sched_node *node;
1126 if (!node->num_children)
1128 node = node->children[0];
1130 if (node && node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF) {
1131 u32 teid = LE32_TO_CPU(node->info.node_teid);
1132 enum ice_status status;
1134 /* remove the default leaf node */
1135 status = ice_sched_remove_elems(pi->hw, node->parent, 1, &teid);
1137 ice_free_sched_node(pi, node);
1142 * ice_sched_rm_dflt_nodes - free the default nodes in the tree
1143 * @pi: port information structure
1145 * This function frees all the nodes except root and TC that were created by
1146 * the FW during initialization
1148 static void ice_sched_rm_dflt_nodes(struct ice_port_info *pi)
1150 struct ice_sched_node *node;
1152 ice_rm_dflt_leaf_node(pi);
1154 /* remove the default nodes except TC and root nodes */
1157 if (node->tx_sched_layer >= pi->hw->sw_entry_point_layer &&
1158 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_TC &&
1159 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_ROOT_PORT) {
1160 ice_free_sched_node(pi, node);
1164 if (!node->num_children)
1166 node = node->children[0];
1171 * ice_sched_init_port - Initialize scheduler by querying information from FW
1172 * @pi: port info structure for the tree to cleanup
1174 * This function is the initial call to find the total number of Tx scheduler
1175 * resources, default topology created by firmware and storing the information
1178 enum ice_status ice_sched_init_port(struct ice_port_info *pi)
1180 struct ice_aqc_get_topo_elem *buf;
1181 enum ice_status status;
1188 return ICE_ERR_PARAM;
1191 /* Query the Default Topology from FW */
1192 buf = (struct ice_aqc_get_topo_elem *)ice_malloc(hw,
1193 ICE_AQ_MAX_BUF_LEN);
1195 return ICE_ERR_NO_MEMORY;
1197 /* Query default scheduling tree topology */
1198 status = ice_aq_get_dflt_topo(hw, pi->lport, buf, ICE_AQ_MAX_BUF_LEN,
1199 &num_branches, NULL);
1203 /* num_branches should be between 1-8 */
1204 if (num_branches < 1 || num_branches > ICE_TXSCHED_MAX_BRANCHES) {
1205 ice_debug(hw, ICE_DBG_SCHED, "num_branches unexpected %d\n",
1207 status = ICE_ERR_PARAM;
1211 /* get the number of elements on the default/first branch */
1212 num_elems = LE16_TO_CPU(buf[0].hdr.num_elems);
1214 /* num_elems should always be between 1-9 */
1215 if (num_elems < 1 || num_elems > ICE_AQC_TOPO_MAX_LEVEL_NUM) {
1216 ice_debug(hw, ICE_DBG_SCHED, "num_elems unexpected %d\n",
1218 status = ICE_ERR_PARAM;
1222 /* If the last node is a leaf node then the index of the queue group
1223 * layer is two less than the number of elements.
1225 if (num_elems > 2 && buf[0].generic[num_elems - 1].data.elem_type ==
1226 ICE_AQC_ELEM_TYPE_LEAF)
1227 pi->last_node_teid =
1228 LE32_TO_CPU(buf[0].generic[num_elems - 2].node_teid);
1230 pi->last_node_teid =
1231 LE32_TO_CPU(buf[0].generic[num_elems - 1].node_teid);
1233 /* Insert the Tx Sched root node */
1234 status = ice_sched_add_root_node(pi, &buf[0].generic[0]);
1238 /* Parse the default tree and cache the information */
1239 for (i = 0; i < num_branches; i++) {
1240 num_elems = LE16_TO_CPU(buf[i].hdr.num_elems);
1242 /* Skip root element as already inserted */
1243 for (j = 1; j < num_elems; j++) {
1244 /* update the sw entry point */
1245 if (buf[0].generic[j].data.elem_type ==
1246 ICE_AQC_ELEM_TYPE_ENTRY_POINT)
1247 hw->sw_entry_point_layer = j;
1249 status = ice_sched_add_node(pi, j, &buf[i].generic[j]);
1255 /* Remove the default nodes. */
1257 ice_sched_rm_dflt_nodes(pi);
1259 /* initialize the port for handling the scheduler tree */
1260 pi->port_state = ICE_SCHED_PORT_STATE_READY;
1261 ice_init_lock(&pi->sched_lock);
1262 for (i = 0; i < ICE_AQC_TOPO_MAX_LEVEL_NUM; i++)
1263 INIT_LIST_HEAD(&hw->rl_prof_list[i]);
1266 if (status && pi->root) {
1267 ice_free_sched_node(pi, pi->root);
1276 * ice_sched_get_node - Get the struct ice_sched_node for given TEID
1277 * @pi: port information structure
1278 * @teid: Scheduler node TEID
1280 * This function retrieves the ice_sched_node struct for given TEID from
1281 * the SW DB and returns it to the caller.
1283 struct ice_sched_node *ice_sched_get_node(struct ice_port_info *pi, u32 teid)
1285 struct ice_sched_node *node;
1290 /* Find the node starting from root */
1291 ice_acquire_lock(&pi->sched_lock);
1292 node = ice_sched_find_node_by_teid(pi->root, teid);
1293 ice_release_lock(&pi->sched_lock);
1296 ice_debug(pi->hw, ICE_DBG_SCHED, "Node not found for teid=0x%x\n", teid);
1302 * ice_sched_query_res_alloc - query the FW for num of logical sched layers
1303 * @hw: pointer to the HW struct
1305 * query FW for allocated scheduler resources and store in HW struct
1307 enum ice_status ice_sched_query_res_alloc(struct ice_hw *hw)
1309 struct ice_aqc_query_txsched_res_resp *buf;
1310 enum ice_status status = ICE_SUCCESS;
1317 buf = (struct ice_aqc_query_txsched_res_resp *)
1318 ice_malloc(hw, sizeof(*buf));
1320 return ICE_ERR_NO_MEMORY;
1322 status = ice_aq_query_sched_res(hw, sizeof(*buf), buf, NULL);
1324 goto sched_query_out;
1326 hw->num_tx_sched_layers = LE16_TO_CPU(buf->sched_props.logical_levels);
1327 hw->num_tx_sched_phys_layers =
1328 LE16_TO_CPU(buf->sched_props.phys_levels);
1329 hw->flattened_layers = buf->sched_props.flattening_bitmap;
1330 hw->max_cgds = buf->sched_props.max_pf_cgds;
1332 /* max sibling group size of current layer refers to the max children
1333 * of the below layer node.
1334 * layer 1 node max children will be layer 2 max sibling group size
1335 * layer 2 node max children will be layer 3 max sibling group size
1336 * and so on. This array will be populated from root (index 0) to
1337 * qgroup layer 7. Leaf node has no children.
1339 for (i = 0; i < hw->num_tx_sched_layers - 1; i++) {
1340 max_sibl = buf->layer_props[i + 1].max_sibl_grp_sz;
1341 hw->max_children[i] = LE16_TO_CPU(max_sibl);
1344 hw->layer_info = (struct ice_aqc_layer_props *)
1345 ice_memdup(hw, buf->layer_props,
1346 (hw->num_tx_sched_layers *
1347 sizeof(*hw->layer_info)),
1349 if (!hw->layer_info) {
1350 status = ICE_ERR_NO_MEMORY;
1351 goto sched_query_out;
1360 * ice_sched_get_psm_clk_freq - determine the PSM clock frequency
1361 * @hw: pointer to the HW struct
1363 * Determine the PSM clock frequency and store in HW struct
1365 void ice_sched_get_psm_clk_freq(struct ice_hw *hw)
1369 val = rd32(hw, GLGEN_CLKSTAT_SRC);
1370 clk_src = (val & GLGEN_CLKSTAT_SRC_PSM_CLK_SRC_M) >>
1371 GLGEN_CLKSTAT_SRC_PSM_CLK_SRC_S;
1373 #define PSM_CLK_SRC_367_MHZ 0x0
1374 #define PSM_CLK_SRC_416_MHZ 0x1
1375 #define PSM_CLK_SRC_446_MHZ 0x2
1376 #define PSM_CLK_SRC_390_MHZ 0x3
1379 case PSM_CLK_SRC_367_MHZ:
1380 hw->psm_clk_freq = ICE_PSM_CLK_367MHZ_IN_HZ;
1382 case PSM_CLK_SRC_416_MHZ:
1383 hw->psm_clk_freq = ICE_PSM_CLK_416MHZ_IN_HZ;
1385 case PSM_CLK_SRC_446_MHZ:
1386 hw->psm_clk_freq = ICE_PSM_CLK_446MHZ_IN_HZ;
1388 case PSM_CLK_SRC_390_MHZ:
1389 hw->psm_clk_freq = ICE_PSM_CLK_390MHZ_IN_HZ;
1392 ice_debug(hw, ICE_DBG_SCHED, "PSM clk_src unexpected %u\n",
1394 /* fall back to a safe default */
1395 hw->psm_clk_freq = ICE_PSM_CLK_446MHZ_IN_HZ;
1400 * ice_sched_find_node_in_subtree - Find node in part of base node subtree
1401 * @hw: pointer to the HW struct
1402 * @base: pointer to the base node
1403 * @node: pointer to the node to search
1405 * This function checks whether a given node is part of the base node
1409 ice_sched_find_node_in_subtree(struct ice_hw *hw, struct ice_sched_node *base,
1410 struct ice_sched_node *node)
1414 for (i = 0; i < base->num_children; i++) {
1415 struct ice_sched_node *child = base->children[i];
1420 if (child->tx_sched_layer > node->tx_sched_layer)
1423 /* this recursion is intentional, and wouldn't
1424 * go more than 8 calls
1426 if (ice_sched_find_node_in_subtree(hw, child, node))
1433 * ice_sched_get_free_qgrp - Scan all queue group siblings and find a free node
1434 * @pi: port information structure
1435 * @vsi_node: software VSI handle
1436 * @qgrp_node: first queue group node identified for scanning
1437 * @owner: LAN or RDMA
1439 * This function retrieves a free LAN or RDMA queue group node by scanning
1440 * qgrp_node and its siblings for the queue group with the fewest number
1441 * of queues currently assigned.
1443 static struct ice_sched_node *
1444 ice_sched_get_free_qgrp(struct ice_port_info *pi,
1445 struct ice_sched_node *vsi_node,
1446 struct ice_sched_node *qgrp_node, u8 owner)
1448 struct ice_sched_node *min_qgrp;
1453 min_children = qgrp_node->num_children;
1456 min_qgrp = qgrp_node;
1457 /* scan all queue groups until find a node which has less than the
1458 * minimum number of children. This way all queue group nodes get
1459 * equal number of shares and active. The bandwidth will be equally
1460 * distributed across all queues.
1463 /* make sure the qgroup node is part of the VSI subtree */
1464 if (ice_sched_find_node_in_subtree(pi->hw, vsi_node, qgrp_node))
1465 if (qgrp_node->num_children < min_children &&
1466 qgrp_node->owner == owner) {
1467 /* replace the new min queue group node */
1468 min_qgrp = qgrp_node;
1469 min_children = min_qgrp->num_children;
1470 /* break if it has no children, */
1474 qgrp_node = qgrp_node->sibling;
1480 * ice_sched_get_free_qparent - Get a free LAN or RDMA queue group node
1481 * @pi: port information structure
1482 * @vsi_handle: software VSI handle
1483 * @tc: branch number
1484 * @owner: LAN or RDMA
1486 * This function retrieves a free LAN or RDMA queue group node
1488 struct ice_sched_node *
1489 ice_sched_get_free_qparent(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
1492 struct ice_sched_node *vsi_node, *qgrp_node;
1493 struct ice_vsi_ctx *vsi_ctx;
1497 qgrp_layer = ice_sched_get_qgrp_layer(pi->hw);
1498 max_children = pi->hw->max_children[qgrp_layer];
1500 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
1503 vsi_node = vsi_ctx->sched.vsi_node[tc];
1504 /* validate invalid VSI ID */
1508 /* get the first queue group node from VSI sub-tree */
1509 qgrp_node = ice_sched_get_first_node(pi, vsi_node, qgrp_layer);
1511 /* make sure the qgroup node is part of the VSI subtree */
1512 if (ice_sched_find_node_in_subtree(pi->hw, vsi_node, qgrp_node))
1513 if (qgrp_node->num_children < max_children &&
1514 qgrp_node->owner == owner)
1516 qgrp_node = qgrp_node->sibling;
1519 /* Select the best queue group */
1520 return ice_sched_get_free_qgrp(pi, vsi_node, qgrp_node, owner);
1524 * ice_sched_get_vsi_node - Get a VSI node based on VSI ID
1525 * @pi: pointer to the port information structure
1526 * @tc_node: pointer to the TC node
1527 * @vsi_handle: software VSI handle
1529 * This function retrieves a VSI node for a given VSI ID from a given
1532 struct ice_sched_node *
1533 ice_sched_get_vsi_node(struct ice_port_info *pi, struct ice_sched_node *tc_node,
1536 struct ice_sched_node *node;
1539 vsi_layer = ice_sched_get_vsi_layer(pi->hw);
1540 node = ice_sched_get_first_node(pi, tc_node, vsi_layer);
1542 /* Check whether it already exists */
1544 if (node->vsi_handle == vsi_handle)
1546 node = node->sibling;
1553 * ice_sched_get_agg_node - Get an aggregator node based on aggregator ID
1554 * @pi: pointer to the port information structure
1555 * @tc_node: pointer to the TC node
1556 * @agg_id: aggregator ID
1558 * This function retrieves an aggregator node for a given aggregator ID from
1561 static struct ice_sched_node *
1562 ice_sched_get_agg_node(struct ice_port_info *pi, struct ice_sched_node *tc_node,
1565 struct ice_sched_node *node;
1566 struct ice_hw *hw = pi->hw;
1571 agg_layer = ice_sched_get_agg_layer(hw);
1572 node = ice_sched_get_first_node(pi, tc_node, agg_layer);
1574 /* Check whether it already exists */
1576 if (node->agg_id == agg_id)
1578 node = node->sibling;
1585 * ice_sched_check_node - Compare node parameters between SW DB and HW DB
1586 * @hw: pointer to the HW struct
1587 * @node: pointer to the ice_sched_node struct
1589 * This function queries and compares the HW element with SW DB node parameters
1591 static bool ice_sched_check_node(struct ice_hw *hw, struct ice_sched_node *node)
1593 struct ice_aqc_txsched_elem_data buf;
1594 enum ice_status status;
1597 node_teid = LE32_TO_CPU(node->info.node_teid);
1598 status = ice_sched_query_elem(hw, node_teid, &buf);
1599 if (status != ICE_SUCCESS)
1602 if (memcmp(&buf, &node->info, sizeof(buf))) {
1603 ice_debug(hw, ICE_DBG_SCHED, "Node mismatch for teid=0x%x\n",
1612 * ice_sched_calc_vsi_child_nodes - calculate number of VSI child nodes
1613 * @hw: pointer to the HW struct
1614 * @num_qs: number of queues
1615 * @num_nodes: num nodes array
1617 * This function calculates the number of VSI child nodes based on the
1621 ice_sched_calc_vsi_child_nodes(struct ice_hw *hw, u16 num_qs, u16 *num_nodes)
1626 qgl = ice_sched_get_qgrp_layer(hw);
1627 vsil = ice_sched_get_vsi_layer(hw);
1629 /* calculate num nodes from queue group to VSI layer */
1630 for (i = qgl; i > vsil; i--) {
1631 /* round to the next integer if there is a remainder */
1632 num = DIVIDE_AND_ROUND_UP(num, hw->max_children[i]);
1634 /* need at least one node */
1635 num_nodes[i] = num ? num : 1;
1640 * ice_sched_add_vsi_child_nodes - add VSI child nodes to tree
1641 * @pi: port information structure
1642 * @vsi_handle: software VSI handle
1643 * @tc_node: pointer to the TC node
1644 * @num_nodes: pointer to the num nodes that needs to be added per layer
1645 * @owner: node owner (LAN or RDMA)
1647 * This function adds the VSI child nodes to tree. It gets called for
1648 * LAN and RDMA separately.
1650 static enum ice_status
1651 ice_sched_add_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle,
1652 struct ice_sched_node *tc_node, u16 *num_nodes,
1655 struct ice_sched_node *parent, *node;
1656 struct ice_hw *hw = pi->hw;
1657 enum ice_status status;
1658 u32 first_node_teid;
1662 qgl = ice_sched_get_qgrp_layer(hw);
1663 vsil = ice_sched_get_vsi_layer(hw);
1664 parent = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1665 for (i = vsil + 1; i <= qgl; i++) {
1669 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
1673 if (status != ICE_SUCCESS || num_nodes[i] != num_added)
1676 /* The newly added node can be a new parent for the next
1680 parent = ice_sched_find_node_by_teid(tc_node,
1684 node->owner = owner;
1685 node = node->sibling;
1688 parent = parent->children[0];
1696 * ice_sched_calc_vsi_support_nodes - calculate number of VSI support nodes
1697 * @pi: pointer to the port info structure
1698 * @tc_node: pointer to TC node
1699 * @num_nodes: pointer to num nodes array
1701 * This function calculates the number of supported nodes needed to add this
1702 * VSI into Tx tree including the VSI, parent and intermediate nodes in below
1706 ice_sched_calc_vsi_support_nodes(struct ice_port_info *pi,
1707 struct ice_sched_node *tc_node, u16 *num_nodes)
1709 struct ice_sched_node *node;
1713 vsil = ice_sched_get_vsi_layer(pi->hw);
1714 for (i = vsil; i >= pi->hw->sw_entry_point_layer; i--)
1715 /* Add intermediate nodes if TC has no children and
1716 * need at least one node for VSI
1718 if (!tc_node->num_children || i == vsil) {
1721 /* If intermediate nodes are reached max children
1722 * then add a new one.
1724 node = ice_sched_get_first_node(pi, tc_node, (u8)i);
1725 /* scan all the siblings */
1727 if (node->num_children <
1728 pi->hw->max_children[i])
1730 node = node->sibling;
1733 /* tree has one intermediate node to add this new VSI.
1734 * So no need to calculate supported nodes for below
1739 /* all the nodes are full, allocate a new one */
1745 * ice_sched_add_vsi_support_nodes - add VSI supported nodes into Tx tree
1746 * @pi: port information structure
1747 * @vsi_handle: software VSI handle
1748 * @tc_node: pointer to TC node
1749 * @num_nodes: pointer to num nodes array
1751 * This function adds the VSI supported nodes into Tx tree including the
1752 * VSI, its parent and intermediate nodes in below layers
1754 static enum ice_status
1755 ice_sched_add_vsi_support_nodes(struct ice_port_info *pi, u16 vsi_handle,
1756 struct ice_sched_node *tc_node, u16 *num_nodes)
1758 struct ice_sched_node *parent = tc_node;
1759 enum ice_status status;
1760 u32 first_node_teid;
1765 return ICE_ERR_PARAM;
1767 vsil = ice_sched_get_vsi_layer(pi->hw);
1768 for (i = pi->hw->sw_entry_point_layer; i <= vsil; i++) {
1769 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent,
1773 if (status != ICE_SUCCESS || num_nodes[i] != num_added)
1776 /* The newly added node can be a new parent for the next
1780 parent = ice_sched_find_node_by_teid(tc_node,
1783 parent = parent->children[0];
1789 parent->vsi_handle = vsi_handle;
1796 * ice_sched_add_vsi_to_topo - add a new VSI into tree
1797 * @pi: port information structure
1798 * @vsi_handle: software VSI handle
1801 * This function adds a new VSI into scheduler tree
1803 static enum ice_status
1804 ice_sched_add_vsi_to_topo(struct ice_port_info *pi, u16 vsi_handle, u8 tc)
1806 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
1807 struct ice_sched_node *tc_node;
1809 tc_node = ice_sched_get_tc_node(pi, tc);
1811 return ICE_ERR_PARAM;
1813 /* calculate number of supported nodes needed for this VSI */
1814 ice_sched_calc_vsi_support_nodes(pi, tc_node, num_nodes);
1816 /* add VSI supported nodes to TC subtree */
1817 return ice_sched_add_vsi_support_nodes(pi, vsi_handle, tc_node,
1822 * ice_sched_update_vsi_child_nodes - update VSI child nodes
1823 * @pi: port information structure
1824 * @vsi_handle: software VSI handle
1826 * @new_numqs: new number of max queues
1827 * @owner: owner of this subtree
1829 * This function updates the VSI child nodes based on the number of queues
1831 static enum ice_status
1832 ice_sched_update_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle,
1833 u8 tc, u16 new_numqs, u8 owner)
1835 u16 new_num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
1836 struct ice_sched_node *vsi_node;
1837 struct ice_sched_node *tc_node;
1838 struct ice_vsi_ctx *vsi_ctx;
1839 enum ice_status status = ICE_SUCCESS;
1840 struct ice_hw *hw = pi->hw;
1843 tc_node = ice_sched_get_tc_node(pi, tc);
1847 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1851 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
1853 return ICE_ERR_PARAM;
1855 prev_numqs = vsi_ctx->sched.max_lanq[tc];
1856 /* num queues are not changed or less than the previous number */
1857 if (new_numqs <= prev_numqs)
1859 status = ice_alloc_lan_q_ctx(hw, vsi_handle, tc, new_numqs);
1864 ice_sched_calc_vsi_child_nodes(hw, new_numqs, new_num_nodes);
1865 /* Keep the max number of queue configuration all the time. Update the
1866 * tree only if number of queues > previous number of queues. This may
1867 * leave some extra nodes in the tree if number of queues < previous
1868 * number but that wouldn't harm anything. Removing those extra nodes
1869 * may complicate the code if those nodes are part of SRL or
1870 * individually rate limited.
1872 status = ice_sched_add_vsi_child_nodes(pi, vsi_handle, tc_node,
1873 new_num_nodes, owner);
1876 vsi_ctx->sched.max_lanq[tc] = new_numqs;
1882 * ice_sched_cfg_vsi - configure the new/existing VSI
1883 * @pi: port information structure
1884 * @vsi_handle: software VSI handle
1886 * @maxqs: max number of queues
1887 * @owner: LAN or RDMA
1888 * @enable: TC enabled or disabled
1890 * This function adds/updates VSI nodes based on the number of queues. If TC is
1891 * enabled and VSI is in suspended state then resume the VSI back. If TC is
1892 * disabled then suspend the VSI if it is not already.
1895 ice_sched_cfg_vsi(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 maxqs,
1896 u8 owner, bool enable)
1898 struct ice_sched_node *vsi_node, *tc_node;
1899 struct ice_vsi_ctx *vsi_ctx;
1900 enum ice_status status = ICE_SUCCESS;
1901 struct ice_hw *hw = pi->hw;
1903 ice_debug(pi->hw, ICE_DBG_SCHED, "add/config VSI %d\n", vsi_handle);
1904 tc_node = ice_sched_get_tc_node(pi, tc);
1906 return ICE_ERR_PARAM;
1907 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
1909 return ICE_ERR_PARAM;
1910 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1912 /* suspend the VSI if TC is not enabled */
1914 if (vsi_node && vsi_node->in_use) {
1915 u32 teid = LE32_TO_CPU(vsi_node->info.node_teid);
1917 status = ice_sched_suspend_resume_elems(hw, 1, &teid,
1920 vsi_node->in_use = false;
1925 /* TC is enabled, if it is a new VSI then add it to the tree */
1927 status = ice_sched_add_vsi_to_topo(pi, vsi_handle, tc);
1931 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1935 vsi_ctx->sched.vsi_node[tc] = vsi_node;
1936 vsi_node->in_use = true;
1937 /* invalidate the max queues whenever VSI gets added first time
1938 * into the scheduler tree (boot or after reset). We need to
1939 * recreate the child nodes all the time in these cases.
1941 vsi_ctx->sched.max_lanq[tc] = 0;
1944 /* update the VSI child nodes */
1945 status = ice_sched_update_vsi_child_nodes(pi, vsi_handle, tc, maxqs,
1950 /* TC is enabled, resume the VSI if it is in the suspend state */
1951 if (!vsi_node->in_use) {
1952 u32 teid = LE32_TO_CPU(vsi_node->info.node_teid);
1954 status = ice_sched_suspend_resume_elems(hw, 1, &teid, false);
1956 vsi_node->in_use = true;
1963 * ice_sched_rm_agg_vsi_entry - remove aggregator related VSI info entry
1964 * @pi: port information structure
1965 * @vsi_handle: software VSI handle
1967 * This function removes single aggregator VSI info entry from
1970 static void ice_sched_rm_agg_vsi_info(struct ice_port_info *pi, u16 vsi_handle)
1972 struct ice_sched_agg_info *agg_info;
1973 struct ice_sched_agg_info *atmp;
1975 LIST_FOR_EACH_ENTRY_SAFE(agg_info, atmp, &pi->hw->agg_list,
1978 struct ice_sched_agg_vsi_info *agg_vsi_info;
1979 struct ice_sched_agg_vsi_info *vtmp;
1981 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, vtmp,
1982 &agg_info->agg_vsi_list,
1983 ice_sched_agg_vsi_info, list_entry)
1984 if (agg_vsi_info->vsi_handle == vsi_handle) {
1985 LIST_DEL(&agg_vsi_info->list_entry);
1986 ice_free(pi->hw, agg_vsi_info);
1993 * ice_sched_is_leaf_node_present - check for a leaf node in the sub-tree
1994 * @node: pointer to the sub-tree node
1996 * This function checks for a leaf node presence in a given sub-tree node.
1998 static bool ice_sched_is_leaf_node_present(struct ice_sched_node *node)
2002 for (i = 0; i < node->num_children; i++)
2003 if (ice_sched_is_leaf_node_present(node->children[i]))
2005 /* check for a leaf node */
2006 return (node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF);
2010 * ice_sched_rm_vsi_cfg - remove the VSI and its children nodes
2011 * @pi: port information structure
2012 * @vsi_handle: software VSI handle
2013 * @owner: LAN or RDMA
2015 * This function removes the VSI and its LAN or RDMA children nodes from the
2018 static enum ice_status
2019 ice_sched_rm_vsi_cfg(struct ice_port_info *pi, u16 vsi_handle, u8 owner)
2021 enum ice_status status = ICE_ERR_PARAM;
2022 struct ice_vsi_ctx *vsi_ctx;
2025 ice_debug(pi->hw, ICE_DBG_SCHED, "removing VSI %d\n", vsi_handle);
2026 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
2028 ice_acquire_lock(&pi->sched_lock);
2029 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
2031 goto exit_sched_rm_vsi_cfg;
2033 ice_for_each_traffic_class(i) {
2034 struct ice_sched_node *vsi_node, *tc_node;
2037 tc_node = ice_sched_get_tc_node(pi, i);
2041 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
2045 if (ice_sched_is_leaf_node_present(vsi_node)) {
2046 ice_debug(pi->hw, ICE_DBG_SCHED, "VSI has leaf nodes in TC %d\n", i);
2047 status = ICE_ERR_IN_USE;
2048 goto exit_sched_rm_vsi_cfg;
2050 while (j < vsi_node->num_children) {
2051 if (vsi_node->children[j]->owner == owner) {
2052 ice_free_sched_node(pi, vsi_node->children[j]);
2054 /* reset the counter again since the num
2055 * children will be updated after node removal
2062 /* remove the VSI if it has no children */
2063 if (!vsi_node->num_children) {
2064 ice_free_sched_node(pi, vsi_node);
2065 vsi_ctx->sched.vsi_node[i] = NULL;
2067 /* clean up aggregator related VSI info if any */
2068 ice_sched_rm_agg_vsi_info(pi, vsi_handle);
2070 if (owner == ICE_SCHED_NODE_OWNER_LAN)
2071 vsi_ctx->sched.max_lanq[i] = 0;
2073 status = ICE_SUCCESS;
2075 exit_sched_rm_vsi_cfg:
2076 ice_release_lock(&pi->sched_lock);
2081 * ice_rm_vsi_lan_cfg - remove VSI and its LAN children nodes
2082 * @pi: port information structure
2083 * @vsi_handle: software VSI handle
2085 * This function clears the VSI and its LAN children nodes from scheduler tree
2088 enum ice_status ice_rm_vsi_lan_cfg(struct ice_port_info *pi, u16 vsi_handle)
2090 return ice_sched_rm_vsi_cfg(pi, vsi_handle, ICE_SCHED_NODE_OWNER_LAN);
2094 * ice_sched_is_tree_balanced - Check tree nodes are identical or not
2095 * @hw: pointer to the HW struct
2096 * @node: pointer to the ice_sched_node struct
2098 * This function compares all the nodes for a given tree against HW DB nodes
2099 * This function needs to be called with the port_info->sched_lock held
2101 bool ice_sched_is_tree_balanced(struct ice_hw *hw, struct ice_sched_node *node)
2105 /* start from the leaf node */
2106 for (i = 0; i < node->num_children; i++)
2107 /* Fail if node doesn't match with the SW DB
2108 * this recursion is intentional, and wouldn't
2109 * go more than 9 calls
2111 if (!ice_sched_is_tree_balanced(hw, node->children[i]))
2114 return ice_sched_check_node(hw, node);
2118 * ice_aq_query_node_to_root - retrieve the tree topology for a given node TEID
2119 * @hw: pointer to the HW struct
2120 * @node_teid: node TEID
2121 * @buf: pointer to buffer
2122 * @buf_size: buffer size in bytes
2123 * @cd: pointer to command details structure or NULL
2125 * This function retrieves the tree topology from the firmware for a given
2126 * node TEID to the root node.
2129 ice_aq_query_node_to_root(struct ice_hw *hw, u32 node_teid,
2130 struct ice_aqc_txsched_elem_data *buf, u16 buf_size,
2131 struct ice_sq_cd *cd)
2133 struct ice_aqc_query_node_to_root *cmd;
2134 struct ice_aq_desc desc;
2136 cmd = &desc.params.query_node_to_root;
2137 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_node_to_root);
2138 cmd->teid = CPU_TO_LE32(node_teid);
2139 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2143 * ice_get_agg_info - get the aggregator ID
2144 * @hw: pointer to the hardware structure
2145 * @agg_id: aggregator ID
2147 * This function validates aggregator ID. The function returns info if
2148 * aggregator ID is present in list otherwise it returns null.
2150 static struct ice_sched_agg_info *
2151 ice_get_agg_info(struct ice_hw *hw, u32 agg_id)
2153 struct ice_sched_agg_info *agg_info;
2155 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
2157 if (agg_info->agg_id == agg_id)
2164 * ice_sched_get_free_vsi_parent - Find a free parent node in aggregator subtree
2165 * @hw: pointer to the HW struct
2166 * @node: pointer to a child node
2167 * @num_nodes: num nodes count array
2169 * This function walks through the aggregator subtree to find a free parent
2172 static struct ice_sched_node *
2173 ice_sched_get_free_vsi_parent(struct ice_hw *hw, struct ice_sched_node *node,
2176 u8 l = node->tx_sched_layer;
2179 vsil = ice_sched_get_vsi_layer(hw);
2181 /* Is it VSI parent layer ? */
2183 return (node->num_children < hw->max_children[l]) ? node : NULL;
2185 /* We have intermediate nodes. Let's walk through the subtree. If the
2186 * intermediate node has space to add a new node then clear the count
2188 if (node->num_children < hw->max_children[l])
2190 /* The below recursive call is intentional and wouldn't go more than
2191 * 2 or 3 iterations.
2194 for (i = 0; i < node->num_children; i++) {
2195 struct ice_sched_node *parent;
2197 parent = ice_sched_get_free_vsi_parent(hw, node->children[i],
2207 * ice_sched_update_parent - update the new parent in SW DB
2208 * @new_parent: pointer to a new parent node
2209 * @node: pointer to a child node
2211 * This function removes the child from the old parent and adds it to a new
2215 ice_sched_update_parent(struct ice_sched_node *new_parent,
2216 struct ice_sched_node *node)
2218 struct ice_sched_node *old_parent;
2221 old_parent = node->parent;
2223 /* update the old parent children */
2224 for (i = 0; i < old_parent->num_children; i++)
2225 if (old_parent->children[i] == node) {
2226 for (j = i + 1; j < old_parent->num_children; j++)
2227 old_parent->children[j - 1] =
2228 old_parent->children[j];
2229 old_parent->num_children--;
2233 /* now move the node to a new parent */
2234 new_parent->children[new_parent->num_children++] = node;
2235 node->parent = new_parent;
2236 node->info.parent_teid = new_parent->info.node_teid;
2240 * ice_sched_move_nodes - move child nodes to a given parent
2241 * @pi: port information structure
2242 * @parent: pointer to parent node
2243 * @num_items: number of child nodes to be moved
2244 * @list: pointer to child node teids
2246 * This function move the child nodes to a given parent.
2248 static enum ice_status
2249 ice_sched_move_nodes(struct ice_port_info *pi, struct ice_sched_node *parent,
2250 u16 num_items, u32 *list)
2252 enum ice_status status = ICE_SUCCESS;
2253 struct ice_aqc_move_elem *buf;
2254 struct ice_sched_node *node;
2255 u16 i, grps_movd = 0;
2261 if (!parent || !num_items)
2262 return ICE_ERR_PARAM;
2264 /* Does parent have enough space */
2265 if (parent->num_children + num_items >
2266 hw->max_children[parent->tx_sched_layer])
2267 return ICE_ERR_AQ_FULL;
2269 buf_len = ice_struct_size(buf, teid, 1);
2270 buf = (struct ice_aqc_move_elem *)ice_malloc(hw, buf_len);
2272 return ICE_ERR_NO_MEMORY;
2274 for (i = 0; i < num_items; i++) {
2275 node = ice_sched_find_node_by_teid(pi->root, list[i]);
2277 status = ICE_ERR_PARAM;
2281 buf->hdr.src_parent_teid = node->info.parent_teid;
2282 buf->hdr.dest_parent_teid = parent->info.node_teid;
2283 buf->teid[0] = node->info.node_teid;
2284 buf->hdr.num_elems = CPU_TO_LE16(1);
2285 status = ice_aq_move_sched_elems(hw, 1, buf, buf_len,
2287 if (status && grps_movd != 1) {
2288 status = ICE_ERR_CFG;
2292 /* update the SW DB */
2293 ice_sched_update_parent(parent, node);
2302 * ice_sched_move_vsi_to_agg - move VSI to aggregator node
2303 * @pi: port information structure
2304 * @vsi_handle: software VSI handle
2305 * @agg_id: aggregator ID
2308 * This function moves a VSI to an aggregator node or its subtree.
2309 * Intermediate nodes may be created if required.
2311 static enum ice_status
2312 ice_sched_move_vsi_to_agg(struct ice_port_info *pi, u16 vsi_handle, u32 agg_id,
2315 struct ice_sched_node *vsi_node, *agg_node, *tc_node, *parent;
2316 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
2317 u32 first_node_teid, vsi_teid;
2318 enum ice_status status;
2319 u16 num_nodes_added;
2322 tc_node = ice_sched_get_tc_node(pi, tc);
2326 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2328 return ICE_ERR_DOES_NOT_EXIST;
2330 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
2332 return ICE_ERR_DOES_NOT_EXIST;
2334 /* Is this VSI already part of given aggregator? */
2335 if (ice_sched_find_node_in_subtree(pi->hw, agg_node, vsi_node))
2338 aggl = ice_sched_get_agg_layer(pi->hw);
2339 vsil = ice_sched_get_vsi_layer(pi->hw);
2341 /* set intermediate node count to 1 between aggregator and VSI layers */
2342 for (i = aggl + 1; i < vsil; i++)
2345 /* Check if the aggregator subtree has any free node to add the VSI */
2346 for (i = 0; i < agg_node->num_children; i++) {
2347 parent = ice_sched_get_free_vsi_parent(pi->hw,
2348 agg_node->children[i],
2356 for (i = aggl + 1; i < vsil; i++) {
2357 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
2361 if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added)
2364 /* The newly added node can be a new parent for the next
2367 if (num_nodes_added)
2368 parent = ice_sched_find_node_by_teid(tc_node,
2371 parent = parent->children[0];
2378 vsi_teid = LE32_TO_CPU(vsi_node->info.node_teid);
2379 return ice_sched_move_nodes(pi, parent, 1, &vsi_teid);
2383 * ice_move_all_vsi_to_dflt_agg - move all VSI(s) to default aggregator
2384 * @pi: port information structure
2385 * @agg_info: aggregator info
2386 * @tc: traffic class number
2387 * @rm_vsi_info: true or false
2389 * This function move all the VSI(s) to the default aggregator and delete
2390 * aggregator VSI info based on passed in boolean parameter rm_vsi_info. The
2391 * caller holds the scheduler lock.
2393 static enum ice_status
2394 ice_move_all_vsi_to_dflt_agg(struct ice_port_info *pi,
2395 struct ice_sched_agg_info *agg_info, u8 tc,
2398 struct ice_sched_agg_vsi_info *agg_vsi_info;
2399 struct ice_sched_agg_vsi_info *tmp;
2400 enum ice_status status = ICE_SUCCESS;
2402 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, tmp, &agg_info->agg_vsi_list,
2403 ice_sched_agg_vsi_info, list_entry) {
2404 u16 vsi_handle = agg_vsi_info->vsi_handle;
2406 /* Move VSI to default aggregator */
2407 if (!ice_is_tc_ena(agg_vsi_info->tc_bitmap[0], tc))
2410 status = ice_sched_move_vsi_to_agg(pi, vsi_handle,
2411 ICE_DFLT_AGG_ID, tc);
2415 ice_clear_bit(tc, agg_vsi_info->tc_bitmap);
2416 if (rm_vsi_info && !agg_vsi_info->tc_bitmap[0]) {
2417 LIST_DEL(&agg_vsi_info->list_entry);
2418 ice_free(pi->hw, agg_vsi_info);
2426 * ice_sched_is_agg_inuse - check whether the aggregator is in use or not
2427 * @pi: port information structure
2428 * @node: node pointer
2430 * This function checks whether the aggregator is attached with any VSI or not.
2433 ice_sched_is_agg_inuse(struct ice_port_info *pi, struct ice_sched_node *node)
2437 vsil = ice_sched_get_vsi_layer(pi->hw);
2438 if (node->tx_sched_layer < vsil - 1) {
2439 for (i = 0; i < node->num_children; i++)
2440 if (ice_sched_is_agg_inuse(pi, node->children[i]))
2444 return node->num_children ? true : false;
2449 * ice_sched_rm_agg_cfg - remove the aggregator node
2450 * @pi: port information structure
2451 * @agg_id: aggregator ID
2454 * This function removes the aggregator node and intermediate nodes if any
2457 static enum ice_status
2458 ice_sched_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc)
2460 struct ice_sched_node *tc_node, *agg_node;
2461 struct ice_hw *hw = pi->hw;
2463 tc_node = ice_sched_get_tc_node(pi, tc);
2467 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2469 return ICE_ERR_DOES_NOT_EXIST;
2471 /* Can't remove the aggregator node if it has children */
2472 if (ice_sched_is_agg_inuse(pi, agg_node))
2473 return ICE_ERR_IN_USE;
2475 /* need to remove the whole subtree if aggregator node is the
2478 while (agg_node->tx_sched_layer > hw->sw_entry_point_layer) {
2479 struct ice_sched_node *parent = agg_node->parent;
2484 if (parent->num_children > 1)
2490 ice_free_sched_node(pi, agg_node);
2495 * ice_rm_agg_cfg_tc - remove aggregator configuration for TC
2496 * @pi: port information structure
2497 * @agg_info: aggregator ID
2499 * @rm_vsi_info: bool value true or false
2501 * This function removes aggregator reference to VSI of given TC. It removes
2502 * the aggregator configuration completely for requested TC. The caller needs
2503 * to hold the scheduler lock.
2505 static enum ice_status
2506 ice_rm_agg_cfg_tc(struct ice_port_info *pi, struct ice_sched_agg_info *agg_info,
2507 u8 tc, bool rm_vsi_info)
2509 enum ice_status status = ICE_SUCCESS;
2511 /* If nothing to remove - return success */
2512 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
2513 goto exit_rm_agg_cfg_tc;
2515 status = ice_move_all_vsi_to_dflt_agg(pi, agg_info, tc, rm_vsi_info);
2517 goto exit_rm_agg_cfg_tc;
2519 /* Delete aggregator node(s) */
2520 status = ice_sched_rm_agg_cfg(pi, agg_info->agg_id, tc);
2522 goto exit_rm_agg_cfg_tc;
2524 ice_clear_bit(tc, agg_info->tc_bitmap);
2530 * ice_save_agg_tc_bitmap - save aggregator TC bitmap
2531 * @pi: port information structure
2532 * @agg_id: aggregator ID
2533 * @tc_bitmap: 8 bits TC bitmap
2535 * Save aggregator TC bitmap. This function needs to be called with scheduler
2538 static enum ice_status
2539 ice_save_agg_tc_bitmap(struct ice_port_info *pi, u32 agg_id,
2540 ice_bitmap_t *tc_bitmap)
2542 struct ice_sched_agg_info *agg_info;
2544 agg_info = ice_get_agg_info(pi->hw, agg_id);
2546 return ICE_ERR_PARAM;
2547 ice_cp_bitmap(agg_info->replay_tc_bitmap, tc_bitmap,
2548 ICE_MAX_TRAFFIC_CLASS);
2553 * ice_sched_add_agg_cfg - create an aggregator node
2554 * @pi: port information structure
2555 * @agg_id: aggregator ID
2558 * This function creates an aggregator node and intermediate nodes if required
2561 static enum ice_status
2562 ice_sched_add_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc)
2564 struct ice_sched_node *parent, *agg_node, *tc_node;
2565 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
2566 enum ice_status status = ICE_SUCCESS;
2567 struct ice_hw *hw = pi->hw;
2568 u32 first_node_teid;
2569 u16 num_nodes_added;
2572 tc_node = ice_sched_get_tc_node(pi, tc);
2576 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2577 /* Does Agg node already exist ? */
2581 aggl = ice_sched_get_agg_layer(hw);
2583 /* need one node in Agg layer */
2584 num_nodes[aggl] = 1;
2586 /* Check whether the intermediate nodes have space to add the
2587 * new aggregator. If they are full, then SW needs to allocate a new
2588 * intermediate node on those layers
2590 for (i = hw->sw_entry_point_layer; i < aggl; i++) {
2591 parent = ice_sched_get_first_node(pi, tc_node, i);
2593 /* scan all the siblings */
2595 if (parent->num_children < hw->max_children[i])
2597 parent = parent->sibling;
2600 /* all the nodes are full, reserve one for this layer */
2605 /* add the aggregator node */
2607 for (i = hw->sw_entry_point_layer; i <= aggl; i++) {
2611 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
2615 if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added)
2618 /* The newly added node can be a new parent for the next
2621 if (num_nodes_added) {
2622 parent = ice_sched_find_node_by_teid(tc_node,
2624 /* register aggregator ID with the aggregator node */
2625 if (parent && i == aggl)
2626 parent->agg_id = agg_id;
2628 parent = parent->children[0];
2636 * ice_sched_cfg_agg - configure aggregator node
2637 * @pi: port information structure
2638 * @agg_id: aggregator ID
2639 * @agg_type: aggregator type queue, VSI, or aggregator group
2640 * @tc_bitmap: bits TC bitmap
2642 * It registers a unique aggregator node into scheduler services. It
2643 * allows a user to register with a unique ID to track it's resources.
2644 * The aggregator type determines if this is a queue group, VSI group
2645 * or aggregator group. It then creates the aggregator node(s) for requested
2646 * TC(s) or removes an existing aggregator node including its configuration
2647 * if indicated via tc_bitmap. Call ice_rm_agg_cfg to release aggregator
2648 * resources and remove aggregator ID.
2649 * This function needs to be called with scheduler lock held.
2651 static enum ice_status
2652 ice_sched_cfg_agg(struct ice_port_info *pi, u32 agg_id,
2653 enum ice_agg_type agg_type, ice_bitmap_t *tc_bitmap)
2655 struct ice_sched_agg_info *agg_info;
2656 enum ice_status status = ICE_SUCCESS;
2657 struct ice_hw *hw = pi->hw;
2660 agg_info = ice_get_agg_info(hw, agg_id);
2662 /* Create new entry for new aggregator ID */
2663 agg_info = (struct ice_sched_agg_info *)
2664 ice_malloc(hw, sizeof(*agg_info));
2666 status = ICE_ERR_NO_MEMORY;
2669 agg_info->agg_id = agg_id;
2670 agg_info->agg_type = agg_type;
2671 agg_info->tc_bitmap[0] = 0;
2673 /* Initialize the aggregator VSI list head */
2674 INIT_LIST_HEAD(&agg_info->agg_vsi_list);
2676 /* Add new entry in aggregator list */
2677 LIST_ADD(&agg_info->list_entry, &hw->agg_list);
2679 /* Create aggregator node(s) for requested TC(s) */
2680 ice_for_each_traffic_class(tc) {
2681 if (!ice_is_tc_ena(*tc_bitmap, tc)) {
2682 /* Delete aggregator cfg TC if it exists previously */
2683 status = ice_rm_agg_cfg_tc(pi, agg_info, tc, false);
2689 /* Check if aggregator node for TC already exists */
2690 if (ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
2693 /* Create new aggregator node for TC */
2694 status = ice_sched_add_agg_cfg(pi, agg_id, tc);
2698 /* Save aggregator node's TC information */
2699 ice_set_bit(tc, agg_info->tc_bitmap);
2706 * ice_cfg_agg - config aggregator node
2707 * @pi: port information structure
2708 * @agg_id: aggregator ID
2709 * @agg_type: aggregator type queue, VSI, or aggregator group
2710 * @tc_bitmap: bits TC bitmap
2712 * This function configures aggregator node(s).
2715 ice_cfg_agg(struct ice_port_info *pi, u32 agg_id, enum ice_agg_type agg_type,
2718 ice_bitmap_t bitmap = tc_bitmap;
2719 enum ice_status status;
2721 ice_acquire_lock(&pi->sched_lock);
2722 status = ice_sched_cfg_agg(pi, agg_id, agg_type,
2723 (ice_bitmap_t *)&bitmap);
2725 status = ice_save_agg_tc_bitmap(pi, agg_id,
2726 (ice_bitmap_t *)&bitmap);
2727 ice_release_lock(&pi->sched_lock);
2732 * ice_get_agg_vsi_info - get the aggregator ID
2733 * @agg_info: aggregator info
2734 * @vsi_handle: software VSI handle
2736 * The function returns aggregator VSI info based on VSI handle. This function
2737 * needs to be called with scheduler lock held.
2739 static struct ice_sched_agg_vsi_info *
2740 ice_get_agg_vsi_info(struct ice_sched_agg_info *agg_info, u16 vsi_handle)
2742 struct ice_sched_agg_vsi_info *agg_vsi_info;
2744 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
2745 ice_sched_agg_vsi_info, list_entry)
2746 if (agg_vsi_info->vsi_handle == vsi_handle)
2747 return agg_vsi_info;
2753 * ice_get_vsi_agg_info - get the aggregator info of VSI
2754 * @hw: pointer to the hardware structure
2755 * @vsi_handle: Sw VSI handle
2757 * The function returns aggregator info of VSI represented via vsi_handle. The
2758 * VSI has in this case a different aggregator than the default one. This
2759 * function needs to be called with scheduler lock held.
2761 static struct ice_sched_agg_info *
2762 ice_get_vsi_agg_info(struct ice_hw *hw, u16 vsi_handle)
2764 struct ice_sched_agg_info *agg_info;
2766 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
2768 struct ice_sched_agg_vsi_info *agg_vsi_info;
2770 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2778 * ice_save_agg_vsi_tc_bitmap - save aggregator VSI TC bitmap
2779 * @pi: port information structure
2780 * @agg_id: aggregator ID
2781 * @vsi_handle: software VSI handle
2782 * @tc_bitmap: TC bitmap of enabled TC(s)
2784 * Save VSI to aggregator TC bitmap. This function needs to call with scheduler
2787 static enum ice_status
2788 ice_save_agg_vsi_tc_bitmap(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle,
2789 ice_bitmap_t *tc_bitmap)
2791 struct ice_sched_agg_vsi_info *agg_vsi_info;
2792 struct ice_sched_agg_info *agg_info;
2794 agg_info = ice_get_agg_info(pi->hw, agg_id);
2796 return ICE_ERR_PARAM;
2797 /* check if entry already exist */
2798 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2800 return ICE_ERR_PARAM;
2801 ice_cp_bitmap(agg_vsi_info->replay_tc_bitmap, tc_bitmap,
2802 ICE_MAX_TRAFFIC_CLASS);
2807 * ice_sched_assoc_vsi_to_agg - associate/move VSI to new/default aggregator
2808 * @pi: port information structure
2809 * @agg_id: aggregator ID
2810 * @vsi_handle: software VSI handle
2811 * @tc_bitmap: TC bitmap of enabled TC(s)
2813 * This function moves VSI to a new or default aggregator node. If VSI is
2814 * already associated to the aggregator node then no operation is performed on
2815 * the tree. This function needs to be called with scheduler lock held.
2817 static enum ice_status
2818 ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
2819 u16 vsi_handle, ice_bitmap_t *tc_bitmap)
2821 struct ice_sched_agg_vsi_info *agg_vsi_info;
2822 struct ice_sched_agg_info *agg_info;
2823 enum ice_status status = ICE_SUCCESS;
2824 struct ice_hw *hw = pi->hw;
2827 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
2828 return ICE_ERR_PARAM;
2829 agg_info = ice_get_agg_info(hw, agg_id);
2831 return ICE_ERR_PARAM;
2832 /* check if entry already exist */
2833 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2834 if (!agg_vsi_info) {
2835 /* Create new entry for VSI under aggregator list */
2836 agg_vsi_info = (struct ice_sched_agg_vsi_info *)
2837 ice_malloc(hw, sizeof(*agg_vsi_info));
2839 return ICE_ERR_PARAM;
2841 /* add VSI ID into the aggregator list */
2842 agg_vsi_info->vsi_handle = vsi_handle;
2843 LIST_ADD(&agg_vsi_info->list_entry, &agg_info->agg_vsi_list);
2845 /* Move VSI node to new aggregator node for requested TC(s) */
2846 ice_for_each_traffic_class(tc) {
2847 if (!ice_is_tc_ena(*tc_bitmap, tc))
2850 /* Move VSI to new aggregator */
2851 status = ice_sched_move_vsi_to_agg(pi, vsi_handle, agg_id, tc);
2855 if (agg_id != ICE_DFLT_AGG_ID)
2856 ice_set_bit(tc, agg_vsi_info->tc_bitmap);
2858 ice_clear_bit(tc, agg_vsi_info->tc_bitmap);
2860 /* If VSI moved back to default aggregator, delete agg_vsi_info. */
2861 if (!ice_is_any_bit_set(agg_vsi_info->tc_bitmap,
2862 ICE_MAX_TRAFFIC_CLASS)) {
2863 LIST_DEL(&agg_vsi_info->list_entry);
2864 ice_free(hw, agg_vsi_info);
2870 * ice_sched_rm_unused_rl_prof - remove unused RL profile
2871 * @hw: pointer to the hardware structure
2873 * This function removes unused rate limit profiles from the HW and
2874 * SW DB. The caller needs to hold scheduler lock.
2876 static void ice_sched_rm_unused_rl_prof(struct ice_hw *hw)
2880 for (ln = 0; ln < hw->num_tx_sched_layers; ln++) {
2881 struct ice_aqc_rl_profile_info *rl_prof_elem;
2882 struct ice_aqc_rl_profile_info *rl_prof_tmp;
2884 LIST_FOR_EACH_ENTRY_SAFE(rl_prof_elem, rl_prof_tmp,
2885 &hw->rl_prof_list[ln],
2886 ice_aqc_rl_profile_info, list_entry) {
2887 if (!ice_sched_del_rl_profile(hw, rl_prof_elem))
2888 ice_debug(hw, ICE_DBG_SCHED, "Removed rl profile\n");
2894 * ice_sched_update_elem - update element
2895 * @hw: pointer to the HW struct
2896 * @node: pointer to node
2897 * @info: node info to update
2899 * Update the HW DB, and local SW DB of node. Update the scheduling
2900 * parameters of node from argument info data buffer (Info->data buf) and
2901 * returns success or error on config sched element failure. The caller
2902 * needs to hold scheduler lock.
2904 static enum ice_status
2905 ice_sched_update_elem(struct ice_hw *hw, struct ice_sched_node *node,
2906 struct ice_aqc_txsched_elem_data *info)
2908 struct ice_aqc_txsched_elem_data buf;
2909 enum ice_status status;
2914 /* Parent TEID is reserved field in this aq call */
2915 buf.parent_teid = 0;
2916 /* Element type is reserved field in this aq call */
2917 buf.data.elem_type = 0;
2918 /* Flags is reserved field in this aq call */
2922 /* Configure element node */
2923 status = ice_aq_cfg_sched_elems(hw, num_elems, &buf, sizeof(buf),
2925 if (status || elem_cfgd != num_elems) {
2926 ice_debug(hw, ICE_DBG_SCHED, "Config sched elem error\n");
2930 /* Config success case */
2931 /* Now update local SW DB */
2932 /* Only copy the data portion of info buffer */
2933 node->info.data = info->data;
2938 * ice_sched_cfg_node_bw_alloc - configure node BW weight/alloc params
2939 * @hw: pointer to the HW struct
2940 * @node: sched node to configure
2941 * @rl_type: rate limit type CIR, EIR, or shared
2942 * @bw_alloc: BW weight/allocation
2944 * This function configures node element's BW allocation.
2946 static enum ice_status
2947 ice_sched_cfg_node_bw_alloc(struct ice_hw *hw, struct ice_sched_node *node,
2948 enum ice_rl_type rl_type, u16 bw_alloc)
2950 struct ice_aqc_txsched_elem_data buf;
2951 struct ice_aqc_txsched_elem *data;
2952 enum ice_status status;
2956 if (rl_type == ICE_MIN_BW) {
2957 data->valid_sections |= ICE_AQC_ELEM_VALID_CIR;
2958 data->cir_bw.bw_alloc = CPU_TO_LE16(bw_alloc);
2959 } else if (rl_type == ICE_MAX_BW) {
2960 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
2961 data->eir_bw.bw_alloc = CPU_TO_LE16(bw_alloc);
2963 return ICE_ERR_PARAM;
2966 /* Configure element */
2967 status = ice_sched_update_elem(hw, node, &buf);
2972 * ice_move_vsi_to_agg - moves VSI to new or default aggregator
2973 * @pi: port information structure
2974 * @agg_id: aggregator ID
2975 * @vsi_handle: software VSI handle
2976 * @tc_bitmap: TC bitmap of enabled TC(s)
2978 * Move or associate VSI to a new or default aggregator node.
2981 ice_move_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle,
2984 ice_bitmap_t bitmap = tc_bitmap;
2985 enum ice_status status;
2987 ice_acquire_lock(&pi->sched_lock);
2988 status = ice_sched_assoc_vsi_to_agg(pi, agg_id, vsi_handle,
2989 (ice_bitmap_t *)&bitmap);
2991 status = ice_save_agg_vsi_tc_bitmap(pi, agg_id, vsi_handle,
2992 (ice_bitmap_t *)&bitmap);
2993 ice_release_lock(&pi->sched_lock);
2998 * ice_rm_agg_cfg - remove aggregator configuration
2999 * @pi: port information structure
3000 * @agg_id: aggregator ID
3002 * This function removes aggregator reference to VSI and delete aggregator ID
3003 * info. It removes the aggregator configuration completely.
3005 enum ice_status ice_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id)
3007 struct ice_sched_agg_info *agg_info;
3008 enum ice_status status = ICE_SUCCESS;
3011 ice_acquire_lock(&pi->sched_lock);
3012 agg_info = ice_get_agg_info(pi->hw, agg_id);
3014 status = ICE_ERR_DOES_NOT_EXIST;
3015 goto exit_ice_rm_agg_cfg;
3018 ice_for_each_traffic_class(tc) {
3019 status = ice_rm_agg_cfg_tc(pi, agg_info, tc, true);
3021 goto exit_ice_rm_agg_cfg;
3024 if (ice_is_any_bit_set(agg_info->tc_bitmap, ICE_MAX_TRAFFIC_CLASS)) {
3025 status = ICE_ERR_IN_USE;
3026 goto exit_ice_rm_agg_cfg;
3029 /* Safe to delete entry now */
3030 LIST_DEL(&agg_info->list_entry);
3031 ice_free(pi->hw, agg_info);
3033 /* Remove unused RL profile IDs from HW and SW DB */
3034 ice_sched_rm_unused_rl_prof(pi->hw);
3036 exit_ice_rm_agg_cfg:
3037 ice_release_lock(&pi->sched_lock);
3042 * ice_set_clear_cir_bw_alloc - set or clear CIR BW alloc information
3043 * @bw_t_info: bandwidth type information structure
3044 * @bw_alloc: Bandwidth allocation information
3046 * Save or clear CIR BW alloc information (bw_alloc) in the passed param
3050 ice_set_clear_cir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc)
3052 bw_t_info->cir_bw.bw_alloc = bw_alloc;
3053 if (bw_t_info->cir_bw.bw_alloc)
3054 ice_set_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap);
3056 ice_clear_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap);
3060 * ice_set_clear_eir_bw_alloc - set or clear EIR BW alloc information
3061 * @bw_t_info: bandwidth type information structure
3062 * @bw_alloc: Bandwidth allocation information
3064 * Save or clear EIR BW alloc information (bw_alloc) in the passed param
3068 ice_set_clear_eir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc)
3070 bw_t_info->eir_bw.bw_alloc = bw_alloc;
3071 if (bw_t_info->eir_bw.bw_alloc)
3072 ice_set_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap);
3074 ice_clear_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap);
3078 * ice_sched_save_vsi_bw_alloc - save VSI node's BW alloc information
3079 * @pi: port information structure
3080 * @vsi_handle: sw VSI handle
3081 * @tc: traffic class
3082 * @rl_type: rate limit type min or max
3083 * @bw_alloc: Bandwidth allocation information
3085 * Save BW alloc information of VSI type node for post replay use.
3087 static enum ice_status
3088 ice_sched_save_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3089 enum ice_rl_type rl_type, u16 bw_alloc)
3091 struct ice_vsi_ctx *vsi_ctx;
3093 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3094 return ICE_ERR_PARAM;
3095 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3097 return ICE_ERR_PARAM;
3100 ice_set_clear_cir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc],
3104 ice_set_clear_eir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc],
3108 return ICE_ERR_PARAM;
3114 * ice_set_clear_cir_bw - set or clear CIR BW
3115 * @bw_t_info: bandwidth type information structure
3116 * @bw: bandwidth in Kbps - Kilo bits per sec
3118 * Save or clear CIR bandwidth (BW) in the passed param bw_t_info.
3120 static void ice_set_clear_cir_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3122 if (bw == ICE_SCHED_DFLT_BW) {
3123 ice_clear_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap);
3124 bw_t_info->cir_bw.bw = 0;
3126 /* Save type of BW information */
3127 ice_set_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap);
3128 bw_t_info->cir_bw.bw = bw;
3133 * ice_set_clear_eir_bw - set or clear EIR BW
3134 * @bw_t_info: bandwidth type information structure
3135 * @bw: bandwidth in Kbps - Kilo bits per sec
3137 * Save or clear EIR bandwidth (BW) in the passed param bw_t_info.
3139 static void ice_set_clear_eir_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3141 if (bw == ICE_SCHED_DFLT_BW) {
3142 ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3143 bw_t_info->eir_bw.bw = 0;
3145 /* EIR BW and Shared BW profiles are mutually exclusive and
3146 * hence only one of them may be set for any given element.
3147 * First clear earlier saved shared BW information.
3149 ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3150 bw_t_info->shared_bw = 0;
3151 /* save EIR BW information */
3152 ice_set_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3153 bw_t_info->eir_bw.bw = bw;
3158 * ice_set_clear_shared_bw - set or clear shared BW
3159 * @bw_t_info: bandwidth type information structure
3160 * @bw: bandwidth in Kbps - Kilo bits per sec
3162 * Save or clear shared bandwidth (BW) in the passed param bw_t_info.
3164 static void ice_set_clear_shared_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3166 if (bw == ICE_SCHED_DFLT_BW) {
3167 ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3168 bw_t_info->shared_bw = 0;
3170 /* EIR BW and Shared BW profiles are mutually exclusive and
3171 * hence only one of them may be set for any given element.
3172 * First clear earlier saved EIR BW information.
3174 ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3175 bw_t_info->eir_bw.bw = 0;
3176 /* save shared BW information */
3177 ice_set_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3178 bw_t_info->shared_bw = bw;
3183 * ice_sched_save_vsi_bw - save VSI node's BW information
3184 * @pi: port information structure
3185 * @vsi_handle: sw VSI handle
3186 * @tc: traffic class
3187 * @rl_type: rate limit type min, max, or shared
3188 * @bw: bandwidth in Kbps - Kilo bits per sec
3190 * Save BW information of VSI type node for post replay use.
3192 static enum ice_status
3193 ice_sched_save_vsi_bw(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3194 enum ice_rl_type rl_type, u32 bw)
3196 struct ice_vsi_ctx *vsi_ctx;
3198 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3199 return ICE_ERR_PARAM;
3200 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3202 return ICE_ERR_PARAM;
3205 ice_set_clear_cir_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3208 ice_set_clear_eir_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3211 ice_set_clear_shared_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3214 return ICE_ERR_PARAM;
3220 * ice_set_clear_prio - set or clear priority information
3221 * @bw_t_info: bandwidth type information structure
3222 * @prio: priority to save
3224 * Save or clear priority (prio) in the passed param bw_t_info.
3226 static void ice_set_clear_prio(struct ice_bw_type_info *bw_t_info, u8 prio)
3228 bw_t_info->generic = prio;
3229 if (bw_t_info->generic)
3230 ice_set_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap);
3232 ice_clear_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap);
3236 * ice_sched_save_vsi_prio - save VSI node's priority information
3237 * @pi: port information structure
3238 * @vsi_handle: Software VSI handle
3239 * @tc: traffic class
3240 * @prio: priority to save
3242 * Save priority information of VSI type node for post replay use.
3244 static enum ice_status
3245 ice_sched_save_vsi_prio(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3248 struct ice_vsi_ctx *vsi_ctx;
3250 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3251 return ICE_ERR_PARAM;
3252 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3254 return ICE_ERR_PARAM;
3255 if (tc >= ICE_MAX_TRAFFIC_CLASS)
3256 return ICE_ERR_PARAM;
3257 ice_set_clear_prio(&vsi_ctx->sched.bw_t_info[tc], prio);
3262 * ice_sched_save_agg_bw_alloc - save aggregator node's BW alloc information
3263 * @pi: port information structure
3264 * @agg_id: node aggregator ID
3265 * @tc: traffic class
3266 * @rl_type: rate limit type min or max
3267 * @bw_alloc: bandwidth alloc information
3269 * Save BW alloc information of AGG type node for post replay use.
3271 static enum ice_status
3272 ice_sched_save_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3273 enum ice_rl_type rl_type, u16 bw_alloc)
3275 struct ice_sched_agg_info *agg_info;
3277 agg_info = ice_get_agg_info(pi->hw, agg_id);
3279 return ICE_ERR_PARAM;
3280 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
3281 return ICE_ERR_PARAM;
3284 ice_set_clear_cir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc);
3287 ice_set_clear_eir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc);
3290 return ICE_ERR_PARAM;
3296 * ice_sched_save_agg_bw - save aggregator node's BW information
3297 * @pi: port information structure
3298 * @agg_id: node aggregator ID
3299 * @tc: traffic class
3300 * @rl_type: rate limit type min, max, or shared
3301 * @bw: bandwidth in Kbps - Kilo bits per sec
3303 * Save BW information of AGG type node for post replay use.
3305 static enum ice_status
3306 ice_sched_save_agg_bw(struct ice_port_info *pi, u32 agg_id, u8 tc,
3307 enum ice_rl_type rl_type, u32 bw)
3309 struct ice_sched_agg_info *agg_info;
3311 agg_info = ice_get_agg_info(pi->hw, agg_id);
3313 return ICE_ERR_PARAM;
3314 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
3315 return ICE_ERR_PARAM;
3318 ice_set_clear_cir_bw(&agg_info->bw_t_info[tc], bw);
3321 ice_set_clear_eir_bw(&agg_info->bw_t_info[tc], bw);
3324 ice_set_clear_shared_bw(&agg_info->bw_t_info[tc], bw);
3327 return ICE_ERR_PARAM;
3333 * ice_cfg_vsi_bw_lmt_per_tc - configure VSI BW limit per TC
3334 * @pi: port information structure
3335 * @vsi_handle: software VSI handle
3336 * @tc: traffic class
3337 * @rl_type: min or max
3338 * @bw: bandwidth in Kbps
3340 * This function configures BW limit of VSI scheduling node based on TC
3344 ice_cfg_vsi_bw_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3345 enum ice_rl_type rl_type, u32 bw)
3347 enum ice_status status;
3349 status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle,
3353 ice_acquire_lock(&pi->sched_lock);
3354 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw);
3355 ice_release_lock(&pi->sched_lock);
3361 * ice_cfg_dflt_vsi_bw_lmt_per_tc - configure default VSI BW limit per TC
3362 * @pi: port information structure
3363 * @vsi_handle: software VSI handle
3364 * @tc: traffic class
3365 * @rl_type: min or max
3367 * This function configures default BW limit of VSI scheduling node based on TC
3371 ice_cfg_vsi_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3372 enum ice_rl_type rl_type)
3374 enum ice_status status;
3376 status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle,
3381 ice_acquire_lock(&pi->sched_lock);
3382 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type,
3384 ice_release_lock(&pi->sched_lock);
3390 * ice_cfg_agg_bw_lmt_per_tc - configure aggregator BW limit per TC
3391 * @pi: port information structure
3392 * @agg_id: aggregator ID
3393 * @tc: traffic class
3394 * @rl_type: min or max
3395 * @bw: bandwidth in Kbps
3397 * This function applies BW limit to aggregator scheduling node based on TC
3401 ice_cfg_agg_bw_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3402 enum ice_rl_type rl_type, u32 bw)
3404 enum ice_status status;
3406 status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG,
3409 ice_acquire_lock(&pi->sched_lock);
3410 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw);
3411 ice_release_lock(&pi->sched_lock);
3417 * ice_cfg_agg_bw_dflt_lmt_per_tc - configure aggregator BW default limit per TC
3418 * @pi: port information structure
3419 * @agg_id: aggregator ID
3420 * @tc: traffic class
3421 * @rl_type: min or max
3423 * This function applies default BW limit to aggregator scheduling node based
3424 * on TC information.
3427 ice_cfg_agg_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3428 enum ice_rl_type rl_type)
3430 enum ice_status status;
3432 status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG,
3436 ice_acquire_lock(&pi->sched_lock);
3437 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type,
3439 ice_release_lock(&pi->sched_lock);
3445 * ice_cfg_vsi_bw_shared_lmt - configure VSI BW shared limit
3446 * @pi: port information structure
3447 * @vsi_handle: software VSI handle
3448 * @bw: bandwidth in Kbps
3450 * This function Configures shared rate limiter(SRL) of all VSI type nodes
3451 * across all traffic classes for VSI matching handle.
3454 ice_cfg_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle, u32 bw)
3456 return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle, bw);
3460 * ice_cfg_vsi_bw_no_shared_lmt - configure VSI BW for no shared limiter
3461 * @pi: port information structure
3462 * @vsi_handle: software VSI handle
3464 * This function removes the shared rate limiter(SRL) of all VSI type nodes
3465 * across all traffic classes for VSI matching handle.
3468 ice_cfg_vsi_bw_no_shared_lmt(struct ice_port_info *pi, u16 vsi_handle)
3470 return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle,
3475 * ice_cfg_agg_bw_shared_lmt - configure aggregator BW shared limit
3476 * @pi: port information structure
3477 * @agg_id: aggregator ID
3478 * @bw: bandwidth in Kbps
3480 * This function configures the shared rate limiter(SRL) of all aggregator type
3481 * nodes across all traffic classes for aggregator matching agg_id.
3484 ice_cfg_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw)
3486 return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, bw);
3490 * ice_cfg_agg_bw_no_shared_lmt - configure aggregator BW for no shared limiter
3491 * @pi: port information structure
3492 * @agg_id: aggregator ID
3494 * This function removes the shared rate limiter(SRL) of all aggregator type
3495 * nodes across all traffic classes for aggregator matching agg_id.
3498 ice_cfg_agg_bw_no_shared_lmt(struct ice_port_info *pi, u32 agg_id)
3500 return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, ICE_SCHED_DFLT_BW);
3504 * ice_config_vsi_queue_priority - config VSI queue priority of node
3505 * @pi: port information structure
3506 * @num_qs: number of VSI queues
3507 * @q_ids: queue IDs array
3508 * @q_prio: queue priority array
3510 * This function configures the queue node priority (Sibling Priority) of the
3511 * passed in VSI's queue(s) for a given traffic class (TC).
3514 ice_cfg_vsi_q_priority(struct ice_port_info *pi, u16 num_qs, u32 *q_ids,
3517 enum ice_status status = ICE_ERR_PARAM;
3520 ice_acquire_lock(&pi->sched_lock);
3522 for (i = 0; i < num_qs; i++) {
3523 struct ice_sched_node *node;
3525 node = ice_sched_find_node_by_teid(pi->root, q_ids[i]);
3526 if (!node || node->info.data.elem_type !=
3527 ICE_AQC_ELEM_TYPE_LEAF) {
3528 status = ICE_ERR_PARAM;
3531 /* Configure Priority */
3532 status = ice_sched_cfg_sibl_node_prio(pi, node, q_prio[i]);
3537 ice_release_lock(&pi->sched_lock);
3542 * ice_cfg_agg_vsi_priority_per_tc - config aggregator's VSI priority per TC
3543 * @pi: port information structure
3544 * @agg_id: Aggregator ID
3545 * @num_vsis: number of VSI(s)
3546 * @vsi_handle_arr: array of software VSI handles
3547 * @node_prio: pointer to node priority
3548 * @tc: traffic class
3550 * This function configures the node priority (Sibling Priority) of the
3551 * passed in VSI's for a given traffic class (TC) of an Aggregator ID.
3554 ice_cfg_agg_vsi_priority_per_tc(struct ice_port_info *pi, u32 agg_id,
3555 u16 num_vsis, u16 *vsi_handle_arr,
3556 u8 *node_prio, u8 tc)
3558 struct ice_sched_agg_vsi_info *agg_vsi_info;
3559 struct ice_sched_node *tc_node, *agg_node;
3560 enum ice_status status = ICE_ERR_PARAM;
3561 struct ice_sched_agg_info *agg_info;
3562 bool agg_id_present = false;
3563 struct ice_hw *hw = pi->hw;
3566 ice_acquire_lock(&pi->sched_lock);
3567 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
3569 if (agg_info->agg_id == agg_id) {
3570 agg_id_present = true;
3573 if (!agg_id_present)
3574 goto exit_agg_priority_per_tc;
3576 tc_node = ice_sched_get_tc_node(pi, tc);
3578 goto exit_agg_priority_per_tc;
3580 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
3582 goto exit_agg_priority_per_tc;
3584 if (num_vsis > hw->max_children[agg_node->tx_sched_layer])
3585 goto exit_agg_priority_per_tc;
3587 for (i = 0; i < num_vsis; i++) {
3588 struct ice_sched_node *vsi_node;
3589 bool vsi_handle_valid = false;
3592 status = ICE_ERR_PARAM;
3593 vsi_handle = vsi_handle_arr[i];
3594 if (!ice_is_vsi_valid(hw, vsi_handle))
3595 goto exit_agg_priority_per_tc;
3596 /* Verify child nodes before applying settings */
3597 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
3598 ice_sched_agg_vsi_info, list_entry)
3599 if (agg_vsi_info->vsi_handle == vsi_handle) {
3600 /* cppcheck-suppress unreadVariable */
3601 vsi_handle_valid = true;
3605 if (!vsi_handle_valid)
3606 goto exit_agg_priority_per_tc;
3608 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
3610 goto exit_agg_priority_per_tc;
3612 if (ice_sched_find_node_in_subtree(hw, agg_node, vsi_node)) {
3613 /* Configure Priority */
3614 status = ice_sched_cfg_sibl_node_prio(pi, vsi_node,
3618 status = ice_sched_save_vsi_prio(pi, vsi_handle, tc,
3625 exit_agg_priority_per_tc:
3626 ice_release_lock(&pi->sched_lock);
3631 * ice_cfg_vsi_bw_alloc - config VSI BW alloc per TC
3632 * @pi: port information structure
3633 * @vsi_handle: software VSI handle
3634 * @ena_tcmap: enabled TC map
3635 * @rl_type: Rate limit type CIR/EIR
3636 * @bw_alloc: Array of BW alloc
3638 * This function configures the BW allocation of the passed in VSI's
3639 * node(s) for enabled traffic class.
3642 ice_cfg_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 ena_tcmap,
3643 enum ice_rl_type rl_type, u8 *bw_alloc)
3645 enum ice_status status = ICE_SUCCESS;
3648 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3649 return ICE_ERR_PARAM;
3651 ice_acquire_lock(&pi->sched_lock);
3653 /* Return success if no nodes are present across TC */
3654 ice_for_each_traffic_class(tc) {
3655 struct ice_sched_node *tc_node, *vsi_node;
3657 if (!ice_is_tc_ena(ena_tcmap, tc))
3660 tc_node = ice_sched_get_tc_node(pi, tc);
3664 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
3668 status = ice_sched_cfg_node_bw_alloc(pi->hw, vsi_node, rl_type,
3672 status = ice_sched_save_vsi_bw_alloc(pi, vsi_handle, tc,
3673 rl_type, bw_alloc[tc]);
3678 ice_release_lock(&pi->sched_lock);
3683 * ice_cfg_agg_bw_alloc - config aggregator BW alloc
3684 * @pi: port information structure
3685 * @agg_id: aggregator ID
3686 * @ena_tcmap: enabled TC map
3687 * @rl_type: rate limit type CIR/EIR
3688 * @bw_alloc: array of BW alloc
3690 * This function configures the BW allocation of passed in aggregator for
3691 * enabled traffic class(s).
3694 ice_cfg_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 ena_tcmap,
3695 enum ice_rl_type rl_type, u8 *bw_alloc)
3697 struct ice_sched_agg_info *agg_info;
3698 bool agg_id_present = false;
3699 enum ice_status status = ICE_SUCCESS;
3700 struct ice_hw *hw = pi->hw;
3703 ice_acquire_lock(&pi->sched_lock);
3704 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
3706 if (agg_info->agg_id == agg_id) {
3707 agg_id_present = true;
3710 if (!agg_id_present) {
3711 status = ICE_ERR_PARAM;
3712 goto exit_cfg_agg_bw_alloc;
3715 /* Return success if no nodes are present across TC */
3716 ice_for_each_traffic_class(tc) {
3717 struct ice_sched_node *tc_node, *agg_node;
3719 if (!ice_is_tc_ena(ena_tcmap, tc))
3722 tc_node = ice_sched_get_tc_node(pi, tc);
3726 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
3730 status = ice_sched_cfg_node_bw_alloc(hw, agg_node, rl_type,
3734 status = ice_sched_save_agg_bw_alloc(pi, agg_id, tc, rl_type,
3740 exit_cfg_agg_bw_alloc:
3741 ice_release_lock(&pi->sched_lock);
3746 * ice_sched_calc_wakeup - calculate RL profile wakeup parameter
3747 * @hw: pointer to the HW struct
3748 * @bw: bandwidth in Kbps
3750 * This function calculates the wakeup parameter of RL profile.
3752 static u16 ice_sched_calc_wakeup(struct ice_hw *hw, s32 bw)
3754 s64 bytes_per_sec, wakeup_int, wakeup_a, wakeup_b, wakeup_f;
3758 /* Get the wakeup integer value */
3759 bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE);
3760 wakeup_int = DIV_64BIT(hw->psm_clk_freq, bytes_per_sec);
3761 if (wakeup_int > 63) {
3762 wakeup = (u16)((1 << 15) | wakeup_int);
3764 /* Calculate fraction value up to 4 decimals
3765 * Convert Integer value to a constant multiplier
3767 wakeup_b = (s64)ICE_RL_PROF_MULTIPLIER * wakeup_int;
3768 wakeup_a = DIV_64BIT((s64)ICE_RL_PROF_MULTIPLIER *
3769 hw->psm_clk_freq, bytes_per_sec);
3771 /* Get Fraction value */
3772 wakeup_f = wakeup_a - wakeup_b;
3774 /* Round up the Fractional value via Ceil(Fractional value) */
3775 if (wakeup_f > DIV_64BIT(ICE_RL_PROF_MULTIPLIER, 2))
3778 wakeup_f_int = (s32)DIV_64BIT(wakeup_f * ICE_RL_PROF_FRACTION,
3779 ICE_RL_PROF_MULTIPLIER);
3780 wakeup |= (u16)(wakeup_int << 9);
3781 wakeup |= (u16)(0x1ff & wakeup_f_int);
3788 * ice_sched_bw_to_rl_profile - convert BW to profile parameters
3789 * @hw: pointer to the HW struct
3790 * @bw: bandwidth in Kbps
3791 * @profile: profile parameters to return
3793 * This function converts the BW to profile structure format.
3795 static enum ice_status
3796 ice_sched_bw_to_rl_profile(struct ice_hw *hw, u32 bw,
3797 struct ice_aqc_rl_profile_elem *profile)
3799 enum ice_status status = ICE_ERR_PARAM;
3800 s64 bytes_per_sec, ts_rate, mv_tmp;
3806 /* Bw settings range is from 0.5Mb/sec to 100Gb/sec */
3807 if (bw < ICE_SCHED_MIN_BW || bw > ICE_SCHED_MAX_BW)
3810 /* Bytes per second from Kbps */
3811 bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE);
3813 /* encode is 6 bits but really useful are 5 bits */
3814 for (i = 0; i < 64; i++) {
3815 u64 pow_result = BIT_ULL(i);
3817 ts_rate = DIV_64BIT((s64)hw->psm_clk_freq,
3818 pow_result * ICE_RL_PROF_TS_MULTIPLIER);
3822 /* Multiplier value */
3823 mv_tmp = DIV_64BIT(bytes_per_sec * ICE_RL_PROF_MULTIPLIER,
3826 /* Round to the nearest ICE_RL_PROF_MULTIPLIER */
3827 mv = round_up_64bit(mv_tmp, ICE_RL_PROF_MULTIPLIER);
3829 /* First multiplier value greater than the given
3832 if (mv > ICE_RL_PROF_ACCURACY_BYTES) {
3841 wm = ice_sched_calc_wakeup(hw, bw);
3842 profile->rl_multiply = CPU_TO_LE16(mv);
3843 profile->wake_up_calc = CPU_TO_LE16(wm);
3844 profile->rl_encode = CPU_TO_LE16(encode);
3845 status = ICE_SUCCESS;
3847 status = ICE_ERR_DOES_NOT_EXIST;
3854 * ice_sched_add_rl_profile - add RL profile
3855 * @hw: pointer to the hardware structure
3856 * @rl_type: type of rate limit BW - min, max, or shared
3857 * @bw: bandwidth in Kbps - Kilo bits per sec
3858 * @layer_num: specifies in which layer to create profile
3860 * This function first checks the existing list for corresponding BW
3861 * parameter. If it exists, it returns the associated profile otherwise
3862 * it creates a new rate limit profile for requested BW, and adds it to
3863 * the HW DB and local list. It returns the new profile or null on error.
3864 * The caller needs to hold the scheduler lock.
3866 static struct ice_aqc_rl_profile_info *
3867 ice_sched_add_rl_profile(struct ice_hw *hw, enum ice_rl_type rl_type,
3868 u32 bw, u8 layer_num)
3870 struct ice_aqc_rl_profile_info *rl_prof_elem;
3871 u16 profiles_added = 0, num_profiles = 1;
3872 struct ice_aqc_rl_profile_elem *buf;
3873 enum ice_status status;
3876 if (layer_num >= ICE_AQC_TOPO_MAX_LEVEL_NUM)
3880 profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR;
3883 profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR;
3886 profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL;
3894 LIST_FOR_EACH_ENTRY(rl_prof_elem, &hw->rl_prof_list[layer_num],
3895 ice_aqc_rl_profile_info, list_entry)
3896 if ((rl_prof_elem->profile.flags & ICE_AQC_RL_PROFILE_TYPE_M) ==
3897 profile_type && rl_prof_elem->bw == bw)
3898 /* Return existing profile ID info */
3899 return rl_prof_elem;
3901 /* Create new profile ID */
3902 rl_prof_elem = (struct ice_aqc_rl_profile_info *)
3903 ice_malloc(hw, sizeof(*rl_prof_elem));
3908 status = ice_sched_bw_to_rl_profile(hw, bw, &rl_prof_elem->profile);
3909 if (status != ICE_SUCCESS)
3910 goto exit_add_rl_prof;
3912 rl_prof_elem->bw = bw;
3913 /* layer_num is zero relative, and fw expects level from 1 to 9 */
3914 rl_prof_elem->profile.level = layer_num + 1;
3915 rl_prof_elem->profile.flags = profile_type;
3916 rl_prof_elem->profile.max_burst_size = CPU_TO_LE16(hw->max_burst_size);
3918 /* Create new entry in HW DB */
3919 buf = &rl_prof_elem->profile;
3920 status = ice_aq_add_rl_profile(hw, num_profiles, buf, sizeof(*buf),
3921 &profiles_added, NULL);
3922 if (status || profiles_added != num_profiles)
3923 goto exit_add_rl_prof;
3925 /* Good entry - add in the list */
3926 rl_prof_elem->prof_id_ref = 0;
3927 LIST_ADD(&rl_prof_elem->list_entry, &hw->rl_prof_list[layer_num]);
3928 return rl_prof_elem;
3931 ice_free(hw, rl_prof_elem);
3936 * ice_sched_cfg_node_bw_lmt - configure node sched params
3937 * @hw: pointer to the HW struct
3938 * @node: sched node to configure
3939 * @rl_type: rate limit type CIR, EIR, or shared
3940 * @rl_prof_id: rate limit profile ID
3942 * This function configures node element's BW limit.
3944 static enum ice_status
3945 ice_sched_cfg_node_bw_lmt(struct ice_hw *hw, struct ice_sched_node *node,
3946 enum ice_rl_type rl_type, u16 rl_prof_id)
3948 struct ice_aqc_txsched_elem_data buf;
3949 struct ice_aqc_txsched_elem *data;
3955 data->valid_sections |= ICE_AQC_ELEM_VALID_CIR;
3956 data->cir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id);
3959 /* EIR BW and Shared BW profiles are mutually exclusive and
3960 * hence only one of them may be set for any given element
3962 if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED)
3964 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
3965 data->eir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id);
3968 /* Check for removing shared BW */
3969 if (rl_prof_id == ICE_SCHED_NO_SHARED_RL_PROF_ID) {
3970 /* remove shared profile */
3971 data->valid_sections &= ~ICE_AQC_ELEM_VALID_SHARED;
3972 data->srl_id = 0; /* clear SRL field */
3974 /* enable back EIR to default profile */
3975 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
3976 data->eir_bw.bw_profile_idx =
3977 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
3980 /* EIR BW and Shared BW profiles are mutually exclusive and
3981 * hence only one of them may be set for any given element
3983 if ((data->valid_sections & ICE_AQC_ELEM_VALID_EIR) &&
3984 (LE16_TO_CPU(data->eir_bw.bw_profile_idx) !=
3985 ICE_SCHED_DFLT_RL_PROF_ID))
3987 /* EIR BW is set to default, disable it */
3988 data->valid_sections &= ~ICE_AQC_ELEM_VALID_EIR;
3989 /* Okay to enable shared BW now */
3990 data->valid_sections |= ICE_AQC_ELEM_VALID_SHARED;
3991 data->srl_id = CPU_TO_LE16(rl_prof_id);
3994 /* Unknown rate limit type */
3995 return ICE_ERR_PARAM;
3998 /* Configure element */
3999 return ice_sched_update_elem(hw, node, &buf);
4003 * ice_sched_get_node_rl_prof_id - get node's rate limit profile ID
4005 * @rl_type: rate limit type
4007 * If existing profile matches, it returns the corresponding rate
4008 * limit profile ID, otherwise it returns an invalid ID as error.
4011 ice_sched_get_node_rl_prof_id(struct ice_sched_node *node,
4012 enum ice_rl_type rl_type)
4014 u16 rl_prof_id = ICE_SCHED_INVAL_PROF_ID;
4015 struct ice_aqc_txsched_elem *data;
4017 data = &node->info.data;
4020 if (data->valid_sections & ICE_AQC_ELEM_VALID_CIR)
4021 rl_prof_id = LE16_TO_CPU(data->cir_bw.bw_profile_idx);
4024 if (data->valid_sections & ICE_AQC_ELEM_VALID_EIR)
4025 rl_prof_id = LE16_TO_CPU(data->eir_bw.bw_profile_idx);
4028 if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED)
4029 rl_prof_id = LE16_TO_CPU(data->srl_id);
4039 * ice_sched_get_rl_prof_layer - selects rate limit profile creation layer
4040 * @pi: port information structure
4041 * @rl_type: type of rate limit BW - min, max, or shared
4042 * @layer_index: layer index
4044 * This function returns requested profile creation layer.
4047 ice_sched_get_rl_prof_layer(struct ice_port_info *pi, enum ice_rl_type rl_type,
4050 struct ice_hw *hw = pi->hw;
4052 if (layer_index >= hw->num_tx_sched_layers)
4053 return ICE_SCHED_INVAL_LAYER_NUM;
4056 if (hw->layer_info[layer_index].max_cir_rl_profiles)
4060 if (hw->layer_info[layer_index].max_eir_rl_profiles)
4064 /* if current layer doesn't support SRL profile creation
4065 * then try a layer up or down.
4067 if (hw->layer_info[layer_index].max_srl_profiles)
4069 else if (layer_index < hw->num_tx_sched_layers - 1 &&
4070 hw->layer_info[layer_index + 1].max_srl_profiles)
4071 return layer_index + 1;
4072 else if (layer_index > 0 &&
4073 hw->layer_info[layer_index - 1].max_srl_profiles)
4074 return layer_index - 1;
4079 return ICE_SCHED_INVAL_LAYER_NUM;
4083 * ice_sched_get_srl_node - get shared rate limit node
4085 * @srl_layer: shared rate limit layer
4087 * This function returns SRL node to be used for shared rate limit purpose.
4088 * The caller needs to hold scheduler lock.
4090 static struct ice_sched_node *
4091 ice_sched_get_srl_node(struct ice_sched_node *node, u8 srl_layer)
4093 if (srl_layer > node->tx_sched_layer)
4094 return node->children[0];
4095 else if (srl_layer < node->tx_sched_layer)
4096 /* Node can't be created without a parent. It will always
4097 * have a valid parent except root node.
4099 return node->parent;
4105 * ice_sched_rm_rl_profile - remove RL profile ID
4106 * @hw: pointer to the hardware structure
4107 * @layer_num: layer number where profiles are saved
4108 * @profile_type: profile type like EIR, CIR, or SRL
4109 * @profile_id: profile ID to remove
4111 * This function removes rate limit profile from layer 'layer_num' of type
4112 * 'profile_type' and profile ID as 'profile_id'. The caller needs to hold
4115 static enum ice_status
4116 ice_sched_rm_rl_profile(struct ice_hw *hw, u8 layer_num, u8 profile_type,
4119 struct ice_aqc_rl_profile_info *rl_prof_elem;
4120 enum ice_status status = ICE_SUCCESS;
4122 if (layer_num >= ICE_AQC_TOPO_MAX_LEVEL_NUM)
4123 return ICE_ERR_PARAM;
4124 /* Check the existing list for RL profile */
4125 LIST_FOR_EACH_ENTRY(rl_prof_elem, &hw->rl_prof_list[layer_num],
4126 ice_aqc_rl_profile_info, list_entry)
4127 if ((rl_prof_elem->profile.flags & ICE_AQC_RL_PROFILE_TYPE_M) ==
4129 LE16_TO_CPU(rl_prof_elem->profile.profile_id) ==
4131 if (rl_prof_elem->prof_id_ref)
4132 rl_prof_elem->prof_id_ref--;
4134 /* Remove old profile ID from database */
4135 status = ice_sched_del_rl_profile(hw, rl_prof_elem);
4136 if (status && status != ICE_ERR_IN_USE)
4137 ice_debug(hw, ICE_DBG_SCHED, "Remove rl profile failed\n");
4140 if (status == ICE_ERR_IN_USE)
4141 status = ICE_SUCCESS;
4146 * ice_sched_set_node_bw_dflt - set node's bandwidth limit to default
4147 * @pi: port information structure
4148 * @node: pointer to node structure
4149 * @rl_type: rate limit type min, max, or shared
4150 * @layer_num: layer number where RL profiles are saved
4152 * This function configures node element's BW rate limit profile ID of
4153 * type CIR, EIR, or SRL to default. This function needs to be called
4154 * with the scheduler lock held.
4156 static enum ice_status
4157 ice_sched_set_node_bw_dflt(struct ice_port_info *pi,
4158 struct ice_sched_node *node,
4159 enum ice_rl_type rl_type, u8 layer_num)
4161 enum ice_status status;
4170 profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR;
4171 rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID;
4174 profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR;
4175 rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID;
4178 profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL;
4179 /* No SRL is configured for default case */
4180 rl_prof_id = ICE_SCHED_NO_SHARED_RL_PROF_ID;
4183 return ICE_ERR_PARAM;
4185 /* Save existing RL prof ID for later clean up */
4186 old_id = ice_sched_get_node_rl_prof_id(node, rl_type);
4187 /* Configure BW scheduling parameters */
4188 status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id);
4192 /* Remove stale RL profile ID */
4193 if (old_id == ICE_SCHED_DFLT_RL_PROF_ID ||
4194 old_id == ICE_SCHED_INVAL_PROF_ID)
4197 return ice_sched_rm_rl_profile(hw, layer_num, profile_type, old_id);
4201 * ice_sched_set_eir_srl_excl - set EIR/SRL exclusiveness
4202 * @pi: port information structure
4203 * @node: pointer to node structure
4204 * @layer_num: layer number where rate limit profiles are saved
4205 * @rl_type: rate limit type min, max, or shared
4206 * @bw: bandwidth value
4208 * This function prepares node element's bandwidth to SRL or EIR exclusively.
4209 * EIR BW and Shared BW profiles are mutually exclusive and hence only one of
4210 * them may be set for any given element. This function needs to be called
4211 * with the scheduler lock held.
4213 static enum ice_status
4214 ice_sched_set_eir_srl_excl(struct ice_port_info *pi,
4215 struct ice_sched_node *node,
4216 u8 layer_num, enum ice_rl_type rl_type, u32 bw)
4218 if (rl_type == ICE_SHARED_BW) {
4219 /* SRL node passed in this case, it may be different node */
4220 if (bw == ICE_SCHED_DFLT_BW)
4221 /* SRL being removed, ice_sched_cfg_node_bw_lmt()
4222 * enables EIR to default. EIR is not set in this
4223 * case, so no additional action is required.
4227 /* SRL being configured, set EIR to default here.
4228 * ice_sched_cfg_node_bw_lmt() disables EIR when it
4231 return ice_sched_set_node_bw_dflt(pi, node, ICE_MAX_BW,
4233 } else if (rl_type == ICE_MAX_BW &&
4234 node->info.data.valid_sections & ICE_AQC_ELEM_VALID_SHARED) {
4235 /* Remove Shared profile. Set default shared BW call
4236 * removes shared profile for a node.
4238 return ice_sched_set_node_bw_dflt(pi, node,
4246 * ice_sched_set_node_bw - set node's bandwidth
4247 * @pi: port information structure
4249 * @rl_type: rate limit type min, max, or shared
4250 * @bw: bandwidth in Kbps - Kilo bits per sec
4251 * @layer_num: layer number
4253 * This function adds new profile corresponding to requested BW, configures
4254 * node's RL profile ID of type CIR, EIR, or SRL, and removes old profile
4255 * ID from local database. The caller needs to hold scheduler lock.
4257 static enum ice_status
4258 ice_sched_set_node_bw(struct ice_port_info *pi, struct ice_sched_node *node,
4259 enum ice_rl_type rl_type, u32 bw, u8 layer_num)
4261 struct ice_aqc_rl_profile_info *rl_prof_info;
4262 enum ice_status status = ICE_ERR_PARAM;
4263 struct ice_hw *hw = pi->hw;
4264 u16 old_id, rl_prof_id;
4266 rl_prof_info = ice_sched_add_rl_profile(hw, rl_type, bw, layer_num);
4270 rl_prof_id = LE16_TO_CPU(rl_prof_info->profile.profile_id);
4272 /* Save existing RL prof ID for later clean up */
4273 old_id = ice_sched_get_node_rl_prof_id(node, rl_type);
4274 /* Configure BW scheduling parameters */
4275 status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id);
4279 /* New changes has been applied */
4280 /* Increment the profile ID reference count */
4281 rl_prof_info->prof_id_ref++;
4283 /* Check for old ID removal */
4284 if ((old_id == ICE_SCHED_DFLT_RL_PROF_ID && rl_type != ICE_SHARED_BW) ||
4285 old_id == ICE_SCHED_INVAL_PROF_ID || old_id == rl_prof_id)
4288 return ice_sched_rm_rl_profile(hw, layer_num,
4289 rl_prof_info->profile.flags &
4290 ICE_AQC_RL_PROFILE_TYPE_M, old_id);
4294 * ice_sched_set_node_bw_lmt - set node's BW limit
4295 * @pi: port information structure
4297 * @rl_type: rate limit type min, max, or shared
4298 * @bw: bandwidth in Kbps - Kilo bits per sec
4300 * It updates node's BW limit parameters like BW RL profile ID of type CIR,
4301 * EIR, or SRL. The caller needs to hold scheduler lock.
4303 static enum ice_status
4304 ice_sched_set_node_bw_lmt(struct ice_port_info *pi, struct ice_sched_node *node,
4305 enum ice_rl_type rl_type, u32 bw)
4307 struct ice_sched_node *cfg_node = node;
4308 enum ice_status status;
4314 return ICE_ERR_PARAM;
4316 /* Remove unused RL profile IDs from HW and SW DB */
4317 ice_sched_rm_unused_rl_prof(hw);
4318 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
4319 node->tx_sched_layer);
4320 if (layer_num >= hw->num_tx_sched_layers)
4321 return ICE_ERR_PARAM;
4323 if (rl_type == ICE_SHARED_BW) {
4324 /* SRL node may be different */
4325 cfg_node = ice_sched_get_srl_node(node, layer_num);
4329 /* EIR BW and Shared BW profiles are mutually exclusive and
4330 * hence only one of them may be set for any given element
4332 status = ice_sched_set_eir_srl_excl(pi, cfg_node, layer_num, rl_type,
4336 if (bw == ICE_SCHED_DFLT_BW)
4337 return ice_sched_set_node_bw_dflt(pi, cfg_node, rl_type,
4339 return ice_sched_set_node_bw(pi, cfg_node, rl_type, bw, layer_num);
4343 * ice_sched_set_node_bw_dflt_lmt - set node's BW limit to default
4344 * @pi: port information structure
4345 * @node: pointer to node structure
4346 * @rl_type: rate limit type min, max, or shared
4348 * This function configures node element's BW rate limit profile ID of
4349 * type CIR, EIR, or SRL to default. This function needs to be called
4350 * with the scheduler lock held.
4352 static enum ice_status
4353 ice_sched_set_node_bw_dflt_lmt(struct ice_port_info *pi,
4354 struct ice_sched_node *node,
4355 enum ice_rl_type rl_type)
4357 return ice_sched_set_node_bw_lmt(pi, node, rl_type,
4362 * ice_sched_validate_srl_node - Check node for SRL applicability
4363 * @node: sched node to configure
4364 * @sel_layer: selected SRL layer
4366 * This function checks if the SRL can be applied to a selceted layer node on
4367 * behalf of the requested node (first argument). This function needs to be
4368 * called with scheduler lock held.
4370 static enum ice_status
4371 ice_sched_validate_srl_node(struct ice_sched_node *node, u8 sel_layer)
4373 /* SRL profiles are not available on all layers. Check if the
4374 * SRL profile can be applied to a node above or below the
4375 * requested node. SRL configuration is possible only if the
4376 * selected layer's node has single child.
4378 if (sel_layer == node->tx_sched_layer ||
4379 ((sel_layer == node->tx_sched_layer + 1) &&
4380 node->num_children == 1) ||
4381 ((sel_layer == node->tx_sched_layer - 1) &&
4382 (node->parent && node->parent->num_children == 1)))
4389 * ice_sched_save_q_bw - save queue node's BW information
4390 * @q_ctx: queue context structure
4391 * @rl_type: rate limit type min, max, or shared
4392 * @bw: bandwidth in Kbps - Kilo bits per sec
4394 * Save BW information of queue type node for post replay use.
4396 static enum ice_status
4397 ice_sched_save_q_bw(struct ice_q_ctx *q_ctx, enum ice_rl_type rl_type, u32 bw)
4401 ice_set_clear_cir_bw(&q_ctx->bw_t_info, bw);
4404 ice_set_clear_eir_bw(&q_ctx->bw_t_info, bw);
4407 ice_set_clear_shared_bw(&q_ctx->bw_t_info, bw);
4410 return ICE_ERR_PARAM;
4416 * ice_sched_set_q_bw_lmt - sets queue BW limit
4417 * @pi: port information structure
4418 * @vsi_handle: sw VSI handle
4419 * @tc: traffic class
4420 * @q_handle: software queue handle
4421 * @rl_type: min, max, or shared
4422 * @bw: bandwidth in Kbps
4424 * This function sets BW limit of queue scheduling node.
4426 static enum ice_status
4427 ice_sched_set_q_bw_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4428 u16 q_handle, enum ice_rl_type rl_type, u32 bw)
4430 enum ice_status status = ICE_ERR_PARAM;
4431 struct ice_sched_node *node;
4432 struct ice_q_ctx *q_ctx;
4434 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4435 return ICE_ERR_PARAM;
4436 ice_acquire_lock(&pi->sched_lock);
4437 q_ctx = ice_get_lan_q_ctx(pi->hw, vsi_handle, tc, q_handle);
4440 node = ice_sched_find_node_by_teid(pi->root, q_ctx->q_teid);
4442 ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong q_teid\n");
4446 /* Return error if it is not a leaf node */
4447 if (node->info.data.elem_type != ICE_AQC_ELEM_TYPE_LEAF)
4450 /* SRL bandwidth layer selection */
4451 if (rl_type == ICE_SHARED_BW) {
4452 u8 sel_layer; /* selected layer */
4454 sel_layer = ice_sched_get_rl_prof_layer(pi, rl_type,
4455 node->tx_sched_layer);
4456 if (sel_layer >= pi->hw->num_tx_sched_layers) {
4457 status = ICE_ERR_PARAM;
4460 status = ice_sched_validate_srl_node(node, sel_layer);
4465 if (bw == ICE_SCHED_DFLT_BW)
4466 status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type);
4468 status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw);
4471 status = ice_sched_save_q_bw(q_ctx, rl_type, bw);
4474 ice_release_lock(&pi->sched_lock);
4479 * ice_cfg_q_bw_lmt - configure queue BW limit
4480 * @pi: port information structure
4481 * @vsi_handle: sw VSI handle
4482 * @tc: traffic class
4483 * @q_handle: software queue handle
4484 * @rl_type: min, max, or shared
4485 * @bw: bandwidth in Kbps
4487 * This function configures BW limit of queue scheduling node.
4490 ice_cfg_q_bw_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4491 u16 q_handle, enum ice_rl_type rl_type, u32 bw)
4493 return ice_sched_set_q_bw_lmt(pi, vsi_handle, tc, q_handle, rl_type,
4498 * ice_cfg_q_bw_dflt_lmt - configure queue BW default limit
4499 * @pi: port information structure
4500 * @vsi_handle: sw VSI handle
4501 * @tc: traffic class
4502 * @q_handle: software queue handle
4503 * @rl_type: min, max, or shared
4505 * This function configures BW default limit of queue scheduling node.
4508 ice_cfg_q_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4509 u16 q_handle, enum ice_rl_type rl_type)
4511 return ice_sched_set_q_bw_lmt(pi, vsi_handle, tc, q_handle, rl_type,
4516 * ice_sched_save_tc_node_bw - save TC node BW limit
4517 * @pi: port information structure
4519 * @rl_type: min or max
4520 * @bw: bandwidth in Kbps
4522 * This function saves the modified values of bandwidth settings for later
4523 * replay purpose (restore) after reset.
4525 static enum ice_status
4526 ice_sched_save_tc_node_bw(struct ice_port_info *pi, u8 tc,
4527 enum ice_rl_type rl_type, u32 bw)
4529 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4530 return ICE_ERR_PARAM;
4533 ice_set_clear_cir_bw(&pi->tc_node_bw_t_info[tc], bw);
4536 ice_set_clear_eir_bw(&pi->tc_node_bw_t_info[tc], bw);
4539 ice_set_clear_shared_bw(&pi->tc_node_bw_t_info[tc], bw);
4542 return ICE_ERR_PARAM;
4548 * ice_sched_set_tc_node_bw_lmt - sets TC node BW limit
4549 * @pi: port information structure
4551 * @rl_type: min or max
4552 * @bw: bandwidth in Kbps
4554 * This function configures bandwidth limit of TC node.
4556 static enum ice_status
4557 ice_sched_set_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc,
4558 enum ice_rl_type rl_type, u32 bw)
4560 enum ice_status status = ICE_ERR_PARAM;
4561 struct ice_sched_node *tc_node;
4563 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4565 ice_acquire_lock(&pi->sched_lock);
4566 tc_node = ice_sched_get_tc_node(pi, tc);
4568 goto exit_set_tc_node_bw;
4569 if (bw == ICE_SCHED_DFLT_BW)
4570 status = ice_sched_set_node_bw_dflt_lmt(pi, tc_node, rl_type);
4572 status = ice_sched_set_node_bw_lmt(pi, tc_node, rl_type, bw);
4574 status = ice_sched_save_tc_node_bw(pi, tc, rl_type, bw);
4576 exit_set_tc_node_bw:
4577 ice_release_lock(&pi->sched_lock);
4582 * ice_cfg_tc_node_bw_lmt - configure TC node BW limit
4583 * @pi: port information structure
4585 * @rl_type: min or max
4586 * @bw: bandwidth in Kbps
4588 * This function configures BW limit of TC node.
4589 * Note: The minimum guaranteed reservation is done via DCBX.
4592 ice_cfg_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc,
4593 enum ice_rl_type rl_type, u32 bw)
4595 return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, bw);
4599 * ice_cfg_tc_node_bw_dflt_lmt - configure TC node BW default limit
4600 * @pi: port information structure
4602 * @rl_type: min or max
4604 * This function configures BW default limit of TC node.
4607 ice_cfg_tc_node_bw_dflt_lmt(struct ice_port_info *pi, u8 tc,
4608 enum ice_rl_type rl_type)
4610 return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, ICE_SCHED_DFLT_BW);
4614 * ice_sched_save_tc_node_bw_alloc - save TC node's BW alloc information
4615 * @pi: port information structure
4616 * @tc: traffic class
4617 * @rl_type: rate limit type min or max
4618 * @bw_alloc: Bandwidth allocation information
4620 * Save BW alloc information of VSI type node for post replay use.
4622 static enum ice_status
4623 ice_sched_save_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4624 enum ice_rl_type rl_type, u16 bw_alloc)
4626 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4627 return ICE_ERR_PARAM;
4630 ice_set_clear_cir_bw_alloc(&pi->tc_node_bw_t_info[tc],
4634 ice_set_clear_eir_bw_alloc(&pi->tc_node_bw_t_info[tc],
4638 return ICE_ERR_PARAM;
4644 * ice_sched_set_tc_node_bw_alloc - set TC node BW alloc
4645 * @pi: port information structure
4647 * @rl_type: min or max
4648 * @bw_alloc: bandwidth alloc
4650 * This function configures bandwidth alloc of TC node, also saves the
4651 * changed settings for replay purpose, and return success if it succeeds
4652 * in modifying bandwidth alloc setting.
4654 static enum ice_status
4655 ice_sched_set_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4656 enum ice_rl_type rl_type, u8 bw_alloc)
4658 enum ice_status status = ICE_ERR_PARAM;
4659 struct ice_sched_node *tc_node;
4661 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4663 ice_acquire_lock(&pi->sched_lock);
4664 tc_node = ice_sched_get_tc_node(pi, tc);
4666 goto exit_set_tc_node_bw_alloc;
4667 status = ice_sched_cfg_node_bw_alloc(pi->hw, tc_node, rl_type,
4670 goto exit_set_tc_node_bw_alloc;
4671 status = ice_sched_save_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc);
4673 exit_set_tc_node_bw_alloc:
4674 ice_release_lock(&pi->sched_lock);
4679 * ice_cfg_tc_node_bw_alloc - configure TC node BW alloc
4680 * @pi: port information structure
4682 * @rl_type: min or max
4683 * @bw_alloc: bandwidth alloc
4685 * This function configures BW limit of TC node.
4686 * Note: The minimum guaranteed reservation is done via DCBX.
4689 ice_cfg_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4690 enum ice_rl_type rl_type, u8 bw_alloc)
4692 return ice_sched_set_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc);
4696 * ice_sched_set_agg_bw_dflt_lmt - set aggregator node's BW limit to default
4697 * @pi: port information structure
4698 * @vsi_handle: software VSI handle
4700 * This function retrieves the aggregator ID based on VSI ID and TC,
4701 * and sets node's BW limit to default. This function needs to be
4702 * called with the scheduler lock held.
4705 ice_sched_set_agg_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle)
4707 struct ice_vsi_ctx *vsi_ctx;
4708 enum ice_status status = ICE_SUCCESS;
4711 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4712 return ICE_ERR_PARAM;
4713 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
4715 return ICE_ERR_PARAM;
4717 ice_for_each_traffic_class(tc) {
4718 struct ice_sched_node *node;
4720 node = vsi_ctx->sched.ag_node[tc];
4724 /* Set min profile to default */
4725 status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MIN_BW);
4729 /* Set max profile to default */
4730 status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MAX_BW);
4734 /* Remove shared profile, if there is one */
4735 status = ice_sched_set_node_bw_dflt_lmt(pi, node,
4745 * ice_sched_get_node_by_id_type - get node from ID type
4746 * @pi: port information structure
4748 * @agg_type: type of aggregator
4749 * @tc: traffic class
4751 * This function returns node identified by ID of type aggregator, and
4752 * based on traffic class (TC). This function needs to be called with
4753 * the scheduler lock held.
4755 static struct ice_sched_node *
4756 ice_sched_get_node_by_id_type(struct ice_port_info *pi, u32 id,
4757 enum ice_agg_type agg_type, u8 tc)
4759 struct ice_sched_node *node = NULL;
4760 struct ice_sched_node *child_node;
4763 case ICE_AGG_TYPE_VSI: {
4764 struct ice_vsi_ctx *vsi_ctx;
4765 u16 vsi_handle = (u16)id;
4767 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4769 /* Get sched_vsi_info */
4770 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
4773 node = vsi_ctx->sched.vsi_node[tc];
4777 case ICE_AGG_TYPE_AGG: {
4778 struct ice_sched_node *tc_node;
4780 tc_node = ice_sched_get_tc_node(pi, tc);
4782 node = ice_sched_get_agg_node(pi, tc_node, id);
4786 case ICE_AGG_TYPE_Q:
4787 /* The current implementation allows single queue to modify */
4788 node = ice_sched_get_node(pi, id);
4791 case ICE_AGG_TYPE_QG:
4792 /* The current implementation allows single qg to modify */
4793 child_node = ice_sched_get_node(pi, id);
4796 node = child_node->parent;
4807 * ice_sched_set_node_bw_lmt_per_tc - set node BW limit per TC
4808 * @pi: port information structure
4809 * @id: ID (software VSI handle or AGG ID)
4810 * @agg_type: aggregator type (VSI or AGG type node)
4811 * @tc: traffic class
4812 * @rl_type: min or max
4813 * @bw: bandwidth in Kbps
4815 * This function sets BW limit of VSI or Aggregator scheduling node
4816 * based on TC information from passed in argument BW.
4819 ice_sched_set_node_bw_lmt_per_tc(struct ice_port_info *pi, u32 id,
4820 enum ice_agg_type agg_type, u8 tc,
4821 enum ice_rl_type rl_type, u32 bw)
4823 enum ice_status status = ICE_ERR_PARAM;
4824 struct ice_sched_node *node;
4829 if (rl_type == ICE_UNKNOWN_BW)
4832 ice_acquire_lock(&pi->sched_lock);
4833 node = ice_sched_get_node_by_id_type(pi, id, agg_type, tc);
4835 ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong id, agg type, or tc\n");
4836 goto exit_set_node_bw_lmt_per_tc;
4838 if (bw == ICE_SCHED_DFLT_BW)
4839 status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type);
4841 status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw);
4843 exit_set_node_bw_lmt_per_tc:
4844 ice_release_lock(&pi->sched_lock);
4849 * ice_sched_validate_vsi_srl_node - validate VSI SRL node
4850 * @pi: port information structure
4851 * @vsi_handle: software VSI handle
4853 * This function validates SRL node of the VSI node if available SRL layer is
4854 * different than the VSI node layer on all TC(s).This function needs to be
4855 * called with scheduler lock held.
4857 static enum ice_status
4858 ice_sched_validate_vsi_srl_node(struct ice_port_info *pi, u16 vsi_handle)
4860 u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM;
4863 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4864 return ICE_ERR_PARAM;
4866 /* Return success if no nodes are present across TC */
4867 ice_for_each_traffic_class(tc) {
4868 struct ice_sched_node *tc_node, *vsi_node;
4869 enum ice_rl_type rl_type = ICE_SHARED_BW;
4870 enum ice_status status;
4872 tc_node = ice_sched_get_tc_node(pi, tc);
4876 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
4880 /* SRL bandwidth layer selection */
4881 if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) {
4882 u8 node_layer = vsi_node->tx_sched_layer;
4885 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
4887 if (layer_num >= pi->hw->num_tx_sched_layers)
4888 return ICE_ERR_PARAM;
4889 sel_layer = layer_num;
4892 status = ice_sched_validate_srl_node(vsi_node, sel_layer);
4900 * ice_sched_set_vsi_bw_shared_lmt - set VSI BW shared limit
4901 * @pi: port information structure
4902 * @vsi_handle: software VSI handle
4903 * @bw: bandwidth in Kbps
4905 * This function Configures shared rate limiter(SRL) of all VSI type nodes
4906 * across all traffic classes for VSI matching handle. When BW value of
4907 * ICE_SCHED_DFLT_BW is passed, it removes the SRL from the node.
4910 ice_sched_set_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle,
4913 enum ice_status status = ICE_SUCCESS;
4917 return ICE_ERR_PARAM;
4919 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4920 return ICE_ERR_PARAM;
4922 ice_acquire_lock(&pi->sched_lock);
4923 status = ice_sched_validate_vsi_srl_node(pi, vsi_handle);
4925 goto exit_set_vsi_bw_shared_lmt;
4926 /* Return success if no nodes are present across TC */
4927 ice_for_each_traffic_class(tc) {
4928 struct ice_sched_node *tc_node, *vsi_node;
4929 enum ice_rl_type rl_type = ICE_SHARED_BW;
4931 tc_node = ice_sched_get_tc_node(pi, tc);
4935 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
4939 if (bw == ICE_SCHED_DFLT_BW)
4940 /* It removes existing SRL from the node */
4941 status = ice_sched_set_node_bw_dflt_lmt(pi, vsi_node,
4944 status = ice_sched_set_node_bw_lmt(pi, vsi_node,
4948 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw);
4953 exit_set_vsi_bw_shared_lmt:
4954 ice_release_lock(&pi->sched_lock);
4959 * ice_sched_validate_agg_srl_node - validate AGG SRL node
4960 * @pi: port information structure
4961 * @agg_id: aggregator ID
4963 * This function validates SRL node of the AGG node if available SRL layer is
4964 * different than the AGG node layer on all TC(s).This function needs to be
4965 * called with scheduler lock held.
4967 static enum ice_status
4968 ice_sched_validate_agg_srl_node(struct ice_port_info *pi, u32 agg_id)
4970 u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM;
4971 struct ice_sched_agg_info *agg_info;
4972 bool agg_id_present = false;
4973 enum ice_status status = ICE_SUCCESS;
4976 LIST_FOR_EACH_ENTRY(agg_info, &pi->hw->agg_list, ice_sched_agg_info,
4978 if (agg_info->agg_id == agg_id) {
4979 agg_id_present = true;
4982 if (!agg_id_present)
4983 return ICE_ERR_PARAM;
4984 /* Return success if no nodes are present across TC */
4985 ice_for_each_traffic_class(tc) {
4986 struct ice_sched_node *tc_node, *agg_node;
4987 enum ice_rl_type rl_type = ICE_SHARED_BW;
4989 tc_node = ice_sched_get_tc_node(pi, tc);
4993 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
4996 /* SRL bandwidth layer selection */
4997 if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) {
4998 u8 node_layer = agg_node->tx_sched_layer;
5001 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
5003 if (layer_num >= pi->hw->num_tx_sched_layers)
5004 return ICE_ERR_PARAM;
5005 sel_layer = layer_num;
5008 status = ice_sched_validate_srl_node(agg_node, sel_layer);
5016 * ice_sched_set_agg_bw_shared_lmt - set aggregator BW shared limit
5017 * @pi: port information structure
5018 * @agg_id: aggregator ID
5019 * @bw: bandwidth in Kbps
5021 * This function configures the shared rate limiter(SRL) of all aggregator type
5022 * nodes across all traffic classes for aggregator matching agg_id. When
5023 * BW value of ICE_SCHED_DFLT_BW is passed, it removes SRL from the
5027 ice_sched_set_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw)
5029 struct ice_sched_agg_info *agg_info;
5030 struct ice_sched_agg_info *tmp;
5031 bool agg_id_present = false;
5032 enum ice_status status = ICE_SUCCESS;
5036 return ICE_ERR_PARAM;
5038 ice_acquire_lock(&pi->sched_lock);
5039 status = ice_sched_validate_agg_srl_node(pi, agg_id);
5041 goto exit_agg_bw_shared_lmt;
5043 LIST_FOR_EACH_ENTRY_SAFE(agg_info, tmp, &pi->hw->agg_list,
5044 ice_sched_agg_info, list_entry)
5045 if (agg_info->agg_id == agg_id) {
5046 agg_id_present = true;
5050 if (!agg_id_present) {
5051 status = ICE_ERR_PARAM;
5052 goto exit_agg_bw_shared_lmt;
5055 /* Return success if no nodes are present across TC */
5056 ice_for_each_traffic_class(tc) {
5057 enum ice_rl_type rl_type = ICE_SHARED_BW;
5058 struct ice_sched_node *tc_node, *agg_node;
5060 tc_node = ice_sched_get_tc_node(pi, tc);
5064 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
5068 if (bw == ICE_SCHED_DFLT_BW)
5069 /* It removes existing SRL from the node */
5070 status = ice_sched_set_node_bw_dflt_lmt(pi, agg_node,
5073 status = ice_sched_set_node_bw_lmt(pi, agg_node,
5077 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw);
5082 exit_agg_bw_shared_lmt:
5083 ice_release_lock(&pi->sched_lock);
5088 * ice_sched_cfg_sibl_node_prio - configure node sibling priority
5089 * @pi: port information structure
5090 * @node: sched node to configure
5091 * @priority: sibling priority
5093 * This function configures node element's sibling priority only. This
5094 * function needs to be called with scheduler lock held.
5097 ice_sched_cfg_sibl_node_prio(struct ice_port_info *pi,
5098 struct ice_sched_node *node, u8 priority)
5100 struct ice_aqc_txsched_elem_data buf;
5101 struct ice_aqc_txsched_elem *data;
5102 struct ice_hw *hw = pi->hw;
5103 enum ice_status status;
5106 return ICE_ERR_PARAM;
5109 data->valid_sections |= ICE_AQC_ELEM_VALID_GENERIC;
5110 priority = (priority << ICE_AQC_ELEM_GENERIC_PRIO_S) &
5111 ICE_AQC_ELEM_GENERIC_PRIO_M;
5112 data->generic &= ~ICE_AQC_ELEM_GENERIC_PRIO_M;
5113 data->generic |= priority;
5115 /* Configure element */
5116 status = ice_sched_update_elem(hw, node, &buf);
5121 * ice_cfg_rl_burst_size - Set burst size value
5122 * @hw: pointer to the HW struct
5123 * @bytes: burst size in bytes
5125 * This function configures/set the burst size to requested new value. The new
5126 * burst size value is used for future rate limit calls. It doesn't change the
5127 * existing or previously created RL profiles.
5129 enum ice_status ice_cfg_rl_burst_size(struct ice_hw *hw, u32 bytes)
5131 u16 burst_size_to_prog;
5133 if (bytes < ICE_MIN_BURST_SIZE_ALLOWED ||
5134 bytes > ICE_MAX_BURST_SIZE_ALLOWED)
5135 return ICE_ERR_PARAM;
5136 if (ice_round_to_num(bytes, 64) <=
5137 ICE_MAX_BURST_SIZE_64_BYTE_GRANULARITY) {
5138 /* 64 byte granularity case */
5139 /* Disable MSB granularity bit */
5140 burst_size_to_prog = ICE_64_BYTE_GRANULARITY;
5141 /* round number to nearest 64 byte granularity */
5142 bytes = ice_round_to_num(bytes, 64);
5143 /* The value is in 64 byte chunks */
5144 burst_size_to_prog |= (u16)(bytes / 64);
5146 /* k bytes granularity case */
5147 /* Enable MSB granularity bit */
5148 burst_size_to_prog = ICE_KBYTE_GRANULARITY;
5149 /* round number to nearest 1024 granularity */
5150 bytes = ice_round_to_num(bytes, 1024);
5151 /* check rounding doesn't go beyond allowed */
5152 if (bytes > ICE_MAX_BURST_SIZE_KBYTE_GRANULARITY)
5153 bytes = ICE_MAX_BURST_SIZE_KBYTE_GRANULARITY;
5154 /* The value is in k bytes */
5155 burst_size_to_prog |= (u16)(bytes / 1024);
5157 hw->max_burst_size = burst_size_to_prog;
5162 * ice_sched_replay_node_prio - re-configure node priority
5163 * @hw: pointer to the HW struct
5164 * @node: sched node to configure
5165 * @priority: priority value
5167 * This function configures node element's priority value. It
5168 * needs to be called with scheduler lock held.
5170 static enum ice_status
5171 ice_sched_replay_node_prio(struct ice_hw *hw, struct ice_sched_node *node,
5174 struct ice_aqc_txsched_elem_data buf;
5175 struct ice_aqc_txsched_elem *data;
5176 enum ice_status status;
5180 data->valid_sections |= ICE_AQC_ELEM_VALID_GENERIC;
5181 data->generic = priority;
5183 /* Configure element */
5184 status = ice_sched_update_elem(hw, node, &buf);
5189 * ice_sched_replay_node_bw - replay node(s) BW
5190 * @hw: pointer to the HW struct
5191 * @node: sched node to configure
5192 * @bw_t_info: BW type information
5194 * This function restores node's BW from bw_t_info. The caller needs
5195 * to hold the scheduler lock.
5197 static enum ice_status
5198 ice_sched_replay_node_bw(struct ice_hw *hw, struct ice_sched_node *node,
5199 struct ice_bw_type_info *bw_t_info)
5201 struct ice_port_info *pi = hw->port_info;
5202 enum ice_status status = ICE_ERR_PARAM;
5207 if (!ice_is_any_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CNT))
5209 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_PRIO)) {
5210 status = ice_sched_replay_node_prio(hw, node,
5211 bw_t_info->generic);
5215 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CIR)) {
5216 status = ice_sched_set_node_bw_lmt(pi, node, ICE_MIN_BW,
5217 bw_t_info->cir_bw.bw);
5221 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CIR_WT)) {
5222 bw_alloc = bw_t_info->cir_bw.bw_alloc;
5223 status = ice_sched_cfg_node_bw_alloc(hw, node, ICE_MIN_BW,
5228 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_EIR)) {
5229 status = ice_sched_set_node_bw_lmt(pi, node, ICE_MAX_BW,
5230 bw_t_info->eir_bw.bw);
5234 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_EIR_WT)) {
5235 bw_alloc = bw_t_info->eir_bw.bw_alloc;
5236 status = ice_sched_cfg_node_bw_alloc(hw, node, ICE_MAX_BW,
5241 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_SHARED))
5242 status = ice_sched_set_node_bw_lmt(pi, node, ICE_SHARED_BW,
5243 bw_t_info->shared_bw);
5248 * ice_sched_replay_agg_bw - replay aggregator node(s) BW
5249 * @hw: pointer to the HW struct
5250 * @agg_info: aggregator data structure
5252 * This function re-creates aggregator type nodes. The caller needs to hold
5253 * the scheduler lock.
5255 static enum ice_status
5256 ice_sched_replay_agg_bw(struct ice_hw *hw, struct ice_sched_agg_info *agg_info)
5258 struct ice_sched_node *tc_node, *agg_node;
5259 enum ice_status status = ICE_SUCCESS;
5263 return ICE_ERR_PARAM;
5264 ice_for_each_traffic_class(tc) {
5265 if (!ice_is_any_bit_set(agg_info->bw_t_info[tc].bw_t_bitmap,
5268 tc_node = ice_sched_get_tc_node(hw->port_info, tc);
5270 status = ICE_ERR_PARAM;
5273 agg_node = ice_sched_get_agg_node(hw->port_info, tc_node,
5276 status = ICE_ERR_PARAM;
5279 status = ice_sched_replay_node_bw(hw, agg_node,
5280 &agg_info->bw_t_info[tc]);
5288 * ice_sched_get_ena_tc_bitmap - get enabled TC bitmap
5289 * @pi: port info struct
5290 * @tc_bitmap: 8 bits TC bitmap to check
5291 * @ena_tc_bitmap: 8 bits enabled TC bitmap to return
5293 * This function returns enabled TC bitmap in variable ena_tc_bitmap. Some TCs
5294 * may be missing, it returns enabled TCs. This function needs to be called with
5295 * scheduler lock held.
5298 ice_sched_get_ena_tc_bitmap(struct ice_port_info *pi, ice_bitmap_t *tc_bitmap,
5299 ice_bitmap_t *ena_tc_bitmap)
5303 /* Some TC(s) may be missing after reset, adjust for replay */
5304 ice_for_each_traffic_class(tc)
5305 if (ice_is_tc_ena(*tc_bitmap, tc) &&
5306 (ice_sched_get_tc_node(pi, tc)))
5307 ice_set_bit(tc, ena_tc_bitmap);
5311 * ice_sched_replay_agg - recreate aggregator node(s)
5312 * @hw: pointer to the HW struct
5314 * This function recreate aggregator type nodes which are not replayed earlier.
5315 * It also replay aggregator BW information. These aggregator nodes are not
5316 * associated with VSI type node yet.
5318 void ice_sched_replay_agg(struct ice_hw *hw)
5320 struct ice_port_info *pi = hw->port_info;
5321 struct ice_sched_agg_info *agg_info;
5323 ice_acquire_lock(&pi->sched_lock);
5324 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
5326 /* replay aggregator (re-create aggregator node) */
5327 if (!ice_cmp_bitmap(agg_info->tc_bitmap,
5328 agg_info->replay_tc_bitmap,
5329 ICE_MAX_TRAFFIC_CLASS)) {
5330 ice_declare_bitmap(replay_bitmap,
5331 ICE_MAX_TRAFFIC_CLASS);
5332 enum ice_status status;
5334 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5335 ice_sched_get_ena_tc_bitmap(pi,
5336 agg_info->replay_tc_bitmap,
5338 status = ice_sched_cfg_agg(hw->port_info,
5343 ice_info(hw, "Replay agg id[%d] failed\n",
5345 /* Move on to next one */
5348 /* Replay aggregator node BW (restore aggregator BW) */
5349 status = ice_sched_replay_agg_bw(hw, agg_info);
5351 ice_info(hw, "Replay agg bw [id=%d] failed\n",
5354 ice_release_lock(&pi->sched_lock);
5358 * ice_sched_replay_agg_vsi_preinit - Agg/VSI replay pre initialization
5359 * @hw: pointer to the HW struct
5361 * This function initialize aggregator(s) TC bitmap to zero. A required
5362 * preinit step for replaying aggregators.
5364 void ice_sched_replay_agg_vsi_preinit(struct ice_hw *hw)
5366 struct ice_port_info *pi = hw->port_info;
5367 struct ice_sched_agg_info *agg_info;
5369 ice_acquire_lock(&pi->sched_lock);
5370 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
5372 struct ice_sched_agg_vsi_info *agg_vsi_info;
5374 agg_info->tc_bitmap[0] = 0;
5375 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
5376 ice_sched_agg_vsi_info, list_entry)
5377 agg_vsi_info->tc_bitmap[0] = 0;
5379 ice_release_lock(&pi->sched_lock);
5383 * ice_sched_replay_root_node_bw - replay root node BW
5384 * @pi: port information structure
5386 * Replay root node BW settings.
5388 enum ice_status ice_sched_replay_root_node_bw(struct ice_port_info *pi)
5390 enum ice_status status = ICE_SUCCESS;
5393 return ICE_ERR_PARAM;
5394 ice_acquire_lock(&pi->sched_lock);
5396 status = ice_sched_replay_node_bw(pi->hw, pi->root,
5397 &pi->root_node_bw_t_info);
5398 ice_release_lock(&pi->sched_lock);
5403 * ice_sched_replay_tc_node_bw - replay TC node(s) BW
5404 * @pi: port information structure
5406 * This function replay TC nodes.
5408 enum ice_status ice_sched_replay_tc_node_bw(struct ice_port_info *pi)
5410 enum ice_status status = ICE_SUCCESS;
5414 return ICE_ERR_PARAM;
5415 ice_acquire_lock(&pi->sched_lock);
5416 ice_for_each_traffic_class(tc) {
5417 struct ice_sched_node *tc_node;
5419 tc_node = ice_sched_get_tc_node(pi, tc);
5421 continue; /* TC not present */
5422 status = ice_sched_replay_node_bw(pi->hw, tc_node,
5423 &pi->tc_node_bw_t_info[tc]);
5427 ice_release_lock(&pi->sched_lock);
5432 * ice_sched_replay_vsi_bw - replay VSI type node(s) BW
5433 * @hw: pointer to the HW struct
5434 * @vsi_handle: software VSI handle
5435 * @tc_bitmap: 8 bits TC bitmap
5437 * This function replays VSI type nodes bandwidth. This function needs to be
5438 * called with scheduler lock held.
5440 static enum ice_status
5441 ice_sched_replay_vsi_bw(struct ice_hw *hw, u16 vsi_handle,
5442 ice_bitmap_t *tc_bitmap)
5444 struct ice_sched_node *vsi_node, *tc_node;
5445 struct ice_port_info *pi = hw->port_info;
5446 struct ice_bw_type_info *bw_t_info;
5447 struct ice_vsi_ctx *vsi_ctx;
5448 enum ice_status status = ICE_SUCCESS;
5451 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
5453 return ICE_ERR_PARAM;
5454 ice_for_each_traffic_class(tc) {
5455 if (!ice_is_tc_ena(*tc_bitmap, tc))
5457 tc_node = ice_sched_get_tc_node(pi, tc);
5460 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
5463 bw_t_info = &vsi_ctx->sched.bw_t_info[tc];
5464 status = ice_sched_replay_node_bw(hw, vsi_node, bw_t_info);
5472 * ice_sched_replay_vsi_agg - replay aggregator & VSI to aggregator node(s)
5473 * @hw: pointer to the HW struct
5474 * @vsi_handle: software VSI handle
5476 * This function replays aggregator node, VSI to aggregator type nodes, and
5477 * their node bandwidth information. This function needs to be called with
5478 * scheduler lock held.
5480 static enum ice_status
5481 ice_sched_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle)
5483 ice_declare_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5484 struct ice_sched_agg_vsi_info *agg_vsi_info;
5485 struct ice_port_info *pi = hw->port_info;
5486 struct ice_sched_agg_info *agg_info;
5487 enum ice_status status;
5489 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5490 if (!ice_is_vsi_valid(hw, vsi_handle))
5491 return ICE_ERR_PARAM;
5492 agg_info = ice_get_vsi_agg_info(hw, vsi_handle);
5494 return ICE_SUCCESS; /* Not present in list - default Agg case */
5495 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
5497 return ICE_SUCCESS; /* Not present in list - default Agg case */
5498 ice_sched_get_ena_tc_bitmap(pi, agg_info->replay_tc_bitmap,
5500 /* Replay aggregator node associated to vsi_handle */
5501 status = ice_sched_cfg_agg(hw->port_info, agg_info->agg_id,
5502 ICE_AGG_TYPE_AGG, replay_bitmap);
5505 /* Replay aggregator node BW (restore aggregator BW) */
5506 status = ice_sched_replay_agg_bw(hw, agg_info);
5510 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5511 ice_sched_get_ena_tc_bitmap(pi, agg_vsi_info->replay_tc_bitmap,
5513 /* Move this VSI (vsi_handle) to above aggregator */
5514 status = ice_sched_assoc_vsi_to_agg(pi, agg_info->agg_id, vsi_handle,
5518 /* Replay VSI BW (restore VSI BW) */
5519 return ice_sched_replay_vsi_bw(hw, vsi_handle,
5520 agg_vsi_info->tc_bitmap);
5524 * ice_replay_vsi_agg - replay VSI to aggregator node
5525 * @hw: pointer to the HW struct
5526 * @vsi_handle: software VSI handle
5528 * This function replays association of VSI to aggregator type nodes, and
5529 * node bandwidth information.
5531 enum ice_status ice_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle)
5533 struct ice_port_info *pi = hw->port_info;
5534 enum ice_status status;
5536 ice_acquire_lock(&pi->sched_lock);
5537 status = ice_sched_replay_vsi_agg(hw, vsi_handle);
5538 ice_release_lock(&pi->sched_lock);
5543 * ice_sched_replay_q_bw - replay queue type node BW
5544 * @pi: port information structure
5545 * @q_ctx: queue context structure
5547 * This function replays queue type node bandwidth. This function needs to be
5548 * called with scheduler lock held.
5551 ice_sched_replay_q_bw(struct ice_port_info *pi, struct ice_q_ctx *q_ctx)
5553 struct ice_sched_node *q_node;
5555 /* Following also checks the presence of node in tree */
5556 q_node = ice_sched_find_node_by_teid(pi->root, q_ctx->q_teid);
5558 return ICE_ERR_PARAM;
5559 return ice_sched_replay_node_bw(pi->hw, q_node, &q_ctx->bw_t_info);