1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019, Intel Corporation. */
6 #include "ice_dcb_lib.h"
7 #include "ice_dcb_nl.h"
11 * ice_dcbnl_devreset - perform enough of a ifdown/ifup to sync DCBNL info
12 * @netdev: device associated with interface that needs reset
14 static void ice_dcbnl_devreset(struct net_device *netdev)
16 struct ice_pf *pf = ice_netdev_to_pf(netdev);
18 while (ice_is_reset_in_progress(pf->state))
19 usleep_range(1000, 2000);
22 netdev_state_change(netdev);
23 dev_open(netdev, NULL);
24 netdev_state_change(netdev);
28 * ice_dcbnl_getets - retrieve local ETS configuration
29 * @netdev: the relevant netdev
30 * @ets: struct to hold ETS configuration
32 static int ice_dcbnl_getets(struct net_device *netdev, struct ieee_ets *ets)
34 struct ice_dcbx_cfg *dcbxcfg;
37 pf = ice_netdev_to_pf(netdev);
38 dcbxcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
40 ets->willing = dcbxcfg->etscfg.willing;
41 ets->ets_cap = dcbxcfg->etscfg.maxtcs;
42 ets->cbs = dcbxcfg->etscfg.cbs;
43 memcpy(ets->tc_tx_bw, dcbxcfg->etscfg.tcbwtable, sizeof(ets->tc_tx_bw));
44 memcpy(ets->tc_rx_bw, dcbxcfg->etscfg.tcbwtable, sizeof(ets->tc_rx_bw));
45 memcpy(ets->tc_tsa, dcbxcfg->etscfg.tsatable, sizeof(ets->tc_tsa));
46 memcpy(ets->prio_tc, dcbxcfg->etscfg.prio_table, sizeof(ets->prio_tc));
47 memcpy(ets->tc_reco_bw, dcbxcfg->etsrec.tcbwtable,
48 sizeof(ets->tc_reco_bw));
49 memcpy(ets->tc_reco_tsa, dcbxcfg->etsrec.tsatable,
50 sizeof(ets->tc_reco_tsa));
51 memcpy(ets->reco_prio_tc, dcbxcfg->etscfg.prio_table,
52 sizeof(ets->reco_prio_tc));
58 * ice_dcbnl_setets - set IEEE ETS configuration
59 * @netdev: pointer to relevant netdev
60 * @ets: struct to hold ETS configuration
62 static int ice_dcbnl_setets(struct net_device *netdev, struct ieee_ets *ets)
64 struct ice_pf *pf = ice_netdev_to_pf(netdev);
65 struct ice_dcbx_cfg *new_cfg;
66 int bwcfg = 0, bwrec = 0;
69 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
70 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
73 if (pf->lag && pf->lag->bonded) {
74 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
78 new_cfg = &pf->hw.port_info->qos_cfg.desired_dcbx_cfg;
80 mutex_lock(&pf->tc_mutex);
82 new_cfg->etscfg.willing = ets->willing;
83 new_cfg->etscfg.cbs = ets->cbs;
84 ice_for_each_traffic_class(i) {
85 new_cfg->etscfg.tcbwtable[i] = ets->tc_tx_bw[i];
86 bwcfg += ets->tc_tx_bw[i];
87 new_cfg->etscfg.tsatable[i] = ets->tc_tsa[i];
88 if (new_cfg->pfc_mode == ICE_QOS_MODE_VLAN) {
89 /* in DSCP mode up->tc mapping cannot change */
90 new_cfg->etscfg.prio_table[i] = ets->prio_tc[i];
91 new_cfg->etsrec.prio_table[i] = ets->reco_prio_tc[i];
93 new_cfg->etsrec.tcbwtable[i] = ets->tc_reco_bw[i];
94 bwrec += ets->tc_reco_bw[i];
95 new_cfg->etsrec.tsatable[i] = ets->tc_reco_tsa[i];
98 if (ice_dcb_bwchk(pf, new_cfg)) {
103 new_cfg->etscfg.maxtcs = pf->hw.func_caps.common_cap.maxtc;
106 new_cfg->etscfg.tcbwtable[0] = 100;
109 new_cfg->etsrec.tcbwtable[0] = 100;
111 err = ice_pf_dcb_cfg(pf, new_cfg, true);
112 /* return of zero indicates new cfg applied */
113 if (err == ICE_DCB_HW_CHG_RST)
114 ice_dcbnl_devreset(netdev);
115 if (err == ICE_DCB_NO_HW_CHG)
116 err = ICE_DCB_HW_CHG_RST;
119 mutex_unlock(&pf->tc_mutex);
124 * ice_dcbnl_getnumtcs - Get max number of traffic classes supported
125 * @dev: pointer to netdev struct
127 * @num: total number of TCs supported by the adapter
129 * Return the total number of TCs supported
132 ice_dcbnl_getnumtcs(struct net_device *dev, int __always_unused tcid, u8 *num)
134 struct ice_pf *pf = ice_netdev_to_pf(dev);
136 if (!test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags))
139 *num = pf->hw.func_caps.common_cap.maxtc;
144 * ice_dcbnl_getdcbx - retrieve current DCBX capability
145 * @netdev: pointer to the netdev struct
147 static u8 ice_dcbnl_getdcbx(struct net_device *netdev)
149 struct ice_pf *pf = ice_netdev_to_pf(netdev);
155 * ice_dcbnl_setdcbx - set required DCBX capability
156 * @netdev: the corresponding netdev
157 * @mode: required mode
159 static u8 ice_dcbnl_setdcbx(struct net_device *netdev, u8 mode)
161 struct ice_pf *pf = ice_netdev_to_pf(netdev);
162 struct ice_qos_cfg *qos_cfg;
164 /* if FW LLDP agent is running, DCBNL not allowed to change mode */
165 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags))
166 return ICE_DCB_NO_HW_CHG;
168 /* No support for LLD_MANAGED modes or CEE+IEEE */
169 if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
170 ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
171 !(mode & DCB_CAP_DCBX_HOST))
172 return ICE_DCB_NO_HW_CHG;
174 /* Already set to the given mode no change */
175 if (mode == pf->dcbx_cap)
176 return ICE_DCB_NO_HW_CHG;
178 if (pf->lag && pf->lag->bonded) {
179 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
180 return ICE_DCB_NO_HW_CHG;
183 qos_cfg = &pf->hw.port_info->qos_cfg;
185 /* DSCP configuration is not DCBx negotiated */
186 if (qos_cfg->local_dcbx_cfg.pfc_mode == ICE_QOS_MODE_DSCP)
187 return ICE_DCB_NO_HW_CHG;
191 if (mode & DCB_CAP_DCBX_VER_CEE)
192 qos_cfg->local_dcbx_cfg.dcbx_mode = ICE_DCBX_MODE_CEE;
194 qos_cfg->local_dcbx_cfg.dcbx_mode = ICE_DCBX_MODE_IEEE;
196 dev_info(ice_pf_to_dev(pf), "DCBx mode = 0x%x\n", mode);
197 return ICE_DCB_HW_CHG_RST;
201 * ice_dcbnl_get_perm_hw_addr - MAC address used by DCBX
202 * @netdev: pointer to netdev struct
203 * @perm_addr: buffer to return permanent MAC address
205 static void ice_dcbnl_get_perm_hw_addr(struct net_device *netdev, u8 *perm_addr)
207 struct ice_pf *pf = ice_netdev_to_pf(netdev);
208 struct ice_port_info *pi = pf->hw.port_info;
211 memset(perm_addr, 0xff, MAX_ADDR_LEN);
213 for (i = 0; i < netdev->addr_len; i++)
214 perm_addr[i] = pi->mac.perm_addr[i];
216 for (j = 0; j < netdev->addr_len; j++, i++)
217 perm_addr[i] = pi->mac.perm_addr[j];
221 * ice_get_pfc_delay - Retrieve PFC Link Delay
222 * @hw: pointer to HW struct
223 * @delay: holds the PFC Link Delay value
225 static void ice_get_pfc_delay(struct ice_hw *hw, u16 *delay)
229 val = rd32(hw, PRTDCB_GENC);
230 *delay = FIELD_GET(PRTDCB_GENC_PFCLDA_M, val);
234 * ice_dcbnl_getpfc - retrieve local IEEE PFC config
235 * @netdev: pointer to netdev struct
236 * @pfc: struct to hold PFC info
238 static int ice_dcbnl_getpfc(struct net_device *netdev, struct ieee_pfc *pfc)
240 struct ice_pf *pf = ice_netdev_to_pf(netdev);
241 struct ice_port_info *pi = pf->hw.port_info;
242 struct ice_dcbx_cfg *dcbxcfg;
245 dcbxcfg = &pi->qos_cfg.local_dcbx_cfg;
246 pfc->pfc_cap = dcbxcfg->pfc.pfccap;
247 pfc->pfc_en = dcbxcfg->pfc.pfcena;
248 pfc->mbc = dcbxcfg->pfc.mbc;
249 ice_get_pfc_delay(&pf->hw, &pfc->delay);
251 ice_for_each_traffic_class(i) {
252 pfc->requests[i] = pf->stats.priority_xoff_tx[i];
253 pfc->indications[i] = pf->stats.priority_xoff_rx[i];
260 * ice_dcbnl_setpfc - set local IEEE PFC config
261 * @netdev: pointer to relevant netdev
262 * @pfc: pointer to struct holding PFC config
264 static int ice_dcbnl_setpfc(struct net_device *netdev, struct ieee_pfc *pfc)
266 struct ice_pf *pf = ice_netdev_to_pf(netdev);
267 struct ice_dcbx_cfg *new_cfg;
270 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
271 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
274 if (pf->lag && pf->lag->bonded) {
275 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
279 mutex_lock(&pf->tc_mutex);
281 new_cfg = &pf->hw.port_info->qos_cfg.desired_dcbx_cfg;
284 new_cfg->pfc.pfccap = pfc->pfc_cap;
286 new_cfg->pfc.pfccap = pf->hw.func_caps.common_cap.maxtc;
288 new_cfg->pfc.pfcena = pfc->pfc_en;
290 err = ice_pf_dcb_cfg(pf, new_cfg, true);
291 if (err == ICE_DCB_HW_CHG_RST)
292 ice_dcbnl_devreset(netdev);
293 if (err == ICE_DCB_NO_HW_CHG)
294 err = ICE_DCB_HW_CHG_RST;
295 mutex_unlock(&pf->tc_mutex);
300 * ice_dcbnl_get_pfc_cfg - Get CEE PFC config
301 * @netdev: pointer to netdev struct
302 * @prio: corresponding user priority
303 * @setting: the PFC setting for given priority
306 ice_dcbnl_get_pfc_cfg(struct net_device *netdev, int prio, u8 *setting)
308 struct ice_pf *pf = ice_netdev_to_pf(netdev);
309 struct ice_port_info *pi = pf->hw.port_info;
311 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
312 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
315 if (prio >= ICE_MAX_USER_PRIORITY)
318 *setting = (pi->qos_cfg.local_dcbx_cfg.pfc.pfcena >> prio) & 0x1;
319 dev_dbg(ice_pf_to_dev(pf), "Get PFC Config up=%d, setting=%d, pfcenable=0x%x\n",
320 prio, *setting, pi->qos_cfg.local_dcbx_cfg.pfc.pfcena);
324 * ice_dcbnl_set_pfc_cfg - Set CEE PFC config
325 * @netdev: the corresponding netdev
326 * @prio: User Priority
327 * @set: PFC setting to apply
329 static void ice_dcbnl_set_pfc_cfg(struct net_device *netdev, int prio, u8 set)
331 struct ice_pf *pf = ice_netdev_to_pf(netdev);
332 struct ice_dcbx_cfg *new_cfg;
334 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
335 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
338 if (prio >= ICE_MAX_USER_PRIORITY)
341 if (pf->lag && pf->lag->bonded) {
342 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
346 new_cfg = &pf->hw.port_info->qos_cfg.desired_dcbx_cfg;
348 new_cfg->pfc.pfccap = pf->hw.func_caps.common_cap.maxtc;
350 new_cfg->pfc.pfcena |= BIT(prio);
352 new_cfg->pfc.pfcena &= ~BIT(prio);
354 dev_dbg(ice_pf_to_dev(pf), "Set PFC config UP:%d set:%d pfcena:0x%x\n",
355 prio, set, new_cfg->pfc.pfcena);
359 * ice_dcbnl_getpfcstate - get CEE PFC mode
360 * @netdev: pointer to netdev struct
362 static u8 ice_dcbnl_getpfcstate(struct net_device *netdev)
364 struct ice_pf *pf = ice_netdev_to_pf(netdev);
365 struct ice_port_info *pi = pf->hw.port_info;
367 /* Return enabled if any UP enabled for PFC */
368 if (pi->qos_cfg.local_dcbx_cfg.pfc.pfcena)
375 * ice_dcbnl_getstate - get DCB enabled state
376 * @netdev: pointer to netdev struct
378 static u8 ice_dcbnl_getstate(struct net_device *netdev)
380 struct ice_pf *pf = ice_netdev_to_pf(netdev);
383 state = test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
385 dev_dbg(ice_pf_to_dev(pf), "DCB enabled state = %d\n", state);
390 * ice_dcbnl_setstate - Set CEE DCB state
391 * @netdev: pointer to relevant netdev
392 * @state: state value to set
394 static u8 ice_dcbnl_setstate(struct net_device *netdev, u8 state)
396 struct ice_pf *pf = ice_netdev_to_pf(netdev);
398 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
399 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
400 return ICE_DCB_NO_HW_CHG;
402 if (pf->lag && pf->lag->bonded) {
403 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
404 return ICE_DCB_NO_HW_CHG;
408 if (!!state == test_bit(ICE_FLAG_DCB_ENA, pf->flags))
409 return ICE_DCB_NO_HW_CHG;
412 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
413 memcpy(&pf->hw.port_info->qos_cfg.desired_dcbx_cfg,
414 &pf->hw.port_info->qos_cfg.local_dcbx_cfg,
415 sizeof(struct ice_dcbx_cfg));
417 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
420 return ICE_DCB_HW_CHG;
424 * ice_dcbnl_get_pg_tc_cfg_tx - get CEE PG Tx config
425 * @netdev: pointer to netdev struct
426 * @prio: the corresponding user priority
427 * @prio_type: traffic priority type
428 * @pgid: the BW group ID the traffic class belongs to
429 * @bw_pct: BW percentage for the corresponding BWG
430 * @up_map: prio mapped to corresponding TC
433 ice_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int prio,
434 u8 __always_unused *prio_type, u8 *pgid,
435 u8 __always_unused *bw_pct,
436 u8 __always_unused *up_map)
438 struct ice_pf *pf = ice_netdev_to_pf(netdev);
439 struct ice_port_info *pi = pf->hw.port_info;
441 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
442 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
445 if (prio >= ICE_MAX_USER_PRIORITY)
448 *pgid = pi->qos_cfg.local_dcbx_cfg.etscfg.prio_table[prio];
449 dev_dbg(ice_pf_to_dev(pf), "Get PG config prio=%d tc=%d\n", prio,
454 * ice_dcbnl_set_pg_tc_cfg_tx - set CEE PG Tx config
455 * @netdev: pointer to relevant netdev
456 * @tc: the corresponding traffic class
457 * @prio_type: the traffic priority type
458 * @bwg_id: the BW group ID the TC belongs to
459 * @bw_pct: the BW perventage for the BWG
460 * @up_map: prio mapped to corresponding TC
463 ice_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
464 u8 __always_unused prio_type,
465 u8 __always_unused bwg_id,
466 u8 __always_unused bw_pct, u8 up_map)
468 struct ice_pf *pf = ice_netdev_to_pf(netdev);
469 struct ice_dcbx_cfg *new_cfg;
472 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
473 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
476 if (tc >= ICE_MAX_TRAFFIC_CLASS)
479 if (pf->lag && pf->lag->bonded) {
480 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
484 new_cfg = &pf->hw.port_info->qos_cfg.desired_dcbx_cfg;
486 /* prio_type, bwg_id and bw_pct per UP are not supported */
488 ice_for_each_traffic_class(i) {
490 new_cfg->etscfg.prio_table[i] = tc;
492 new_cfg->etscfg.tsatable[tc] = ICE_IEEE_TSA_ETS;
496 * ice_dcbnl_get_pg_bwg_cfg_tx - Get CEE PGBW config
497 * @netdev: pointer to the netdev struct
498 * @pgid: corresponding traffic class
499 * @bw_pct: the BW percentage for the corresponding TC
502 ice_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int pgid, u8 *bw_pct)
504 struct ice_pf *pf = ice_netdev_to_pf(netdev);
505 struct ice_port_info *pi = pf->hw.port_info;
507 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
508 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
511 if (pgid >= ICE_MAX_TRAFFIC_CLASS)
514 *bw_pct = pi->qos_cfg.local_dcbx_cfg.etscfg.tcbwtable[pgid];
515 dev_dbg(ice_pf_to_dev(pf), "Get PG BW config tc=%d bw_pct=%d\n",
520 * ice_dcbnl_set_pg_bwg_cfg_tx - set CEE PG Tx BW config
521 * @netdev: the corresponding netdev
522 * @pgid: Correspongind traffic class
523 * @bw_pct: the BW percentage for the specified TC
526 ice_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int pgid, u8 bw_pct)
528 struct ice_pf *pf = ice_netdev_to_pf(netdev);
529 struct ice_dcbx_cfg *new_cfg;
531 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
532 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
535 if (pgid >= ICE_MAX_TRAFFIC_CLASS)
538 if (pf->lag && pf->lag->bonded) {
539 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
543 new_cfg = &pf->hw.port_info->qos_cfg.desired_dcbx_cfg;
545 new_cfg->etscfg.tcbwtable[pgid] = bw_pct;
549 * ice_dcbnl_get_pg_tc_cfg_rx - Get CEE PG Rx config
550 * @netdev: pointer to netdev struct
551 * @prio: the corresponding user priority
552 * @prio_type: the traffic priority type
554 * @bw_pct: the BW percentage for the corresponding BWG
555 * @up_map: prio mapped to corresponding TC
558 ice_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int prio,
559 u8 __always_unused *prio_type, u8 *pgid,
560 u8 __always_unused *bw_pct,
561 u8 __always_unused *up_map)
563 struct ice_pf *pf = ice_netdev_to_pf(netdev);
564 struct ice_port_info *pi = pf->hw.port_info;
566 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
567 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
570 if (prio >= ICE_MAX_USER_PRIORITY)
573 *pgid = pi->qos_cfg.local_dcbx_cfg.etscfg.prio_table[prio];
577 * ice_dcbnl_set_pg_tc_cfg_rx
578 * @netdev: relevant netdev struct
579 * @prio: corresponding user priority
580 * @prio_type: the traffic priority type
582 * @bw_pct: BW percentage for corresponding BWG
583 * @up_map: prio mapped to corresponding TC
585 * lldpad requires this function pointer to be non-NULL to complete CEE config.
588 ice_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev,
589 int __always_unused prio,
590 u8 __always_unused prio_type,
591 u8 __always_unused pgid,
592 u8 __always_unused bw_pct,
593 u8 __always_unused up_map)
595 struct ice_pf *pf = ice_netdev_to_pf(netdev);
597 dev_dbg(ice_pf_to_dev(pf), "Rx TC PG Config Not Supported.\n");
601 * ice_dcbnl_get_pg_bwg_cfg_rx - Get CEE PG BW Rx config
602 * @netdev: pointer to netdev struct
603 * @pgid: the corresponding traffic class
604 * @bw_pct: the BW percentage for the corresponding TC
607 ice_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int __always_unused pgid,
610 struct ice_pf *pf = ice_netdev_to_pf(netdev);
612 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
613 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
620 * ice_dcbnl_set_pg_bwg_cfg_rx
621 * @netdev: the corresponding netdev
622 * @pgid: corresponding TC
623 * @bw_pct: BW percentage for given TC
625 * lldpad requires this function pointer to be non-NULL to complete CEE config.
628 ice_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int __always_unused pgid,
629 u8 __always_unused bw_pct)
631 struct ice_pf *pf = ice_netdev_to_pf(netdev);
633 dev_dbg(ice_pf_to_dev(pf), "Rx BWG PG Config Not Supported.\n");
637 * ice_dcbnl_get_cap - Get DCBX capabilities of adapter
638 * @netdev: pointer to netdev struct
639 * @capid: the capability type
640 * @cap: the capability value
642 static u8 ice_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
644 struct ice_pf *pf = ice_netdev_to_pf(netdev);
646 if (!(test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags)))
647 return ICE_DCB_NO_HW_CHG;
650 case DCB_CAP_ATTR_PG:
653 case DCB_CAP_ATTR_PFC:
656 case DCB_CAP_ATTR_UP2TC:
659 case DCB_CAP_ATTR_PG_TCS:
662 case DCB_CAP_ATTR_PFC_TCS:
665 case DCB_CAP_ATTR_GSP:
668 case DCB_CAP_ATTR_BCN:
671 case DCB_CAP_ATTR_DCBX:
679 dev_dbg(ice_pf_to_dev(pf), "DCBX Get Capability cap=%d capval=0x%x\n",
685 * ice_dcbnl_getapp - get CEE APP
686 * @netdev: pointer to netdev struct
687 * @idtype: the App selector
688 * @id: the App ethtype or port number
690 static int ice_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
692 struct ice_pf *pf = ice_netdev_to_pf(netdev);
693 struct dcb_app app = {
698 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
699 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
702 return dcb_getapp(netdev, &app);
706 * ice_dcbnl_find_app - Search for APP in given DCB config
707 * @cfg: struct to hold DCBX config
708 * @app: struct to hold app data to look for
711 ice_dcbnl_find_app(struct ice_dcbx_cfg *cfg,
712 struct ice_dcb_app_priority_table *app)
716 for (i = 0; i < cfg->numapps; i++) {
717 if (app->selector == cfg->app[i].selector &&
718 app->prot_id == cfg->app[i].prot_id &&
719 app->priority == cfg->app[i].priority)
726 #define ICE_BYTES_PER_DSCP_VAL 8
729 * ice_dcbnl_setapp - set local IEEE App config
730 * @netdev: relevant netdev struct
731 * @app: struct to hold app config info
733 static int ice_dcbnl_setapp(struct net_device *netdev, struct dcb_app *app)
735 struct ice_pf *pf = ice_netdev_to_pf(netdev);
736 struct ice_dcb_app_priority_table new_app;
737 struct ice_dcbx_cfg *old_cfg, *new_cfg;
741 /* ONLY DSCP APP TLVs have operational significance */
742 if (app->selector != IEEE_8021QAZ_APP_SEL_DSCP)
745 /* only allow APP TLVs in SW Mode */
746 if (pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) {
747 netdev_err(netdev, "can't do DSCP QoS when FW DCB agent active\n");
751 if (!(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
754 if (!ice_is_feature_supported(pf, ICE_F_DSCP))
757 if (app->protocol >= ICE_DSCP_NUM_VAL) {
758 netdev_err(netdev, "DSCP value 0x%04X out of range\n",
763 if (pf->lag && pf->lag->bonded) {
764 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
768 max_tc = pf->hw.func_caps.common_cap.maxtc;
769 if (app->priority >= max_tc) {
770 netdev_err(netdev, "TC %d out of range, max TC %d\n",
771 app->priority, max_tc);
776 mutex_lock(&pf->tc_mutex);
778 new_cfg = &pf->hw.port_info->qos_cfg.desired_dcbx_cfg;
779 old_cfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
781 ret = dcb_ieee_setapp(netdev, app);
785 if (test_and_set_bit(app->protocol, new_cfg->dscp_mapped)) {
786 netdev_err(netdev, "DSCP value 0x%04X already user mapped\n",
788 ret = dcb_ieee_delapp(netdev, app);
790 netdev_err(netdev, "Failed to delete re-mapping TLV\n");
795 new_app.selector = app->selector;
796 new_app.prot_id = app->protocol;
797 new_app.priority = app->priority;
799 /* If port is not in DSCP mode, need to set */
800 if (old_cfg->pfc_mode == ICE_QOS_MODE_VLAN) {
804 ret = ice_aq_set_pfc_mode(&pf->hw, ICE_AQC_PFC_DSCP_BASED_PFC,
807 netdev_err(netdev, "Failed to set DSCP PFC mode %d\n",
811 netdev_info(netdev, "Switched QoS to L3 DSCP mode\n");
813 new_cfg->pfc_mode = ICE_QOS_MODE_DSCP;
815 /* set default DSCP QoS values */
816 new_cfg->etscfg.willing = 0;
817 new_cfg->pfc.pfccap = max_tc;
818 new_cfg->pfc.willing = 0;
820 for (i = 0; i < max_tc; i++)
821 for (j = 0; j < ICE_BYTES_PER_DSCP_VAL; j++) {
824 dscp = (i * max_tc) + j;
825 offset = max_tc * ICE_BYTES_PER_DSCP_VAL;
827 new_cfg->dscp_map[dscp] = i;
828 /* if less that 8 TCs supported */
829 if (max_tc < ICE_MAX_TRAFFIC_CLASS)
830 new_cfg->dscp_map[dscp + offset] = i;
833 new_cfg->etscfg.tcbwtable[0] = 100;
834 new_cfg->etscfg.tsatable[0] = ICE_IEEE_TSA_ETS;
835 new_cfg->etscfg.prio_table[0] = 0;
837 for (i = 1; i < max_tc; i++) {
838 new_cfg->etscfg.tcbwtable[i] = 0;
839 new_cfg->etscfg.tsatable[i] = ICE_IEEE_TSA_ETS;
840 new_cfg->etscfg.prio_table[i] = i;
842 } /* end of switching to DSCP mode */
844 /* apply new mapping for this DSCP value */
845 new_cfg->dscp_map[app->protocol] = app->priority;
846 new_cfg->app[new_cfg->numapps++] = new_app;
848 ret = ice_pf_dcb_cfg(pf, new_cfg, true);
849 /* return of zero indicates new cfg applied */
850 if (ret == ICE_DCB_HW_CHG_RST)
851 ice_dcbnl_devreset(netdev);
853 ret = ICE_DCB_NO_HW_CHG;
856 mutex_unlock(&pf->tc_mutex);
861 * ice_dcbnl_delapp - Delete local IEEE App config
862 * @netdev: relevant netdev
863 * @app: struct to hold app too delete
865 * Will not delete first application required by the FW
867 static int ice_dcbnl_delapp(struct net_device *netdev, struct dcb_app *app)
869 struct ice_pf *pf = ice_netdev_to_pf(netdev);
870 struct ice_dcbx_cfg *old_cfg, *new_cfg;
874 if (pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) {
875 netdev_err(netdev, "can't delete DSCP netlink app when FW DCB agent is active\n");
879 if (pf->lag && pf->lag->bonded) {
880 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
884 mutex_lock(&pf->tc_mutex);
885 old_cfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
887 ret = dcb_ieee_delapp(netdev, app);
891 new_cfg = &pf->hw.port_info->qos_cfg.desired_dcbx_cfg;
893 for (i = 0; i < new_cfg->numapps; i++) {
894 if (app->selector == new_cfg->app[i].selector &&
895 app->protocol == new_cfg->app[i].prot_id &&
896 app->priority == new_cfg->app[i].priority) {
897 new_cfg->app[i].selector = 0;
898 new_cfg->app[i].prot_id = 0;
899 new_cfg->app[i].priority = 0;
904 /* Did not find DCB App */
905 if (i == new_cfg->numapps) {
912 for (j = i; j < new_cfg->numapps; j++) {
913 new_cfg->app[j].selector = old_cfg->app[j + 1].selector;
914 new_cfg->app[j].prot_id = old_cfg->app[j + 1].prot_id;
915 new_cfg->app[j].priority = old_cfg->app[j + 1].priority;
918 /* if not a DSCP APP TLV or DSCP is not supported, we are done */
919 if (app->selector != IEEE_8021QAZ_APP_SEL_DSCP ||
920 !ice_is_feature_supported(pf, ICE_F_DSCP)) {
921 ret = ICE_DCB_HW_CHG;
925 /* if DSCP TLV, then need to address change in mapping */
926 clear_bit(app->protocol, new_cfg->dscp_mapped);
927 /* remap this DSCP value to default value */
928 new_cfg->dscp_map[app->protocol] = app->protocol %
929 ICE_BYTES_PER_DSCP_VAL;
931 /* if the last DSCP mapping just got deleted, need to switch
932 * to L2 VLAN QoS mode
934 if (bitmap_empty(new_cfg->dscp_mapped, ICE_DSCP_NUM_VAL) &&
935 new_cfg->pfc_mode == ICE_QOS_MODE_DSCP) {
936 ret = ice_aq_set_pfc_mode(&pf->hw,
937 ICE_AQC_PFC_VLAN_BASED_PFC,
940 netdev_info(netdev, "Failed to set VLAN PFC mode %d\n",
944 netdev_info(netdev, "Switched QoS to L2 VLAN mode\n");
946 new_cfg->pfc_mode = ICE_QOS_MODE_VLAN;
948 ret = ice_dcb_sw_dflt_cfg(pf, true, true);
950 ret = ice_pf_dcb_cfg(pf, new_cfg, true);
953 /* return of ICE_DCB_HW_CHG_RST indicates new cfg applied
954 * and reset needs to be performed
956 if (ret == ICE_DCB_HW_CHG_RST)
957 ice_dcbnl_devreset(netdev);
959 /* if the change was not siginificant enough to actually call
960 * the reconfiguration flow, we still need to tell caller that
961 * their request was successfully handled
963 if (ret == ICE_DCB_NO_HW_CHG)
964 ret = ICE_DCB_HW_CHG;
967 mutex_unlock(&pf->tc_mutex);
972 * ice_dcbnl_cee_set_all - Commit CEE DCB settings to HW
973 * @netdev: the corresponding netdev
975 static u8 ice_dcbnl_cee_set_all(struct net_device *netdev)
977 struct ice_pf *pf = ice_netdev_to_pf(netdev);
978 struct ice_dcbx_cfg *new_cfg;
981 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
982 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
983 return ICE_DCB_NO_HW_CHG;
985 if (pf->lag && pf->lag->bonded) {
986 netdev_err(netdev, "DCB changes not allowed when in a bond\n");
987 return ICE_DCB_NO_HW_CHG;
990 new_cfg = &pf->hw.port_info->qos_cfg.desired_dcbx_cfg;
992 mutex_lock(&pf->tc_mutex);
994 err = ice_pf_dcb_cfg(pf, new_cfg, true);
996 mutex_unlock(&pf->tc_mutex);
997 return (err != ICE_DCB_HW_CHG_RST) ? ICE_DCB_NO_HW_CHG : err;
1000 static const struct dcbnl_rtnl_ops dcbnl_ops = {
1001 /* IEEE 802.1Qaz std */
1002 .ieee_getets = ice_dcbnl_getets,
1003 .ieee_setets = ice_dcbnl_setets,
1004 .ieee_getpfc = ice_dcbnl_getpfc,
1005 .ieee_setpfc = ice_dcbnl_setpfc,
1006 .ieee_setapp = ice_dcbnl_setapp,
1007 .ieee_delapp = ice_dcbnl_delapp,
1010 .getstate = ice_dcbnl_getstate,
1011 .setstate = ice_dcbnl_setstate,
1012 .getpermhwaddr = ice_dcbnl_get_perm_hw_addr,
1013 .setpgtccfgtx = ice_dcbnl_set_pg_tc_cfg_tx,
1014 .setpgbwgcfgtx = ice_dcbnl_set_pg_bwg_cfg_tx,
1015 .setpgtccfgrx = ice_dcbnl_set_pg_tc_cfg_rx,
1016 .setpgbwgcfgrx = ice_dcbnl_set_pg_bwg_cfg_rx,
1017 .getpgtccfgtx = ice_dcbnl_get_pg_tc_cfg_tx,
1018 .getpgbwgcfgtx = ice_dcbnl_get_pg_bwg_cfg_tx,
1019 .getpgtccfgrx = ice_dcbnl_get_pg_tc_cfg_rx,
1020 .getpgbwgcfgrx = ice_dcbnl_get_pg_bwg_cfg_rx,
1021 .setpfccfg = ice_dcbnl_set_pfc_cfg,
1022 .getpfccfg = ice_dcbnl_get_pfc_cfg,
1023 .setall = ice_dcbnl_cee_set_all,
1024 .getcap = ice_dcbnl_get_cap,
1025 .getnumtcs = ice_dcbnl_getnumtcs,
1026 .getpfcstate = ice_dcbnl_getpfcstate,
1027 .getapp = ice_dcbnl_getapp,
1029 /* DCBX configuration */
1030 .getdcbx = ice_dcbnl_getdcbx,
1031 .setdcbx = ice_dcbnl_setdcbx,
1035 * ice_dcbnl_set_all - set all the apps and ieee data from DCBX config
1036 * @vsi: pointer to VSI struct
1038 void ice_dcbnl_set_all(struct ice_vsi *vsi)
1040 struct net_device *netdev = vsi->netdev;
1041 struct ice_dcbx_cfg *dcbxcfg;
1042 struct ice_port_info *pi;
1043 struct dcb_app sapp;
1050 pf = ice_netdev_to_pf(netdev);
1051 pi = pf->hw.port_info;
1053 /* SW DCB taken care of by SW Default Config */
1054 if (pf->dcbx_cap & DCB_CAP_DCBX_HOST)
1057 /* DCB not enabled */
1058 if (!test_bit(ICE_FLAG_DCB_ENA, pf->flags))
1061 dcbxcfg = &pi->qos_cfg.local_dcbx_cfg;
1063 for (i = 0; i < dcbxcfg->numapps; i++) {
1066 prio = dcbxcfg->app[i].priority;
1067 tc_map = BIT(dcbxcfg->etscfg.prio_table[prio]);
1069 /* Add APP only if the TC is enabled for this VSI */
1070 if (tc_map & vsi->tc_cfg.ena_tc) {
1071 sapp.selector = dcbxcfg->app[i].selector;
1072 sapp.protocol = dcbxcfg->app[i].prot_id;
1073 sapp.priority = prio;
1074 dcb_ieee_setapp(netdev, &sapp);
1077 /* Notify user-space of the changes */
1078 dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, 0, 0);
1082 * ice_dcbnl_vsi_del_app - Delete APP on all VSIs
1083 * @vsi: pointer to the main VSI
1084 * @app: APP to delete
1086 * Delete given APP from all the VSIs for given PF
1089 ice_dcbnl_vsi_del_app(struct ice_vsi *vsi,
1090 struct ice_dcb_app_priority_table *app)
1092 struct dcb_app sapp;
1095 sapp.selector = app->selector;
1096 sapp.protocol = app->prot_id;
1097 sapp.priority = app->priority;
1098 err = ice_dcbnl_delapp(vsi->netdev, &sapp);
1099 dev_dbg(ice_pf_to_dev(vsi->back), "Deleting app for VSI idx=%d err=%d sel=%d proto=0x%x, prio=%d\n",
1100 vsi->idx, err, app->selector, app->prot_id, app->priority);
1104 * ice_dcbnl_flush_apps - Delete all removed APPs
1105 * @pf: the corresponding PF
1106 * @old_cfg: old DCBX configuration data
1107 * @new_cfg: new DCBX configuration data
1109 * Find and delete all APPS that are not present in the passed
1113 ice_dcbnl_flush_apps(struct ice_pf *pf, struct ice_dcbx_cfg *old_cfg,
1114 struct ice_dcbx_cfg *new_cfg)
1116 struct ice_vsi *main_vsi = ice_get_main_vsi(pf);
1122 for (i = 0; i < old_cfg->numapps; i++) {
1123 struct ice_dcb_app_priority_table app = old_cfg->app[i];
1125 /* The APP is not available anymore delete it */
1126 if (!ice_dcbnl_find_app(new_cfg, &app))
1127 ice_dcbnl_vsi_del_app(main_vsi, &app);
1132 * ice_dcbnl_setup - setup DCBNL
1133 * @vsi: VSI to get associated netdev from
1135 void ice_dcbnl_setup(struct ice_vsi *vsi)
1137 struct net_device *netdev = vsi->netdev;
1140 pf = ice_netdev_to_pf(netdev);
1141 if (!test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags))
1144 netdev->dcbnl_ops = &dcbnl_ops;
1145 ice_dcbnl_set_all(vsi);