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;
282 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
284 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
286 for (i = 0; i < count; i++) {
287 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
288 DCBX_APP_PROTOCOL_ID);
289 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
291 priority = ffs(priority_map) - 1;
293 DP_ERR(p_hwfn, "Invalid priority\n");
297 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
298 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
299 protocol_id, &type, ieee)) {
300 /* ETH always have the enable bit reset, as it gets
301 * vlan information per packet. For other protocols,
302 * should be set according to the dcbx_enabled
303 * indication, but we only got here if there was an
304 * app tlv for the protocol, so dcbx must be enabled.
306 enable = !(type == DCBX_PROTOCOL_ETH);
308 qed_dcbx_update_app_info(p_data, p_hwfn, enable,
313 /* Update ramrod protocol data and hw_info fields
314 * with default info when corresponding APP TLV's are not detected.
315 * The enabled field has a different logic for ethernet as only for
316 * ethernet dcb should disabled by default, as the information arrives
317 * from the OS (unless an explicit app tlv was present).
319 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
320 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
321 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
322 if (p_data->arr[type].update)
325 enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
326 qed_dcbx_update_app_info(p_data, p_hwfn, enable,
333 /* Parse app TLV's to update TC information in hw_info structure for
334 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
336 static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
338 struct dcbx_app_priority_feature *p_app;
339 struct dcbx_app_priority_entry *p_tbl;
340 struct qed_dcbx_results data = { 0 };
341 struct dcbx_ets_feature *p_ets;
342 struct qed_hw_info *p_info;
343 u32 pri_tc_tbl, flags;
348 flags = p_hwfn->p_dcbx_info->operational.flags;
349 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
351 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
352 p_tbl = p_app->app_pri_tbl;
354 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
355 pri_tc_tbl = p_ets->pri_tc_tbl[0];
357 p_info = &p_hwfn->hw_info;
358 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
360 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
361 num_entries, dcbx_version);
365 p_info->num_active_tc = QED_MFW_GET_FIELD(p_ets->flags,
367 p_hwfn->qm_info.ooo_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
368 data.pf_id = p_hwfn->rel_pf_id;
369 data.dcbx_enabled = !!dcbx_version;
371 qed_dcbx_dp_protocol(p_hwfn, &data);
373 memcpy(&p_hwfn->p_dcbx_info->results, &data,
374 sizeof(struct qed_dcbx_results));
380 qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
381 struct qed_ptt *p_ptt,
382 struct qed_dcbx_mib_meta_data *p_data,
383 enum qed_mib_read_type type)
385 u32 prefix_seq_num, suffix_seq_num;
389 /* The data is considered to be valid only if both sequence numbers are
393 if (type == QED_DCBX_REMOTE_LLDP_MIB) {
394 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
395 p_data->addr, p_data->size);
396 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
397 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
399 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
400 p_data->addr, p_data->size);
401 prefix_seq_num = p_data->mib->prefix_seq_num;
402 suffix_seq_num = p_data->mib->suffix_seq_num;
408 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
409 type, read_count, prefix_seq_num, suffix_seq_num);
410 } while ((prefix_seq_num != suffix_seq_num) &&
411 (read_count < QED_DCBX_MAX_MIB_READ_TRY));
413 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
415 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
416 type, read_count, prefix_seq_num, suffix_seq_num);
424 qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
425 struct qed_dcbx_app_prio *p_prio,
426 struct qed_dcbx_results *p_results)
430 p_prio->roce = QED_DCBX_INVALID_PRIORITY;
431 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
432 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
433 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
435 if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
436 p_results->arr[DCBX_PROTOCOL_ROCE].enable)
437 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
439 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
440 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
441 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
442 p_prio->roce_v2 = val;
445 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
446 p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
447 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
449 if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
450 p_results->arr[DCBX_PROTOCOL_FCOE].enable)
451 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
453 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
454 p_results->arr[DCBX_PROTOCOL_ETH].enable)
455 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
457 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
458 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
459 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
464 qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
465 struct dcbx_app_priority_feature *p_app,
466 struct dcbx_app_priority_entry *p_tbl,
467 struct qed_dcbx_params *p_params, bool ieee)
469 struct qed_app_entry *entry;
473 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
475 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
476 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
477 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
478 DCBX_APP_NUM_ENTRIES);
479 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
480 entry = &p_params->app_entry[i];
485 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
488 case DCBX_APP_SF_IEEE_RESERVED:
490 val = QED_MFW_GET_FIELD(p_tbl[i].entry,
492 entry->sf_ieee = val ?
493 QED_DCBX_SF_IEEE_TCP_UDP_PORT :
494 QED_DCBX_SF_IEEE_ETHTYPE;
496 case DCBX_APP_SF_IEEE_ETHTYPE:
497 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
499 case DCBX_APP_SF_IEEE_TCP_PORT:
500 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
502 case DCBX_APP_SF_IEEE_UDP_PORT:
503 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
505 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
506 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
510 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
514 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
515 entry->prio = ffs(pri_map) - 1;
516 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
517 DCBX_APP_PROTOCOL_ID);
518 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
520 &entry->proto_type, ieee);
523 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
524 "APP params: willing %d, valid %d error = %d\n",
525 p_params->app_willing, p_params->app_valid,
526 p_params->app_error);
530 qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
531 u32 pfc, struct qed_dcbx_params *p_params)
535 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
536 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
537 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
538 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
539 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
540 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
541 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
542 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
543 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
544 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
545 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
546 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
548 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
549 "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
550 p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
551 p_params->pfc.enabled);
555 qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
556 struct dcbx_ets_feature *p_ets,
557 struct qed_dcbx_params *p_params)
559 u32 bw_map[2], tsa_map[2], pri_map;
562 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
564 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
566 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
567 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
569 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
570 "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
571 p_params->ets_willing, p_params->ets_enabled,
572 p_params->ets_cbs, p_ets->pri_tc_tbl[0],
573 p_params->max_ets_tc);
575 if (p_params->ets_enabled && !p_params->max_ets_tc) {
576 p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
577 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
578 "ETS params: max_ets_tc is forced to %d\n",
579 p_params->max_ets_tc);
582 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
583 * encoded in a type u32 array of size 2.
585 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
586 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
587 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
588 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
589 pri_map = p_ets->pri_tc_tbl[0];
590 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
591 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
592 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
593 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
594 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
595 "elem %d bw_tbl %x tsa_tbl %x\n",
596 i, p_params->ets_tc_bw_tbl[i],
597 p_params->ets_tc_tsa_tbl[i]);
602 qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
603 struct dcbx_app_priority_feature *p_app,
604 struct dcbx_app_priority_entry *p_tbl,
605 struct dcbx_ets_feature *p_ets,
606 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
608 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
609 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
610 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
614 qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
616 struct dcbx_features *p_feat;
618 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
619 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
620 p_feat->app.app_pri_tbl, &p_feat->ets,
621 p_feat->pfc, ¶ms->local.params, false);
622 params->local.valid = true;
626 qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
628 struct dcbx_features *p_feat;
630 p_feat = &p_hwfn->p_dcbx_info->remote.features;
631 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
632 p_feat->app.app_pri_tbl, &p_feat->ets,
633 p_feat->pfc, ¶ms->remote.params, false);
634 params->remote.valid = true;
638 qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
639 struct qed_dcbx_get *params)
641 struct qed_dcbx_operational_params *p_operational;
642 struct qed_dcbx_results *p_results;
643 struct dcbx_features *p_feat;
648 flags = p_hwfn->p_dcbx_info->operational.flags;
650 /* If DCBx version is non zero, then negotiation
651 * was successfuly performed
653 p_operational = ¶ms->operational;
654 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
655 DCBX_CONFIG_VERSION_DISABLED);
657 p_operational->enabled = enabled;
658 p_operational->valid = false;
659 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx is disabled\n");
663 p_feat = &p_hwfn->p_dcbx_info->operational.features;
664 p_results = &p_hwfn->p_dcbx_info->results;
666 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
667 DCBX_CONFIG_VERSION_IEEE);
668 p_operational->ieee = val;
669 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
670 DCBX_CONFIG_VERSION_CEE);
671 p_operational->cee = val;
673 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
674 DCBX_CONFIG_VERSION_STATIC);
675 p_operational->local = val;
677 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
678 "Version support: ieee %d, cee %d, static %d\n",
679 p_operational->ieee, p_operational->cee,
680 p_operational->local);
682 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
683 p_feat->app.app_pri_tbl, &p_feat->ets,
684 p_feat->pfc, ¶ms->operational.params,
685 p_operational->ieee);
686 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
687 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
688 p_operational->err = err;
689 p_operational->enabled = enabled;
690 p_operational->valid = true;
694 qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
695 struct qed_dcbx_get *params)
697 struct lldp_config_params_s *p_local;
699 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
701 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
702 sizeof(p_local->local_chassis_id));
703 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
704 sizeof(p_local->local_port_id));
708 qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
709 struct qed_dcbx_get *params)
711 struct lldp_status_params_s *p_remote;
713 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
715 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
716 sizeof(p_remote->peer_chassis_id));
717 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
718 sizeof(p_remote->peer_port_id));
722 qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
723 enum qed_mib_read_type type)
726 case QED_DCBX_REMOTE_MIB:
727 qed_dcbx_get_remote_params(p_hwfn, p_params);
729 case QED_DCBX_LOCAL_MIB:
730 qed_dcbx_get_local_params(p_hwfn, p_params);
732 case QED_DCBX_OPERATIONAL_MIB:
733 qed_dcbx_get_operational_params(p_hwfn, p_params);
735 case QED_DCBX_REMOTE_LLDP_MIB:
736 qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
738 case QED_DCBX_LOCAL_LLDP_MIB:
739 qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
742 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
750 qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
752 struct qed_dcbx_mib_meta_data data;
755 memset(&data, 0, sizeof(data));
756 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
758 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
759 data.size = sizeof(struct lldp_config_params_s);
760 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
766 qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
767 struct qed_ptt *p_ptt,
768 enum qed_mib_read_type type)
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_remote = p_hwfn->p_dcbx_info->lldp_remote;
777 data.size = sizeof(struct lldp_status_params_s);
778 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
784 qed_dcbx_read_operational_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 +
793 offsetof(struct public_port, operational_dcbx_mib);
794 data.mib = &p_hwfn->p_dcbx_info->operational;
795 data.size = sizeof(struct dcbx_mib);
796 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
802 qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
803 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
805 struct qed_dcbx_mib_meta_data data;
808 memset(&data, 0, sizeof(data));
809 data.addr = p_hwfn->mcp_info->port_addr +
810 offsetof(struct public_port, remote_dcbx_mib);
811 data.mib = &p_hwfn->p_dcbx_info->remote;
812 data.size = sizeof(struct dcbx_mib);
813 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
819 qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
821 struct qed_dcbx_mib_meta_data data;
824 memset(&data, 0, sizeof(data));
825 data.addr = p_hwfn->mcp_info->port_addr +
826 offsetof(struct public_port, local_admin_dcbx_mib);
827 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
828 data.size = sizeof(struct dcbx_local_params);
829 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
834 static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
835 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
840 case QED_DCBX_OPERATIONAL_MIB:
841 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
843 case QED_DCBX_REMOTE_MIB:
844 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
846 case QED_DCBX_LOCAL_MIB:
847 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
849 case QED_DCBX_REMOTE_LLDP_MIB:
850 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
852 case QED_DCBX_LOCAL_LLDP_MIB:
853 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
856 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
862 void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
864 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
865 void *cookie = hwfn->cdev->ops_cookie;
867 if (cookie && op->dcbx_aen)
868 op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
872 * Reconfigure QM and invoke PF update ramrod command if operational MIB
873 * change is detected.
876 qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
877 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
881 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
885 if (type == QED_DCBX_OPERATIONAL_MIB) {
886 rc = qed_dcbx_process_mib_info(p_hwfn);
888 /* reconfigure tcs of QM queues according
889 * to negotiation results
891 qed_qm_reconf(p_hwfn, p_ptt);
893 /* update storm FW with negotiation results */
894 qed_sp_pf_update(p_hwfn);
896 /* for roce PFs, we may want to enable/disable DPM
897 * when DCBx change occurs
899 if (p_hwfn->hw_info.personality ==
901 qed_roce_dpm_dcbx(p_hwfn, p_ptt);
905 qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
907 if (type == QED_DCBX_OPERATIONAL_MIB) {
908 struct qed_dcbx_results *p_data;
911 /* Configure in NIG which protocols support EDPM and should
914 p_data = &p_hwfn->p_dcbx_info->results;
915 val = (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE].tc) |
916 (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE_V2].tc);
917 val <<= NIG_REG_TX_EDPM_CTRL_TX_EDPM_TC_EN_SHIFT;
918 val |= NIG_REG_TX_EDPM_CTRL_TX_EDPM_EN;
919 qed_wr(p_hwfn, p_ptt, NIG_REG_TX_EDPM_CTRL, val);
922 qed_dcbx_aen(p_hwfn, type);
927 int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
929 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
930 if (!p_hwfn->p_dcbx_info)
936 void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
938 kfree(p_hwfn->p_dcbx_info);
939 p_hwfn->p_dcbx_info = NULL;
942 static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
943 struct qed_dcbx_results *p_src,
944 enum dcbx_protocol_type type)
946 p_data->dcb_enable_flag = p_src->arr[type].enable;
947 p_data->dcb_priority = p_src->arr[type].priority;
948 p_data->dcb_tc = p_src->arr[type].tc;
951 /* Set pf update ramrod command params */
952 void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
953 struct pf_update_ramrod_data *p_dest)
955 struct protocol_dcb_data *p_dcb_data;
956 bool update_flag = false;
958 p_dest->pf_id = p_src->pf_id;
960 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
961 p_dest->update_fcoe_dcb_data_mode = update_flag;
963 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
964 p_dest->update_roce_dcb_data_mode = update_flag;
966 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
967 p_dest->update_rroce_dcb_data_mode = update_flag;
969 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
970 p_dest->update_iscsi_dcb_data_mode = update_flag;
971 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
972 p_dest->update_eth_dcb_data_mode = update_flag;
974 p_dcb_data = &p_dest->fcoe_dcb_data;
975 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
976 p_dcb_data = &p_dest->roce_dcb_data;
977 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
978 p_dcb_data = &p_dest->rroce_dcb_data;
979 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
980 p_dcb_data = &p_dest->iscsi_dcb_data;
981 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
982 p_dcb_data = &p_dest->eth_dcb_data;
983 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
987 static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
988 struct qed_dcbx_get *p_get,
989 enum qed_mib_read_type type)
991 struct qed_ptt *p_ptt;
994 if (IS_VF(p_hwfn->cdev))
997 p_ptt = qed_ptt_acquire(p_hwfn);
1001 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
1005 rc = qed_dcbx_get_params(p_hwfn, p_get, type);
1008 qed_ptt_release(p_hwfn, p_ptt);
1013 qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
1014 u32 *pfc, struct qed_dcbx_params *p_params)
1019 *pfc &= ~DCBX_PFC_ERROR_MASK;
1021 if (p_params->pfc.willing)
1022 *pfc |= DCBX_PFC_WILLING_MASK;
1024 *pfc &= ~DCBX_PFC_WILLING_MASK;
1026 if (p_params->pfc.enabled)
1027 *pfc |= DCBX_PFC_ENABLED_MASK;
1029 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1031 *pfc &= ~DCBX_PFC_CAPS_MASK;
1032 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
1034 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1035 if (p_params->pfc.prio[i])
1038 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
1039 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
1041 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
1045 qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
1046 struct dcbx_ets_feature *p_ets,
1047 struct qed_dcbx_params *p_params)
1049 u8 *bw_map, *tsa_map;
1053 if (p_params->ets_willing)
1054 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1056 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1058 if (p_params->ets_cbs)
1059 p_ets->flags |= DCBX_ETS_CBS_MASK;
1061 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1063 if (p_params->ets_enabled)
1064 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1066 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1068 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1069 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1071 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1072 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1073 p_ets->pri_tc_tbl[0] = 0;
1074 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1075 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1076 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1077 /* Copy the priority value to the corresponding 4 bits in the
1078 * traffic class table.
1080 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1081 p_ets->pri_tc_tbl[0] |= val;
1083 for (i = 0; i < 2; i++) {
1084 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1085 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1090 qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1091 struct dcbx_app_priority_feature *p_app,
1092 struct qed_dcbx_params *p_params, bool ieee)
1097 if (p_params->app_willing)
1098 p_app->flags |= DCBX_APP_WILLING_MASK;
1100 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1102 if (p_params->app_valid)
1103 p_app->flags |= DCBX_APP_ENABLED_MASK;
1105 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1107 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1108 p_app->flags |= (u32)p_params->num_app_entries <<
1109 DCBX_APP_NUM_ENTRIES_SHIFT;
1111 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1112 entry = &p_app->app_pri_tbl[i].entry;
1115 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
1116 switch (p_params->app_entry[i].sf_ieee) {
1117 case QED_DCBX_SF_IEEE_ETHTYPE:
1118 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1119 DCBX_APP_SF_IEEE_SHIFT);
1120 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1123 case QED_DCBX_SF_IEEE_TCP_PORT:
1124 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1125 DCBX_APP_SF_IEEE_SHIFT);
1126 *entry |= ((u32)DCBX_APP_SF_PORT <<
1129 case QED_DCBX_SF_IEEE_UDP_PORT:
1130 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1131 DCBX_APP_SF_IEEE_SHIFT);
1132 *entry |= ((u32)DCBX_APP_SF_PORT <<
1135 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1136 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1137 DCBX_APP_SF_IEEE_SHIFT);
1138 *entry |= ((u32)DCBX_APP_SF_PORT <<
1143 *entry &= ~DCBX_APP_SF_MASK;
1144 if (p_params->app_entry[i].ethtype)
1145 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1148 *entry |= ((u32)DCBX_APP_SF_PORT <<
1152 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1153 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1154 DCBX_APP_PROTOCOL_ID_SHIFT);
1155 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1156 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1157 DCBX_APP_PRI_MAP_SHIFT);
1162 qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1163 struct dcbx_local_params *local_admin,
1164 struct qed_dcbx_set *params)
1168 local_admin->flags = 0;
1169 memcpy(&local_admin->features,
1170 &p_hwfn->p_dcbx_info->operational.features,
1171 sizeof(local_admin->features));
1173 if (params->enabled) {
1174 local_admin->config = params->ver_num;
1175 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1177 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1180 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx version = %d\n",
1181 local_admin->config);
1183 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1184 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1185 ¶ms->config.params);
1187 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1188 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1189 ¶ms->config.params);
1191 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1192 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1193 ¶ms->config.params, ieee);
1196 int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1197 struct qed_dcbx_set *params, bool hw_commit)
1199 struct dcbx_local_params local_admin;
1200 struct qed_dcbx_mib_meta_data data;
1201 u32 resp = 0, param = 0;
1205 memcpy(&p_hwfn->p_dcbx_info->set, params,
1206 sizeof(struct qed_dcbx_set));
1210 /* clear set-parmas cache */
1211 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1213 memset(&local_admin, 0, sizeof(local_admin));
1214 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1216 data.addr = p_hwfn->mcp_info->port_addr +
1217 offsetof(struct public_port, local_admin_dcbx_mib);
1218 data.local_admin = &local_admin;
1219 data.size = sizeof(struct dcbx_local_params);
1220 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1222 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1223 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, ¶m);
1225 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1230 int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1231 struct qed_dcbx_set *params)
1233 struct qed_dcbx_get *dcbx_info;
1236 if (p_hwfn->p_dcbx_info->set.config.valid) {
1237 memcpy(params, &p_hwfn->p_dcbx_info->set,
1238 sizeof(struct qed_dcbx_set));
1242 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
1246 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1252 p_hwfn->p_dcbx_info->set.override_flags = 0;
1253 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1254 if (dcbx_info->operational.cee)
1255 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1256 if (dcbx_info->operational.ieee)
1257 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1258 if (dcbx_info->operational.local)
1259 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1261 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1262 BUILD_BUG_ON(sizeof(dcbx_info->operational.params) !=
1263 sizeof(p_hwfn->p_dcbx_info->set.config.params));
1264 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1265 &dcbx_info->operational.params,
1266 sizeof(p_hwfn->p_dcbx_info->set.config.params));
1267 p_hwfn->p_dcbx_info->set.config.valid = true;
1269 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1276 static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1277 enum qed_mib_read_type type)
1279 struct qed_dcbx_get *dcbx_info;
1281 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
1285 memset(dcbx_info, 0, sizeof(*dcbx_info));
1286 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1291 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1292 !dcbx_info->operational.enabled) {
1293 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1301 static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1303 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1304 struct qed_dcbx_get *dcbx_info;
1307 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1311 enabled = dcbx_info->operational.enabled;
1312 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1318 static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1320 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1321 struct qed_dcbx_set dcbx_set;
1322 struct qed_ptt *ptt;
1325 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1327 memset(&dcbx_set, 0, sizeof(dcbx_set));
1328 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1332 dcbx_set.enabled = !!state;
1334 ptt = qed_ptt_acquire(hwfn);
1338 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1340 qed_ptt_release(hwfn, ptt);
1345 static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1346 u8 *pgid, u8 *bw_pct, u8 *up_map)
1348 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1349 struct qed_dcbx_get *dcbx_info;
1351 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1352 *prio_type = *pgid = *bw_pct = *up_map = 0;
1353 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1354 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1358 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1362 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1366 static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1368 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1369 struct qed_dcbx_get *dcbx_info;
1372 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1373 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1374 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1378 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1382 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1383 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1387 static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1388 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1390 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1391 *prio = *bwg_id = *bw_pct = *up_map = 0;
1394 static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1395 int bwg_id, u8 *bw_pct)
1397 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1401 static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1402 int priority, u8 *setting)
1404 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1405 struct qed_dcbx_get *dcbx_info;
1407 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1408 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1409 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1413 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1417 *setting = dcbx_info->operational.params.pfc.prio[priority];
1418 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1422 static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1424 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1425 struct qed_dcbx_set dcbx_set;
1426 struct qed_ptt *ptt;
1429 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1431 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1432 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1436 memset(&dcbx_set, 0, sizeof(dcbx_set));
1437 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1441 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1442 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1444 ptt = qed_ptt_acquire(hwfn);
1448 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1450 qed_ptt_release(hwfn, ptt);
1453 static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1455 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1456 struct qed_dcbx_get *dcbx_info;
1459 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1460 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1465 case DCB_CAP_ATTR_PG:
1466 case DCB_CAP_ATTR_PFC:
1467 case DCB_CAP_ATTR_UP2TC:
1468 case DCB_CAP_ATTR_GSP:
1471 case DCB_CAP_ATTR_PG_TCS:
1472 case DCB_CAP_ATTR_PFC_TCS:
1475 case DCB_CAP_ATTR_DCBX:
1476 *cap = (DCB_CAP_DCBX_VER_CEE | DCB_CAP_DCBX_VER_IEEE |
1477 DCB_CAP_DCBX_STATIC);
1484 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1490 static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1492 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1493 struct qed_dcbx_get *dcbx_info;
1496 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1497 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1502 case DCB_NUMTCS_ATTR_PG:
1503 *num = dcbx_info->operational.params.max_ets_tc;
1505 case DCB_NUMTCS_ATTR_PFC:
1506 *num = dcbx_info->operational.params.pfc.max_tc;
1513 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1518 static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1520 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1521 struct qed_dcbx_get *dcbx_info;
1524 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1528 enabled = dcbx_info->operational.params.pfc.enabled;
1529 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1535 static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1537 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1538 struct qed_dcbx_get *dcbx_info;
1541 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1545 if (dcbx_info->operational.ieee)
1546 mode |= DCB_CAP_DCBX_VER_IEEE;
1547 if (dcbx_info->operational.cee)
1548 mode |= DCB_CAP_DCBX_VER_CEE;
1549 if (dcbx_info->operational.local)
1550 mode |= DCB_CAP_DCBX_STATIC;
1552 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1558 static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1560 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1562 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1563 struct qed_dcbx_set dcbx_set;
1564 struct qed_ptt *ptt;
1567 DP_VERBOSE(hwfn, QED_MSG_DCB,
1568 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1569 tc, pri_type, pgid, bw_pct, up_map);
1571 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1572 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1576 memset(&dcbx_set, 0, sizeof(dcbx_set));
1577 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1581 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1582 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1584 ptt = qed_ptt_acquire(hwfn);
1588 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1590 qed_ptt_release(hwfn, ptt);
1593 static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1594 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1596 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1599 static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1601 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1602 struct qed_dcbx_set dcbx_set;
1603 struct qed_ptt *ptt;
1606 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1607 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1608 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1612 memset(&dcbx_set, 0, sizeof(dcbx_set));
1613 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1617 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1618 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1620 ptt = qed_ptt_acquire(hwfn);
1624 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1626 qed_ptt_release(hwfn, ptt);
1629 static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1631 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1634 static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1636 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1637 struct qed_dcbx_set dcbx_set;
1638 struct qed_ptt *ptt;
1641 memset(&dcbx_set, 0, sizeof(dcbx_set));
1642 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1646 ptt = qed_ptt_acquire(hwfn);
1650 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1652 qed_ptt_release(hwfn, ptt);
1657 static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1659 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1660 struct qed_dcbx_set dcbx_set;
1661 struct qed_ptt *ptt;
1664 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1665 memset(&dcbx_set, 0, sizeof(dcbx_set));
1666 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1671 case DCB_NUMTCS_ATTR_PG:
1672 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1673 dcbx_set.config.params.max_ets_tc = num;
1675 case DCB_NUMTCS_ATTR_PFC:
1676 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1677 dcbx_set.config.params.pfc.max_tc = num;
1680 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1684 ptt = qed_ptt_acquire(hwfn);
1688 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1690 qed_ptt_release(hwfn, ptt);
1695 static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1697 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1698 struct qed_dcbx_set dcbx_set;
1699 struct qed_ptt *ptt;
1702 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1704 memset(&dcbx_set, 0, sizeof(dcbx_set));
1705 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1709 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1710 dcbx_set.config.params.pfc.enabled = !!state;
1712 ptt = qed_ptt_acquire(hwfn);
1716 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1718 qed_ptt_release(hwfn, ptt);
1721 static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1723 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1724 struct qed_dcbx_get *dcbx_info;
1725 struct qed_app_entry *entry;
1730 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1734 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1735 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1736 entry = &dcbx_info->operational.params.app_entry[i];
1737 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1743 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1744 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1754 static int qed_dcbnl_setapp(struct qed_dev *cdev,
1755 u8 idtype, u16 idval, u8 pri_map)
1757 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1758 struct qed_dcbx_set dcbx_set;
1759 struct qed_app_entry *entry;
1760 struct qed_ptt *ptt;
1764 memset(&dcbx_set, 0, sizeof(dcbx_set));
1765 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1769 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1770 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1771 entry = &dcbx_set.config.params.app_entry[i];
1772 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1774 /* First empty slot */
1775 if (!entry->proto_id) {
1776 dcbx_set.config.params.num_app_entries++;
1781 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1782 DP_ERR(cdev, "App table is full\n");
1786 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1787 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1788 dcbx_set.config.params.app_entry[i].proto_id = idval;
1789 dcbx_set.config.params.app_entry[i].prio = pri_map;
1791 ptt = qed_ptt_acquire(hwfn);
1795 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1797 qed_ptt_release(hwfn, ptt);
1802 static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1804 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1805 struct qed_dcbx_set dcbx_set;
1806 struct qed_ptt *ptt;
1809 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1811 if (!(mode & DCB_CAP_DCBX_VER_IEEE) &&
1812 !(mode & DCB_CAP_DCBX_VER_CEE) && !(mode & DCB_CAP_DCBX_STATIC)) {
1813 DP_INFO(hwfn, "Allowed modes are cee, ieee or static\n");
1817 memset(&dcbx_set, 0, sizeof(dcbx_set));
1818 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1822 dcbx_set.ver_num = 0;
1823 if (mode & DCB_CAP_DCBX_VER_CEE) {
1824 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1825 dcbx_set.enabled = true;
1828 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1829 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1830 dcbx_set.enabled = true;
1833 if (mode & DCB_CAP_DCBX_STATIC) {
1834 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1835 dcbx_set.enabled = true;
1838 ptt = qed_ptt_acquire(hwfn);
1842 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1844 qed_ptt_release(hwfn, ptt);
1849 static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1851 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1852 struct qed_dcbx_get *dcbx_info;
1854 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1855 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1861 case DCB_FEATCFG_ATTR_PG:
1862 if (dcbx_info->operational.params.ets_enabled)
1863 *flags = DCB_FEATCFG_ENABLE;
1865 *flags = DCB_FEATCFG_ERROR;
1867 case DCB_FEATCFG_ATTR_PFC:
1868 if (dcbx_info->operational.params.pfc.enabled)
1869 *flags = DCB_FEATCFG_ENABLE;
1871 *flags = DCB_FEATCFG_ERROR;
1873 case DCB_FEATCFG_ATTR_APP:
1874 if (dcbx_info->operational.params.app_valid)
1875 *flags = DCB_FEATCFG_ENABLE;
1877 *flags = DCB_FEATCFG_ERROR;
1880 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1885 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1891 static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1893 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1894 struct qed_dcbx_set dcbx_set;
1895 bool enabled, willing;
1896 struct qed_ptt *ptt;
1899 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1901 memset(&dcbx_set, 0, sizeof(dcbx_set));
1902 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1906 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1907 willing = !!(flags & DCB_FEATCFG_WILLING);
1909 case DCB_FEATCFG_ATTR_PG:
1910 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1911 dcbx_set.config.params.ets_enabled = enabled;
1912 dcbx_set.config.params.ets_willing = willing;
1914 case DCB_FEATCFG_ATTR_PFC:
1915 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1916 dcbx_set.config.params.pfc.enabled = enabled;
1917 dcbx_set.config.params.pfc.willing = willing;
1919 case DCB_FEATCFG_ATTR_APP:
1920 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1921 dcbx_set.config.params.app_willing = willing;
1924 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1928 ptt = qed_ptt_acquire(hwfn);
1932 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1934 qed_ptt_release(hwfn, ptt);
1939 static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1940 struct dcb_peer_app_info *info,
1943 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1944 struct qed_dcbx_get *dcbx_info;
1946 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1950 info->willing = dcbx_info->remote.params.app_willing;
1951 info->error = dcbx_info->remote.params.app_error;
1952 *app_count = dcbx_info->remote.params.num_app_entries;
1958 static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1959 struct dcb_app *table)
1961 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1962 struct qed_dcbx_get *dcbx_info;
1965 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1969 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
1970 if (dcbx_info->remote.params.app_entry[i].ethtype)
1971 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
1973 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
1974 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
1976 dcbx_info->remote.params.app_entry[i].proto_id;
1984 static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
1986 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1987 struct qed_dcbx_get *dcbx_info;
1990 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1994 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1995 if (dcbx_info->remote.params.pfc.prio[i])
1996 pfc->pfc_en |= BIT(i);
1998 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
1999 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
2000 pfc->pfc_en, pfc->tcs_supported);
2006 static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
2008 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2009 struct qed_dcbx_get *dcbx_info;
2012 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2016 pg->willing = dcbx_info->remote.params.ets_willing;
2017 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
2018 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
2019 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
2022 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
2028 static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
2029 struct ieee_pfc *pfc, bool remote)
2031 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2032 struct qed_dcbx_params *params;
2033 struct qed_dcbx_get *dcbx_info;
2036 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2040 if (!dcbx_info->operational.ieee) {
2041 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2047 memset(dcbx_info, 0, sizeof(*dcbx_info));
2048 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2049 QED_DCBX_REMOTE_MIB);
2055 params = &dcbx_info->remote.params;
2057 params = &dcbx_info->operational.params;
2060 pfc->pfc_cap = params->pfc.max_tc;
2062 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2063 if (params->pfc.prio[i])
2064 pfc->pfc_en |= BIT(i);
2071 static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2073 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2076 static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2078 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2079 struct qed_dcbx_get *dcbx_info;
2080 struct qed_dcbx_set dcbx_set;
2081 struct qed_ptt *ptt;
2084 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2088 if (!dcbx_info->operational.ieee) {
2089 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2096 memset(&dcbx_set, 0, sizeof(dcbx_set));
2097 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2101 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2102 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2103 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2105 dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
2107 ptt = qed_ptt_acquire(hwfn);
2111 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2113 qed_ptt_release(hwfn, ptt);
2118 static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2119 struct ieee_ets *ets, bool remote)
2121 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2122 struct qed_dcbx_get *dcbx_info;
2123 struct qed_dcbx_params *params;
2126 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2130 if (!dcbx_info->operational.ieee) {
2131 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2137 memset(dcbx_info, 0, sizeof(*dcbx_info));
2138 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2139 QED_DCBX_REMOTE_MIB);
2145 params = &dcbx_info->remote.params;
2147 params = &dcbx_info->operational.params;
2150 ets->ets_cap = params->max_ets_tc;
2151 ets->willing = params->ets_willing;
2152 ets->cbs = params->ets_cbs;
2153 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2154 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2155 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2161 static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2163 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2166 static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2168 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2169 struct qed_dcbx_get *dcbx_info;
2170 struct qed_dcbx_set dcbx_set;
2171 struct qed_ptt *ptt;
2174 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2178 if (!dcbx_info->operational.ieee) {
2179 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2186 memset(&dcbx_set, 0, sizeof(dcbx_set));
2187 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2191 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2192 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2193 dcbx_set.config.params.ets_willing = ets->willing;
2194 dcbx_set.config.params.ets_cbs = ets->cbs;
2195 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2196 sizeof(ets->tc_tx_bw));
2197 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2198 sizeof(ets->tc_tsa));
2199 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2200 sizeof(ets->prio_tc));
2202 ptt = qed_ptt_acquire(hwfn);
2206 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2208 qed_ptt_release(hwfn, ptt);
2214 qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2216 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2220 qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2222 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2225 static int qed_get_sf_ieee_value(u8 selector, u8 *sf_ieee)
2228 case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
2229 *sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
2231 case IEEE_8021QAZ_APP_SEL_STREAM:
2232 *sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
2234 case IEEE_8021QAZ_APP_SEL_DGRAM:
2235 *sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
2237 case IEEE_8021QAZ_APP_SEL_ANY:
2238 *sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
2247 static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
2249 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2250 struct qed_dcbx_get *dcbx_info;
2251 struct qed_app_entry *entry;
2256 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d\n",
2257 app->selector, app->protocol);
2259 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2260 DP_INFO(cdev, "Invalid selector field value %d\n",
2265 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2269 if (!dcbx_info->operational.ieee) {
2270 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2275 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2276 entry = &dcbx_info->operational.params.app_entry[i];
2277 if ((entry->sf_ieee == sf_ieee) &&
2278 (entry->proto_id == app->protocol)) {
2284 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2285 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2291 app->priority = ffs(prio) - 1;
2298 static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
2300 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2301 struct qed_dcbx_get *dcbx_info;
2302 struct qed_dcbx_set dcbx_set;
2303 struct qed_app_entry *entry;
2304 struct qed_ptt *ptt;
2308 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d pri = %d\n",
2309 app->selector, app->protocol, app->priority);
2310 if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) {
2311 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2315 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2316 DP_INFO(cdev, "Invalid selector field value %d\n",
2321 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2325 if (!dcbx_info->operational.ieee) {
2326 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2333 memset(&dcbx_set, 0, sizeof(dcbx_set));
2334 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2338 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2339 entry = &dcbx_set.config.params.app_entry[i];
2340 if ((entry->sf_ieee == sf_ieee) &&
2341 (entry->proto_id == app->protocol))
2343 /* First empty slot */
2344 if (!entry->proto_id) {
2345 dcbx_set.config.params.num_app_entries++;
2350 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2351 DP_ERR(cdev, "App table is full\n");
2355 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
2356 dcbx_set.config.params.app_entry[i].sf_ieee = sf_ieee;
2357 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2358 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2360 ptt = qed_ptt_acquire(hwfn);
2364 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2366 qed_ptt_release(hwfn, ptt);
2371 const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2372 .getstate = qed_dcbnl_getstate,
2373 .setstate = qed_dcbnl_setstate,
2374 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2375 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2376 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2377 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2378 .getpfccfg = qed_dcbnl_getpfccfg,
2379 .setpfccfg = qed_dcbnl_setpfccfg,
2380 .getcap = qed_dcbnl_getcap,
2381 .getnumtcs = qed_dcbnl_getnumtcs,
2382 .getpfcstate = qed_dcbnl_getpfcstate,
2383 .getdcbx = qed_dcbnl_getdcbx,
2384 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2385 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2386 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2387 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2388 .setall = qed_dcbnl_setall,
2389 .setnumtcs = qed_dcbnl_setnumtcs,
2390 .setpfcstate = qed_dcbnl_setpfcstate,
2391 .setapp = qed_dcbnl_setapp,
2392 .setdcbx = qed_dcbnl_setdcbx,
2393 .setfeatcfg = qed_dcbnl_setfeatcfg,
2394 .getfeatcfg = qed_dcbnl_getfeatcfg,
2395 .getapp = qed_dcbnl_getapp,
2396 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2397 .peer_getapptable = qed_dcbnl_peer_getapptable,
2398 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2399 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2400 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2401 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2402 .ieee_getets = qed_dcbnl_ieee_getets,
2403 .ieee_setets = qed_dcbnl_ieee_setets,
2404 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2405 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2406 .ieee_getapp = qed_dcbnl_ieee_getapp,
2407 .ieee_setapp = qed_dcbnl_ieee_setapp,