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