net/ice/base: add basic Tx scheduler
[dpdk.git] / drivers / net / ice / base / ice_sched.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2018
3  */
4
5 #ifndef _ICE_SCHED_H_
6 #define _ICE_SCHED_H_
7
8 #include "ice_common.h"
9
10 #define ICE_QGRP_LAYER_OFFSET   2
11 #define ICE_VSI_LAYER_OFFSET    4
12 #define ICE_AGG_LAYER_OFFSET    6
13 #define ICE_SCHED_INVAL_LAYER_NUM       0xFF
14 /* Burst size is a 12 bits register that is configured while creating the RL
15  * profile(s). MSB is a granularity bit and tells the granularity type
16  * 0 - LSB bits are in bytes granularity
17  * 1 - LSB bits are in 1K bytes granularity
18  */
19 #define ICE_BYTE_GRANULARITY                    0
20 #define ICE_KBYTE_GRANULARITY                   0x800
21 #define ICE_MIN_BURST_SIZE_ALLOWED              1 /* In Bytes */
22 #define ICE_MAX_BURST_SIZE_ALLOWED              (2047 * 1024) /* In Bytes */
23 #define ICE_MAX_BURST_SIZE_BYTE_GRANULARITY     2047 /* In Bytes */
24 #define ICE_MAX_BURST_SIZE_KBYTE_GRANULARITY    ICE_MAX_BURST_SIZE_ALLOWED
25
26 #define ICE_RL_PROF_FREQUENCY 446000000
27 #define ICE_RL_PROF_ACCURACY_BYTES 128
28 #define ICE_RL_PROF_MULTIPLIER 10000
29 #define ICE_RL_PROF_TS_MULTIPLIER 32
30 #define ICE_RL_PROF_FRACTION 512
31
32 struct rl_profile_params {
33         u32 bw;                 /* in Kbps */
34         u16 rl_multiplier;
35         u16 wake_up_calc;
36         u16 rl_encode;
37 };
38
39 /* BW rate limit profile parameters list entry along
40  * with bandwidth maintained per layer in port info
41  */
42 struct ice_aqc_rl_profile_info {
43         struct ice_aqc_rl_profile_elem profile;
44         struct LIST_ENTRY_TYPE list_entry;
45         u32 bw;                 /* requested */
46         u16 prof_id_ref;        /* profile id to node association ref count */
47 };
48
49 struct ice_sched_agg_vsi_info {
50         struct LIST_ENTRY_TYPE list_entry;
51         ice_declare_bitmap(tc_bitmap, ICE_MAX_TRAFFIC_CLASS);
52         u16 vsi_handle;
53         /* save agg vsi TC bitmap */
54         ice_declare_bitmap(replay_tc_bitmap, ICE_MAX_TRAFFIC_CLASS);
55 };
56
57 struct ice_sched_agg_info {
58         struct LIST_HEAD_TYPE agg_vsi_list;
59         struct LIST_ENTRY_TYPE list_entry;
60         ice_declare_bitmap(tc_bitmap, ICE_MAX_TRAFFIC_CLASS);
61         u32 agg_id;
62         enum ice_agg_type agg_type;
63         /* bw_t_info saves agg bw information */
64         struct ice_bw_type_info bw_t_info[ICE_MAX_TRAFFIC_CLASS];
65         /* save agg TC bitmap */
66         ice_declare_bitmap(replay_tc_bitmap, ICE_MAX_TRAFFIC_CLASS);
67 };
68
69 /* FW AQ command calls */
70 enum ice_status
71 ice_aq_query_rl_profile(struct ice_hw *hw, u16 num_profiles,
72                         struct ice_aqc_rl_profile_generic_elem *buf,
73                         u16 buf_size, struct ice_sq_cd *cd);
74 enum ice_status
75 ice_aq_cfg_l2_node_cgd(struct ice_hw *hw, u16 num_nodes,
76                        struct ice_aqc_cfg_l2_node_cgd_data *buf, u16 buf_size,
77                        struct ice_sq_cd *cd);
78 enum ice_status
79 ice_aq_move_sched_elems(struct ice_hw *hw, u16 grps_req,
80                         struct ice_aqc_move_elem *buf, u16 buf_size,
81                         u16 *grps_movd, struct ice_sq_cd *cd);
82 enum ice_status
83 ice_aq_query_sched_elems(struct ice_hw *hw, u16 elems_req,
84                          struct ice_aqc_get_elem *buf, u16 buf_size,
85                          u16 *elems_ret, struct ice_sq_cd *cd);
86 enum ice_status ice_sched_init_port(struct ice_port_info *pi);
87 enum ice_status ice_sched_query_res_alloc(struct ice_hw *hw);
88
89 /* Functions to cleanup scheduler SW DB */
90 void ice_sched_clear_port(struct ice_port_info *pi);
91 void ice_sched_cleanup_all(struct ice_hw *hw);
92 void ice_sched_clear_agg(struct ice_hw *hw);
93
94 /* Get a scheduling node from SW DB for given TEID */
95 struct ice_sched_node *ice_sched_get_node(struct ice_port_info *pi, u32 teid);
96 struct ice_sched_node *
97 ice_sched_find_node_by_teid(struct ice_sched_node *start_node, u32 teid);
98 /* Add a scheduling node into SW DB for given info */
99 enum ice_status
100 ice_sched_add_node(struct ice_port_info *pi, u8 layer,
101                    struct ice_aqc_txsched_elem_data *info);
102 void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node);
103 struct ice_sched_node *ice_sched_get_tc_node(struct ice_port_info *pi, u8 tc);
104 struct ice_sched_node *
105 ice_sched_get_free_qparent(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
106                            u8 owner);
107 enum ice_status
108 ice_sched_cfg_vsi(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 maxqs,
109                   u8 owner, bool enable);
110 enum ice_status ice_rm_vsi_lan_cfg(struct ice_port_info *pi, u16 vsi_handle);
111 struct ice_sched_node *
112 ice_sched_get_agg_node(struct ice_hw *hw, struct ice_sched_node *tc_node,
113                        u32 agg_id);
114 struct ice_sched_node *
115 ice_sched_get_vsi_node(struct ice_hw *hw, struct ice_sched_node *tc_node,
116                        u16 vsi_handle);
117 bool ice_sched_is_tree_balanced(struct ice_hw *hw, struct ice_sched_node *node);
118 enum ice_status
119 ice_aq_query_node_to_root(struct ice_hw *hw, u32 node_teid,
120                           struct ice_aqc_get_elem *buf, u16 buf_size,
121                           struct ice_sq_cd *cd);
122
123 /* Tx scheduler rate limiter functions */
124 enum ice_status
125 ice_cfg_agg(struct ice_port_info *pi, u32 agg_id,
126             enum ice_agg_type agg_type, u8 tc_bitmap);
127 enum ice_status
128 ice_move_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle,
129                     u8 tc_bitmap);
130 enum ice_status ice_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id);
131 enum ice_status
132 ice_cfg_q_bw_lmt(struct ice_port_info *pi, u32 q_id, enum ice_rl_type rl_type,
133                  u32 bw);
134 enum ice_status
135 ice_cfg_q_bw_dflt_lmt(struct ice_port_info *pi, u32 q_id,
136                       enum ice_rl_type rl_type);
137 enum ice_status
138 ice_cfg_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc,
139                        enum ice_rl_type rl_type, u32 bw);
140 enum ice_status
141 ice_cfg_tc_node_bw_dflt_lmt(struct ice_port_info *pi, u8 tc,
142                             enum ice_rl_type rl_type);
143 enum ice_status
144 ice_cfg_vsi_bw_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
145                           enum ice_rl_type rl_type, u32 bw);
146 enum ice_status
147 ice_cfg_vsi_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
148                                enum ice_rl_type rl_type);
149 enum ice_status
150 ice_cfg_agg_bw_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc,
151                           enum ice_rl_type rl_type, u32 bw);
152 enum ice_status
153 ice_cfg_agg_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc,
154                                enum ice_rl_type rl_type);
155 enum ice_status
156 ice_cfg_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle, u32 bw);
157 enum ice_status
158 ice_cfg_vsi_bw_no_shared_lmt(struct ice_port_info *pi, u16 vsi_handle);
159 enum ice_status
160 ice_cfg_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw);
161 enum ice_status
162 ice_cfg_agg_bw_no_shared_lmt(struct ice_port_info *pi, u32 agg_id);
163 enum ice_status
164 ice_cfg_vsi_q_priority(struct ice_port_info *pi, u16 num_qs, u32 *q_ids,
165                        u8 *q_prio);
166 enum ice_status
167 ice_cfg_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 ena_tcmap,
168                      enum ice_rl_type rl_type, u8 *bw_alloc);
169 enum ice_status
170 ice_cfg_agg_vsi_priority_per_tc(struct ice_port_info *pi, u32 agg_id,
171                                 u16 num_vsis, u16 *vsi_handle_arr,
172                                 u8 *node_prio, u8 tc);
173 enum ice_status
174 ice_cfg_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 ena_tcmap,
175                      enum ice_rl_type rl_type, u8 *bw_alloc);
176 bool
177 ice_sched_find_node_in_subtree(struct ice_hw *hw, struct ice_sched_node *base,
178                                struct ice_sched_node *node);
179 enum ice_status
180 ice_sched_set_node_bw_lmt(struct ice_port_info *pi, struct ice_sched_node *node,
181                           enum ice_rl_type rl_type, u32 bw);
182 enum ice_status
183 ice_sched_set_agg_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle);
184 enum ice_status
185 ice_sched_set_node_bw_lmt_per_tc(struct ice_port_info *pi, u32 id,
186                                  enum ice_agg_type agg_type, u8 tc,
187                                  enum ice_rl_type rl_type, u32 bw);
188 enum ice_status
189 ice_sched_set_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle,
190                                 u32 bw);
191 enum ice_status
192 ice_sched_set_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw);
193 enum ice_status
194 ice_sched_cfg_sibl_node_prio(struct ice_hw *hw, struct ice_sched_node *node,
195                              u8 priority);
196 enum ice_status
197 ice_sched_cfg_node_bw_alloc(struct ice_hw *hw, struct ice_sched_node *node,
198                             enum ice_rl_type rl_type, u8 bw_alloc);
199 enum ice_status
200 ice_sched_add_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc);
201 enum ice_status
202 ice_sched_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc);
203 enum ice_status
204 ice_sched_move_vsi_to_agg(struct ice_port_info *pi, u16 vsi_handle, u32 agg_id,
205                           u8 tc);
206 enum ice_status
207 ice_sched_del_rl_profile(struct ice_hw *hw,
208                          struct ice_aqc_rl_profile_info *rl_info);
209 void ice_sched_rm_unused_rl_prof(struct ice_port_info *pi);
210 #endif /* _ICE_SCHED_H_ */