1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, v.1,  (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 
22 /*
23 * Copyright 2014-2017 Cavium, Inc.
24 * The contents of this file are subject to the terms of the Common Development
25 * and Distribution License, v.1,  (the "License").
26 
27 * You may not use this file except in compliance with the License.
28 
29 * You can obtain a copy of the License at available
30 * at http://opensource.org/licenses/CDDL-1.0
31 
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 */
35 
36 #ifndef __ECORE_DCBX_API_H__
37 #define __ECORE_DCBX_API_H__
38 
39 #include "ecore_status.h"
40 
41 #define DCBX_CONFIG_MAX_APP_PROTOCOL	4
42 
43 enum ecore_mib_read_type {
44 	ECORE_DCBX_OPERATIONAL_MIB,
45 	ECORE_DCBX_REMOTE_MIB,
46 	ECORE_DCBX_LOCAL_MIB,
47 	ECORE_DCBX_REMOTE_LLDP_MIB,
48 	ECORE_DCBX_LOCAL_LLDP_MIB
49 };
50 
51 struct ecore_dcbx_app_data {
52 	bool enable;		/* DCB enabled */
53 	u8 update;		/* Update indication */
54 	u8 priority;		/* Priority */
55 	u8 tc;			/* Traffic Class */
56 	bool dscp_enable;	/* DSCP enabled */
57 	u8 dscp_val;		/* DSCP value */
58 };
59 
60 #ifndef __EXTRACT__LINUX__
61 enum dcbx_protocol_type {
62 	DCBX_PROTOCOL_ISCSI,
63 	DCBX_PROTOCOL_FCOE,
64 	DCBX_PROTOCOL_ROCE,
65 	DCBX_PROTOCOL_ROCE_V2,
66 	DCBX_PROTOCOL_ETH,
67 	DCBX_PROTOCOL_IWARP,
68 	DCBX_MAX_PROTOCOL_TYPE
69 };
70 
71 #define ECORE_LLDP_CHASSIS_ID_STAT_LEN 4
72 #define ECORE_LLDP_PORT_ID_STAT_LEN 4
73 #define ECORE_DCBX_MAX_APP_PROTOCOL 32
74 #define ECORE_MAX_PFC_PRIORITIES 8
75 #define ECORE_DCBX_DSCP_SIZE 64
76 
77 struct ecore_dcbx_lldp_remote {
78 	u32     peer_chassis_id[ECORE_LLDP_CHASSIS_ID_STAT_LEN];
79 	u32     peer_port_id[ECORE_LLDP_PORT_ID_STAT_LEN];
80 	bool	enable_rx;
81 	bool	enable_tx;
82 	u32     tx_interval;
83 	u32     max_credit;
84 };
85 
86 struct ecore_dcbx_lldp_local {
87 	u32     local_chassis_id[ECORE_LLDP_CHASSIS_ID_STAT_LEN];
88 	u32     local_port_id[ECORE_LLDP_PORT_ID_STAT_LEN];
89 };
90 
91 struct ecore_dcbx_app_prio {
92 	u8	roce;
93 	u8	roce_v2;
94 	u8	fcoe;
95 	u8	iscsi;
96 	u8	eth;
97 };
98 
99 struct ecore_dbcx_pfc_params {
100 	bool	willing;
101 	bool	enabled;
102 	u8	prio[ECORE_MAX_PFC_PRIORITIES];
103 	u8	max_tc;
104 };
105 
106 enum ecore_dcbx_sf_ieee_type {
107 	ECORE_DCBX_SF_IEEE_ETHTYPE,
108 	ECORE_DCBX_SF_IEEE_TCP_PORT,
109 	ECORE_DCBX_SF_IEEE_UDP_PORT,
110 	ECORE_DCBX_SF_IEEE_TCP_UDP_PORT
111 };
112 
113 struct ecore_app_entry {
114 	bool ethtype;
115 	enum ecore_dcbx_sf_ieee_type sf_ieee;
116 	bool enabled;
117 	u8 prio;
118 	u16 proto_id;
119 	enum dcbx_protocol_type proto_type;
120 };
121 
122 struct ecore_dcbx_params {
123 	struct ecore_app_entry app_entry[ECORE_DCBX_MAX_APP_PROTOCOL];
124 	u16	num_app_entries;
125 	bool	app_willing;
126 	bool	app_valid;
127 	bool	app_error;
128 	bool	ets_willing;
129 	bool	ets_enabled;
130 	bool	ets_cbs;
131 	bool	valid;          /* Indicate validity of params */
132 	u8	ets_pri_tc_tbl[ECORE_MAX_PFC_PRIORITIES];
133 	u8	ets_tc_bw_tbl[ECORE_MAX_PFC_PRIORITIES];
134 	u8	ets_tc_tsa_tbl[ECORE_MAX_PFC_PRIORITIES];
135 	struct ecore_dbcx_pfc_params pfc;
136 	u8	max_ets_tc;
137 };
138 
139 struct ecore_dcbx_admin_params {
140 	struct ecore_dcbx_params params;
141 	bool valid;		/* Indicate validity of params */
142 };
143 
144 struct ecore_dcbx_remote_params {
145 	struct ecore_dcbx_params params;
146 	bool valid;		/* Indicate validity of params */
147 };
148 
149 struct ecore_dcbx_operational_params {
150 	struct ecore_dcbx_app_prio app_prio;
151 	struct ecore_dcbx_params params;
152 	bool valid;		/* Indicate validity of params */
153 	bool enabled;
154 	bool ieee;
155 	bool cee;
156 	bool local;
157 	u32 err;
158 };
159 
160 struct ecore_dcbx_dscp_params {
161 	bool enabled;
162 	u8 dscp_pri_map[ECORE_DCBX_DSCP_SIZE];
163 };
164 
165 struct ecore_dcbx_get {
166 	struct ecore_dcbx_operational_params operational;
167 	struct ecore_dcbx_lldp_remote lldp_remote;
168 	struct ecore_dcbx_lldp_local lldp_local;
169 	struct ecore_dcbx_remote_params remote;
170 	struct ecore_dcbx_admin_params local;
171 	struct ecore_dcbx_dscp_params dscp;
172 };
173 #endif
174 
175 #define ECORE_DCBX_VERSION_DISABLED	0
176 #define ECORE_DCBX_VERSION_IEEE		1
177 #define ECORE_DCBX_VERSION_CEE		2
178 #define ECORE_DCBX_VERSION_DYNAMIC	3
179 
180 struct ecore_dcbx_set {
181 #define ECORE_DCBX_OVERRIDE_STATE	(1 << 0)
182 #define ECORE_DCBX_OVERRIDE_PFC_CFG	(1 << 1)
183 #define ECORE_DCBX_OVERRIDE_ETS_CFG	(1 << 2)
184 #define ECORE_DCBX_OVERRIDE_APP_CFG	(1 << 3)
185 #define ECORE_DCBX_OVERRIDE_DSCP_CFG	(1 << 4)
186 	u32 override_flags;
187 	bool enabled;
188 	struct ecore_dcbx_admin_params config;
189 	u32 ver_num;
190 	struct ecore_dcbx_dscp_params dscp;
191 };
192 
193 struct ecore_dcbx_results {
194 	bool dcbx_enabled;
195 	u8 pf_id;
196 	struct ecore_dcbx_app_data arr[DCBX_MAX_PROTOCOL_TYPE];
197 };
198 
199 struct ecore_dcbx_app_metadata {
200 	enum dcbx_protocol_type id;
201 	char *name;
202 	enum ecore_pci_personality personality;
203 };
204 
205 enum _ecore_status_t ecore_dcbx_query_params(struct ecore_hwfn *,
206 					     struct ecore_dcbx_get *,
207 					     enum ecore_mib_read_type);
208 
209 enum _ecore_status_t ecore_dcbx_get_config_params(struct ecore_hwfn *,
210 						  struct ecore_dcbx_set *);
211 
212 enum _ecore_status_t ecore_dcbx_config_params(struct ecore_hwfn *,
213 					      struct ecore_ptt *,
214 					      struct ecore_dcbx_set *,
215 					      bool);
216 
217 static const struct ecore_dcbx_app_metadata ecore_dcbx_app_update[] = {
218 	{DCBX_PROTOCOL_ISCSI, "ISCSI", ECORE_PCI_ISCSI},
219 	{DCBX_PROTOCOL_FCOE, "FCOE", ECORE_PCI_FCOE},
220 	{DCBX_PROTOCOL_ROCE, "ROCE", ECORE_PCI_ETH_ROCE},
221 	{DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", ECORE_PCI_ETH_ROCE},
222 	{DCBX_PROTOCOL_ETH, "ETH", ECORE_PCI_ETH},
223 	{DCBX_PROTOCOL_IWARP, "IWARP", ECORE_PCI_ETH_IWARP}
224 };
225 
226 #endif /* __ECORE_DCBX_API_H__ */
227