1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/types.h>
34 #include <asm/byteorder.h>
35 #include <linux/bitops.h>
36 #include <linux/dcbnl.h>
37 #include <linux/errno.h>
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/string.h>
46 #include "qed_sriov.h"
49 #include <linux/qed/qed_eth_if.h>
52 #define QED_DCBX_MAX_MIB_READ_TRY (100)
53 #define QED_ETH_TYPE_DEFAULT (0)
54 #define QED_ETH_TYPE_ROCE (0x8915)
55 #define QED_UDP_PORT_TYPE_ROCE_V2 (0x12B7)
56 #define QED_ETH_TYPE_FCOE (0x8906)
57 #define QED_TCP_PORT_ISCSI (0xCBC)
59 #define QED_DCBX_INVALID_PRIORITY 0xFF
61 /* Get Traffic Class from priority traffic class table, 4 bits represent
62 * the traffic class corresponding to the priority.
64 #define QED_DCBX_PRIO2TC(prio_tc_tbl, prio) \
65 ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
67 static const struct qed_dcbx_app_metadata qed_dcbx_app_update[] = {
68 {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_ISCSI},
69 {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_FCOE},
70 {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_ETH_ROCE},
71 {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_ETH_ROCE},
72 {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH},
75 static bool qed_dcbx_app_ethtype(u32 app_info_bitmap)
77 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
81 static bool qed_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
83 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
86 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
87 return qed_dcbx_app_ethtype(app_info_bitmap);
89 return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
92 static bool qed_dcbx_app_port(u32 app_info_bitmap)
94 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
98 static bool qed_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
100 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
103 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
104 return qed_dcbx_app_port(app_info_bitmap);
106 return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
109 static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
114 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
116 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
118 return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT));
121 static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
126 port = qed_dcbx_ieee_app_port(app_info_bitmap,
127 DCBX_APP_SF_IEEE_TCP_PORT);
129 port = qed_dcbx_app_port(app_info_bitmap);
131 return !!(port && (proto_id == QED_TCP_PORT_ISCSI));
134 static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
139 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
141 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
143 return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE));
146 static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
151 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
153 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
155 return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE));
158 static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
163 port = qed_dcbx_ieee_app_port(app_info_bitmap,
164 DCBX_APP_SF_IEEE_UDP_PORT);
166 port = qed_dcbx_app_port(app_info_bitmap);
168 return !!(port && (proto_id == QED_UDP_PORT_TYPE_ROCE_V2));
172 qed_dcbx_dp_protocol(struct qed_hwfn *p_hwfn, struct qed_dcbx_results *p_data)
174 enum dcbx_protocol_type id;
177 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "DCBX negotiated: %d\n",
178 p_data->dcbx_enabled);
180 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
181 id = qed_dcbx_app_update[i].id;
183 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
184 "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n",
185 qed_dcbx_app_update[i].name, p_data->arr[id].update,
186 p_data->arr[id].enable, p_data->arr[id].priority,
187 p_data->arr[id].tc, p_hwfn->hw_info.num_active_tc);
192 qed_dcbx_set_params(struct qed_dcbx_results *p_data,
193 struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
194 bool enable, u8 prio, u8 tc,
195 enum dcbx_protocol_type type,
196 enum qed_pci_personality personality)
198 /* PF update ramrod data */
199 p_data->arr[type].enable = enable;
200 p_data->arr[type].priority = prio;
201 p_data->arr[type].tc = tc;
203 p_data->arr[type].update = UPDATE_DCB;
205 p_data->arr[type].update = DONT_UPDATE_DCB_DSCP;
207 /* Do not add vlan tag 0 when DCB is enabled and port in UFP/OV mode */
208 if ((test_bit(QED_MF_8021Q_TAGGING, &p_hwfn->cdev->mf_bits) ||
209 test_bit(QED_MF_8021AD_TAGGING, &p_hwfn->cdev->mf_bits)))
210 p_data->arr[type].dont_add_vlan0 = true;
213 if (p_hwfn->hw_info.personality == personality)
214 qed_hw_info_set_offload_tc(&p_hwfn->hw_info, tc);
216 /* Configure dcbx vlan priority in doorbell block for roce EDPM */
217 if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) &&
218 type == DCBX_PROTOCOL_ROCE) {
219 qed_wr(p_hwfn, p_ptt, DORQ_REG_TAG1_OVRD_MODE, 1);
220 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_PCP_BB_K2, prio << 1);
224 /* Update app protocol data and hw_info fields with the TLV info */
226 qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
227 struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
228 bool enable, u8 prio, u8 tc,
229 enum dcbx_protocol_type type)
231 enum qed_pci_personality personality;
232 enum dcbx_protocol_type id;
235 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
236 id = qed_dcbx_app_update[i].id;
241 personality = qed_dcbx_app_update[i].personality;
243 qed_dcbx_set_params(p_data, p_hwfn, p_ptt, enable,
244 prio, tc, type, personality);
249 qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
251 u16 id, enum dcbx_protocol_type *type, bool ieee)
253 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
254 *type = DCBX_PROTOCOL_FCOE;
255 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
256 *type = DCBX_PROTOCOL_ROCE;
257 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
258 *type = DCBX_PROTOCOL_ISCSI;
259 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
260 *type = DCBX_PROTOCOL_ETH;
261 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
262 *type = DCBX_PROTOCOL_ROCE_V2;
264 *type = DCBX_MAX_PROTOCOL_TYPE;
265 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
266 "No action required, App TLV entry = 0x%x\n",
274 /* Parse app TLV's to update TC information in hw_info structure for
275 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
278 qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
279 struct qed_dcbx_results *p_data,
280 struct dcbx_app_priority_entry *p_tbl,
281 u32 pri_tc_tbl, int count, u8 dcbx_version)
283 enum dcbx_protocol_type type;
284 bool enable, ieee, eth_tlv;
290 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
292 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
295 for (i = 0; i < count; i++) {
296 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
297 DCBX_APP_PROTOCOL_ID);
298 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
300 priority = ffs(priority_map) - 1;
302 DP_ERR(p_hwfn, "Invalid priority\n");
306 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
307 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
308 protocol_id, &type, ieee)) {
309 /* ETH always have the enable bit reset, as it gets
310 * vlan information per packet. For other protocols,
311 * should be set according to the dcbx_enabled
312 * indication, but we only got here if there was an
313 * app tlv for the protocol, so dcbx must be enabled.
315 if (type == DCBX_PROTOCOL_ETH) {
322 qed_dcbx_update_app_info(p_data, p_hwfn, p_ptt, enable,
327 /* If Eth TLV is not detected, use UFP TC as default TC */
328 if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) && !eth_tlv)
329 p_data->arr[DCBX_PROTOCOL_ETH].tc = p_hwfn->ufp_info.tc;
331 /* Update ramrod protocol data and hw_info fields
332 * with default info when corresponding APP TLV's are not detected.
333 * The enabled field has a different logic for ethernet as only for
334 * ethernet dcb should disabled by default, as the information arrives
335 * from the OS (unless an explicit app tlv was present).
337 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
338 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
339 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
340 if (p_data->arr[type].update)
343 enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
344 qed_dcbx_update_app_info(p_data, p_hwfn, p_ptt, enable,
351 /* Parse app TLV's to update TC information in hw_info structure for
352 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
355 qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
357 struct dcbx_app_priority_feature *p_app;
358 struct dcbx_app_priority_entry *p_tbl;
359 struct qed_dcbx_results data = { 0 };
360 struct dcbx_ets_feature *p_ets;
361 struct qed_hw_info *p_info;
362 u32 pri_tc_tbl, flags;
367 flags = p_hwfn->p_dcbx_info->operational.flags;
368 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
370 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
371 p_tbl = p_app->app_pri_tbl;
373 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
374 pri_tc_tbl = p_ets->pri_tc_tbl[0];
376 p_info = &p_hwfn->hw_info;
377 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
379 rc = qed_dcbx_process_tlv(p_hwfn, p_ptt, &data, p_tbl, pri_tc_tbl,
380 num_entries, dcbx_version);
384 p_info->num_active_tc = QED_MFW_GET_FIELD(p_ets->flags,
386 p_hwfn->qm_info.ooo_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
387 data.pf_id = p_hwfn->rel_pf_id;
388 data.dcbx_enabled = !!dcbx_version;
390 qed_dcbx_dp_protocol(p_hwfn, &data);
392 memcpy(&p_hwfn->p_dcbx_info->results, &data,
393 sizeof(struct qed_dcbx_results));
399 qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
400 struct qed_ptt *p_ptt,
401 struct qed_dcbx_mib_meta_data *p_data,
402 enum qed_mib_read_type type)
404 u32 prefix_seq_num, suffix_seq_num;
408 /* The data is considered to be valid only if both sequence numbers are
412 if (type == QED_DCBX_REMOTE_LLDP_MIB) {
413 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
414 p_data->addr, p_data->size);
415 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
416 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
418 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
419 p_data->addr, p_data->size);
420 prefix_seq_num = p_data->mib->prefix_seq_num;
421 suffix_seq_num = p_data->mib->suffix_seq_num;
427 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
428 type, read_count, prefix_seq_num, suffix_seq_num);
429 } while ((prefix_seq_num != suffix_seq_num) &&
430 (read_count < QED_DCBX_MAX_MIB_READ_TRY));
432 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
434 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
435 type, read_count, prefix_seq_num, suffix_seq_num);
443 qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
444 struct qed_dcbx_app_prio *p_prio,
445 struct qed_dcbx_results *p_results)
449 p_prio->roce = QED_DCBX_INVALID_PRIORITY;
450 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
451 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
452 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
454 if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
455 p_results->arr[DCBX_PROTOCOL_ROCE].enable)
456 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
458 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
459 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
460 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
461 p_prio->roce_v2 = val;
464 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
465 p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
466 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
468 if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
469 p_results->arr[DCBX_PROTOCOL_FCOE].enable)
470 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
472 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
473 p_results->arr[DCBX_PROTOCOL_ETH].enable)
474 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
476 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
477 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
478 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
483 qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
484 struct dcbx_app_priority_feature *p_app,
485 struct dcbx_app_priority_entry *p_tbl,
486 struct qed_dcbx_params *p_params, bool ieee)
488 struct qed_app_entry *entry;
492 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
494 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
495 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
496 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
497 DCBX_APP_NUM_ENTRIES);
498 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
499 entry = &p_params->app_entry[i];
504 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
507 case DCBX_APP_SF_IEEE_RESERVED:
509 val = QED_MFW_GET_FIELD(p_tbl[i].entry,
511 entry->sf_ieee = val ?
512 QED_DCBX_SF_IEEE_TCP_UDP_PORT :
513 QED_DCBX_SF_IEEE_ETHTYPE;
515 case DCBX_APP_SF_IEEE_ETHTYPE:
516 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
518 case DCBX_APP_SF_IEEE_TCP_PORT:
519 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
521 case DCBX_APP_SF_IEEE_UDP_PORT:
522 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
524 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
525 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
529 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
533 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
534 entry->prio = ffs(pri_map) - 1;
535 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
536 DCBX_APP_PROTOCOL_ID);
537 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
539 &entry->proto_type, ieee);
542 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
543 "APP params: willing %d, valid %d error = %d\n",
544 p_params->app_willing, p_params->app_valid,
545 p_params->app_error);
549 qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
550 u32 pfc, struct qed_dcbx_params *p_params)
554 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
555 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
556 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
557 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
558 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
559 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
560 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
561 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
562 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
563 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
564 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
565 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
567 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
568 "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
569 p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
570 p_params->pfc.enabled);
574 qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
575 struct dcbx_ets_feature *p_ets,
576 struct qed_dcbx_params *p_params)
578 u32 bw_map[2], tsa_map[2], pri_map;
581 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
583 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
585 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
586 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
588 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
589 "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
590 p_params->ets_willing, p_params->ets_enabled,
591 p_params->ets_cbs, p_ets->pri_tc_tbl[0],
592 p_params->max_ets_tc);
594 if (p_params->ets_enabled && !p_params->max_ets_tc) {
595 p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
596 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
597 "ETS params: max_ets_tc is forced to %d\n",
598 p_params->max_ets_tc);
601 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
602 * encoded in a type u32 array of size 2.
604 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
605 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
606 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
607 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
608 pri_map = p_ets->pri_tc_tbl[0];
609 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
610 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
611 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
612 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
613 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
614 "elem %d bw_tbl %x tsa_tbl %x\n",
615 i, p_params->ets_tc_bw_tbl[i],
616 p_params->ets_tc_tsa_tbl[i]);
621 qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
622 struct dcbx_app_priority_feature *p_app,
623 struct dcbx_app_priority_entry *p_tbl,
624 struct dcbx_ets_feature *p_ets,
625 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
627 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
628 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
629 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
633 qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
635 struct dcbx_features *p_feat;
637 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
638 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
639 p_feat->app.app_pri_tbl, &p_feat->ets,
640 p_feat->pfc, ¶ms->local.params, false);
641 params->local.valid = true;
645 qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
647 struct dcbx_features *p_feat;
649 p_feat = &p_hwfn->p_dcbx_info->remote.features;
650 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
651 p_feat->app.app_pri_tbl, &p_feat->ets,
652 p_feat->pfc, ¶ms->remote.params, false);
653 params->remote.valid = true;
657 qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
658 struct qed_dcbx_get *params)
660 struct qed_dcbx_operational_params *p_operational;
661 struct qed_dcbx_results *p_results;
662 struct dcbx_features *p_feat;
667 flags = p_hwfn->p_dcbx_info->operational.flags;
669 /* If DCBx version is non zero, then negotiation
670 * was successfuly performed
672 p_operational = ¶ms->operational;
673 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
674 DCBX_CONFIG_VERSION_DISABLED);
676 p_operational->enabled = enabled;
677 p_operational->valid = false;
678 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx is disabled\n");
682 p_feat = &p_hwfn->p_dcbx_info->operational.features;
683 p_results = &p_hwfn->p_dcbx_info->results;
685 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
686 DCBX_CONFIG_VERSION_IEEE);
687 p_operational->ieee = val;
688 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
689 DCBX_CONFIG_VERSION_CEE);
690 p_operational->cee = val;
692 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
693 DCBX_CONFIG_VERSION_STATIC);
694 p_operational->local = val;
696 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
697 "Version support: ieee %d, cee %d, static %d\n",
698 p_operational->ieee, p_operational->cee,
699 p_operational->local);
701 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
702 p_feat->app.app_pri_tbl, &p_feat->ets,
703 p_feat->pfc, ¶ms->operational.params,
704 p_operational->ieee);
705 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
706 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
707 p_operational->err = err;
708 p_operational->enabled = enabled;
709 p_operational->valid = true;
713 qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
714 struct qed_dcbx_get *params)
716 struct lldp_config_params_s *p_local;
718 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
720 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
721 sizeof(p_local->local_chassis_id));
722 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
723 sizeof(p_local->local_port_id));
727 qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
728 struct qed_dcbx_get *params)
730 struct lldp_status_params_s *p_remote;
732 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
734 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
735 sizeof(p_remote->peer_chassis_id));
736 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
737 sizeof(p_remote->peer_port_id));
741 qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
742 enum qed_mib_read_type type)
745 case QED_DCBX_REMOTE_MIB:
746 qed_dcbx_get_remote_params(p_hwfn, p_params);
748 case QED_DCBX_LOCAL_MIB:
749 qed_dcbx_get_local_params(p_hwfn, p_params);
751 case QED_DCBX_OPERATIONAL_MIB:
752 qed_dcbx_get_operational_params(p_hwfn, p_params);
754 case QED_DCBX_REMOTE_LLDP_MIB:
755 qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
757 case QED_DCBX_LOCAL_LLDP_MIB:
758 qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
761 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
769 qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
771 struct qed_dcbx_mib_meta_data data;
774 memset(&data, 0, sizeof(data));
775 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
777 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
778 data.size = sizeof(struct lldp_config_params_s);
779 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
785 qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
786 struct qed_ptt *p_ptt,
787 enum qed_mib_read_type type)
789 struct qed_dcbx_mib_meta_data data;
792 memset(&data, 0, sizeof(data));
793 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
795 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
796 data.size = sizeof(struct lldp_status_params_s);
797 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
803 qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
804 struct qed_ptt *p_ptt,
805 enum qed_mib_read_type type)
807 struct qed_dcbx_mib_meta_data data;
810 memset(&data, 0, sizeof(data));
811 data.addr = p_hwfn->mcp_info->port_addr +
812 offsetof(struct public_port, operational_dcbx_mib);
813 data.mib = &p_hwfn->p_dcbx_info->operational;
814 data.size = sizeof(struct dcbx_mib);
815 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
821 qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
822 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
824 struct qed_dcbx_mib_meta_data data;
827 memset(&data, 0, sizeof(data));
828 data.addr = p_hwfn->mcp_info->port_addr +
829 offsetof(struct public_port, remote_dcbx_mib);
830 data.mib = &p_hwfn->p_dcbx_info->remote;
831 data.size = sizeof(struct dcbx_mib);
832 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
838 qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
840 struct qed_dcbx_mib_meta_data data;
843 memset(&data, 0, sizeof(data));
844 data.addr = p_hwfn->mcp_info->port_addr +
845 offsetof(struct public_port, local_admin_dcbx_mib);
846 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
847 data.size = sizeof(struct dcbx_local_params);
848 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
853 static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
854 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
859 case QED_DCBX_OPERATIONAL_MIB:
860 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
862 case QED_DCBX_REMOTE_MIB:
863 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
865 case QED_DCBX_LOCAL_MIB:
866 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
868 case QED_DCBX_REMOTE_LLDP_MIB:
869 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
871 case QED_DCBX_LOCAL_LLDP_MIB:
872 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
875 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
881 static void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
883 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
884 void *cookie = hwfn->cdev->ops_cookie;
886 if (cookie && op->dcbx_aen)
887 op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
891 * Reconfigure QM and invoke PF update ramrod command if operational MIB
892 * change is detected.
895 qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
896 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
900 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
904 if (type == QED_DCBX_OPERATIONAL_MIB) {
905 rc = qed_dcbx_process_mib_info(p_hwfn, p_ptt);
907 /* reconfigure tcs of QM queues according
908 * to negotiation results
910 qed_qm_reconf(p_hwfn, p_ptt);
912 /* update storm FW with negotiation results */
913 qed_sp_pf_update(p_hwfn);
915 /* for roce PFs, we may want to enable/disable DPM
916 * when DCBx change occurs
918 if (p_hwfn->hw_info.personality ==
920 qed_roce_dpm_dcbx(p_hwfn, p_ptt);
924 qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
926 if (type == QED_DCBX_OPERATIONAL_MIB) {
927 struct qed_dcbx_results *p_data;
930 /* Configure in NIG which protocols support EDPM and should
933 p_data = &p_hwfn->p_dcbx_info->results;
934 val = (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE].tc) |
935 (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE_V2].tc);
936 val <<= NIG_REG_TX_EDPM_CTRL_TX_EDPM_TC_EN_SHIFT;
937 val |= NIG_REG_TX_EDPM_CTRL_TX_EDPM_EN;
938 qed_wr(p_hwfn, p_ptt, NIG_REG_TX_EDPM_CTRL, val);
941 qed_dcbx_aen(p_hwfn, type);
946 int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
948 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
949 if (!p_hwfn->p_dcbx_info)
955 void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
957 kfree(p_hwfn->p_dcbx_info);
958 p_hwfn->p_dcbx_info = NULL;
961 static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
962 struct qed_dcbx_results *p_src,
963 enum dcbx_protocol_type type)
965 p_data->dcb_enable_flag = p_src->arr[type].enable;
966 p_data->dcb_priority = p_src->arr[type].priority;
967 p_data->dcb_tc = p_src->arr[type].tc;
968 p_data->dcb_dont_add_vlan0 = p_src->arr[type].dont_add_vlan0;
971 /* Set pf update ramrod command params */
972 void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
973 struct pf_update_ramrod_data *p_dest)
975 struct protocol_dcb_data *p_dcb_data;
978 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
979 p_dest->update_fcoe_dcb_data_mode = update_flag;
981 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
982 p_dest->update_roce_dcb_data_mode = update_flag;
984 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
985 p_dest->update_rroce_dcb_data_mode = update_flag;
987 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
988 p_dest->update_iscsi_dcb_data_mode = update_flag;
989 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
990 p_dest->update_eth_dcb_data_mode = update_flag;
992 p_dcb_data = &p_dest->fcoe_dcb_data;
993 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
994 p_dcb_data = &p_dest->roce_dcb_data;
995 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
996 p_dcb_data = &p_dest->rroce_dcb_data;
997 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
998 p_dcb_data = &p_dest->iscsi_dcb_data;
999 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
1000 p_dcb_data = &p_dest->eth_dcb_data;
1001 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
1004 u8 qed_dcbx_get_priority_tc(struct qed_hwfn *p_hwfn, u8 pri)
1006 struct qed_dcbx_get *dcbx_info = &p_hwfn->p_dcbx_info->get;
1008 if (pri >= QED_MAX_PFC_PRIORITIES) {
1009 DP_ERR(p_hwfn, "Invalid priority %d\n", pri);
1010 return QED_DCBX_DEFAULT_TC;
1013 if (!dcbx_info->operational.valid) {
1014 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
1015 "Dcbx parameters not available\n");
1016 return QED_DCBX_DEFAULT_TC;
1019 return dcbx_info->operational.params.ets_pri_tc_tbl[pri];
1023 static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
1024 struct qed_dcbx_get *p_get,
1025 enum qed_mib_read_type type)
1027 struct qed_ptt *p_ptt;
1030 if (IS_VF(p_hwfn->cdev))
1033 p_ptt = qed_ptt_acquire(p_hwfn);
1037 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
1041 rc = qed_dcbx_get_params(p_hwfn, p_get, type);
1044 qed_ptt_release(p_hwfn, p_ptt);
1049 qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
1050 u32 *pfc, struct qed_dcbx_params *p_params)
1055 *pfc &= ~DCBX_PFC_ERROR_MASK;
1057 if (p_params->pfc.willing)
1058 *pfc |= DCBX_PFC_WILLING_MASK;
1060 *pfc &= ~DCBX_PFC_WILLING_MASK;
1062 if (p_params->pfc.enabled)
1063 *pfc |= DCBX_PFC_ENABLED_MASK;
1065 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1067 *pfc &= ~DCBX_PFC_CAPS_MASK;
1068 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
1070 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1071 if (p_params->pfc.prio[i])
1074 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
1075 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
1077 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
1081 qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
1082 struct dcbx_ets_feature *p_ets,
1083 struct qed_dcbx_params *p_params)
1085 u8 *bw_map, *tsa_map;
1089 if (p_params->ets_willing)
1090 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1092 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1094 if (p_params->ets_cbs)
1095 p_ets->flags |= DCBX_ETS_CBS_MASK;
1097 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1099 if (p_params->ets_enabled)
1100 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1102 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1104 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1105 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1107 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1108 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1109 p_ets->pri_tc_tbl[0] = 0;
1110 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1111 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1112 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1113 /* Copy the priority value to the corresponding 4 bits in the
1114 * traffic class table.
1116 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1117 p_ets->pri_tc_tbl[0] |= val;
1119 for (i = 0; i < 2; i++) {
1120 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1121 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1126 qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1127 struct dcbx_app_priority_feature *p_app,
1128 struct qed_dcbx_params *p_params, bool ieee)
1133 if (p_params->app_willing)
1134 p_app->flags |= DCBX_APP_WILLING_MASK;
1136 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1138 if (p_params->app_valid)
1139 p_app->flags |= DCBX_APP_ENABLED_MASK;
1141 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1143 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1144 p_app->flags |= (u32)p_params->num_app_entries <<
1145 DCBX_APP_NUM_ENTRIES_SHIFT;
1147 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1148 entry = &p_app->app_pri_tbl[i].entry;
1151 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
1152 switch (p_params->app_entry[i].sf_ieee) {
1153 case QED_DCBX_SF_IEEE_ETHTYPE:
1154 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1155 DCBX_APP_SF_IEEE_SHIFT);
1156 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1159 case QED_DCBX_SF_IEEE_TCP_PORT:
1160 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1161 DCBX_APP_SF_IEEE_SHIFT);
1162 *entry |= ((u32)DCBX_APP_SF_PORT <<
1165 case QED_DCBX_SF_IEEE_UDP_PORT:
1166 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1167 DCBX_APP_SF_IEEE_SHIFT);
1168 *entry |= ((u32)DCBX_APP_SF_PORT <<
1171 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1172 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1173 DCBX_APP_SF_IEEE_SHIFT);
1174 *entry |= ((u32)DCBX_APP_SF_PORT <<
1179 *entry &= ~DCBX_APP_SF_MASK;
1180 if (p_params->app_entry[i].ethtype)
1181 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1184 *entry |= ((u32)DCBX_APP_SF_PORT <<
1188 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1189 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1190 DCBX_APP_PROTOCOL_ID_SHIFT);
1191 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1192 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1193 DCBX_APP_PRI_MAP_SHIFT);
1198 qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1199 struct dcbx_local_params *local_admin,
1200 struct qed_dcbx_set *params)
1204 local_admin->flags = 0;
1205 memcpy(&local_admin->features,
1206 &p_hwfn->p_dcbx_info->operational.features,
1207 sizeof(local_admin->features));
1209 if (params->enabled) {
1210 local_admin->config = params->ver_num;
1211 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1213 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1216 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx version = %d\n",
1217 local_admin->config);
1219 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1220 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1221 ¶ms->config.params);
1223 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1224 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1225 ¶ms->config.params);
1227 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1228 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1229 ¶ms->config.params, ieee);
1232 int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1233 struct qed_dcbx_set *params, bool hw_commit)
1235 struct dcbx_local_params local_admin;
1236 struct qed_dcbx_mib_meta_data data;
1237 u32 resp = 0, param = 0;
1241 memcpy(&p_hwfn->p_dcbx_info->set, params,
1242 sizeof(struct qed_dcbx_set));
1246 /* clear set-parmas cache */
1247 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1249 memset(&local_admin, 0, sizeof(local_admin));
1250 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1252 data.addr = p_hwfn->mcp_info->port_addr +
1253 offsetof(struct public_port, local_admin_dcbx_mib);
1254 data.local_admin = &local_admin;
1255 data.size = sizeof(struct dcbx_local_params);
1256 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1258 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1259 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, ¶m);
1261 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1266 int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1267 struct qed_dcbx_set *params)
1269 struct qed_dcbx_get *dcbx_info;
1272 if (p_hwfn->p_dcbx_info->set.config.valid) {
1273 memcpy(params, &p_hwfn->p_dcbx_info->set,
1274 sizeof(struct qed_dcbx_set));
1278 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
1282 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1288 p_hwfn->p_dcbx_info->set.override_flags = 0;
1289 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1290 if (dcbx_info->operational.cee)
1291 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1292 if (dcbx_info->operational.ieee)
1293 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1294 if (dcbx_info->operational.local)
1295 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1297 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1298 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1299 &dcbx_info->operational.params,
1300 sizeof(struct qed_dcbx_admin_params));
1301 p_hwfn->p_dcbx_info->set.config.valid = true;
1303 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1310 static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1311 enum qed_mib_read_type type)
1313 struct qed_dcbx_get *dcbx_info;
1315 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_ATOMIC);
1319 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1324 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1325 !dcbx_info->operational.enabled) {
1326 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1334 static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1336 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1337 struct qed_dcbx_get *dcbx_info;
1340 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1344 enabled = dcbx_info->operational.enabled;
1345 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1351 static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1353 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1354 struct qed_dcbx_set dcbx_set;
1355 struct qed_ptt *ptt;
1358 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1360 memset(&dcbx_set, 0, sizeof(dcbx_set));
1361 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1365 dcbx_set.enabled = !!state;
1367 ptt = qed_ptt_acquire(hwfn);
1371 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1373 qed_ptt_release(hwfn, ptt);
1378 static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1379 u8 *pgid, u8 *bw_pct, u8 *up_map)
1381 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1382 struct qed_dcbx_get *dcbx_info;
1384 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1385 *prio_type = *pgid = *bw_pct = *up_map = 0;
1386 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1387 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1391 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1395 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1399 static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1401 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1402 struct qed_dcbx_get *dcbx_info;
1405 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1406 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1407 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1411 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1415 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1416 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1420 static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1421 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1423 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1424 *prio = *bwg_id = *bw_pct = *up_map = 0;
1427 static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1428 int bwg_id, u8 *bw_pct)
1430 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1434 static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1435 int priority, u8 *setting)
1437 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1438 struct qed_dcbx_get *dcbx_info;
1440 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1441 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1442 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1446 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1450 *setting = dcbx_info->operational.params.pfc.prio[priority];
1451 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1455 static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1457 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1458 struct qed_dcbx_set dcbx_set;
1459 struct qed_ptt *ptt;
1462 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1464 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1465 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1469 memset(&dcbx_set, 0, sizeof(dcbx_set));
1470 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1474 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1475 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1477 ptt = qed_ptt_acquire(hwfn);
1481 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1483 qed_ptt_release(hwfn, ptt);
1486 static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1488 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1489 struct qed_dcbx_get *dcbx_info;
1492 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1493 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1498 case DCB_CAP_ATTR_PG:
1499 case DCB_CAP_ATTR_PFC:
1500 case DCB_CAP_ATTR_UP2TC:
1501 case DCB_CAP_ATTR_GSP:
1504 case DCB_CAP_ATTR_PG_TCS:
1505 case DCB_CAP_ATTR_PFC_TCS:
1508 case DCB_CAP_ATTR_DCBX:
1509 *cap = (DCB_CAP_DCBX_VER_CEE | DCB_CAP_DCBX_VER_IEEE |
1510 DCB_CAP_DCBX_STATIC);
1517 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1523 static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1525 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1526 struct qed_dcbx_get *dcbx_info;
1529 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1530 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1535 case DCB_NUMTCS_ATTR_PG:
1536 *num = dcbx_info->operational.params.max_ets_tc;
1538 case DCB_NUMTCS_ATTR_PFC:
1539 *num = dcbx_info->operational.params.pfc.max_tc;
1546 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1551 static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1553 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1554 struct qed_dcbx_get *dcbx_info;
1557 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1561 enabled = dcbx_info->operational.params.pfc.enabled;
1562 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1568 static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1570 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1571 struct qed_dcbx_get *dcbx_info;
1574 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1578 if (dcbx_info->operational.ieee)
1579 mode |= DCB_CAP_DCBX_VER_IEEE;
1580 if (dcbx_info->operational.cee)
1581 mode |= DCB_CAP_DCBX_VER_CEE;
1582 if (dcbx_info->operational.local)
1583 mode |= DCB_CAP_DCBX_STATIC;
1585 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1591 static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1593 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1595 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1596 struct qed_dcbx_set dcbx_set;
1597 struct qed_ptt *ptt;
1600 DP_VERBOSE(hwfn, QED_MSG_DCB,
1601 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1602 tc, pri_type, pgid, bw_pct, up_map);
1604 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1605 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1609 memset(&dcbx_set, 0, sizeof(dcbx_set));
1610 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1614 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1615 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1617 ptt = qed_ptt_acquire(hwfn);
1621 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1623 qed_ptt_release(hwfn, ptt);
1626 static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1627 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1629 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1632 static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1634 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1635 struct qed_dcbx_set dcbx_set;
1636 struct qed_ptt *ptt;
1639 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1640 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1641 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1645 memset(&dcbx_set, 0, sizeof(dcbx_set));
1646 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1650 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1651 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1653 ptt = qed_ptt_acquire(hwfn);
1657 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1659 qed_ptt_release(hwfn, ptt);
1662 static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1664 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1667 static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1669 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1670 struct qed_dcbx_set dcbx_set;
1671 struct qed_ptt *ptt;
1674 memset(&dcbx_set, 0, sizeof(dcbx_set));
1675 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1679 ptt = qed_ptt_acquire(hwfn);
1683 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1685 qed_ptt_release(hwfn, ptt);
1690 static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1692 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1693 struct qed_dcbx_set dcbx_set;
1694 struct qed_ptt *ptt;
1697 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1698 memset(&dcbx_set, 0, sizeof(dcbx_set));
1699 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1704 case DCB_NUMTCS_ATTR_PG:
1705 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1706 dcbx_set.config.params.max_ets_tc = num;
1708 case DCB_NUMTCS_ATTR_PFC:
1709 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1710 dcbx_set.config.params.pfc.max_tc = num;
1713 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1717 ptt = qed_ptt_acquire(hwfn);
1721 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1723 qed_ptt_release(hwfn, ptt);
1728 static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1730 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1731 struct qed_dcbx_set dcbx_set;
1732 struct qed_ptt *ptt;
1735 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1737 memset(&dcbx_set, 0, sizeof(dcbx_set));
1738 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1742 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1743 dcbx_set.config.params.pfc.enabled = !!state;
1745 ptt = qed_ptt_acquire(hwfn);
1749 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1751 qed_ptt_release(hwfn, ptt);
1754 static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1756 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1757 struct qed_dcbx_get *dcbx_info;
1758 struct qed_app_entry *entry;
1763 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1767 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1768 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1769 entry = &dcbx_info->operational.params.app_entry[i];
1770 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1776 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1777 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1787 static int qed_dcbnl_setapp(struct qed_dev *cdev,
1788 u8 idtype, u16 idval, u8 pri_map)
1790 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1791 struct qed_dcbx_set dcbx_set;
1792 struct qed_app_entry *entry;
1793 struct qed_ptt *ptt;
1797 memset(&dcbx_set, 0, sizeof(dcbx_set));
1798 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1802 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1803 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1804 entry = &dcbx_set.config.params.app_entry[i];
1805 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1807 /* First empty slot */
1808 if (!entry->proto_id) {
1809 dcbx_set.config.params.num_app_entries++;
1814 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1815 DP_ERR(cdev, "App table is full\n");
1819 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1820 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1821 dcbx_set.config.params.app_entry[i].proto_id = idval;
1822 dcbx_set.config.params.app_entry[i].prio = pri_map;
1824 ptt = qed_ptt_acquire(hwfn);
1828 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1830 qed_ptt_release(hwfn, ptt);
1835 static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1837 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1838 struct qed_dcbx_set dcbx_set;
1839 struct qed_ptt *ptt;
1842 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1844 if (!(mode & DCB_CAP_DCBX_VER_IEEE) &&
1845 !(mode & DCB_CAP_DCBX_VER_CEE) && !(mode & DCB_CAP_DCBX_STATIC)) {
1846 DP_INFO(hwfn, "Allowed modes are cee, ieee or static\n");
1850 memset(&dcbx_set, 0, sizeof(dcbx_set));
1851 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1855 dcbx_set.ver_num = 0;
1856 if (mode & DCB_CAP_DCBX_VER_CEE) {
1857 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1858 dcbx_set.enabled = true;
1861 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1862 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1863 dcbx_set.enabled = true;
1866 if (mode & DCB_CAP_DCBX_STATIC) {
1867 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1868 dcbx_set.enabled = true;
1871 ptt = qed_ptt_acquire(hwfn);
1875 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1877 qed_ptt_release(hwfn, ptt);
1882 static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1884 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1885 struct qed_dcbx_get *dcbx_info;
1887 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1888 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1894 case DCB_FEATCFG_ATTR_PG:
1895 if (dcbx_info->operational.params.ets_enabled)
1896 *flags = DCB_FEATCFG_ENABLE;
1898 *flags = DCB_FEATCFG_ERROR;
1900 case DCB_FEATCFG_ATTR_PFC:
1901 if (dcbx_info->operational.params.pfc.enabled)
1902 *flags = DCB_FEATCFG_ENABLE;
1904 *flags = DCB_FEATCFG_ERROR;
1906 case DCB_FEATCFG_ATTR_APP:
1907 if (dcbx_info->operational.params.app_valid)
1908 *flags = DCB_FEATCFG_ENABLE;
1910 *flags = DCB_FEATCFG_ERROR;
1913 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1918 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1924 static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1926 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1927 struct qed_dcbx_set dcbx_set;
1928 bool enabled, willing;
1929 struct qed_ptt *ptt;
1932 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1934 memset(&dcbx_set, 0, sizeof(dcbx_set));
1935 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1939 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1940 willing = !!(flags & DCB_FEATCFG_WILLING);
1942 case DCB_FEATCFG_ATTR_PG:
1943 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1944 dcbx_set.config.params.ets_enabled = enabled;
1945 dcbx_set.config.params.ets_willing = willing;
1947 case DCB_FEATCFG_ATTR_PFC:
1948 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1949 dcbx_set.config.params.pfc.enabled = enabled;
1950 dcbx_set.config.params.pfc.willing = willing;
1952 case DCB_FEATCFG_ATTR_APP:
1953 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1954 dcbx_set.config.params.app_willing = willing;
1957 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1961 ptt = qed_ptt_acquire(hwfn);
1965 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1967 qed_ptt_release(hwfn, ptt);
1972 static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1973 struct dcb_peer_app_info *info,
1976 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1977 struct qed_dcbx_get *dcbx_info;
1979 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1983 info->willing = dcbx_info->remote.params.app_willing;
1984 info->error = dcbx_info->remote.params.app_error;
1985 *app_count = dcbx_info->remote.params.num_app_entries;
1991 static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1992 struct dcb_app *table)
1994 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1995 struct qed_dcbx_get *dcbx_info;
1998 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2002 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
2003 if (dcbx_info->remote.params.app_entry[i].ethtype)
2004 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
2006 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
2007 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
2009 dcbx_info->remote.params.app_entry[i].proto_id;
2017 static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
2019 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2020 struct qed_dcbx_get *dcbx_info;
2023 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2027 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2028 if (dcbx_info->remote.params.pfc.prio[i])
2029 pfc->pfc_en |= BIT(i);
2031 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
2032 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
2033 pfc->pfc_en, pfc->tcs_supported);
2039 static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
2041 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2042 struct qed_dcbx_get *dcbx_info;
2045 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2049 pg->willing = dcbx_info->remote.params.ets_willing;
2050 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
2051 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
2052 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
2055 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
2061 static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
2062 struct ieee_pfc *pfc, bool remote)
2064 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2065 struct qed_dcbx_params *params;
2066 struct qed_dcbx_get *dcbx_info;
2069 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2073 if (!dcbx_info->operational.ieee) {
2074 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2080 memset(dcbx_info, 0, sizeof(*dcbx_info));
2081 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2082 QED_DCBX_REMOTE_MIB);
2088 params = &dcbx_info->remote.params;
2090 params = &dcbx_info->operational.params;
2093 pfc->pfc_cap = params->pfc.max_tc;
2095 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2096 if (params->pfc.prio[i])
2097 pfc->pfc_en |= BIT(i);
2104 static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2106 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2109 static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2111 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2112 struct qed_dcbx_get *dcbx_info;
2113 struct qed_dcbx_set dcbx_set;
2114 struct qed_ptt *ptt;
2117 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2121 if (!dcbx_info->operational.ieee) {
2122 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2129 memset(&dcbx_set, 0, sizeof(dcbx_set));
2130 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2134 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2135 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2136 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2138 dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
2140 ptt = qed_ptt_acquire(hwfn);
2144 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2146 qed_ptt_release(hwfn, ptt);
2151 static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2152 struct ieee_ets *ets, bool remote)
2154 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2155 struct qed_dcbx_get *dcbx_info;
2156 struct qed_dcbx_params *params;
2159 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2163 if (!dcbx_info->operational.ieee) {
2164 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2170 memset(dcbx_info, 0, sizeof(*dcbx_info));
2171 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2172 QED_DCBX_REMOTE_MIB);
2178 params = &dcbx_info->remote.params;
2180 params = &dcbx_info->operational.params;
2183 ets->ets_cap = params->max_ets_tc;
2184 ets->willing = params->ets_willing;
2185 ets->cbs = params->ets_cbs;
2186 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2187 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2188 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2194 static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2196 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2199 static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2201 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2202 struct qed_dcbx_get *dcbx_info;
2203 struct qed_dcbx_set dcbx_set;
2204 struct qed_ptt *ptt;
2207 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2211 if (!dcbx_info->operational.ieee) {
2212 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2219 memset(&dcbx_set, 0, sizeof(dcbx_set));
2220 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2224 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2225 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2226 dcbx_set.config.params.ets_willing = ets->willing;
2227 dcbx_set.config.params.ets_cbs = ets->cbs;
2228 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2229 sizeof(ets->tc_tx_bw));
2230 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2231 sizeof(ets->tc_tsa));
2232 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2233 sizeof(ets->prio_tc));
2235 ptt = qed_ptt_acquire(hwfn);
2239 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2241 qed_ptt_release(hwfn, ptt);
2247 qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2249 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2253 qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2255 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2258 static int qed_get_sf_ieee_value(u8 selector, u8 *sf_ieee)
2261 case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
2262 *sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
2264 case IEEE_8021QAZ_APP_SEL_STREAM:
2265 *sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
2267 case IEEE_8021QAZ_APP_SEL_DGRAM:
2268 *sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
2270 case IEEE_8021QAZ_APP_SEL_ANY:
2271 *sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
2280 static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
2282 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2283 struct qed_dcbx_get *dcbx_info;
2284 struct qed_app_entry *entry;
2289 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d\n",
2290 app->selector, app->protocol);
2292 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2293 DP_INFO(cdev, "Invalid selector field value %d\n",
2298 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2302 if (!dcbx_info->operational.ieee) {
2303 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2308 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2309 entry = &dcbx_info->operational.params.app_entry[i];
2310 if ((entry->sf_ieee == sf_ieee) &&
2311 (entry->proto_id == app->protocol)) {
2317 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2318 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2324 app->priority = ffs(prio) - 1;
2331 static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
2333 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2334 struct qed_dcbx_get *dcbx_info;
2335 struct qed_dcbx_set dcbx_set;
2336 struct qed_app_entry *entry;
2337 struct qed_ptt *ptt;
2341 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d pri = %d\n",
2342 app->selector, app->protocol, app->priority);
2343 if (app->priority >= QED_MAX_PFC_PRIORITIES) {
2344 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2348 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2349 DP_INFO(cdev, "Invalid selector field value %d\n",
2354 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2358 if (!dcbx_info->operational.ieee) {
2359 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2366 memset(&dcbx_set, 0, sizeof(dcbx_set));
2367 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2371 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2372 entry = &dcbx_set.config.params.app_entry[i];
2373 if ((entry->sf_ieee == sf_ieee) &&
2374 (entry->proto_id == app->protocol))
2376 /* First empty slot */
2377 if (!entry->proto_id) {
2378 dcbx_set.config.params.num_app_entries++;
2383 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2384 DP_ERR(cdev, "App table is full\n");
2388 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
2389 dcbx_set.config.params.app_entry[i].sf_ieee = sf_ieee;
2390 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2391 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2393 ptt = qed_ptt_acquire(hwfn);
2397 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2399 qed_ptt_release(hwfn, ptt);
2404 const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2405 .getstate = qed_dcbnl_getstate,
2406 .setstate = qed_dcbnl_setstate,
2407 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2408 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2409 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2410 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2411 .getpfccfg = qed_dcbnl_getpfccfg,
2412 .setpfccfg = qed_dcbnl_setpfccfg,
2413 .getcap = qed_dcbnl_getcap,
2414 .getnumtcs = qed_dcbnl_getnumtcs,
2415 .getpfcstate = qed_dcbnl_getpfcstate,
2416 .getdcbx = qed_dcbnl_getdcbx,
2417 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2418 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2419 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2420 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2421 .setall = qed_dcbnl_setall,
2422 .setnumtcs = qed_dcbnl_setnumtcs,
2423 .setpfcstate = qed_dcbnl_setpfcstate,
2424 .setapp = qed_dcbnl_setapp,
2425 .setdcbx = qed_dcbnl_setdcbx,
2426 .setfeatcfg = qed_dcbnl_setfeatcfg,
2427 .getfeatcfg = qed_dcbnl_getfeatcfg,
2428 .getapp = qed_dcbnl_getapp,
2429 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2430 .peer_getapptable = qed_dcbnl_peer_getapptable,
2431 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2432 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2433 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2434 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2435 .ieee_getets = qed_dcbnl_ieee_getets,
2436 .ieee_setets = qed_dcbnl_ieee_setets,
2437 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2438 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2439 .ieee_getapp = qed_dcbnl_ieee_getapp,
2440 .ieee_setapp = qed_dcbnl_ieee_setapp,