1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/types.h>
10 #include <asm/byteorder.h>
11 #include <linux/bitops.h>
12 #include <linux/dcbnl.h>
13 #include <linux/errno.h>
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/string.h>
23 #include <linux/qed/qed_eth_if.h>
26 #define QED_DCBX_MAX_MIB_READ_TRY (100)
27 #define QED_ETH_TYPE_DEFAULT (0)
28 #define QED_ETH_TYPE_ROCE (0x8915)
29 #define QED_UDP_PORT_TYPE_ROCE_V2 (0x12B7)
30 #define QED_ETH_TYPE_FCOE (0x8906)
31 #define QED_TCP_PORT_ISCSI (0xCBC)
33 #define QED_DCBX_INVALID_PRIORITY 0xFF
35 /* Get Traffic Class from priority traffic class table, 4 bits represent
36 * the traffic class corresponding to the priority.
38 #define QED_DCBX_PRIO2TC(prio_tc_tbl, prio) \
39 ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
41 static const struct qed_dcbx_app_metadata qed_dcbx_app_update[] = {
42 {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_DEFAULT},
43 {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_DEFAULT},
44 {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_DEFAULT},
45 {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_DEFAULT},
46 {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH}
49 static bool qed_dcbx_app_ethtype(u32 app_info_bitmap)
51 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
55 static bool qed_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
57 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
60 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
61 return qed_dcbx_app_ethtype(app_info_bitmap);
63 return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
66 static bool qed_dcbx_app_port(u32 app_info_bitmap)
68 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
72 static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
77 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
79 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
81 return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT));
84 static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id)
86 return !!(qed_dcbx_app_port(app_info_bitmap) &&
87 proto_id == QED_TCP_PORT_ISCSI);
90 static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
95 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
97 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
99 return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE));
102 static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
107 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
109 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
111 return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE));
114 static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id)
116 return !!(qed_dcbx_app_port(app_info_bitmap) &&
117 proto_id == QED_UDP_PORT_TYPE_ROCE_V2);
121 qed_dcbx_dp_protocol(struct qed_hwfn *p_hwfn, struct qed_dcbx_results *p_data)
123 enum dcbx_protocol_type id;
126 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "DCBX negotiated: %d\n",
127 p_data->dcbx_enabled);
129 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
130 id = qed_dcbx_app_update[i].id;
132 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
133 "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n",
134 qed_dcbx_app_update[i].name, p_data->arr[id].update,
135 p_data->arr[id].enable, p_data->arr[id].priority,
136 p_data->arr[id].tc, p_hwfn->hw_info.num_tc);
141 qed_dcbx_set_params(struct qed_dcbx_results *p_data,
142 struct qed_hw_info *p_info,
147 enum dcbx_protocol_type type,
148 enum qed_pci_personality personality)
150 /* PF update ramrod data */
151 p_data->arr[type].update = update;
152 p_data->arr[type].enable = enable;
153 p_data->arr[type].priority = prio;
154 p_data->arr[type].tc = tc;
157 if (p_info->personality == personality) {
158 if (personality == QED_PCI_ETH)
159 p_info->non_offload_tc = tc;
161 p_info->offload_tc = tc;
165 /* Update app protocol data and hw_info fields with the TLV info */
167 qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
168 struct qed_hwfn *p_hwfn,
171 u8 prio, u8 tc, enum dcbx_protocol_type type)
173 struct qed_hw_info *p_info = &p_hwfn->hw_info;
174 enum qed_pci_personality personality;
175 enum dcbx_protocol_type id;
179 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
180 id = qed_dcbx_app_update[i].id;
185 personality = qed_dcbx_app_update[i].personality;
186 name = qed_dcbx_app_update[i].name;
188 qed_dcbx_set_params(p_data, p_info, enable, update,
189 prio, tc, type, personality);
194 qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
196 u16 id, enum dcbx_protocol_type *type, bool ieee)
198 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
199 *type = DCBX_PROTOCOL_FCOE;
200 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
201 *type = DCBX_PROTOCOL_ROCE;
202 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id)) {
203 *type = DCBX_PROTOCOL_ISCSI;
204 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
205 *type = DCBX_PROTOCOL_ETH;
206 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id)) {
207 *type = DCBX_PROTOCOL_ROCE_V2;
209 *type = DCBX_MAX_PROTOCOL_TYPE;
211 "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n",
212 id, app_prio_bitmap);
219 /* Parse app TLV's to update TC information in hw_info structure for
220 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
223 qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
224 struct qed_dcbx_results *p_data,
225 struct dcbx_app_priority_entry *p_tbl,
226 u32 pri_tc_tbl, int count, u8 dcbx_version)
229 enum dcbx_protocol_type type;
235 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
237 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
239 for (i = 0; i < count; i++) {
240 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
241 DCBX_APP_PROTOCOL_ID);
242 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
244 priority = ffs(priority_map) - 1;
246 DP_ERR(p_hwfn, "Invalid priority\n");
250 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
251 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
252 protocol_id, &type, ieee)) {
253 /* ETH always have the enable bit reset, as it gets
254 * vlan information per packet. For other protocols,
255 * should be set according to the dcbx_enabled
256 * indication, but we only got here if there was an
257 * app tlv for the protocol, so dcbx must be enabled.
259 enable = !(type == DCBX_PROTOCOL_ETH);
261 qed_dcbx_update_app_info(p_data, p_hwfn, enable, true,
266 /* If RoCE-V2 TLV is not detected, driver need to use RoCE app
267 * data for RoCE-v2 not the default app data.
269 if (!p_data->arr[DCBX_PROTOCOL_ROCE_V2].update &&
270 p_data->arr[DCBX_PROTOCOL_ROCE].update) {
271 tc = p_data->arr[DCBX_PROTOCOL_ROCE].tc;
272 priority = p_data->arr[DCBX_PROTOCOL_ROCE].priority;
273 qed_dcbx_update_app_info(p_data, p_hwfn, true, true,
274 priority, tc, DCBX_PROTOCOL_ROCE_V2);
277 /* Update ramrod protocol data and hw_info fields
278 * with default info when corresponding APP TLV's are not detected.
279 * The enabled field has a different logic for ethernet as only for
280 * ethernet dcb should disabled by default, as the information arrives
281 * from the OS (unless an explicit app tlv was present).
283 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
284 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
285 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
286 if (p_data->arr[type].update)
289 enable = !(type == DCBX_PROTOCOL_ETH);
290 qed_dcbx_update_app_info(p_data, p_hwfn, enable, true,
297 /* Parse app TLV's to update TC information in hw_info structure for
298 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
300 static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
302 struct dcbx_app_priority_feature *p_app;
303 struct dcbx_app_priority_entry *p_tbl;
304 struct qed_dcbx_results data = { 0 };
305 struct dcbx_ets_feature *p_ets;
306 struct qed_hw_info *p_info;
307 u32 pri_tc_tbl, flags;
312 flags = p_hwfn->p_dcbx_info->operational.flags;
313 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
315 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
316 p_tbl = p_app->app_pri_tbl;
318 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
319 pri_tc_tbl = p_ets->pri_tc_tbl[0];
321 p_info = &p_hwfn->hw_info;
322 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
324 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
325 num_entries, dcbx_version);
329 p_info->num_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
330 data.pf_id = p_hwfn->rel_pf_id;
331 data.dcbx_enabled = !!dcbx_version;
333 qed_dcbx_dp_protocol(p_hwfn, &data);
335 memcpy(&p_hwfn->p_dcbx_info->results, &data,
336 sizeof(struct qed_dcbx_results));
342 qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
343 struct qed_ptt *p_ptt,
344 struct qed_dcbx_mib_meta_data *p_data,
345 enum qed_mib_read_type type)
347 u32 prefix_seq_num, suffix_seq_num;
351 /* The data is considered to be valid only if both sequence numbers are
355 if (type == QED_DCBX_REMOTE_LLDP_MIB) {
356 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
357 p_data->addr, p_data->size);
358 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
359 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
361 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
362 p_data->addr, p_data->size);
363 prefix_seq_num = p_data->mib->prefix_seq_num;
364 suffix_seq_num = p_data->mib->suffix_seq_num;
370 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
371 type, read_count, prefix_seq_num, suffix_seq_num);
372 } while ((prefix_seq_num != suffix_seq_num) &&
373 (read_count < QED_DCBX_MAX_MIB_READ_TRY));
375 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
377 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
378 type, read_count, prefix_seq_num, suffix_seq_num);
387 qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
388 struct qed_dcbx_app_prio *p_prio,
389 struct qed_dcbx_results *p_results)
393 p_prio->roce = QED_DCBX_INVALID_PRIORITY;
394 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
395 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
396 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
398 if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
399 p_results->arr[DCBX_PROTOCOL_ROCE].enable)
400 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
402 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
403 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
404 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
405 p_prio->roce_v2 = val;
408 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
409 p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
410 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
412 if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
413 p_results->arr[DCBX_PROTOCOL_FCOE].enable)
414 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
416 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
417 p_results->arr[DCBX_PROTOCOL_ETH].enable)
418 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
420 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
421 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
422 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
427 qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
428 struct dcbx_app_priority_feature *p_app,
429 struct dcbx_app_priority_entry *p_tbl,
430 struct qed_dcbx_params *p_params, bool ieee)
432 struct qed_app_entry *entry;
436 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
438 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
439 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
440 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
441 DCBX_APP_NUM_ENTRIES);
442 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
443 entry = &p_params->app_entry[i];
444 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
446 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
447 entry->prio = ffs(pri_map) - 1;
448 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
449 DCBX_APP_PROTOCOL_ID);
450 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
452 &entry->proto_type, ieee);
455 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
456 "APP params: willing %d, valid %d error = %d\n",
457 p_params->app_willing, p_params->app_valid,
458 p_params->app_error);
462 qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
463 u32 pfc, struct qed_dcbx_params *p_params)
467 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
468 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
469 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
470 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
471 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
472 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
473 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
474 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
475 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
476 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
477 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
478 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
480 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
481 "PFC params: willing %d, pfc_bitmap %d\n",
482 p_params->pfc.willing, pfc_map);
486 qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
487 struct dcbx_ets_feature *p_ets,
488 struct qed_dcbx_params *p_params)
490 u32 bw_map[2], tsa_map[2], pri_map;
493 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
495 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
497 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
498 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
500 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
501 "ETS params: willing %d, ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
502 p_params->ets_willing,
504 p_ets->pri_tc_tbl[0], p_params->max_ets_tc);
506 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
507 * encoded in a type u32 array of size 2.
509 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
510 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
511 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
512 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
513 pri_map = p_ets->pri_tc_tbl[0];
514 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
515 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
516 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
517 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
518 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
519 "elem %d bw_tbl %x tsa_tbl %x\n",
520 i, p_params->ets_tc_bw_tbl[i],
521 p_params->ets_tc_tsa_tbl[i]);
526 qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
527 struct dcbx_app_priority_feature *p_app,
528 struct dcbx_app_priority_entry *p_tbl,
529 struct dcbx_ets_feature *p_ets,
530 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
532 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
533 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
534 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
538 qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn,
539 struct qed_ptt *p_ptt, struct qed_dcbx_get *params)
541 struct dcbx_features *p_feat;
543 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
544 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
545 p_feat->app.app_pri_tbl, &p_feat->ets,
546 p_feat->pfc, ¶ms->local.params, false);
547 params->local.valid = true;
551 qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn,
552 struct qed_ptt *p_ptt, struct qed_dcbx_get *params)
554 struct dcbx_features *p_feat;
556 p_feat = &p_hwfn->p_dcbx_info->remote.features;
557 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
558 p_feat->app.app_pri_tbl, &p_feat->ets,
559 p_feat->pfc, ¶ms->remote.params, false);
560 params->remote.valid = true;
564 qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
565 struct qed_ptt *p_ptt,
566 struct qed_dcbx_get *params)
568 struct qed_dcbx_operational_params *p_operational;
569 struct qed_dcbx_results *p_results;
570 struct dcbx_features *p_feat;
575 flags = p_hwfn->p_dcbx_info->operational.flags;
577 /* If DCBx version is non zero, then negotiation
578 * was successfuly performed
580 p_operational = ¶ms->operational;
581 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
582 DCBX_CONFIG_VERSION_DISABLED);
584 p_operational->enabled = enabled;
585 p_operational->valid = false;
589 p_feat = &p_hwfn->p_dcbx_info->operational.features;
590 p_results = &p_hwfn->p_dcbx_info->results;
592 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
593 DCBX_CONFIG_VERSION_IEEE);
594 p_operational->ieee = val;
595 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
596 DCBX_CONFIG_VERSION_CEE);
597 p_operational->cee = val;
599 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Version support: ieee %d, cee %d\n",
600 p_operational->ieee, p_operational->cee);
602 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
603 p_feat->app.app_pri_tbl, &p_feat->ets,
604 p_feat->pfc, ¶ms->operational.params,
605 p_operational->ieee);
606 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
607 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
608 p_operational->err = err;
609 p_operational->enabled = enabled;
610 p_operational->valid = true;
614 qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
615 struct qed_ptt *p_ptt,
616 struct qed_dcbx_get *params)
618 struct lldp_config_params_s *p_local;
620 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
622 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
623 ARRAY_SIZE(p_local->local_chassis_id));
624 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
625 ARRAY_SIZE(p_local->local_port_id));
629 qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
630 struct qed_ptt *p_ptt,
631 struct qed_dcbx_get *params)
633 struct lldp_status_params_s *p_remote;
635 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
637 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
638 ARRAY_SIZE(p_remote->peer_chassis_id));
639 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
640 ARRAY_SIZE(p_remote->peer_port_id));
644 qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
645 struct qed_dcbx_get *p_params,
646 enum qed_mib_read_type type)
649 case QED_DCBX_REMOTE_MIB:
650 qed_dcbx_get_remote_params(p_hwfn, p_ptt, p_params);
652 case QED_DCBX_LOCAL_MIB:
653 qed_dcbx_get_local_params(p_hwfn, p_ptt, p_params);
655 case QED_DCBX_OPERATIONAL_MIB:
656 qed_dcbx_get_operational_params(p_hwfn, p_ptt, p_params);
658 case QED_DCBX_REMOTE_LLDP_MIB:
659 qed_dcbx_get_remote_lldp_params(p_hwfn, p_ptt, p_params);
661 case QED_DCBX_LOCAL_LLDP_MIB:
662 qed_dcbx_get_local_lldp_params(p_hwfn, p_ptt, p_params);
665 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
674 qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
676 struct qed_dcbx_mib_meta_data data;
679 memset(&data, 0, sizeof(data));
680 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
682 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
683 data.size = sizeof(struct lldp_config_params_s);
684 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
690 qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
691 struct qed_ptt *p_ptt,
692 enum qed_mib_read_type type)
694 struct qed_dcbx_mib_meta_data data;
697 memset(&data, 0, sizeof(data));
698 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
700 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
701 data.size = sizeof(struct lldp_status_params_s);
702 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
708 qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
709 struct qed_ptt *p_ptt,
710 enum qed_mib_read_type type)
712 struct qed_dcbx_mib_meta_data data;
715 memset(&data, 0, sizeof(data));
716 data.addr = p_hwfn->mcp_info->port_addr +
717 offsetof(struct public_port, operational_dcbx_mib);
718 data.mib = &p_hwfn->p_dcbx_info->operational;
719 data.size = sizeof(struct dcbx_mib);
720 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
726 qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
727 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
729 struct qed_dcbx_mib_meta_data data;
732 memset(&data, 0, sizeof(data));
733 data.addr = p_hwfn->mcp_info->port_addr +
734 offsetof(struct public_port, remote_dcbx_mib);
735 data.mib = &p_hwfn->p_dcbx_info->remote;
736 data.size = sizeof(struct dcbx_mib);
737 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
743 qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
745 struct qed_dcbx_mib_meta_data data;
748 memset(&data, 0, sizeof(data));
749 data.addr = p_hwfn->mcp_info->port_addr +
750 offsetof(struct public_port, local_admin_dcbx_mib);
751 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
752 data.size = sizeof(struct dcbx_local_params);
753 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
758 static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
759 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
764 case QED_DCBX_OPERATIONAL_MIB:
765 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
767 case QED_DCBX_REMOTE_MIB:
768 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
770 case QED_DCBX_LOCAL_MIB:
771 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
773 case QED_DCBX_REMOTE_LLDP_MIB:
774 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
776 case QED_DCBX_LOCAL_LLDP_MIB:
777 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
780 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
787 * Reconfigure QM and invoke PF update ramrod command if operational MIB
788 * change is detected.
791 qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
792 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
796 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
800 if (type == QED_DCBX_OPERATIONAL_MIB) {
801 rc = qed_dcbx_process_mib_info(p_hwfn);
803 /* reconfigure tcs of QM queues according
804 * to negotiation results
806 qed_qm_reconf(p_hwfn, p_ptt);
808 /* update storm FW with negotiation results */
809 qed_sp_pf_update(p_hwfn);
816 int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
820 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
821 if (!p_hwfn->p_dcbx_info) {
823 "Failed to allocate 'struct qed_dcbx_info'\n");
830 void qed_dcbx_info_free(struct qed_hwfn *p_hwfn,
831 struct qed_dcbx_info *p_dcbx_info)
833 kfree(p_hwfn->p_dcbx_info);
836 static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
837 struct qed_dcbx_results *p_src,
838 enum dcbx_protocol_type type)
840 p_data->dcb_enable_flag = p_src->arr[type].enable;
841 p_data->dcb_priority = p_src->arr[type].priority;
842 p_data->dcb_tc = p_src->arr[type].tc;
845 /* Set pf update ramrod command params */
846 void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
847 struct pf_update_ramrod_data *p_dest)
849 struct protocol_dcb_data *p_dcb_data;
850 bool update_flag = false;
852 p_dest->pf_id = p_src->pf_id;
854 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
855 p_dest->update_fcoe_dcb_data_flag = update_flag;
857 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
858 p_dest->update_roce_dcb_data_flag = update_flag;
859 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
860 p_dest->update_roce_dcb_data_flag = update_flag;
862 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
863 p_dest->update_iscsi_dcb_data_flag = update_flag;
864 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
865 p_dest->update_eth_dcb_data_flag = update_flag;
867 p_dcb_data = &p_dest->fcoe_dcb_data;
868 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
869 p_dcb_data = &p_dest->roce_dcb_data;
871 if (p_src->arr[DCBX_PROTOCOL_ROCE].update)
872 qed_dcbx_update_protocol_data(p_dcb_data, p_src,
874 if (p_src->arr[DCBX_PROTOCOL_ROCE_V2].update)
875 qed_dcbx_update_protocol_data(p_dcb_data, p_src,
876 DCBX_PROTOCOL_ROCE_V2);
878 p_dcb_data = &p_dest->iscsi_dcb_data;
879 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
880 p_dcb_data = &p_dest->eth_dcb_data;
881 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
885 static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
886 struct qed_dcbx_get *p_get,
887 enum qed_mib_read_type type)
889 struct qed_ptt *p_ptt;
892 p_ptt = qed_ptt_acquire(p_hwfn);
896 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
900 rc = qed_dcbx_get_params(p_hwfn, p_ptt, p_get, type);
903 qed_ptt_release(p_hwfn, p_ptt);
908 qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
909 u32 *pfc, struct qed_dcbx_params *p_params)
914 if (p_params->pfc.willing)
915 *pfc |= DCBX_PFC_WILLING_MASK;
917 *pfc &= ~DCBX_PFC_WILLING_MASK;
919 if (p_params->pfc.enabled)
920 *pfc |= DCBX_PFC_ENABLED_MASK;
922 *pfc &= ~DCBX_PFC_ENABLED_MASK;
924 *pfc &= ~DCBX_PFC_CAPS_MASK;
925 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
927 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
928 if (p_params->pfc.prio[i])
931 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
933 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
937 qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
938 struct dcbx_ets_feature *p_ets,
939 struct qed_dcbx_params *p_params)
941 u8 *bw_map, *tsa_map;
945 if (p_params->ets_willing)
946 p_ets->flags |= DCBX_ETS_WILLING_MASK;
948 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
950 if (p_params->ets_cbs)
951 p_ets->flags |= DCBX_ETS_CBS_MASK;
953 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
955 if (p_params->ets_enabled)
956 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
958 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
960 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
961 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
963 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
964 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
965 p_ets->pri_tc_tbl[0] = 0;
966 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
967 bw_map[i] = p_params->ets_tc_bw_tbl[i];
968 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
969 /* Copy the priority value to the corresponding 4 bits in the
970 * traffic class table.
972 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
973 p_ets->pri_tc_tbl[0] |= val;
975 for (i = 0; i < 2; i++) {
976 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
977 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
982 qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
983 struct dcbx_app_priority_feature *p_app,
984 struct qed_dcbx_params *p_params)
989 if (p_params->app_willing)
990 p_app->flags |= DCBX_APP_WILLING_MASK;
992 p_app->flags &= ~DCBX_APP_WILLING_MASK;
994 if (p_params->app_valid)
995 p_app->flags |= DCBX_APP_ENABLED_MASK;
997 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
999 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1000 p_app->flags |= (u32)p_params->num_app_entries <<
1001 DCBX_APP_NUM_ENTRIES_SHIFT;
1003 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1004 entry = &p_app->app_pri_tbl[i].entry;
1005 *entry &= ~DCBX_APP_SF_MASK;
1006 if (p_params->app_entry[i].ethtype)
1007 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1010 *entry |= ((u32)DCBX_APP_SF_PORT << DCBX_APP_SF_SHIFT);
1011 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1012 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1013 DCBX_APP_PROTOCOL_ID_SHIFT);
1014 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1015 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1016 DCBX_APP_PRI_MAP_SHIFT);
1021 qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1022 struct dcbx_local_params *local_admin,
1023 struct qed_dcbx_set *params)
1025 local_admin->flags = 0;
1026 memcpy(&local_admin->features,
1027 &p_hwfn->p_dcbx_info->operational.features,
1028 sizeof(local_admin->features));
1030 if (params->enabled)
1031 local_admin->config = params->ver_num;
1033 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1035 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1036 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1037 ¶ms->config.params);
1039 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1040 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1041 ¶ms->config.params);
1043 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1044 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1045 ¶ms->config.params);
1048 int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1049 struct qed_dcbx_set *params, bool hw_commit)
1051 struct dcbx_local_params local_admin;
1052 struct qed_dcbx_mib_meta_data data;
1053 u32 resp = 0, param = 0;
1057 memcpy(&p_hwfn->p_dcbx_info->set, params,
1058 sizeof(struct qed_dcbx_set));
1062 /* clear set-parmas cache */
1063 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1065 memset(&local_admin, 0, sizeof(local_admin));
1066 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1068 data.addr = p_hwfn->mcp_info->port_addr +
1069 offsetof(struct public_port, local_admin_dcbx_mib);
1070 data.local_admin = &local_admin;
1071 data.size = sizeof(struct dcbx_local_params);
1072 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1074 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1075 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, ¶m);
1077 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1082 int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1083 struct qed_dcbx_set *params)
1085 struct qed_dcbx_get *dcbx_info;
1088 if (p_hwfn->p_dcbx_info->set.config.valid) {
1089 memcpy(params, &p_hwfn->p_dcbx_info->set,
1090 sizeof(struct qed_dcbx_set));
1094 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL);
1096 DP_ERR(p_hwfn, "Failed to allocate struct qed_dcbx_info\n");
1100 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1106 p_hwfn->p_dcbx_info->set.override_flags = 0;
1107 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1108 if (dcbx_info->operational.cee)
1109 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1110 if (dcbx_info->operational.ieee)
1111 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1113 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1114 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1115 &dcbx_info->operational.params,
1116 sizeof(struct qed_dcbx_admin_params));
1117 p_hwfn->p_dcbx_info->set.config.valid = true;
1119 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1126 static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1127 enum qed_mib_read_type type)
1129 struct qed_dcbx_get *dcbx_info;
1131 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL);
1133 DP_ERR(hwfn->cdev, "Failed to allocate memory for dcbx_info\n");
1137 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1142 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1143 !dcbx_info->operational.enabled) {
1144 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1152 static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1154 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1155 struct qed_dcbx_get *dcbx_info;
1158 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1162 enabled = dcbx_info->operational.enabled;
1163 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1169 static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1171 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1172 struct qed_dcbx_set dcbx_set;
1173 struct qed_ptt *ptt;
1176 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1178 memset(&dcbx_set, 0, sizeof(dcbx_set));
1179 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1183 dcbx_set.enabled = !!state;
1185 ptt = qed_ptt_acquire(hwfn);
1189 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1191 qed_ptt_release(hwfn, ptt);
1196 static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1197 u8 *pgid, u8 *bw_pct, u8 *up_map)
1199 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1200 struct qed_dcbx_get *dcbx_info;
1202 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1203 *prio_type = *pgid = *bw_pct = *up_map = 0;
1204 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1205 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1209 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1213 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1217 static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1219 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1220 struct qed_dcbx_get *dcbx_info;
1223 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1224 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1225 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1229 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1233 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1234 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1238 static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1239 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1241 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1242 *prio = *bwg_id = *bw_pct = *up_map = 0;
1245 static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1246 int bwg_id, u8 *bw_pct)
1248 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1252 static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1253 int priority, u8 *setting)
1255 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1256 struct qed_dcbx_get *dcbx_info;
1258 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1259 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1260 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1264 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1268 *setting = dcbx_info->operational.params.pfc.prio[priority];
1269 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1273 static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1275 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1276 struct qed_dcbx_set dcbx_set;
1277 struct qed_ptt *ptt;
1280 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1282 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1283 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1287 memset(&dcbx_set, 0, sizeof(dcbx_set));
1288 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1292 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1293 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1295 ptt = qed_ptt_acquire(hwfn);
1299 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1301 qed_ptt_release(hwfn, ptt);
1304 static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1306 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1307 struct qed_dcbx_get *dcbx_info;
1310 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1311 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1316 case DCB_CAP_ATTR_PG:
1317 case DCB_CAP_ATTR_PFC:
1318 case DCB_CAP_ATTR_UP2TC:
1319 case DCB_CAP_ATTR_GSP:
1322 case DCB_CAP_ATTR_PG_TCS:
1323 case DCB_CAP_ATTR_PFC_TCS:
1326 case DCB_CAP_ATTR_DCBX:
1327 *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
1328 DCB_CAP_DCBX_VER_IEEE);
1335 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1341 static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1343 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1344 struct qed_dcbx_get *dcbx_info;
1347 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1348 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1353 case DCB_NUMTCS_ATTR_PG:
1354 *num = dcbx_info->operational.params.max_ets_tc;
1356 case DCB_NUMTCS_ATTR_PFC:
1357 *num = dcbx_info->operational.params.pfc.max_tc;
1364 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1369 static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1371 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1372 struct qed_dcbx_get *dcbx_info;
1375 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1379 enabled = dcbx_info->operational.params.pfc.enabled;
1380 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1386 static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1388 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1389 struct qed_dcbx_get *dcbx_info;
1392 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1396 if (dcbx_info->operational.enabled)
1397 mode |= DCB_CAP_DCBX_LLD_MANAGED;
1398 if (dcbx_info->operational.ieee)
1399 mode |= DCB_CAP_DCBX_VER_IEEE;
1400 if (dcbx_info->operational.cee)
1401 mode |= DCB_CAP_DCBX_VER_CEE;
1403 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1409 static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1411 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1413 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1414 struct qed_dcbx_set dcbx_set;
1415 struct qed_ptt *ptt;
1418 DP_VERBOSE(hwfn, QED_MSG_DCB,
1419 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1420 tc, pri_type, pgid, bw_pct, up_map);
1422 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1423 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1427 memset(&dcbx_set, 0, sizeof(dcbx_set));
1428 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1432 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1433 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1435 ptt = qed_ptt_acquire(hwfn);
1439 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1441 qed_ptt_release(hwfn, ptt);
1444 static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1445 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1447 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1450 static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1452 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1453 struct qed_dcbx_set dcbx_set;
1454 struct qed_ptt *ptt;
1457 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1458 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1459 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1463 memset(&dcbx_set, 0, sizeof(dcbx_set));
1464 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1468 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1469 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1471 ptt = qed_ptt_acquire(hwfn);
1475 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1477 qed_ptt_release(hwfn, ptt);
1480 static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1482 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1485 static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1487 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1488 struct qed_dcbx_set dcbx_set;
1489 struct qed_ptt *ptt;
1492 memset(&dcbx_set, 0, sizeof(dcbx_set));
1493 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1497 ptt = qed_ptt_acquire(hwfn);
1501 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1503 qed_ptt_release(hwfn, ptt);
1508 static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1510 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1511 struct qed_dcbx_set dcbx_set;
1512 struct qed_ptt *ptt;
1515 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1516 memset(&dcbx_set, 0, sizeof(dcbx_set));
1517 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1522 case DCB_NUMTCS_ATTR_PG:
1523 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1524 dcbx_set.config.params.max_ets_tc = num;
1526 case DCB_NUMTCS_ATTR_PFC:
1527 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1528 dcbx_set.config.params.pfc.max_tc = num;
1531 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1535 ptt = qed_ptt_acquire(hwfn);
1539 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1541 qed_ptt_release(hwfn, ptt);
1546 static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1548 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1549 struct qed_dcbx_set dcbx_set;
1550 struct qed_ptt *ptt;
1553 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1555 memset(&dcbx_set, 0, sizeof(dcbx_set));
1556 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1560 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1561 dcbx_set.config.params.pfc.enabled = !!state;
1563 ptt = qed_ptt_acquire(hwfn);
1567 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1569 qed_ptt_release(hwfn, ptt);
1572 static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1574 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1575 struct qed_dcbx_get *dcbx_info;
1576 struct qed_app_entry *entry;
1581 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1585 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1586 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1587 entry = &dcbx_info->operational.params.app_entry[i];
1588 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1594 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1595 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1605 static int qed_dcbnl_setapp(struct qed_dev *cdev,
1606 u8 idtype, u16 idval, u8 pri_map)
1608 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1609 struct qed_dcbx_set dcbx_set;
1610 struct qed_app_entry *entry;
1611 struct qed_ptt *ptt;
1615 memset(&dcbx_set, 0, sizeof(dcbx_set));
1616 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1620 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1621 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1622 entry = &dcbx_set.config.params.app_entry[i];
1623 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1625 /* First empty slot */
1626 if (!entry->proto_id)
1630 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1631 DP_ERR(cdev, "App table is full\n");
1635 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1636 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1637 dcbx_set.config.params.app_entry[i].proto_id = idval;
1638 dcbx_set.config.params.app_entry[i].prio = pri_map;
1640 ptt = qed_ptt_acquire(hwfn);
1644 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1646 qed_ptt_release(hwfn, ptt);
1651 static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1653 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1654 struct qed_dcbx_set dcbx_set;
1655 struct qed_ptt *ptt;
1658 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1660 if (!(mode & DCB_CAP_DCBX_VER_IEEE) && !(mode & DCB_CAP_DCBX_VER_CEE)) {
1661 DP_INFO(hwfn, "Allowed mode is cee, ieee or both\n");
1665 memset(&dcbx_set, 0, sizeof(dcbx_set));
1666 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1670 dcbx_set.ver_num = 0;
1671 if (mode & DCB_CAP_DCBX_VER_CEE) {
1672 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1673 dcbx_set.enabled = true;
1676 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1677 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1678 dcbx_set.enabled = true;
1681 ptt = qed_ptt_acquire(hwfn);
1685 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1687 qed_ptt_release(hwfn, ptt);
1692 static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1694 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1695 struct qed_dcbx_get *dcbx_info;
1697 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1698 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1704 case DCB_FEATCFG_ATTR_PG:
1705 if (dcbx_info->operational.params.ets_enabled)
1706 *flags = DCB_FEATCFG_ENABLE;
1708 *flags = DCB_FEATCFG_ERROR;
1710 case DCB_FEATCFG_ATTR_PFC:
1711 if (dcbx_info->operational.params.pfc.enabled)
1712 *flags = DCB_FEATCFG_ENABLE;
1714 *flags = DCB_FEATCFG_ERROR;
1716 case DCB_FEATCFG_ATTR_APP:
1717 if (dcbx_info->operational.params.app_valid)
1718 *flags = DCB_FEATCFG_ENABLE;
1720 *flags = DCB_FEATCFG_ERROR;
1723 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1728 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1734 static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1736 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1737 struct qed_dcbx_set dcbx_set;
1738 bool enabled, willing;
1739 struct qed_ptt *ptt;
1742 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1744 memset(&dcbx_set, 0, sizeof(dcbx_set));
1745 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1749 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1750 willing = !!(flags & DCB_FEATCFG_WILLING);
1752 case DCB_FEATCFG_ATTR_PG:
1753 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1754 dcbx_set.config.params.ets_enabled = enabled;
1755 dcbx_set.config.params.ets_willing = willing;
1757 case DCB_FEATCFG_ATTR_PFC:
1758 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1759 dcbx_set.config.params.pfc.enabled = enabled;
1760 dcbx_set.config.params.pfc.willing = willing;
1762 case DCB_FEATCFG_ATTR_APP:
1763 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1764 dcbx_set.config.params.app_willing = willing;
1767 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1771 ptt = qed_ptt_acquire(hwfn);
1775 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1777 qed_ptt_release(hwfn, ptt);
1782 static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1783 struct dcb_peer_app_info *info,
1786 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1787 struct qed_dcbx_get *dcbx_info;
1789 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1793 info->willing = dcbx_info->remote.params.app_willing;
1794 info->error = dcbx_info->remote.params.app_error;
1795 *app_count = dcbx_info->remote.params.num_app_entries;
1801 static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1802 struct dcb_app *table)
1804 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1805 struct qed_dcbx_get *dcbx_info;
1808 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1812 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
1813 if (dcbx_info->remote.params.app_entry[i].ethtype)
1814 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
1816 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
1817 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
1819 dcbx_info->remote.params.app_entry[i].proto_id;
1827 static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
1829 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1830 struct qed_dcbx_get *dcbx_info;
1833 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1837 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1838 if (dcbx_info->remote.params.pfc.prio[i])
1839 pfc->pfc_en |= BIT(i);
1841 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
1842 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
1843 pfc->pfc_en, pfc->tcs_supported);
1849 static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
1851 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1852 struct qed_dcbx_get *dcbx_info;
1855 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1859 pg->willing = dcbx_info->remote.params.ets_willing;
1860 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1861 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
1862 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
1865 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
1871 static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
1872 struct ieee_pfc *pfc, bool remote)
1874 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1875 struct qed_dcbx_params *params;
1876 struct qed_dcbx_get *dcbx_info;
1879 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1883 if (!dcbx_info->operational.ieee) {
1884 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
1889 memset(dcbx_info, 0, sizeof(*dcbx_info));
1890 rc = qed_dcbx_query_params(hwfn, dcbx_info,
1891 QED_DCBX_REMOTE_MIB);
1897 params = &dcbx_info->remote.params;
1899 params = &dcbx_info->operational.params;
1902 pfc->pfc_cap = params->pfc.max_tc;
1904 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1905 if (params->pfc.prio[i])
1906 pfc->pfc_en |= BIT(i);
1913 static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
1915 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
1918 static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
1920 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1921 struct qed_dcbx_get *dcbx_info;
1922 struct qed_dcbx_set dcbx_set;
1923 struct qed_ptt *ptt;
1926 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1930 if (!dcbx_info->operational.ieee) {
1931 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
1938 memset(&dcbx_set, 0, sizeof(dcbx_set));
1939 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1943 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1944 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1945 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
1947 ptt = qed_ptt_acquire(hwfn);
1951 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1953 qed_ptt_release(hwfn, ptt);
1958 static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
1959 struct ieee_ets *ets, bool remote)
1961 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1962 struct qed_dcbx_get *dcbx_info;
1963 struct qed_dcbx_params *params;
1966 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1970 if (!dcbx_info->operational.ieee) {
1971 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
1977 memset(dcbx_info, 0, sizeof(*dcbx_info));
1978 rc = qed_dcbx_query_params(hwfn, dcbx_info,
1979 QED_DCBX_REMOTE_MIB);
1985 params = &dcbx_info->remote.params;
1987 params = &dcbx_info->operational.params;
1990 ets->ets_cap = params->max_ets_tc;
1991 ets->willing = params->ets_willing;
1992 ets->cbs = params->ets_cbs;
1993 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
1994 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
1995 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2001 static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2003 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2006 static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2008 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2009 struct qed_dcbx_get *dcbx_info;
2010 struct qed_dcbx_set dcbx_set;
2011 struct qed_ptt *ptt;
2014 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2018 if (!dcbx_info->operational.ieee) {
2019 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2026 memset(&dcbx_set, 0, sizeof(dcbx_set));
2027 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2031 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2032 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2033 dcbx_set.config.params.ets_willing = ets->willing;
2034 dcbx_set.config.params.ets_cbs = ets->cbs;
2035 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2036 sizeof(ets->tc_tx_bw));
2037 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2038 sizeof(ets->tc_tsa));
2039 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2040 sizeof(ets->prio_tc));
2042 ptt = qed_ptt_acquire(hwfn);
2046 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2048 qed_ptt_release(hwfn, ptt);
2053 int qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2055 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2058 int qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2060 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2063 int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
2065 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2066 struct qed_dcbx_get *dcbx_info;
2067 struct qed_app_entry *entry;
2072 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2076 if (!dcbx_info->operational.ieee) {
2077 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2082 /* ieee defines the selector field value for ethertype to be 1 */
2083 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
2084 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2085 entry = &dcbx_info->operational.params.app_entry[i];
2086 if ((entry->ethtype == ethtype) &&
2087 (entry->proto_id == app->protocol)) {
2093 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2094 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2100 app->priority = ffs(prio) - 1;
2107 int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
2109 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2110 struct qed_dcbx_get *dcbx_info;
2111 struct qed_dcbx_set dcbx_set;
2112 struct qed_app_entry *entry;
2113 struct qed_ptt *ptt;
2117 if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) {
2118 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2122 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2126 if (!dcbx_info->operational.ieee) {
2127 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2134 memset(&dcbx_set, 0, sizeof(dcbx_set));
2135 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2139 /* ieee defines the selector field value for ethertype to be 1 */
2140 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
2141 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2142 entry = &dcbx_set.config.params.app_entry[i];
2143 if ((entry->ethtype == ethtype) &&
2144 (entry->proto_id == app->protocol))
2146 /* First empty slot */
2147 if (!entry->proto_id)
2151 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2152 DP_ERR(cdev, "App table is full\n");
2156 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
2157 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
2158 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2159 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2161 ptt = qed_ptt_acquire(hwfn);
2165 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2167 qed_ptt_release(hwfn, ptt);
2172 const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2173 .getstate = qed_dcbnl_getstate,
2174 .setstate = qed_dcbnl_setstate,
2175 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2176 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2177 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2178 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2179 .getpfccfg = qed_dcbnl_getpfccfg,
2180 .setpfccfg = qed_dcbnl_setpfccfg,
2181 .getcap = qed_dcbnl_getcap,
2182 .getnumtcs = qed_dcbnl_getnumtcs,
2183 .getpfcstate = qed_dcbnl_getpfcstate,
2184 .getdcbx = qed_dcbnl_getdcbx,
2185 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2186 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2187 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2188 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2189 .setall = qed_dcbnl_setall,
2190 .setnumtcs = qed_dcbnl_setnumtcs,
2191 .setpfcstate = qed_dcbnl_setpfcstate,
2192 .setapp = qed_dcbnl_setapp,
2193 .setdcbx = qed_dcbnl_setdcbx,
2194 .setfeatcfg = qed_dcbnl_setfeatcfg,
2195 .getfeatcfg = qed_dcbnl_getfeatcfg,
2196 .getapp = qed_dcbnl_getapp,
2197 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2198 .peer_getapptable = qed_dcbnl_peer_getapptable,
2199 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2200 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2201 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2202 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2203 .ieee_getets = qed_dcbnl_ieee_getets,
2204 .ieee_setets = qed_dcbnl_ieee_setets,
2205 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2206 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2207 .ieee_getapp = qed_dcbnl_ieee_getapp,
2208 .ieee_setapp = qed_dcbnl_ieee_setapp,