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_vsi_cfg_netdev_tc - Setup the netdev TC configuration
9 * @vsi: the VSI being configured
10 * @ena_tc: TC map to be enabled
12 void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc)
14 struct net_device *netdev = vsi->netdev;
15 struct ice_pf *pf = vsi->back;
16 struct ice_dcbx_cfg *dcbcfg;
24 netdev_reset_tc(netdev);
28 if (netdev_set_num_tc(netdev, vsi->tc_cfg.numtc))
31 dcbcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
33 ice_for_each_traffic_class(i)
34 if (vsi->tc_cfg.ena_tc & BIT(i))
35 netdev_set_tc_queue(netdev,
36 vsi->tc_cfg.tc_info[i].netdev_tc,
37 vsi->tc_cfg.tc_info[i].qcount_tx,
38 vsi->tc_cfg.tc_info[i].qoffset);
40 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
41 u8 ets_tc = dcbcfg->etscfg.prio_table[i];
43 /* Get the mapped netdev TC# for the UP */
44 netdev_tc = vsi->tc_cfg.tc_info[ets_tc].netdev_tc;
45 netdev_set_prio_tc_map(netdev, i, netdev_tc);
50 * ice_dcb_get_ena_tc - return bitmap of enabled TCs
51 * @dcbcfg: DCB config to evaluate for enabled TCs
53 u8 ice_dcb_get_ena_tc(struct ice_dcbx_cfg *dcbcfg)
55 u8 i, num_tc, ena_tc = 1;
57 num_tc = ice_dcb_get_num_tc(dcbcfg);
59 for (i = 0; i < num_tc; i++)
66 * ice_is_pfc_causing_hung_q
67 * @pf: pointer to PF structure
68 * @txqueue: Tx queue which is supposedly hung queue
70 * find if PFC is causing the hung queue, if yes return true else false
72 bool ice_is_pfc_causing_hung_q(struct ice_pf *pf, unsigned int txqueue)
74 u8 num_tcs = 0, i, tc, up_mapped_tc, up_in_tc = 0;
75 u64 ref_prio_xoff[ICE_MAX_UP];
79 vsi = ice_get_main_vsi(pf);
83 ice_for_each_traffic_class(i)
84 if (vsi->tc_cfg.ena_tc & BIT(i))
87 /* first find out the TC to which the hung queue belongs to */
88 for (tc = 0; tc < num_tcs - 1; tc++)
89 if (ice_find_q_in_range(vsi->tc_cfg.tc_info[tc].qoffset,
90 vsi->tc_cfg.tc_info[tc + 1].qoffset,
94 /* Build a bit map of all UPs associated to the suspect hung queue TC,
95 * so that we check for its counter increment.
97 up2tc = rd32(&pf->hw, PRTDCB_TUP2TC);
98 for (i = 0; i < ICE_MAX_UP; i++) {
99 up_mapped_tc = (up2tc >> (i * 3)) & 0x7;
100 if (up_mapped_tc == tc)
104 /* Now that we figured out that hung queue is PFC enabled, still the
105 * Tx timeout can be legitimate. So to make sure Tx timeout is
106 * absolutely caused by PFC storm, check if the counters are
109 for (i = 0; i < ICE_MAX_UP; i++)
110 if (up_in_tc & BIT(i))
111 ref_prio_xoff[i] = pf->stats.priority_xoff_rx[i];
113 ice_update_dcb_stats(pf);
115 for (i = 0; i < ICE_MAX_UP; i++)
116 if (up_in_tc & BIT(i))
117 if (pf->stats.priority_xoff_rx[i] > ref_prio_xoff[i])
124 * ice_dcb_get_mode - gets the DCB mode
125 * @port_info: pointer to port info structure
126 * @host: if set it's HOST if not it's MANAGED
128 static u8 ice_dcb_get_mode(struct ice_port_info *port_info, bool host)
133 mode = DCB_CAP_DCBX_HOST;
135 mode = DCB_CAP_DCBX_LLD_MANAGED;
137 if (port_info->qos_cfg.local_dcbx_cfg.dcbx_mode & ICE_DCBX_MODE_CEE)
138 return mode | DCB_CAP_DCBX_VER_CEE;
140 return mode | DCB_CAP_DCBX_VER_IEEE;
144 * ice_dcb_get_num_tc - Get the number of TCs from DCBX config
145 * @dcbcfg: config to retrieve number of TCs from
147 u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg *dcbcfg)
149 bool tc_unused = false;
154 /* Scan the ETS Config Priority Table to find traffic classes
155 * enabled and create a bitmask of enabled TCs
157 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++)
158 num_tc |= BIT(dcbcfg->etscfg.prio_table[i]);
160 /* Scan bitmask for contiguous TCs starting with TC0 */
161 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
162 if (num_tc & BIT(i)) {
166 pr_err("Non-contiguous TCs - Disabling DCB\n");
174 /* There is always at least 1 TC */
182 * ice_dcb_get_tc - Get the TC associated with the queue
183 * @vsi: ptr to the VSI
184 * @queue_index: queue number associated with VSI
186 u8 ice_dcb_get_tc(struct ice_vsi *vsi, int queue_index)
188 return vsi->tx_rings[queue_index]->dcb_tc;
192 * ice_vsi_cfg_dcb_rings - Update rings to reflect DCB TC
193 * @vsi: VSI owner of rings being updated
195 void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi)
197 struct ice_ring *tx_ring, *rx_ring;
201 if (!test_bit(ICE_FLAG_DCB_ENA, vsi->back->flags)) {
202 /* Reset the TC information */
203 for (i = 0; i < vsi->num_txq; i++) {
204 tx_ring = vsi->tx_rings[i];
207 for (i = 0; i < vsi->num_rxq; i++) {
208 rx_ring = vsi->rx_rings[i];
214 ice_for_each_traffic_class(n) {
215 if (!(vsi->tc_cfg.ena_tc & BIT(n)))
218 qoffset = vsi->tc_cfg.tc_info[n].qoffset;
219 qcount = vsi->tc_cfg.tc_info[n].qcount_tx;
220 for (i = qoffset; i < (qoffset + qcount); i++) {
221 tx_ring = vsi->tx_rings[i];
222 rx_ring = vsi->rx_rings[i];
230 * ice_dcb_bwchk - check if ETS bandwidth input parameters are correct
231 * @pf: pointer to the PF struct
232 * @dcbcfg: pointer to DCB config structure
234 int ice_dcb_bwchk(struct ice_pf *pf, struct ice_dcbx_cfg *dcbcfg)
236 struct ice_dcb_ets_cfg *etscfg = &dcbcfg->etscfg;
237 u8 num_tc, total_bw = 0;
240 /* returns number of contigous TCs and 1 TC for non-contigous TCs,
241 * since at least 1 TC has to be configured
243 num_tc = ice_dcb_get_num_tc(dcbcfg);
245 /* no bandwidth checks required if there's only one TC, so assign
246 * all bandwidth to TC0 and return
249 etscfg->tcbwtable[0] = ICE_TC_MAX_BW;
253 for (i = 0; i < num_tc; i++)
254 total_bw += etscfg->tcbwtable[i];
257 etscfg->tcbwtable[0] = ICE_TC_MAX_BW;
258 } else if (total_bw != ICE_TC_MAX_BW) {
259 dev_err(ice_pf_to_dev(pf), "Invalid config, total bandwidth must equal 100\n");
267 * ice_pf_dcb_cfg - Apply new DCB configuration
268 * @pf: pointer to the PF struct
269 * @new_cfg: DCBX config to apply
270 * @locked: is the RTNL held
272 int ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked)
274 struct ice_aqc_port_ets_elem buf = { 0 };
275 struct ice_dcbx_cfg *old_cfg, *curr_cfg;
276 struct device *dev = ice_pf_to_dev(pf);
277 int ret = ICE_DCB_NO_HW_CHG;
278 struct iidc_event *event;
279 struct ice_vsi *pf_vsi;
281 curr_cfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
283 /* FW does not care if change happened */
284 if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
285 ret = ICE_DCB_HW_CHG_RST;
287 /* Enable DCB tagging only when more than one TC */
288 if (ice_dcb_get_num_tc(new_cfg) > 1) {
289 dev_dbg(dev, "DCB tagging enabled (num TC > 1)\n");
290 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
292 dev_dbg(dev, "DCB tagging disabled (num TC = 1)\n");
293 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
296 if (!memcmp(new_cfg, curr_cfg, sizeof(*new_cfg))) {
297 dev_dbg(dev, "No change in DCB config required\n");
301 if (ice_dcb_bwchk(pf, new_cfg))
304 /* Store old config in case FW config fails */
305 old_cfg = kmemdup(curr_cfg, sizeof(*old_cfg), GFP_KERNEL);
309 dev_info(dev, "Commit DCB Configuration to the hardware\n");
310 pf_vsi = ice_get_main_vsi(pf);
312 dev_dbg(dev, "PF VSI doesn't exist\n");
317 /* Notify AUX drivers about impending change to TCs */
318 event = kzalloc(sizeof(*event), GFP_KERNEL);
324 set_bit(IIDC_EVENT_BEFORE_TC_CHANGE, event->type);
325 ice_send_event_to_aux(pf, event);
328 /* avoid race conditions by holding the lock while disabling and
329 * re-enabling the VSI
333 ice_dis_vsi(pf_vsi, true);
335 memcpy(curr_cfg, new_cfg, sizeof(*curr_cfg));
336 memcpy(&curr_cfg->etsrec, &curr_cfg->etscfg, sizeof(curr_cfg->etsrec));
337 memcpy(&new_cfg->etsrec, &curr_cfg->etscfg, sizeof(curr_cfg->etsrec));
339 /* Only send new config to HW if we are in SW LLDP mode. Otherwise,
340 * the new config came from the HW in the first place.
342 if (pf->hw.port_info->qos_cfg.is_sw_lldp) {
343 ret = ice_set_dcb_cfg(pf->hw.port_info);
345 dev_err(dev, "Set DCB Config failed\n");
346 /* Restore previous settings to local config */
347 memcpy(curr_cfg, old_cfg, sizeof(*curr_cfg));
352 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
354 dev_err(dev, "Query Port ETS failed\n");
358 ice_pf_dcb_recfg(pf);
361 ice_ena_vsi(pf_vsi, true);
370 * ice_cfg_etsrec_defaults - Set default ETS recommended DCB config
371 * @pi: port information structure
373 static void ice_cfg_etsrec_defaults(struct ice_port_info *pi)
375 struct ice_dcbx_cfg *dcbcfg = &pi->qos_cfg.local_dcbx_cfg;
378 /* Ensure ETS recommended DCB configuration is not already set */
379 if (dcbcfg->etsrec.maxtcs)
382 /* In CEE mode, set the default to 1 TC */
383 dcbcfg->etsrec.maxtcs = 1;
384 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
385 dcbcfg->etsrec.tcbwtable[i] = i ? 0 : 100;
386 dcbcfg->etsrec.tsatable[i] = i ? ICE_IEEE_TSA_STRICT :
392 * ice_dcb_need_recfg - Check if DCB needs reconfig
393 * @pf: board private structure
394 * @old_cfg: current DCB config
395 * @new_cfg: new DCB config
398 ice_dcb_need_recfg(struct ice_pf *pf, struct ice_dcbx_cfg *old_cfg,
399 struct ice_dcbx_cfg *new_cfg)
401 struct device *dev = ice_pf_to_dev(pf);
402 bool need_reconfig = false;
404 /* Check if ETS configuration has changed */
405 if (memcmp(&new_cfg->etscfg, &old_cfg->etscfg,
406 sizeof(new_cfg->etscfg))) {
407 /* If Priority Table has changed reconfig is needed */
408 if (memcmp(&new_cfg->etscfg.prio_table,
409 &old_cfg->etscfg.prio_table,
410 sizeof(new_cfg->etscfg.prio_table))) {
411 need_reconfig = true;
412 dev_dbg(dev, "ETS UP2TC changed.\n");
415 if (memcmp(&new_cfg->etscfg.tcbwtable,
416 &old_cfg->etscfg.tcbwtable,
417 sizeof(new_cfg->etscfg.tcbwtable)))
418 dev_dbg(dev, "ETS TC BW Table changed.\n");
420 if (memcmp(&new_cfg->etscfg.tsatable,
421 &old_cfg->etscfg.tsatable,
422 sizeof(new_cfg->etscfg.tsatable)))
423 dev_dbg(dev, "ETS TSA Table changed.\n");
426 /* Check if PFC configuration has changed */
427 if (memcmp(&new_cfg->pfc, &old_cfg->pfc, sizeof(new_cfg->pfc))) {
428 need_reconfig = true;
429 dev_dbg(dev, "PFC config change detected.\n");
432 /* Check if APP Table has changed */
433 if (memcmp(&new_cfg->app, &old_cfg->app, sizeof(new_cfg->app))) {
434 need_reconfig = true;
435 dev_dbg(dev, "APP Table change detected.\n");
438 dev_dbg(dev, "dcb need_reconfig=%d\n", need_reconfig);
439 return need_reconfig;
443 * ice_dcb_rebuild - rebuild DCB post reset
444 * @pf: physical function instance
446 void ice_dcb_rebuild(struct ice_pf *pf)
448 struct ice_aqc_port_ets_elem buf = { 0 };
449 struct device *dev = ice_pf_to_dev(pf);
450 struct ice_dcbx_cfg *err_cfg;
453 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
455 dev_err(dev, "Query Port ETS failed\n");
459 mutex_lock(&pf->tc_mutex);
461 if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
462 ice_cfg_etsrec_defaults(pf->hw.port_info);
464 ret = ice_set_dcb_cfg(pf->hw.port_info);
466 dev_err(dev, "Failed to set DCB config in rebuild\n");
470 if (!pf->hw.port_info->qos_cfg.is_sw_lldp) {
471 ret = ice_cfg_lldp_mib_change(&pf->hw, true);
472 if (ret && !pf->hw.port_info->qos_cfg.is_sw_lldp) {
473 dev_err(dev, "Failed to register for MIB changes\n");
478 dev_info(dev, "DCB info restored\n");
479 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
481 dev_err(dev, "Query Port ETS failed\n");
485 mutex_unlock(&pf->tc_mutex);
490 dev_err(dev, "Disabling DCB until new settings occur\n");
491 err_cfg = kzalloc(sizeof(*err_cfg), GFP_KERNEL);
493 mutex_unlock(&pf->tc_mutex);
497 err_cfg->etscfg.willing = true;
498 err_cfg->etscfg.tcbwtable[0] = ICE_TC_MAX_BW;
499 err_cfg->etscfg.tsatable[0] = ICE_IEEE_TSA_ETS;
500 memcpy(&err_cfg->etsrec, &err_cfg->etscfg, sizeof(err_cfg->etsrec));
501 /* Coverity warns the return code of ice_pf_dcb_cfg() is not checked
502 * here as is done for other calls to that function. That check is
503 * not necessary since this is in this function's error cleanup path.
504 * Suppress the Coverity warning with the following comment...
506 /* coverity[check_return] */
507 ice_pf_dcb_cfg(pf, err_cfg, false);
510 mutex_unlock(&pf->tc_mutex);
514 * ice_dcb_init_cfg - set the initial DCB config in SW
515 * @pf: PF to apply config to
516 * @locked: Is the RTNL held
518 static int ice_dcb_init_cfg(struct ice_pf *pf, bool locked)
520 struct ice_dcbx_cfg *newcfg;
521 struct ice_port_info *pi;
524 pi = pf->hw.port_info;
525 newcfg = kmemdup(&pi->qos_cfg.local_dcbx_cfg, sizeof(*newcfg),
530 memset(&pi->qos_cfg.local_dcbx_cfg, 0, sizeof(*newcfg));
532 dev_info(ice_pf_to_dev(pf), "Configuring initial DCB values\n");
533 if (ice_pf_dcb_cfg(pf, newcfg, locked))
542 * ice_dcb_sw_dflt_cfg - Apply a default DCB config
543 * @pf: PF to apply config to
544 * @ets_willing: configure ETS willing
545 * @locked: was this function called with RTNL held
547 static int ice_dcb_sw_dflt_cfg(struct ice_pf *pf, bool ets_willing, bool locked)
549 struct ice_aqc_port_ets_elem buf = { 0 };
550 struct ice_dcbx_cfg *dcbcfg;
551 struct ice_port_info *pi;
557 dcbcfg = kzalloc(sizeof(*dcbcfg), GFP_KERNEL);
561 memset(&pi->qos_cfg.local_dcbx_cfg, 0, sizeof(*dcbcfg));
563 dcbcfg->etscfg.willing = ets_willing ? 1 : 0;
564 dcbcfg->etscfg.maxtcs = hw->func_caps.common_cap.maxtc;
565 dcbcfg->etscfg.tcbwtable[0] = 100;
566 dcbcfg->etscfg.tsatable[0] = ICE_IEEE_TSA_ETS;
568 memcpy(&dcbcfg->etsrec, &dcbcfg->etscfg,
569 sizeof(dcbcfg->etsrec));
570 dcbcfg->etsrec.willing = 0;
572 dcbcfg->pfc.willing = 1;
573 dcbcfg->pfc.pfccap = hw->func_caps.common_cap.maxtc;
576 dcbcfg->app[0].selector = ICE_APP_SEL_ETHTYPE;
577 dcbcfg->app[0].priority = 3;
578 dcbcfg->app[0].prot_id = ETH_P_FCOE;
580 ret = ice_pf_dcb_cfg(pf, dcbcfg, locked);
585 return ice_query_port_ets(pi, &buf, sizeof(buf), NULL);
589 * ice_dcb_tc_contig - Check that TCs are contiguous
590 * @prio_table: pointer to priority table
592 * Check if TCs begin with TC0 and are contiguous
594 static bool ice_dcb_tc_contig(u8 *prio_table)
596 bool found_empty = false;
600 /* Create a bitmap of used TCs */
601 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++)
602 used_tc |= BIT(prio_table[i]);
604 for (i = 0; i < CEE_DCBX_MAX_PRIO; i++) {
605 if (used_tc & BIT(i)) {
617 * ice_dcb_noncontig_cfg - Configure DCB for non-contiguous TCs
618 * @pf: pointer to the PF struct
620 * If non-contiguous TCs, then configure SW DCB with TC0 and ETS non-willing
622 static int ice_dcb_noncontig_cfg(struct ice_pf *pf)
624 struct ice_dcbx_cfg *dcbcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
625 struct device *dev = ice_pf_to_dev(pf);
628 /* Configure SW DCB default with ETS non-willing */
629 ret = ice_dcb_sw_dflt_cfg(pf, false, true);
631 dev_err(dev, "Failed to set local DCB config %d\n", ret);
635 /* Reconfigure with ETS willing so that FW will send LLDP MIB event */
636 dcbcfg->etscfg.willing = 1;
637 ret = ice_set_dcb_cfg(pf->hw.port_info);
639 dev_err(dev, "Failed to set DCB to unwilling\n");
645 * ice_pf_dcb_recfg - Reconfigure all VEBs and VSIs
646 * @pf: pointer to the PF struct
648 * Assumed caller has already disabled all VSIs before
649 * calling this function. Reconfiguring DCB based on
652 void ice_pf_dcb_recfg(struct ice_pf *pf)
654 struct ice_dcbx_cfg *dcbcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
655 struct iidc_event *event;
659 /* Update each VSI */
660 ice_for_each_vsi(pf, v) {
661 struct ice_vsi *vsi = pf->vsi[v];
666 if (vsi->type == ICE_VSI_PF) {
667 tc_map = ice_dcb_get_ena_tc(dcbcfg);
669 /* If DCBX request non-contiguous TC, then configure
672 if (!ice_dcb_tc_contig(dcbcfg->etscfg.prio_table)) {
673 tc_map = ICE_DFLT_TRAFFIC_CLASS;
674 ice_dcb_noncontig_cfg(pf);
677 tc_map = ICE_DFLT_TRAFFIC_CLASS;
680 ret = ice_vsi_cfg_tc(vsi, tc_map);
682 dev_err(ice_pf_to_dev(pf), "Failed to config TC for VSI index: %d\n",
687 ice_vsi_map_rings_to_vectors(vsi);
688 if (vsi->type == ICE_VSI_PF)
689 ice_dcbnl_set_all(vsi);
691 /* Notify the AUX drivers that TC change is finished */
692 event = kzalloc(sizeof(*event), GFP_KERNEL);
696 set_bit(IIDC_EVENT_AFTER_TC_CHANGE, event->type);
697 ice_send_event_to_aux(pf, event);
702 * ice_init_pf_dcb - initialize DCB for a PF
703 * @pf: PF to initialize DCB for
704 * @locked: Was function called with RTNL held
706 int ice_init_pf_dcb(struct ice_pf *pf, bool locked)
708 struct device *dev = ice_pf_to_dev(pf);
709 struct ice_port_info *port_info;
710 struct ice_hw *hw = &pf->hw;
713 port_info = hw->port_info;
715 err = ice_init_dcb(hw, false);
716 if (err && !port_info->qos_cfg.is_sw_lldp) {
717 dev_err(dev, "Error initializing DCB %d\n", err);
721 dev_info(dev, "DCB is enabled in the hardware, max number of TCs supported on this port are %d\n",
722 pf->hw.func_caps.common_cap.maxtc);
724 struct ice_vsi *pf_vsi;
726 /* FW LLDP is disabled, activate SW DCBX/LLDP mode */
727 dev_info(dev, "FW LLDP is disabled, DCBx/LLDP in SW mode.\n");
728 clear_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
729 err = ice_dcb_sw_dflt_cfg(pf, true, locked);
731 dev_err(dev, "Failed to set local DCB config %d\n",
737 /* If the FW DCBX engine is not running then Rx LLDP packets
738 * need to be redirected up the stack.
740 pf_vsi = ice_get_main_vsi(pf);
742 dev_err(dev, "Failed to set local DCB config\n");
747 ice_cfg_sw_lldp(pf_vsi, false, true);
749 pf->dcbx_cap = ice_dcb_get_mode(port_info, true);
753 set_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
755 /* DCBX/LLDP enabled in FW, set DCBNL mode advertisement */
756 pf->dcbx_cap = ice_dcb_get_mode(port_info, false);
758 err = ice_dcb_init_cfg(pf, locked);
765 dev_err(dev, "DCB init failed\n");
770 * ice_update_dcb_stats - Update DCB stats counters
771 * @pf: PF whose stats needs to be updated
773 void ice_update_dcb_stats(struct ice_pf *pf)
775 struct ice_hw_port_stats *prev_ps, *cur_ps;
776 struct ice_hw *hw = &pf->hw;
780 port = hw->port_info->lport;
781 prev_ps = &pf->stats_prev;
784 for (i = 0; i < 8; i++) {
785 ice_stat_update32(hw, GLPRT_PXOFFRXC(port, i),
786 pf->stat_prev_loaded,
787 &prev_ps->priority_xoff_rx[i],
788 &cur_ps->priority_xoff_rx[i]);
789 ice_stat_update32(hw, GLPRT_PXONRXC(port, i),
790 pf->stat_prev_loaded,
791 &prev_ps->priority_xon_rx[i],
792 &cur_ps->priority_xon_rx[i]);
793 ice_stat_update32(hw, GLPRT_PXONTXC(port, i),
794 pf->stat_prev_loaded,
795 &prev_ps->priority_xon_tx[i],
796 &cur_ps->priority_xon_tx[i]);
797 ice_stat_update32(hw, GLPRT_PXOFFTXC(port, i),
798 pf->stat_prev_loaded,
799 &prev_ps->priority_xoff_tx[i],
800 &cur_ps->priority_xoff_tx[i]);
801 ice_stat_update32(hw, GLPRT_RXON2OFFCNT(port, i),
802 pf->stat_prev_loaded,
803 &prev_ps->priority_xon_2_xoff[i],
804 &cur_ps->priority_xon_2_xoff[i]);
809 * ice_tx_prepare_vlan_flags_dcb - prepare VLAN tagging for DCB
810 * @tx_ring: ring to send buffer on
811 * @first: pointer to struct ice_tx_buf
813 * This should not be called if the outer VLAN is software offloaded as the VLAN
814 * tag will already be configured with the correct ID and priority bits
817 ice_tx_prepare_vlan_flags_dcb(struct ice_ring *tx_ring,
818 struct ice_tx_buf *first)
820 struct sk_buff *skb = first->skb;
822 if (!test_bit(ICE_FLAG_DCB_ENA, tx_ring->vsi->back->flags))
825 /* Insert 802.1p priority into VLAN header */
826 if ((first->tx_flags & ICE_TX_FLAGS_HW_VLAN) ||
827 skb->priority != TC_PRIO_CONTROL) {
828 first->tx_flags &= ~ICE_TX_FLAGS_VLAN_PR_M;
829 /* Mask the lower 3 bits to set the 802.1p priority */
830 first->tx_flags |= (skb->priority & 0x7) <<
831 ICE_TX_FLAGS_VLAN_PR_S;
832 /* if this is not already set it means a VLAN 0 + priority needs
835 first->tx_flags |= ICE_TX_FLAGS_HW_VLAN;
840 * ice_dcb_process_lldp_set_mib_change - Process MIB change
842 * @event: pointer to the admin queue receive event
845 ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf,
846 struct ice_rq_event_info *event)
848 struct ice_aqc_port_ets_elem buf = { 0 };
849 struct device *dev = ice_pf_to_dev(pf);
850 struct ice_aqc_lldp_get_mib *mib;
851 struct ice_dcbx_cfg tmp_dcbx_cfg;
852 bool need_reconfig = false;
853 struct ice_port_info *pi;
854 struct ice_vsi *pf_vsi;
858 /* Not DCB capable or capability disabled */
859 if (!(test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags)))
862 if (pf->dcbx_cap & DCB_CAP_DCBX_HOST) {
863 dev_dbg(dev, "MIB Change Event in HOST mode\n");
867 pi = pf->hw.port_info;
868 mib = (struct ice_aqc_lldp_get_mib *)&event->desc.params.raw;
869 /* Ignore if event is not for Nearest Bridge */
870 mib_type = ((mib->type >> ICE_AQ_LLDP_BRID_TYPE_S) &
871 ICE_AQ_LLDP_BRID_TYPE_M);
872 dev_dbg(dev, "LLDP event MIB bridge type 0x%x\n", mib_type);
873 if (mib_type != ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID)
876 /* Check MIB Type and return if event for Remote MIB update */
877 mib_type = mib->type & ICE_AQ_LLDP_MIB_TYPE_M;
878 dev_dbg(dev, "LLDP event mib type %s\n", mib_type ? "remote" : "local");
879 if (mib_type == ICE_AQ_LLDP_MIB_REMOTE) {
880 /* Update the remote cached instance and return */
881 ret = ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_REMOTE,
882 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID,
883 &pi->qos_cfg.remote_dcbx_cfg);
885 dev_err(dev, "Failed to get remote DCB config\n");
890 mutex_lock(&pf->tc_mutex);
892 /* store the old configuration */
893 tmp_dcbx_cfg = pf->hw.port_info->qos_cfg.local_dcbx_cfg;
895 /* Reset the old DCBX configuration data */
896 memset(&pi->qos_cfg.local_dcbx_cfg, 0,
897 sizeof(pi->qos_cfg.local_dcbx_cfg));
899 /* Get updated DCBX data from firmware */
900 ret = ice_get_dcb_cfg(pf->hw.port_info);
902 dev_err(dev, "Failed to get DCB config\n");
906 /* No change detected in DCBX configs */
907 if (!memcmp(&tmp_dcbx_cfg, &pi->qos_cfg.local_dcbx_cfg,
908 sizeof(tmp_dcbx_cfg))) {
909 dev_dbg(dev, "No change detected in DCBX configuration.\n");
913 pf->dcbx_cap = ice_dcb_get_mode(pi, false);
915 need_reconfig = ice_dcb_need_recfg(pf, &tmp_dcbx_cfg,
916 &pi->qos_cfg.local_dcbx_cfg);
917 ice_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &pi->qos_cfg.local_dcbx_cfg);
921 /* Enable DCB tagging only when more than one TC */
922 if (ice_dcb_get_num_tc(&pi->qos_cfg.local_dcbx_cfg) > 1) {
923 dev_dbg(dev, "DCB tagging enabled (num TC > 1)\n");
924 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
926 dev_dbg(dev, "DCB tagging disabled (num TC = 1)\n");
927 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
930 pf_vsi = ice_get_main_vsi(pf);
932 dev_dbg(dev, "PF VSI doesn't exist\n");
937 ice_dis_vsi(pf_vsi, true);
939 ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
941 dev_err(dev, "Query Port ETS failed\n");
945 /* changes in configuration update VSI */
946 ice_pf_dcb_recfg(pf);
948 ice_ena_vsi(pf_vsi, true);
952 mutex_unlock(&pf->tc_mutex);