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