1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019, Intel Corporation. */
3 
4 #ifndef _ICE_DCB_H_
5 #define _ICE_DCB_H_
6 
7 #include "ice_type.h"
8 
9 #define ICE_DCBX_STATUS_NOT_STARTED	0
10 #define ICE_DCBX_STATUS_IN_PROGRESS	1
11 #define ICE_DCBX_STATUS_DONE		2
12 #define ICE_DCBX_STATUS_DIS		7
13 
14 #define ICE_TLV_TYPE_END		0
15 #define ICE_TLV_TYPE_ORG		127
16 
17 #define ICE_IEEE_8021QAZ_OUI		0x0080C2
18 #define ICE_IEEE_SUBTYPE_ETS_CFG	9
19 #define ICE_IEEE_SUBTYPE_ETS_REC	10
20 #define ICE_IEEE_SUBTYPE_PFC_CFG	11
21 #define ICE_IEEE_SUBTYPE_APP_PRI	12
22 
23 #define ICE_CEE_DCBX_OUI		0x001B21
24 #define ICE_CEE_DCBX_TYPE		2
25 
26 #define ICE_DSCP_OUI			0xFFFFFF
27 #define ICE_DSCP_SUBTYPE_DSCP2UP	0x41
28 #define ICE_DSCP_SUBTYPE_ENFORCE	0x42
29 #define ICE_DSCP_SUBTYPE_TCBW		0x43
30 #define ICE_DSCP_SUBTYPE_PFC		0x44
31 #define ICE_DSCP_IPV6_OFFSET		80
32 
33 #define ICE_CEE_SUBTYPE_PG_CFG		2
34 #define ICE_CEE_SUBTYPE_PFC_CFG		3
35 #define ICE_CEE_SUBTYPE_APP_PRI		4
36 #define ICE_CEE_MAX_FEAT_TYPE		3
37 /* Defines for LLDP TLV header */
38 #define ICE_LLDP_TLV_LEN_S		0
39 #define ICE_LLDP_TLV_LEN_M		(0x01FF << ICE_LLDP_TLV_LEN_S)
40 #define ICE_LLDP_TLV_TYPE_S		9
41 #define ICE_LLDP_TLV_TYPE_M		(0x7F << ICE_LLDP_TLV_TYPE_S)
42 #define ICE_LLDP_TLV_SUBTYPE_S		0
43 #define ICE_LLDP_TLV_SUBTYPE_M		(0xFF << ICE_LLDP_TLV_SUBTYPE_S)
44 #define ICE_LLDP_TLV_OUI_S		8
45 #define ICE_LLDP_TLV_OUI_M		(0xFFFFFFUL << ICE_LLDP_TLV_OUI_S)
46 
47 /* Defines for IEEE ETS TLV */
48 #define ICE_IEEE_ETS_MAXTC_S	0
49 #define ICE_IEEE_ETS_MAXTC_M		(0x7 << ICE_IEEE_ETS_MAXTC_S)
50 #define ICE_IEEE_ETS_CBS_S		6
51 #define ICE_IEEE_ETS_CBS_M		BIT(ICE_IEEE_ETS_CBS_S)
52 #define ICE_IEEE_ETS_WILLING_S		7
53 #define ICE_IEEE_ETS_WILLING_M		BIT(ICE_IEEE_ETS_WILLING_S)
54 #define ICE_IEEE_ETS_PRIO_0_S		0
55 #define ICE_IEEE_ETS_PRIO_0_M		(0x7 << ICE_IEEE_ETS_PRIO_0_S)
56 #define ICE_IEEE_ETS_PRIO_1_S		4
57 #define ICE_IEEE_ETS_PRIO_1_M		(0x7 << ICE_IEEE_ETS_PRIO_1_S)
58 #define ICE_CEE_PGID_PRIO_0_S		0
59 #define ICE_CEE_PGID_PRIO_0_M		(0xF << ICE_CEE_PGID_PRIO_0_S)
60 #define ICE_CEE_PGID_PRIO_1_S		4
61 #define ICE_CEE_PGID_PRIO_1_M		(0xF << ICE_CEE_PGID_PRIO_1_S)
62 #define ICE_CEE_PGID_STRICT		15
63 
64 /* Defines for IEEE TSA types */
65 #define ICE_IEEE_TSA_STRICT		0
66 #define ICE_IEEE_TSA_ETS		2
67 
68 /* Defines for IEEE PFC TLV */
69 #define ICE_IEEE_PFC_CAP_S		0
70 #define ICE_IEEE_PFC_CAP_M		(0xF << ICE_IEEE_PFC_CAP_S)
71 #define ICE_IEEE_PFC_MBC_S		6
72 #define ICE_IEEE_PFC_MBC_M		BIT(ICE_IEEE_PFC_MBC_S)
73 #define ICE_IEEE_PFC_WILLING_S		7
74 #define ICE_IEEE_PFC_WILLING_M		BIT(ICE_IEEE_PFC_WILLING_S)
75 
76 /* Defines for IEEE APP TLV */
77 #define ICE_IEEE_APP_SEL_S		0
78 #define ICE_IEEE_APP_SEL_M		(0x7 << ICE_IEEE_APP_SEL_S)
79 #define ICE_IEEE_APP_PRIO_S		5
80 #define ICE_IEEE_APP_PRIO_M		(0x7 << ICE_IEEE_APP_PRIO_S)
81 
82 /* TLV definitions for preparing MIB */
83 #define ICE_IEEE_TLV_ID_ETS_CFG		3
84 #define ICE_IEEE_TLV_ID_ETS_REC		4
85 #define ICE_IEEE_TLV_ID_PFC_CFG		5
86 #define ICE_IEEE_TLV_ID_APP_PRI		6
87 #define ICE_TLV_ID_END_OF_LLDPPDU	7
88 #define ICE_TLV_ID_START		ICE_IEEE_TLV_ID_ETS_CFG
89 #define ICE_TLV_ID_DSCP_UP		3
90 #define ICE_TLV_ID_DSCP_ENF		4
91 #define ICE_TLV_ID_DSCP_TC_BW		5
92 #define ICE_TLV_ID_DSCP_TO_PFC		6
93 
94 #define ICE_IEEE_ETS_TLV_LEN		25
95 #define ICE_IEEE_PFC_TLV_LEN		6
96 #define ICE_IEEE_APP_TLV_LEN		11
97 
98 #define ICE_DSCP_UP_TLV_LEN		148
99 #define ICE_DSCP_ENF_TLV_LEN		132
100 #define ICE_DSCP_TC_BW_TLV_LEN		25
101 #define ICE_DSCP_PFC_TLV_LEN		6
102 
103 /* IEEE 802.1AB LLDP Organization specific TLV */
104 struct ice_lldp_org_tlv {
105 	__be16 typelen;
106 	__be32 ouisubtype;
107 	u8 tlvinfo[];
108 } __packed;
109 
110 struct ice_cee_tlv_hdr {
111 	__be16 typelen;
112 	u8 operver;
113 	u8 maxver;
114 };
115 
116 struct ice_cee_ctrl_tlv {
117 	struct ice_cee_tlv_hdr hdr;
118 	__be32 seqno;
119 	__be32 ackno;
120 };
121 
122 struct ice_cee_feat_tlv {
123 	struct ice_cee_tlv_hdr hdr;
124 	u8 en_will_err; /* Bits: |En|Will|Err|Reserved(5)| */
125 #define ICE_CEE_FEAT_TLV_ENA_M		0x80
126 #define ICE_CEE_FEAT_TLV_WILLING_M	0x40
127 #define ICE_CEE_FEAT_TLV_ERR_M		0x20
128 	u8 subtype;
129 	u8 tlvinfo[];
130 };
131 
132 struct ice_cee_app_prio {
133 	__be16 protocol;
134 	u8 upper_oui_sel; /* Bits: |Upper OUI(6)|Selector(2)| */
135 #define ICE_CEE_APP_SELECTOR_M	0x03
136 	__be16 lower_oui;
137 	u8 prio_map;
138 } __packed;
139 
140 int ice_aq_set_pfc_mode(struct ice_hw *hw, u8 pfc_mode, struct ice_sq_cd *cd);
141 int
142 ice_aq_get_dcb_cfg(struct ice_hw *hw, u8 mib_type, u8 bridgetype,
143 		   struct ice_dcbx_cfg *dcbcfg);
144 int ice_get_dcb_cfg(struct ice_port_info *pi);
145 int ice_set_dcb_cfg(struct ice_port_info *pi);
146 int ice_init_dcb(struct ice_hw *hw, bool enable_mib_change);
147 int
148 ice_query_port_ets(struct ice_port_info *pi,
149 		   struct ice_aqc_port_ets_elem *buf, u16 buf_size,
150 		   struct ice_sq_cd *cmd_details);
151 #ifdef CONFIG_DCB
152 int
153 ice_aq_stop_lldp(struct ice_hw *hw, bool shutdown_lldp_agent, bool persist,
154 		 struct ice_sq_cd *cd);
155 int ice_aq_start_lldp(struct ice_hw *hw, bool persist, struct ice_sq_cd *cd);
156 int
157 ice_aq_start_stop_dcbx(struct ice_hw *hw, bool start_dcbx_agent,
158 		       bool *dcbx_agent_status, struct ice_sq_cd *cd);
159 int ice_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_mib);
160 #else /* CONFIG_DCB */
161 static inline int
162 ice_aq_stop_lldp(struct ice_hw __always_unused *hw,
163 		 bool __always_unused shutdown_lldp_agent,
164 		 bool __always_unused persist,
165 		 struct ice_sq_cd __always_unused *cd)
166 {
167 	return 0;
168 }
169 
170 static inline int
171 ice_aq_start_lldp(struct ice_hw __always_unused *hw,
172 		  bool __always_unused persist,
173 		  struct ice_sq_cd __always_unused *cd)
174 {
175 	return 0;
176 }
177 
178 static inline int
179 ice_aq_start_stop_dcbx(struct ice_hw __always_unused *hw,
180 		       bool __always_unused start_dcbx_agent,
181 		       bool *dcbx_agent_status,
182 		       struct ice_sq_cd __always_unused *cd)
183 {
184 	*dcbx_agent_status = false;
185 
186 	return 0;
187 }
188 
189 static inline int
190 ice_cfg_lldp_mib_change(struct ice_hw __always_unused *hw,
191 			bool __always_unused ena_mib)
192 {
193 	return 0;
194 }
195 
196 #endif /* CONFIG_DCB */
197 #endif /* _ICE_DCB_H_ */
198