1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019, Intel Corporation. */
4 #include "ice_dcb_lib.h"
5 #include "ice_dcb_nl.h"
6 #include "ice_devlink.h"
9 * ice_dcb_get_ena_tc - return bitmap of enabled TCs
10 * @dcbcfg: DCB config to evaluate for enabled TCs
12 static u8 ice_dcb_get_ena_tc(struct ice_dcbx_cfg *dcbcfg)
14 u8 i, num_tc, ena_tc = 1;
16 num_tc = ice_dcb_get_num_tc(dcbcfg);
18 for (i = 0; i < num_tc; i++)
25 * ice_is_pfc_causing_hung_q
26 * @pf: pointer to PF structure
27 * @txqueue: Tx queue which is supposedly hung queue
29 * find if PFC is causing the hung queue, if yes return true else false
31 bool ice_is_pfc_causing_hung_q(struct ice_pf *pf, unsigned int txqueue)
33 u8 num_tcs = 0, i, tc, up_mapped_tc, up_in_tc = 0;
34 u64 ref_prio_xoff[ICE_MAX_UP];
38 vsi = ice_get_main_vsi(pf);
42 ice_for_each_traffic_class(i)
43 if (vsi->tc_cfg.ena_tc & BIT(i))
46 /* first find out the TC to which the hung queue belongs to */
47 for (tc = 0; tc < num_tcs - 1; tc++)
48 if (ice_find_q_in_range(vsi->tc_cfg.tc_info[tc].qoffset,
49 vsi->tc_cfg.tc_info[tc + 1].qoffset,
53 /* Build a bit map of all UPs associated to the suspect hung queue TC,
54 * so that we check for its counter increment.
56 up2tc = rd32(&pf->hw, PRTDCB_TUP2TC);
57 for (i = 0; i < ICE_MAX_UP; i++) {
58 up_mapped_tc = (up2tc >> (i * 3)) & 0x7;
59 if (up_mapped_tc == tc)
63 /* Now that we figured out that hung queue is PFC enabled, still the
64 * Tx timeout can be legitimate. So to make sure Tx timeout is
65 * absolutely caused by PFC storm, check if the counters are
68 for (i = 0; i < ICE_MAX_UP; i++)
69 if (up_in_tc & BIT(i))
70 ref_prio_xoff[i] = pf->stats.priority_xoff_rx[i];
72 ice_update_dcb_stats(pf);
74 for (i = 0; i < ICE_MAX_UP; i++)
75 if (up_in_tc & BIT(i))
76 if (pf->stats.priority_xoff_rx[i] > ref_prio_xoff[i])
83 * ice_dcb_get_mode - gets the DCB mode
84 * @port_info: pointer to port info structure
85 * @host: if set it's HOST if not it's MANAGED
87 static u8 ice_dcb_get_mode(struct ice_port_info *port_info, bool host)
92 mode = DCB_CAP_DCBX_HOST;
94 mode = DCB_CAP_DCBX_LLD_MANAGED;
96 if (port_info->qos_cfg.local_dcbx_cfg.dcbx_mode & ICE_DCBX_MODE_CEE)
97 return mode | DCB_CAP_DCBX_VER_CEE;
99 return mode | DCB_CAP_DCBX_VER_IEEE;
103 * ice_dcb_get_num_tc - Get the number of TCs from DCBX config
104 * @dcbcfg: config to retrieve number of TCs from
106 u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg *dcbcfg)
108 bool tc_unused = false;
113 /* Scan the ETS Config Priority Table to find traffic classes
114 * enabled and create a bitmask of enabled TCs
116 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++)
117 num_tc |= BIT(dcbcfg->etscfg.prio_table[i]);
119 /* Scan bitmask for contiguous TCs starting with TC0 */
120 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
121 if (num_tc & BIT(i)) {
125 pr_err("Non-contiguous TCs - Disabling DCB\n");
133 /* There is always at least 1 TC */
141 * ice_get_first_droptc - returns number of first droptc
142 * @vsi: used to find the first droptc
144 * This function returns the value of first_droptc.
145 * When DCB is enabled, first droptc information is derived from enabled_tc
146 * and PFC enabled bits. otherwise this function returns 0 as there is one
147 * TC without DCB (tc0)
149 static u8 ice_get_first_droptc(struct ice_vsi *vsi)
151 struct ice_dcbx_cfg *cfg = &vsi->port_info->qos_cfg.local_dcbx_cfg;
152 struct device *dev = ice_pf_to_dev(vsi->back);
153 u8 num_tc, ena_tc_map, pfc_ena_map;
156 num_tc = ice_dcb_get_num_tc(cfg);
158 /* get bitmap of enabled TCs */
159 ena_tc_map = ice_dcb_get_ena_tc(cfg);
161 /* get bitmap of PFC enabled TCs */
162 pfc_ena_map = cfg->pfc.pfcena;
164 /* get first TC that is not PFC enabled */
165 for (i = 0; i < num_tc; i++) {
166 if ((ena_tc_map & BIT(i)) && (!(pfc_ena_map & BIT(i)))) {
167 dev_dbg(dev, "first drop tc = %d\n", i);
172 dev_dbg(dev, "first drop tc = 0\n");
177 * ice_vsi_set_dcb_tc_cfg - Set VSI's TC based on DCB configuration
178 * @vsi: pointer to the VSI instance
180 void ice_vsi_set_dcb_tc_cfg(struct ice_vsi *vsi)
182 struct ice_dcbx_cfg *cfg = &vsi->port_info->qos_cfg.local_dcbx_cfg;
186 vsi->tc_cfg.ena_tc = ice_dcb_get_ena_tc(cfg);
187 vsi->tc_cfg.numtc = ice_dcb_get_num_tc(cfg);
190 vsi->tc_cfg.ena_tc = BIT(ice_get_first_droptc(vsi));
191 vsi->tc_cfg.numtc = 1;
196 vsi->tc_cfg.ena_tc = ICE_DFLT_TRAFFIC_CLASS;
197 vsi->tc_cfg.numtc = 1;
202 * ice_dcb_get_tc - Get the TC associated with the queue
203 * @vsi: ptr to the VSI
204 * @queue_index: queue number associated with VSI
206 u8 ice_dcb_get_tc(struct ice_vsi *vsi, int queue_index)
208 return vsi->tx_rings[queue_index]->dcb_tc;
212 * ice_vsi_cfg_dcb_rings - Update rings to reflect DCB TC
213 * @vsi: VSI owner of rings being updated
215 void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi)
217 struct ice_tx_ring *tx_ring;
218 struct ice_rx_ring *rx_ring;
222 if (!test_bit(ICE_FLAG_DCB_ENA, vsi->back->flags)) {
223 /* Reset the TC information */
224 ice_for_each_txq(vsi, i) {
225 tx_ring = vsi->tx_rings[i];
228 ice_for_each_rxq(vsi, i) {
229 rx_ring = vsi->rx_rings[i];
235 ice_for_each_traffic_class(n) {
236 if (!(vsi->tc_cfg.ena_tc & BIT(n)))
239 qoffset = vsi->tc_cfg.tc_info[n].qoffset;
240 qcount = vsi->tc_cfg.tc_info[n].qcount_tx;
241 for (i = qoffset; i < (qoffset + qcount); i++)
242 vsi->tx_rings[i]->dcb_tc = n;
244 qcount = vsi->tc_cfg.tc_info[n].qcount_rx;
245 for (i = qoffset; i < (qoffset + qcount); i++)
246 vsi->rx_rings[i]->dcb_tc = n;
248 /* applicable only if "all_enatc" is set, which will be set from
249 * setup_tc method as part of configuring channels
251 if (vsi->all_enatc) {
252 u8 first_droptc = ice_get_first_droptc(vsi);
254 /* When DCB is configured, TC for ADQ queues (which are really
255 * PF queues) should be the first drop TC of the main VSI
257 ice_for_each_chnl_tc(n) {
258 if (!(vsi->all_enatc & BIT(n)))
261 qoffset = vsi->mqprio_qopt.qopt.offset[n];
262 qcount = vsi->mqprio_qopt.qopt.count[n];
263 for (i = qoffset; i < (qoffset + qcount); i++) {
264 vsi->tx_rings[i]->dcb_tc = first_droptc;
265 vsi->rx_rings[i]->dcb_tc = first_droptc;
272 * ice_dcb_ena_dis_vsi - disable certain VSIs for DCB config/reconfig
273 * @pf: pointer to the PF instance
274 * @ena: true to enable VSIs, false to disable
275 * @locked: true if caller holds RTNL lock, false otherwise
277 * Before a new DCB configuration can be applied, VSIs of type PF, SWITCHDEV
278 * and CHNL need to be brought down. Following completion of DCB configuration
279 * the VSIs that were downed need to be brought up again. This helper function
282 static void ice_dcb_ena_dis_vsi(struct ice_pf *pf, bool ena, bool locked)
286 ice_for_each_vsi(pf, i) {
287 struct ice_vsi *vsi = pf->vsi[i];
294 case ICE_VSI_SWITCHDEV_CTRL:
297 ice_ena_vsi(vsi, locked);
299 ice_dis_vsi(vsi, locked);
308 * ice_dcb_bwchk - check if ETS bandwidth input parameters are correct
309 * @pf: pointer to the PF struct
310 * @dcbcfg: pointer to DCB config structure
312 int ice_dcb_bwchk(struct ice_pf *pf, struct ice_dcbx_cfg *dcbcfg)
314 struct ice_dcb_ets_cfg *etscfg = &dcbcfg->etscfg;
315 u8 num_tc, total_bw = 0;
318 /* returns number of contigous TCs and 1 TC for non-contigous TCs,
319 * since at least 1 TC has to be configured
321 num_tc = ice_dcb_get_num_tc(dcbcfg);
323 /* no bandwidth checks required if there's only one TC, so assign
324 * all bandwidth to TC0 and return
327 etscfg->tcbwtable[0] = ICE_TC_MAX_BW;
331 for (i = 0; i < num_tc; i++)
332 total_bw += etscfg->tcbwtable[i];
335 etscfg->tcbwtable[0] = ICE_TC_MAX_BW;
336 } else if (total_bw != ICE_TC_MAX_BW) {
337 dev_err(ice_pf_to_dev(pf), "Invalid config, total bandwidth must equal 100\n");
345 * ice_pf_dcb_cfg - Apply new DCB configuration
346 * @pf: pointer to the PF struct
347 * @new_cfg: DCBX config to apply
348 * @locked: is the RTNL held
350 int ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked)
352 struct ice_aqc_port_ets_elem buf = { 0 };
353 struct ice_dcbx_cfg *old_cfg, *curr_cfg;
354 struct device *dev = ice_pf_to_dev(pf);
355 int ret = ICE_DCB_NO_HW_CHG;
356 struct iidc_event *event;
357 struct ice_vsi *pf_vsi;
359 curr_cfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
361 /* FW does not care if change happened */
362 if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
363 ret = ICE_DCB_HW_CHG_RST;
365 /* Enable DCB tagging only when more than one TC */
366 if (ice_dcb_get_num_tc(new_cfg) > 1) {
367 dev_dbg(dev, "DCB tagging enabled (num TC > 1)\n");
368 if (pf->hw.port_info->is_custom_tx_enabled) {
369 dev_err(dev, "Custom Tx scheduler feature enabled, can't configure DCB\n");
372 ice_tear_down_devlink_rate_tree(pf);
374 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
376 dev_dbg(dev, "DCB tagging disabled (num TC = 1)\n");
377 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
380 if (!memcmp(new_cfg, curr_cfg, sizeof(*new_cfg))) {
381 dev_dbg(dev, "No change in DCB config required\n");
385 if (ice_dcb_bwchk(pf, new_cfg))
388 /* Store old config in case FW config fails */
389 old_cfg = kmemdup(curr_cfg, sizeof(*old_cfg), GFP_KERNEL);
393 dev_info(dev, "Commit DCB Configuration to the hardware\n");
394 pf_vsi = ice_get_main_vsi(pf);
396 dev_dbg(dev, "PF VSI doesn't exist\n");
401 /* Notify AUX drivers about impending change to TCs */
402 event = kzalloc(sizeof(*event), GFP_KERNEL);
408 set_bit(IIDC_EVENT_BEFORE_TC_CHANGE, event->type);
409 ice_send_event_to_aux(pf, event);
412 /* avoid race conditions by holding the lock while disabling and
413 * re-enabling the VSI
418 /* disable VSIs affected by DCB changes */
419 ice_dcb_ena_dis_vsi(pf, false, true);
421 memcpy(curr_cfg, new_cfg, sizeof(*curr_cfg));
422 memcpy(&curr_cfg->etsrec, &curr_cfg->etscfg, sizeof(curr_cfg->etsrec));
423 memcpy(&new_cfg->etsrec, &curr_cfg->etscfg, sizeof(curr_cfg->etsrec));
425 /* Only send new config to HW if we are in SW LLDP mode. Otherwise,
426 * the new config came from the HW in the first place.
428 if (pf->hw.port_info->qos_cfg.is_sw_lldp) {
429 ret = ice_set_dcb_cfg(pf->hw.port_info);
431 dev_err(dev, "Set DCB Config failed\n");
432 /* Restore previous settings to local config */
433 memcpy(curr_cfg, old_cfg, sizeof(*curr_cfg));
438 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
440 dev_err(dev, "Query Port ETS failed\n");
444 ice_pf_dcb_recfg(pf, false);
447 /* enable previously downed VSIs */
448 ice_dcb_ena_dis_vsi(pf, true, true);
457 * ice_cfg_etsrec_defaults - Set default ETS recommended DCB config
458 * @pi: port information structure
460 static void ice_cfg_etsrec_defaults(struct ice_port_info *pi)
462 struct ice_dcbx_cfg *dcbcfg = &pi->qos_cfg.local_dcbx_cfg;
465 /* Ensure ETS recommended DCB configuration is not already set */
466 if (dcbcfg->etsrec.maxtcs)
469 /* In CEE mode, set the default to 1 TC */
470 dcbcfg->etsrec.maxtcs = 1;
471 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
472 dcbcfg->etsrec.tcbwtable[i] = i ? 0 : 100;
473 dcbcfg->etsrec.tsatable[i] = i ? ICE_IEEE_TSA_STRICT :
479 * ice_dcb_need_recfg - Check if DCB needs reconfig
480 * @pf: board private structure
481 * @old_cfg: current DCB config
482 * @new_cfg: new DCB config
485 ice_dcb_need_recfg(struct ice_pf *pf, struct ice_dcbx_cfg *old_cfg,
486 struct ice_dcbx_cfg *new_cfg)
488 struct device *dev = ice_pf_to_dev(pf);
489 bool need_reconfig = false;
491 /* Check if ETS configuration has changed */
492 if (memcmp(&new_cfg->etscfg, &old_cfg->etscfg,
493 sizeof(new_cfg->etscfg))) {
494 /* If Priority Table has changed reconfig is needed */
495 if (memcmp(&new_cfg->etscfg.prio_table,
496 &old_cfg->etscfg.prio_table,
497 sizeof(new_cfg->etscfg.prio_table))) {
498 need_reconfig = true;
499 dev_dbg(dev, "ETS UP2TC changed.\n");
502 if (memcmp(&new_cfg->etscfg.tcbwtable,
503 &old_cfg->etscfg.tcbwtable,
504 sizeof(new_cfg->etscfg.tcbwtable)))
505 dev_dbg(dev, "ETS TC BW Table changed.\n");
507 if (memcmp(&new_cfg->etscfg.tsatable,
508 &old_cfg->etscfg.tsatable,
509 sizeof(new_cfg->etscfg.tsatable)))
510 dev_dbg(dev, "ETS TSA Table changed.\n");
513 /* Check if PFC configuration has changed */
514 if (memcmp(&new_cfg->pfc, &old_cfg->pfc, sizeof(new_cfg->pfc))) {
515 need_reconfig = true;
516 dev_dbg(dev, "PFC config change detected.\n");
519 /* Check if APP Table has changed */
520 if (memcmp(&new_cfg->app, &old_cfg->app, sizeof(new_cfg->app))) {
521 need_reconfig = true;
522 dev_dbg(dev, "APP Table change detected.\n");
525 dev_dbg(dev, "dcb need_reconfig=%d\n", need_reconfig);
526 return need_reconfig;
530 * ice_dcb_rebuild - rebuild DCB post reset
531 * @pf: physical function instance
533 void ice_dcb_rebuild(struct ice_pf *pf)
535 struct ice_aqc_port_ets_elem buf = { 0 };
536 struct device *dev = ice_pf_to_dev(pf);
537 struct ice_dcbx_cfg *err_cfg;
540 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
542 dev_err(dev, "Query Port ETS failed\n");
546 mutex_lock(&pf->tc_mutex);
548 if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
549 ice_cfg_etsrec_defaults(pf->hw.port_info);
551 ret = ice_set_dcb_cfg(pf->hw.port_info);
553 dev_err(dev, "Failed to set DCB config in rebuild\n");
557 if (!pf->hw.port_info->qos_cfg.is_sw_lldp) {
558 ret = ice_cfg_lldp_mib_change(&pf->hw, true);
559 if (ret && !pf->hw.port_info->qos_cfg.is_sw_lldp) {
560 dev_err(dev, "Failed to register for MIB changes\n");
565 dev_info(dev, "DCB info restored\n");
566 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
568 dev_err(dev, "Query Port ETS failed\n");
572 mutex_unlock(&pf->tc_mutex);
577 dev_err(dev, "Disabling DCB until new settings occur\n");
578 err_cfg = kzalloc(sizeof(*err_cfg), GFP_KERNEL);
580 mutex_unlock(&pf->tc_mutex);
584 err_cfg->etscfg.willing = true;
585 err_cfg->etscfg.tcbwtable[0] = ICE_TC_MAX_BW;
586 err_cfg->etscfg.tsatable[0] = ICE_IEEE_TSA_ETS;
587 memcpy(&err_cfg->etsrec, &err_cfg->etscfg, sizeof(err_cfg->etsrec));
588 /* Coverity warns the return code of ice_pf_dcb_cfg() is not checked
589 * here as is done for other calls to that function. That check is
590 * not necessary since this is in this function's error cleanup path.
591 * Suppress the Coverity warning with the following comment...
593 /* coverity[check_return] */
594 ice_pf_dcb_cfg(pf, err_cfg, false);
597 mutex_unlock(&pf->tc_mutex);
601 * ice_dcb_init_cfg - set the initial DCB config in SW
602 * @pf: PF to apply config to
603 * @locked: Is the RTNL held
605 static int ice_dcb_init_cfg(struct ice_pf *pf, bool locked)
607 struct ice_dcbx_cfg *newcfg;
608 struct ice_port_info *pi;
611 pi = pf->hw.port_info;
612 newcfg = kmemdup(&pi->qos_cfg.local_dcbx_cfg, sizeof(*newcfg),
617 memset(&pi->qos_cfg.local_dcbx_cfg, 0, sizeof(*newcfg));
619 dev_info(ice_pf_to_dev(pf), "Configuring initial DCB values\n");
620 if (ice_pf_dcb_cfg(pf, newcfg, locked))
629 * ice_dcb_sw_dflt_cfg - Apply a default DCB config
630 * @pf: PF to apply config to
631 * @ets_willing: configure ETS willing
632 * @locked: was this function called with RTNL held
634 int ice_dcb_sw_dflt_cfg(struct ice_pf *pf, bool ets_willing, bool locked)
636 struct ice_aqc_port_ets_elem buf = { 0 };
637 struct ice_dcbx_cfg *dcbcfg;
638 struct ice_port_info *pi;
644 dcbcfg = kzalloc(sizeof(*dcbcfg), GFP_KERNEL);
648 memset(&pi->qos_cfg.local_dcbx_cfg, 0, sizeof(*dcbcfg));
650 dcbcfg->etscfg.willing = ets_willing ? 1 : 0;
651 dcbcfg->etscfg.maxtcs = hw->func_caps.common_cap.maxtc;
652 dcbcfg->etscfg.tcbwtable[0] = 100;
653 dcbcfg->etscfg.tsatable[0] = ICE_IEEE_TSA_ETS;
655 memcpy(&dcbcfg->etsrec, &dcbcfg->etscfg,
656 sizeof(dcbcfg->etsrec));
657 dcbcfg->etsrec.willing = 0;
659 dcbcfg->pfc.willing = 1;
660 dcbcfg->pfc.pfccap = hw->func_caps.common_cap.maxtc;
663 dcbcfg->app[0].selector = ICE_APP_SEL_ETHTYPE;
664 dcbcfg->app[0].priority = 3;
665 dcbcfg->app[0].prot_id = ETH_P_FCOE;
667 ret = ice_pf_dcb_cfg(pf, dcbcfg, locked);
672 return ice_query_port_ets(pi, &buf, sizeof(buf), NULL);
676 * ice_dcb_tc_contig - Check that TCs are contiguous
677 * @prio_table: pointer to priority table
679 * Check if TCs begin with TC0 and are contiguous
681 static bool ice_dcb_tc_contig(u8 *prio_table)
683 bool found_empty = false;
687 /* Create a bitmap of used TCs */
688 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++)
689 used_tc |= BIT(prio_table[i]);
691 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++) {
692 if (used_tc & BIT(i)) {
704 * ice_dcb_noncontig_cfg - Configure DCB for non-contiguous TCs
705 * @pf: pointer to the PF struct
707 * If non-contiguous TCs, then configure SW DCB with TC0 and ETS non-willing
709 static int ice_dcb_noncontig_cfg(struct ice_pf *pf)
711 struct ice_dcbx_cfg *dcbcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
712 struct device *dev = ice_pf_to_dev(pf);
715 /* Configure SW DCB default with ETS non-willing */
716 ret = ice_dcb_sw_dflt_cfg(pf, false, true);
718 dev_err(dev, "Failed to set local DCB config %d\n", ret);
722 /* Reconfigure with ETS willing so that FW will send LLDP MIB event */
723 dcbcfg->etscfg.willing = 1;
724 ret = ice_set_dcb_cfg(pf->hw.port_info);
726 dev_err(dev, "Failed to set DCB to unwilling\n");
732 * ice_pf_dcb_recfg - Reconfigure all VEBs and VSIs
733 * @pf: pointer to the PF struct
734 * @locked: is adev device lock held
736 * Assumed caller has already disabled all VSIs before
737 * calling this function. Reconfiguring DCB based on
740 void ice_pf_dcb_recfg(struct ice_pf *pf, bool locked)
742 struct ice_dcbx_cfg *dcbcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
743 struct iidc_event *event;
747 /* Update each VSI */
748 ice_for_each_vsi(pf, v) {
749 struct ice_vsi *vsi = pf->vsi[v];
754 if (vsi->type == ICE_VSI_PF) {
755 tc_map = ice_dcb_get_ena_tc(dcbcfg);
757 /* If DCBX request non-contiguous TC, then configure
760 if (!ice_dcb_tc_contig(dcbcfg->etscfg.prio_table)) {
761 tc_map = ICE_DFLT_TRAFFIC_CLASS;
762 ice_dcb_noncontig_cfg(pf);
764 } else if (vsi->type == ICE_VSI_CHNL) {
765 tc_map = BIT(ice_get_first_droptc(vsi));
767 tc_map = ICE_DFLT_TRAFFIC_CLASS;
770 ret = ice_vsi_cfg_tc(vsi, tc_map);
772 dev_err(ice_pf_to_dev(pf), "Failed to config TC for VSI index: %d\n",
776 /* no need to proceed with remaining cfg if it is CHNL
779 if (vsi->type == ICE_VSI_CHNL ||
780 vsi->type == ICE_VSI_SWITCHDEV_CTRL)
783 ice_vsi_map_rings_to_vectors(vsi);
784 if (vsi->type == ICE_VSI_PF)
785 ice_dcbnl_set_all(vsi);
788 /* Notify the AUX drivers that TC change is finished */
789 event = kzalloc(sizeof(*event), GFP_KERNEL);
793 set_bit(IIDC_EVENT_AFTER_TC_CHANGE, event->type);
794 ice_send_event_to_aux(pf, event);
800 * ice_init_pf_dcb - initialize DCB for a PF
801 * @pf: PF to initialize DCB for
802 * @locked: Was function called with RTNL held
804 int ice_init_pf_dcb(struct ice_pf *pf, bool locked)
806 struct device *dev = ice_pf_to_dev(pf);
807 struct ice_port_info *port_info;
808 struct ice_hw *hw = &pf->hw;
811 port_info = hw->port_info;
813 err = ice_init_dcb(hw, false);
814 if (err && !port_info->qos_cfg.is_sw_lldp) {
815 dev_err(dev, "Error initializing DCB %d\n", err);
819 dev_info(dev, "DCB is enabled in the hardware, max number of TCs supported on this port are %d\n",
820 pf->hw.func_caps.common_cap.maxtc);
822 struct ice_vsi *pf_vsi;
824 /* FW LLDP is disabled, activate SW DCBX/LLDP mode */
825 dev_info(dev, "FW LLDP is disabled, DCBx/LLDP in SW mode.\n");
826 clear_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
827 err = ice_aq_set_pfc_mode(&pf->hw, ICE_AQC_PFC_VLAN_BASED_PFC,
830 dev_info(dev, "Failed to set VLAN PFC mode\n");
832 err = ice_dcb_sw_dflt_cfg(pf, true, locked);
834 dev_err(dev, "Failed to set local DCB config %d\n",
840 /* If the FW DCBX engine is not running then Rx LLDP packets
841 * need to be redirected up the stack.
843 pf_vsi = ice_get_main_vsi(pf);
845 dev_err(dev, "Failed to set local DCB config\n");
850 ice_cfg_sw_lldp(pf_vsi, false, true);
852 pf->dcbx_cap = ice_dcb_get_mode(port_info, true);
856 set_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
858 /* DCBX/LLDP enabled in FW, set DCBNL mode advertisement */
859 pf->dcbx_cap = ice_dcb_get_mode(port_info, false);
861 err = ice_dcb_init_cfg(pf, locked);
868 dev_err(dev, "DCB init failed\n");
873 * ice_update_dcb_stats - Update DCB stats counters
874 * @pf: PF whose stats needs to be updated
876 void ice_update_dcb_stats(struct ice_pf *pf)
878 struct ice_hw_port_stats *prev_ps, *cur_ps;
879 struct ice_hw *hw = &pf->hw;
883 port = hw->port_info->lport;
884 prev_ps = &pf->stats_prev;
887 if (ice_is_reset_in_progress(pf->state))
888 pf->stat_prev_loaded = false;
890 for (i = 0; i < 8; i++) {
891 ice_stat_update32(hw, GLPRT_PXOFFRXC(port, i),
892 pf->stat_prev_loaded,
893 &prev_ps->priority_xoff_rx[i],
894 &cur_ps->priority_xoff_rx[i]);
895 ice_stat_update32(hw, GLPRT_PXONRXC(port, i),
896 pf->stat_prev_loaded,
897 &prev_ps->priority_xon_rx[i],
898 &cur_ps->priority_xon_rx[i]);
899 ice_stat_update32(hw, GLPRT_PXONTXC(port, i),
900 pf->stat_prev_loaded,
901 &prev_ps->priority_xon_tx[i],
902 &cur_ps->priority_xon_tx[i]);
903 ice_stat_update32(hw, GLPRT_PXOFFTXC(port, i),
904 pf->stat_prev_loaded,
905 &prev_ps->priority_xoff_tx[i],
906 &cur_ps->priority_xoff_tx[i]);
907 ice_stat_update32(hw, GLPRT_RXON2OFFCNT(port, i),
908 pf->stat_prev_loaded,
909 &prev_ps->priority_xon_2_xoff[i],
910 &cur_ps->priority_xon_2_xoff[i]);
915 * ice_tx_prepare_vlan_flags_dcb - prepare VLAN tagging for DCB
916 * @tx_ring: ring to send buffer on
917 * @first: pointer to struct ice_tx_buf
919 * This should not be called if the outer VLAN is software offloaded as the VLAN
920 * tag will already be configured with the correct ID and priority bits
923 ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring *tx_ring,
924 struct ice_tx_buf *first)
926 struct sk_buff *skb = first->skb;
928 if (!test_bit(ICE_FLAG_DCB_ENA, tx_ring->vsi->back->flags))
931 /* Insert 802.1p priority into VLAN header */
932 if ((first->tx_flags & ICE_TX_FLAGS_HW_VLAN ||
933 first->tx_flags & ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN) ||
934 skb->priority != TC_PRIO_CONTROL) {
935 first->vid &= ~VLAN_PRIO_MASK;
936 /* Mask the lower 3 bits to set the 802.1p priority */
937 first->vid |= FIELD_PREP(VLAN_PRIO_MASK, skb->priority);
938 /* if this is not already set it means a VLAN 0 + priority needs
941 if (tx_ring->flags & ICE_TX_FLAGS_RING_VLAN_L2TAG2)
942 first->tx_flags |= ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN;
944 first->tx_flags |= ICE_TX_FLAGS_HW_VLAN;
949 * ice_dcb_is_mib_change_pending - Check if MIB change is pending
950 * @state: MIB change state
952 static bool ice_dcb_is_mib_change_pending(u8 state)
954 return ICE_AQ_LLDP_MIB_CHANGE_PENDING ==
955 FIELD_GET(ICE_AQ_LLDP_MIB_CHANGE_STATE_M, state);
959 * ice_dcb_process_lldp_set_mib_change - Process MIB change
961 * @event: pointer to the admin queue receive event
964 ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf,
965 struct ice_rq_event_info *event)
967 struct ice_aqc_port_ets_elem buf = { 0 };
968 struct device *dev = ice_pf_to_dev(pf);
969 struct ice_aqc_lldp_get_mib *mib;
970 struct ice_dcbx_cfg tmp_dcbx_cfg;
971 bool pending_handled = true;
972 bool need_reconfig = false;
973 struct ice_port_info *pi;
977 /* Not DCB capable or capability disabled */
978 if (!(test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags)))
981 if (pf->dcbx_cap & DCB_CAP_DCBX_HOST) {
982 dev_dbg(dev, "MIB Change Event in HOST mode\n");
986 pi = pf->hw.port_info;
987 mib = (struct ice_aqc_lldp_get_mib *)&event->desc.params.raw;
989 /* Ignore if event is not for Nearest Bridge */
990 mib_type = FIELD_GET(ICE_AQ_LLDP_BRID_TYPE_M, mib->type);
991 dev_dbg(dev, "LLDP event MIB bridge type 0x%x\n", mib_type);
992 if (mib_type != ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID)
995 /* A pending change event contains accurate config information, and
996 * the FW setting has not been updaed yet, so detect if change is
997 * pending to determine where to pull config information from
1000 if (ice_dcb_is_mib_change_pending(mib->state))
1001 pending_handled = false;
1003 /* Check MIB Type and return if event for Remote MIB update */
1004 mib_type = FIELD_GET(ICE_AQ_LLDP_MIB_TYPE_M, mib->type);
1005 dev_dbg(dev, "LLDP event mib type %s\n", mib_type ? "remote" : "local");
1006 if (mib_type == ICE_AQ_LLDP_MIB_REMOTE) {
1007 /* Update the remote cached instance and return */
1008 if (!pending_handled) {
1009 ice_get_dcb_cfg_from_mib_change(pi, event);
1012 ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_REMOTE,
1013 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID,
1014 &pi->qos_cfg.remote_dcbx_cfg);
1016 dev_dbg(dev, "Failed to get remote DCB config\n");
1021 /* That a DCB change has happened is now determined */
1022 mutex_lock(&pf->tc_mutex);
1024 /* store the old configuration */
1025 tmp_dcbx_cfg = pi->qos_cfg.local_dcbx_cfg;
1027 /* Reset the old DCBX configuration data */
1028 memset(&pi->qos_cfg.local_dcbx_cfg, 0,
1029 sizeof(pi->qos_cfg.local_dcbx_cfg));
1031 /* Get updated DCBX data from firmware */
1032 if (!pending_handled) {
1033 ice_get_dcb_cfg_from_mib_change(pi, event);
1035 ret = ice_get_dcb_cfg(pi);
1037 dev_err(dev, "Failed to get DCB config\n");
1042 /* No change detected in DCBX configs */
1043 if (!memcmp(&tmp_dcbx_cfg, &pi->qos_cfg.local_dcbx_cfg,
1044 sizeof(tmp_dcbx_cfg))) {
1045 dev_dbg(dev, "No change detected in DCBX configuration.\n");
1049 pf->dcbx_cap = ice_dcb_get_mode(pi, false);
1051 need_reconfig = ice_dcb_need_recfg(pf, &tmp_dcbx_cfg,
1052 &pi->qos_cfg.local_dcbx_cfg);
1053 ice_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &pi->qos_cfg.local_dcbx_cfg);
1057 /* Enable DCB tagging only when more than one TC */
1058 if (ice_dcb_get_num_tc(&pi->qos_cfg.local_dcbx_cfg) > 1) {
1059 dev_dbg(dev, "DCB tagging enabled (num TC > 1)\n");
1060 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
1062 dev_dbg(dev, "DCB tagging disabled (num TC = 1)\n");
1063 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
1066 /* Send Execute Pending MIB Change event if it is a Pending event */
1067 if (!pending_handled) {
1068 ice_lldp_execute_pending_mib(&pf->hw);
1069 pending_handled = true;
1073 /* disable VSIs affected by DCB changes */
1074 ice_dcb_ena_dis_vsi(pf, false, true);
1076 ret = ice_query_port_ets(pi, &buf, sizeof(buf), NULL);
1078 dev_err(dev, "Query Port ETS failed\n");
1082 /* changes in configuration update VSI */
1083 ice_pf_dcb_recfg(pf, false);
1085 /* enable previously downed VSIs */
1086 ice_dcb_ena_dis_vsi(pf, true, true);
1090 mutex_unlock(&pf->tc_mutex);
1092 /* Send Execute Pending MIB Change event if it is a Pending event */
1093 if (!pending_handled)
1094 ice_lldp_execute_pending_mib(&pf->hw);