xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_dcbx_api.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 /*
2  * Copyright (c) 2017-2018 Cavium, Inc.
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
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
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  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef __ECORE_DCBX_API_H__
30 #define __ECORE_DCBX_API_H__
31 
32 #include "ecore_status.h"
33 
34 #define DCBX_CONFIG_MAX_APP_PROTOCOL	4
35 
36 enum ecore_mib_read_type {
37 	ECORE_DCBX_OPERATIONAL_MIB,
38 	ECORE_DCBX_REMOTE_MIB,
39 	ECORE_DCBX_LOCAL_MIB,
40 	ECORE_DCBX_REMOTE_LLDP_MIB,
41 	ECORE_DCBX_LOCAL_LLDP_MIB,
42 	ECORE_DCBX_LLDP_TLVS
43 };
44 
45 struct ecore_dcbx_app_data {
46 	bool enable;		/* DCB enabled */
47 	u8 update;		/* Update indication */
48 	u8 priority;		/* Priority */
49 	u8 tc;			/* Traffic Class */
50 	bool dscp_enable;	/* DSCP enabled */
51 	u8 dscp_val;		/* DSCP value */
52 	bool dont_add_vlan0;	/* Do not insert a vlan tag with id 0 */
53 };
54 
55 #ifndef __EXTRACT__LINUX__IF__
56 enum dcbx_protocol_type {
57 	DCBX_PROTOCOL_ISCSI,
58 	DCBX_PROTOCOL_FCOE,
59 	DCBX_PROTOCOL_ROCE,
60 	DCBX_PROTOCOL_ROCE_V2,
61 	DCBX_PROTOCOL_ETH,
62 	DCBX_PROTOCOL_IWARP,
63 	DCBX_MAX_PROTOCOL_TYPE
64 };
65 
66 #define ECORE_LLDP_CHASSIS_ID_STAT_LEN 4
67 #define ECORE_LLDP_PORT_ID_STAT_LEN 4
68 #define ECORE_DCBX_MAX_APP_PROTOCOL 32
69 #define ECORE_MAX_PFC_PRIORITIES 8
70 #define ECORE_DCBX_DSCP_SIZE 64
71 
72 struct ecore_dcbx_lldp_remote {
73 	u32     peer_chassis_id[ECORE_LLDP_CHASSIS_ID_STAT_LEN];
74 	u32     peer_port_id[ECORE_LLDP_PORT_ID_STAT_LEN];
75 	bool	enable_rx;
76 	bool	enable_tx;
77 	u32     tx_interval;
78 	u32     max_credit;
79 };
80 
81 struct ecore_dcbx_lldp_local {
82 	u32     local_chassis_id[ECORE_LLDP_CHASSIS_ID_STAT_LEN];
83 	u32     local_port_id[ECORE_LLDP_PORT_ID_STAT_LEN];
84 };
85 
86 struct ecore_dcbx_app_prio {
87 	u8	roce;
88 	u8	roce_v2;
89 	u8	fcoe;
90 	u8	iscsi;
91 	u8	eth;
92 };
93 
94 struct ecore_dbcx_pfc_params {
95 	bool	willing;
96 	bool	enabled;
97 	u8	prio[ECORE_MAX_PFC_PRIORITIES];
98 	u8	max_tc;
99 };
100 
101 enum ecore_dcbx_sf_ieee_type {
102 	ECORE_DCBX_SF_IEEE_ETHTYPE,
103 	ECORE_DCBX_SF_IEEE_TCP_PORT,
104 	ECORE_DCBX_SF_IEEE_UDP_PORT,
105 	ECORE_DCBX_SF_IEEE_TCP_UDP_PORT
106 };
107 
108 struct ecore_app_entry {
109 	bool ethtype;
110 	enum ecore_dcbx_sf_ieee_type sf_ieee;
111 	bool enabled;
112 	u8 prio;
113 	u16 proto_id;
114 	enum dcbx_protocol_type proto_type;
115 };
116 
117 struct ecore_dcbx_params {
118 	struct ecore_app_entry app_entry[ECORE_DCBX_MAX_APP_PROTOCOL];
119 	u16	num_app_entries;
120 	bool	app_willing;
121 	bool	app_valid;
122 	bool	app_error;
123 	bool	ets_willing;
124 	bool	ets_enabled;
125 	bool	ets_cbs;
126 	u8	ets_pri_tc_tbl[ECORE_MAX_PFC_PRIORITIES];
127 	u8	ets_tc_bw_tbl[ECORE_MAX_PFC_PRIORITIES];
128 	u8	ets_tc_tsa_tbl[ECORE_MAX_PFC_PRIORITIES];
129 	struct ecore_dbcx_pfc_params pfc;
130 	u8	max_ets_tc;
131 };
132 
133 struct ecore_dcbx_admin_params {
134 	struct ecore_dcbx_params params;
135 	bool valid;		/* Indicate validity of params */
136 };
137 
138 struct ecore_dcbx_remote_params {
139 	struct ecore_dcbx_params params;
140 	bool valid;		/* Indicate validity of params */
141 };
142 
143 struct ecore_dcbx_operational_params {
144 	struct ecore_dcbx_app_prio app_prio;
145 	struct ecore_dcbx_params params;
146 	bool valid;		/* Indicate validity of params */
147 	bool enabled;
148 	bool ieee;
149 	bool cee;
150 	bool local;
151 	u32 err;
152 };
153 
154 struct ecore_dcbx_dscp_params {
155 	bool enabled;
156 	u8 dscp_pri_map[ECORE_DCBX_DSCP_SIZE];
157 };
158 
159 struct ecore_dcbx_get {
160 	struct ecore_dcbx_operational_params operational;
161 	struct ecore_dcbx_lldp_remote lldp_remote;
162 	struct ecore_dcbx_lldp_local lldp_local;
163 	struct ecore_dcbx_remote_params remote;
164 	struct ecore_dcbx_admin_params local;
165 	struct ecore_dcbx_dscp_params dscp;
166 };
167 #endif
168 
169 #define ECORE_DCBX_VERSION_DISABLED	0
170 #define ECORE_DCBX_VERSION_IEEE		1
171 #define ECORE_DCBX_VERSION_CEE		2
172 #define ECORE_DCBX_VERSION_DYNAMIC	3
173 
174 struct ecore_dcbx_set {
175 #define ECORE_DCBX_OVERRIDE_STATE	(1 << 0)
176 #define ECORE_DCBX_OVERRIDE_PFC_CFG	(1 << 1)
177 #define ECORE_DCBX_OVERRIDE_ETS_CFG	(1 << 2)
178 #define ECORE_DCBX_OVERRIDE_APP_CFG	(1 << 3)
179 #define ECORE_DCBX_OVERRIDE_DSCP_CFG	(1 << 4)
180 	u32 override_flags;
181 	bool enabled;
182 	struct ecore_dcbx_admin_params config;
183 	u32 ver_num;
184 	struct ecore_dcbx_dscp_params dscp;
185 };
186 
187 struct ecore_dcbx_results {
188 	bool dcbx_enabled;
189 	u8 pf_id;
190 	struct ecore_dcbx_app_data arr[DCBX_MAX_PROTOCOL_TYPE];
191 };
192 
193 struct ecore_dcbx_app_metadata {
194 	enum dcbx_protocol_type id;
195 	char *name;
196 	enum ecore_pci_personality personality;
197 };
198 
199 enum ecore_lldp_agent {
200 	ECORE_LLDP_NEAREST_BRIDGE = 0,
201 	ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE,
202 	ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE,
203 	ECORE_LLDP_MAX_AGENTS
204 };
205 
206 struct ecore_lldp_config_params {
207 	enum ecore_lldp_agent agent;
208 	u8 tx_interval;
209 	u8 tx_hold;
210 	u8 tx_credit;
211 	bool rx_enable;
212 	bool tx_enable;
213 	u32 chassis_id_tlv[ECORE_LLDP_CHASSIS_ID_STAT_LEN];
214 	u32 port_id_tlv[ECORE_LLDP_PORT_ID_STAT_LEN];
215 };
216 
217 #define ECORE_LLDP_SYS_TLV_SIZE 256
218 struct ecore_lldp_sys_tlvs {
219 	bool discard_mandatory_tlv;
220 	u8 buf[ECORE_LLDP_SYS_TLV_SIZE];
221 	u16 buf_size;
222 };
223 
224 struct ecore_lldp_stats {
225 	enum ecore_lldp_agent agent;
226 	u32 tx_frames;
227 	u32 rx_frames;
228 	u32 rx_discards;
229 	u32 rx_age_outs;
230 };
231 
232 enum _ecore_status_t ecore_dcbx_query_params(struct ecore_hwfn *p_hwfn,
233 					     struct ecore_dcbx_get *p_get,
234 					     enum ecore_mib_read_type type);
235 
236 enum _ecore_status_t ecore_dcbx_get_config_params(struct ecore_hwfn *p_hwfn,
237 						  struct ecore_dcbx_set
238 						  *params);
239 
240 enum _ecore_status_t ecore_dcbx_config_params(struct ecore_hwfn *p_hwfn,
241 					      struct ecore_ptt *p_ptt,
242 					      struct ecore_dcbx_set *params,
243 					      bool hw_commit);
244 
245 enum _ecore_status_t ecore_lldp_register_tlv(struct ecore_hwfn *p_hwfn,
246 					     struct ecore_ptt *p_ptt,
247 					     enum ecore_lldp_agent agent,
248 					     u8 tlv_type);
249 
250 enum _ecore_status_t
251 ecore_lldp_get_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
252 		      struct ecore_lldp_config_params *p_params);
253 
254 enum _ecore_status_t
255 ecore_lldp_set_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
256 		      struct ecore_lldp_config_params *p_params);
257 
258 enum _ecore_status_t
259 ecore_lldp_set_system_tlvs(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
260 			   struct ecore_lldp_sys_tlvs *p_params);
261 
262 /* Returns priority value for a given dscp index */
263 enum _ecore_status_t
264 ecore_dcbx_get_dscp_priority(struct ecore_hwfn *p_hwfn,
265 			     u8 dscp_index, u8 *p_dscp_pri);
266 
267 /* Sets priority value for a given dscp index */
268 enum _ecore_status_t
269 ecore_dcbx_set_dscp_priority(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
270 			     u8 dscp_index, u8 pri_val);
271 
272 enum _ecore_status_t
273 ecore_lldp_get_stats(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
274 		     struct ecore_lldp_stats *p_params);
275 
276 #ifndef __EXTRACT__LINUX__C__
277 static const struct ecore_dcbx_app_metadata ecore_dcbx_app_update[] = {
278 	{DCBX_PROTOCOL_ISCSI, "ISCSI", ECORE_PCI_ISCSI},
279 	{DCBX_PROTOCOL_FCOE, "FCOE", ECORE_PCI_FCOE},
280 	{DCBX_PROTOCOL_ROCE, "ROCE", ECORE_PCI_ETH_ROCE},
281 	{DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", ECORE_PCI_ETH_ROCE},
282 	{DCBX_PROTOCOL_ETH, "ETH", ECORE_PCI_ETH},
283 	{DCBX_PROTOCOL_IWARP, "IWARP", ECORE_PCI_ETH_IWARP}
284 };
285 #endif
286 
287 #endif /* __ECORE_DCBX_API_H__ */
288