xref: /freebsd/sys/dev/ice/ice_dcb.h (revision f2635e844dd138ac9dfba676f27d41750049af26)
171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2015f8cc5SEric Joyner /*  Copyright (c) 2024, Intel Corporation
371d10453SEric Joyner  *  All rights reserved.
471d10453SEric Joyner  *
571d10453SEric Joyner  *  Redistribution and use in source and binary forms, with or without
671d10453SEric Joyner  *  modification, are permitted provided that the following conditions are met:
771d10453SEric Joyner  *
871d10453SEric Joyner  *   1. Redistributions of source code must retain the above copyright notice,
971d10453SEric Joyner  *      this list of conditions and the following disclaimer.
1071d10453SEric Joyner  *
1171d10453SEric Joyner  *   2. Redistributions in binary form must reproduce the above copyright
1271d10453SEric Joyner  *      notice, this list of conditions and the following disclaimer in the
1371d10453SEric Joyner  *      documentation and/or other materials provided with the distribution.
1471d10453SEric Joyner  *
1571d10453SEric Joyner  *   3. Neither the name of the Intel Corporation nor the names of its
1671d10453SEric Joyner  *      contributors may be used to endorse or promote products derived from
1771d10453SEric Joyner  *      this software without specific prior written permission.
1871d10453SEric Joyner  *
1971d10453SEric Joyner  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2071d10453SEric Joyner  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171d10453SEric Joyner  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2271d10453SEric Joyner  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2371d10453SEric Joyner  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471d10453SEric Joyner  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571d10453SEric Joyner  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2671d10453SEric Joyner  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2771d10453SEric Joyner  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2871d10453SEric Joyner  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971d10453SEric Joyner  *  POSSIBILITY OF SUCH DAMAGE.
3071d10453SEric Joyner  */
3171d10453SEric Joyner 
3271d10453SEric Joyner #ifndef _ICE_DCB_H_
3371d10453SEric Joyner #define _ICE_DCB_H_
3471d10453SEric Joyner 
3571d10453SEric Joyner #include "ice_type.h"
3671d10453SEric Joyner #include "ice_common.h"
3771d10453SEric Joyner 
3871d10453SEric Joyner #define ICE_DCBX_OFFLOAD_DIS		0
3971d10453SEric Joyner #define ICE_DCBX_OFFLOAD_ENABLED	1
4071d10453SEric Joyner 
4171d10453SEric Joyner #define ICE_DCBX_STATUS_NOT_STARTED	0
4271d10453SEric Joyner #define ICE_DCBX_STATUS_IN_PROGRESS	1
4371d10453SEric Joyner #define ICE_DCBX_STATUS_DONE		2
4471d10453SEric Joyner #define ICE_DCBX_STATUS_MULTIPLE_PEERS	3
4571d10453SEric Joyner #define ICE_DCBX_STATUS_DIS		7
4671d10453SEric Joyner 
4771d10453SEric Joyner #define ICE_TLV_TYPE_END		0
4871d10453SEric Joyner #define ICE_TLV_TYPE_ORG		127
4971d10453SEric Joyner 
5071d10453SEric Joyner #define ICE_IEEE_8021QAZ_OUI		0x0080C2
5171d10453SEric Joyner #define ICE_IEEE_SUBTYPE_ETS_CFG	9
5271d10453SEric Joyner #define ICE_IEEE_SUBTYPE_ETS_REC	10
5371d10453SEric Joyner #define ICE_IEEE_SUBTYPE_PFC_CFG	11
5471d10453SEric Joyner #define ICE_IEEE_SUBTYPE_APP_PRI	12
5571d10453SEric Joyner 
5671d10453SEric Joyner #define ICE_CEE_DCBX_OUI		0x001B21
5771d10453SEric Joyner #define ICE_CEE_DCBX_TYPE		2
5871d10453SEric Joyner 
5956429daeSEric Joyner #define ICE_DSCP_OUI			0xFFFFFF
6056429daeSEric Joyner #define ICE_DSCP_SUBTYPE_DSCP2UP	0x41
6156429daeSEric Joyner #define ICE_DSCP_SUBTYPE_ENFORCE	0x42
6256429daeSEric Joyner #define ICE_DSCP_SUBTYPE_TCBW		0x43
6356429daeSEric Joyner #define ICE_DSCP_SUBTYPE_PFC		0x44
6456429daeSEric Joyner #define ICE_DSCP_IPV6_OFFSET		80
6556429daeSEric Joyner 
6671d10453SEric Joyner #define ICE_CEE_SUBTYPE_CTRL		1
6771d10453SEric Joyner #define ICE_CEE_SUBTYPE_PG_CFG		2
6871d10453SEric Joyner #define ICE_CEE_SUBTYPE_PFC_CFG		3
6971d10453SEric Joyner #define ICE_CEE_SUBTYPE_APP_PRI		4
7071d10453SEric Joyner 
7171d10453SEric Joyner #define ICE_CEE_MAX_FEAT_TYPE		3
7271d10453SEric Joyner #define ICE_LLDP_ADMINSTATUS_DIS	0
7371d10453SEric Joyner #define ICE_LLDP_ADMINSTATUS_ENA_RX	1
7471d10453SEric Joyner #define ICE_LLDP_ADMINSTATUS_ENA_TX	2
7571d10453SEric Joyner #define ICE_LLDP_ADMINSTATUS_ENA_RXTX	3
7671d10453SEric Joyner 
7771d10453SEric Joyner /* Defines for LLDP TLV header */
7871d10453SEric Joyner #define ICE_LLDP_TLV_LEN_S		0
7971d10453SEric Joyner #define ICE_LLDP_TLV_LEN_M		(0x01FF << ICE_LLDP_TLV_LEN_S)
8071d10453SEric Joyner #define ICE_LLDP_TLV_TYPE_S		9
8171d10453SEric Joyner #define ICE_LLDP_TLV_TYPE_M		(0x7F << ICE_LLDP_TLV_TYPE_S)
8271d10453SEric Joyner #define ICE_LLDP_TLV_SUBTYPE_S		0
8371d10453SEric Joyner #define ICE_LLDP_TLV_SUBTYPE_M		(0xFF << ICE_LLDP_TLV_SUBTYPE_S)
8471d10453SEric Joyner #define ICE_LLDP_TLV_OUI_S		8
8571d10453SEric Joyner #define ICE_LLDP_TLV_OUI_M		(0xFFFFFFUL << ICE_LLDP_TLV_OUI_S)
8671d10453SEric Joyner 
8771d10453SEric Joyner /* Defines for IEEE ETS TLV */
8871d10453SEric Joyner #define ICE_IEEE_ETS_MAXTC_S	0
8971d10453SEric Joyner #define ICE_IEEE_ETS_MAXTC_M		(0x7 << ICE_IEEE_ETS_MAXTC_S)
9071d10453SEric Joyner #define ICE_IEEE_ETS_CBS_S		6
9171d10453SEric Joyner #define ICE_IEEE_ETS_CBS_M		BIT(ICE_IEEE_ETS_CBS_S)
9271d10453SEric Joyner #define ICE_IEEE_ETS_WILLING_S		7
9371d10453SEric Joyner #define ICE_IEEE_ETS_WILLING_M		BIT(ICE_IEEE_ETS_WILLING_S)
9471d10453SEric Joyner #define ICE_IEEE_ETS_PRIO_0_S		0
9571d10453SEric Joyner #define ICE_IEEE_ETS_PRIO_0_M		(0x7 << ICE_IEEE_ETS_PRIO_0_S)
9671d10453SEric Joyner #define ICE_IEEE_ETS_PRIO_1_S		4
9771d10453SEric Joyner #define ICE_IEEE_ETS_PRIO_1_M		(0x7 << ICE_IEEE_ETS_PRIO_1_S)
9871d10453SEric Joyner #define ICE_CEE_PGID_PRIO_0_S		0
9971d10453SEric Joyner #define ICE_CEE_PGID_PRIO_0_M		(0xF << ICE_CEE_PGID_PRIO_0_S)
10071d10453SEric Joyner #define ICE_CEE_PGID_PRIO_1_S		4
10171d10453SEric Joyner #define ICE_CEE_PGID_PRIO_1_M		(0xF << ICE_CEE_PGID_PRIO_1_S)
10271d10453SEric Joyner #define ICE_CEE_PGID_STRICT		15
10371d10453SEric Joyner 
10471d10453SEric Joyner /* Defines for IEEE TSA types */
10571d10453SEric Joyner #define ICE_IEEE_TSA_STRICT		0
10671d10453SEric Joyner #define ICE_IEEE_TSA_CBS		1
10771d10453SEric Joyner #define ICE_IEEE_TSA_ETS		2
10871d10453SEric Joyner #define ICE_IEEE_TSA_VENDOR		255
10971d10453SEric Joyner 
11071d10453SEric Joyner /* Defines for IEEE PFC TLV */
11171d10453SEric Joyner #define ICE_IEEE_PFC_CAP_S		0
11271d10453SEric Joyner #define ICE_IEEE_PFC_CAP_M		(0xF << ICE_IEEE_PFC_CAP_S)
11371d10453SEric Joyner #define ICE_IEEE_PFC_MBC_S		6
11471d10453SEric Joyner #define ICE_IEEE_PFC_MBC_M		BIT(ICE_IEEE_PFC_MBC_S)
11571d10453SEric Joyner #define ICE_IEEE_PFC_WILLING_S		7
11671d10453SEric Joyner #define ICE_IEEE_PFC_WILLING_M		BIT(ICE_IEEE_PFC_WILLING_S)
11771d10453SEric Joyner 
11871d10453SEric Joyner /* Defines for IEEE APP TLV */
11971d10453SEric Joyner #define ICE_IEEE_APP_SEL_S		0
12071d10453SEric Joyner #define ICE_IEEE_APP_SEL_M		(0x7 << ICE_IEEE_APP_SEL_S)
12171d10453SEric Joyner #define ICE_IEEE_APP_PRIO_S		5
12271d10453SEric Joyner #define ICE_IEEE_APP_PRIO_M		(0x7 << ICE_IEEE_APP_PRIO_S)
12371d10453SEric Joyner 
12471d10453SEric Joyner /* TLV definitions for preparing MIB */
12571d10453SEric Joyner #define ICE_TLV_ID_CHASSIS_ID		0
12671d10453SEric Joyner #define ICE_TLV_ID_PORT_ID		1
12771d10453SEric Joyner #define ICE_TLV_ID_TIME_TO_LIVE		2
12871d10453SEric Joyner #define ICE_IEEE_TLV_ID_ETS_CFG		3
12971d10453SEric Joyner #define ICE_IEEE_TLV_ID_ETS_REC		4
13071d10453SEric Joyner #define ICE_IEEE_TLV_ID_PFC_CFG		5
13171d10453SEric Joyner #define ICE_IEEE_TLV_ID_APP_PRI		6
13271d10453SEric Joyner #define ICE_TLV_ID_END_OF_LLDPPDU	7
13371d10453SEric Joyner #define ICE_TLV_ID_START		ICE_IEEE_TLV_ID_ETS_CFG
13456429daeSEric Joyner #define ICE_TLV_ID_DSCP_UP		3
13556429daeSEric Joyner #define ICE_TLV_ID_DSCP_ENF		4
13656429daeSEric Joyner #define ICE_TLV_ID_DSCP_TC_BW		5
13756429daeSEric Joyner #define ICE_TLV_ID_DSCP_TO_PFC		6
13871d10453SEric Joyner 
13971d10453SEric Joyner #define ICE_IEEE_ETS_TLV_LEN		25
14071d10453SEric Joyner #define ICE_IEEE_PFC_TLV_LEN		6
14171d10453SEric Joyner #define ICE_IEEE_APP_TLV_LEN		11
14271d10453SEric Joyner 
14356429daeSEric Joyner #define ICE_DSCP_UP_TLV_LEN		148
14456429daeSEric Joyner #define ICE_DSCP_ENF_TLV_LEN		132
14556429daeSEric Joyner #define ICE_DSCP_TC_BW_TLV_LEN		25
14656429daeSEric Joyner #define ICE_DSCP_PFC_TLV_LEN		6
14756429daeSEric Joyner 
14871d10453SEric Joyner #pragma pack(1)
14971d10453SEric Joyner /* IEEE 802.1AB LLDP Organization specific TLV */
15071d10453SEric Joyner struct ice_lldp_org_tlv {
15171d10453SEric Joyner 	__be16 typelen;
15271d10453SEric Joyner 	__be32 ouisubtype;
1537d7af7f8SEric Joyner 	u8 tlvinfo[STRUCT_HACK_VAR_LEN];
15471d10453SEric Joyner };
15571d10453SEric Joyner #pragma pack()
15671d10453SEric Joyner 
15771d10453SEric Joyner struct ice_cee_tlv_hdr {
15871d10453SEric Joyner 	__be16 typelen;
15971d10453SEric Joyner 	u8 operver;
16071d10453SEric Joyner 	u8 maxver;
16171d10453SEric Joyner };
16271d10453SEric Joyner 
16371d10453SEric Joyner struct ice_cee_ctrl_tlv {
16471d10453SEric Joyner 	struct ice_cee_tlv_hdr hdr;
16571d10453SEric Joyner 	__be32 seqno;
16671d10453SEric Joyner 	__be32 ackno;
16771d10453SEric Joyner };
16871d10453SEric Joyner 
16971d10453SEric Joyner struct ice_cee_feat_tlv {
17071d10453SEric Joyner 	struct ice_cee_tlv_hdr hdr;
17171d10453SEric Joyner 	u8 en_will_err; /* Bits: |En|Will|Err|Reserved(5)| */
17271d10453SEric Joyner #define ICE_CEE_FEAT_TLV_ENA_M		0x80
17371d10453SEric Joyner #define ICE_CEE_FEAT_TLV_WILLING_M	0x40
17471d10453SEric Joyner #define ICE_CEE_FEAT_TLV_ERR_M		0x20
17571d10453SEric Joyner 	u8 subtype;
1767d7af7f8SEric Joyner 	u8 tlvinfo[STRUCT_HACK_VAR_LEN];
17771d10453SEric Joyner };
17871d10453SEric Joyner 
17971d10453SEric Joyner #pragma pack(1)
18071d10453SEric Joyner struct ice_cee_app_prio {
18171d10453SEric Joyner 	__be16 protocol;
18271d10453SEric Joyner 	u8 upper_oui_sel; /* Bits: |Upper OUI(6)|Selector(2)| */
18371d10453SEric Joyner #define ICE_CEE_APP_SELECTOR_M	0x03
18471d10453SEric Joyner 	__be16 lower_oui;
18571d10453SEric Joyner 	u8 prio_map;
18671d10453SEric Joyner };
18771d10453SEric Joyner #pragma pack()
18871d10453SEric Joyner 
18971d10453SEric Joyner /* TODO: The below structures related LLDP/DCBX variables
19071d10453SEric Joyner  * and statistics are defined but need to find how to get
19171d10453SEric Joyner  * the required information from the Firmware to use them
19271d10453SEric Joyner  */
19371d10453SEric Joyner 
19471d10453SEric Joyner /* IEEE 802.1AB LLDP Agent Statistics */
19571d10453SEric Joyner struct ice_lldp_stats {
19671d10453SEric Joyner 	u64 remtablelastchangetime;
19771d10453SEric Joyner 	u64 remtableinserts;
19871d10453SEric Joyner 	u64 remtabledeletes;
19971d10453SEric Joyner 	u64 remtabledrops;
20071d10453SEric Joyner 	u64 remtableageouts;
20171d10453SEric Joyner 	u64 txframestotal;
20271d10453SEric Joyner 	u64 rxframesdiscarded;
20371d10453SEric Joyner 	u64 rxportframeerrors;
20471d10453SEric Joyner 	u64 rxportframestotal;
20571d10453SEric Joyner 	u64 rxporttlvsdiscardedtotal;
20671d10453SEric Joyner 	u64 rxporttlvsunrecognizedtotal;
20771d10453SEric Joyner 	u64 remtoomanyneighbors;
20871d10453SEric Joyner };
20971d10453SEric Joyner 
21071d10453SEric Joyner /* IEEE 802.1Qaz DCBX variables */
21171d10453SEric Joyner struct ice_dcbx_variables {
21271d10453SEric Joyner 	u32 defmaxtrafficclasses;
21371d10453SEric Joyner 	u32 defprioritytcmapping;
21471d10453SEric Joyner 	u32 deftcbandwidth;
21571d10453SEric Joyner 	u32 deftsaassignment;
21671d10453SEric Joyner };
21771d10453SEric Joyner 
218*f2635e84SEric Joyner int
21971d10453SEric Joyner ice_aq_get_lldp_mib(struct ice_hw *hw, u8 bridge_type, u8 mib_type, void *buf,
22071d10453SEric Joyner 		    u16 buf_size, u16 *local_len, u16 *remote_len,
22171d10453SEric Joyner 		    struct ice_sq_cd *cd);
222*f2635e84SEric Joyner int
22371d10453SEric Joyner ice_aq_add_delete_lldp_tlv(struct ice_hw *hw, u8 bridge_type, bool add_lldp_tlv,
22471d10453SEric Joyner 			   void *buf, u16 buf_size, u16 tlv_len, u16 *mib_len,
22571d10453SEric Joyner 			   struct ice_sq_cd *cd);
226*f2635e84SEric Joyner int
22771d10453SEric Joyner ice_aq_update_lldp_tlv(struct ice_hw *hw, u8 bridge_type, void *buf,
22871d10453SEric Joyner 		       u16 buf_size, u16 old_len, u16 new_len, u16 offset,
22971d10453SEric Joyner 		       u16 *mib_len, struct ice_sq_cd *cd);
230*f2635e84SEric Joyner int
23171d10453SEric Joyner ice_aq_dcb_ignore_pfc(struct ice_hw *hw, u8 tcmap, bool request, u8 *tcmap_ret,
23271d10453SEric Joyner 		      struct ice_sq_cd *cd);
233*f2635e84SEric Joyner int
23471d10453SEric Joyner ice_aq_get_cee_dcb_cfg(struct ice_hw *hw,
23571d10453SEric Joyner 		       struct ice_aqc_get_cee_dcb_cfg_resp *buff,
23671d10453SEric Joyner 		       struct ice_sq_cd *cd);
237*f2635e84SEric Joyner int
23871d10453SEric Joyner ice_aq_query_pfc_mode(struct ice_hw *hw, u8 *pfcmode_ret, struct ice_sq_cd *cd);
239*f2635e84SEric Joyner int
24071d10453SEric Joyner ice_aq_set_dcb_parameters(struct ice_hw *hw, bool dcb_enable,
24171d10453SEric Joyner 			  struct ice_sq_cd *cd);
242*f2635e84SEric Joyner int
24356429daeSEric Joyner ice_aq_set_pfc_mode(struct ice_hw *hw, u8 pfc_mode, struct ice_sq_cd *cd);
244*f2635e84SEric Joyner int ice_lldp_to_dcb_cfg(u8 *lldpmib, struct ice_dcbx_cfg *dcbcfg);
24571d10453SEric Joyner u8 ice_get_dcbx_status(struct ice_hw *hw);
246*f2635e84SEric Joyner int
24771d10453SEric Joyner ice_aq_get_dcb_cfg(struct ice_hw *hw, u8 mib_type, u8 bridgetype,
24871d10453SEric Joyner 		   struct ice_dcbx_cfg *dcbcfg);
249*f2635e84SEric Joyner int ice_get_dcb_cfg(struct ice_port_info *pi);
250*f2635e84SEric Joyner int ice_set_dcb_cfg(struct ice_port_info *pi);
2518923de59SPiotr Kubaj void ice_get_dcb_cfg_from_mib_change(struct ice_port_info *pi,
2528923de59SPiotr Kubaj 				     struct ice_rq_event_info *event);
253*f2635e84SEric Joyner int ice_init_dcb(struct ice_hw *hw, bool enable_mib_change);
25471d10453SEric Joyner void ice_dcb_cfg_to_lldp(u8 *lldpmib, u16 *miblen, struct ice_dcbx_cfg *dcbcfg);
255*f2635e84SEric Joyner int
25671d10453SEric Joyner ice_query_port_ets(struct ice_port_info *pi,
25771d10453SEric Joyner 		   struct ice_aqc_port_ets_elem *buf, u16 buf_size,
25871d10453SEric Joyner 		   struct ice_sq_cd *cmd_details);
259*f2635e84SEric Joyner int
26071d10453SEric Joyner ice_aq_query_port_ets(struct ice_port_info *pi,
26171d10453SEric Joyner 		      struct ice_aqc_port_ets_elem *buf, u16 buf_size,
26271d10453SEric Joyner 		      struct ice_sq_cd *cd);
263*f2635e84SEric Joyner int
26471d10453SEric Joyner ice_update_port_tc_tree_cfg(struct ice_port_info *pi,
26571d10453SEric Joyner 			    struct ice_aqc_port_ets_elem *buf);
266*f2635e84SEric Joyner int
26771d10453SEric Joyner ice_aq_stop_lldp(struct ice_hw *hw, bool shutdown_lldp_agent, bool persist,
26871d10453SEric Joyner 		 struct ice_sq_cd *cd);
269*f2635e84SEric Joyner int
27071d10453SEric Joyner ice_aq_start_lldp(struct ice_hw *hw, bool persist, struct ice_sq_cd *cd);
271*f2635e84SEric Joyner int
27271d10453SEric Joyner ice_aq_start_stop_dcbx(struct ice_hw *hw, bool start_dcbx_agent,
27371d10453SEric Joyner 		       bool *dcbx_agent_status, struct ice_sq_cd *cd);
274*f2635e84SEric Joyner int ice_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_mib);
275*f2635e84SEric Joyner int
27671d10453SEric Joyner ice_aq_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_update,
27771d10453SEric Joyner 			   struct ice_sq_cd *cd);
27871d10453SEric Joyner #endif /* _ICE_DCB_H_ */
279