• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* bnx2x_dcb.c: Broadcom Everest network driver.
2  *
3  * Copyright 2009-2012 Broadcom Corporation
4  *
5  * Unless you and Broadcom execute a separate written software license
6  * agreement governing use of this software, this software is licensed to you
7  * under the terms of the GNU General Public License version 2, available
8  * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
9  *
10  * Notwithstanding the above, under no circumstances may you combine this
11  * software in any way with any other Broadcom software provided under a
12  * license other than the GPL, without Broadcom's express prior written
13  * consent.
14  *
15  * Maintained by: Eilon Greenstein <eilong@broadcom.com>
16  * Written by: Dmitry Kravkov
17  *
18  */
19 
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 
22 #include <linux/netdevice.h>
23 #include <linux/types.h>
24 #include <linux/errno.h>
25 #include <linux/rtnetlink.h>
26 #include <net/dcbnl.h>
27 
28 #include "bnx2x.h"
29 #include "bnx2x_cmn.h"
30 #include "bnx2x_dcb.h"
31 
32 /* forward declarations of dcbx related functions */
33 static int bnx2x_dcbx_stop_hw_tx(struct bnx2x *bp);
34 static void bnx2x_pfc_set_pfc(struct bnx2x *bp);
35 static void bnx2x_dcbx_update_ets_params(struct bnx2x *bp);
36 static int bnx2x_dcbx_resume_hw_tx(struct bnx2x *bp);
37 static void bnx2x_dcbx_get_ets_pri_pg_tbl(struct bnx2x *bp,
38 					  u32 *set_configuration_ets_pg,
39 					  u32 *pri_pg_tbl);
40 static void bnx2x_dcbx_get_num_pg_traf_type(struct bnx2x *bp,
41 					    u32 *pg_pri_orginal_spread,
42 					    struct pg_help_data *help_data);
43 static void bnx2x_dcbx_fill_cos_params(struct bnx2x *bp,
44 				       struct pg_help_data *help_data,
45 				       struct dcbx_ets_feature *ets,
46 				       u32 *pg_pri_orginal_spread);
47 static void bnx2x_dcbx_separate_pauseable_from_non(struct bnx2x *bp,
48 				struct cos_help_data *cos_data,
49 				u32 *pg_pri_orginal_spread,
50 				struct dcbx_ets_feature *ets);
51 static void bnx2x_dcbx_fw_struct(struct bnx2x *bp,
52 				 struct bnx2x_func_tx_start_params*);
53 
54 /* helpers: read/write len bytes from addr into buff by REG_RD/REG_WR */
bnx2x_read_data(struct bnx2x * bp,u32 * buff,u32 addr,u32 len)55 static void bnx2x_read_data(struct bnx2x *bp, u32 *buff,
56 				   u32 addr, u32 len)
57 {
58 	int i;
59 	for (i = 0; i < len; i += 4, buff++)
60 		*buff = REG_RD(bp, addr + i);
61 }
62 
bnx2x_write_data(struct bnx2x * bp,u32 * buff,u32 addr,u32 len)63 static void bnx2x_write_data(struct bnx2x *bp, u32 *buff,
64 				    u32 addr, u32 len)
65 {
66 	int i;
67 	for (i = 0; i < len; i += 4, buff++)
68 		REG_WR(bp, addr + i, *buff);
69 }
70 
bnx2x_pfc_set(struct bnx2x * bp)71 static void bnx2x_pfc_set(struct bnx2x *bp)
72 {
73 	struct bnx2x_nig_brb_pfc_port_params pfc_params = {0};
74 	u32 pri_bit, val = 0;
75 	int i;
76 
77 	pfc_params.num_of_rx_cos_priority_mask =
78 					bp->dcbx_port_params.ets.num_of_cos;
79 
80 	/* Tx COS configuration */
81 	for (i = 0; i < bp->dcbx_port_params.ets.num_of_cos; i++)
82 		/*
83 		 * We configure only the pauseable bits (non pauseable aren't
84 		 * configured at all) it's done to avoid false pauses from
85 		 * network
86 		 */
87 		pfc_params.rx_cos_priority_mask[i] =
88 			bp->dcbx_port_params.ets.cos_params[i].pri_bitmask
89 				& DCBX_PFC_PRI_PAUSE_MASK(bp);
90 
91 	/*
92 	 * Rx COS configuration
93 	 * Changing PFC RX configuration .
94 	 * In RX COS0 will always be configured to lossy and COS1 to lossless
95 	 */
96 	for (i = 0 ; i < MAX_PFC_PRIORITIES ; i++) {
97 		pri_bit = 1 << i;
98 
99 		if (pri_bit & DCBX_PFC_PRI_PAUSE_MASK(bp))
100 			val |= 1 << (i * 4);
101 	}
102 
103 	pfc_params.pkt_priority_to_cos = val;
104 
105 	/* RX COS0 */
106 	pfc_params.llfc_low_priority_classes = 0;
107 	/* RX COS1 */
108 	pfc_params.llfc_high_priority_classes = DCBX_PFC_PRI_PAUSE_MASK(bp);
109 
110 	/* BRB configuration */
111 	pfc_params.cos0_pauseable = false;
112 	pfc_params.cos1_pauseable = true;
113 
114 	bnx2x_acquire_phy_lock(bp);
115 	bp->link_params.feature_config_flags |= FEATURE_CONFIG_PFC_ENABLED;
116 	bnx2x_update_pfc(&bp->link_params, &bp->link_vars, &pfc_params);
117 	bnx2x_release_phy_lock(bp);
118 }
119 
bnx2x_pfc_clear(struct bnx2x * bp)120 static void bnx2x_pfc_clear(struct bnx2x *bp)
121 {
122 	struct bnx2x_nig_brb_pfc_port_params nig_params = {0};
123 	nig_params.pause_enable = 1;
124 	bnx2x_acquire_phy_lock(bp);
125 	bp->link_params.feature_config_flags &= ~FEATURE_CONFIG_PFC_ENABLED;
126 	bnx2x_update_pfc(&bp->link_params, &bp->link_vars, &nig_params);
127 	bnx2x_release_phy_lock(bp);
128 }
129 
bnx2x_dump_dcbx_drv_param(struct bnx2x * bp,struct dcbx_features * features,u32 error)130 static void  bnx2x_dump_dcbx_drv_param(struct bnx2x *bp,
131 				       struct dcbx_features *features,
132 				       u32 error)
133 {
134 	u8 i = 0;
135 	DP(NETIF_MSG_LINK, "local_mib.error %x\n", error);
136 
137 	/* PG */
138 	DP(NETIF_MSG_LINK,
139 	   "local_mib.features.ets.enabled %x\n", features->ets.enabled);
140 	for (i = 0; i < DCBX_MAX_NUM_PG_BW_ENTRIES; i++)
141 		DP(NETIF_MSG_LINK,
142 		   "local_mib.features.ets.pg_bw_tbl[%d] %d\n", i,
143 		   DCBX_PG_BW_GET(features->ets.pg_bw_tbl, i));
144 	for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++)
145 		DP(NETIF_MSG_LINK,
146 		   "local_mib.features.ets.pri_pg_tbl[%d] %d\n", i,
147 		   DCBX_PRI_PG_GET(features->ets.pri_pg_tbl, i));
148 
149 	/* pfc */
150 	DP(BNX2X_MSG_DCB, "dcbx_features.pfc.pri_en_bitmap %x\n",
151 					features->pfc.pri_en_bitmap);
152 	DP(BNX2X_MSG_DCB, "dcbx_features.pfc.pfc_caps %x\n",
153 					features->pfc.pfc_caps);
154 	DP(BNX2X_MSG_DCB, "dcbx_features.pfc.enabled %x\n",
155 					features->pfc.enabled);
156 
157 	DP(BNX2X_MSG_DCB, "dcbx_features.app.default_pri %x\n",
158 					features->app.default_pri);
159 	DP(BNX2X_MSG_DCB, "dcbx_features.app.tc_supported %x\n",
160 					features->app.tc_supported);
161 	DP(BNX2X_MSG_DCB, "dcbx_features.app.enabled %x\n",
162 					features->app.enabled);
163 	for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
164 		DP(BNX2X_MSG_DCB,
165 		   "dcbx_features.app.app_pri_tbl[%x].app_id %x\n",
166 		   i, features->app.app_pri_tbl[i].app_id);
167 		DP(BNX2X_MSG_DCB,
168 		   "dcbx_features.app.app_pri_tbl[%x].pri_bitmap %x\n",
169 		   i, features->app.app_pri_tbl[i].pri_bitmap);
170 		DP(BNX2X_MSG_DCB,
171 		   "dcbx_features.app.app_pri_tbl[%x].appBitfield %x\n",
172 		   i, features->app.app_pri_tbl[i].appBitfield);
173 	}
174 }
175 
bnx2x_dcbx_get_ap_priority(struct bnx2x * bp,u8 pri_bitmap,u8 llfc_traf_type)176 static void bnx2x_dcbx_get_ap_priority(struct bnx2x *bp,
177 				       u8 pri_bitmap,
178 				       u8 llfc_traf_type)
179 {
180 	u32 pri = MAX_PFC_PRIORITIES;
181 	u32 index = MAX_PFC_PRIORITIES - 1;
182 	u32 pri_mask;
183 	u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
184 
185 	/* Choose the highest priority */
186 	while ((MAX_PFC_PRIORITIES == pri) && (0 != index)) {
187 		pri_mask = 1 << index;
188 		if (GET_FLAGS(pri_bitmap, pri_mask))
189 			pri = index ;
190 		index--;
191 	}
192 
193 	if (pri < MAX_PFC_PRIORITIES)
194 		ttp[llfc_traf_type] = max_t(u32, ttp[llfc_traf_type], pri);
195 }
196 
bnx2x_dcbx_get_ap_feature(struct bnx2x * bp,struct dcbx_app_priority_feature * app,u32 error)197 static void bnx2x_dcbx_get_ap_feature(struct bnx2x *bp,
198 				   struct dcbx_app_priority_feature *app,
199 				   u32 error) {
200 	u8 index;
201 	u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
202 
203 	if (GET_FLAGS(error, DCBX_LOCAL_APP_ERROR))
204 		DP(BNX2X_MSG_DCB, "DCBX_LOCAL_APP_ERROR\n");
205 
206 	if (GET_FLAGS(error, DCBX_LOCAL_APP_MISMATCH))
207 		DP(BNX2X_MSG_DCB, "DCBX_LOCAL_APP_MISMATCH\n");
208 
209 	if (GET_FLAGS(error, DCBX_REMOTE_APP_TLV_NOT_FOUND))
210 		DP(BNX2X_MSG_DCB, "DCBX_REMOTE_APP_TLV_NOT_FOUND\n");
211 	if (app->enabled &&
212 	    !GET_FLAGS(error, DCBX_LOCAL_APP_ERROR | DCBX_LOCAL_APP_MISMATCH |
213 			      DCBX_REMOTE_APP_TLV_NOT_FOUND)) {
214 
215 		bp->dcbx_port_params.app.enabled = true;
216 
217 		for (index = 0 ; index < LLFC_DRIVER_TRAFFIC_TYPE_MAX; index++)
218 			ttp[index] = 0;
219 
220 		if (app->default_pri < MAX_PFC_PRIORITIES)
221 			ttp[LLFC_TRAFFIC_TYPE_NW] = app->default_pri;
222 
223 		for (index = 0 ; index < DCBX_MAX_APP_PROTOCOL; index++) {
224 			struct dcbx_app_priority_entry *entry =
225 							app->app_pri_tbl;
226 
227 			if (GET_FLAGS(entry[index].appBitfield,
228 				     DCBX_APP_SF_ETH_TYPE) &&
229 			   ETH_TYPE_FCOE == entry[index].app_id)
230 				bnx2x_dcbx_get_ap_priority(bp,
231 						entry[index].pri_bitmap,
232 						LLFC_TRAFFIC_TYPE_FCOE);
233 
234 			if (GET_FLAGS(entry[index].appBitfield,
235 				     DCBX_APP_SF_PORT) &&
236 			   TCP_PORT_ISCSI == entry[index].app_id)
237 				bnx2x_dcbx_get_ap_priority(bp,
238 						entry[index].pri_bitmap,
239 						LLFC_TRAFFIC_TYPE_ISCSI);
240 		}
241 	} else {
242 		DP(BNX2X_MSG_DCB, "DCBX_LOCAL_APP_DISABLED\n");
243 		bp->dcbx_port_params.app.enabled = false;
244 		for (index = 0 ; index < LLFC_DRIVER_TRAFFIC_TYPE_MAX; index++)
245 			ttp[index] = INVALID_TRAFFIC_TYPE_PRIORITY;
246 	}
247 }
248 
bnx2x_dcbx_get_ets_feature(struct bnx2x * bp,struct dcbx_ets_feature * ets,u32 error)249 static void bnx2x_dcbx_get_ets_feature(struct bnx2x *bp,
250 				       struct dcbx_ets_feature *ets,
251 				       u32 error) {
252 	int i = 0;
253 	u32 pg_pri_orginal_spread[DCBX_MAX_NUM_PG_BW_ENTRIES] = {0};
254 	struct pg_help_data pg_help_data;
255 	struct bnx2x_dcbx_cos_params *cos_params =
256 			bp->dcbx_port_params.ets.cos_params;
257 
258 	memset(&pg_help_data, 0, sizeof(struct pg_help_data));
259 
260 
261 	if (GET_FLAGS(error, DCBX_LOCAL_ETS_ERROR))
262 		DP(BNX2X_MSG_DCB, "DCBX_LOCAL_ETS_ERROR\n");
263 
264 	if (GET_FLAGS(error, DCBX_REMOTE_ETS_TLV_NOT_FOUND))
265 		DP(BNX2X_MSG_DCB, "DCBX_REMOTE_ETS_TLV_NOT_FOUND\n");
266 
267 	/* Clean up old settings of ets on COS */
268 	for (i = 0; i < ARRAY_SIZE(bp->dcbx_port_params.ets.cos_params) ; i++) {
269 		cos_params[i].pauseable = false;
270 		cos_params[i].strict = BNX2X_DCBX_STRICT_INVALID;
271 		cos_params[i].bw_tbl = DCBX_INVALID_COS_BW;
272 		cos_params[i].pri_bitmask = 0;
273 	}
274 
275 	if (bp->dcbx_port_params.app.enabled && ets->enabled &&
276 	   !GET_FLAGS(error,
277 		      DCBX_LOCAL_ETS_ERROR | DCBX_REMOTE_ETS_TLV_NOT_FOUND)) {
278 		DP(BNX2X_MSG_DCB, "DCBX_LOCAL_ETS_ENABLE\n");
279 		bp->dcbx_port_params.ets.enabled = true;
280 
281 		bnx2x_dcbx_get_ets_pri_pg_tbl(bp,
282 					      pg_pri_orginal_spread,
283 					      ets->pri_pg_tbl);
284 
285 		bnx2x_dcbx_get_num_pg_traf_type(bp,
286 						pg_pri_orginal_spread,
287 						&pg_help_data);
288 
289 		bnx2x_dcbx_fill_cos_params(bp, &pg_help_data,
290 					   ets, pg_pri_orginal_spread);
291 
292 	} else {
293 		DP(BNX2X_MSG_DCB, "DCBX_LOCAL_ETS_DISABLED\n");
294 		bp->dcbx_port_params.ets.enabled = false;
295 		ets->pri_pg_tbl[0] = 0;
296 
297 		for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES ; i++)
298 			DCBX_PG_BW_SET(ets->pg_bw_tbl, i, 1);
299 	}
300 }
301 
bnx2x_dcbx_get_pfc_feature(struct bnx2x * bp,struct dcbx_pfc_feature * pfc,u32 error)302 static void  bnx2x_dcbx_get_pfc_feature(struct bnx2x *bp,
303 					struct dcbx_pfc_feature *pfc, u32 error)
304 {
305 
306 	if (GET_FLAGS(error, DCBX_LOCAL_PFC_ERROR))
307 		DP(BNX2X_MSG_DCB, "DCBX_LOCAL_PFC_ERROR\n");
308 
309 	if (GET_FLAGS(error, DCBX_REMOTE_PFC_TLV_NOT_FOUND))
310 		DP(BNX2X_MSG_DCB, "DCBX_REMOTE_PFC_TLV_NOT_FOUND\n");
311 	if (bp->dcbx_port_params.app.enabled && pfc->enabled &&
312 	   !GET_FLAGS(error, DCBX_LOCAL_PFC_ERROR | DCBX_LOCAL_PFC_MISMATCH |
313 			     DCBX_REMOTE_PFC_TLV_NOT_FOUND)) {
314 		bp->dcbx_port_params.pfc.enabled = true;
315 		bp->dcbx_port_params.pfc.priority_non_pauseable_mask =
316 			~(pfc->pri_en_bitmap);
317 	} else {
318 		DP(BNX2X_MSG_DCB, "DCBX_LOCAL_PFC_DISABLED\n");
319 		bp->dcbx_port_params.pfc.enabled = false;
320 		bp->dcbx_port_params.pfc.priority_non_pauseable_mask = 0;
321 	}
322 }
323 
324 /* maps unmapped priorities to to the same COS as L2 */
bnx2x_dcbx_map_nw(struct bnx2x * bp)325 static void bnx2x_dcbx_map_nw(struct bnx2x *bp)
326 {
327 	int i;
328 	u32 unmapped = (1 << MAX_PFC_PRIORITIES) - 1; /* all ones */
329 	u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
330 	u32 nw_prio = 1 << ttp[LLFC_TRAFFIC_TYPE_NW];
331 	struct bnx2x_dcbx_cos_params *cos_params =
332 			bp->dcbx_port_params.ets.cos_params;
333 
334 	/* get unmapped priorities by clearing mapped bits */
335 	for (i = 0; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++)
336 		unmapped &= ~(1 << ttp[i]);
337 
338 	/* find cos for nw prio and extend it with unmapped */
339 	for (i = 0; i < ARRAY_SIZE(bp->dcbx_port_params.ets.cos_params); i++) {
340 		if (cos_params[i].pri_bitmask & nw_prio) {
341 			/* extend the bitmask with unmapped */
342 			DP(BNX2X_MSG_DCB,
343 			   "cos %d extended with 0x%08x\n", i, unmapped);
344 			cos_params[i].pri_bitmask |= unmapped;
345 			break;
346 		}
347 	}
348 }
349 
bnx2x_get_dcbx_drv_param(struct bnx2x * bp,struct dcbx_features * features,u32 error)350 static void bnx2x_get_dcbx_drv_param(struct bnx2x *bp,
351 				     struct dcbx_features *features,
352 				     u32 error)
353 {
354 	bnx2x_dcbx_get_ap_feature(bp, &features->app, error);
355 
356 	bnx2x_dcbx_get_pfc_feature(bp, &features->pfc, error);
357 
358 	bnx2x_dcbx_get_ets_feature(bp, &features->ets, error);
359 
360 	bnx2x_dcbx_map_nw(bp);
361 }
362 
363 #define DCBX_LOCAL_MIB_MAX_TRY_READ		(100)
bnx2x_dcbx_read_mib(struct bnx2x * bp,u32 * base_mib_addr,u32 offset,int read_mib_type)364 static int bnx2x_dcbx_read_mib(struct bnx2x *bp,
365 			       u32 *base_mib_addr,
366 			       u32 offset,
367 			       int read_mib_type)
368 {
369 	int max_try_read = 0;
370 	u32 mib_size, prefix_seq_num, suffix_seq_num;
371 	struct lldp_remote_mib *remote_mib ;
372 	struct lldp_local_mib  *local_mib;
373 
374 
375 	switch (read_mib_type) {
376 	case DCBX_READ_LOCAL_MIB:
377 		mib_size = sizeof(struct lldp_local_mib);
378 		break;
379 	case DCBX_READ_REMOTE_MIB:
380 		mib_size = sizeof(struct lldp_remote_mib);
381 		break;
382 	default:
383 		return 1; /*error*/
384 	}
385 
386 	offset += BP_PORT(bp) * mib_size;
387 
388 	do {
389 		bnx2x_read_data(bp, base_mib_addr, offset, mib_size);
390 
391 		max_try_read++;
392 
393 		switch (read_mib_type) {
394 		case DCBX_READ_LOCAL_MIB:
395 			local_mib = (struct lldp_local_mib *) base_mib_addr;
396 			prefix_seq_num = local_mib->prefix_seq_num;
397 			suffix_seq_num = local_mib->suffix_seq_num;
398 			break;
399 		case DCBX_READ_REMOTE_MIB:
400 			remote_mib = (struct lldp_remote_mib *) base_mib_addr;
401 			prefix_seq_num = remote_mib->prefix_seq_num;
402 			suffix_seq_num = remote_mib->suffix_seq_num;
403 			break;
404 		default:
405 			return 1; /*error*/
406 		}
407 	} while ((prefix_seq_num != suffix_seq_num) &&
408 	       (max_try_read < DCBX_LOCAL_MIB_MAX_TRY_READ));
409 
410 	if (max_try_read >= DCBX_LOCAL_MIB_MAX_TRY_READ) {
411 		BNX2X_ERR("MIB could not be read\n");
412 		return 1;
413 	}
414 
415 	return 0;
416 }
417 
bnx2x_pfc_set_pfc(struct bnx2x * bp)418 static void bnx2x_pfc_set_pfc(struct bnx2x *bp)
419 {
420 	if (bp->dcbx_port_params.pfc.enabled &&
421 	    !(bp->dcbx_error & DCBX_REMOTE_MIB_ERROR))
422 		/*
423 		 * 1. Fills up common PFC structures if required
424 		 * 2. Configure NIG, MAC and BRB via the elink
425 		 */
426 		bnx2x_pfc_set(bp);
427 	else
428 		bnx2x_pfc_clear(bp);
429 }
430 
bnx2x_dcbx_stop_hw_tx(struct bnx2x * bp)431 static int bnx2x_dcbx_stop_hw_tx(struct bnx2x *bp)
432 {
433 	struct bnx2x_func_state_params func_params = {NULL};
434 
435 	func_params.f_obj = &bp->func_obj;
436 	func_params.cmd = BNX2X_F_CMD_TX_STOP;
437 
438 	DP(BNX2X_MSG_DCB, "STOP TRAFFIC\n");
439 	return bnx2x_func_state_change(bp, &func_params);
440 }
441 
bnx2x_dcbx_resume_hw_tx(struct bnx2x * bp)442 static int bnx2x_dcbx_resume_hw_tx(struct bnx2x *bp)
443 {
444 	struct bnx2x_func_state_params func_params = {NULL};
445 	struct bnx2x_func_tx_start_params *tx_params =
446 		&func_params.params.tx_start;
447 
448 	func_params.f_obj = &bp->func_obj;
449 	func_params.cmd = BNX2X_F_CMD_TX_START;
450 
451 	bnx2x_dcbx_fw_struct(bp, tx_params);
452 
453 	DP(BNX2X_MSG_DCB, "START TRAFFIC\n");
454 	return bnx2x_func_state_change(bp, &func_params);
455 }
456 
bnx2x_dcbx_2cos_limit_update_ets_config(struct bnx2x * bp)457 static void bnx2x_dcbx_2cos_limit_update_ets_config(struct bnx2x *bp)
458 {
459 	struct bnx2x_dcbx_pg_params *ets = &(bp->dcbx_port_params.ets);
460 	int rc = 0;
461 
462 	if (ets->num_of_cos == 0 || ets->num_of_cos > DCBX_COS_MAX_NUM_E2) {
463 		BNX2X_ERR("Illegal number of COSes %d\n", ets->num_of_cos);
464 		return;
465 	}
466 
467 	/* valid COS entries */
468 	if (ets->num_of_cos == 1)   /* no ETS */
469 		return;
470 
471 	/* sanity */
472 	if (((BNX2X_DCBX_STRICT_INVALID == ets->cos_params[0].strict) &&
473 	     (DCBX_INVALID_COS_BW == ets->cos_params[0].bw_tbl)) ||
474 	    ((BNX2X_DCBX_STRICT_INVALID == ets->cos_params[1].strict) &&
475 	     (DCBX_INVALID_COS_BW == ets->cos_params[1].bw_tbl))) {
476 		BNX2X_ERR("all COS should have at least bw_limit or strict"
477 			    "ets->cos_params[0].strict= %x"
478 			    "ets->cos_params[0].bw_tbl= %x"
479 			    "ets->cos_params[1].strict= %x"
480 			    "ets->cos_params[1].bw_tbl= %x",
481 			  ets->cos_params[0].strict,
482 			  ets->cos_params[0].bw_tbl,
483 			  ets->cos_params[1].strict,
484 			  ets->cos_params[1].bw_tbl);
485 		return;
486 	}
487 	/* If we join a group and there is bw_tbl and strict then bw rules */
488 	if ((DCBX_INVALID_COS_BW != ets->cos_params[0].bw_tbl) &&
489 	    (DCBX_INVALID_COS_BW != ets->cos_params[1].bw_tbl)) {
490 		u32 bw_tbl_0 = ets->cos_params[0].bw_tbl;
491 		u32 bw_tbl_1 = ets->cos_params[1].bw_tbl;
492 		/* Do not allow 0-100 configuration
493 		 * since PBF does not support it
494 		 * force 1-99 instead
495 		 */
496 		if (bw_tbl_0 == 0) {
497 			bw_tbl_0 = 1;
498 			bw_tbl_1 = 99;
499 		} else if (bw_tbl_1 == 0) {
500 			bw_tbl_1 = 1;
501 			bw_tbl_0 = 99;
502 		}
503 
504 		bnx2x_ets_bw_limit(&bp->link_params, bw_tbl_0, bw_tbl_1);
505 	} else {
506 		if (ets->cos_params[0].strict == BNX2X_DCBX_STRICT_COS_HIGHEST)
507 			rc = bnx2x_ets_strict(&bp->link_params, 0);
508 		else if (ets->cos_params[1].strict
509 					== BNX2X_DCBX_STRICT_COS_HIGHEST)
510 			rc = bnx2x_ets_strict(&bp->link_params, 1);
511 		if (rc)
512 			BNX2X_ERR("update_ets_params failed\n");
513 	}
514 }
515 
516 /*
517  * In E3B0 the configuration may have more than 2 COS.
518  */
bnx2x_dcbx_update_ets_config(struct bnx2x * bp)519 static void bnx2x_dcbx_update_ets_config(struct bnx2x *bp)
520 {
521 	struct bnx2x_dcbx_pg_params *ets = &(bp->dcbx_port_params.ets);
522 	struct bnx2x_ets_params ets_params = { 0 };
523 	u8 i;
524 
525 	ets_params.num_of_cos = ets->num_of_cos;
526 
527 	for (i = 0; i < ets->num_of_cos; i++) {
528 		/* COS is SP */
529 		if (ets->cos_params[i].strict != BNX2X_DCBX_STRICT_INVALID) {
530 			if (ets->cos_params[i].bw_tbl != DCBX_INVALID_COS_BW) {
531 				BNX2X_ERR("COS can't be not BW and not SP\n");
532 				return;
533 			}
534 
535 			ets_params.cos[i].state = bnx2x_cos_state_strict;
536 			ets_params.cos[i].params.sp_params.pri =
537 						ets->cos_params[i].strict;
538 		} else { /* COS is BW */
539 			if (ets->cos_params[i].bw_tbl == DCBX_INVALID_COS_BW) {
540 				BNX2X_ERR("COS can't be not BW and not SP\n");
541 				return;
542 			}
543 			ets_params.cos[i].state = bnx2x_cos_state_bw;
544 			ets_params.cos[i].params.bw_params.bw =
545 						(u8)ets->cos_params[i].bw_tbl;
546 		}
547 	}
548 
549 	/* Configure the ETS in HW */
550 	if (bnx2x_ets_e3b0_config(&bp->link_params, &bp->link_vars,
551 				  &ets_params)) {
552 		BNX2X_ERR("bnx2x_ets_e3b0_config failed\n");
553 		bnx2x_ets_disabled(&bp->link_params, &bp->link_vars);
554 	}
555 }
556 
bnx2x_dcbx_update_ets_params(struct bnx2x * bp)557 static void bnx2x_dcbx_update_ets_params(struct bnx2x *bp)
558 {
559 	bnx2x_ets_disabled(&bp->link_params, &bp->link_vars);
560 
561 	if (!bp->dcbx_port_params.ets.enabled ||
562 	    (bp->dcbx_error & DCBX_REMOTE_MIB_ERROR))
563 		return;
564 
565 	if (CHIP_IS_E3B0(bp))
566 		bnx2x_dcbx_update_ets_config(bp);
567 	else
568 		bnx2x_dcbx_2cos_limit_update_ets_config(bp);
569 }
570 
571 #ifdef BCM_DCBNL
bnx2x_dcbx_read_shmem_remote_mib(struct bnx2x * bp)572 static int bnx2x_dcbx_read_shmem_remote_mib(struct bnx2x *bp)
573 {
574 	struct lldp_remote_mib remote_mib = {0};
575 	u32 dcbx_remote_mib_offset = SHMEM2_RD(bp, dcbx_remote_mib_offset);
576 	int rc;
577 
578 	DP(BNX2X_MSG_DCB, "dcbx_remote_mib_offset 0x%x\n",
579 	   dcbx_remote_mib_offset);
580 
581 	if (SHMEM_DCBX_REMOTE_MIB_NONE == dcbx_remote_mib_offset) {
582 		BNX2X_ERR("FW doesn't support dcbx_remote_mib_offset\n");
583 		return -EINVAL;
584 	}
585 
586 	rc = bnx2x_dcbx_read_mib(bp, (u32 *)&remote_mib, dcbx_remote_mib_offset,
587 				 DCBX_READ_REMOTE_MIB);
588 
589 	if (rc) {
590 		BNX2X_ERR("Faild to read remote mib from FW\n");
591 		return rc;
592 	}
593 
594 	/* save features and flags */
595 	bp->dcbx_remote_feat = remote_mib.features;
596 	bp->dcbx_remote_flags = remote_mib.flags;
597 	return 0;
598 }
599 #endif
600 
bnx2x_dcbx_read_shmem_neg_results(struct bnx2x * bp)601 static int bnx2x_dcbx_read_shmem_neg_results(struct bnx2x *bp)
602 {
603 	struct lldp_local_mib local_mib = {0};
604 	u32 dcbx_neg_res_offset = SHMEM2_RD(bp, dcbx_neg_res_offset);
605 	int rc;
606 
607 	DP(BNX2X_MSG_DCB, "dcbx_neg_res_offset 0x%x\n", dcbx_neg_res_offset);
608 
609 	if (SHMEM_DCBX_NEG_RES_NONE == dcbx_neg_res_offset) {
610 		BNX2X_ERR("FW doesn't support dcbx_neg_res_offset\n");
611 		return -EINVAL;
612 	}
613 
614 	rc = bnx2x_dcbx_read_mib(bp, (u32 *)&local_mib, dcbx_neg_res_offset,
615 				 DCBX_READ_LOCAL_MIB);
616 
617 	if (rc) {
618 		BNX2X_ERR("Faild to read local mib from FW\n");
619 		return rc;
620 	}
621 
622 	/* save features and error */
623 	bp->dcbx_local_feat = local_mib.features;
624 	bp->dcbx_error = local_mib.error;
625 	return 0;
626 }
627 
628 
629 #ifdef BCM_DCBNL
630 static inline
bnx2x_dcbx_dcbnl_app_up(struct dcbx_app_priority_entry * ent)631 u8 bnx2x_dcbx_dcbnl_app_up(struct dcbx_app_priority_entry *ent)
632 {
633 	u8 pri;
634 
635 	/* Choose the highest priority */
636 	for (pri = MAX_PFC_PRIORITIES - 1; pri > 0; pri--)
637 		if (ent->pri_bitmap & (1 << pri))
638 			break;
639 	return pri;
640 }
641 
642 static inline
bnx2x_dcbx_dcbnl_app_idtype(struct dcbx_app_priority_entry * ent)643 u8 bnx2x_dcbx_dcbnl_app_idtype(struct dcbx_app_priority_entry *ent)
644 {
645 	return ((ent->appBitfield & DCBX_APP_ENTRY_SF_MASK) ==
646 		DCBX_APP_SF_PORT) ? DCB_APP_IDTYPE_PORTNUM :
647 		DCB_APP_IDTYPE_ETHTYPE;
648 }
649 
bnx2x_dcbnl_update_applist(struct bnx2x * bp,bool delall)650 int bnx2x_dcbnl_update_applist(struct bnx2x *bp, bool delall)
651 {
652 	int i, err = 0;
653 
654 	for (i = 0; i < DCBX_MAX_APP_PROTOCOL && err == 0; i++) {
655 		struct dcbx_app_priority_entry *ent =
656 			&bp->dcbx_local_feat.app.app_pri_tbl[i];
657 
658 		if (ent->appBitfield & DCBX_APP_ENTRY_VALID) {
659 			u8 up = bnx2x_dcbx_dcbnl_app_up(ent);
660 
661 			/* avoid invalid user-priority */
662 			if (up) {
663 				struct dcb_app app;
664 				app.selector = bnx2x_dcbx_dcbnl_app_idtype(ent);
665 				app.protocol = ent->app_id;
666 				app.priority = delall ? 0 : up;
667 				err = dcb_setapp(bp->dev, &app);
668 			}
669 		}
670 	}
671 	return err;
672 }
673 #endif
674 
bnx2x_dcbx_update_tc_mapping(struct bnx2x * bp)675 static inline void bnx2x_dcbx_update_tc_mapping(struct bnx2x *bp)
676 {
677 	u8 prio, cos;
678 	for (cos = 0; cos < bp->dcbx_port_params.ets.num_of_cos; cos++) {
679 		for (prio = 0; prio < BNX2X_MAX_PRIORITY; prio++) {
680 			if (bp->dcbx_port_params.ets.cos_params[cos].pri_bitmask
681 			    & (1 << prio)) {
682 				bp->prio_to_cos[prio] = cos;
683 				DP(BNX2X_MSG_DCB,
684 				   "tx_mapping %d --> %d\n", prio, cos);
685 			}
686 		}
687 	}
688 
689 	/* setup tc must be called under rtnl lock, but we can't take it here
690 	 * as we are handling an attetntion on a work queue which must be
691 	 * flushed at some rtnl-locked contexts (e.g. if down)
692 	 */
693 	if (!test_and_set_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
694 		schedule_delayed_work(&bp->sp_rtnl_task, 0);
695 }
696 
bnx2x_dcbx_set_params(struct bnx2x * bp,u32 state)697 void bnx2x_dcbx_set_params(struct bnx2x *bp, u32 state)
698 {
699 	switch (state) {
700 	case BNX2X_DCBX_STATE_NEG_RECEIVED:
701 		{
702 			DP(BNX2X_MSG_DCB, "BNX2X_DCBX_STATE_NEG_RECEIVED\n");
703 #ifdef BCM_DCBNL
704 			/**
705 			 * Delete app tlvs from dcbnl before reading new
706 			 * negotiation results
707 			 */
708 			bnx2x_dcbnl_update_applist(bp, true);
709 
710 			/* Read rmeote mib if dcbx is in the FW */
711 			if (bnx2x_dcbx_read_shmem_remote_mib(bp))
712 				return;
713 #endif
714 			/* Read neg results if dcbx is in the FW */
715 			if (bnx2x_dcbx_read_shmem_neg_results(bp))
716 				return;
717 
718 			bnx2x_dump_dcbx_drv_param(bp, &bp->dcbx_local_feat,
719 						  bp->dcbx_error);
720 
721 			bnx2x_get_dcbx_drv_param(bp, &bp->dcbx_local_feat,
722 						 bp->dcbx_error);
723 
724 			/* mark DCBX result for PMF migration */
725 			bnx2x_update_drv_flags(bp,
726 					       1 << DRV_FLAGS_DCB_CONFIGURED,
727 					       1);
728 #ifdef BCM_DCBNL
729 			/*
730 			 * Add new app tlvs to dcbnl
731 			 */
732 			bnx2x_dcbnl_update_applist(bp, false);
733 #endif
734 			/*
735 			 * reconfigure the netdevice with the results of the new
736 			 * dcbx negotiation.
737 			 */
738 			bnx2x_dcbx_update_tc_mapping(bp);
739 
740 			/*
741 			 * allow other funtions to update their netdevices
742 			 * accordingly
743 			 */
744 			if (IS_MF(bp))
745 				bnx2x_link_sync_notify(bp);
746 
747 			bnx2x_dcbx_stop_hw_tx(bp);
748 
749 			return;
750 		}
751 	case BNX2X_DCBX_STATE_TX_PAUSED:
752 		DP(BNX2X_MSG_DCB, "BNX2X_DCBX_STATE_TX_PAUSED\n");
753 		bnx2x_pfc_set_pfc(bp);
754 
755 		bnx2x_dcbx_update_ets_params(bp);
756 		bnx2x_dcbx_resume_hw_tx(bp);
757 
758 		return;
759 	case BNX2X_DCBX_STATE_TX_RELEASED:
760 		DP(BNX2X_MSG_DCB, "BNX2X_DCBX_STATE_TX_RELEASED\n");
761 		bnx2x_fw_command(bp, DRV_MSG_CODE_DCBX_PMF_DRV_OK, 0);
762 #ifdef BCM_DCBNL
763 		/*
764 		 * Send a notification for the new negotiated parameters
765 		 */
766 		dcbnl_cee_notify(bp->dev, RTM_GETDCB, DCB_CMD_CEE_GET, 0, 0);
767 #endif
768 		return;
769 	default:
770 		BNX2X_ERR("Unknown DCBX_STATE\n");
771 	}
772 }
773 
774 #define LLDP_ADMIN_MIB_OFFSET(bp)	(PORT_MAX*sizeof(struct lldp_params) + \
775 				      BP_PORT(bp)*sizeof(struct lldp_admin_mib))
776 
bnx2x_dcbx_admin_mib_updated_params(struct bnx2x * bp,u32 dcbx_lldp_params_offset)777 static void bnx2x_dcbx_admin_mib_updated_params(struct bnx2x *bp,
778 				u32 dcbx_lldp_params_offset)
779 {
780 	struct lldp_admin_mib admin_mib;
781 	u32 i, other_traf_type = PREDEFINED_APP_IDX_MAX, traf_type = 0;
782 	u32 offset = dcbx_lldp_params_offset + LLDP_ADMIN_MIB_OFFSET(bp);
783 
784 	/*shortcuts*/
785 	struct dcbx_features *af = &admin_mib.features;
786 	struct bnx2x_config_dcbx_params *dp = &bp->dcbx_config_params;
787 
788 	memset(&admin_mib, 0, sizeof(struct lldp_admin_mib));
789 
790 	/* Read the data first */
791 	bnx2x_read_data(bp, (u32 *)&admin_mib, offset,
792 			sizeof(struct lldp_admin_mib));
793 
794 	if (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_ON)
795 		SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_DCBX_ENABLED);
796 	else
797 		RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_DCBX_ENABLED);
798 
799 	if (dp->overwrite_settings == BNX2X_DCBX_OVERWRITE_SETTINGS_ENABLE) {
800 
801 		RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_CEE_VERSION_MASK);
802 		admin_mib.ver_cfg_flags |=
803 			(dp->admin_dcbx_version << DCBX_CEE_VERSION_SHIFT) &
804 			 DCBX_CEE_VERSION_MASK;
805 
806 		af->ets.enabled = (u8)dp->admin_ets_enable;
807 
808 		af->pfc.enabled = (u8)dp->admin_pfc_enable;
809 
810 		/* FOR IEEE dp->admin_tc_supported_tx_enable */
811 		if (dp->admin_ets_configuration_tx_enable)
812 			SET_FLAGS(admin_mib.ver_cfg_flags,
813 				  DCBX_ETS_CONFIG_TX_ENABLED);
814 		else
815 			RESET_FLAGS(admin_mib.ver_cfg_flags,
816 				    DCBX_ETS_CONFIG_TX_ENABLED);
817 		/* For IEEE admin_ets_recommendation_tx_enable */
818 		if (dp->admin_pfc_tx_enable)
819 			SET_FLAGS(admin_mib.ver_cfg_flags,
820 				  DCBX_PFC_CONFIG_TX_ENABLED);
821 		else
822 			RESET_FLAGS(admin_mib.ver_cfg_flags,
823 				  DCBX_PFC_CONFIG_TX_ENABLED);
824 
825 		if (dp->admin_application_priority_tx_enable)
826 			SET_FLAGS(admin_mib.ver_cfg_flags,
827 				  DCBX_APP_CONFIG_TX_ENABLED);
828 		else
829 			RESET_FLAGS(admin_mib.ver_cfg_flags,
830 				  DCBX_APP_CONFIG_TX_ENABLED);
831 
832 		if (dp->admin_ets_willing)
833 			SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_ETS_WILLING);
834 		else
835 			RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_ETS_WILLING);
836 		/* For IEEE admin_ets_reco_valid */
837 		if (dp->admin_pfc_willing)
838 			SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_PFC_WILLING);
839 		else
840 			RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_PFC_WILLING);
841 
842 		if (dp->admin_app_priority_willing)
843 			SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_APP_WILLING);
844 		else
845 			RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_APP_WILLING);
846 
847 		for (i = 0 ; i < DCBX_MAX_NUM_PG_BW_ENTRIES; i++) {
848 			DCBX_PG_BW_SET(af->ets.pg_bw_tbl, i,
849 				(u8)dp->admin_configuration_bw_precentage[i]);
850 
851 			DP(BNX2X_MSG_DCB, "pg_bw_tbl[%d] = %02x\n",
852 			   i, DCBX_PG_BW_GET(af->ets.pg_bw_tbl, i));
853 		}
854 
855 		for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++) {
856 			DCBX_PRI_PG_SET(af->ets.pri_pg_tbl, i,
857 					(u8)dp->admin_configuration_ets_pg[i]);
858 
859 			DP(BNX2X_MSG_DCB, "pri_pg_tbl[%d] = %02x\n",
860 			   i, DCBX_PRI_PG_GET(af->ets.pri_pg_tbl, i));
861 		}
862 
863 		/*For IEEE admin_recommendation_bw_precentage
864 		 *For IEEE admin_recommendation_ets_pg */
865 		af->pfc.pri_en_bitmap = (u8)dp->admin_pfc_bitmap;
866 		for (i = 0; i < DCBX_CONFIG_MAX_APP_PROTOCOL; i++) {
867 			if (dp->admin_priority_app_table[i].valid) {
868 				struct bnx2x_admin_priority_app_table *table =
869 					dp->admin_priority_app_table;
870 				if ((ETH_TYPE_FCOE == table[i].app_id) &&
871 				   (TRAFFIC_TYPE_ETH == table[i].traffic_type))
872 					traf_type = FCOE_APP_IDX;
873 				else if ((TCP_PORT_ISCSI == table[i].app_id) &&
874 				   (TRAFFIC_TYPE_PORT == table[i].traffic_type))
875 					traf_type = ISCSI_APP_IDX;
876 				else
877 					traf_type = other_traf_type++;
878 
879 				af->app.app_pri_tbl[traf_type].app_id =
880 					table[i].app_id;
881 
882 				af->app.app_pri_tbl[traf_type].pri_bitmap =
883 					(u8)(1 << table[i].priority);
884 
885 				af->app.app_pri_tbl[traf_type].appBitfield =
886 				    (DCBX_APP_ENTRY_VALID);
887 
888 				af->app.app_pri_tbl[traf_type].appBitfield |=
889 				   (TRAFFIC_TYPE_ETH == table[i].traffic_type) ?
890 					DCBX_APP_SF_ETH_TYPE : DCBX_APP_SF_PORT;
891 			}
892 		}
893 
894 		af->app.default_pri = (u8)dp->admin_default_priority;
895 
896 	}
897 
898 	/* Write the data. */
899 	bnx2x_write_data(bp, (u32 *)&admin_mib, offset,
900 			 sizeof(struct lldp_admin_mib));
901 
902 }
903 
bnx2x_dcbx_set_state(struct bnx2x * bp,bool dcb_on,u32 dcbx_enabled)904 void bnx2x_dcbx_set_state(struct bnx2x *bp, bool dcb_on, u32 dcbx_enabled)
905 {
906 	if (!CHIP_IS_E1x(bp)) {
907 		bp->dcb_state = dcb_on;
908 		bp->dcbx_enabled = dcbx_enabled;
909 	} else {
910 		bp->dcb_state = false;
911 		bp->dcbx_enabled = BNX2X_DCBX_ENABLED_INVALID;
912 	}
913 	DP(BNX2X_MSG_DCB, "DCB state [%s:%s]\n",
914 	   dcb_on ? "ON" : "OFF",
915 	   dcbx_enabled == BNX2X_DCBX_ENABLED_OFF ? "user-mode" :
916 	   dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_OFF ? "on-chip static" :
917 	   dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_ON ?
918 	   "on-chip with negotiation" : "invalid");
919 }
920 
bnx2x_dcbx_init_params(struct bnx2x * bp)921 void bnx2x_dcbx_init_params(struct bnx2x *bp)
922 {
923 	bp->dcbx_config_params.admin_dcbx_version = 0x0; /* 0 - CEE; 1 - IEEE */
924 	bp->dcbx_config_params.admin_ets_willing = 1;
925 	bp->dcbx_config_params.admin_pfc_willing = 1;
926 	bp->dcbx_config_params.overwrite_settings = 1;
927 	bp->dcbx_config_params.admin_ets_enable = 1;
928 	bp->dcbx_config_params.admin_pfc_enable = 1;
929 	bp->dcbx_config_params.admin_tc_supported_tx_enable = 1;
930 	bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
931 	bp->dcbx_config_params.admin_pfc_tx_enable = 1;
932 	bp->dcbx_config_params.admin_application_priority_tx_enable = 1;
933 	bp->dcbx_config_params.admin_ets_reco_valid = 1;
934 	bp->dcbx_config_params.admin_app_priority_willing = 1;
935 	bp->dcbx_config_params.admin_configuration_bw_precentage[0] = 100;
936 	bp->dcbx_config_params.admin_configuration_bw_precentage[1] = 0;
937 	bp->dcbx_config_params.admin_configuration_bw_precentage[2] = 0;
938 	bp->dcbx_config_params.admin_configuration_bw_precentage[3] = 0;
939 	bp->dcbx_config_params.admin_configuration_bw_precentage[4] = 0;
940 	bp->dcbx_config_params.admin_configuration_bw_precentage[5] = 0;
941 	bp->dcbx_config_params.admin_configuration_bw_precentage[6] = 0;
942 	bp->dcbx_config_params.admin_configuration_bw_precentage[7] = 0;
943 	bp->dcbx_config_params.admin_configuration_ets_pg[0] = 0;
944 	bp->dcbx_config_params.admin_configuration_ets_pg[1] = 0;
945 	bp->dcbx_config_params.admin_configuration_ets_pg[2] = 0;
946 	bp->dcbx_config_params.admin_configuration_ets_pg[3] = 0;
947 	bp->dcbx_config_params.admin_configuration_ets_pg[4] = 0;
948 	bp->dcbx_config_params.admin_configuration_ets_pg[5] = 0;
949 	bp->dcbx_config_params.admin_configuration_ets_pg[6] = 0;
950 	bp->dcbx_config_params.admin_configuration_ets_pg[7] = 0;
951 	bp->dcbx_config_params.admin_recommendation_bw_precentage[0] = 100;
952 	bp->dcbx_config_params.admin_recommendation_bw_precentage[1] = 0;
953 	bp->dcbx_config_params.admin_recommendation_bw_precentage[2] = 0;
954 	bp->dcbx_config_params.admin_recommendation_bw_precentage[3] = 0;
955 	bp->dcbx_config_params.admin_recommendation_bw_precentage[4] = 0;
956 	bp->dcbx_config_params.admin_recommendation_bw_precentage[5] = 0;
957 	bp->dcbx_config_params.admin_recommendation_bw_precentage[6] = 0;
958 	bp->dcbx_config_params.admin_recommendation_bw_precentage[7] = 0;
959 	bp->dcbx_config_params.admin_recommendation_ets_pg[0] = 0;
960 	bp->dcbx_config_params.admin_recommendation_ets_pg[1] = 1;
961 	bp->dcbx_config_params.admin_recommendation_ets_pg[2] = 2;
962 	bp->dcbx_config_params.admin_recommendation_ets_pg[3] = 3;
963 	bp->dcbx_config_params.admin_recommendation_ets_pg[4] = 4;
964 	bp->dcbx_config_params.admin_recommendation_ets_pg[5] = 5;
965 	bp->dcbx_config_params.admin_recommendation_ets_pg[6] = 6;
966 	bp->dcbx_config_params.admin_recommendation_ets_pg[7] = 7;
967 	bp->dcbx_config_params.admin_pfc_bitmap = 0x0;
968 	bp->dcbx_config_params.admin_priority_app_table[0].valid = 0;
969 	bp->dcbx_config_params.admin_priority_app_table[1].valid = 0;
970 	bp->dcbx_config_params.admin_priority_app_table[2].valid = 0;
971 	bp->dcbx_config_params.admin_priority_app_table[3].valid = 0;
972 	bp->dcbx_config_params.admin_default_priority = 0;
973 }
974 
bnx2x_dcbx_init(struct bnx2x * bp)975 void bnx2x_dcbx_init(struct bnx2x *bp)
976 {
977 	u32 dcbx_lldp_params_offset = SHMEM_LLDP_DCBX_PARAMS_NONE;
978 
979 	if (bp->dcbx_enabled <= 0)
980 		return;
981 
982 	/* validate:
983 	 * chip of good for dcbx version,
984 	 * dcb is wanted
985 	 * the function is pmf
986 	 * shmem2 contains DCBX support fields
987 	 */
988 	DP(BNX2X_MSG_DCB, "dcb_state %d bp->port.pmf %d\n",
989 	   bp->dcb_state, bp->port.pmf);
990 
991 	if (bp->dcb_state == BNX2X_DCB_STATE_ON && bp->port.pmf &&
992 	    SHMEM2_HAS(bp, dcbx_lldp_params_offset)) {
993 		dcbx_lldp_params_offset =
994 			SHMEM2_RD(bp, dcbx_lldp_params_offset);
995 
996 		DP(BNX2X_MSG_DCB, "dcbx_lldp_params_offset 0x%x\n",
997 		   dcbx_lldp_params_offset);
998 
999 		bnx2x_update_drv_flags(bp, 1 << DRV_FLAGS_DCB_CONFIGURED, 0);
1000 
1001 		if (SHMEM_LLDP_DCBX_PARAMS_NONE != dcbx_lldp_params_offset) {
1002 			bnx2x_dcbx_admin_mib_updated_params(bp,
1003 				dcbx_lldp_params_offset);
1004 
1005 			/* Let HW start negotiation */
1006 			bnx2x_fw_command(bp,
1007 					 DRV_MSG_CODE_DCBX_ADMIN_PMF_MSG, 0);
1008 		}
1009 	}
1010 }
1011 static void
bnx2x_dcbx_print_cos_params(struct bnx2x * bp,struct bnx2x_func_tx_start_params * pfc_fw_cfg)1012 bnx2x_dcbx_print_cos_params(struct bnx2x *bp,
1013 			    struct bnx2x_func_tx_start_params *pfc_fw_cfg)
1014 {
1015 	u8 pri = 0;
1016 	u8 cos = 0;
1017 
1018 	DP(BNX2X_MSG_DCB,
1019 	   "pfc_fw_cfg->dcb_version %x\n", pfc_fw_cfg->dcb_version);
1020 	DP(BNX2X_MSG_DCB,
1021 	   "pdev->params.dcbx_port_params.pfc.priority_non_pauseable_mask %x\n",
1022 	   bp->dcbx_port_params.pfc.priority_non_pauseable_mask);
1023 
1024 	for (cos = 0 ; cos < bp->dcbx_port_params.ets.num_of_cos ; cos++) {
1025 		DP(BNX2X_MSG_DCB,
1026 		   "pdev->params.dcbx_port_params.ets.cos_params[%d].pri_bitmask %x\n",
1027 		   cos, bp->dcbx_port_params.ets.cos_params[cos].pri_bitmask);
1028 
1029 		DP(BNX2X_MSG_DCB,
1030 		   "pdev->params.dcbx_port_params.ets.cos_params[%d].bw_tbl %x\n",
1031 		   cos, bp->dcbx_port_params.ets.cos_params[cos].bw_tbl);
1032 
1033 		DP(BNX2X_MSG_DCB,
1034 		   "pdev->params.dcbx_port_params.ets.cos_params[%d].strict %x\n",
1035 		   cos, bp->dcbx_port_params.ets.cos_params[cos].strict);
1036 
1037 		DP(BNX2X_MSG_DCB,
1038 		   "pdev->params.dcbx_port_params.ets.cos_params[%d].pauseable %x\n",
1039 		   cos, bp->dcbx_port_params.ets.cos_params[cos].pauseable);
1040 	}
1041 
1042 	for (pri = 0; pri < LLFC_DRIVER_TRAFFIC_TYPE_MAX; pri++) {
1043 		DP(BNX2X_MSG_DCB,
1044 		   "pfc_fw_cfg->traffic_type_to_priority_cos[%d].priority %x\n",
1045 		   pri, pfc_fw_cfg->traffic_type_to_priority_cos[pri].priority);
1046 
1047 		DP(BNX2X_MSG_DCB,
1048 		   "pfc_fw_cfg->traffic_type_to_priority_cos[%d].cos %x\n",
1049 		   pri, pfc_fw_cfg->traffic_type_to_priority_cos[pri].cos);
1050 	}
1051 }
1052 
1053 /* fills help_data according to pg_info */
bnx2x_dcbx_get_num_pg_traf_type(struct bnx2x * bp,u32 * pg_pri_orginal_spread,struct pg_help_data * help_data)1054 static void bnx2x_dcbx_get_num_pg_traf_type(struct bnx2x *bp,
1055 					    u32 *pg_pri_orginal_spread,
1056 					    struct pg_help_data *help_data)
1057 {
1058 	bool pg_found  = false;
1059 	u32 i, traf_type, add_traf_type, add_pg;
1060 	u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
1061 	struct pg_entry_help_data *data = help_data->data; /*shotcut*/
1062 
1063 	/* Set to invalid */
1064 	for (i = 0; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++)
1065 		data[i].pg = DCBX_ILLEGAL_PG;
1066 
1067 	for (add_traf_type = 0;
1068 	     add_traf_type < LLFC_DRIVER_TRAFFIC_TYPE_MAX; add_traf_type++) {
1069 		pg_found = false;
1070 		if (ttp[add_traf_type] < MAX_PFC_PRIORITIES) {
1071 			add_pg = (u8)pg_pri_orginal_spread[ttp[add_traf_type]];
1072 			for (traf_type = 0;
1073 			     traf_type < LLFC_DRIVER_TRAFFIC_TYPE_MAX;
1074 			     traf_type++) {
1075 				if (data[traf_type].pg == add_pg) {
1076 					if (!(data[traf_type].pg_priority &
1077 					     (1 << ttp[add_traf_type])))
1078 						data[traf_type].
1079 							num_of_dif_pri++;
1080 					data[traf_type].pg_priority |=
1081 						(1 << ttp[add_traf_type]);
1082 					pg_found = true;
1083 					break;
1084 				}
1085 			}
1086 			if (false == pg_found) {
1087 				data[help_data->num_of_pg].pg = add_pg;
1088 				data[help_data->num_of_pg].pg_priority =
1089 						(1 << ttp[add_traf_type]);
1090 				data[help_data->num_of_pg].num_of_dif_pri = 1;
1091 				help_data->num_of_pg++;
1092 			}
1093 		}
1094 		DP(BNX2X_MSG_DCB,
1095 		   "add_traf_type %d pg_found %s num_of_pg %d\n",
1096 		   add_traf_type, (false == pg_found) ? "NO" : "YES",
1097 		   help_data->num_of_pg);
1098 	}
1099 }
1100 
bnx2x_dcbx_ets_disabled_entry_data(struct bnx2x * bp,struct cos_help_data * cos_data,u32 pri_join_mask)1101 static void bnx2x_dcbx_ets_disabled_entry_data(struct bnx2x *bp,
1102 					       struct cos_help_data *cos_data,
1103 					       u32 pri_join_mask)
1104 {
1105 	/* Only one priority than only one COS */
1106 	cos_data->data[0].pausable =
1107 		IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
1108 	cos_data->data[0].pri_join_mask = pri_join_mask;
1109 	cos_data->data[0].cos_bw = 100;
1110 	cos_data->num_of_cos = 1;
1111 }
1112 
bnx2x_dcbx_add_to_cos_bw(struct bnx2x * bp,struct cos_entry_help_data * data,u8 pg_bw)1113 static inline void bnx2x_dcbx_add_to_cos_bw(struct bnx2x *bp,
1114 					    struct cos_entry_help_data *data,
1115 					    u8 pg_bw)
1116 {
1117 	if (data->cos_bw == DCBX_INVALID_COS_BW)
1118 		data->cos_bw = pg_bw;
1119 	else
1120 		data->cos_bw += pg_bw;
1121 }
1122 
bnx2x_dcbx_separate_pauseable_from_non(struct bnx2x * bp,struct cos_help_data * cos_data,u32 * pg_pri_orginal_spread,struct dcbx_ets_feature * ets)1123 static void bnx2x_dcbx_separate_pauseable_from_non(struct bnx2x *bp,
1124 			struct cos_help_data *cos_data,
1125 			u32 *pg_pri_orginal_spread,
1126 			struct dcbx_ets_feature *ets)
1127 {
1128 	u32	pri_tested	= 0;
1129 	u8	i		= 0;
1130 	u8	entry		= 0;
1131 	u8	pg_entry	= 0;
1132 	u8	num_of_pri	= LLFC_DRIVER_TRAFFIC_TYPE_MAX;
1133 
1134 	cos_data->data[0].pausable = true;
1135 	cos_data->data[1].pausable = false;
1136 	cos_data->data[0].pri_join_mask = cos_data->data[1].pri_join_mask = 0;
1137 
1138 	for (i = 0 ; i < num_of_pri ; i++) {
1139 		pri_tested = 1 << bp->dcbx_port_params.
1140 					app.traffic_type_priority[i];
1141 
1142 		if (pri_tested & DCBX_PFC_PRI_NON_PAUSE_MASK(bp)) {
1143 			cos_data->data[1].pri_join_mask |= pri_tested;
1144 			entry = 1;
1145 		} else {
1146 			cos_data->data[0].pri_join_mask |= pri_tested;
1147 			entry = 0;
1148 		}
1149 		pg_entry = (u8)pg_pri_orginal_spread[bp->dcbx_port_params.
1150 						app.traffic_type_priority[i]];
1151 		/* There can be only one strict pg */
1152 		if (pg_entry < DCBX_MAX_NUM_PG_BW_ENTRIES)
1153 			bnx2x_dcbx_add_to_cos_bw(bp, &cos_data->data[entry],
1154 				DCBX_PG_BW_GET(ets->pg_bw_tbl, pg_entry));
1155 		else
1156 			/* If we join a group and one is strict
1157 			 * than the bw rulls */
1158 			cos_data->data[entry].strict =
1159 						BNX2X_DCBX_STRICT_COS_HIGHEST;
1160 	}
1161 	if ((0 == cos_data->data[0].pri_join_mask) &&
1162 	    (0 == cos_data->data[1].pri_join_mask))
1163 		BNX2X_ERR("dcbx error: Both groups must have priorities\n");
1164 }
1165 
1166 
1167 #ifndef POWER_OF_2
1168 #define POWER_OF_2(x)	((0 != x) && (0 == (x & (x-1))))
1169 #endif
1170 
bnx2x_dcbx_2cos_limit_cee_single_pg_to_cos_params(struct bnx2x * bp,struct pg_help_data * pg_help_data,struct cos_help_data * cos_data,u32 pri_join_mask,u8 num_of_dif_pri)1171 static void bnx2x_dcbx_2cos_limit_cee_single_pg_to_cos_params(struct bnx2x *bp,
1172 					      struct pg_help_data *pg_help_data,
1173 					      struct cos_help_data *cos_data,
1174 					      u32 pri_join_mask,
1175 					      u8 num_of_dif_pri)
1176 {
1177 	u8 i = 0;
1178 	u32 pri_tested = 0;
1179 	u32 pri_mask_without_pri = 0;
1180 	u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
1181 	/*debug*/
1182 	if (num_of_dif_pri == 1) {
1183 		bnx2x_dcbx_ets_disabled_entry_data(bp, cos_data, pri_join_mask);
1184 		return;
1185 	}
1186 	/* single priority group */
1187 	if (pg_help_data->data[0].pg < DCBX_MAX_NUM_PG_BW_ENTRIES) {
1188 		/* If there are both pauseable and non-pauseable priorities,
1189 		 * the pauseable priorities go to the first queue and
1190 		 * the non-pauseable priorities go to the second queue.
1191 		 */
1192 		if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
1193 			/* Pauseable */
1194 			cos_data->data[0].pausable = true;
1195 			/* Non pauseable.*/
1196 			cos_data->data[1].pausable = false;
1197 
1198 			if (2 == num_of_dif_pri) {
1199 				cos_data->data[0].cos_bw = 50;
1200 				cos_data->data[1].cos_bw = 50;
1201 			}
1202 
1203 			if (3 == num_of_dif_pri) {
1204 				if (POWER_OF_2(DCBX_PFC_PRI_GET_PAUSE(bp,
1205 							pri_join_mask))) {
1206 					cos_data->data[0].cos_bw = 33;
1207 					cos_data->data[1].cos_bw = 67;
1208 				} else {
1209 					cos_data->data[0].cos_bw = 67;
1210 					cos_data->data[1].cos_bw = 33;
1211 				}
1212 			}
1213 
1214 		} else if (IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask)) {
1215 			/* If there are only pauseable priorities,
1216 			 * then one/two priorities go to the first queue
1217 			 * and one priority goes to the second queue.
1218 			 */
1219 			if (2 == num_of_dif_pri) {
1220 				cos_data->data[0].cos_bw = 50;
1221 				cos_data->data[1].cos_bw = 50;
1222 			} else {
1223 				cos_data->data[0].cos_bw = 67;
1224 				cos_data->data[1].cos_bw = 33;
1225 			}
1226 			cos_data->data[1].pausable = true;
1227 			cos_data->data[0].pausable = true;
1228 			/* All priorities except FCOE */
1229 			cos_data->data[0].pri_join_mask = (pri_join_mask &
1230 				((u8)~(1 << ttp[LLFC_TRAFFIC_TYPE_FCOE])));
1231 			/* Only FCOE priority.*/
1232 			cos_data->data[1].pri_join_mask =
1233 				(1 << ttp[LLFC_TRAFFIC_TYPE_FCOE]);
1234 		} else
1235 			/* If there are only non-pauseable priorities,
1236 			 * they will all go to the same queue.
1237 			 */
1238 			bnx2x_dcbx_ets_disabled_entry_data(bp,
1239 						cos_data, pri_join_mask);
1240 	} else {
1241 		/* priority group which is not BW limited (PG#15):*/
1242 		if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
1243 			/* If there are both pauseable and non-pauseable
1244 			 * priorities, the pauseable priorities go to the first
1245 			 * queue and the non-pauseable priorities
1246 			 * go to the second queue.
1247 			 */
1248 			if (DCBX_PFC_PRI_GET_PAUSE(bp, pri_join_mask) >
1249 			    DCBX_PFC_PRI_GET_NON_PAUSE(bp, pri_join_mask)) {
1250 				cos_data->data[0].strict =
1251 					BNX2X_DCBX_STRICT_COS_HIGHEST;
1252 				cos_data->data[1].strict =
1253 					BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
1254 						BNX2X_DCBX_STRICT_COS_HIGHEST);
1255 			} else {
1256 				cos_data->data[0].strict =
1257 					BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
1258 						BNX2X_DCBX_STRICT_COS_HIGHEST);
1259 				cos_data->data[1].strict =
1260 					BNX2X_DCBX_STRICT_COS_HIGHEST;
1261 			}
1262 			/* Pauseable */
1263 			cos_data->data[0].pausable = true;
1264 			/* Non pause-able.*/
1265 			cos_data->data[1].pausable = false;
1266 		} else {
1267 			/* If there are only pauseable priorities or
1268 			 * only non-pauseable,* the lower priorities go
1269 			 * to the first queue and the higherpriorities go
1270 			 * to the second queue.
1271 			 */
1272 			cos_data->data[0].pausable =
1273 				cos_data->data[1].pausable =
1274 				IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
1275 
1276 			for (i = 0 ; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++) {
1277 				pri_tested = 1 << bp->dcbx_port_params.
1278 					app.traffic_type_priority[i];
1279 				/* Remove priority tested */
1280 				pri_mask_without_pri =
1281 					(pri_join_mask & ((u8)(~pri_tested)));
1282 				if (pri_mask_without_pri < pri_tested)
1283 					break;
1284 			}
1285 
1286 			if (i == LLFC_DRIVER_TRAFFIC_TYPE_MAX)
1287 				BNX2X_ERR("Invalid value for pri_join_mask - could not find a priority\n");
1288 
1289 			cos_data->data[0].pri_join_mask = pri_mask_without_pri;
1290 			cos_data->data[1].pri_join_mask = pri_tested;
1291 			/* Both queues are strict priority,
1292 			 * and that with the highest priority
1293 			 * gets the highest strict priority in the arbiter.
1294 			 */
1295 			cos_data->data[0].strict =
1296 					BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
1297 						BNX2X_DCBX_STRICT_COS_HIGHEST);
1298 			cos_data->data[1].strict =
1299 					BNX2X_DCBX_STRICT_COS_HIGHEST;
1300 		}
1301 	}
1302 }
1303 
bnx2x_dcbx_2cos_limit_cee_two_pg_to_cos_params(struct bnx2x * bp,struct pg_help_data * pg_help_data,struct dcbx_ets_feature * ets,struct cos_help_data * cos_data,u32 * pg_pri_orginal_spread,u32 pri_join_mask,u8 num_of_dif_pri)1304 static void bnx2x_dcbx_2cos_limit_cee_two_pg_to_cos_params(
1305 			    struct bnx2x		*bp,
1306 			    struct  pg_help_data	*pg_help_data,
1307 			    struct dcbx_ets_feature	*ets,
1308 			    struct cos_help_data	*cos_data,
1309 			    u32			*pg_pri_orginal_spread,
1310 			    u32				pri_join_mask,
1311 			    u8				num_of_dif_pri)
1312 {
1313 	u8 i = 0;
1314 	u8 pg[DCBX_COS_MAX_NUM_E2] = { 0 };
1315 
1316 	/* If there are both pauseable and non-pauseable priorities,
1317 	 * the pauseable priorities go to the first queue and
1318 	 * the non-pauseable priorities go to the second queue.
1319 	 */
1320 	if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
1321 		if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp,
1322 					 pg_help_data->data[0].pg_priority) ||
1323 		    IS_DCBX_PFC_PRI_MIX_PAUSE(bp,
1324 					 pg_help_data->data[1].pg_priority)) {
1325 			/* If one PG contains both pauseable and
1326 			 * non-pauseable priorities then ETS is disabled.
1327 			 */
1328 			bnx2x_dcbx_separate_pauseable_from_non(bp, cos_data,
1329 					pg_pri_orginal_spread, ets);
1330 			bp->dcbx_port_params.ets.enabled = false;
1331 			return;
1332 		}
1333 
1334 		/* Pauseable */
1335 		cos_data->data[0].pausable = true;
1336 		/* Non pauseable. */
1337 		cos_data->data[1].pausable = false;
1338 		if (IS_DCBX_PFC_PRI_ONLY_PAUSE(bp,
1339 				pg_help_data->data[0].pg_priority)) {
1340 			/* 0 is pauseable */
1341 			cos_data->data[0].pri_join_mask =
1342 				pg_help_data->data[0].pg_priority;
1343 			pg[0] = pg_help_data->data[0].pg;
1344 			cos_data->data[1].pri_join_mask =
1345 				pg_help_data->data[1].pg_priority;
1346 			pg[1] = pg_help_data->data[1].pg;
1347 		} else {/* 1 is pauseable */
1348 			cos_data->data[0].pri_join_mask =
1349 				pg_help_data->data[1].pg_priority;
1350 			pg[0] = pg_help_data->data[1].pg;
1351 			cos_data->data[1].pri_join_mask =
1352 				pg_help_data->data[0].pg_priority;
1353 			pg[1] = pg_help_data->data[0].pg;
1354 		}
1355 	} else {
1356 		/* If there are only pauseable priorities or
1357 		 * only non-pauseable, each PG goes to a queue.
1358 		 */
1359 		cos_data->data[0].pausable = cos_data->data[1].pausable =
1360 			IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
1361 		cos_data->data[0].pri_join_mask =
1362 			pg_help_data->data[0].pg_priority;
1363 		pg[0] = pg_help_data->data[0].pg;
1364 		cos_data->data[1].pri_join_mask =
1365 			pg_help_data->data[1].pg_priority;
1366 		pg[1] = pg_help_data->data[1].pg;
1367 	}
1368 
1369 	/* There can be only one strict pg */
1370 	for (i = 0 ; i < ARRAY_SIZE(pg); i++) {
1371 		if (pg[i] < DCBX_MAX_NUM_PG_BW_ENTRIES)
1372 			cos_data->data[i].cos_bw =
1373 				DCBX_PG_BW_GET(ets->pg_bw_tbl, pg[i]);
1374 		else
1375 			cos_data->data[i].strict =
1376 						BNX2X_DCBX_STRICT_COS_HIGHEST;
1377 	}
1378 }
1379 
bnx2x_dcbx_join_pgs(struct bnx2x * bp,struct dcbx_ets_feature * ets,struct pg_help_data * pg_help_data,u8 required_num_of_pg)1380 static int bnx2x_dcbx_join_pgs(
1381 			      struct bnx2x            *bp,
1382 			      struct dcbx_ets_feature *ets,
1383 			      struct pg_help_data     *pg_help_data,
1384 			      u8                      required_num_of_pg)
1385 {
1386 	u8 entry_joined    = pg_help_data->num_of_pg - 1;
1387 	u8 entry_removed   = entry_joined + 1;
1388 	u8 pg_joined       = 0;
1389 
1390 	if (required_num_of_pg == 0 || ARRAY_SIZE(pg_help_data->data)
1391 						<= pg_help_data->num_of_pg) {
1392 
1393 		BNX2X_ERR("required_num_of_pg can't be zero\n");
1394 		return -EINVAL;
1395 	}
1396 
1397 	while (required_num_of_pg < pg_help_data->num_of_pg) {
1398 		entry_joined = pg_help_data->num_of_pg - 2;
1399 		entry_removed = entry_joined + 1;
1400 		/* protect index */
1401 		entry_removed %= ARRAY_SIZE(pg_help_data->data);
1402 
1403 		pg_help_data->data[entry_joined].pg_priority |=
1404 			pg_help_data->data[entry_removed].pg_priority;
1405 
1406 		pg_help_data->data[entry_joined].num_of_dif_pri +=
1407 			pg_help_data->data[entry_removed].num_of_dif_pri;
1408 
1409 		if (pg_help_data->data[entry_joined].pg == DCBX_STRICT_PRI_PG ||
1410 		    pg_help_data->data[entry_removed].pg == DCBX_STRICT_PRI_PG)
1411 			/* Entries joined strict priority rules */
1412 			pg_help_data->data[entry_joined].pg =
1413 							DCBX_STRICT_PRI_PG;
1414 		else {
1415 			/* Entries can be joined join BW */
1416 			pg_joined = DCBX_PG_BW_GET(ets->pg_bw_tbl,
1417 					pg_help_data->data[entry_joined].pg) +
1418 				    DCBX_PG_BW_GET(ets->pg_bw_tbl,
1419 					pg_help_data->data[entry_removed].pg);
1420 
1421 			DCBX_PG_BW_SET(ets->pg_bw_tbl,
1422 				pg_help_data->data[entry_joined].pg, pg_joined);
1423 		}
1424 		/* Joined the entries */
1425 		pg_help_data->num_of_pg--;
1426 	}
1427 
1428 	return 0;
1429 }
1430 
bnx2x_dcbx_2cos_limit_cee_three_pg_to_cos_params(struct bnx2x * bp,struct pg_help_data * pg_help_data,struct dcbx_ets_feature * ets,struct cos_help_data * cos_data,u32 * pg_pri_orginal_spread,u32 pri_join_mask,u8 num_of_dif_pri)1431 static void bnx2x_dcbx_2cos_limit_cee_three_pg_to_cos_params(
1432 			      struct bnx2x		*bp,
1433 			      struct pg_help_data	*pg_help_data,
1434 			      struct dcbx_ets_feature	*ets,
1435 			      struct cos_help_data	*cos_data,
1436 			      u32			*pg_pri_orginal_spread,
1437 			      u32			pri_join_mask,
1438 			      u8			num_of_dif_pri)
1439 {
1440 	u8 i = 0;
1441 	u32 pri_tested = 0;
1442 	u8 entry = 0;
1443 	u8 pg_entry = 0;
1444 	bool b_found_strict = false;
1445 	u8 num_of_pri = LLFC_DRIVER_TRAFFIC_TYPE_MAX;
1446 
1447 	cos_data->data[0].pri_join_mask = cos_data->data[1].pri_join_mask = 0;
1448 	/* If there are both pauseable and non-pauseable priorities,
1449 	 * the pauseable priorities go to the first queue and the
1450 	 * non-pauseable priorities go to the second queue.
1451 	 */
1452 	if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask))
1453 		bnx2x_dcbx_separate_pauseable_from_non(bp,
1454 				cos_data, pg_pri_orginal_spread, ets);
1455 	else {
1456 		/* If two BW-limited PG-s were combined to one queue,
1457 		 * the BW is their sum.
1458 		 *
1459 		 * If there are only pauseable priorities or only non-pauseable,
1460 		 * and there are both BW-limited and non-BW-limited PG-s,
1461 		 * the BW-limited PG/s go to one queue and the non-BW-limited
1462 		 * PG/s go to the second queue.
1463 		 *
1464 		 * If there are only pauseable priorities or only non-pauseable
1465 		 * and all are BW limited, then	two priorities go to the first
1466 		 * queue and one priority goes to the second queue.
1467 		 *
1468 		 * We will join this two cases:
1469 		 * if one is BW limited it will go to the secoend queue
1470 		 * otherwise the last priority will get it
1471 		 */
1472 
1473 		cos_data->data[0].pausable = cos_data->data[1].pausable =
1474 			IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
1475 
1476 		for (i = 0 ; i < num_of_pri; i++) {
1477 			pri_tested = 1 << bp->dcbx_port_params.
1478 				app.traffic_type_priority[i];
1479 			pg_entry = (u8)pg_pri_orginal_spread[bp->
1480 				dcbx_port_params.app.traffic_type_priority[i]];
1481 
1482 			if (pg_entry < DCBX_MAX_NUM_PG_BW_ENTRIES) {
1483 				entry = 0;
1484 
1485 				if (i == (num_of_pri-1) &&
1486 				    false == b_found_strict)
1487 					/* last entry will be handled separately
1488 					 * If no priority is strict than last
1489 					 * enty goes to last queue.*/
1490 					entry = 1;
1491 				cos_data->data[entry].pri_join_mask |=
1492 								pri_tested;
1493 				bnx2x_dcbx_add_to_cos_bw(bp,
1494 					&cos_data->data[entry],
1495 					DCBX_PG_BW_GET(ets->pg_bw_tbl,
1496 						       pg_entry));
1497 			} else {
1498 				b_found_strict = true;
1499 				cos_data->data[1].pri_join_mask |= pri_tested;
1500 				/* If we join a group and one is strict
1501 				 * than the bw rulls */
1502 				cos_data->data[1].strict =
1503 					BNX2X_DCBX_STRICT_COS_HIGHEST;
1504 			}
1505 		}
1506 	}
1507 }
1508 
1509 
bnx2x_dcbx_2cos_limit_cee_fill_cos_params(struct bnx2x * bp,struct pg_help_data * help_data,struct dcbx_ets_feature * ets,struct cos_help_data * cos_data,u32 * pg_pri_orginal_spread,u32 pri_join_mask,u8 num_of_dif_pri)1510 static void bnx2x_dcbx_2cos_limit_cee_fill_cos_params(struct bnx2x *bp,
1511 				       struct pg_help_data *help_data,
1512 				       struct dcbx_ets_feature *ets,
1513 				       struct cos_help_data *cos_data,
1514 				       u32 *pg_pri_orginal_spread,
1515 				       u32 pri_join_mask,
1516 				       u8 num_of_dif_pri)
1517 {
1518 
1519 	/* default E2 settings */
1520 	cos_data->num_of_cos = DCBX_COS_MAX_NUM_E2;
1521 
1522 	switch (help_data->num_of_pg) {
1523 	case 1:
1524 		bnx2x_dcbx_2cos_limit_cee_single_pg_to_cos_params(
1525 					       bp,
1526 					       help_data,
1527 					       cos_data,
1528 					       pri_join_mask,
1529 					       num_of_dif_pri);
1530 		break;
1531 	case 2:
1532 		bnx2x_dcbx_2cos_limit_cee_two_pg_to_cos_params(
1533 					    bp,
1534 					    help_data,
1535 					    ets,
1536 					    cos_data,
1537 					    pg_pri_orginal_spread,
1538 					    pri_join_mask,
1539 					    num_of_dif_pri);
1540 		break;
1541 
1542 	case 3:
1543 		bnx2x_dcbx_2cos_limit_cee_three_pg_to_cos_params(
1544 					      bp,
1545 					      help_data,
1546 					      ets,
1547 					      cos_data,
1548 					      pg_pri_orginal_spread,
1549 					      pri_join_mask,
1550 					      num_of_dif_pri);
1551 		break;
1552 	default:
1553 		BNX2X_ERR("Wrong pg_help_data.num_of_pg\n");
1554 		bnx2x_dcbx_ets_disabled_entry_data(bp,
1555 						   cos_data, pri_join_mask);
1556 	}
1557 }
1558 
bnx2x_dcbx_spread_strict_pri(struct bnx2x * bp,struct cos_help_data * cos_data,u8 entry,u8 num_spread_of_entries,u8 strict_app_pris)1559 static int bnx2x_dcbx_spread_strict_pri(struct bnx2x *bp,
1560 					struct cos_help_data *cos_data,
1561 					u8 entry,
1562 					u8 num_spread_of_entries,
1563 					u8 strict_app_pris)
1564 {
1565 	u8 strict_pri = BNX2X_DCBX_STRICT_COS_HIGHEST;
1566 	u8 num_of_app_pri = MAX_PFC_PRIORITIES;
1567 	u8 app_pri_bit = 0;
1568 
1569 	while (num_spread_of_entries && num_of_app_pri > 0) {
1570 		app_pri_bit = 1 << (num_of_app_pri - 1);
1571 		if (app_pri_bit & strict_app_pris) {
1572 			struct cos_entry_help_data *data = &cos_data->
1573 								data[entry];
1574 			num_spread_of_entries--;
1575 			if (num_spread_of_entries == 0) {
1576 				/* last entry needed put all the entries left */
1577 				data->cos_bw = DCBX_INVALID_COS_BW;
1578 				data->strict = strict_pri;
1579 				data->pri_join_mask = strict_app_pris;
1580 				data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
1581 							data->pri_join_mask);
1582 			} else {
1583 				strict_app_pris &= ~app_pri_bit;
1584 
1585 				data->cos_bw = DCBX_INVALID_COS_BW;
1586 				data->strict = strict_pri;
1587 				data->pri_join_mask = app_pri_bit;
1588 				data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
1589 							data->pri_join_mask);
1590 			}
1591 
1592 			strict_pri =
1593 			    BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(strict_pri);
1594 			entry++;
1595 		}
1596 
1597 		num_of_app_pri--;
1598 	}
1599 
1600 	if (num_spread_of_entries) {
1601 		BNX2X_ERR("Didn't succeed to spread strict priorities\n");
1602 		return -EINVAL;
1603 	}
1604 
1605 	return 0;
1606 }
1607 
bnx2x_dcbx_cee_fill_strict_pri(struct bnx2x * bp,struct cos_help_data * cos_data,u8 entry,u8 num_spread_of_entries,u8 strict_app_pris)1608 static u8 bnx2x_dcbx_cee_fill_strict_pri(struct bnx2x *bp,
1609 					 struct cos_help_data *cos_data,
1610 					 u8 entry,
1611 					 u8 num_spread_of_entries,
1612 					 u8 strict_app_pris)
1613 {
1614 
1615 	if (bnx2x_dcbx_spread_strict_pri(bp, cos_data, entry,
1616 					 num_spread_of_entries,
1617 					 strict_app_pris)) {
1618 		struct cos_entry_help_data *data = &cos_data->
1619 						    data[entry];
1620 		/* Fill BW entry */
1621 		data->cos_bw = DCBX_INVALID_COS_BW;
1622 		data->strict = BNX2X_DCBX_STRICT_COS_HIGHEST;
1623 		data->pri_join_mask = strict_app_pris;
1624 		data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
1625 				 data->pri_join_mask);
1626 		return 1;
1627 	}
1628 
1629 	return num_spread_of_entries;
1630 }
1631 
bnx2x_dcbx_cee_fill_cos_params(struct bnx2x * bp,struct pg_help_data * help_data,struct dcbx_ets_feature * ets,struct cos_help_data * cos_data,u32 pri_join_mask)1632 static void bnx2x_dcbx_cee_fill_cos_params(struct bnx2x *bp,
1633 					   struct pg_help_data *help_data,
1634 					   struct dcbx_ets_feature *ets,
1635 					   struct cos_help_data *cos_data,
1636 					   u32 pri_join_mask)
1637 
1638 {
1639 	u8 need_num_of_entries = 0;
1640 	u8 i = 0;
1641 	u8 entry = 0;
1642 
1643 	/*
1644 	 * if the number of requested PG-s in CEE is greater than 3
1645 	 * then the results are not determined since this is a violation
1646 	 * of the standard.
1647 	 */
1648 	if (help_data->num_of_pg > DCBX_COS_MAX_NUM_E3B0) {
1649 		if (bnx2x_dcbx_join_pgs(bp, ets, help_data,
1650 					DCBX_COS_MAX_NUM_E3B0)) {
1651 			BNX2X_ERR("Unable to reduce the number of PGs - we will disables ETS\n");
1652 			bnx2x_dcbx_ets_disabled_entry_data(bp, cos_data,
1653 							   pri_join_mask);
1654 			return;
1655 		}
1656 	}
1657 
1658 	for (i = 0 ; i < help_data->num_of_pg; i++) {
1659 		struct pg_entry_help_data *pg =  &help_data->data[i];
1660 		if (pg->pg < DCBX_MAX_NUM_PG_BW_ENTRIES) {
1661 			struct cos_entry_help_data *data = &cos_data->
1662 							    data[entry];
1663 			/* Fill BW entry */
1664 			data->cos_bw = DCBX_PG_BW_GET(ets->pg_bw_tbl, pg->pg);
1665 			data->strict = BNX2X_DCBX_STRICT_INVALID;
1666 			data->pri_join_mask = pg->pg_priority;
1667 			data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
1668 						data->pri_join_mask);
1669 
1670 			entry++;
1671 		} else {
1672 			need_num_of_entries =  min_t(u8,
1673 				(u8)pg->num_of_dif_pri,
1674 				(u8)DCBX_COS_MAX_NUM_E3B0 -
1675 						 help_data->num_of_pg + 1);
1676 			/*
1677 			 * If there are still VOQ-s which have no associated PG,
1678 			 * then associate these VOQ-s to PG15. These PG-s will
1679 			 * be used for SP between priorities on PG15.
1680 			 */
1681 			entry += bnx2x_dcbx_cee_fill_strict_pri(bp, cos_data,
1682 				entry, need_num_of_entries, pg->pg_priority);
1683 		}
1684 	}
1685 
1686 	/* the entry will represent the number of COSes used */
1687 	cos_data->num_of_cos = entry;
1688 }
bnx2x_dcbx_fill_cos_params(struct bnx2x * bp,struct pg_help_data * help_data,struct dcbx_ets_feature * ets,u32 * pg_pri_orginal_spread)1689 static void bnx2x_dcbx_fill_cos_params(struct bnx2x *bp,
1690 				       struct pg_help_data *help_data,
1691 				       struct dcbx_ets_feature *ets,
1692 				       u32 *pg_pri_orginal_spread)
1693 {
1694 	struct cos_help_data         cos_data;
1695 	u8                    i                           = 0;
1696 	u32                   pri_join_mask               = 0;
1697 	u8                    num_of_dif_pri              = 0;
1698 
1699 	memset(&cos_data, 0, sizeof(cos_data));
1700 
1701 	/* Validate the pg value */
1702 	for (i = 0; i < help_data->num_of_pg ; i++) {
1703 		if (DCBX_STRICT_PRIORITY != help_data->data[i].pg &&
1704 		    DCBX_MAX_NUM_PG_BW_ENTRIES <= help_data->data[i].pg)
1705 			BNX2X_ERR("Invalid pg[%d] data %x\n", i,
1706 				  help_data->data[i].pg);
1707 		pri_join_mask   |=  help_data->data[i].pg_priority;
1708 		num_of_dif_pri  += help_data->data[i].num_of_dif_pri;
1709 	}
1710 
1711 	/* defaults */
1712 	cos_data.num_of_cos = 1;
1713 	for (i = 0; i < ARRAY_SIZE(cos_data.data); i++) {
1714 		cos_data.data[i].pri_join_mask = 0;
1715 		cos_data.data[i].pausable = false;
1716 		cos_data.data[i].strict = BNX2X_DCBX_STRICT_INVALID;
1717 		cos_data.data[i].cos_bw = DCBX_INVALID_COS_BW;
1718 	}
1719 
1720 	if (CHIP_IS_E3B0(bp))
1721 		bnx2x_dcbx_cee_fill_cos_params(bp, help_data, ets,
1722 					       &cos_data, pri_join_mask);
1723 	else /* E2 + E3A0 */
1724 		bnx2x_dcbx_2cos_limit_cee_fill_cos_params(bp,
1725 							  help_data, ets,
1726 							  &cos_data,
1727 							  pg_pri_orginal_spread,
1728 							  pri_join_mask,
1729 							  num_of_dif_pri);
1730 
1731 	for (i = 0; i < cos_data.num_of_cos ; i++) {
1732 		struct bnx2x_dcbx_cos_params *p =
1733 			&bp->dcbx_port_params.ets.cos_params[i];
1734 
1735 		p->strict = cos_data.data[i].strict;
1736 		p->bw_tbl = cos_data.data[i].cos_bw;
1737 		p->pri_bitmask = cos_data.data[i].pri_join_mask;
1738 		p->pauseable = cos_data.data[i].pausable;
1739 
1740 		/* sanity */
1741 		if (p->bw_tbl != DCBX_INVALID_COS_BW ||
1742 		    p->strict != BNX2X_DCBX_STRICT_INVALID) {
1743 			if (p->pri_bitmask == 0)
1744 				BNX2X_ERR("Invalid pri_bitmask for %d\n", i);
1745 
1746 			if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp)) {
1747 
1748 				if (p->pauseable &&
1749 				    DCBX_PFC_PRI_GET_NON_PAUSE(bp,
1750 						p->pri_bitmask) != 0)
1751 					BNX2X_ERR("Inconsistent config for pausable COS %d\n",
1752 						  i);
1753 
1754 				if (!p->pauseable &&
1755 				    DCBX_PFC_PRI_GET_PAUSE(bp,
1756 						p->pri_bitmask) != 0)
1757 					BNX2X_ERR("Inconsistent config for nonpausable COS %d\n",
1758 						  i);
1759 			}
1760 		}
1761 
1762 		if (p->pauseable)
1763 			DP(BNX2X_MSG_DCB, "COS %d PAUSABLE prijoinmask 0x%x\n",
1764 				  i, cos_data.data[i].pri_join_mask);
1765 		else
1766 			DP(BNX2X_MSG_DCB,
1767 			   "COS %d NONPAUSABLE prijoinmask 0x%x\n",
1768 			   i, cos_data.data[i].pri_join_mask);
1769 	}
1770 
1771 	bp->dcbx_port_params.ets.num_of_cos = cos_data.num_of_cos ;
1772 }
1773 
bnx2x_dcbx_get_ets_pri_pg_tbl(struct bnx2x * bp,u32 * set_configuration_ets_pg,u32 * pri_pg_tbl)1774 static void bnx2x_dcbx_get_ets_pri_pg_tbl(struct bnx2x *bp,
1775 				u32 *set_configuration_ets_pg,
1776 				u32 *pri_pg_tbl)
1777 {
1778 	int i;
1779 
1780 	for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++) {
1781 		set_configuration_ets_pg[i] = DCBX_PRI_PG_GET(pri_pg_tbl, i);
1782 
1783 		DP(BNX2X_MSG_DCB, "set_configuration_ets_pg[%d] = 0x%x\n",
1784 		   i, set_configuration_ets_pg[i]);
1785 	}
1786 }
1787 
bnx2x_dcbx_fw_struct(struct bnx2x * bp,struct bnx2x_func_tx_start_params * pfc_fw_cfg)1788 static void bnx2x_dcbx_fw_struct(struct bnx2x *bp,
1789 				 struct bnx2x_func_tx_start_params *pfc_fw_cfg)
1790 {
1791 	u16 pri_bit = 0;
1792 	u8 cos = 0, pri = 0;
1793 	struct priority_cos *tt2cos;
1794 	u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
1795 
1796 	memset(pfc_fw_cfg, 0, sizeof(*pfc_fw_cfg));
1797 
1798 	/* to disable DCB - the structure must be zeroed */
1799 	if (bp->dcbx_error & DCBX_REMOTE_MIB_ERROR)
1800 		return;
1801 
1802 	/*shortcut*/
1803 	tt2cos = pfc_fw_cfg->traffic_type_to_priority_cos;
1804 
1805 	/* Fw version should be incremented each update */
1806 	pfc_fw_cfg->dcb_version = ++bp->dcb_version;
1807 	pfc_fw_cfg->dcb_enabled = 1;
1808 
1809 	/* Fill priority parameters */
1810 	for (pri = 0; pri < LLFC_DRIVER_TRAFFIC_TYPE_MAX; pri++) {
1811 		tt2cos[pri].priority = ttp[pri];
1812 		pri_bit = 1 << tt2cos[pri].priority;
1813 
1814 		/* Fill COS parameters based on COS calculated to
1815 		 * make it more general for future use */
1816 		for (cos = 0; cos < bp->dcbx_port_params.ets.num_of_cos; cos++)
1817 			if (bp->dcbx_port_params.ets.cos_params[cos].
1818 						pri_bitmask & pri_bit)
1819 					tt2cos[pri].cos = cos;
1820 	}
1821 
1822 	/* we never want the FW to add a 0 vlan tag */
1823 	pfc_fw_cfg->dont_add_pri_0_en = 1;
1824 
1825 	bnx2x_dcbx_print_cos_params(bp,	pfc_fw_cfg);
1826 }
1827 
bnx2x_dcbx_pmf_update(struct bnx2x * bp)1828 void bnx2x_dcbx_pmf_update(struct bnx2x *bp)
1829 {
1830 	/* if we need to syncronize DCBX result from prev PMF
1831 	 * read it from shmem and update bp and netdev accordingly
1832 	 */
1833 	if (SHMEM2_HAS(bp, drv_flags) &&
1834 	   GET_FLAGS(SHMEM2_RD(bp, drv_flags), 1 << DRV_FLAGS_DCB_CONFIGURED)) {
1835 		/* Read neg results if dcbx is in the FW */
1836 		if (bnx2x_dcbx_read_shmem_neg_results(bp))
1837 			return;
1838 
1839 		bnx2x_dump_dcbx_drv_param(bp, &bp->dcbx_local_feat,
1840 					  bp->dcbx_error);
1841 		bnx2x_get_dcbx_drv_param(bp, &bp->dcbx_local_feat,
1842 					 bp->dcbx_error);
1843 #ifdef BCM_DCBNL
1844 		/*
1845 		 * Add new app tlvs to dcbnl
1846 		 */
1847 		bnx2x_dcbnl_update_applist(bp, false);
1848 		/*
1849 		 * Send a notification for the new negotiated parameters
1850 		 */
1851 		dcbnl_cee_notify(bp->dev, RTM_GETDCB, DCB_CMD_CEE_GET, 0, 0);
1852 #endif
1853 		/*
1854 		 * reconfigure the netdevice with the results of the new
1855 		 * dcbx negotiation.
1856 		 */
1857 		bnx2x_dcbx_update_tc_mapping(bp);
1858 
1859 	}
1860 }
1861 
1862 /* DCB netlink */
1863 #ifdef BCM_DCBNL
1864 
1865 #define BNX2X_DCBX_CAPS		(DCB_CAP_DCBX_LLD_MANAGED | \
1866 				DCB_CAP_DCBX_VER_CEE | DCB_CAP_DCBX_STATIC)
1867 
bnx2x_dcbnl_set_valid(struct bnx2x * bp)1868 static inline bool bnx2x_dcbnl_set_valid(struct bnx2x *bp)
1869 {
1870 	/* validate dcbnl call that may change HW state:
1871 	 * DCB is on and DCBX mode was SUCCESSFULLY set by the user.
1872 	 */
1873 	return bp->dcb_state && bp->dcbx_mode_uset;
1874 }
1875 
bnx2x_dcbnl_get_state(struct net_device * netdev)1876 static u8 bnx2x_dcbnl_get_state(struct net_device *netdev)
1877 {
1878 	struct bnx2x *bp = netdev_priv(netdev);
1879 	DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcb_state);
1880 	return bp->dcb_state;
1881 }
1882 
bnx2x_dcbnl_set_state(struct net_device * netdev,u8 state)1883 static u8 bnx2x_dcbnl_set_state(struct net_device *netdev, u8 state)
1884 {
1885 	struct bnx2x *bp = netdev_priv(netdev);
1886 	DP(BNX2X_MSG_DCB, "state = %s\n", state ? "on" : "off");
1887 
1888 	bnx2x_dcbx_set_state(bp, (state ? true : false), bp->dcbx_enabled);
1889 	return 0;
1890 }
1891 
bnx2x_dcbnl_get_perm_hw_addr(struct net_device * netdev,u8 * perm_addr)1892 static void bnx2x_dcbnl_get_perm_hw_addr(struct net_device *netdev,
1893 					 u8 *perm_addr)
1894 {
1895 	struct bnx2x *bp = netdev_priv(netdev);
1896 	DP(BNX2X_MSG_DCB, "GET-PERM-ADDR\n");
1897 
1898 	/* first the HW mac address */
1899 	memcpy(perm_addr, netdev->dev_addr, netdev->addr_len);
1900 
1901 #ifdef BCM_CNIC
1902 	/* second SAN address */
1903 	memcpy(perm_addr+netdev->addr_len, bp->fip_mac, netdev->addr_len);
1904 #endif
1905 }
1906 
bnx2x_dcbnl_set_pg_tccfg_tx(struct net_device * netdev,int prio,u8 prio_type,u8 pgid,u8 bw_pct,u8 up_map)1907 static void bnx2x_dcbnl_set_pg_tccfg_tx(struct net_device *netdev, int prio,
1908 					u8 prio_type, u8 pgid, u8 bw_pct,
1909 					u8 up_map)
1910 {
1911 	struct bnx2x *bp = netdev_priv(netdev);
1912 
1913 	DP(BNX2X_MSG_DCB, "prio[%d] = %d\n", prio, pgid);
1914 	if (!bnx2x_dcbnl_set_valid(bp) || prio >= DCBX_MAX_NUM_PRI_PG_ENTRIES)
1915 		return;
1916 
1917 	/**
1918 	 * bw_pct ingnored -	band-width percentage devision between user
1919 	 *			priorities within the same group is not
1920 	 *			standard and hence not supported
1921 	 *
1922 	 * prio_type igonred -	priority levels within the same group are not
1923 	 *			standard and hence are not supported. According
1924 	 *			to the standard pgid 15 is dedicated to strict
1925 	 *			prioirty traffic (on the port level).
1926 	 *
1927 	 * up_map ignored
1928 	 */
1929 
1930 	bp->dcbx_config_params.admin_configuration_ets_pg[prio] = pgid;
1931 	bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
1932 }
1933 
bnx2x_dcbnl_set_pg_bwgcfg_tx(struct net_device * netdev,int pgid,u8 bw_pct)1934 static void bnx2x_dcbnl_set_pg_bwgcfg_tx(struct net_device *netdev,
1935 					 int pgid, u8 bw_pct)
1936 {
1937 	struct bnx2x *bp = netdev_priv(netdev);
1938 	DP(BNX2X_MSG_DCB, "pgid[%d] = %d\n", pgid, bw_pct);
1939 
1940 	if (!bnx2x_dcbnl_set_valid(bp) || pgid >= DCBX_MAX_NUM_PG_BW_ENTRIES)
1941 		return;
1942 
1943 	bp->dcbx_config_params.admin_configuration_bw_precentage[pgid] = bw_pct;
1944 	bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
1945 }
1946 
bnx2x_dcbnl_set_pg_tccfg_rx(struct net_device * netdev,int prio,u8 prio_type,u8 pgid,u8 bw_pct,u8 up_map)1947 static void bnx2x_dcbnl_set_pg_tccfg_rx(struct net_device *netdev, int prio,
1948 					u8 prio_type, u8 pgid, u8 bw_pct,
1949 					u8 up_map)
1950 {
1951 	struct bnx2x *bp = netdev_priv(netdev);
1952 	DP(BNX2X_MSG_DCB, "Nothing to set; No RX support\n");
1953 }
1954 
bnx2x_dcbnl_set_pg_bwgcfg_rx(struct net_device * netdev,int pgid,u8 bw_pct)1955 static void bnx2x_dcbnl_set_pg_bwgcfg_rx(struct net_device *netdev,
1956 					 int pgid, u8 bw_pct)
1957 {
1958 	struct bnx2x *bp = netdev_priv(netdev);
1959 	DP(BNX2X_MSG_DCB, "Nothing to set; No RX support\n");
1960 }
1961 
bnx2x_dcbnl_get_pg_tccfg_tx(struct net_device * netdev,int prio,u8 * prio_type,u8 * pgid,u8 * bw_pct,u8 * up_map)1962 static void bnx2x_dcbnl_get_pg_tccfg_tx(struct net_device *netdev, int prio,
1963 					u8 *prio_type, u8 *pgid, u8 *bw_pct,
1964 					u8 *up_map)
1965 {
1966 	struct bnx2x *bp = netdev_priv(netdev);
1967 	DP(BNX2X_MSG_DCB, "prio = %d\n", prio);
1968 
1969 	/**
1970 	 * bw_pct ingnored -	band-width percentage devision between user
1971 	 *			priorities within the same group is not
1972 	 *			standard and hence not supported
1973 	 *
1974 	 * prio_type igonred -	priority levels within the same group are not
1975 	 *			standard and hence are not supported. According
1976 	 *			to the standard pgid 15 is dedicated to strict
1977 	 *			prioirty traffic (on the port level).
1978 	 *
1979 	 * up_map ignored
1980 	 */
1981 	*up_map = *bw_pct = *prio_type = *pgid = 0;
1982 
1983 	if (!bp->dcb_state || prio >= DCBX_MAX_NUM_PRI_PG_ENTRIES)
1984 		return;
1985 
1986 	*pgid = DCBX_PRI_PG_GET(bp->dcbx_local_feat.ets.pri_pg_tbl, prio);
1987 }
1988 
bnx2x_dcbnl_get_pg_bwgcfg_tx(struct net_device * netdev,int pgid,u8 * bw_pct)1989 static void bnx2x_dcbnl_get_pg_bwgcfg_tx(struct net_device *netdev,
1990 					 int pgid, u8 *bw_pct)
1991 {
1992 	struct bnx2x *bp = netdev_priv(netdev);
1993 	DP(BNX2X_MSG_DCB, "pgid = %d\n", pgid);
1994 
1995 	*bw_pct = 0;
1996 
1997 	if (!bp->dcb_state || pgid >= DCBX_MAX_NUM_PG_BW_ENTRIES)
1998 		return;
1999 
2000 	*bw_pct = DCBX_PG_BW_GET(bp->dcbx_local_feat.ets.pg_bw_tbl, pgid);
2001 }
2002 
bnx2x_dcbnl_get_pg_tccfg_rx(struct net_device * netdev,int prio,u8 * prio_type,u8 * pgid,u8 * bw_pct,u8 * up_map)2003 static void bnx2x_dcbnl_get_pg_tccfg_rx(struct net_device *netdev, int prio,
2004 					u8 *prio_type, u8 *pgid, u8 *bw_pct,
2005 					u8 *up_map)
2006 {
2007 	struct bnx2x *bp = netdev_priv(netdev);
2008 	DP(BNX2X_MSG_DCB, "Nothing to get; No RX support\n");
2009 
2010 	*prio_type = *pgid = *bw_pct = *up_map = 0;
2011 }
2012 
bnx2x_dcbnl_get_pg_bwgcfg_rx(struct net_device * netdev,int pgid,u8 * bw_pct)2013 static void bnx2x_dcbnl_get_pg_bwgcfg_rx(struct net_device *netdev,
2014 					 int pgid, u8 *bw_pct)
2015 {
2016 	struct bnx2x *bp = netdev_priv(netdev);
2017 	DP(BNX2X_MSG_DCB, "Nothing to get; No RX support\n");
2018 
2019 	*bw_pct = 0;
2020 }
2021 
bnx2x_dcbnl_set_pfc_cfg(struct net_device * netdev,int prio,u8 setting)2022 static void bnx2x_dcbnl_set_pfc_cfg(struct net_device *netdev, int prio,
2023 				    u8 setting)
2024 {
2025 	struct bnx2x *bp = netdev_priv(netdev);
2026 	DP(BNX2X_MSG_DCB, "prio[%d] = %d\n", prio, setting);
2027 
2028 	if (!bnx2x_dcbnl_set_valid(bp) || prio >= MAX_PFC_PRIORITIES)
2029 		return;
2030 
2031 	bp->dcbx_config_params.admin_pfc_bitmap |= ((setting ? 1 : 0) << prio);
2032 
2033 	if (setting)
2034 		bp->dcbx_config_params.admin_pfc_tx_enable = 1;
2035 }
2036 
bnx2x_dcbnl_get_pfc_cfg(struct net_device * netdev,int prio,u8 * setting)2037 static void bnx2x_dcbnl_get_pfc_cfg(struct net_device *netdev, int prio,
2038 				    u8 *setting)
2039 {
2040 	struct bnx2x *bp = netdev_priv(netdev);
2041 	DP(BNX2X_MSG_DCB, "prio = %d\n", prio);
2042 
2043 	*setting = 0;
2044 
2045 	if (!bp->dcb_state || prio >= MAX_PFC_PRIORITIES)
2046 		return;
2047 
2048 	*setting = (bp->dcbx_local_feat.pfc.pri_en_bitmap >> prio) & 0x1;
2049 }
2050 
bnx2x_dcbnl_set_all(struct net_device * netdev)2051 static u8 bnx2x_dcbnl_set_all(struct net_device *netdev)
2052 {
2053 	struct bnx2x *bp = netdev_priv(netdev);
2054 	int rc = 0;
2055 
2056 	DP(BNX2X_MSG_DCB, "SET-ALL\n");
2057 
2058 	if (!bnx2x_dcbnl_set_valid(bp))
2059 		return 1;
2060 
2061 	if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
2062 		netdev_err(bp->dev,
2063 			   "Handling parity error recovery. Try again later\n");
2064 		return 1;
2065 	}
2066 	if (netif_running(bp->dev)) {
2067 		bnx2x_nic_unload(bp, UNLOAD_NORMAL);
2068 		rc = bnx2x_nic_load(bp, LOAD_NORMAL);
2069 	}
2070 	DP(BNX2X_MSG_DCB, "set_dcbx_params done (%d)\n", rc);
2071 	if (rc)
2072 		return 1;
2073 
2074 	return 0;
2075 }
2076 
bnx2x_dcbnl_get_cap(struct net_device * netdev,int capid,u8 * cap)2077 static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
2078 {
2079 	struct bnx2x *bp = netdev_priv(netdev);
2080 	u8 rval = 0;
2081 
2082 	if (bp->dcb_state) {
2083 		switch (capid) {
2084 		case DCB_CAP_ATTR_PG:
2085 			*cap = true;
2086 			break;
2087 		case DCB_CAP_ATTR_PFC:
2088 			*cap = true;
2089 			break;
2090 		case DCB_CAP_ATTR_UP2TC:
2091 			*cap = false;
2092 			break;
2093 		case DCB_CAP_ATTR_PG_TCS:
2094 			*cap = 0x80;	/* 8 priorities for PGs */
2095 			break;
2096 		case DCB_CAP_ATTR_PFC_TCS:
2097 			*cap = 0x80;	/* 8 priorities for PFC */
2098 			break;
2099 		case DCB_CAP_ATTR_GSP:
2100 			*cap = true;
2101 			break;
2102 		case DCB_CAP_ATTR_BCN:
2103 			*cap = false;
2104 			break;
2105 		case DCB_CAP_ATTR_DCBX:
2106 			*cap = BNX2X_DCBX_CAPS;
2107 			break;
2108 		default:
2109 			BNX2X_ERR("Non valid capability ID\n");
2110 			rval = -EINVAL;
2111 			break;
2112 		}
2113 	} else {
2114 		DP(BNX2X_MSG_DCB, "DCB disabled\n");
2115 		rval = -EINVAL;
2116 	}
2117 
2118 	DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap);
2119 	return rval;
2120 }
2121 
bnx2x_dcbnl_get_numtcs(struct net_device * netdev,int tcid,u8 * num)2122 static int bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
2123 {
2124 	struct bnx2x *bp = netdev_priv(netdev);
2125 	u8 rval = 0;
2126 
2127 	DP(BNX2X_MSG_DCB, "tcid %d\n", tcid);
2128 
2129 	if (bp->dcb_state) {
2130 		switch (tcid) {
2131 		case DCB_NUMTCS_ATTR_PG:
2132 			*num = CHIP_IS_E3B0(bp) ? DCBX_COS_MAX_NUM_E3B0 :
2133 						  DCBX_COS_MAX_NUM_E2;
2134 			break;
2135 		case DCB_NUMTCS_ATTR_PFC:
2136 			*num = CHIP_IS_E3B0(bp) ? DCBX_COS_MAX_NUM_E3B0 :
2137 						  DCBX_COS_MAX_NUM_E2;
2138 			break;
2139 		default:
2140 			BNX2X_ERR("Non valid TC-ID\n");
2141 			rval = -EINVAL;
2142 			break;
2143 		}
2144 	} else {
2145 		DP(BNX2X_MSG_DCB, "DCB disabled\n");
2146 		rval = -EINVAL;
2147 	}
2148 
2149 	return rval;
2150 }
2151 
bnx2x_dcbnl_set_numtcs(struct net_device * netdev,int tcid,u8 num)2152 static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
2153 {
2154 	struct bnx2x *bp = netdev_priv(netdev);
2155 	DP(BNX2X_MSG_DCB, "num tcs = %d; Not supported\n", num);
2156 	return -EINVAL;
2157 }
2158 
bnx2x_dcbnl_get_pfc_state(struct net_device * netdev)2159 static u8  bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
2160 {
2161 	struct bnx2x *bp = netdev_priv(netdev);
2162 	DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
2163 
2164 	if (!bp->dcb_state)
2165 		return 0;
2166 
2167 	return bp->dcbx_local_feat.pfc.enabled;
2168 }
2169 
bnx2x_dcbnl_set_pfc_state(struct net_device * netdev,u8 state)2170 static void bnx2x_dcbnl_set_pfc_state(struct net_device *netdev, u8 state)
2171 {
2172 	struct bnx2x *bp = netdev_priv(netdev);
2173 	DP(BNX2X_MSG_DCB, "state = %s\n", state ? "on" : "off");
2174 
2175 	if (!bnx2x_dcbnl_set_valid(bp))
2176 		return;
2177 
2178 	bp->dcbx_config_params.admin_pfc_tx_enable =
2179 	bp->dcbx_config_params.admin_pfc_enable = (state ? 1 : 0);
2180 }
2181 
bnx2x_admin_app_set_ent(struct bnx2x_admin_priority_app_table * app_ent,u8 idtype,u16 idval,u8 up)2182 static void bnx2x_admin_app_set_ent(
2183 	struct bnx2x_admin_priority_app_table *app_ent,
2184 	u8 idtype, u16 idval, u8 up)
2185 {
2186 	app_ent->valid = 1;
2187 
2188 	switch (idtype) {
2189 	case DCB_APP_IDTYPE_ETHTYPE:
2190 		app_ent->traffic_type = TRAFFIC_TYPE_ETH;
2191 		break;
2192 	case DCB_APP_IDTYPE_PORTNUM:
2193 		app_ent->traffic_type = TRAFFIC_TYPE_PORT;
2194 		break;
2195 	default:
2196 		break; /* never gets here */
2197 	}
2198 	app_ent->app_id = idval;
2199 	app_ent->priority = up;
2200 }
2201 
bnx2x_admin_app_is_equal(struct bnx2x_admin_priority_app_table * app_ent,u8 idtype,u16 idval)2202 static bool bnx2x_admin_app_is_equal(
2203 	struct bnx2x_admin_priority_app_table *app_ent,
2204 	u8 idtype, u16 idval)
2205 {
2206 	if (!app_ent->valid)
2207 		return false;
2208 
2209 	switch (idtype) {
2210 	case DCB_APP_IDTYPE_ETHTYPE:
2211 		if (app_ent->traffic_type != TRAFFIC_TYPE_ETH)
2212 			return false;
2213 		break;
2214 	case DCB_APP_IDTYPE_PORTNUM:
2215 		if (app_ent->traffic_type != TRAFFIC_TYPE_PORT)
2216 			return false;
2217 		break;
2218 	default:
2219 		return false;
2220 	}
2221 	if (app_ent->app_id != idval)
2222 		return false;
2223 
2224 	return true;
2225 }
2226 
bnx2x_set_admin_app_up(struct bnx2x * bp,u8 idtype,u16 idval,u8 up)2227 static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up)
2228 {
2229 	int i, ff;
2230 
2231 	/* iterate over the app entries looking for idtype and idval */
2232 	for (i = 0, ff = -1; i < DCBX_CONFIG_MAX_APP_PROTOCOL; i++) {
2233 		struct bnx2x_admin_priority_app_table *app_ent =
2234 			&bp->dcbx_config_params.admin_priority_app_table[i];
2235 		if (bnx2x_admin_app_is_equal(app_ent, idtype, idval))
2236 			break;
2237 
2238 		if (ff < 0 && !app_ent->valid)
2239 			ff = i;
2240 	}
2241 	if (i < DCBX_CONFIG_MAX_APP_PROTOCOL)
2242 		/* if found overwrite up */
2243 		bp->dcbx_config_params.
2244 			admin_priority_app_table[i].priority = up;
2245 	else if (ff >= 0)
2246 		/* not found use first-free */
2247 		bnx2x_admin_app_set_ent(
2248 			&bp->dcbx_config_params.admin_priority_app_table[ff],
2249 			idtype, idval, up);
2250 	else {
2251 		/* app table is full */
2252 		BNX2X_ERR("Application table is too large\n");
2253 		return -EBUSY;
2254 	}
2255 
2256 	/* up configured, if not 0 make sure feature is enabled */
2257 	if (up)
2258 		bp->dcbx_config_params.admin_application_priority_tx_enable = 1;
2259 
2260 	return 0;
2261 }
2262 
bnx2x_dcbnl_set_app_up(struct net_device * netdev,u8 idtype,u16 idval,u8 up)2263 static u8 bnx2x_dcbnl_set_app_up(struct net_device *netdev, u8 idtype,
2264 				 u16 idval, u8 up)
2265 {
2266 	struct bnx2x *bp = netdev_priv(netdev);
2267 
2268 	DP(BNX2X_MSG_DCB, "app_type %d, app_id %x, prio bitmap %d\n",
2269 	   idtype, idval, up);
2270 
2271 	if (!bnx2x_dcbnl_set_valid(bp)) {
2272 		DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
2273 		return -EINVAL;
2274 	}
2275 
2276 	/* verify idtype */
2277 	switch (idtype) {
2278 	case DCB_APP_IDTYPE_ETHTYPE:
2279 	case DCB_APP_IDTYPE_PORTNUM:
2280 		break;
2281 	default:
2282 		DP(BNX2X_MSG_DCB, "Wrong ID type\n");
2283 		return -EINVAL;
2284 	}
2285 	return bnx2x_set_admin_app_up(bp, idtype, idval, up);
2286 }
2287 
bnx2x_dcbnl_get_dcbx(struct net_device * netdev)2288 static u8 bnx2x_dcbnl_get_dcbx(struct net_device *netdev)
2289 {
2290 	struct bnx2x *bp = netdev_priv(netdev);
2291 	u8 state;
2292 
2293 	state = DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE;
2294 
2295 	if (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_OFF)
2296 		state |= DCB_CAP_DCBX_STATIC;
2297 
2298 	return state;
2299 }
2300 
bnx2x_dcbnl_set_dcbx(struct net_device * netdev,u8 state)2301 static u8 bnx2x_dcbnl_set_dcbx(struct net_device *netdev, u8 state)
2302 {
2303 	struct bnx2x *bp = netdev_priv(netdev);
2304 	DP(BNX2X_MSG_DCB, "state = %02x\n", state);
2305 
2306 	/* set dcbx mode */
2307 
2308 	if ((state & BNX2X_DCBX_CAPS) != state) {
2309 		BNX2X_ERR("Requested DCBX mode %x is beyond advertised capabilities\n",
2310 			  state);
2311 		return 1;
2312 	}
2313 
2314 	if (bp->dcb_state != BNX2X_DCB_STATE_ON) {
2315 		BNX2X_ERR("DCB turned off, DCBX configuration is invalid\n");
2316 		return 1;
2317 	}
2318 
2319 	if (state & DCB_CAP_DCBX_STATIC)
2320 		bp->dcbx_enabled = BNX2X_DCBX_ENABLED_ON_NEG_OFF;
2321 	else
2322 		bp->dcbx_enabled = BNX2X_DCBX_ENABLED_ON_NEG_ON;
2323 
2324 	bp->dcbx_mode_uset = true;
2325 	return 0;
2326 }
2327 
bnx2x_dcbnl_get_featcfg(struct net_device * netdev,int featid,u8 * flags)2328 static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
2329 				  u8 *flags)
2330 {
2331 	struct bnx2x *bp = netdev_priv(netdev);
2332 	u8 rval = 0;
2333 
2334 	DP(BNX2X_MSG_DCB, "featid %d\n", featid);
2335 
2336 	if (bp->dcb_state) {
2337 		*flags = 0;
2338 		switch (featid) {
2339 		case DCB_FEATCFG_ATTR_PG:
2340 			if (bp->dcbx_local_feat.ets.enabled)
2341 				*flags |= DCB_FEATCFG_ENABLE;
2342 			if (bp->dcbx_error & DCBX_LOCAL_ETS_ERROR)
2343 				*flags |= DCB_FEATCFG_ERROR;
2344 			break;
2345 		case DCB_FEATCFG_ATTR_PFC:
2346 			if (bp->dcbx_local_feat.pfc.enabled)
2347 				*flags |= DCB_FEATCFG_ENABLE;
2348 			if (bp->dcbx_error & (DCBX_LOCAL_PFC_ERROR |
2349 			    DCBX_LOCAL_PFC_MISMATCH))
2350 				*flags |= DCB_FEATCFG_ERROR;
2351 			break;
2352 		case DCB_FEATCFG_ATTR_APP:
2353 			if (bp->dcbx_local_feat.app.enabled)
2354 				*flags |= DCB_FEATCFG_ENABLE;
2355 			if (bp->dcbx_error & (DCBX_LOCAL_APP_ERROR |
2356 			    DCBX_LOCAL_APP_MISMATCH))
2357 				*flags |= DCB_FEATCFG_ERROR;
2358 			break;
2359 		default:
2360 			BNX2X_ERR("Non valid featrue-ID\n");
2361 			rval = -EINVAL;
2362 			break;
2363 		}
2364 	} else {
2365 		DP(BNX2X_MSG_DCB, "DCB disabled\n");
2366 		rval = -EINVAL;
2367 	}
2368 
2369 	return rval;
2370 }
2371 
bnx2x_dcbnl_set_featcfg(struct net_device * netdev,int featid,u8 flags)2372 static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
2373 				  u8 flags)
2374 {
2375 	struct bnx2x *bp = netdev_priv(netdev);
2376 	u8 rval = 0;
2377 
2378 	DP(BNX2X_MSG_DCB, "featid = %d flags = %02x\n", featid, flags);
2379 
2380 	/* ignore the 'advertise' flag */
2381 	if (bnx2x_dcbnl_set_valid(bp)) {
2382 		switch (featid) {
2383 		case DCB_FEATCFG_ATTR_PG:
2384 			bp->dcbx_config_params.admin_ets_enable =
2385 				flags & DCB_FEATCFG_ENABLE ? 1 : 0;
2386 			bp->dcbx_config_params.admin_ets_willing =
2387 				flags & DCB_FEATCFG_WILLING ? 1 : 0;
2388 			break;
2389 		case DCB_FEATCFG_ATTR_PFC:
2390 			bp->dcbx_config_params.admin_pfc_enable =
2391 				flags & DCB_FEATCFG_ENABLE ? 1 : 0;
2392 			bp->dcbx_config_params.admin_pfc_willing =
2393 				flags & DCB_FEATCFG_WILLING ? 1 : 0;
2394 			break;
2395 		case DCB_FEATCFG_ATTR_APP:
2396 			/* ignore enable, always enabled */
2397 			bp->dcbx_config_params.admin_app_priority_willing =
2398 				flags & DCB_FEATCFG_WILLING ? 1 : 0;
2399 			break;
2400 		default:
2401 			BNX2X_ERR("Non valid featrue-ID\n");
2402 			rval = -EINVAL;
2403 			break;
2404 		}
2405 	} else {
2406 		DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
2407 		rval = -EINVAL;
2408 	}
2409 
2410 	return rval;
2411 }
2412 
bnx2x_peer_appinfo(struct net_device * netdev,struct dcb_peer_app_info * info,u16 * app_count)2413 static int bnx2x_peer_appinfo(struct net_device *netdev,
2414 			      struct dcb_peer_app_info *info, u16* app_count)
2415 {
2416 	int i;
2417 	struct bnx2x *bp = netdev_priv(netdev);
2418 
2419 	DP(BNX2X_MSG_DCB, "APP-INFO\n");
2420 
2421 	info->willing = (bp->dcbx_remote_flags & DCBX_APP_REM_WILLING) ?: 0;
2422 	info->error = (bp->dcbx_remote_flags & DCBX_APP_RX_ERROR) ?: 0;
2423 	*app_count = 0;
2424 
2425 	for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++)
2426 		if (bp->dcbx_remote_feat.app.app_pri_tbl[i].appBitfield &
2427 		    DCBX_APP_ENTRY_VALID)
2428 			(*app_count)++;
2429 	return 0;
2430 }
2431 
bnx2x_peer_apptable(struct net_device * netdev,struct dcb_app * table)2432 static int bnx2x_peer_apptable(struct net_device *netdev,
2433 			       struct dcb_app *table)
2434 {
2435 	int i, j;
2436 	struct bnx2x *bp = netdev_priv(netdev);
2437 
2438 	DP(BNX2X_MSG_DCB, "APP-TABLE\n");
2439 
2440 	for (i = 0, j = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
2441 		struct dcbx_app_priority_entry *ent =
2442 			&bp->dcbx_remote_feat.app.app_pri_tbl[i];
2443 
2444 		if (ent->appBitfield & DCBX_APP_ENTRY_VALID) {
2445 			table[j].selector = bnx2x_dcbx_dcbnl_app_idtype(ent);
2446 			table[j].priority = bnx2x_dcbx_dcbnl_app_up(ent);
2447 			table[j++].protocol = ent->app_id;
2448 		}
2449 	}
2450 	return 0;
2451 }
2452 
bnx2x_cee_peer_getpg(struct net_device * netdev,struct cee_pg * pg)2453 static int bnx2x_cee_peer_getpg(struct net_device *netdev, struct cee_pg *pg)
2454 {
2455 	int i;
2456 	struct bnx2x *bp = netdev_priv(netdev);
2457 
2458 	pg->willing = (bp->dcbx_remote_flags & DCBX_ETS_REM_WILLING) ?: 0;
2459 
2460 	for (i = 0; i < CEE_DCBX_MAX_PGS; i++) {
2461 		pg->pg_bw[i] =
2462 			DCBX_PG_BW_GET(bp->dcbx_remote_feat.ets.pg_bw_tbl, i);
2463 		pg->prio_pg[i] =
2464 			DCBX_PRI_PG_GET(bp->dcbx_remote_feat.ets.pri_pg_tbl, i);
2465 	}
2466 	return 0;
2467 }
2468 
bnx2x_cee_peer_getpfc(struct net_device * netdev,struct cee_pfc * pfc)2469 static int bnx2x_cee_peer_getpfc(struct net_device *netdev,
2470 				 struct cee_pfc *pfc)
2471 {
2472 	struct bnx2x *bp = netdev_priv(netdev);
2473 	pfc->tcs_supported = bp->dcbx_remote_feat.pfc.pfc_caps;
2474 	pfc->pfc_en = bp->dcbx_remote_feat.pfc.pri_en_bitmap;
2475 	return 0;
2476 }
2477 
2478 const struct dcbnl_rtnl_ops bnx2x_dcbnl_ops = {
2479 	.getstate		= bnx2x_dcbnl_get_state,
2480 	.setstate		= bnx2x_dcbnl_set_state,
2481 	.getpermhwaddr		= bnx2x_dcbnl_get_perm_hw_addr,
2482 	.setpgtccfgtx		= bnx2x_dcbnl_set_pg_tccfg_tx,
2483 	.setpgbwgcfgtx		= bnx2x_dcbnl_set_pg_bwgcfg_tx,
2484 	.setpgtccfgrx		= bnx2x_dcbnl_set_pg_tccfg_rx,
2485 	.setpgbwgcfgrx		= bnx2x_dcbnl_set_pg_bwgcfg_rx,
2486 	.getpgtccfgtx		= bnx2x_dcbnl_get_pg_tccfg_tx,
2487 	.getpgbwgcfgtx		= bnx2x_dcbnl_get_pg_bwgcfg_tx,
2488 	.getpgtccfgrx		= bnx2x_dcbnl_get_pg_tccfg_rx,
2489 	.getpgbwgcfgrx		= bnx2x_dcbnl_get_pg_bwgcfg_rx,
2490 	.setpfccfg		= bnx2x_dcbnl_set_pfc_cfg,
2491 	.getpfccfg		= bnx2x_dcbnl_get_pfc_cfg,
2492 	.setall			= bnx2x_dcbnl_set_all,
2493 	.getcap			= bnx2x_dcbnl_get_cap,
2494 	.getnumtcs		= bnx2x_dcbnl_get_numtcs,
2495 	.setnumtcs		= bnx2x_dcbnl_set_numtcs,
2496 	.getpfcstate		= bnx2x_dcbnl_get_pfc_state,
2497 	.setpfcstate		= bnx2x_dcbnl_set_pfc_state,
2498 	.setapp			= bnx2x_dcbnl_set_app_up,
2499 	.getdcbx		= bnx2x_dcbnl_get_dcbx,
2500 	.setdcbx		= bnx2x_dcbnl_set_dcbx,
2501 	.getfeatcfg		= bnx2x_dcbnl_get_featcfg,
2502 	.setfeatcfg		= bnx2x_dcbnl_set_featcfg,
2503 	.peer_getappinfo	= bnx2x_peer_appinfo,
2504 	.peer_getapptable	= bnx2x_peer_apptable,
2505 	.cee_peer_getpg		= bnx2x_cee_peer_getpg,
2506 	.cee_peer_getpfc	= bnx2x_cee_peer_getpfc,
2507 };
2508 
2509 #endif /* BCM_DCBNL */
2510