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 app_tlv, 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 (app_tlv && 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 app_tlv, 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, app_tlv, 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_ERR(p_hwfn, "No action required, App TLV entry = 0x%x\n",
273 /* Parse app TLV's to update TC information in hw_info structure for
274 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
277 qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
278 struct qed_dcbx_results *p_data,
279 struct dcbx_app_priority_entry *p_tbl,
280 u32 pri_tc_tbl, int count, u8 dcbx_version)
282 enum dcbx_protocol_type type;
283 bool enable, ieee, eth_tlv;
289 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
291 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
294 for (i = 0; i < count; i++) {
295 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
296 DCBX_APP_PROTOCOL_ID);
297 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
299 priority = ffs(priority_map) - 1;
301 DP_ERR(p_hwfn, "Invalid priority\n");
305 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
306 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
307 protocol_id, &type, ieee)) {
308 /* ETH always have the enable bit reset, as it gets
309 * vlan information per packet. For other protocols,
310 * should be set according to the dcbx_enabled
311 * indication, but we only got here if there was an
312 * app tlv for the protocol, so dcbx must be enabled.
314 if (type == DCBX_PROTOCOL_ETH) {
321 qed_dcbx_update_app_info(p_data, p_hwfn, p_ptt, true,
322 enable, priority, tc, type);
326 /* If Eth TLV is not detected, use UFP TC as default TC */
327 if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) && !eth_tlv)
328 p_data->arr[DCBX_PROTOCOL_ETH].tc = p_hwfn->ufp_info.tc;
330 /* Update ramrod protocol data and hw_info fields
331 * with default info when corresponding APP TLV's are not detected.
332 * The enabled field has a different logic for ethernet as only for
333 * ethernet dcb should disabled by default, as the information arrives
334 * from the OS (unless an explicit app tlv was present).
336 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
337 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
338 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
339 if (p_data->arr[type].update)
342 enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
343 qed_dcbx_update_app_info(p_data, p_hwfn, p_ptt, false, enable,
350 /* Parse app TLV's to update TC information in hw_info structure for
351 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
354 qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
356 struct dcbx_app_priority_feature *p_app;
357 struct dcbx_app_priority_entry *p_tbl;
358 struct qed_dcbx_results data = { 0 };
359 struct dcbx_ets_feature *p_ets;
360 struct qed_hw_info *p_info;
361 u32 pri_tc_tbl, flags;
366 flags = p_hwfn->p_dcbx_info->operational.flags;
367 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
369 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
370 p_tbl = p_app->app_pri_tbl;
372 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
373 pri_tc_tbl = p_ets->pri_tc_tbl[0];
375 p_info = &p_hwfn->hw_info;
376 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
378 rc = qed_dcbx_process_tlv(p_hwfn, p_ptt, &data, p_tbl, pri_tc_tbl,
379 num_entries, dcbx_version);
383 p_info->num_active_tc = QED_MFW_GET_FIELD(p_ets->flags,
385 p_hwfn->qm_info.ooo_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
386 data.pf_id = p_hwfn->rel_pf_id;
387 data.dcbx_enabled = !!dcbx_version;
389 qed_dcbx_dp_protocol(p_hwfn, &data);
391 memcpy(&p_hwfn->p_dcbx_info->results, &data,
392 sizeof(struct qed_dcbx_results));
398 qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
399 struct qed_ptt *p_ptt,
400 struct qed_dcbx_mib_meta_data *p_data,
401 enum qed_mib_read_type type)
403 u32 prefix_seq_num, suffix_seq_num;
407 /* The data is considered to be valid only if both sequence numbers are
411 if (type == QED_DCBX_REMOTE_LLDP_MIB) {
412 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
413 p_data->addr, p_data->size);
414 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
415 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
417 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
418 p_data->addr, p_data->size);
419 prefix_seq_num = p_data->mib->prefix_seq_num;
420 suffix_seq_num = p_data->mib->suffix_seq_num;
426 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
427 type, read_count, prefix_seq_num, suffix_seq_num);
428 } while ((prefix_seq_num != suffix_seq_num) &&
429 (read_count < QED_DCBX_MAX_MIB_READ_TRY));
431 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
433 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
434 type, read_count, prefix_seq_num, suffix_seq_num);
442 qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
443 struct qed_dcbx_app_prio *p_prio,
444 struct qed_dcbx_results *p_results)
448 p_prio->roce = QED_DCBX_INVALID_PRIORITY;
449 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
450 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
451 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
453 if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
454 p_results->arr[DCBX_PROTOCOL_ROCE].enable)
455 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
457 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
458 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
459 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
460 p_prio->roce_v2 = val;
463 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
464 p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
465 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
467 if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
468 p_results->arr[DCBX_PROTOCOL_FCOE].enable)
469 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
471 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
472 p_results->arr[DCBX_PROTOCOL_ETH].enable)
473 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
475 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
476 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
477 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
482 qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
483 struct dcbx_app_priority_feature *p_app,
484 struct dcbx_app_priority_entry *p_tbl,
485 struct qed_dcbx_params *p_params, bool ieee)
487 struct qed_app_entry *entry;
491 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
493 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
494 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
495 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
496 DCBX_APP_NUM_ENTRIES);
497 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
498 entry = &p_params->app_entry[i];
503 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
506 case DCBX_APP_SF_IEEE_RESERVED:
508 val = QED_MFW_GET_FIELD(p_tbl[i].entry,
510 entry->sf_ieee = val ?
511 QED_DCBX_SF_IEEE_TCP_UDP_PORT :
512 QED_DCBX_SF_IEEE_ETHTYPE;
514 case DCBX_APP_SF_IEEE_ETHTYPE:
515 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
517 case DCBX_APP_SF_IEEE_TCP_PORT:
518 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
520 case DCBX_APP_SF_IEEE_UDP_PORT:
521 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
523 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
524 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
528 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
532 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
533 entry->prio = ffs(pri_map) - 1;
534 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
535 DCBX_APP_PROTOCOL_ID);
536 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
538 &entry->proto_type, ieee);
541 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
542 "APP params: willing %d, valid %d error = %d\n",
543 p_params->app_willing, p_params->app_valid,
544 p_params->app_error);
548 qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
549 u32 pfc, struct qed_dcbx_params *p_params)
553 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
554 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
555 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
556 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
557 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
558 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
559 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
560 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
561 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
562 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
563 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
564 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
566 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
567 "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
568 p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
569 p_params->pfc.enabled);
573 qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
574 struct dcbx_ets_feature *p_ets,
575 struct qed_dcbx_params *p_params)
577 u32 bw_map[2], tsa_map[2], pri_map;
580 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
582 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
584 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
585 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
587 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
588 "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
589 p_params->ets_willing, p_params->ets_enabled,
590 p_params->ets_cbs, p_ets->pri_tc_tbl[0],
591 p_params->max_ets_tc);
593 if (p_params->ets_enabled && !p_params->max_ets_tc) {
594 p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
595 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
596 "ETS params: max_ets_tc is forced to %d\n",
597 p_params->max_ets_tc);
600 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
601 * encoded in a type u32 array of size 2.
603 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
604 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
605 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
606 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
607 pri_map = p_ets->pri_tc_tbl[0];
608 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
609 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
610 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
611 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
612 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
613 "elem %d bw_tbl %x tsa_tbl %x\n",
614 i, p_params->ets_tc_bw_tbl[i],
615 p_params->ets_tc_tsa_tbl[i]);
620 qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
621 struct dcbx_app_priority_feature *p_app,
622 struct dcbx_app_priority_entry *p_tbl,
623 struct dcbx_ets_feature *p_ets,
624 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
626 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
627 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
628 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
632 qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
634 struct dcbx_features *p_feat;
636 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
637 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
638 p_feat->app.app_pri_tbl, &p_feat->ets,
639 p_feat->pfc, ¶ms->local.params, false);
640 params->local.valid = true;
644 qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
646 struct dcbx_features *p_feat;
648 p_feat = &p_hwfn->p_dcbx_info->remote.features;
649 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
650 p_feat->app.app_pri_tbl, &p_feat->ets,
651 p_feat->pfc, ¶ms->remote.params, false);
652 params->remote.valid = true;
656 qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
657 struct qed_dcbx_get *params)
659 struct qed_dcbx_operational_params *p_operational;
660 struct qed_dcbx_results *p_results;
661 struct dcbx_features *p_feat;
666 flags = p_hwfn->p_dcbx_info->operational.flags;
668 /* If DCBx version is non zero, then negotiation
669 * was successfuly performed
671 p_operational = ¶ms->operational;
672 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
673 DCBX_CONFIG_VERSION_DISABLED);
675 p_operational->enabled = enabled;
676 p_operational->valid = false;
677 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx is disabled\n");
681 p_feat = &p_hwfn->p_dcbx_info->operational.features;
682 p_results = &p_hwfn->p_dcbx_info->results;
684 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
685 DCBX_CONFIG_VERSION_IEEE);
686 p_operational->ieee = val;
687 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
688 DCBX_CONFIG_VERSION_CEE);
689 p_operational->cee = val;
691 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
692 DCBX_CONFIG_VERSION_STATIC);
693 p_operational->local = val;
695 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
696 "Version support: ieee %d, cee %d, static %d\n",
697 p_operational->ieee, p_operational->cee,
698 p_operational->local);
700 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
701 p_feat->app.app_pri_tbl, &p_feat->ets,
702 p_feat->pfc, ¶ms->operational.params,
703 p_operational->ieee);
704 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
705 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
706 p_operational->err = err;
707 p_operational->enabled = enabled;
708 p_operational->valid = true;
712 qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
713 struct qed_dcbx_get *params)
715 struct lldp_config_params_s *p_local;
717 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
719 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
720 sizeof(p_local->local_chassis_id));
721 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
722 sizeof(p_local->local_port_id));
726 qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
727 struct qed_dcbx_get *params)
729 struct lldp_status_params_s *p_remote;
731 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
733 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
734 sizeof(p_remote->peer_chassis_id));
735 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
736 sizeof(p_remote->peer_port_id));
740 qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
741 enum qed_mib_read_type type)
744 case QED_DCBX_REMOTE_MIB:
745 qed_dcbx_get_remote_params(p_hwfn, p_params);
747 case QED_DCBX_LOCAL_MIB:
748 qed_dcbx_get_local_params(p_hwfn, p_params);
750 case QED_DCBX_OPERATIONAL_MIB:
751 qed_dcbx_get_operational_params(p_hwfn, p_params);
753 case QED_DCBX_REMOTE_LLDP_MIB:
754 qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
756 case QED_DCBX_LOCAL_LLDP_MIB:
757 qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
760 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
768 qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
770 struct qed_dcbx_mib_meta_data data;
773 memset(&data, 0, sizeof(data));
774 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
776 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
777 data.size = sizeof(struct lldp_config_params_s);
778 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
784 qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
785 struct qed_ptt *p_ptt,
786 enum qed_mib_read_type type)
788 struct qed_dcbx_mib_meta_data data;
791 memset(&data, 0, sizeof(data));
792 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
794 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
795 data.size = sizeof(struct lldp_status_params_s);
796 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
802 qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
803 struct qed_ptt *p_ptt,
804 enum qed_mib_read_type type)
806 struct qed_dcbx_mib_meta_data data;
809 memset(&data, 0, sizeof(data));
810 data.addr = p_hwfn->mcp_info->port_addr +
811 offsetof(struct public_port, operational_dcbx_mib);
812 data.mib = &p_hwfn->p_dcbx_info->operational;
813 data.size = sizeof(struct dcbx_mib);
814 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
820 qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
821 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
823 struct qed_dcbx_mib_meta_data data;
826 memset(&data, 0, sizeof(data));
827 data.addr = p_hwfn->mcp_info->port_addr +
828 offsetof(struct public_port, remote_dcbx_mib);
829 data.mib = &p_hwfn->p_dcbx_info->remote;
830 data.size = sizeof(struct dcbx_mib);
831 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
837 qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
839 struct qed_dcbx_mib_meta_data data;
842 memset(&data, 0, sizeof(data));
843 data.addr = p_hwfn->mcp_info->port_addr +
844 offsetof(struct public_port, local_admin_dcbx_mib);
845 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
846 data.size = sizeof(struct dcbx_local_params);
847 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
852 static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
853 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
858 case QED_DCBX_OPERATIONAL_MIB:
859 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
861 case QED_DCBX_REMOTE_MIB:
862 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
864 case QED_DCBX_LOCAL_MIB:
865 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
867 case QED_DCBX_REMOTE_LLDP_MIB:
868 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
870 case QED_DCBX_LOCAL_LLDP_MIB:
871 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
874 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
880 static void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
882 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
883 void *cookie = hwfn->cdev->ops_cookie;
885 if (cookie && op->dcbx_aen)
886 op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
890 * Reconfigure QM and invoke PF update ramrod command if operational MIB
891 * change is detected.
894 qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
895 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
899 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
903 if (type == QED_DCBX_OPERATIONAL_MIB) {
904 rc = qed_dcbx_process_mib_info(p_hwfn, p_ptt);
906 /* reconfigure tcs of QM queues according
907 * to negotiation results
909 qed_qm_reconf(p_hwfn, p_ptt);
911 /* update storm FW with negotiation results */
912 qed_sp_pf_update(p_hwfn);
914 /* for roce PFs, we may want to enable/disable DPM
915 * when DCBx change occurs
917 if (p_hwfn->hw_info.personality ==
919 qed_roce_dpm_dcbx(p_hwfn, p_ptt);
923 qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
925 if (type == QED_DCBX_OPERATIONAL_MIB) {
926 struct qed_dcbx_results *p_data;
929 /* Configure in NIG which protocols support EDPM and should
932 p_data = &p_hwfn->p_dcbx_info->results;
933 val = (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE].tc) |
934 (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE_V2].tc);
935 val <<= NIG_REG_TX_EDPM_CTRL_TX_EDPM_TC_EN_SHIFT;
936 val |= NIG_REG_TX_EDPM_CTRL_TX_EDPM_EN;
937 qed_wr(p_hwfn, p_ptt, NIG_REG_TX_EDPM_CTRL, val);
940 qed_dcbx_aen(p_hwfn, type);
945 int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
947 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
948 if (!p_hwfn->p_dcbx_info)
954 void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
956 kfree(p_hwfn->p_dcbx_info);
957 p_hwfn->p_dcbx_info = NULL;
960 static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
961 struct qed_dcbx_results *p_src,
962 enum dcbx_protocol_type type)
964 p_data->dcb_enable_flag = p_src->arr[type].enable;
965 p_data->dcb_priority = p_src->arr[type].priority;
966 p_data->dcb_tc = p_src->arr[type].tc;
967 p_data->dcb_dont_add_vlan0 = p_src->arr[type].dont_add_vlan0;
970 /* Set pf update ramrod command params */
971 void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
972 struct pf_update_ramrod_data *p_dest)
974 struct protocol_dcb_data *p_dcb_data;
977 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
978 p_dest->update_fcoe_dcb_data_mode = update_flag;
980 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
981 p_dest->update_roce_dcb_data_mode = update_flag;
983 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
984 p_dest->update_rroce_dcb_data_mode = update_flag;
986 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
987 p_dest->update_iscsi_dcb_data_mode = update_flag;
988 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
989 p_dest->update_eth_dcb_data_mode = update_flag;
991 p_dcb_data = &p_dest->fcoe_dcb_data;
992 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
993 p_dcb_data = &p_dest->roce_dcb_data;
994 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
995 p_dcb_data = &p_dest->rroce_dcb_data;
996 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
997 p_dcb_data = &p_dest->iscsi_dcb_data;
998 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
999 p_dcb_data = &p_dest->eth_dcb_data;
1000 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
1003 u8 qed_dcbx_get_priority_tc(struct qed_hwfn *p_hwfn, u8 pri)
1005 struct qed_dcbx_get *dcbx_info = &p_hwfn->p_dcbx_info->get;
1007 if (pri >= QED_MAX_PFC_PRIORITIES) {
1008 DP_ERR(p_hwfn, "Invalid priority %d\n", pri);
1009 return QED_DCBX_DEFAULT_TC;
1012 if (!dcbx_info->operational.valid) {
1013 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
1014 "Dcbx parameters not available\n");
1015 return QED_DCBX_DEFAULT_TC;
1018 return dcbx_info->operational.params.ets_pri_tc_tbl[pri];
1022 static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
1023 struct qed_dcbx_get *p_get,
1024 enum qed_mib_read_type type)
1026 struct qed_ptt *p_ptt;
1029 if (IS_VF(p_hwfn->cdev))
1032 p_ptt = qed_ptt_acquire(p_hwfn);
1036 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
1040 rc = qed_dcbx_get_params(p_hwfn, p_get, type);
1043 qed_ptt_release(p_hwfn, p_ptt);
1048 qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
1049 u32 *pfc, struct qed_dcbx_params *p_params)
1054 *pfc &= ~DCBX_PFC_ERROR_MASK;
1056 if (p_params->pfc.willing)
1057 *pfc |= DCBX_PFC_WILLING_MASK;
1059 *pfc &= ~DCBX_PFC_WILLING_MASK;
1061 if (p_params->pfc.enabled)
1062 *pfc |= DCBX_PFC_ENABLED_MASK;
1064 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1066 *pfc &= ~DCBX_PFC_CAPS_MASK;
1067 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
1069 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1070 if (p_params->pfc.prio[i])
1073 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
1074 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
1076 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
1080 qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
1081 struct dcbx_ets_feature *p_ets,
1082 struct qed_dcbx_params *p_params)
1084 u8 *bw_map, *tsa_map;
1088 if (p_params->ets_willing)
1089 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1091 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1093 if (p_params->ets_cbs)
1094 p_ets->flags |= DCBX_ETS_CBS_MASK;
1096 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1098 if (p_params->ets_enabled)
1099 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1101 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1103 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1104 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1106 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1107 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1108 p_ets->pri_tc_tbl[0] = 0;
1109 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1110 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1111 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1112 /* Copy the priority value to the corresponding 4 bits in the
1113 * traffic class table.
1115 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1116 p_ets->pri_tc_tbl[0] |= val;
1118 for (i = 0; i < 2; i++) {
1119 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1120 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1125 qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1126 struct dcbx_app_priority_feature *p_app,
1127 struct qed_dcbx_params *p_params, bool ieee)
1132 if (p_params->app_willing)
1133 p_app->flags |= DCBX_APP_WILLING_MASK;
1135 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1137 if (p_params->app_valid)
1138 p_app->flags |= DCBX_APP_ENABLED_MASK;
1140 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1142 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1143 p_app->flags |= (u32)p_params->num_app_entries <<
1144 DCBX_APP_NUM_ENTRIES_SHIFT;
1146 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1147 entry = &p_app->app_pri_tbl[i].entry;
1150 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
1151 switch (p_params->app_entry[i].sf_ieee) {
1152 case QED_DCBX_SF_IEEE_ETHTYPE:
1153 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1154 DCBX_APP_SF_IEEE_SHIFT);
1155 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1158 case QED_DCBX_SF_IEEE_TCP_PORT:
1159 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1160 DCBX_APP_SF_IEEE_SHIFT);
1161 *entry |= ((u32)DCBX_APP_SF_PORT <<
1164 case QED_DCBX_SF_IEEE_UDP_PORT:
1165 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1166 DCBX_APP_SF_IEEE_SHIFT);
1167 *entry |= ((u32)DCBX_APP_SF_PORT <<
1170 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1171 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1172 DCBX_APP_SF_IEEE_SHIFT);
1173 *entry |= ((u32)DCBX_APP_SF_PORT <<
1178 *entry &= ~DCBX_APP_SF_MASK;
1179 if (p_params->app_entry[i].ethtype)
1180 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1183 *entry |= ((u32)DCBX_APP_SF_PORT <<
1187 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1188 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1189 DCBX_APP_PROTOCOL_ID_SHIFT);
1190 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1191 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1192 DCBX_APP_PRI_MAP_SHIFT);
1197 qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1198 struct dcbx_local_params *local_admin,
1199 struct qed_dcbx_set *params)
1203 local_admin->flags = 0;
1204 memcpy(&local_admin->features,
1205 &p_hwfn->p_dcbx_info->operational.features,
1206 sizeof(local_admin->features));
1208 if (params->enabled) {
1209 local_admin->config = params->ver_num;
1210 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1212 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1215 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx version = %d\n",
1216 local_admin->config);
1218 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1219 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1220 ¶ms->config.params);
1222 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1223 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1224 ¶ms->config.params);
1226 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1227 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1228 ¶ms->config.params, ieee);
1231 int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1232 struct qed_dcbx_set *params, bool hw_commit)
1234 struct dcbx_local_params local_admin;
1235 struct qed_dcbx_mib_meta_data data;
1236 u32 resp = 0, param = 0;
1240 memcpy(&p_hwfn->p_dcbx_info->set, params,
1241 sizeof(struct qed_dcbx_set));
1245 /* clear set-parmas cache */
1246 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1248 memset(&local_admin, 0, sizeof(local_admin));
1249 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1251 data.addr = p_hwfn->mcp_info->port_addr +
1252 offsetof(struct public_port, local_admin_dcbx_mib);
1253 data.local_admin = &local_admin;
1254 data.size = sizeof(struct dcbx_local_params);
1255 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1257 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1258 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, ¶m);
1260 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1265 int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1266 struct qed_dcbx_set *params)
1268 struct qed_dcbx_get *dcbx_info;
1271 if (p_hwfn->p_dcbx_info->set.config.valid) {
1272 memcpy(params, &p_hwfn->p_dcbx_info->set,
1273 sizeof(struct qed_dcbx_set));
1277 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
1281 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1287 p_hwfn->p_dcbx_info->set.override_flags = 0;
1288 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1289 if (dcbx_info->operational.cee)
1290 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1291 if (dcbx_info->operational.ieee)
1292 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1293 if (dcbx_info->operational.local)
1294 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1296 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1297 BUILD_BUG_ON(sizeof(dcbx_info->operational.params) !=
1298 sizeof(p_hwfn->p_dcbx_info->set.config.params));
1299 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1300 &dcbx_info->operational.params,
1301 sizeof(p_hwfn->p_dcbx_info->set.config.params));
1302 p_hwfn->p_dcbx_info->set.config.valid = true;
1304 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1311 static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1312 enum qed_mib_read_type type)
1314 struct qed_dcbx_get *dcbx_info;
1316 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_ATOMIC);
1320 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1325 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1326 !dcbx_info->operational.enabled) {
1327 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1335 static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1337 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1338 struct qed_dcbx_get *dcbx_info;
1341 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1345 enabled = dcbx_info->operational.enabled;
1346 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1352 static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1354 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1355 struct qed_dcbx_set dcbx_set;
1356 struct qed_ptt *ptt;
1359 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1361 memset(&dcbx_set, 0, sizeof(dcbx_set));
1362 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1366 dcbx_set.enabled = !!state;
1368 ptt = qed_ptt_acquire(hwfn);
1372 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1374 qed_ptt_release(hwfn, ptt);
1379 static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1380 u8 *pgid, u8 *bw_pct, u8 *up_map)
1382 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1383 struct qed_dcbx_get *dcbx_info;
1385 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1386 *prio_type = *pgid = *bw_pct = *up_map = 0;
1387 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1388 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1392 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1396 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1400 static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1402 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1403 struct qed_dcbx_get *dcbx_info;
1406 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1407 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1408 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1412 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1416 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1417 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1421 static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1422 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1424 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1425 *prio = *bwg_id = *bw_pct = *up_map = 0;
1428 static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1429 int bwg_id, u8 *bw_pct)
1431 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1435 static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1436 int priority, u8 *setting)
1438 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1439 struct qed_dcbx_get *dcbx_info;
1441 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1442 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1443 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1447 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1451 *setting = dcbx_info->operational.params.pfc.prio[priority];
1452 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1456 static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1458 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1459 struct qed_dcbx_set dcbx_set;
1460 struct qed_ptt *ptt;
1463 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1465 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1466 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1470 memset(&dcbx_set, 0, sizeof(dcbx_set));
1471 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1475 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1476 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1478 ptt = qed_ptt_acquire(hwfn);
1482 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1484 qed_ptt_release(hwfn, ptt);
1487 static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1489 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1490 struct qed_dcbx_get *dcbx_info;
1493 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1494 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1499 case DCB_CAP_ATTR_PG:
1500 case DCB_CAP_ATTR_PFC:
1501 case DCB_CAP_ATTR_UP2TC:
1502 case DCB_CAP_ATTR_GSP:
1505 case DCB_CAP_ATTR_PG_TCS:
1506 case DCB_CAP_ATTR_PFC_TCS:
1509 case DCB_CAP_ATTR_DCBX:
1510 *cap = (DCB_CAP_DCBX_VER_CEE | DCB_CAP_DCBX_VER_IEEE |
1511 DCB_CAP_DCBX_STATIC);
1518 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1524 static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1526 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1527 struct qed_dcbx_get *dcbx_info;
1530 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1531 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1536 case DCB_NUMTCS_ATTR_PG:
1537 *num = dcbx_info->operational.params.max_ets_tc;
1539 case DCB_NUMTCS_ATTR_PFC:
1540 *num = dcbx_info->operational.params.pfc.max_tc;
1547 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1552 static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1554 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1555 struct qed_dcbx_get *dcbx_info;
1558 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1562 enabled = dcbx_info->operational.params.pfc.enabled;
1563 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1569 static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1571 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1572 struct qed_dcbx_get *dcbx_info;
1575 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1579 if (dcbx_info->operational.ieee)
1580 mode |= DCB_CAP_DCBX_VER_IEEE;
1581 if (dcbx_info->operational.cee)
1582 mode |= DCB_CAP_DCBX_VER_CEE;
1583 if (dcbx_info->operational.local)
1584 mode |= DCB_CAP_DCBX_STATIC;
1586 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1592 static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1594 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1596 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1597 struct qed_dcbx_set dcbx_set;
1598 struct qed_ptt *ptt;
1601 DP_VERBOSE(hwfn, QED_MSG_DCB,
1602 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1603 tc, pri_type, pgid, bw_pct, up_map);
1605 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1606 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1610 memset(&dcbx_set, 0, sizeof(dcbx_set));
1611 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1615 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1616 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1618 ptt = qed_ptt_acquire(hwfn);
1622 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1624 qed_ptt_release(hwfn, ptt);
1627 static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1628 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1630 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1633 static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1635 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1636 struct qed_dcbx_set dcbx_set;
1637 struct qed_ptt *ptt;
1640 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1641 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1642 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1646 memset(&dcbx_set, 0, sizeof(dcbx_set));
1647 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1651 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1652 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1654 ptt = qed_ptt_acquire(hwfn);
1658 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1660 qed_ptt_release(hwfn, ptt);
1663 static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1665 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1668 static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1670 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1671 struct qed_dcbx_set dcbx_set;
1672 struct qed_ptt *ptt;
1675 memset(&dcbx_set, 0, sizeof(dcbx_set));
1676 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1680 ptt = qed_ptt_acquire(hwfn);
1684 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1686 qed_ptt_release(hwfn, ptt);
1691 static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1693 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1694 struct qed_dcbx_set dcbx_set;
1695 struct qed_ptt *ptt;
1698 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1699 memset(&dcbx_set, 0, sizeof(dcbx_set));
1700 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1705 case DCB_NUMTCS_ATTR_PG:
1706 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1707 dcbx_set.config.params.max_ets_tc = num;
1709 case DCB_NUMTCS_ATTR_PFC:
1710 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1711 dcbx_set.config.params.pfc.max_tc = num;
1714 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1718 ptt = qed_ptt_acquire(hwfn);
1722 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1724 qed_ptt_release(hwfn, ptt);
1729 static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1731 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1732 struct qed_dcbx_set dcbx_set;
1733 struct qed_ptt *ptt;
1736 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1738 memset(&dcbx_set, 0, sizeof(dcbx_set));
1739 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1743 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1744 dcbx_set.config.params.pfc.enabled = !!state;
1746 ptt = qed_ptt_acquire(hwfn);
1750 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1752 qed_ptt_release(hwfn, ptt);
1755 static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1757 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1758 struct qed_dcbx_get *dcbx_info;
1759 struct qed_app_entry *entry;
1764 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1768 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1769 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1770 entry = &dcbx_info->operational.params.app_entry[i];
1771 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1777 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1778 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1788 static int qed_dcbnl_setapp(struct qed_dev *cdev,
1789 u8 idtype, u16 idval, u8 pri_map)
1791 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1792 struct qed_dcbx_set dcbx_set;
1793 struct qed_app_entry *entry;
1794 struct qed_ptt *ptt;
1798 memset(&dcbx_set, 0, sizeof(dcbx_set));
1799 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1803 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1804 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1805 entry = &dcbx_set.config.params.app_entry[i];
1806 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1808 /* First empty slot */
1809 if (!entry->proto_id) {
1810 dcbx_set.config.params.num_app_entries++;
1815 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1816 DP_ERR(cdev, "App table is full\n");
1820 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1821 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1822 dcbx_set.config.params.app_entry[i].proto_id = idval;
1823 dcbx_set.config.params.app_entry[i].prio = pri_map;
1825 ptt = qed_ptt_acquire(hwfn);
1829 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1831 qed_ptt_release(hwfn, ptt);
1836 static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1838 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1839 struct qed_dcbx_set dcbx_set;
1840 struct qed_ptt *ptt;
1843 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1845 if (!(mode & DCB_CAP_DCBX_VER_IEEE) &&
1846 !(mode & DCB_CAP_DCBX_VER_CEE) && !(mode & DCB_CAP_DCBX_STATIC)) {
1847 DP_INFO(hwfn, "Allowed modes are cee, ieee or static\n");
1851 memset(&dcbx_set, 0, sizeof(dcbx_set));
1852 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1856 dcbx_set.ver_num = 0;
1857 if (mode & DCB_CAP_DCBX_VER_CEE) {
1858 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1859 dcbx_set.enabled = true;
1862 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1863 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1864 dcbx_set.enabled = true;
1867 if (mode & DCB_CAP_DCBX_STATIC) {
1868 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1869 dcbx_set.enabled = true;
1872 ptt = qed_ptt_acquire(hwfn);
1876 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1878 qed_ptt_release(hwfn, ptt);
1883 static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1885 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1886 struct qed_dcbx_get *dcbx_info;
1888 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1889 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1895 case DCB_FEATCFG_ATTR_PG:
1896 if (dcbx_info->operational.params.ets_enabled)
1897 *flags = DCB_FEATCFG_ENABLE;
1899 *flags = DCB_FEATCFG_ERROR;
1901 case DCB_FEATCFG_ATTR_PFC:
1902 if (dcbx_info->operational.params.pfc.enabled)
1903 *flags = DCB_FEATCFG_ENABLE;
1905 *flags = DCB_FEATCFG_ERROR;
1907 case DCB_FEATCFG_ATTR_APP:
1908 if (dcbx_info->operational.params.app_valid)
1909 *flags = DCB_FEATCFG_ENABLE;
1911 *flags = DCB_FEATCFG_ERROR;
1914 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1919 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1925 static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1927 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1928 struct qed_dcbx_set dcbx_set;
1929 bool enabled, willing;
1930 struct qed_ptt *ptt;
1933 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1935 memset(&dcbx_set, 0, sizeof(dcbx_set));
1936 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1940 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1941 willing = !!(flags & DCB_FEATCFG_WILLING);
1943 case DCB_FEATCFG_ATTR_PG:
1944 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1945 dcbx_set.config.params.ets_enabled = enabled;
1946 dcbx_set.config.params.ets_willing = willing;
1948 case DCB_FEATCFG_ATTR_PFC:
1949 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1950 dcbx_set.config.params.pfc.enabled = enabled;
1951 dcbx_set.config.params.pfc.willing = willing;
1953 case DCB_FEATCFG_ATTR_APP:
1954 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1955 dcbx_set.config.params.app_willing = willing;
1958 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1962 ptt = qed_ptt_acquire(hwfn);
1966 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1968 qed_ptt_release(hwfn, ptt);
1973 static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1974 struct dcb_peer_app_info *info,
1977 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1978 struct qed_dcbx_get *dcbx_info;
1980 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1984 info->willing = dcbx_info->remote.params.app_willing;
1985 info->error = dcbx_info->remote.params.app_error;
1986 *app_count = dcbx_info->remote.params.num_app_entries;
1992 static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1993 struct dcb_app *table)
1995 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1996 struct qed_dcbx_get *dcbx_info;
1999 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2003 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
2004 if (dcbx_info->remote.params.app_entry[i].ethtype)
2005 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
2007 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
2008 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
2010 dcbx_info->remote.params.app_entry[i].proto_id;
2018 static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
2020 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2021 struct qed_dcbx_get *dcbx_info;
2024 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2028 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2029 if (dcbx_info->remote.params.pfc.prio[i])
2030 pfc->pfc_en |= BIT(i);
2032 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
2033 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
2034 pfc->pfc_en, pfc->tcs_supported);
2040 static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
2042 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2043 struct qed_dcbx_get *dcbx_info;
2046 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2050 pg->willing = dcbx_info->remote.params.ets_willing;
2051 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
2052 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
2053 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
2056 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
2062 static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
2063 struct ieee_pfc *pfc, bool remote)
2065 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2066 struct qed_dcbx_params *params;
2067 struct qed_dcbx_get *dcbx_info;
2070 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2074 if (!dcbx_info->operational.ieee) {
2075 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2081 memset(dcbx_info, 0, sizeof(*dcbx_info));
2082 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2083 QED_DCBX_REMOTE_MIB);
2089 params = &dcbx_info->remote.params;
2091 params = &dcbx_info->operational.params;
2094 pfc->pfc_cap = params->pfc.max_tc;
2096 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2097 if (params->pfc.prio[i])
2098 pfc->pfc_en |= BIT(i);
2105 static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2107 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2110 static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2112 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2113 struct qed_dcbx_get *dcbx_info;
2114 struct qed_dcbx_set dcbx_set;
2115 struct qed_ptt *ptt;
2118 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2122 if (!dcbx_info->operational.ieee) {
2123 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2130 memset(&dcbx_set, 0, sizeof(dcbx_set));
2131 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2135 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2136 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2137 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2139 dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
2141 ptt = qed_ptt_acquire(hwfn);
2145 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2147 qed_ptt_release(hwfn, ptt);
2152 static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2153 struct ieee_ets *ets, bool remote)
2155 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2156 struct qed_dcbx_get *dcbx_info;
2157 struct qed_dcbx_params *params;
2160 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2164 if (!dcbx_info->operational.ieee) {
2165 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2171 memset(dcbx_info, 0, sizeof(*dcbx_info));
2172 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2173 QED_DCBX_REMOTE_MIB);
2179 params = &dcbx_info->remote.params;
2181 params = &dcbx_info->operational.params;
2184 ets->ets_cap = params->max_ets_tc;
2185 ets->willing = params->ets_willing;
2186 ets->cbs = params->ets_cbs;
2187 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2188 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2189 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2195 static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2197 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2200 static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2202 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2203 struct qed_dcbx_get *dcbx_info;
2204 struct qed_dcbx_set dcbx_set;
2205 struct qed_ptt *ptt;
2208 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2212 if (!dcbx_info->operational.ieee) {
2213 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2220 memset(&dcbx_set, 0, sizeof(dcbx_set));
2221 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2225 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2226 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2227 dcbx_set.config.params.ets_willing = ets->willing;
2228 dcbx_set.config.params.ets_cbs = ets->cbs;
2229 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2230 sizeof(ets->tc_tx_bw));
2231 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2232 sizeof(ets->tc_tsa));
2233 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2234 sizeof(ets->prio_tc));
2236 ptt = qed_ptt_acquire(hwfn);
2240 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2242 qed_ptt_release(hwfn, ptt);
2248 qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2250 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2254 qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2256 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2259 static int qed_get_sf_ieee_value(u8 selector, u8 *sf_ieee)
2262 case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
2263 *sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
2265 case IEEE_8021QAZ_APP_SEL_STREAM:
2266 *sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
2268 case IEEE_8021QAZ_APP_SEL_DGRAM:
2269 *sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
2271 case IEEE_8021QAZ_APP_SEL_ANY:
2272 *sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
2281 static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
2283 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2284 struct qed_dcbx_get *dcbx_info;
2285 struct qed_app_entry *entry;
2290 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d\n",
2291 app->selector, app->protocol);
2293 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2294 DP_INFO(cdev, "Invalid selector field value %d\n",
2299 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2303 if (!dcbx_info->operational.ieee) {
2304 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2309 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2310 entry = &dcbx_info->operational.params.app_entry[i];
2311 if ((entry->sf_ieee == sf_ieee) &&
2312 (entry->proto_id == app->protocol)) {
2318 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2319 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2325 app->priority = ffs(prio) - 1;
2332 static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
2334 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2335 struct qed_dcbx_get *dcbx_info;
2336 struct qed_dcbx_set dcbx_set;
2337 struct qed_app_entry *entry;
2338 struct qed_ptt *ptt;
2342 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d pri = %d\n",
2343 app->selector, app->protocol, app->priority);
2344 if (app->priority >= QED_MAX_PFC_PRIORITIES) {
2345 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2349 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2350 DP_INFO(cdev, "Invalid selector field value %d\n",
2355 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2359 if (!dcbx_info->operational.ieee) {
2360 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2367 memset(&dcbx_set, 0, sizeof(dcbx_set));
2368 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2372 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2373 entry = &dcbx_set.config.params.app_entry[i];
2374 if ((entry->sf_ieee == sf_ieee) &&
2375 (entry->proto_id == app->protocol))
2377 /* First empty slot */
2378 if (!entry->proto_id) {
2379 dcbx_set.config.params.num_app_entries++;
2384 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2385 DP_ERR(cdev, "App table is full\n");
2389 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
2390 dcbx_set.config.params.app_entry[i].sf_ieee = sf_ieee;
2391 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2392 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2394 ptt = qed_ptt_acquire(hwfn);
2398 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2400 qed_ptt_release(hwfn, ptt);
2405 const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2406 .getstate = qed_dcbnl_getstate,
2407 .setstate = qed_dcbnl_setstate,
2408 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2409 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2410 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2411 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2412 .getpfccfg = qed_dcbnl_getpfccfg,
2413 .setpfccfg = qed_dcbnl_setpfccfg,
2414 .getcap = qed_dcbnl_getcap,
2415 .getnumtcs = qed_dcbnl_getnumtcs,
2416 .getpfcstate = qed_dcbnl_getpfcstate,
2417 .getdcbx = qed_dcbnl_getdcbx,
2418 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2419 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2420 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2421 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2422 .setall = qed_dcbnl_setall,
2423 .setnumtcs = qed_dcbnl_setnumtcs,
2424 .setpfcstate = qed_dcbnl_setpfcstate,
2425 .setapp = qed_dcbnl_setapp,
2426 .setdcbx = qed_dcbnl_setdcbx,
2427 .setfeatcfg = qed_dcbnl_setfeatcfg,
2428 .getfeatcfg = qed_dcbnl_getfeatcfg,
2429 .getapp = qed_dcbnl_getapp,
2430 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2431 .peer_getapptable = qed_dcbnl_peer_getapptable,
2432 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2433 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2434 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2435 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2436 .ieee_getets = qed_dcbnl_ieee_getets,
2437 .ieee_setets = qed_dcbnl_ieee_setets,
2438 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2439 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2440 .ieee_getapp = qed_dcbnl_ieee_getapp,
2441 .ieee_setapp = qed_dcbnl_ieee_setapp,