xref: /freebsd/sys/dev/ice/ice_dcb.h (revision f2635e844dd138ac9dfba676f27d41750049af26)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2024, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _ICE_DCB_H_
33 #define _ICE_DCB_H_
34 
35 #include "ice_type.h"
36 #include "ice_common.h"
37 
38 #define ICE_DCBX_OFFLOAD_DIS		0
39 #define ICE_DCBX_OFFLOAD_ENABLED	1
40 
41 #define ICE_DCBX_STATUS_NOT_STARTED	0
42 #define ICE_DCBX_STATUS_IN_PROGRESS	1
43 #define ICE_DCBX_STATUS_DONE		2
44 #define ICE_DCBX_STATUS_MULTIPLE_PEERS	3
45 #define ICE_DCBX_STATUS_DIS		7
46 
47 #define ICE_TLV_TYPE_END		0
48 #define ICE_TLV_TYPE_ORG		127
49 
50 #define ICE_IEEE_8021QAZ_OUI		0x0080C2
51 #define ICE_IEEE_SUBTYPE_ETS_CFG	9
52 #define ICE_IEEE_SUBTYPE_ETS_REC	10
53 #define ICE_IEEE_SUBTYPE_PFC_CFG	11
54 #define ICE_IEEE_SUBTYPE_APP_PRI	12
55 
56 #define ICE_CEE_DCBX_OUI		0x001B21
57 #define ICE_CEE_DCBX_TYPE		2
58 
59 #define ICE_DSCP_OUI			0xFFFFFF
60 #define ICE_DSCP_SUBTYPE_DSCP2UP	0x41
61 #define ICE_DSCP_SUBTYPE_ENFORCE	0x42
62 #define ICE_DSCP_SUBTYPE_TCBW		0x43
63 #define ICE_DSCP_SUBTYPE_PFC		0x44
64 #define ICE_DSCP_IPV6_OFFSET		80
65 
66 #define ICE_CEE_SUBTYPE_CTRL		1
67 #define ICE_CEE_SUBTYPE_PG_CFG		2
68 #define ICE_CEE_SUBTYPE_PFC_CFG		3
69 #define ICE_CEE_SUBTYPE_APP_PRI		4
70 
71 #define ICE_CEE_MAX_FEAT_TYPE		3
72 #define ICE_LLDP_ADMINSTATUS_DIS	0
73 #define ICE_LLDP_ADMINSTATUS_ENA_RX	1
74 #define ICE_LLDP_ADMINSTATUS_ENA_TX	2
75 #define ICE_LLDP_ADMINSTATUS_ENA_RXTX	3
76 
77 /* Defines for LLDP TLV header */
78 #define ICE_LLDP_TLV_LEN_S		0
79 #define ICE_LLDP_TLV_LEN_M		(0x01FF << ICE_LLDP_TLV_LEN_S)
80 #define ICE_LLDP_TLV_TYPE_S		9
81 #define ICE_LLDP_TLV_TYPE_M		(0x7F << ICE_LLDP_TLV_TYPE_S)
82 #define ICE_LLDP_TLV_SUBTYPE_S		0
83 #define ICE_LLDP_TLV_SUBTYPE_M		(0xFF << ICE_LLDP_TLV_SUBTYPE_S)
84 #define ICE_LLDP_TLV_OUI_S		8
85 #define ICE_LLDP_TLV_OUI_M		(0xFFFFFFUL << ICE_LLDP_TLV_OUI_S)
86 
87 /* Defines for IEEE ETS TLV */
88 #define ICE_IEEE_ETS_MAXTC_S	0
89 #define ICE_IEEE_ETS_MAXTC_M		(0x7 << ICE_IEEE_ETS_MAXTC_S)
90 #define ICE_IEEE_ETS_CBS_S		6
91 #define ICE_IEEE_ETS_CBS_M		BIT(ICE_IEEE_ETS_CBS_S)
92 #define ICE_IEEE_ETS_WILLING_S		7
93 #define ICE_IEEE_ETS_WILLING_M		BIT(ICE_IEEE_ETS_WILLING_S)
94 #define ICE_IEEE_ETS_PRIO_0_S		0
95 #define ICE_IEEE_ETS_PRIO_0_M		(0x7 << ICE_IEEE_ETS_PRIO_0_S)
96 #define ICE_IEEE_ETS_PRIO_1_S		4
97 #define ICE_IEEE_ETS_PRIO_1_M		(0x7 << ICE_IEEE_ETS_PRIO_1_S)
98 #define ICE_CEE_PGID_PRIO_0_S		0
99 #define ICE_CEE_PGID_PRIO_0_M		(0xF << ICE_CEE_PGID_PRIO_0_S)
100 #define ICE_CEE_PGID_PRIO_1_S		4
101 #define ICE_CEE_PGID_PRIO_1_M		(0xF << ICE_CEE_PGID_PRIO_1_S)
102 #define ICE_CEE_PGID_STRICT		15
103 
104 /* Defines for IEEE TSA types */
105 #define ICE_IEEE_TSA_STRICT		0
106 #define ICE_IEEE_TSA_CBS		1
107 #define ICE_IEEE_TSA_ETS		2
108 #define ICE_IEEE_TSA_VENDOR		255
109 
110 /* Defines for IEEE PFC TLV */
111 #define ICE_IEEE_PFC_CAP_S		0
112 #define ICE_IEEE_PFC_CAP_M		(0xF << ICE_IEEE_PFC_CAP_S)
113 #define ICE_IEEE_PFC_MBC_S		6
114 #define ICE_IEEE_PFC_MBC_M		BIT(ICE_IEEE_PFC_MBC_S)
115 #define ICE_IEEE_PFC_WILLING_S		7
116 #define ICE_IEEE_PFC_WILLING_M		BIT(ICE_IEEE_PFC_WILLING_S)
117 
118 /* Defines for IEEE APP TLV */
119 #define ICE_IEEE_APP_SEL_S		0
120 #define ICE_IEEE_APP_SEL_M		(0x7 << ICE_IEEE_APP_SEL_S)
121 #define ICE_IEEE_APP_PRIO_S		5
122 #define ICE_IEEE_APP_PRIO_M		(0x7 << ICE_IEEE_APP_PRIO_S)
123 
124 /* TLV definitions for preparing MIB */
125 #define ICE_TLV_ID_CHASSIS_ID		0
126 #define ICE_TLV_ID_PORT_ID		1
127 #define ICE_TLV_ID_TIME_TO_LIVE		2
128 #define ICE_IEEE_TLV_ID_ETS_CFG		3
129 #define ICE_IEEE_TLV_ID_ETS_REC		4
130 #define ICE_IEEE_TLV_ID_PFC_CFG		5
131 #define ICE_IEEE_TLV_ID_APP_PRI		6
132 #define ICE_TLV_ID_END_OF_LLDPPDU	7
133 #define ICE_TLV_ID_START		ICE_IEEE_TLV_ID_ETS_CFG
134 #define ICE_TLV_ID_DSCP_UP		3
135 #define ICE_TLV_ID_DSCP_ENF		4
136 #define ICE_TLV_ID_DSCP_TC_BW		5
137 #define ICE_TLV_ID_DSCP_TO_PFC		6
138 
139 #define ICE_IEEE_ETS_TLV_LEN		25
140 #define ICE_IEEE_PFC_TLV_LEN		6
141 #define ICE_IEEE_APP_TLV_LEN		11
142 
143 #define ICE_DSCP_UP_TLV_LEN		148
144 #define ICE_DSCP_ENF_TLV_LEN		132
145 #define ICE_DSCP_TC_BW_TLV_LEN		25
146 #define ICE_DSCP_PFC_TLV_LEN		6
147 
148 #pragma pack(1)
149 /* IEEE 802.1AB LLDP Organization specific TLV */
150 struct ice_lldp_org_tlv {
151 	__be16 typelen;
152 	__be32 ouisubtype;
153 	u8 tlvinfo[STRUCT_HACK_VAR_LEN];
154 };
155 #pragma pack()
156 
157 struct ice_cee_tlv_hdr {
158 	__be16 typelen;
159 	u8 operver;
160 	u8 maxver;
161 };
162 
163 struct ice_cee_ctrl_tlv {
164 	struct ice_cee_tlv_hdr hdr;
165 	__be32 seqno;
166 	__be32 ackno;
167 };
168 
169 struct ice_cee_feat_tlv {
170 	struct ice_cee_tlv_hdr hdr;
171 	u8 en_will_err; /* Bits: |En|Will|Err|Reserved(5)| */
172 #define ICE_CEE_FEAT_TLV_ENA_M		0x80
173 #define ICE_CEE_FEAT_TLV_WILLING_M	0x40
174 #define ICE_CEE_FEAT_TLV_ERR_M		0x20
175 	u8 subtype;
176 	u8 tlvinfo[STRUCT_HACK_VAR_LEN];
177 };
178 
179 #pragma pack(1)
180 struct ice_cee_app_prio {
181 	__be16 protocol;
182 	u8 upper_oui_sel; /* Bits: |Upper OUI(6)|Selector(2)| */
183 #define ICE_CEE_APP_SELECTOR_M	0x03
184 	__be16 lower_oui;
185 	u8 prio_map;
186 };
187 #pragma pack()
188 
189 /* TODO: The below structures related LLDP/DCBX variables
190  * and statistics are defined but need to find how to get
191  * the required information from the Firmware to use them
192  */
193 
194 /* IEEE 802.1AB LLDP Agent Statistics */
195 struct ice_lldp_stats {
196 	u64 remtablelastchangetime;
197 	u64 remtableinserts;
198 	u64 remtabledeletes;
199 	u64 remtabledrops;
200 	u64 remtableageouts;
201 	u64 txframestotal;
202 	u64 rxframesdiscarded;
203 	u64 rxportframeerrors;
204 	u64 rxportframestotal;
205 	u64 rxporttlvsdiscardedtotal;
206 	u64 rxporttlvsunrecognizedtotal;
207 	u64 remtoomanyneighbors;
208 };
209 
210 /* IEEE 802.1Qaz DCBX variables */
211 struct ice_dcbx_variables {
212 	u32 defmaxtrafficclasses;
213 	u32 defprioritytcmapping;
214 	u32 deftcbandwidth;
215 	u32 deftsaassignment;
216 };
217 
218 int
219 ice_aq_get_lldp_mib(struct ice_hw *hw, u8 bridge_type, u8 mib_type, void *buf,
220 		    u16 buf_size, u16 *local_len, u16 *remote_len,
221 		    struct ice_sq_cd *cd);
222 int
223 ice_aq_add_delete_lldp_tlv(struct ice_hw *hw, u8 bridge_type, bool add_lldp_tlv,
224 			   void *buf, u16 buf_size, u16 tlv_len, u16 *mib_len,
225 			   struct ice_sq_cd *cd);
226 int
227 ice_aq_update_lldp_tlv(struct ice_hw *hw, u8 bridge_type, void *buf,
228 		       u16 buf_size, u16 old_len, u16 new_len, u16 offset,
229 		       u16 *mib_len, struct ice_sq_cd *cd);
230 int
231 ice_aq_dcb_ignore_pfc(struct ice_hw *hw, u8 tcmap, bool request, u8 *tcmap_ret,
232 		      struct ice_sq_cd *cd);
233 int
234 ice_aq_get_cee_dcb_cfg(struct ice_hw *hw,
235 		       struct ice_aqc_get_cee_dcb_cfg_resp *buff,
236 		       struct ice_sq_cd *cd);
237 int
238 ice_aq_query_pfc_mode(struct ice_hw *hw, u8 *pfcmode_ret, struct ice_sq_cd *cd);
239 int
240 ice_aq_set_dcb_parameters(struct ice_hw *hw, bool dcb_enable,
241 			  struct ice_sq_cd *cd);
242 int
243 ice_aq_set_pfc_mode(struct ice_hw *hw, u8 pfc_mode, struct ice_sq_cd *cd);
244 int ice_lldp_to_dcb_cfg(u8 *lldpmib, struct ice_dcbx_cfg *dcbcfg);
245 u8 ice_get_dcbx_status(struct ice_hw *hw);
246 int
247 ice_aq_get_dcb_cfg(struct ice_hw *hw, u8 mib_type, u8 bridgetype,
248 		   struct ice_dcbx_cfg *dcbcfg);
249 int ice_get_dcb_cfg(struct ice_port_info *pi);
250 int ice_set_dcb_cfg(struct ice_port_info *pi);
251 void ice_get_dcb_cfg_from_mib_change(struct ice_port_info *pi,
252 				     struct ice_rq_event_info *event);
253 int ice_init_dcb(struct ice_hw *hw, bool enable_mib_change);
254 void ice_dcb_cfg_to_lldp(u8 *lldpmib, u16 *miblen, struct ice_dcbx_cfg *dcbcfg);
255 int
256 ice_query_port_ets(struct ice_port_info *pi,
257 		   struct ice_aqc_port_ets_elem *buf, u16 buf_size,
258 		   struct ice_sq_cd *cmd_details);
259 int
260 ice_aq_query_port_ets(struct ice_port_info *pi,
261 		      struct ice_aqc_port_ets_elem *buf, u16 buf_size,
262 		      struct ice_sq_cd *cd);
263 int
264 ice_update_port_tc_tree_cfg(struct ice_port_info *pi,
265 			    struct ice_aqc_port_ets_elem *buf);
266 int
267 ice_aq_stop_lldp(struct ice_hw *hw, bool shutdown_lldp_agent, bool persist,
268 		 struct ice_sq_cd *cd);
269 int
270 ice_aq_start_lldp(struct ice_hw *hw, bool persist, struct ice_sq_cd *cd);
271 int
272 ice_aq_start_stop_dcbx(struct ice_hw *hw, bool start_dcbx_agent,
273 		       bool *dcbx_agent_status, struct ice_sq_cd *cd);
274 int ice_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_mib);
275 int
276 ice_aq_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_update,
277 			   struct ice_sq_cd *cd);
278 #endif /* _ICE_DCB_H_ */
279