1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016 - 2018 Cavium Inc.
9 #include "ecore_sp_commands.h"
10 #include "ecore_dcbx.h"
11 #include "ecore_cxt.h"
12 #include "ecore_gtt_reg_addr.h"
13 #include "ecore_iro.h"
14 #include "ecore_iov_api.h"
16 #define ECORE_DCBX_MAX_MIB_READ_TRY (100)
17 #define ECORE_ETH_TYPE_DEFAULT (0)
19 #define ECORE_DCBX_INVALID_PRIORITY 0xFF
21 /* Get Traffic Class from priority traffic class table, 4 bits represent
22 * the traffic class corresponding to the priority.
24 #define ECORE_DCBX_PRIO2TC(prio_tc_tbl, prio) \
25 ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
27 static bool ecore_dcbx_app_ethtype(u32 app_info_bitmap)
29 return !!(GET_MFW_FIELD(app_info_bitmap, DCBX_APP_SF) ==
33 static bool ecore_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
35 u8 mfw_val = GET_MFW_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
38 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
39 return ecore_dcbx_app_ethtype(app_info_bitmap);
41 return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
44 static bool ecore_dcbx_app_port(u32 app_info_bitmap)
46 return !!(GET_MFW_FIELD(app_info_bitmap, DCBX_APP_SF) ==
50 static bool ecore_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
52 u8 mfw_val = GET_MFW_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
55 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
56 return ecore_dcbx_app_port(app_info_bitmap);
58 return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
61 static bool ecore_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
66 ethtype = ecore_dcbx_ieee_app_ethtype(app_info_bitmap);
68 ethtype = ecore_dcbx_app_ethtype(app_info_bitmap);
70 return !!(ethtype && (proto_id == ECORE_ETH_TYPE_DEFAULT));
73 static bool ecore_dcbx_iwarp_tlv(struct ecore_hwfn *p_hwfn, u32 app_info_bitmap,
74 u16 proto_id, bool ieee)
78 if (!p_hwfn->p_dcbx_info->iwarp_port)
82 port = ecore_dcbx_ieee_app_port(app_info_bitmap,
83 DCBX_APP_SF_IEEE_TCP_PORT);
85 port = ecore_dcbx_app_port(app_info_bitmap);
87 return !!(port && (proto_id == p_hwfn->p_dcbx_info->iwarp_port));
91 ecore_dcbx_dp_protocol(struct ecore_hwfn *p_hwfn,
92 struct ecore_dcbx_results *p_data)
94 enum dcbx_protocol_type id;
97 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "DCBX negotiated: %d\n",
98 p_data->dcbx_enabled);
100 for (i = 0; i < OSAL_ARRAY_SIZE(ecore_dcbx_app_update); i++) {
101 id = ecore_dcbx_app_update[i].id;
103 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
104 "%s info: update %d, enable %d, prio %d, tc %d,"
105 " num_active_tc %d dscp_enable = %d dscp_val = %d\n",
106 ecore_dcbx_app_update[i].name,
107 p_data->arr[id].update,
108 p_data->arr[id].enable, p_data->arr[id].priority,
109 p_data->arr[id].tc, p_hwfn->hw_info.num_active_tc,
110 p_data->arr[id].dscp_enable,
111 p_data->arr[id].dscp_val);
115 u8 ecore_dcbx_get_dscp_value(struct ecore_hwfn *p_hwfn, u8 pri)
117 struct ecore_dcbx_dscp_params *dscp = &p_hwfn->p_dcbx_info->get.dscp;
121 return ECORE_DCBX_DSCP_DISABLED;
123 for (i = 0; i < ECORE_DCBX_DSCP_SIZE; i++)
124 if (pri == dscp->dscp_pri_map[i])
127 return ECORE_DCBX_DSCP_DISABLED;
131 ecore_dcbx_set_params(struct ecore_dcbx_results *p_data,
132 struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
133 bool enable, u8 prio, u8 tc,
134 enum dcbx_protocol_type type,
135 enum ecore_pci_personality personality)
137 /* PF update ramrod data */
138 p_data->arr[type].enable = enable;
139 p_data->arr[type].priority = prio;
140 p_data->arr[type].tc = tc;
141 p_data->arr[type].dscp_val = ecore_dcbx_get_dscp_value(p_hwfn, prio);
142 if (p_data->arr[type].dscp_val == ECORE_DCBX_DSCP_DISABLED) {
143 p_data->arr[type].dscp_enable = false;
144 p_data->arr[type].dscp_val = 0;
146 p_data->arr[type].dscp_enable = true;
148 p_data->arr[type].update = UPDATE_DCB_DSCP;
150 /* Do not add valn tag 0 when DCB is enabled and port is in UFP mode */
151 if (OSAL_TEST_BIT(ECORE_MF_UFP_SPECIFIC, &p_hwfn->p_dev->mf_bits))
152 p_data->arr[type].dont_add_vlan0 = true;
155 if (p_hwfn->hw_info.personality == personality)
156 p_hwfn->hw_info.offload_tc = tc;
158 /* Configure dcbx vlan priority in doorbell block for roce EDPM */
159 if (OSAL_TEST_BIT(ECORE_MF_UFP_SPECIFIC, &p_hwfn->p_dev->mf_bits) &&
160 (type == DCBX_PROTOCOL_ROCE)) {
161 ecore_wr(p_hwfn, p_ptt, DORQ_REG_TAG1_OVRD_MODE, 1);
162 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_PCP_BB_K2, prio << 1);
166 /* Update app protocol data and hw_info fields with the TLV info */
168 ecore_dcbx_update_app_info(struct ecore_dcbx_results *p_data,
169 struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
170 bool enable, u8 prio, u8 tc,
171 enum dcbx_protocol_type type)
173 enum ecore_pci_personality personality;
174 enum dcbx_protocol_type id;
177 for (i = 0; i < OSAL_ARRAY_SIZE(ecore_dcbx_app_update); i++) {
178 id = ecore_dcbx_app_update[i].id;
183 personality = ecore_dcbx_app_update[i].personality;
185 ecore_dcbx_set_params(p_data, p_hwfn, p_ptt, enable,
186 prio, tc, type, personality);
190 static enum _ecore_status_t
191 ecore_dcbx_get_app_priority(u8 pri_bitmap, u8 *priority)
193 u32 pri_mask, pri = ECORE_MAX_PFC_PRIORITIES;
194 u32 index = ECORE_MAX_PFC_PRIORITIES - 1;
195 enum _ecore_status_t rc = ECORE_SUCCESS;
197 /* Bitmap 1 corresponds to priority 0, return priority 0 */
198 if (pri_bitmap == 1) {
203 /* Choose the highest priority */
204 while ((pri == ECORE_MAX_PFC_PRIORITIES) && index) {
205 pri_mask = 1 << index;
206 if (pri_bitmap & pri_mask)
211 if (pri < ECORE_MAX_PFC_PRIORITIES)
220 ecore_dcbx_get_app_protocol_type(struct ecore_hwfn *p_hwfn,
221 u32 app_prio_bitmap, u16 id,
222 enum dcbx_protocol_type *type, bool ieee)
224 if (ecore_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
225 *type = DCBX_PROTOCOL_ETH;
227 *type = DCBX_MAX_PROTOCOL_TYPE;
228 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
229 "No action required, App TLV entry = 0x%x\n",
237 /* Parse app TLV's to update TC information in hw_info structure for
238 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
240 static enum _ecore_status_t
241 ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
242 struct ecore_dcbx_results *p_data,
243 struct dcbx_app_priority_entry *p_tbl, u32 pri_tc_tbl,
244 int count, u8 dcbx_version)
246 enum dcbx_protocol_type type;
247 bool enable, ieee, eth_tlv;
251 enum _ecore_status_t rc = ECORE_SUCCESS;
254 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
255 "Num APP entries = %d pri_tc_tbl = 0x%x dcbx_version = %u\n",
256 count, pri_tc_tbl, dcbx_version);
258 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
261 for (i = 0; i < count; i++) {
262 protocol_id = GET_MFW_FIELD(p_tbl[i].entry,
263 DCBX_APP_PROTOCOL_ID);
264 priority_map = GET_MFW_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
265 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Id = 0x%x pri_map = %u\n",
266 protocol_id, priority_map);
267 rc = ecore_dcbx_get_app_priority(priority_map, &priority);
268 if (rc == ECORE_INVAL) {
269 DP_ERR(p_hwfn, "Invalid priority\n");
273 tc = ECORE_DCBX_PRIO2TC(pri_tc_tbl, priority);
274 if (ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
277 /* ETH always have the enable bit reset, as it gets
278 * vlan information per packet. For other protocols,
279 * should be set according to the dcbx_enabled
280 * indication, but we only got here if there was an
281 * app tlv for the protocol, so dcbx must be enabled.
283 if (type == DCBX_PROTOCOL_ETH) {
290 ecore_dcbx_update_app_info(p_data, p_hwfn, p_ptt,
291 enable, priority, tc, type);
295 /* If Eth TLV is not detected, use UFP TC as default TC */
296 if (OSAL_TEST_BIT(ECORE_MF_UFP_SPECIFIC,
297 &p_hwfn->p_dev->mf_bits) && !eth_tlv)
298 p_data->arr[DCBX_PROTOCOL_ETH].tc = p_hwfn->ufp_info.tc;
300 /* Update ramrod protocol data and hw_info fields
301 * with default info when corresponding APP TLV's are not detected.
302 * The enabled field has a different logic for ethernet as only for
303 * ethernet dcb should disabled by default, as the information arrives
304 * from the OS (unless an explicit app tlv was present).
306 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
307 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
308 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
309 if (p_data->arr[type].update)
312 /* if no app tlv was present, don't override in FW */
313 ecore_dcbx_update_app_info(p_data, p_hwfn, p_ptt, false,
317 return ECORE_SUCCESS;
320 /* Parse app TLV's to update TC information in hw_info structure for
321 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
323 static enum _ecore_status_t
324 ecore_dcbx_process_mib_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
326 struct dcbx_app_priority_feature *p_app;
327 struct dcbx_app_priority_entry *p_tbl;
328 struct ecore_dcbx_results data;
329 struct dcbx_ets_feature *p_ets;
330 struct ecore_hw_info *p_info;
331 u32 pri_tc_tbl, flags;
334 enum _ecore_status_t rc = ECORE_SUCCESS;
336 flags = p_hwfn->p_dcbx_info->operational.flags;
337 dcbx_version = GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION);
339 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
340 p_tbl = p_app->app_pri_tbl;
342 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
343 pri_tc_tbl = p_ets->pri_tc_tbl[0];
345 p_info = &p_hwfn->hw_info;
346 num_entries = GET_MFW_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
348 OSAL_MEMSET(&data, 0, sizeof(struct ecore_dcbx_results));
349 rc = ecore_dcbx_process_tlv(p_hwfn, p_ptt, &data, p_tbl, pri_tc_tbl,
350 num_entries, dcbx_version);
351 if (rc != ECORE_SUCCESS)
354 p_info->num_active_tc = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
355 p_hwfn->qm_info.ooo_tc = GET_MFW_FIELD(p_ets->flags, DCBX_OOO_TC);
356 data.pf_id = p_hwfn->rel_pf_id;
357 data.dcbx_enabled = !!dcbx_version;
359 ecore_dcbx_dp_protocol(p_hwfn, &data);
361 OSAL_MEMCPY(&p_hwfn->p_dcbx_info->results, &data,
362 sizeof(struct ecore_dcbx_results));
364 return ECORE_SUCCESS;
367 static enum _ecore_status_t
368 ecore_dcbx_copy_mib(struct ecore_hwfn *p_hwfn,
369 struct ecore_ptt *p_ptt,
370 struct ecore_dcbx_mib_meta_data *p_data,
371 enum ecore_mib_read_type type)
373 u32 prefix_seq_num, suffix_seq_num;
375 enum _ecore_status_t rc = ECORE_SUCCESS;
377 /* The data is considered to be valid only if both sequence numbers are
381 if (type == ECORE_DCBX_REMOTE_LLDP_MIB) {
382 ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
383 p_data->addr, p_data->size);
384 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
385 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
386 } else if (type == ECORE_DCBX_LLDP_TLVS) {
387 ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_tlvs,
388 p_data->addr, p_data->size);
389 prefix_seq_num = p_data->lldp_tlvs->prefix_seq_num;
390 suffix_seq_num = p_data->lldp_tlvs->suffix_seq_num;
393 ecore_memcpy_from(p_hwfn, p_ptt, p_data->mib,
394 p_data->addr, p_data->size);
395 prefix_seq_num = p_data->mib->prefix_seq_num;
396 suffix_seq_num = p_data->mib->suffix_seq_num;
400 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
401 "mib type = %d, try count = %d prefix seq num ="
402 " %d suffix seq num = %d\n",
403 type, read_count, prefix_seq_num, suffix_seq_num);
404 } while ((prefix_seq_num != suffix_seq_num) &&
405 (read_count < ECORE_DCBX_MAX_MIB_READ_TRY));
407 if (read_count >= ECORE_DCBX_MAX_MIB_READ_TRY) {
409 "MIB read err, mib type = %d, try count ="
410 " %d prefix seq num = %d suffix seq num = %d\n",
411 type, read_count, prefix_seq_num, suffix_seq_num);
419 ecore_dcbx_get_priority_info(struct ecore_hwfn *p_hwfn,
420 struct ecore_dcbx_app_prio *p_prio,
421 struct ecore_dcbx_results *p_results)
425 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
426 p_results->arr[DCBX_PROTOCOL_ETH].enable)
427 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
429 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
430 "Priorities: eth %d\n",
435 ecore_dcbx_get_app_data(struct ecore_hwfn *p_hwfn,
436 struct dcbx_app_priority_feature *p_app,
437 struct dcbx_app_priority_entry *p_tbl,
438 struct ecore_dcbx_params *p_params, bool ieee)
440 struct ecore_app_entry *entry;
444 p_params->app_willing = GET_MFW_FIELD(p_app->flags, DCBX_APP_WILLING);
445 p_params->app_valid = GET_MFW_FIELD(p_app->flags, DCBX_APP_ENABLED);
446 p_params->app_error = GET_MFW_FIELD(p_app->flags, DCBX_APP_ERROR);
447 p_params->num_app_entries = GET_MFW_FIELD(p_app->flags,
448 DCBX_APP_NUM_ENTRIES);
449 for (i = 0; i < p_params->num_app_entries; i++) {
450 entry = &p_params->app_entry[i];
455 sf_ieee = GET_MFW_FIELD(p_tbl[i].entry,
458 case DCBX_APP_SF_IEEE_RESERVED:
460 val = GET_MFW_FIELD(p_tbl[i].entry,
462 entry->sf_ieee = val ?
463 ECORE_DCBX_SF_IEEE_TCP_UDP_PORT :
464 ECORE_DCBX_SF_IEEE_ETHTYPE;
466 case DCBX_APP_SF_IEEE_ETHTYPE:
467 entry->sf_ieee = ECORE_DCBX_SF_IEEE_ETHTYPE;
469 case DCBX_APP_SF_IEEE_TCP_PORT:
470 entry->sf_ieee = ECORE_DCBX_SF_IEEE_TCP_PORT;
472 case DCBX_APP_SF_IEEE_UDP_PORT:
473 entry->sf_ieee = ECORE_DCBX_SF_IEEE_UDP_PORT;
475 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
477 ECORE_DCBX_SF_IEEE_TCP_UDP_PORT;
481 entry->ethtype = !(GET_MFW_FIELD(p_tbl[i].entry,
485 pri_map = GET_MFW_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
486 ecore_dcbx_get_app_priority(pri_map, &entry->prio);
487 entry->proto_id = GET_MFW_FIELD(p_tbl[i].entry,
488 DCBX_APP_PROTOCOL_ID);
489 ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
491 &entry->proto_type, ieee);
494 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
495 "APP params: willing %d, valid %d error = %d\n",
496 p_params->app_willing, p_params->app_valid,
497 p_params->app_error);
501 ecore_dcbx_get_pfc_data(struct ecore_hwfn *p_hwfn,
502 u32 pfc, struct ecore_dcbx_params *p_params)
506 p_params->pfc.willing = GET_MFW_FIELD(pfc, DCBX_PFC_WILLING);
507 p_params->pfc.max_tc = GET_MFW_FIELD(pfc, DCBX_PFC_CAPS);
508 p_params->pfc.enabled = GET_MFW_FIELD(pfc, DCBX_PFC_ENABLED);
509 pfc_map = GET_MFW_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
510 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
511 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
512 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
513 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
514 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
515 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
516 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
517 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
519 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
520 "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
521 p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
522 p_params->pfc.enabled);
526 ecore_dcbx_get_ets_data(struct ecore_hwfn *p_hwfn,
527 struct dcbx_ets_feature *p_ets,
528 struct ecore_dcbx_params *p_params)
530 u32 bw_map[2], tsa_map[2], pri_map;
533 p_params->ets_willing = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_WILLING);
534 p_params->ets_enabled = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_ENABLED);
535 p_params->ets_cbs = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_CBS);
536 p_params->max_ets_tc = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
537 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
538 "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
539 p_params->ets_willing, p_params->ets_enabled,
540 p_params->ets_cbs, p_ets->pri_tc_tbl[0],
541 p_params->max_ets_tc);
543 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
544 * encoded in a type u32 array of size 2.
546 bw_map[0] = OSAL_BE32_TO_CPU(p_ets->tc_bw_tbl[0]);
547 bw_map[1] = OSAL_BE32_TO_CPU(p_ets->tc_bw_tbl[1]);
548 tsa_map[0] = OSAL_BE32_TO_CPU(p_ets->tc_tsa_tbl[0]);
549 tsa_map[1] = OSAL_BE32_TO_CPU(p_ets->tc_tsa_tbl[1]);
550 pri_map = p_ets->pri_tc_tbl[0];
551 for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++) {
552 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
553 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
554 p_params->ets_pri_tc_tbl[i] = ECORE_DCBX_PRIO2TC(pri_map, i);
555 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
556 "elem %d bw_tbl %x tsa_tbl %x\n",
557 i, p_params->ets_tc_bw_tbl[i],
558 p_params->ets_tc_tsa_tbl[i]);
563 ecore_dcbx_get_common_params(struct ecore_hwfn *p_hwfn,
564 struct dcbx_app_priority_feature *p_app,
565 struct dcbx_app_priority_entry *p_tbl,
566 struct dcbx_ets_feature *p_ets,
567 u32 pfc, struct ecore_dcbx_params *p_params,
570 ecore_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
571 ecore_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
572 ecore_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
576 ecore_dcbx_get_local_params(struct ecore_hwfn *p_hwfn,
577 struct ecore_dcbx_get *params)
579 struct dcbx_features *p_feat;
581 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
582 ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
583 p_feat->app.app_pri_tbl, &p_feat->ets,
584 p_feat->pfc, ¶ms->local.params, false);
585 params->local.valid = true;
589 ecore_dcbx_get_remote_params(struct ecore_hwfn *p_hwfn,
590 struct ecore_dcbx_get *params)
592 struct dcbx_features *p_feat;
594 p_feat = &p_hwfn->p_dcbx_info->remote.features;
595 ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
596 p_feat->app.app_pri_tbl, &p_feat->ets,
597 p_feat->pfc, ¶ms->remote.params,
599 params->remote.valid = true;
602 static void ecore_dcbx_get_dscp_params(struct ecore_hwfn *p_hwfn,
603 struct ecore_dcbx_get *params)
605 struct ecore_dcbx_dscp_params *p_dscp;
606 struct dcb_dscp_map *p_dscp_map;
610 p_dscp = ¶ms->dscp;
611 p_dscp_map = &p_hwfn->p_dcbx_info->dscp_map;
612 p_dscp->enabled = GET_MFW_FIELD(p_dscp_map->flags, DCB_DSCP_ENABLE);
614 /* MFW encodes 64 dscp entries into 8 element array of u32 entries,
615 * where each entry holds the 4bit priority map for 8 dscp entries.
617 for (i = 0, entry = 0; i < ECORE_DCBX_DSCP_SIZE / 8; i++) {
618 pri_map = OSAL_BE32_TO_CPU(p_dscp_map->dscp_pri_map[i]);
619 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "elem %d pri_map 0x%x\n",
621 for (j = 0; j < ECORE_DCBX_DSCP_SIZE / 8; j++, entry++)
622 p_dscp->dscp_pri_map[entry] = (u32)(pri_map >>
628 ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
629 struct ecore_dcbx_get *params)
631 struct ecore_dcbx_operational_params *p_operational;
632 struct ecore_dcbx_results *p_results;
633 struct dcbx_features *p_feat;
638 flags = p_hwfn->p_dcbx_info->operational.flags;
640 /* If DCBx version is non zero, then negotiation
641 * was successfuly performed
643 p_operational = ¶ms->operational;
644 enabled = !!(GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION) !=
645 DCBX_CONFIG_VERSION_DISABLED);
647 p_operational->enabled = enabled;
648 p_operational->valid = false;
649 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Dcbx is disabled\n");
653 p_feat = &p_hwfn->p_dcbx_info->operational.features;
654 p_results = &p_hwfn->p_dcbx_info->results;
656 val = !!(GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION) ==
657 DCBX_CONFIG_VERSION_IEEE);
658 p_operational->ieee = val;
660 val = !!(GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION) ==
661 DCBX_CONFIG_VERSION_CEE);
662 p_operational->cee = val;
664 val = !!(GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION) ==
665 DCBX_CONFIG_VERSION_STATIC);
666 p_operational->local = val;
668 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
669 "Version support: ieee %d, cee %d, static %d\n",
670 p_operational->ieee, p_operational->cee,
671 p_operational->local);
673 ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
674 p_feat->app.app_pri_tbl, &p_feat->ets,
675 p_feat->pfc, ¶ms->operational.params,
676 p_operational->ieee);
677 ecore_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio,
679 err = GET_MFW_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
680 p_operational->err = err;
681 p_operational->enabled = enabled;
682 p_operational->valid = true;
685 static void ecore_dcbx_get_local_lldp_params(struct ecore_hwfn *p_hwfn,
686 struct ecore_dcbx_get *params)
688 struct lldp_config_params_s *p_local;
690 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
692 OSAL_MEMCPY(params->lldp_local.local_chassis_id,
693 p_local->local_chassis_id,
694 sizeof(params->lldp_local.local_chassis_id));
695 OSAL_MEMCPY(params->lldp_local.local_port_id, p_local->local_port_id,
696 sizeof(params->lldp_local.local_port_id));
699 static void ecore_dcbx_get_remote_lldp_params(struct ecore_hwfn *p_hwfn,
700 struct ecore_dcbx_get *params)
702 struct lldp_status_params_s *p_remote;
704 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
706 OSAL_MEMCPY(params->lldp_remote.peer_chassis_id,
707 p_remote->peer_chassis_id,
708 sizeof(params->lldp_remote.peer_chassis_id));
709 OSAL_MEMCPY(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
710 sizeof(params->lldp_remote.peer_port_id));
713 static enum _ecore_status_t
714 ecore_dcbx_get_params(struct ecore_hwfn *p_hwfn,
715 struct ecore_dcbx_get *p_params,
716 enum ecore_mib_read_type type)
719 case ECORE_DCBX_REMOTE_MIB:
720 ecore_dcbx_get_remote_params(p_hwfn, p_params);
722 case ECORE_DCBX_LOCAL_MIB:
723 ecore_dcbx_get_local_params(p_hwfn, p_params);
725 case ECORE_DCBX_OPERATIONAL_MIB:
726 ecore_dcbx_get_operational_params(p_hwfn, p_params);
728 case ECORE_DCBX_REMOTE_LLDP_MIB:
729 ecore_dcbx_get_remote_lldp_params(p_hwfn, p_params);
731 case ECORE_DCBX_LOCAL_LLDP_MIB:
732 ecore_dcbx_get_local_lldp_params(p_hwfn, p_params);
735 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
739 return ECORE_SUCCESS;
742 static enum _ecore_status_t
743 ecore_dcbx_read_local_lldp_mib(struct ecore_hwfn *p_hwfn,
744 struct ecore_ptt *p_ptt)
746 struct ecore_dcbx_mib_meta_data data;
747 enum _ecore_status_t rc = ECORE_SUCCESS;
749 OSAL_MEM_ZERO(&data, sizeof(data));
750 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
752 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
753 data.size = sizeof(struct lldp_config_params_s);
754 ecore_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
759 static enum _ecore_status_t
760 ecore_dcbx_read_remote_lldp_mib(struct ecore_hwfn *p_hwfn,
761 struct ecore_ptt *p_ptt,
762 enum ecore_mib_read_type type)
764 struct ecore_dcbx_mib_meta_data data;
765 enum _ecore_status_t rc = ECORE_SUCCESS;
767 OSAL_MEM_ZERO(&data, sizeof(data));
768 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
770 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
771 data.size = sizeof(struct lldp_status_params_s);
772 rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
777 static enum _ecore_status_t
778 ecore_dcbx_read_operational_mib(struct ecore_hwfn *p_hwfn,
779 struct ecore_ptt *p_ptt,
780 enum ecore_mib_read_type type)
782 struct ecore_dcbx_mib_meta_data data;
783 enum _ecore_status_t rc = ECORE_SUCCESS;
785 OSAL_MEM_ZERO(&data, sizeof(data));
786 data.addr = p_hwfn->mcp_info->port_addr +
787 offsetof(struct public_port, operational_dcbx_mib);
788 data.mib = &p_hwfn->p_dcbx_info->operational;
789 data.size = sizeof(struct dcbx_mib);
790 rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
795 static enum _ecore_status_t
796 ecore_dcbx_read_remote_mib(struct ecore_hwfn *p_hwfn,
797 struct ecore_ptt *p_ptt,
798 enum ecore_mib_read_type type)
800 struct ecore_dcbx_mib_meta_data data;
801 enum _ecore_status_t rc = ECORE_SUCCESS;
803 OSAL_MEM_ZERO(&data, sizeof(data));
804 data.addr = p_hwfn->mcp_info->port_addr +
805 offsetof(struct public_port, remote_dcbx_mib);
806 data.mib = &p_hwfn->p_dcbx_info->remote;
807 data.size = sizeof(struct dcbx_mib);
808 rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
813 static enum _ecore_status_t
814 ecore_dcbx_read_local_mib(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
816 struct ecore_dcbx_mib_meta_data data;
817 enum _ecore_status_t rc = ECORE_SUCCESS;
819 OSAL_MEM_ZERO(&data, sizeof(data));
820 data.addr = p_hwfn->mcp_info->port_addr +
821 offsetof(struct public_port, local_admin_dcbx_mib);
822 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
823 data.size = sizeof(struct dcbx_local_params);
824 ecore_memcpy_from(p_hwfn, p_ptt, data.local_admin,
825 data.addr, data.size);
831 ecore_dcbx_read_dscp_mib(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
833 struct ecore_dcbx_mib_meta_data data;
835 data.addr = p_hwfn->mcp_info->port_addr +
836 offsetof(struct public_port, dcb_dscp_map);
837 data.dscp_map = &p_hwfn->p_dcbx_info->dscp_map;
838 data.size = sizeof(struct dcb_dscp_map);
839 ecore_memcpy_from(p_hwfn, p_ptt, data.dscp_map, data.addr, data.size);
842 static enum _ecore_status_t ecore_dcbx_read_mib(struct ecore_hwfn *p_hwfn,
843 struct ecore_ptt *p_ptt,
844 enum ecore_mib_read_type type)
846 enum _ecore_status_t rc = ECORE_INVAL;
849 case ECORE_DCBX_OPERATIONAL_MIB:
850 ecore_dcbx_read_dscp_mib(p_hwfn, p_ptt);
851 rc = ecore_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
853 case ECORE_DCBX_REMOTE_MIB:
854 rc = ecore_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
856 case ECORE_DCBX_LOCAL_MIB:
857 rc = ecore_dcbx_read_local_mib(p_hwfn, p_ptt);
859 case ECORE_DCBX_REMOTE_LLDP_MIB:
860 rc = ecore_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
862 case ECORE_DCBX_LOCAL_LLDP_MIB:
863 rc = ecore_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
866 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
869 return ECORE_SUCCESS;
874 * Reconfigure QM and invoke PF update ramrod command if operational MIB
875 * change is detected.
878 ecore_dcbx_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
879 enum ecore_mib_read_type type)
881 enum _ecore_status_t rc = ECORE_SUCCESS;
883 rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
887 if (type == ECORE_DCBX_OPERATIONAL_MIB) {
888 ecore_dcbx_get_dscp_params(p_hwfn, &p_hwfn->p_dcbx_info->get);
890 rc = ecore_dcbx_process_mib_info(p_hwfn, p_ptt);
892 /* reconfigure tcs of QM queues according
893 * to negotiation results
895 ecore_qm_reconf(p_hwfn, p_ptt);
897 /* update storm FW with negotiation results */
898 ecore_sp_pf_update_dcbx(p_hwfn);
902 ecore_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
904 /* Update the DSCP to TC mapping enable bit if required */
905 if ((type == ECORE_DCBX_OPERATIONAL_MIB) &&
906 p_hwfn->p_dcbx_info->dscp_nig_update) {
907 u8 val = !!p_hwfn->p_dcbx_info->get.dscp.enabled;
908 u32 addr = NIG_REG_DSCP_TO_TC_MAP_ENABLE;
910 rc = ecore_all_ppfids_wr(p_hwfn, p_ptt, addr, val);
911 if (rc != ECORE_SUCCESS) {
912 DP_NOTICE(p_hwfn, false,
913 "Failed to update the DSCP to TC mapping enable bit\n");
917 p_hwfn->p_dcbx_info->dscp_nig_update = false;
920 OSAL_DCBX_AEN(p_hwfn, type);
925 enum _ecore_status_t ecore_dcbx_info_alloc(struct ecore_hwfn *p_hwfn)
927 p_hwfn->p_dcbx_info = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
928 sizeof(*p_hwfn->p_dcbx_info));
929 if (!p_hwfn->p_dcbx_info) {
930 DP_NOTICE(p_hwfn, false,
931 "Failed to allocate `struct ecore_dcbx_info'");
935 p_hwfn->p_dcbx_info->iwarp_port =
936 p_hwfn->pf_params.rdma_pf_params.iwarp_port;
938 return ECORE_SUCCESS;
941 void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn)
943 OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
946 static void ecore_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
947 struct ecore_dcbx_results *p_src,
948 enum dcbx_protocol_type type)
950 p_data->dcb_enable_flag = p_src->arr[type].enable;
951 p_data->dcb_priority = p_src->arr[type].priority;
952 p_data->dcb_tc = p_src->arr[type].tc;
953 p_data->dscp_enable_flag = p_src->arr[type].dscp_enable;
954 p_data->dscp_val = p_src->arr[type].dscp_val;
955 p_data->dcb_dont_add_vlan0 = p_src->arr[type].dont_add_vlan0;
958 /* Set pf update ramrod command params */
959 void ecore_dcbx_set_pf_update_params(struct ecore_dcbx_results *p_src,
960 struct pf_update_ramrod_data *p_dest)
962 struct protocol_dcb_data *p_dcb_data;
965 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
966 p_dest->update_eth_dcb_data_mode = update_flag;
967 update_flag = p_src->arr[DCBX_PROTOCOL_IWARP].update;
968 p_dest->update_iwarp_dcb_data_mode = update_flag;
970 p_dcb_data = &p_dest->eth_dcb_data;
971 ecore_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
972 p_dcb_data = &p_dest->iwarp_dcb_data;
973 ecore_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_IWARP);
976 enum _ecore_status_t ecore_dcbx_query_params(struct ecore_hwfn *p_hwfn,
977 struct ecore_dcbx_get *p_get,
978 enum ecore_mib_read_type type)
980 struct ecore_ptt *p_ptt;
981 enum _ecore_status_t rc;
983 if (IS_VF(p_hwfn->p_dev))
986 p_ptt = ecore_ptt_acquire(p_hwfn);
988 return ECORE_TIMEOUT;
990 rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
991 if (rc != ECORE_SUCCESS)
994 ecore_dcbx_get_dscp_params(p_hwfn, p_get);
996 rc = ecore_dcbx_get_params(p_hwfn, p_get, type);
999 ecore_ptt_release(p_hwfn, p_ptt);
1004 ecore_dcbx_set_pfc_data(struct ecore_hwfn *p_hwfn,
1005 u32 *pfc, struct ecore_dcbx_params *p_params)
1010 if (p_params->pfc.willing)
1011 *pfc |= DCBX_PFC_WILLING_MASK;
1013 *pfc &= ~DCBX_PFC_WILLING_MASK;
1015 if (p_params->pfc.enabled)
1016 *pfc |= DCBX_PFC_ENABLED_MASK;
1018 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1020 *pfc &= ~DCBX_PFC_CAPS_MASK;
1021 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_OFFSET;
1023 for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++)
1024 if (p_params->pfc.prio[i])
1025 pfc_map |= (1 << i);
1026 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
1027 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_OFFSET);
1029 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "pfc = 0x%x\n", *pfc);
1033 ecore_dcbx_set_ets_data(struct ecore_hwfn *p_hwfn,
1034 struct dcbx_ets_feature *p_ets,
1035 struct ecore_dcbx_params *p_params)
1037 u8 *bw_map, *tsa_map;
1041 if (p_params->ets_willing)
1042 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1044 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1046 if (p_params->ets_cbs)
1047 p_ets->flags |= DCBX_ETS_CBS_MASK;
1049 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1051 if (p_params->ets_enabled)
1052 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1054 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1056 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1057 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_OFFSET;
1059 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1060 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1061 p_ets->pri_tc_tbl[0] = 0;
1062 for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++) {
1063 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1064 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1065 /* Copy the priority value to the corresponding 4 bits in the
1066 * traffic class table.
1068 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1069 p_ets->pri_tc_tbl[0] |= val;
1071 for (i = 0; i < 2; i++) {
1072 p_ets->tc_bw_tbl[i] = OSAL_CPU_TO_BE32(p_ets->tc_bw_tbl[i]);
1073 p_ets->tc_tsa_tbl[i] = OSAL_CPU_TO_BE32(p_ets->tc_tsa_tbl[i]);
1076 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
1077 "flags = 0x%x pri_tc = 0x%x tc_bwl[] = {0x%x, 0x%x} tc_tsa = {0x%x, 0x%x}\n",
1078 p_ets->flags, p_ets->pri_tc_tbl[0], p_ets->tc_bw_tbl[0],
1079 p_ets->tc_bw_tbl[1], p_ets->tc_tsa_tbl[0],
1080 p_ets->tc_tsa_tbl[1]);
1084 ecore_dcbx_set_app_data(struct ecore_hwfn *p_hwfn,
1085 struct dcbx_app_priority_feature *p_app,
1086 struct ecore_dcbx_params *p_params, bool ieee)
1091 if (p_params->app_willing)
1092 p_app->flags |= DCBX_APP_WILLING_MASK;
1094 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1096 if (p_params->app_valid)
1097 p_app->flags |= DCBX_APP_ENABLED_MASK;
1099 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1101 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1102 p_app->flags |= (u32)p_params->num_app_entries <<
1103 DCBX_APP_NUM_ENTRIES_OFFSET;
1105 for (i = 0; i < p_params->num_app_entries; i++) {
1106 entry = &p_app->app_pri_tbl[i].entry;
1109 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
1110 switch (p_params->app_entry[i].sf_ieee) {
1111 case ECORE_DCBX_SF_IEEE_ETHTYPE:
1112 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1113 DCBX_APP_SF_IEEE_OFFSET);
1114 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1115 DCBX_APP_SF_OFFSET);
1117 case ECORE_DCBX_SF_IEEE_TCP_PORT:
1118 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1119 DCBX_APP_SF_IEEE_OFFSET);
1120 *entry |= ((u32)DCBX_APP_SF_PORT <<
1121 DCBX_APP_SF_OFFSET);
1123 case ECORE_DCBX_SF_IEEE_UDP_PORT:
1124 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1125 DCBX_APP_SF_IEEE_OFFSET);
1126 *entry |= ((u32)DCBX_APP_SF_PORT <<
1127 DCBX_APP_SF_OFFSET);
1129 case ECORE_DCBX_SF_IEEE_TCP_UDP_PORT:
1130 *entry |= (u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1131 DCBX_APP_SF_IEEE_OFFSET;
1132 *entry |= ((u32)DCBX_APP_SF_PORT <<
1133 DCBX_APP_SF_OFFSET);
1137 *entry &= ~DCBX_APP_SF_MASK;
1138 if (p_params->app_entry[i].ethtype)
1139 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1140 DCBX_APP_SF_OFFSET);
1142 *entry |= ((u32)DCBX_APP_SF_PORT <<
1143 DCBX_APP_SF_OFFSET);
1145 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1146 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1147 DCBX_APP_PROTOCOL_ID_OFFSET);
1148 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1149 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1150 DCBX_APP_PRI_MAP_OFFSET);
1153 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "flags = 0x%x\n", p_app->flags);
1157 ecore_dcbx_set_local_params(struct ecore_hwfn *p_hwfn,
1158 struct dcbx_local_params *local_admin,
1159 struct ecore_dcbx_set *params)
1163 local_admin->flags = 0;
1164 OSAL_MEMCPY(&local_admin->features,
1165 &p_hwfn->p_dcbx_info->operational.features,
1166 sizeof(local_admin->features));
1168 if (params->enabled) {
1169 local_admin->config = params->ver_num;
1170 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1172 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1175 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Dcbx version = %d\n",
1176 local_admin->config);
1178 if (params->override_flags & ECORE_DCBX_OVERRIDE_PFC_CFG)
1179 ecore_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1180 ¶ms->config.params);
1182 if (params->override_flags & ECORE_DCBX_OVERRIDE_ETS_CFG)
1183 ecore_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1184 ¶ms->config.params);
1186 if (params->override_flags & ECORE_DCBX_OVERRIDE_APP_CFG)
1187 ecore_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1188 ¶ms->config.params, ieee);
1191 static enum _ecore_status_t
1192 ecore_dcbx_set_dscp_params(struct ecore_hwfn *p_hwfn,
1193 struct dcb_dscp_map *p_dscp_map,
1194 struct ecore_dcbx_set *p_params)
1199 OSAL_MEMCPY(p_dscp_map, &p_hwfn->p_dcbx_info->dscp_map,
1200 sizeof(*p_dscp_map));
1202 p_dscp_map->flags &= ~DCB_DSCP_ENABLE_MASK;
1203 if (p_params->dscp.enabled)
1204 p_dscp_map->flags |= DCB_DSCP_ENABLE_MASK;
1206 for (i = 0, entry = 0; i < 8; i++) {
1208 for (j = 0; j < 8; j++, entry++)
1209 val |= (((u32)p_params->dscp.dscp_pri_map[entry]) <<
1212 p_dscp_map->dscp_pri_map[i] = OSAL_CPU_TO_BE32(val);
1215 p_hwfn->p_dcbx_info->dscp_nig_update = true;
1217 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "flags = 0x%x\n", p_dscp_map->flags);
1218 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
1219 "pri_map[] = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1220 p_dscp_map->dscp_pri_map[0], p_dscp_map->dscp_pri_map[1],
1221 p_dscp_map->dscp_pri_map[2], p_dscp_map->dscp_pri_map[3],
1222 p_dscp_map->dscp_pri_map[4], p_dscp_map->dscp_pri_map[5],
1223 p_dscp_map->dscp_pri_map[6], p_dscp_map->dscp_pri_map[7]);
1225 return ECORE_SUCCESS;
1228 enum _ecore_status_t ecore_dcbx_config_params(struct ecore_hwfn *p_hwfn,
1229 struct ecore_ptt *p_ptt,
1230 struct ecore_dcbx_set *params,
1233 struct dcbx_local_params local_admin;
1234 struct ecore_dcbx_mib_meta_data data;
1235 struct dcb_dscp_map dscp_map;
1236 u32 resp = 0, param = 0;
1237 enum _ecore_status_t rc = ECORE_SUCCESS;
1239 OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set, params,
1240 sizeof(p_hwfn->p_dcbx_info->set));
1242 return ECORE_SUCCESS;
1244 OSAL_MEMSET(&local_admin, 0, sizeof(local_admin));
1245 ecore_dcbx_set_local_params(p_hwfn, &local_admin, params);
1247 data.addr = p_hwfn->mcp_info->port_addr +
1248 offsetof(struct public_port, local_admin_dcbx_mib);
1249 data.local_admin = &local_admin;
1250 data.size = sizeof(struct dcbx_local_params);
1251 ecore_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1253 if (params->override_flags & ECORE_DCBX_OVERRIDE_DSCP_CFG) {
1254 OSAL_MEMSET(&dscp_map, 0, sizeof(dscp_map));
1255 ecore_dcbx_set_dscp_params(p_hwfn, &dscp_map, params);
1257 data.addr = p_hwfn->mcp_info->port_addr +
1258 offsetof(struct public_port, dcb_dscp_map);
1259 data.dscp_map = &dscp_map;
1260 data.size = sizeof(struct dcb_dscp_map);
1261 ecore_memcpy_to(p_hwfn, p_ptt, data.addr, data.dscp_map,
1265 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1266 1 << DRV_MB_PARAM_LLDP_SEND_OFFSET, &resp, ¶m);
1267 if (rc != ECORE_SUCCESS)
1268 DP_NOTICE(p_hwfn, false,
1269 "Failed to send DCBX update request\n");
1274 enum _ecore_status_t ecore_dcbx_get_config_params(struct ecore_hwfn *p_hwfn,
1275 struct ecore_dcbx_set *params)
1277 struct ecore_dcbx_get *dcbx_info;
1280 if (p_hwfn->p_dcbx_info->set.config.valid) {
1281 OSAL_MEMCPY(params, &p_hwfn->p_dcbx_info->set,
1282 sizeof(struct ecore_dcbx_set));
1283 return ECORE_SUCCESS;
1286 dcbx_info = OSAL_ALLOC(p_hwfn->p_dev, GFP_KERNEL,
1287 sizeof(*dcbx_info));
1291 OSAL_MEMSET(dcbx_info, 0, sizeof(*dcbx_info));
1292 rc = ecore_dcbx_query_params(p_hwfn, dcbx_info,
1293 ECORE_DCBX_OPERATIONAL_MIB);
1295 OSAL_FREE(p_hwfn->p_dev, dcbx_info);
1298 p_hwfn->p_dcbx_info->set.override_flags = 0;
1300 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1301 if (dcbx_info->operational.cee)
1302 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1303 if (dcbx_info->operational.ieee)
1304 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1305 if (dcbx_info->operational.local)
1306 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1308 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1309 OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set.dscp,
1310 &p_hwfn->p_dcbx_info->get.dscp,
1311 sizeof(struct ecore_dcbx_dscp_params));
1312 OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set.config.params,
1313 &dcbx_info->operational.params,
1314 sizeof(p_hwfn->p_dcbx_info->set.config.params));
1315 p_hwfn->p_dcbx_info->set.config.valid = true;
1317 OSAL_MEMCPY(params, &p_hwfn->p_dcbx_info->set,
1318 sizeof(struct ecore_dcbx_set));
1320 OSAL_FREE(p_hwfn->p_dev, dcbx_info);
1322 return ECORE_SUCCESS;
1325 enum _ecore_status_t ecore_lldp_register_tlv(struct ecore_hwfn *p_hwfn,
1326 struct ecore_ptt *p_ptt,
1327 enum ecore_lldp_agent agent,
1330 u32 mb_param = 0, mcp_resp = 0, mcp_param = 0, val = 0;
1331 enum _ecore_status_t rc = ECORE_SUCCESS;
1334 case ECORE_LLDP_NEAREST_BRIDGE:
1335 val = LLDP_NEAREST_BRIDGE;
1337 case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
1338 val = LLDP_NEAREST_NON_TPMR_BRIDGE;
1340 case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
1341 val = LLDP_NEAREST_CUSTOMER_BRIDGE;
1344 DP_ERR(p_hwfn, "Invalid agent type %d\n", agent);
1348 SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_AGENT, val);
1349 SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_TLV_RX_TYPE, tlv_type);
1351 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_REGISTER_LLDP_TLVS_RX,
1352 mb_param, &mcp_resp, &mcp_param);
1353 if (rc != ECORE_SUCCESS)
1354 DP_NOTICE(p_hwfn, false, "Failed to register TLV\n");
1359 enum _ecore_status_t
1360 ecore_lldp_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
1362 struct ecore_dcbx_mib_meta_data data;
1363 enum _ecore_status_t rc = ECORE_SUCCESS;
1364 struct lldp_received_tlvs_s tlvs;
1367 for (i = 0; i < LLDP_MAX_LLDP_AGENTS; i++) {
1368 OSAL_MEM_ZERO(&data, sizeof(data));
1369 data.addr = p_hwfn->mcp_info->port_addr +
1370 offsetof(struct public_port, lldp_received_tlvs[i]);
1371 data.lldp_tlvs = &tlvs;
1372 data.size = sizeof(tlvs);
1373 rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data,
1374 ECORE_DCBX_LLDP_TLVS);
1375 if (rc != ECORE_SUCCESS) {
1376 DP_NOTICE(p_hwfn, false, "Failed to read lldp TLVs\n");
1383 for (i = 0; i < MAX_TLV_BUFFER; i++)
1384 tlvs.tlvs_buffer[i] =
1385 OSAL_CPU_TO_BE32(tlvs.tlvs_buffer[i]);
1387 OSAL_LLDP_RX_TLVS(p_hwfn, tlvs.tlvs_buffer, tlvs.length);
1393 enum _ecore_status_t
1394 ecore_lldp_get_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1395 struct ecore_lldp_config_params *p_params)
1397 struct lldp_config_params_s lldp_params;
1401 switch (p_params->agent) {
1402 case ECORE_LLDP_NEAREST_BRIDGE:
1403 val = LLDP_NEAREST_BRIDGE;
1405 case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
1406 val = LLDP_NEAREST_NON_TPMR_BRIDGE;
1408 case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
1409 val = LLDP_NEAREST_CUSTOMER_BRIDGE;
1412 DP_ERR(p_hwfn, "Invalid agent type %d\n", p_params->agent);
1416 addr = p_hwfn->mcp_info->port_addr +
1417 offsetof(struct public_port, lldp_config_params[val]);
1419 ecore_memcpy_from(p_hwfn, p_ptt, &lldp_params, addr,
1420 sizeof(lldp_params));
1422 p_params->tx_interval = GET_MFW_FIELD(lldp_params.config,
1423 LLDP_CONFIG_TX_INTERVAL);
1424 p_params->tx_hold = GET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_HOLD);
1425 p_params->tx_credit = GET_MFW_FIELD(lldp_params.config,
1426 LLDP_CONFIG_MAX_CREDIT);
1427 p_params->rx_enable = GET_MFW_FIELD(lldp_params.config,
1428 LLDP_CONFIG_ENABLE_RX);
1429 p_params->tx_enable = GET_MFW_FIELD(lldp_params.config,
1430 LLDP_CONFIG_ENABLE_TX);
1432 OSAL_MEMCPY(p_params->chassis_id_tlv, lldp_params.local_chassis_id,
1433 sizeof(p_params->chassis_id_tlv));
1434 for (i = 0; i < ECORE_LLDP_CHASSIS_ID_STAT_LEN; i++)
1435 p_params->chassis_id_tlv[i] =
1436 OSAL_BE32_TO_CPU(p_params->chassis_id_tlv[i]);
1438 OSAL_MEMCPY(p_params->port_id_tlv, lldp_params.local_port_id,
1439 sizeof(p_params->port_id_tlv));
1440 for (i = 0; i < ECORE_LLDP_PORT_ID_STAT_LEN; i++)
1441 p_params->port_id_tlv[i] =
1442 OSAL_BE32_TO_CPU(p_params->port_id_tlv[i]);
1444 return ECORE_SUCCESS;
1447 enum _ecore_status_t
1448 ecore_lldp_set_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1449 struct ecore_lldp_config_params *p_params)
1451 u32 mb_param = 0, mcp_resp = 0, mcp_param = 0;
1452 struct lldp_config_params_s lldp_params;
1453 enum _ecore_status_t rc = ECORE_SUCCESS;
1457 switch (p_params->agent) {
1458 case ECORE_LLDP_NEAREST_BRIDGE:
1459 val = LLDP_NEAREST_BRIDGE;
1461 case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
1462 val = LLDP_NEAREST_NON_TPMR_BRIDGE;
1464 case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
1465 val = LLDP_NEAREST_CUSTOMER_BRIDGE;
1468 DP_ERR(p_hwfn, "Invalid agent type %d\n", p_params->agent);
1472 SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_AGENT, val);
1473 addr = p_hwfn->mcp_info->port_addr +
1474 offsetof(struct public_port, lldp_config_params[val]);
1476 OSAL_MEMSET(&lldp_params, 0, sizeof(lldp_params));
1477 SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_TX_INTERVAL,
1478 p_params->tx_interval);
1479 SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_HOLD, p_params->tx_hold);
1480 SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_MAX_CREDIT,
1481 p_params->tx_credit);
1482 SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_ENABLE_RX,
1483 !!p_params->rx_enable);
1484 SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_ENABLE_TX,
1485 !!p_params->tx_enable);
1487 for (i = 0; i < ECORE_LLDP_CHASSIS_ID_STAT_LEN; i++)
1488 p_params->chassis_id_tlv[i] =
1489 OSAL_CPU_TO_BE32(p_params->chassis_id_tlv[i]);
1490 OSAL_MEMCPY(lldp_params.local_chassis_id, p_params->chassis_id_tlv,
1491 sizeof(lldp_params.local_chassis_id));
1493 for (i = 0; i < ECORE_LLDP_PORT_ID_STAT_LEN; i++)
1494 p_params->port_id_tlv[i] =
1495 OSAL_CPU_TO_BE32(p_params->port_id_tlv[i]);
1496 OSAL_MEMCPY(lldp_params.local_port_id, p_params->port_id_tlv,
1497 sizeof(lldp_params.local_port_id));
1499 ecore_memcpy_to(p_hwfn, p_ptt, addr, &lldp_params, sizeof(lldp_params));
1501 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LLDP,
1502 mb_param, &mcp_resp, &mcp_param);
1503 if (rc != ECORE_SUCCESS)
1504 DP_NOTICE(p_hwfn, false, "SET_LLDP failed, error = %d\n", rc);
1509 enum _ecore_status_t
1510 ecore_lldp_set_system_tlvs(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1511 struct ecore_lldp_sys_tlvs *p_params)
1513 u32 mb_param = 0, mcp_resp = 0, mcp_param = 0;
1514 enum _ecore_status_t rc = ECORE_SUCCESS;
1515 struct lldp_system_tlvs_buffer_s lld_tlv_buf;
1520 p_val = (u32 *)p_params->buf;
1521 for (i = 0; i < ECORE_LLDP_SYS_TLV_SIZE / 4; i++)
1522 p_val[i] = OSAL_CPU_TO_BE32(p_val[i]);
1524 OSAL_MEMSET(&lld_tlv_buf, 0, sizeof(lld_tlv_buf));
1525 SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_VALID, 1);
1526 SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_MANDATORY,
1527 !!p_params->discard_mandatory_tlv);
1528 SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_LENGTH,
1529 p_params->buf_size);
1530 len = ECORE_LLDP_SYS_TLV_SIZE / 2;
1531 OSAL_MEMCPY(lld_tlv_buf.data, p_params->buf, len);
1533 addr = p_hwfn->mcp_info->port_addr +
1534 offsetof(struct public_port, system_lldp_tlvs_buf);
1535 ecore_memcpy_to(p_hwfn, p_ptt, addr, &lld_tlv_buf, sizeof(lld_tlv_buf));
1537 if (p_params->buf_size > len) {
1538 addr = p_hwfn->mcp_info->port_addr +
1539 offsetof(struct public_port, system_lldp_tlvs_buf2);
1540 ecore_memcpy_to(p_hwfn, p_ptt, addr, &p_params->buf[len],
1541 ECORE_LLDP_SYS_TLV_SIZE / 2);
1544 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LLDP,
1545 mb_param, &mcp_resp, &mcp_param);
1546 if (rc != ECORE_SUCCESS)
1547 DP_NOTICE(p_hwfn, false, "SET_LLDP failed, error = %d\n", rc);
1552 enum _ecore_status_t
1553 ecore_dcbx_get_dscp_priority(struct ecore_hwfn *p_hwfn,
1554 u8 dscp_index, u8 *p_dscp_pri)
1556 struct ecore_dcbx_get *p_dcbx_info;
1557 enum _ecore_status_t rc;
1559 if (dscp_index >= ECORE_DCBX_DSCP_SIZE) {
1560 DP_ERR(p_hwfn, "Invalid dscp index %d\n", dscp_index);
1564 p_dcbx_info = OSAL_ALLOC(p_hwfn->p_dev, GFP_KERNEL,
1565 sizeof(*p_dcbx_info));
1569 OSAL_MEMSET(p_dcbx_info, 0, sizeof(*p_dcbx_info));
1570 rc = ecore_dcbx_query_params(p_hwfn, p_dcbx_info,
1571 ECORE_DCBX_OPERATIONAL_MIB);
1573 OSAL_FREE(p_hwfn->p_dev, p_dcbx_info);
1577 *p_dscp_pri = p_dcbx_info->dscp.dscp_pri_map[dscp_index];
1578 OSAL_FREE(p_hwfn->p_dev, p_dcbx_info);
1580 return ECORE_SUCCESS;
1583 enum _ecore_status_t
1584 ecore_dcbx_set_dscp_priority(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1585 u8 dscp_index, u8 pri_val)
1587 struct ecore_dcbx_set dcbx_set;
1588 enum _ecore_status_t rc;
1590 if (dscp_index >= ECORE_DCBX_DSCP_SIZE ||
1591 pri_val >= ECORE_MAX_PFC_PRIORITIES) {
1592 DP_ERR(p_hwfn, "Invalid dscp params: index = %d pri = %d\n",
1593 dscp_index, pri_val);
1597 OSAL_MEMSET(&dcbx_set, 0, sizeof(dcbx_set));
1598 rc = ecore_dcbx_get_config_params(p_hwfn, &dcbx_set);
1602 dcbx_set.override_flags = ECORE_DCBX_OVERRIDE_DSCP_CFG;
1603 dcbx_set.dscp.dscp_pri_map[dscp_index] = pri_val;
1605 return ecore_dcbx_config_params(p_hwfn, p_ptt, &dcbx_set, 1);