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"
8 * ice_dcb_get_ena_tc - return bitmap of enabled TCs
9 * @dcbcfg: DCB config to evaluate for enabled TCs
11 static u8 ice_dcb_get_ena_tc(struct ice_dcbx_cfg *dcbcfg)
13 u8 i, num_tc, ena_tc = 1;
15 num_tc = ice_dcb_get_num_tc(dcbcfg);
17 for (i = 0; i < num_tc; i++)
24 * ice_is_pfc_causing_hung_q
25 * @pf: pointer to PF structure
26 * @txqueue: Tx queue which is supposedly hung queue
28 * find if PFC is causing the hung queue, if yes return true else false
30 bool ice_is_pfc_causing_hung_q(struct ice_pf *pf, unsigned int txqueue)
32 u8 num_tcs = 0, i, tc, up_mapped_tc, up_in_tc = 0;
33 u64 ref_prio_xoff[ICE_MAX_UP];
37 vsi = ice_get_main_vsi(pf);
41 ice_for_each_traffic_class(i)
42 if (vsi->tc_cfg.ena_tc & BIT(i))
45 /* first find out the TC to which the hung queue belongs to */
46 for (tc = 0; tc < num_tcs - 1; tc++)
47 if (ice_find_q_in_range(vsi->tc_cfg.tc_info[tc].qoffset,
48 vsi->tc_cfg.tc_info[tc + 1].qoffset,
52 /* Build a bit map of all UPs associated to the suspect hung queue TC,
53 * so that we check for its counter increment.
55 up2tc = rd32(&pf->hw, PRTDCB_TUP2TC);
56 for (i = 0; i < ICE_MAX_UP; i++) {
57 up_mapped_tc = (up2tc >> (i * 3)) & 0x7;
58 if (up_mapped_tc == tc)
62 /* Now that we figured out that hung queue is PFC enabled, still the
63 * Tx timeout can be legitimate. So to make sure Tx timeout is
64 * absolutely caused by PFC storm, check if the counters are
67 for (i = 0; i < ICE_MAX_UP; i++)
68 if (up_in_tc & BIT(i))
69 ref_prio_xoff[i] = pf->stats.priority_xoff_rx[i];
71 ice_update_dcb_stats(pf);
73 for (i = 0; i < ICE_MAX_UP; i++)
74 if (up_in_tc & BIT(i))
75 if (pf->stats.priority_xoff_rx[i] > ref_prio_xoff[i])
82 * ice_dcb_get_mode - gets the DCB mode
83 * @port_info: pointer to port info structure
84 * @host: if set it's HOST if not it's MANAGED
86 static u8 ice_dcb_get_mode(struct ice_port_info *port_info, bool host)
91 mode = DCB_CAP_DCBX_HOST;
93 mode = DCB_CAP_DCBX_LLD_MANAGED;
95 if (port_info->qos_cfg.local_dcbx_cfg.dcbx_mode & ICE_DCBX_MODE_CEE)
96 return mode | DCB_CAP_DCBX_VER_CEE;
98 return mode | DCB_CAP_DCBX_VER_IEEE;
102 * ice_dcb_get_num_tc - Get the number of TCs from DCBX config
103 * @dcbcfg: config to retrieve number of TCs from
105 u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg *dcbcfg)
107 bool tc_unused = false;
112 /* Scan the ETS Config Priority Table to find traffic classes
113 * enabled and create a bitmask of enabled TCs
115 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++)
116 num_tc |= BIT(dcbcfg->etscfg.prio_table[i]);
118 /* Scan bitmask for contiguous TCs starting with TC0 */
119 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
120 if (num_tc & BIT(i)) {
124 pr_err("Non-contiguous TCs - Disabling DCB\n");
132 /* There is always at least 1 TC */
140 * ice_get_first_droptc - returns number of first droptc
141 * @vsi: used to find the first droptc
143 * This function returns the value of first_droptc.
144 * When DCB is enabled, first droptc information is derived from enabled_tc
145 * and PFC enabled bits. otherwise this function returns 0 as there is one
146 * TC without DCB (tc0)
148 static u8 ice_get_first_droptc(struct ice_vsi *vsi)
150 struct ice_dcbx_cfg *cfg = &vsi->port_info->qos_cfg.local_dcbx_cfg;
151 struct device *dev = ice_pf_to_dev(vsi->back);
152 u8 num_tc, ena_tc_map, pfc_ena_map;
155 num_tc = ice_dcb_get_num_tc(cfg);
157 /* get bitmap of enabled TCs */
158 ena_tc_map = ice_dcb_get_ena_tc(cfg);
160 /* get bitmap of PFC enabled TCs */
161 pfc_ena_map = cfg->pfc.pfcena;
163 /* get first TC that is not PFC enabled */
164 for (i = 0; i < num_tc; i++) {
165 if ((ena_tc_map & BIT(i)) && (!(pfc_ena_map & BIT(i)))) {
166 dev_dbg(dev, "first drop tc = %d\n", i);
171 dev_dbg(dev, "first drop tc = 0\n");
176 * ice_vsi_set_dcb_tc_cfg - Set VSI's TC based on DCB configuration
177 * @vsi: pointer to the VSI instance
179 void ice_vsi_set_dcb_tc_cfg(struct ice_vsi *vsi)
181 struct ice_dcbx_cfg *cfg = &vsi->port_info->qos_cfg.local_dcbx_cfg;
185 vsi->tc_cfg.ena_tc = ice_dcb_get_ena_tc(cfg);
186 vsi->tc_cfg.numtc = ice_dcb_get_num_tc(cfg);
189 vsi->tc_cfg.ena_tc = BIT(ice_get_first_droptc(vsi));
190 vsi->tc_cfg.numtc = 1;
195 vsi->tc_cfg.ena_tc = ICE_DFLT_TRAFFIC_CLASS;
196 vsi->tc_cfg.numtc = 1;
201 * ice_dcb_get_tc - Get the TC associated with the queue
202 * @vsi: ptr to the VSI
203 * @queue_index: queue number associated with VSI
205 u8 ice_dcb_get_tc(struct ice_vsi *vsi, int queue_index)
207 return vsi->tx_rings[queue_index]->dcb_tc;
211 * ice_vsi_cfg_dcb_rings - Update rings to reflect DCB TC
212 * @vsi: VSI owner of rings being updated
214 void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi)
216 struct ice_tx_ring *tx_ring;
217 struct ice_rx_ring *rx_ring;
221 if (!test_bit(ICE_FLAG_DCB_ENA, vsi->back->flags)) {
222 /* Reset the TC information */
223 ice_for_each_txq(vsi, i) {
224 tx_ring = vsi->tx_rings[i];
227 ice_for_each_rxq(vsi, i) {
228 rx_ring = vsi->rx_rings[i];
234 ice_for_each_traffic_class(n) {
235 if (!(vsi->tc_cfg.ena_tc & BIT(n)))
238 qoffset = vsi->tc_cfg.tc_info[n].qoffset;
239 qcount = vsi->tc_cfg.tc_info[n].qcount_tx;
240 for (i = qoffset; i < (qoffset + qcount); i++)
241 vsi->tx_rings[i]->dcb_tc = n;
243 qcount = vsi->tc_cfg.tc_info[n].qcount_rx;
244 for (i = qoffset; i < (qoffset + qcount); i++)
245 vsi->rx_rings[i]->dcb_tc = n;
247 /* applicable only if "all_enatc" is set, which will be set from
248 * setup_tc method as part of configuring channels
250 if (vsi->all_enatc) {
251 u8 first_droptc = ice_get_first_droptc(vsi);
253 /* When DCB is configured, TC for ADQ queues (which are really
254 * PF queues) should be the first drop TC of the main VSI
256 ice_for_each_chnl_tc(n) {
257 if (!(vsi->all_enatc & BIT(n)))
260 qoffset = vsi->mqprio_qopt.qopt.offset[n];
261 qcount = vsi->mqprio_qopt.qopt.count[n];
262 for (i = qoffset; i < (qoffset + qcount); i++) {
263 vsi->tx_rings[i]->dcb_tc = first_droptc;
264 vsi->rx_rings[i]->dcb_tc = first_droptc;
271 * ice_dcb_ena_dis_vsi - disable certain VSIs for DCB config/reconfig
272 * @pf: pointer to the PF instance
273 * @ena: true to enable VSIs, false to disable
274 * @locked: true if caller holds RTNL lock, false otherwise
276 * Before a new DCB configuration can be applied, VSIs of type PF, SWITCHDEV
277 * and CHNL need to be brought down. Following completion of DCB configuration
278 * the VSIs that were downed need to be brought up again. This helper function
281 static void ice_dcb_ena_dis_vsi(struct ice_pf *pf, bool ena, bool locked)
285 ice_for_each_vsi(pf, i) {
286 struct ice_vsi *vsi = pf->vsi[i];
293 case ICE_VSI_SWITCHDEV_CTRL:
296 ice_ena_vsi(vsi, locked);
298 ice_dis_vsi(vsi, locked);
307 * ice_dcb_bwchk - check if ETS bandwidth input parameters are correct
308 * @pf: pointer to the PF struct
309 * @dcbcfg: pointer to DCB config structure
311 int ice_dcb_bwchk(struct ice_pf *pf, struct ice_dcbx_cfg *dcbcfg)
313 struct ice_dcb_ets_cfg *etscfg = &dcbcfg->etscfg;
314 u8 num_tc, total_bw = 0;
317 /* returns number of contigous TCs and 1 TC for non-contigous TCs,
318 * since at least 1 TC has to be configured
320 num_tc = ice_dcb_get_num_tc(dcbcfg);
322 /* no bandwidth checks required if there's only one TC, so assign
323 * all bandwidth to TC0 and return
326 etscfg->tcbwtable[0] = ICE_TC_MAX_BW;
330 for (i = 0; i < num_tc; i++)
331 total_bw += etscfg->tcbwtable[i];
334 etscfg->tcbwtable[0] = ICE_TC_MAX_BW;
335 } else if (total_bw != ICE_TC_MAX_BW) {
336 dev_err(ice_pf_to_dev(pf), "Invalid config, total bandwidth must equal 100\n");
344 * ice_pf_dcb_cfg - Apply new DCB configuration
345 * @pf: pointer to the PF struct
346 * @new_cfg: DCBX config to apply
347 * @locked: is the RTNL held
349 int ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked)
351 struct ice_aqc_port_ets_elem buf = { 0 };
352 struct ice_dcbx_cfg *old_cfg, *curr_cfg;
353 struct device *dev = ice_pf_to_dev(pf);
354 int ret = ICE_DCB_NO_HW_CHG;
355 struct iidc_event *event;
356 struct ice_vsi *pf_vsi;
358 curr_cfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
360 /* FW does not care if change happened */
361 if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
362 ret = ICE_DCB_HW_CHG_RST;
364 /* Enable DCB tagging only when more than one TC */
365 if (ice_dcb_get_num_tc(new_cfg) > 1) {
366 dev_dbg(dev, "DCB tagging enabled (num TC > 1)\n");
367 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
369 dev_dbg(dev, "DCB tagging disabled (num TC = 1)\n");
370 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
373 if (!memcmp(new_cfg, curr_cfg, sizeof(*new_cfg))) {
374 dev_dbg(dev, "No change in DCB config required\n");
378 if (ice_dcb_bwchk(pf, new_cfg))
381 /* Store old config in case FW config fails */
382 old_cfg = kmemdup(curr_cfg, sizeof(*old_cfg), GFP_KERNEL);
386 dev_info(dev, "Commit DCB Configuration to the hardware\n");
387 pf_vsi = ice_get_main_vsi(pf);
389 dev_dbg(dev, "PF VSI doesn't exist\n");
394 /* Notify AUX drivers about impending change to TCs */
395 event = kzalloc(sizeof(*event), GFP_KERNEL);
401 set_bit(IIDC_EVENT_BEFORE_TC_CHANGE, event->type);
402 ice_send_event_to_aux(pf, event);
405 /* avoid race conditions by holding the lock while disabling and
406 * re-enabling the VSI
411 /* disable VSIs affected by DCB changes */
412 ice_dcb_ena_dis_vsi(pf, false, true);
414 memcpy(curr_cfg, new_cfg, sizeof(*curr_cfg));
415 memcpy(&curr_cfg->etsrec, &curr_cfg->etscfg, sizeof(curr_cfg->etsrec));
416 memcpy(&new_cfg->etsrec, &curr_cfg->etscfg, sizeof(curr_cfg->etsrec));
418 /* Only send new config to HW if we are in SW LLDP mode. Otherwise,
419 * the new config came from the HW in the first place.
421 if (pf->hw.port_info->qos_cfg.is_sw_lldp) {
422 ret = ice_set_dcb_cfg(pf->hw.port_info);
424 dev_err(dev, "Set DCB Config failed\n");
425 /* Restore previous settings to local config */
426 memcpy(curr_cfg, old_cfg, sizeof(*curr_cfg));
431 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
433 dev_err(dev, "Query Port ETS failed\n");
437 ice_pf_dcb_recfg(pf);
440 /* enable previously downed VSIs */
441 ice_dcb_ena_dis_vsi(pf, true, true);
450 * ice_cfg_etsrec_defaults - Set default ETS recommended DCB config
451 * @pi: port information structure
453 static void ice_cfg_etsrec_defaults(struct ice_port_info *pi)
455 struct ice_dcbx_cfg *dcbcfg = &pi->qos_cfg.local_dcbx_cfg;
458 /* Ensure ETS recommended DCB configuration is not already set */
459 if (dcbcfg->etsrec.maxtcs)
462 /* In CEE mode, set the default to 1 TC */
463 dcbcfg->etsrec.maxtcs = 1;
464 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
465 dcbcfg->etsrec.tcbwtable[i] = i ? 0 : 100;
466 dcbcfg->etsrec.tsatable[i] = i ? ICE_IEEE_TSA_STRICT :
472 * ice_dcb_need_recfg - Check if DCB needs reconfig
473 * @pf: board private structure
474 * @old_cfg: current DCB config
475 * @new_cfg: new DCB config
478 ice_dcb_need_recfg(struct ice_pf *pf, struct ice_dcbx_cfg *old_cfg,
479 struct ice_dcbx_cfg *new_cfg)
481 struct device *dev = ice_pf_to_dev(pf);
482 bool need_reconfig = false;
484 /* Check if ETS configuration has changed */
485 if (memcmp(&new_cfg->etscfg, &old_cfg->etscfg,
486 sizeof(new_cfg->etscfg))) {
487 /* If Priority Table has changed reconfig is needed */
488 if (memcmp(&new_cfg->etscfg.prio_table,
489 &old_cfg->etscfg.prio_table,
490 sizeof(new_cfg->etscfg.prio_table))) {
491 need_reconfig = true;
492 dev_dbg(dev, "ETS UP2TC changed.\n");
495 if (memcmp(&new_cfg->etscfg.tcbwtable,
496 &old_cfg->etscfg.tcbwtable,
497 sizeof(new_cfg->etscfg.tcbwtable)))
498 dev_dbg(dev, "ETS TC BW Table changed.\n");
500 if (memcmp(&new_cfg->etscfg.tsatable,
501 &old_cfg->etscfg.tsatable,
502 sizeof(new_cfg->etscfg.tsatable)))
503 dev_dbg(dev, "ETS TSA Table changed.\n");
506 /* Check if PFC configuration has changed */
507 if (memcmp(&new_cfg->pfc, &old_cfg->pfc, sizeof(new_cfg->pfc))) {
508 need_reconfig = true;
509 dev_dbg(dev, "PFC config change detected.\n");
512 /* Check if APP Table has changed */
513 if (memcmp(&new_cfg->app, &old_cfg->app, sizeof(new_cfg->app))) {
514 need_reconfig = true;
515 dev_dbg(dev, "APP Table change detected.\n");
518 dev_dbg(dev, "dcb need_reconfig=%d\n", need_reconfig);
519 return need_reconfig;
523 * ice_dcb_rebuild - rebuild DCB post reset
524 * @pf: physical function instance
526 void ice_dcb_rebuild(struct ice_pf *pf)
528 struct ice_aqc_port_ets_elem buf = { 0 };
529 struct device *dev = ice_pf_to_dev(pf);
530 struct ice_dcbx_cfg *err_cfg;
533 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
535 dev_err(dev, "Query Port ETS failed\n");
539 mutex_lock(&pf->tc_mutex);
541 if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
542 ice_cfg_etsrec_defaults(pf->hw.port_info);
544 ret = ice_set_dcb_cfg(pf->hw.port_info);
546 dev_err(dev, "Failed to set DCB config in rebuild\n");
550 if (!pf->hw.port_info->qos_cfg.is_sw_lldp) {
551 ret = ice_cfg_lldp_mib_change(&pf->hw, true);
552 if (ret && !pf->hw.port_info->qos_cfg.is_sw_lldp) {
553 dev_err(dev, "Failed to register for MIB changes\n");
558 dev_info(dev, "DCB info restored\n");
559 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
561 dev_err(dev, "Query Port ETS failed\n");
565 mutex_unlock(&pf->tc_mutex);
570 dev_err(dev, "Disabling DCB until new settings occur\n");
571 err_cfg = kzalloc(sizeof(*err_cfg), GFP_KERNEL);
573 mutex_unlock(&pf->tc_mutex);
577 err_cfg->etscfg.willing = true;
578 err_cfg->etscfg.tcbwtable[0] = ICE_TC_MAX_BW;
579 err_cfg->etscfg.tsatable[0] = ICE_IEEE_TSA_ETS;
580 memcpy(&err_cfg->etsrec, &err_cfg->etscfg, sizeof(err_cfg->etsrec));
581 /* Coverity warns the return code of ice_pf_dcb_cfg() is not checked
582 * here as is done for other calls to that function. That check is
583 * not necessary since this is in this function's error cleanup path.
584 * Suppress the Coverity warning with the following comment...
586 /* coverity[check_return] */
587 ice_pf_dcb_cfg(pf, err_cfg, false);
590 mutex_unlock(&pf->tc_mutex);
594 * ice_dcb_init_cfg - set the initial DCB config in SW
595 * @pf: PF to apply config to
596 * @locked: Is the RTNL held
598 static int ice_dcb_init_cfg(struct ice_pf *pf, bool locked)
600 struct ice_dcbx_cfg *newcfg;
601 struct ice_port_info *pi;
604 pi = pf->hw.port_info;
605 newcfg = kmemdup(&pi->qos_cfg.local_dcbx_cfg, sizeof(*newcfg),
610 memset(&pi->qos_cfg.local_dcbx_cfg, 0, sizeof(*newcfg));
612 dev_info(ice_pf_to_dev(pf), "Configuring initial DCB values\n");
613 if (ice_pf_dcb_cfg(pf, newcfg, locked))
622 * ice_dcb_sw_dflt_cfg - Apply a default DCB config
623 * @pf: PF to apply config to
624 * @ets_willing: configure ETS willing
625 * @locked: was this function called with RTNL held
627 int ice_dcb_sw_dflt_cfg(struct ice_pf *pf, bool ets_willing, bool locked)
629 struct ice_aqc_port_ets_elem buf = { 0 };
630 struct ice_dcbx_cfg *dcbcfg;
631 struct ice_port_info *pi;
637 dcbcfg = kzalloc(sizeof(*dcbcfg), GFP_KERNEL);
641 memset(&pi->qos_cfg.local_dcbx_cfg, 0, sizeof(*dcbcfg));
643 dcbcfg->etscfg.willing = ets_willing ? 1 : 0;
644 dcbcfg->etscfg.maxtcs = hw->func_caps.common_cap.maxtc;
645 dcbcfg->etscfg.tcbwtable[0] = 100;
646 dcbcfg->etscfg.tsatable[0] = ICE_IEEE_TSA_ETS;
648 memcpy(&dcbcfg->etsrec, &dcbcfg->etscfg,
649 sizeof(dcbcfg->etsrec));
650 dcbcfg->etsrec.willing = 0;
652 dcbcfg->pfc.willing = 1;
653 dcbcfg->pfc.pfccap = hw->func_caps.common_cap.maxtc;
656 dcbcfg->app[0].selector = ICE_APP_SEL_ETHTYPE;
657 dcbcfg->app[0].priority = 3;
658 dcbcfg->app[0].prot_id = ETH_P_FCOE;
660 ret = ice_pf_dcb_cfg(pf, dcbcfg, locked);
665 return ice_query_port_ets(pi, &buf, sizeof(buf), NULL);
669 * ice_dcb_tc_contig - Check that TCs are contiguous
670 * @prio_table: pointer to priority table
672 * Check if TCs begin with TC0 and are contiguous
674 static bool ice_dcb_tc_contig(u8 *prio_table)
676 bool found_empty = false;
680 /* Create a bitmap of used TCs */
681 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++)
682 used_tc |= BIT(prio_table[i]);
684 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++) {
685 if (used_tc & BIT(i)) {
697 * ice_dcb_noncontig_cfg - Configure DCB for non-contiguous TCs
698 * @pf: pointer to the PF struct
700 * If non-contiguous TCs, then configure SW DCB with TC0 and ETS non-willing
702 static int ice_dcb_noncontig_cfg(struct ice_pf *pf)
704 struct ice_dcbx_cfg *dcbcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
705 struct device *dev = ice_pf_to_dev(pf);
708 /* Configure SW DCB default with ETS non-willing */
709 ret = ice_dcb_sw_dflt_cfg(pf, false, true);
711 dev_err(dev, "Failed to set local DCB config %d\n", ret);
715 /* Reconfigure with ETS willing so that FW will send LLDP MIB event */
716 dcbcfg->etscfg.willing = 1;
717 ret = ice_set_dcb_cfg(pf->hw.port_info);
719 dev_err(dev, "Failed to set DCB to unwilling\n");
725 * ice_pf_dcb_recfg - Reconfigure all VEBs and VSIs
726 * @pf: pointer to the PF struct
728 * Assumed caller has already disabled all VSIs before
729 * calling this function. Reconfiguring DCB based on
732 void ice_pf_dcb_recfg(struct ice_pf *pf)
734 struct ice_dcbx_cfg *dcbcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
735 struct iidc_event *event;
739 /* Update each VSI */
740 ice_for_each_vsi(pf, v) {
741 struct ice_vsi *vsi = pf->vsi[v];
746 if (vsi->type == ICE_VSI_PF) {
747 tc_map = ice_dcb_get_ena_tc(dcbcfg);
749 /* If DCBX request non-contiguous TC, then configure
752 if (!ice_dcb_tc_contig(dcbcfg->etscfg.prio_table)) {
753 tc_map = ICE_DFLT_TRAFFIC_CLASS;
754 ice_dcb_noncontig_cfg(pf);
756 } else if (vsi->type == ICE_VSI_CHNL) {
757 tc_map = BIT(ice_get_first_droptc(vsi));
759 tc_map = ICE_DFLT_TRAFFIC_CLASS;
762 ret = ice_vsi_cfg_tc(vsi, tc_map);
764 dev_err(ice_pf_to_dev(pf), "Failed to config TC for VSI index: %d\n",
768 /* no need to proceed with remaining cfg if it is CHNL
771 if (vsi->type == ICE_VSI_CHNL ||
772 vsi->type == ICE_VSI_SWITCHDEV_CTRL)
775 ice_vsi_map_rings_to_vectors(vsi);
776 if (vsi->type == ICE_VSI_PF)
777 ice_dcbnl_set_all(vsi);
779 /* Notify the AUX drivers that TC change is finished */
780 event = kzalloc(sizeof(*event), GFP_KERNEL);
784 set_bit(IIDC_EVENT_AFTER_TC_CHANGE, event->type);
785 ice_send_event_to_aux(pf, event);
790 * ice_init_pf_dcb - initialize DCB for a PF
791 * @pf: PF to initialize DCB for
792 * @locked: Was function called with RTNL held
794 int ice_init_pf_dcb(struct ice_pf *pf, bool locked)
796 struct device *dev = ice_pf_to_dev(pf);
797 struct ice_port_info *port_info;
798 struct ice_hw *hw = &pf->hw;
801 port_info = hw->port_info;
803 err = ice_init_dcb(hw, false);
804 if (err && !port_info->qos_cfg.is_sw_lldp) {
805 dev_err(dev, "Error initializing DCB %d\n", err);
809 dev_info(dev, "DCB is enabled in the hardware, max number of TCs supported on this port are %d\n",
810 pf->hw.func_caps.common_cap.maxtc);
812 struct ice_vsi *pf_vsi;
814 /* FW LLDP is disabled, activate SW DCBX/LLDP mode */
815 dev_info(dev, "FW LLDP is disabled, DCBx/LLDP in SW mode.\n");
816 clear_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
817 err = ice_aq_set_pfc_mode(&pf->hw, ICE_AQC_PFC_VLAN_BASED_PFC,
820 dev_info(dev, "Failed to set VLAN PFC mode\n");
822 err = ice_dcb_sw_dflt_cfg(pf, true, locked);
824 dev_err(dev, "Failed to set local DCB config %d\n",
830 /* If the FW DCBX engine is not running then Rx LLDP packets
831 * need to be redirected up the stack.
833 pf_vsi = ice_get_main_vsi(pf);
835 dev_err(dev, "Failed to set local DCB config\n");
840 ice_cfg_sw_lldp(pf_vsi, false, true);
842 pf->dcbx_cap = ice_dcb_get_mode(port_info, true);
846 set_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
848 /* DCBX/LLDP enabled in FW, set DCBNL mode advertisement */
849 pf->dcbx_cap = ice_dcb_get_mode(port_info, false);
851 err = ice_dcb_init_cfg(pf, locked);
858 dev_err(dev, "DCB init failed\n");
863 * ice_update_dcb_stats - Update DCB stats counters
864 * @pf: PF whose stats needs to be updated
866 void ice_update_dcb_stats(struct ice_pf *pf)
868 struct ice_hw_port_stats *prev_ps, *cur_ps;
869 struct ice_hw *hw = &pf->hw;
873 port = hw->port_info->lport;
874 prev_ps = &pf->stats_prev;
877 for (i = 0; i < 8; i++) {
878 ice_stat_update32(hw, GLPRT_PXOFFRXC(port, i),
879 pf->stat_prev_loaded,
880 &prev_ps->priority_xoff_rx[i],
881 &cur_ps->priority_xoff_rx[i]);
882 ice_stat_update32(hw, GLPRT_PXONRXC(port, i),
883 pf->stat_prev_loaded,
884 &prev_ps->priority_xon_rx[i],
885 &cur_ps->priority_xon_rx[i]);
886 ice_stat_update32(hw, GLPRT_PXONTXC(port, i),
887 pf->stat_prev_loaded,
888 &prev_ps->priority_xon_tx[i],
889 &cur_ps->priority_xon_tx[i]);
890 ice_stat_update32(hw, GLPRT_PXOFFTXC(port, i),
891 pf->stat_prev_loaded,
892 &prev_ps->priority_xoff_tx[i],
893 &cur_ps->priority_xoff_tx[i]);
894 ice_stat_update32(hw, GLPRT_RXON2OFFCNT(port, i),
895 pf->stat_prev_loaded,
896 &prev_ps->priority_xon_2_xoff[i],
897 &cur_ps->priority_xon_2_xoff[i]);
902 * ice_tx_prepare_vlan_flags_dcb - prepare VLAN tagging for DCB
903 * @tx_ring: ring to send buffer on
904 * @first: pointer to struct ice_tx_buf
906 * This should not be called if the outer VLAN is software offloaded as the VLAN
907 * tag will already be configured with the correct ID and priority bits
910 ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring *tx_ring,
911 struct ice_tx_buf *first)
913 struct sk_buff *skb = first->skb;
915 if (!test_bit(ICE_FLAG_DCB_ENA, tx_ring->vsi->back->flags))
918 /* Insert 802.1p priority into VLAN header */
919 if ((first->tx_flags & ICE_TX_FLAGS_HW_VLAN) ||
920 skb->priority != TC_PRIO_CONTROL) {
921 first->tx_flags &= ~ICE_TX_FLAGS_VLAN_PR_M;
922 /* Mask the lower 3 bits to set the 802.1p priority */
923 first->tx_flags |= (skb->priority & 0x7) <<
924 ICE_TX_FLAGS_VLAN_PR_S;
925 /* if this is not already set it means a VLAN 0 + priority needs
928 first->tx_flags |= ICE_TX_FLAGS_HW_VLAN;
933 * ice_dcb_process_lldp_set_mib_change - Process MIB change
935 * @event: pointer to the admin queue receive event
938 ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf,
939 struct ice_rq_event_info *event)
941 struct ice_aqc_port_ets_elem buf = { 0 };
942 struct device *dev = ice_pf_to_dev(pf);
943 struct ice_aqc_lldp_get_mib *mib;
944 struct ice_dcbx_cfg tmp_dcbx_cfg;
945 bool need_reconfig = false;
946 struct ice_port_info *pi;
950 /* Not DCB capable or capability disabled */
951 if (!(test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags)))
954 if (pf->dcbx_cap & DCB_CAP_DCBX_HOST) {
955 dev_dbg(dev, "MIB Change Event in HOST mode\n");
959 pi = pf->hw.port_info;
960 mib = (struct ice_aqc_lldp_get_mib *)&event->desc.params.raw;
961 /* Ignore if event is not for Nearest Bridge */
962 mib_type = ((mib->type >> ICE_AQ_LLDP_BRID_TYPE_S) &
963 ICE_AQ_LLDP_BRID_TYPE_M);
964 dev_dbg(dev, "LLDP event MIB bridge type 0x%x\n", mib_type);
965 if (mib_type != ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID)
968 /* Check MIB Type and return if event for Remote MIB update */
969 mib_type = mib->type & ICE_AQ_LLDP_MIB_TYPE_M;
970 dev_dbg(dev, "LLDP event mib type %s\n", mib_type ? "remote" : "local");
971 if (mib_type == ICE_AQ_LLDP_MIB_REMOTE) {
972 /* Update the remote cached instance and return */
973 ret = ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_REMOTE,
974 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID,
975 &pi->qos_cfg.remote_dcbx_cfg);
977 dev_err(dev, "Failed to get remote DCB config\n");
982 mutex_lock(&pf->tc_mutex);
984 /* store the old configuration */
985 tmp_dcbx_cfg = pf->hw.port_info->qos_cfg.local_dcbx_cfg;
987 /* Reset the old DCBX configuration data */
988 memset(&pi->qos_cfg.local_dcbx_cfg, 0,
989 sizeof(pi->qos_cfg.local_dcbx_cfg));
991 /* Get updated DCBX data from firmware */
992 ret = ice_get_dcb_cfg(pf->hw.port_info);
994 dev_err(dev, "Failed to get DCB config\n");
998 /* No change detected in DCBX configs */
999 if (!memcmp(&tmp_dcbx_cfg, &pi->qos_cfg.local_dcbx_cfg,
1000 sizeof(tmp_dcbx_cfg))) {
1001 dev_dbg(dev, "No change detected in DCBX configuration.\n");
1005 pf->dcbx_cap = ice_dcb_get_mode(pi, false);
1007 need_reconfig = ice_dcb_need_recfg(pf, &tmp_dcbx_cfg,
1008 &pi->qos_cfg.local_dcbx_cfg);
1009 ice_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &pi->qos_cfg.local_dcbx_cfg);
1013 /* Enable DCB tagging only when more than one TC */
1014 if (ice_dcb_get_num_tc(&pi->qos_cfg.local_dcbx_cfg) > 1) {
1015 dev_dbg(dev, "DCB tagging enabled (num TC > 1)\n");
1016 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
1018 dev_dbg(dev, "DCB tagging disabled (num TC = 1)\n");
1019 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
1023 /* disable VSIs affected by DCB changes */
1024 ice_dcb_ena_dis_vsi(pf, false, true);
1026 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
1028 dev_err(dev, "Query Port ETS failed\n");
1032 /* changes in configuration update VSI */
1033 ice_pf_dcb_recfg(pf);
1035 /* enable previously downed VSIs */
1036 ice_dcb_ena_dis_vsi(pf, true, true);
1040 mutex_unlock(&pf->tc_mutex);