xref: /freebsd/sys/dev/ice/ice_dcb.h (revision 038405f32f71ad8ba0280ae066417f986ede79db)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2021, 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 /*$FreeBSD$*/
32 
33 #ifndef _ICE_DCB_H_
34 #define _ICE_DCB_H_
35 
36 #include "ice_type.h"
37 #include "ice_common.h"
38 
39 #define ICE_DCBX_OFFLOAD_DIS		0
40 #define ICE_DCBX_OFFLOAD_ENABLED	1
41 
42 #define ICE_DCBX_STATUS_NOT_STARTED	0
43 #define ICE_DCBX_STATUS_IN_PROGRESS	1
44 #define ICE_DCBX_STATUS_DONE		2
45 #define ICE_DCBX_STATUS_MULTIPLE_PEERS	3
46 #define ICE_DCBX_STATUS_DIS		7
47 
48 #define ICE_TLV_TYPE_END		0
49 #define ICE_TLV_TYPE_ORG		127
50 
51 #define ICE_IEEE_8021QAZ_OUI		0x0080C2
52 #define ICE_IEEE_SUBTYPE_ETS_CFG	9
53 #define ICE_IEEE_SUBTYPE_ETS_REC	10
54 #define ICE_IEEE_SUBTYPE_PFC_CFG	11
55 #define ICE_IEEE_SUBTYPE_APP_PRI	12
56 
57 #define ICE_CEE_DCBX_OUI		0x001B21
58 #define ICE_CEE_DCBX_TYPE		2
59 
60 #define ICE_DSCP_OUI			0xFFFFFF
61 #define ICE_DSCP_SUBTYPE_DSCP2UP	0x41
62 #define ICE_DSCP_SUBTYPE_ENFORCE	0x42
63 #define ICE_DSCP_SUBTYPE_TCBW		0x43
64 #define ICE_DSCP_SUBTYPE_PFC		0x44
65 #define ICE_DSCP_IPV6_OFFSET		80
66 
67 #define ICE_CEE_SUBTYPE_CTRL		1
68 #define ICE_CEE_SUBTYPE_PG_CFG		2
69 #define ICE_CEE_SUBTYPE_PFC_CFG		3
70 #define ICE_CEE_SUBTYPE_APP_PRI		4
71 
72 #define ICE_CEE_MAX_FEAT_TYPE		3
73 #define ICE_LLDP_ADMINSTATUS_DIS	0
74 #define ICE_LLDP_ADMINSTATUS_ENA_RX	1
75 #define ICE_LLDP_ADMINSTATUS_ENA_TX	2
76 #define ICE_LLDP_ADMINSTATUS_ENA_RXTX	3
77 
78 /* Defines for LLDP TLV header */
79 #define ICE_LLDP_TLV_LEN_S		0
80 #define ICE_LLDP_TLV_LEN_M		(0x01FF << ICE_LLDP_TLV_LEN_S)
81 #define ICE_LLDP_TLV_TYPE_S		9
82 #define ICE_LLDP_TLV_TYPE_M		(0x7F << ICE_LLDP_TLV_TYPE_S)
83 #define ICE_LLDP_TLV_SUBTYPE_S		0
84 #define ICE_LLDP_TLV_SUBTYPE_M		(0xFF << ICE_LLDP_TLV_SUBTYPE_S)
85 #define ICE_LLDP_TLV_OUI_S		8
86 #define ICE_LLDP_TLV_OUI_M		(0xFFFFFFUL << ICE_LLDP_TLV_OUI_S)
87 
88 /* Defines for IEEE ETS TLV */
89 #define ICE_IEEE_ETS_MAXTC_S	0
90 #define ICE_IEEE_ETS_MAXTC_M		(0x7 << ICE_IEEE_ETS_MAXTC_S)
91 #define ICE_IEEE_ETS_CBS_S		6
92 #define ICE_IEEE_ETS_CBS_M		BIT(ICE_IEEE_ETS_CBS_S)
93 #define ICE_IEEE_ETS_WILLING_S		7
94 #define ICE_IEEE_ETS_WILLING_M		BIT(ICE_IEEE_ETS_WILLING_S)
95 #define ICE_IEEE_ETS_PRIO_0_S		0
96 #define ICE_IEEE_ETS_PRIO_0_M		(0x7 << ICE_IEEE_ETS_PRIO_0_S)
97 #define ICE_IEEE_ETS_PRIO_1_S		4
98 #define ICE_IEEE_ETS_PRIO_1_M		(0x7 << ICE_IEEE_ETS_PRIO_1_S)
99 #define ICE_CEE_PGID_PRIO_0_S		0
100 #define ICE_CEE_PGID_PRIO_0_M		(0xF << ICE_CEE_PGID_PRIO_0_S)
101 #define ICE_CEE_PGID_PRIO_1_S		4
102 #define ICE_CEE_PGID_PRIO_1_M		(0xF << ICE_CEE_PGID_PRIO_1_S)
103 #define ICE_CEE_PGID_STRICT		15
104 
105 /* Defines for IEEE TSA types */
106 #define ICE_IEEE_TSA_STRICT		0
107 #define ICE_IEEE_TSA_CBS		1
108 #define ICE_IEEE_TSA_ETS		2
109 #define ICE_IEEE_TSA_VENDOR		255
110 
111 /* Defines for IEEE PFC TLV */
112 #define ICE_IEEE_PFC_CAP_S		0
113 #define ICE_IEEE_PFC_CAP_M		(0xF << ICE_IEEE_PFC_CAP_S)
114 #define ICE_IEEE_PFC_MBC_S		6
115 #define ICE_IEEE_PFC_MBC_M		BIT(ICE_IEEE_PFC_MBC_S)
116 #define ICE_IEEE_PFC_WILLING_S		7
117 #define ICE_IEEE_PFC_WILLING_M		BIT(ICE_IEEE_PFC_WILLING_S)
118 
119 /* Defines for IEEE APP TLV */
120 #define ICE_IEEE_APP_SEL_S		0
121 #define ICE_IEEE_APP_SEL_M		(0x7 << ICE_IEEE_APP_SEL_S)
122 #define ICE_IEEE_APP_PRIO_S		5
123 #define ICE_IEEE_APP_PRIO_M		(0x7 << ICE_IEEE_APP_PRIO_S)
124 
125 /* TLV definitions for preparing MIB */
126 #define ICE_TLV_ID_CHASSIS_ID		0
127 #define ICE_TLV_ID_PORT_ID		1
128 #define ICE_TLV_ID_TIME_TO_LIVE		2
129 #define ICE_IEEE_TLV_ID_ETS_CFG		3
130 #define ICE_IEEE_TLV_ID_ETS_REC		4
131 #define ICE_IEEE_TLV_ID_PFC_CFG		5
132 #define ICE_IEEE_TLV_ID_APP_PRI		6
133 #define ICE_TLV_ID_END_OF_LLDPPDU	7
134 #define ICE_TLV_ID_START		ICE_IEEE_TLV_ID_ETS_CFG
135 #define ICE_TLV_ID_DSCP_UP		3
136 #define ICE_TLV_ID_DSCP_ENF		4
137 #define ICE_TLV_ID_DSCP_TC_BW		5
138 #define ICE_TLV_ID_DSCP_TO_PFC		6
139 
140 #define ICE_IEEE_ETS_TLV_LEN		25
141 #define ICE_IEEE_PFC_TLV_LEN		6
142 #define ICE_IEEE_APP_TLV_LEN		11
143 
144 #define ICE_DSCP_UP_TLV_LEN		148
145 #define ICE_DSCP_ENF_TLV_LEN		132
146 #define ICE_DSCP_TC_BW_TLV_LEN		25
147 #define ICE_DSCP_PFC_TLV_LEN		6
148 
149 #pragma pack(1)
150 /* IEEE 802.1AB LLDP Organization specific TLV */
151 struct ice_lldp_org_tlv {
152 	__be16 typelen;
153 	__be32 ouisubtype;
154 	u8 tlvinfo[STRUCT_HACK_VAR_LEN];
155 };
156 #pragma pack()
157 
158 struct ice_cee_tlv_hdr {
159 	__be16 typelen;
160 	u8 operver;
161 	u8 maxver;
162 };
163 
164 struct ice_cee_ctrl_tlv {
165 	struct ice_cee_tlv_hdr hdr;
166 	__be32 seqno;
167 	__be32 ackno;
168 };
169 
170 struct ice_cee_feat_tlv {
171 	struct ice_cee_tlv_hdr hdr;
172 	u8 en_will_err; /* Bits: |En|Will|Err|Reserved(5)| */
173 #define ICE_CEE_FEAT_TLV_ENA_M		0x80
174 #define ICE_CEE_FEAT_TLV_WILLING_M	0x40
175 #define ICE_CEE_FEAT_TLV_ERR_M		0x20
176 	u8 subtype;
177 	u8 tlvinfo[STRUCT_HACK_VAR_LEN];
178 };
179 
180 #pragma pack(1)
181 struct ice_cee_app_prio {
182 	__be16 protocol;
183 	u8 upper_oui_sel; /* Bits: |Upper OUI(6)|Selector(2)| */
184 #define ICE_CEE_APP_SELECTOR_M	0x03
185 	__be16 lower_oui;
186 	u8 prio_map;
187 };
188 #pragma pack()
189 
190 /* TODO: The below structures related LLDP/DCBX variables
191  * and statistics are defined but need to find how to get
192  * the required information from the Firmware to use them
193  */
194 
195 /* IEEE 802.1AB LLDP Agent Statistics */
196 struct ice_lldp_stats {
197 	u64 remtablelastchangetime;
198 	u64 remtableinserts;
199 	u64 remtabledeletes;
200 	u64 remtabledrops;
201 	u64 remtableageouts;
202 	u64 txframestotal;
203 	u64 rxframesdiscarded;
204 	u64 rxportframeerrors;
205 	u64 rxportframestotal;
206 	u64 rxporttlvsdiscardedtotal;
207 	u64 rxporttlvsunrecognizedtotal;
208 	u64 remtoomanyneighbors;
209 };
210 
211 /* IEEE 802.1Qaz DCBX variables */
212 struct ice_dcbx_variables {
213 	u32 defmaxtrafficclasses;
214 	u32 defprioritytcmapping;
215 	u32 deftcbandwidth;
216 	u32 deftsaassignment;
217 };
218 
219 enum ice_status
220 ice_aq_get_lldp_mib(struct ice_hw *hw, u8 bridge_type, u8 mib_type, void *buf,
221 		    u16 buf_size, u16 *local_len, u16 *remote_len,
222 		    struct ice_sq_cd *cd);
223 enum ice_status
224 ice_aq_add_delete_lldp_tlv(struct ice_hw *hw, u8 bridge_type, bool add_lldp_tlv,
225 			   void *buf, u16 buf_size, u16 tlv_len, u16 *mib_len,
226 			   struct ice_sq_cd *cd);
227 enum ice_status
228 ice_aq_update_lldp_tlv(struct ice_hw *hw, u8 bridge_type, void *buf,
229 		       u16 buf_size, u16 old_len, u16 new_len, u16 offset,
230 		       u16 *mib_len, struct ice_sq_cd *cd);
231 enum ice_status
232 ice_aq_dcb_ignore_pfc(struct ice_hw *hw, u8 tcmap, bool request, u8 *tcmap_ret,
233 		      struct ice_sq_cd *cd);
234 enum ice_status
235 ice_aq_get_cee_dcb_cfg(struct ice_hw *hw,
236 		       struct ice_aqc_get_cee_dcb_cfg_resp *buff,
237 		       struct ice_sq_cd *cd);
238 enum ice_status
239 ice_aq_query_pfc_mode(struct ice_hw *hw, u8 *pfcmode_ret, struct ice_sq_cd *cd);
240 enum ice_status
241 ice_aq_set_dcb_parameters(struct ice_hw *hw, bool dcb_enable,
242 			  struct ice_sq_cd *cd);
243 enum ice_status
244 ice_aq_set_pfc_mode(struct ice_hw *hw, u8 pfc_mode, struct ice_sq_cd *cd);
245 enum ice_status ice_lldp_to_dcb_cfg(u8 *lldpmib, struct ice_dcbx_cfg *dcbcfg);
246 u8 ice_get_dcbx_status(struct ice_hw *hw);
247 enum ice_status
248 ice_aq_get_dcb_cfg(struct ice_hw *hw, u8 mib_type, u8 bridgetype,
249 		   struct ice_dcbx_cfg *dcbcfg);
250 enum ice_status ice_get_dcb_cfg(struct ice_port_info *pi);
251 enum ice_status ice_set_dcb_cfg(struct ice_port_info *pi);
252 enum ice_status ice_init_dcb(struct ice_hw *hw, bool enable_mib_change);
253 void ice_dcb_cfg_to_lldp(u8 *lldpmib, u16 *miblen, struct ice_dcbx_cfg *dcbcfg);
254 enum ice_status
255 ice_query_port_ets(struct ice_port_info *pi,
256 		   struct ice_aqc_port_ets_elem *buf, u16 buf_size,
257 		   struct ice_sq_cd *cmd_details);
258 enum ice_status
259 ice_aq_query_port_ets(struct ice_port_info *pi,
260 		      struct ice_aqc_port_ets_elem *buf, u16 buf_size,
261 		      struct ice_sq_cd *cd);
262 enum ice_status
263 ice_update_port_tc_tree_cfg(struct ice_port_info *pi,
264 			    struct ice_aqc_port_ets_elem *buf);
265 enum ice_status
266 ice_aq_stop_lldp(struct ice_hw *hw, bool shutdown_lldp_agent, bool persist,
267 		 struct ice_sq_cd *cd);
268 enum ice_status
269 ice_aq_start_lldp(struct ice_hw *hw, bool persist, struct ice_sq_cd *cd);
270 enum ice_status
271 ice_aq_start_stop_dcbx(struct ice_hw *hw, bool start_dcbx_agent,
272 		       bool *dcbx_agent_status, struct ice_sq_cd *cd);
273 enum ice_status ice_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_mib);
274 enum ice_status
275 ice_aq_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_update,
276 			   struct ice_sq_cd *cd);
277 #endif /* _ICE_DCB_H_ */
278