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_hw_info *p_info,
197 enum dcbx_protocol_type type,
198 enum qed_pci_personality personality)
200 /* PF update ramrod data */
201 p_data->arr[type].enable = enable;
202 p_data->arr[type].priority = prio;
203 p_data->arr[type].tc = tc;
205 p_data->arr[type].update = UPDATE_DCB;
207 p_data->arr[type].update = DONT_UPDATE_DCB_DSCP;
210 if (p_info->personality == personality)
211 p_info->offload_tc = tc;
214 /* Update app protocol data and hw_info fields with the TLV info */
216 qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
217 struct qed_hwfn *p_hwfn,
219 u8 prio, u8 tc, enum dcbx_protocol_type type)
221 struct qed_hw_info *p_info = &p_hwfn->hw_info;
222 enum qed_pci_personality personality;
223 enum dcbx_protocol_type id;
227 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
228 id = qed_dcbx_app_update[i].id;
233 personality = qed_dcbx_app_update[i].personality;
234 name = qed_dcbx_app_update[i].name;
236 qed_dcbx_set_params(p_data, p_info, enable,
237 prio, tc, type, personality);
242 qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
244 u16 id, enum dcbx_protocol_type *type, bool ieee)
246 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
247 *type = DCBX_PROTOCOL_FCOE;
248 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
249 *type = DCBX_PROTOCOL_ROCE;
250 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
251 *type = DCBX_PROTOCOL_ISCSI;
252 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
253 *type = DCBX_PROTOCOL_ETH;
254 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
255 *type = DCBX_PROTOCOL_ROCE_V2;
257 *type = DCBX_MAX_PROTOCOL_TYPE;
258 DP_ERR(p_hwfn, "No action required, App TLV entry = 0x%x\n",
266 /* Parse app TLV's to update TC information in hw_info structure for
267 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
270 qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
271 struct qed_dcbx_results *p_data,
272 struct dcbx_app_priority_entry *p_tbl,
273 u32 pri_tc_tbl, int count, u8 dcbx_version)
275 enum dcbx_protocol_type type;
276 bool enable, ieee, eth_tlv;
282 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
284 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
287 for (i = 0; i < count; i++) {
288 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
289 DCBX_APP_PROTOCOL_ID);
290 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
292 priority = ffs(priority_map) - 1;
294 DP_ERR(p_hwfn, "Invalid priority\n");
298 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
299 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
300 protocol_id, &type, ieee)) {
301 /* ETH always have the enable bit reset, as it gets
302 * vlan information per packet. For other protocols,
303 * should be set according to the dcbx_enabled
304 * indication, but we only got here if there was an
305 * app tlv for the protocol, so dcbx must be enabled.
307 if (type == DCBX_PROTOCOL_ETH) {
314 qed_dcbx_update_app_info(p_data, p_hwfn, enable,
319 /* If Eth TLV is not detected, use UFP TC as default TC */
320 if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) && !eth_tlv)
321 p_data->arr[DCBX_PROTOCOL_ETH].tc = p_hwfn->ufp_info.tc;
323 /* Update ramrod protocol data and hw_info fields
324 * with default info when corresponding APP TLV's are not detected.
325 * The enabled field has a different logic for ethernet as only for
326 * ethernet dcb should disabled by default, as the information arrives
327 * from the OS (unless an explicit app tlv was present).
329 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
330 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
331 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
332 if (p_data->arr[type].update)
335 enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
336 qed_dcbx_update_app_info(p_data, p_hwfn, enable,
343 /* Parse app TLV's to update TC information in hw_info structure for
344 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
346 static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
348 struct dcbx_app_priority_feature *p_app;
349 struct dcbx_app_priority_entry *p_tbl;
350 struct qed_dcbx_results data = { 0 };
351 struct dcbx_ets_feature *p_ets;
352 struct qed_hw_info *p_info;
353 u32 pri_tc_tbl, flags;
358 flags = p_hwfn->p_dcbx_info->operational.flags;
359 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
361 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
362 p_tbl = p_app->app_pri_tbl;
364 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
365 pri_tc_tbl = p_ets->pri_tc_tbl[0];
367 p_info = &p_hwfn->hw_info;
368 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
370 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
371 num_entries, dcbx_version);
375 p_info->num_active_tc = QED_MFW_GET_FIELD(p_ets->flags,
377 p_hwfn->qm_info.ooo_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
378 data.pf_id = p_hwfn->rel_pf_id;
379 data.dcbx_enabled = !!dcbx_version;
381 qed_dcbx_dp_protocol(p_hwfn, &data);
383 memcpy(&p_hwfn->p_dcbx_info->results, &data,
384 sizeof(struct qed_dcbx_results));
390 qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
391 struct qed_ptt *p_ptt,
392 struct qed_dcbx_mib_meta_data *p_data,
393 enum qed_mib_read_type type)
395 u32 prefix_seq_num, suffix_seq_num;
399 /* The data is considered to be valid only if both sequence numbers are
403 if (type == QED_DCBX_REMOTE_LLDP_MIB) {
404 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
405 p_data->addr, p_data->size);
406 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
407 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
409 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
410 p_data->addr, p_data->size);
411 prefix_seq_num = p_data->mib->prefix_seq_num;
412 suffix_seq_num = p_data->mib->suffix_seq_num;
418 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
419 type, read_count, prefix_seq_num, suffix_seq_num);
420 } while ((prefix_seq_num != suffix_seq_num) &&
421 (read_count < QED_DCBX_MAX_MIB_READ_TRY));
423 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
425 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
426 type, read_count, prefix_seq_num, suffix_seq_num);
434 qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
435 struct qed_dcbx_app_prio *p_prio,
436 struct qed_dcbx_results *p_results)
440 p_prio->roce = QED_DCBX_INVALID_PRIORITY;
441 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
442 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
443 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
445 if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
446 p_results->arr[DCBX_PROTOCOL_ROCE].enable)
447 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
449 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
450 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
451 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
452 p_prio->roce_v2 = val;
455 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
456 p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
457 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
459 if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
460 p_results->arr[DCBX_PROTOCOL_FCOE].enable)
461 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
463 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
464 p_results->arr[DCBX_PROTOCOL_ETH].enable)
465 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
467 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
468 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
469 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
474 qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
475 struct dcbx_app_priority_feature *p_app,
476 struct dcbx_app_priority_entry *p_tbl,
477 struct qed_dcbx_params *p_params, bool ieee)
479 struct qed_app_entry *entry;
483 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
485 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
486 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
487 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
488 DCBX_APP_NUM_ENTRIES);
489 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
490 entry = &p_params->app_entry[i];
495 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
498 case DCBX_APP_SF_IEEE_RESERVED:
500 val = QED_MFW_GET_FIELD(p_tbl[i].entry,
502 entry->sf_ieee = val ?
503 QED_DCBX_SF_IEEE_TCP_UDP_PORT :
504 QED_DCBX_SF_IEEE_ETHTYPE;
506 case DCBX_APP_SF_IEEE_ETHTYPE:
507 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
509 case DCBX_APP_SF_IEEE_TCP_PORT:
510 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
512 case DCBX_APP_SF_IEEE_UDP_PORT:
513 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
515 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
516 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
520 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
524 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
525 entry->prio = ffs(pri_map) - 1;
526 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
527 DCBX_APP_PROTOCOL_ID);
528 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
530 &entry->proto_type, ieee);
533 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
534 "APP params: willing %d, valid %d error = %d\n",
535 p_params->app_willing, p_params->app_valid,
536 p_params->app_error);
540 qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
541 u32 pfc, struct qed_dcbx_params *p_params)
545 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
546 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
547 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
548 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
549 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
550 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
551 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
552 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
553 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
554 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
555 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
556 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
558 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
559 "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
560 p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
561 p_params->pfc.enabled);
565 qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
566 struct dcbx_ets_feature *p_ets,
567 struct qed_dcbx_params *p_params)
569 u32 bw_map[2], tsa_map[2], pri_map;
572 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
574 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
576 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
577 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
579 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
580 "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
581 p_params->ets_willing, p_params->ets_enabled,
582 p_params->ets_cbs, p_ets->pri_tc_tbl[0],
583 p_params->max_ets_tc);
585 if (p_params->ets_enabled && !p_params->max_ets_tc) {
586 p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
587 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
588 "ETS params: max_ets_tc is forced to %d\n",
589 p_params->max_ets_tc);
592 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
593 * encoded in a type u32 array of size 2.
595 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
596 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
597 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
598 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
599 pri_map = p_ets->pri_tc_tbl[0];
600 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
601 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
602 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
603 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
604 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
605 "elem %d bw_tbl %x tsa_tbl %x\n",
606 i, p_params->ets_tc_bw_tbl[i],
607 p_params->ets_tc_tsa_tbl[i]);
612 qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
613 struct dcbx_app_priority_feature *p_app,
614 struct dcbx_app_priority_entry *p_tbl,
615 struct dcbx_ets_feature *p_ets,
616 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
618 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
619 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
620 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
624 qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
626 struct dcbx_features *p_feat;
628 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
629 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
630 p_feat->app.app_pri_tbl, &p_feat->ets,
631 p_feat->pfc, ¶ms->local.params, false);
632 params->local.valid = true;
636 qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
638 struct dcbx_features *p_feat;
640 p_feat = &p_hwfn->p_dcbx_info->remote.features;
641 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
642 p_feat->app.app_pri_tbl, &p_feat->ets,
643 p_feat->pfc, ¶ms->remote.params, false);
644 params->remote.valid = true;
648 qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
649 struct qed_dcbx_get *params)
651 struct qed_dcbx_operational_params *p_operational;
652 struct qed_dcbx_results *p_results;
653 struct dcbx_features *p_feat;
658 flags = p_hwfn->p_dcbx_info->operational.flags;
660 /* If DCBx version is non zero, then negotiation
661 * was successfuly performed
663 p_operational = ¶ms->operational;
664 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
665 DCBX_CONFIG_VERSION_DISABLED);
667 p_operational->enabled = enabled;
668 p_operational->valid = false;
669 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx is disabled\n");
673 p_feat = &p_hwfn->p_dcbx_info->operational.features;
674 p_results = &p_hwfn->p_dcbx_info->results;
676 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
677 DCBX_CONFIG_VERSION_IEEE);
678 p_operational->ieee = val;
679 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
680 DCBX_CONFIG_VERSION_CEE);
681 p_operational->cee = val;
683 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
684 DCBX_CONFIG_VERSION_STATIC);
685 p_operational->local = val;
687 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
688 "Version support: ieee %d, cee %d, static %d\n",
689 p_operational->ieee, p_operational->cee,
690 p_operational->local);
692 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
693 p_feat->app.app_pri_tbl, &p_feat->ets,
694 p_feat->pfc, ¶ms->operational.params,
695 p_operational->ieee);
696 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
697 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
698 p_operational->err = err;
699 p_operational->enabled = enabled;
700 p_operational->valid = true;
704 qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
705 struct qed_dcbx_get *params)
707 struct lldp_config_params_s *p_local;
709 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
711 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
712 ARRAY_SIZE(p_local->local_chassis_id));
713 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
714 ARRAY_SIZE(p_local->local_port_id));
718 qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
719 struct qed_dcbx_get *params)
721 struct lldp_status_params_s *p_remote;
723 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
725 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
726 ARRAY_SIZE(p_remote->peer_chassis_id));
727 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
728 ARRAY_SIZE(p_remote->peer_port_id));
732 qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
733 enum qed_mib_read_type type)
736 case QED_DCBX_REMOTE_MIB:
737 qed_dcbx_get_remote_params(p_hwfn, p_params);
739 case QED_DCBX_LOCAL_MIB:
740 qed_dcbx_get_local_params(p_hwfn, p_params);
742 case QED_DCBX_OPERATIONAL_MIB:
743 qed_dcbx_get_operational_params(p_hwfn, p_params);
745 case QED_DCBX_REMOTE_LLDP_MIB:
746 qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
748 case QED_DCBX_LOCAL_LLDP_MIB:
749 qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
752 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
760 qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
762 struct qed_dcbx_mib_meta_data data;
765 memset(&data, 0, sizeof(data));
766 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
768 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
769 data.size = sizeof(struct lldp_config_params_s);
770 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
776 qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
777 struct qed_ptt *p_ptt,
778 enum qed_mib_read_type type)
780 struct qed_dcbx_mib_meta_data data;
783 memset(&data, 0, sizeof(data));
784 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
786 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
787 data.size = sizeof(struct lldp_status_params_s);
788 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
794 qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
795 struct qed_ptt *p_ptt,
796 enum qed_mib_read_type type)
798 struct qed_dcbx_mib_meta_data data;
801 memset(&data, 0, sizeof(data));
802 data.addr = p_hwfn->mcp_info->port_addr +
803 offsetof(struct public_port, operational_dcbx_mib);
804 data.mib = &p_hwfn->p_dcbx_info->operational;
805 data.size = sizeof(struct dcbx_mib);
806 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
812 qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
813 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
815 struct qed_dcbx_mib_meta_data data;
818 memset(&data, 0, sizeof(data));
819 data.addr = p_hwfn->mcp_info->port_addr +
820 offsetof(struct public_port, remote_dcbx_mib);
821 data.mib = &p_hwfn->p_dcbx_info->remote;
822 data.size = sizeof(struct dcbx_mib);
823 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
829 qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
831 struct qed_dcbx_mib_meta_data data;
834 memset(&data, 0, sizeof(data));
835 data.addr = p_hwfn->mcp_info->port_addr +
836 offsetof(struct public_port, local_admin_dcbx_mib);
837 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
838 data.size = sizeof(struct dcbx_local_params);
839 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
844 static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
845 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
850 case QED_DCBX_OPERATIONAL_MIB:
851 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
853 case QED_DCBX_REMOTE_MIB:
854 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
856 case QED_DCBX_LOCAL_MIB:
857 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
859 case QED_DCBX_REMOTE_LLDP_MIB:
860 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
862 case QED_DCBX_LOCAL_LLDP_MIB:
863 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
866 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
872 void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
874 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
875 void *cookie = hwfn->cdev->ops_cookie;
877 if (cookie && op->dcbx_aen)
878 op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
882 * Reconfigure QM and invoke PF update ramrod command if operational MIB
883 * change is detected.
886 qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
887 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
891 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
895 if (type == QED_DCBX_OPERATIONAL_MIB) {
896 rc = qed_dcbx_process_mib_info(p_hwfn);
898 /* reconfigure tcs of QM queues according
899 * to negotiation results
901 qed_qm_reconf(p_hwfn, p_ptt);
903 /* update storm FW with negotiation results */
904 qed_sp_pf_update(p_hwfn);
906 /* for roce PFs, we may want to enable/disable DPM
907 * when DCBx change occurs
909 if (p_hwfn->hw_info.personality ==
911 qed_roce_dpm_dcbx(p_hwfn, p_ptt);
915 qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
917 if (type == QED_DCBX_OPERATIONAL_MIB) {
918 struct qed_dcbx_results *p_data;
921 /* Configure in NIG which protocols support EDPM and should
924 p_data = &p_hwfn->p_dcbx_info->results;
925 val = (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE].tc) |
926 (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE_V2].tc);
927 val <<= NIG_REG_TX_EDPM_CTRL_TX_EDPM_TC_EN_SHIFT;
928 val |= NIG_REG_TX_EDPM_CTRL_TX_EDPM_EN;
929 qed_wr(p_hwfn, p_ptt, NIG_REG_TX_EDPM_CTRL, val);
932 qed_dcbx_aen(p_hwfn, type);
937 int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
939 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
940 if (!p_hwfn->p_dcbx_info)
946 void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
948 kfree(p_hwfn->p_dcbx_info);
949 p_hwfn->p_dcbx_info = NULL;
952 static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
953 struct qed_dcbx_results *p_src,
954 enum dcbx_protocol_type type)
956 p_data->dcb_enable_flag = p_src->arr[type].enable;
957 p_data->dcb_priority = p_src->arr[type].priority;
958 p_data->dcb_tc = p_src->arr[type].tc;
961 /* Set pf update ramrod command params */
962 void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
963 struct pf_update_ramrod_data *p_dest)
965 struct protocol_dcb_data *p_dcb_data;
968 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
969 p_dest->update_fcoe_dcb_data_mode = update_flag;
971 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
972 p_dest->update_roce_dcb_data_mode = update_flag;
974 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
975 p_dest->update_rroce_dcb_data_mode = update_flag;
977 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
978 p_dest->update_iscsi_dcb_data_mode = update_flag;
979 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
980 p_dest->update_eth_dcb_data_mode = update_flag;
982 p_dcb_data = &p_dest->fcoe_dcb_data;
983 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
984 p_dcb_data = &p_dest->roce_dcb_data;
985 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
986 p_dcb_data = &p_dest->rroce_dcb_data;
987 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
988 p_dcb_data = &p_dest->iscsi_dcb_data;
989 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
990 p_dcb_data = &p_dest->eth_dcb_data;
991 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
995 static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
996 struct qed_dcbx_get *p_get,
997 enum qed_mib_read_type type)
999 struct qed_ptt *p_ptt;
1002 if (IS_VF(p_hwfn->cdev))
1005 p_ptt = qed_ptt_acquire(p_hwfn);
1009 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
1013 rc = qed_dcbx_get_params(p_hwfn, p_get, type);
1016 qed_ptt_release(p_hwfn, p_ptt);
1021 qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
1022 u32 *pfc, struct qed_dcbx_params *p_params)
1027 *pfc &= ~DCBX_PFC_ERROR_MASK;
1029 if (p_params->pfc.willing)
1030 *pfc |= DCBX_PFC_WILLING_MASK;
1032 *pfc &= ~DCBX_PFC_WILLING_MASK;
1034 if (p_params->pfc.enabled)
1035 *pfc |= DCBX_PFC_ENABLED_MASK;
1037 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1039 *pfc &= ~DCBX_PFC_CAPS_MASK;
1040 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
1042 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1043 if (p_params->pfc.prio[i])
1046 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
1047 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
1049 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
1053 qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
1054 struct dcbx_ets_feature *p_ets,
1055 struct qed_dcbx_params *p_params)
1057 u8 *bw_map, *tsa_map;
1061 if (p_params->ets_willing)
1062 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1064 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1066 if (p_params->ets_cbs)
1067 p_ets->flags |= DCBX_ETS_CBS_MASK;
1069 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1071 if (p_params->ets_enabled)
1072 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1074 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1076 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1077 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1079 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1080 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1081 p_ets->pri_tc_tbl[0] = 0;
1082 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1083 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1084 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1085 /* Copy the priority value to the corresponding 4 bits in the
1086 * traffic class table.
1088 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1089 p_ets->pri_tc_tbl[0] |= val;
1091 for (i = 0; i < 2; i++) {
1092 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1093 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1098 qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1099 struct dcbx_app_priority_feature *p_app,
1100 struct qed_dcbx_params *p_params, bool ieee)
1105 if (p_params->app_willing)
1106 p_app->flags |= DCBX_APP_WILLING_MASK;
1108 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1110 if (p_params->app_valid)
1111 p_app->flags |= DCBX_APP_ENABLED_MASK;
1113 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1115 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1116 p_app->flags |= (u32)p_params->num_app_entries <<
1117 DCBX_APP_NUM_ENTRIES_SHIFT;
1119 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1120 entry = &p_app->app_pri_tbl[i].entry;
1123 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
1124 switch (p_params->app_entry[i].sf_ieee) {
1125 case QED_DCBX_SF_IEEE_ETHTYPE:
1126 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1127 DCBX_APP_SF_IEEE_SHIFT);
1128 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1131 case QED_DCBX_SF_IEEE_TCP_PORT:
1132 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1133 DCBX_APP_SF_IEEE_SHIFT);
1134 *entry |= ((u32)DCBX_APP_SF_PORT <<
1137 case QED_DCBX_SF_IEEE_UDP_PORT:
1138 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1139 DCBX_APP_SF_IEEE_SHIFT);
1140 *entry |= ((u32)DCBX_APP_SF_PORT <<
1143 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1144 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1145 DCBX_APP_SF_IEEE_SHIFT);
1146 *entry |= ((u32)DCBX_APP_SF_PORT <<
1151 *entry &= ~DCBX_APP_SF_MASK;
1152 if (p_params->app_entry[i].ethtype)
1153 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1156 *entry |= ((u32)DCBX_APP_SF_PORT <<
1160 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1161 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1162 DCBX_APP_PROTOCOL_ID_SHIFT);
1163 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1164 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1165 DCBX_APP_PRI_MAP_SHIFT);
1170 qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1171 struct dcbx_local_params *local_admin,
1172 struct qed_dcbx_set *params)
1176 local_admin->flags = 0;
1177 memcpy(&local_admin->features,
1178 &p_hwfn->p_dcbx_info->operational.features,
1179 sizeof(local_admin->features));
1181 if (params->enabled) {
1182 local_admin->config = params->ver_num;
1183 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1185 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1188 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx version = %d\n",
1189 local_admin->config);
1191 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1192 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1193 ¶ms->config.params);
1195 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1196 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1197 ¶ms->config.params);
1199 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1200 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1201 ¶ms->config.params, ieee);
1204 int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1205 struct qed_dcbx_set *params, bool hw_commit)
1207 struct dcbx_local_params local_admin;
1208 struct qed_dcbx_mib_meta_data data;
1209 u32 resp = 0, param = 0;
1213 memcpy(&p_hwfn->p_dcbx_info->set, params,
1214 sizeof(struct qed_dcbx_set));
1218 /* clear set-parmas cache */
1219 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1221 memset(&local_admin, 0, sizeof(local_admin));
1222 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1224 data.addr = p_hwfn->mcp_info->port_addr +
1225 offsetof(struct public_port, local_admin_dcbx_mib);
1226 data.local_admin = &local_admin;
1227 data.size = sizeof(struct dcbx_local_params);
1228 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1230 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1231 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, ¶m);
1233 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1238 int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1239 struct qed_dcbx_set *params)
1241 struct qed_dcbx_get *dcbx_info;
1244 if (p_hwfn->p_dcbx_info->set.config.valid) {
1245 memcpy(params, &p_hwfn->p_dcbx_info->set,
1246 sizeof(struct qed_dcbx_set));
1250 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
1254 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1260 p_hwfn->p_dcbx_info->set.override_flags = 0;
1261 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1262 if (dcbx_info->operational.cee)
1263 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1264 if (dcbx_info->operational.ieee)
1265 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1266 if (dcbx_info->operational.local)
1267 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1269 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1270 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1271 &dcbx_info->operational.params,
1272 sizeof(struct qed_dcbx_admin_params));
1273 p_hwfn->p_dcbx_info->set.config.valid = true;
1275 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1282 static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1283 enum qed_mib_read_type type)
1285 struct qed_dcbx_get *dcbx_info;
1287 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_ATOMIC);
1291 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1296 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1297 !dcbx_info->operational.enabled) {
1298 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1306 static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1308 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1309 struct qed_dcbx_get *dcbx_info;
1312 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1316 enabled = dcbx_info->operational.enabled;
1317 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1323 static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1325 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1326 struct qed_dcbx_set dcbx_set;
1327 struct qed_ptt *ptt;
1330 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1332 memset(&dcbx_set, 0, sizeof(dcbx_set));
1333 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1337 dcbx_set.enabled = !!state;
1339 ptt = qed_ptt_acquire(hwfn);
1343 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1345 qed_ptt_release(hwfn, ptt);
1350 static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1351 u8 *pgid, u8 *bw_pct, u8 *up_map)
1353 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1354 struct qed_dcbx_get *dcbx_info;
1356 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1357 *prio_type = *pgid = *bw_pct = *up_map = 0;
1358 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1359 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1363 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1367 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1371 static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1373 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1374 struct qed_dcbx_get *dcbx_info;
1377 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1378 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1379 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1383 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1387 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1388 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1392 static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1393 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1395 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1396 *prio = *bwg_id = *bw_pct = *up_map = 0;
1399 static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1400 int bwg_id, u8 *bw_pct)
1402 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1406 static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1407 int priority, u8 *setting)
1409 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1410 struct qed_dcbx_get *dcbx_info;
1412 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1413 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1414 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1418 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1422 *setting = dcbx_info->operational.params.pfc.prio[priority];
1423 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1427 static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1429 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1430 struct qed_dcbx_set dcbx_set;
1431 struct qed_ptt *ptt;
1434 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1436 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1437 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1441 memset(&dcbx_set, 0, sizeof(dcbx_set));
1442 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1446 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1447 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1449 ptt = qed_ptt_acquire(hwfn);
1453 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1455 qed_ptt_release(hwfn, ptt);
1458 static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1460 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1461 struct qed_dcbx_get *dcbx_info;
1464 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1465 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1470 case DCB_CAP_ATTR_PG:
1471 case DCB_CAP_ATTR_PFC:
1472 case DCB_CAP_ATTR_UP2TC:
1473 case DCB_CAP_ATTR_GSP:
1476 case DCB_CAP_ATTR_PG_TCS:
1477 case DCB_CAP_ATTR_PFC_TCS:
1480 case DCB_CAP_ATTR_DCBX:
1481 *cap = (DCB_CAP_DCBX_VER_CEE | DCB_CAP_DCBX_VER_IEEE |
1482 DCB_CAP_DCBX_STATIC);
1489 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1495 static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1497 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1498 struct qed_dcbx_get *dcbx_info;
1501 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1502 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1507 case DCB_NUMTCS_ATTR_PG:
1508 *num = dcbx_info->operational.params.max_ets_tc;
1510 case DCB_NUMTCS_ATTR_PFC:
1511 *num = dcbx_info->operational.params.pfc.max_tc;
1518 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1523 static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1525 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1526 struct qed_dcbx_get *dcbx_info;
1529 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1533 enabled = dcbx_info->operational.params.pfc.enabled;
1534 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1540 static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1542 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1543 struct qed_dcbx_get *dcbx_info;
1546 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1550 if (dcbx_info->operational.ieee)
1551 mode |= DCB_CAP_DCBX_VER_IEEE;
1552 if (dcbx_info->operational.cee)
1553 mode |= DCB_CAP_DCBX_VER_CEE;
1554 if (dcbx_info->operational.local)
1555 mode |= DCB_CAP_DCBX_STATIC;
1557 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1563 static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1565 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1567 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1568 struct qed_dcbx_set dcbx_set;
1569 struct qed_ptt *ptt;
1572 DP_VERBOSE(hwfn, QED_MSG_DCB,
1573 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1574 tc, pri_type, pgid, bw_pct, up_map);
1576 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1577 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1581 memset(&dcbx_set, 0, sizeof(dcbx_set));
1582 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1586 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1587 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1589 ptt = qed_ptt_acquire(hwfn);
1593 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1595 qed_ptt_release(hwfn, ptt);
1598 static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1599 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1601 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1604 static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1606 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1607 struct qed_dcbx_set dcbx_set;
1608 struct qed_ptt *ptt;
1611 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1612 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1613 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1617 memset(&dcbx_set, 0, sizeof(dcbx_set));
1618 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1622 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1623 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1625 ptt = qed_ptt_acquire(hwfn);
1629 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1631 qed_ptt_release(hwfn, ptt);
1634 static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1636 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1639 static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1641 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1642 struct qed_dcbx_set dcbx_set;
1643 struct qed_ptt *ptt;
1646 memset(&dcbx_set, 0, sizeof(dcbx_set));
1647 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1651 ptt = qed_ptt_acquire(hwfn);
1655 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1657 qed_ptt_release(hwfn, ptt);
1662 static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1664 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1665 struct qed_dcbx_set dcbx_set;
1666 struct qed_ptt *ptt;
1669 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1670 memset(&dcbx_set, 0, sizeof(dcbx_set));
1671 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1676 case DCB_NUMTCS_ATTR_PG:
1677 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1678 dcbx_set.config.params.max_ets_tc = num;
1680 case DCB_NUMTCS_ATTR_PFC:
1681 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1682 dcbx_set.config.params.pfc.max_tc = num;
1685 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1689 ptt = qed_ptt_acquire(hwfn);
1693 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1695 qed_ptt_release(hwfn, ptt);
1700 static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1702 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1703 struct qed_dcbx_set dcbx_set;
1704 struct qed_ptt *ptt;
1707 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1709 memset(&dcbx_set, 0, sizeof(dcbx_set));
1710 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1714 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1715 dcbx_set.config.params.pfc.enabled = !!state;
1717 ptt = qed_ptt_acquire(hwfn);
1721 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1723 qed_ptt_release(hwfn, ptt);
1726 static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1728 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1729 struct qed_dcbx_get *dcbx_info;
1730 struct qed_app_entry *entry;
1735 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1739 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1740 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1741 entry = &dcbx_info->operational.params.app_entry[i];
1742 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1748 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1749 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1759 static int qed_dcbnl_setapp(struct qed_dev *cdev,
1760 u8 idtype, u16 idval, u8 pri_map)
1762 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1763 struct qed_dcbx_set dcbx_set;
1764 struct qed_app_entry *entry;
1765 struct qed_ptt *ptt;
1769 memset(&dcbx_set, 0, sizeof(dcbx_set));
1770 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1774 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1775 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1776 entry = &dcbx_set.config.params.app_entry[i];
1777 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1779 /* First empty slot */
1780 if (!entry->proto_id) {
1781 dcbx_set.config.params.num_app_entries++;
1786 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1787 DP_ERR(cdev, "App table is full\n");
1791 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1792 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1793 dcbx_set.config.params.app_entry[i].proto_id = idval;
1794 dcbx_set.config.params.app_entry[i].prio = pri_map;
1796 ptt = qed_ptt_acquire(hwfn);
1800 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1802 qed_ptt_release(hwfn, ptt);
1807 static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1809 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1810 struct qed_dcbx_set dcbx_set;
1811 struct qed_ptt *ptt;
1814 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1816 if (!(mode & DCB_CAP_DCBX_VER_IEEE) &&
1817 !(mode & DCB_CAP_DCBX_VER_CEE) && !(mode & DCB_CAP_DCBX_STATIC)) {
1818 DP_INFO(hwfn, "Allowed modes are cee, ieee or static\n");
1822 memset(&dcbx_set, 0, sizeof(dcbx_set));
1823 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1827 dcbx_set.ver_num = 0;
1828 if (mode & DCB_CAP_DCBX_VER_CEE) {
1829 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1830 dcbx_set.enabled = true;
1833 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1834 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1835 dcbx_set.enabled = true;
1838 if (mode & DCB_CAP_DCBX_STATIC) {
1839 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1840 dcbx_set.enabled = true;
1843 ptt = qed_ptt_acquire(hwfn);
1847 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1849 qed_ptt_release(hwfn, ptt);
1854 static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1856 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1857 struct qed_dcbx_get *dcbx_info;
1859 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1860 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1866 case DCB_FEATCFG_ATTR_PG:
1867 if (dcbx_info->operational.params.ets_enabled)
1868 *flags = DCB_FEATCFG_ENABLE;
1870 *flags = DCB_FEATCFG_ERROR;
1872 case DCB_FEATCFG_ATTR_PFC:
1873 if (dcbx_info->operational.params.pfc.enabled)
1874 *flags = DCB_FEATCFG_ENABLE;
1876 *flags = DCB_FEATCFG_ERROR;
1878 case DCB_FEATCFG_ATTR_APP:
1879 if (dcbx_info->operational.params.app_valid)
1880 *flags = DCB_FEATCFG_ENABLE;
1882 *flags = DCB_FEATCFG_ERROR;
1885 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1890 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1896 static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1898 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1899 struct qed_dcbx_set dcbx_set;
1900 bool enabled, willing;
1901 struct qed_ptt *ptt;
1904 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1906 memset(&dcbx_set, 0, sizeof(dcbx_set));
1907 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1911 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1912 willing = !!(flags & DCB_FEATCFG_WILLING);
1914 case DCB_FEATCFG_ATTR_PG:
1915 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1916 dcbx_set.config.params.ets_enabled = enabled;
1917 dcbx_set.config.params.ets_willing = willing;
1919 case DCB_FEATCFG_ATTR_PFC:
1920 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1921 dcbx_set.config.params.pfc.enabled = enabled;
1922 dcbx_set.config.params.pfc.willing = willing;
1924 case DCB_FEATCFG_ATTR_APP:
1925 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1926 dcbx_set.config.params.app_willing = willing;
1929 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1933 ptt = qed_ptt_acquire(hwfn);
1937 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1939 qed_ptt_release(hwfn, ptt);
1944 static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1945 struct dcb_peer_app_info *info,
1948 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1949 struct qed_dcbx_get *dcbx_info;
1951 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1955 info->willing = dcbx_info->remote.params.app_willing;
1956 info->error = dcbx_info->remote.params.app_error;
1957 *app_count = dcbx_info->remote.params.num_app_entries;
1963 static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1964 struct dcb_app *table)
1966 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1967 struct qed_dcbx_get *dcbx_info;
1970 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1974 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
1975 if (dcbx_info->remote.params.app_entry[i].ethtype)
1976 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
1978 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
1979 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
1981 dcbx_info->remote.params.app_entry[i].proto_id;
1989 static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
1991 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1992 struct qed_dcbx_get *dcbx_info;
1995 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1999 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2000 if (dcbx_info->remote.params.pfc.prio[i])
2001 pfc->pfc_en |= BIT(i);
2003 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
2004 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
2005 pfc->pfc_en, pfc->tcs_supported);
2011 static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
2013 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2014 struct qed_dcbx_get *dcbx_info;
2017 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2021 pg->willing = dcbx_info->remote.params.ets_willing;
2022 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
2023 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
2024 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
2027 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
2033 static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
2034 struct ieee_pfc *pfc, bool remote)
2036 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2037 struct qed_dcbx_params *params;
2038 struct qed_dcbx_get *dcbx_info;
2041 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2045 if (!dcbx_info->operational.ieee) {
2046 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2052 memset(dcbx_info, 0, sizeof(*dcbx_info));
2053 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2054 QED_DCBX_REMOTE_MIB);
2060 params = &dcbx_info->remote.params;
2062 params = &dcbx_info->operational.params;
2065 pfc->pfc_cap = params->pfc.max_tc;
2067 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2068 if (params->pfc.prio[i])
2069 pfc->pfc_en |= BIT(i);
2076 static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2078 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2081 static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2083 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2084 struct qed_dcbx_get *dcbx_info;
2085 struct qed_dcbx_set dcbx_set;
2086 struct qed_ptt *ptt;
2089 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2093 if (!dcbx_info->operational.ieee) {
2094 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2101 memset(&dcbx_set, 0, sizeof(dcbx_set));
2102 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2106 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2107 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2108 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2110 dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
2112 ptt = qed_ptt_acquire(hwfn);
2116 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2118 qed_ptt_release(hwfn, ptt);
2123 static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2124 struct ieee_ets *ets, bool remote)
2126 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2127 struct qed_dcbx_get *dcbx_info;
2128 struct qed_dcbx_params *params;
2131 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2135 if (!dcbx_info->operational.ieee) {
2136 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2142 memset(dcbx_info, 0, sizeof(*dcbx_info));
2143 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2144 QED_DCBX_REMOTE_MIB);
2150 params = &dcbx_info->remote.params;
2152 params = &dcbx_info->operational.params;
2155 ets->ets_cap = params->max_ets_tc;
2156 ets->willing = params->ets_willing;
2157 ets->cbs = params->ets_cbs;
2158 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2159 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2160 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2166 static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2168 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2171 static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2173 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2174 struct qed_dcbx_get *dcbx_info;
2175 struct qed_dcbx_set dcbx_set;
2176 struct qed_ptt *ptt;
2179 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2183 if (!dcbx_info->operational.ieee) {
2184 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2191 memset(&dcbx_set, 0, sizeof(dcbx_set));
2192 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2196 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2197 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2198 dcbx_set.config.params.ets_willing = ets->willing;
2199 dcbx_set.config.params.ets_cbs = ets->cbs;
2200 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2201 sizeof(ets->tc_tx_bw));
2202 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2203 sizeof(ets->tc_tsa));
2204 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2205 sizeof(ets->prio_tc));
2207 ptt = qed_ptt_acquire(hwfn);
2211 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2213 qed_ptt_release(hwfn, ptt);
2219 qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2221 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2225 qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2227 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2230 static int qed_get_sf_ieee_value(u8 selector, u8 *sf_ieee)
2233 case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
2234 *sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
2236 case IEEE_8021QAZ_APP_SEL_STREAM:
2237 *sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
2239 case IEEE_8021QAZ_APP_SEL_DGRAM:
2240 *sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
2242 case IEEE_8021QAZ_APP_SEL_ANY:
2243 *sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
2252 static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
2254 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2255 struct qed_dcbx_get *dcbx_info;
2256 struct qed_app_entry *entry;
2261 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d\n",
2262 app->selector, app->protocol);
2264 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2265 DP_INFO(cdev, "Invalid selector field value %d\n",
2270 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2274 if (!dcbx_info->operational.ieee) {
2275 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2280 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2281 entry = &dcbx_info->operational.params.app_entry[i];
2282 if ((entry->sf_ieee == sf_ieee) &&
2283 (entry->proto_id == app->protocol)) {
2289 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2290 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2296 app->priority = ffs(prio) - 1;
2303 static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
2305 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2306 struct qed_dcbx_get *dcbx_info;
2307 struct qed_dcbx_set dcbx_set;
2308 struct qed_app_entry *entry;
2309 struct qed_ptt *ptt;
2313 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d pri = %d\n",
2314 app->selector, app->protocol, app->priority);
2315 if (app->priority >= QED_MAX_PFC_PRIORITIES) {
2316 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2320 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2321 DP_INFO(cdev, "Invalid selector field value %d\n",
2326 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2330 if (!dcbx_info->operational.ieee) {
2331 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2338 memset(&dcbx_set, 0, sizeof(dcbx_set));
2339 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2343 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2344 entry = &dcbx_set.config.params.app_entry[i];
2345 if ((entry->sf_ieee == sf_ieee) &&
2346 (entry->proto_id == app->protocol))
2348 /* First empty slot */
2349 if (!entry->proto_id) {
2350 dcbx_set.config.params.num_app_entries++;
2355 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2356 DP_ERR(cdev, "App table is full\n");
2360 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
2361 dcbx_set.config.params.app_entry[i].sf_ieee = sf_ieee;
2362 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2363 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2365 ptt = qed_ptt_acquire(hwfn);
2369 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2371 qed_ptt_release(hwfn, ptt);
2376 const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2377 .getstate = qed_dcbnl_getstate,
2378 .setstate = qed_dcbnl_setstate,
2379 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2380 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2381 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2382 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2383 .getpfccfg = qed_dcbnl_getpfccfg,
2384 .setpfccfg = qed_dcbnl_setpfccfg,
2385 .getcap = qed_dcbnl_getcap,
2386 .getnumtcs = qed_dcbnl_getnumtcs,
2387 .getpfcstate = qed_dcbnl_getpfcstate,
2388 .getdcbx = qed_dcbnl_getdcbx,
2389 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2390 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2391 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2392 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2393 .setall = qed_dcbnl_setall,
2394 .setnumtcs = qed_dcbnl_setnumtcs,
2395 .setpfcstate = qed_dcbnl_setpfcstate,
2396 .setapp = qed_dcbnl_setapp,
2397 .setdcbx = qed_dcbnl_setdcbx,
2398 .setfeatcfg = qed_dcbnl_setfeatcfg,
2399 .getfeatcfg = qed_dcbnl_getfeatcfg,
2400 .getapp = qed_dcbnl_getapp,
2401 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2402 .peer_getapptable = qed_dcbnl_peer_getapptable,
2403 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2404 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2405 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2406 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2407 .ieee_getets = qed_dcbnl_ieee_getets,
2408 .ieee_setets = qed_dcbnl_ieee_setets,
2409 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2410 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2411 .ieee_getapp = qed_dcbnl_ieee_getapp,
2412 .ieee_setapp = qed_dcbnl_ieee_setapp,