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