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"
10 #define ICE_APP_PROT_ID_ROCE 0x8915
13 * ice_dcbnl_devreset - perform enough of a ifdown/ifup to sync DCBNL info
14 * @netdev: device associated with interface that needs reset
16 static void ice_dcbnl_devreset(struct net_device *netdev)
18 struct ice_pf *pf = ice_netdev_to_pf(netdev);
20 while (ice_is_reset_in_progress(pf->state))
21 usleep_range(1000, 2000);
23 set_bit(__ICE_DCBNL_DEVRESET, pf->state);
25 netdev_state_change(netdev);
26 dev_open(netdev, NULL);
27 netdev_state_change(netdev);
28 clear_bit(__ICE_DCBNL_DEVRESET, pf->state);
32 * ice_dcbnl_getets - retrieve local ETS configuration
33 * @netdev: the relevant netdev
34 * @ets: struct to hold ETS configuration
36 static int ice_dcbnl_getets(struct net_device *netdev, struct ieee_ets *ets)
38 struct ice_dcbx_cfg *dcbxcfg;
39 struct ice_port_info *pi;
42 pf = ice_netdev_to_pf(netdev);
43 pi = pf->hw.port_info;
44 dcbxcfg = &pi->local_dcbx_cfg;
46 ets->willing = dcbxcfg->etscfg.willing;
47 ets->ets_cap = dcbxcfg->etscfg.maxtcs;
48 ets->cbs = dcbxcfg->etscfg.cbs;
49 memcpy(ets->tc_tx_bw, dcbxcfg->etscfg.tcbwtable, sizeof(ets->tc_tx_bw));
50 memcpy(ets->tc_rx_bw, dcbxcfg->etscfg.tcbwtable, sizeof(ets->tc_rx_bw));
51 memcpy(ets->tc_tsa, dcbxcfg->etscfg.tsatable, sizeof(ets->tc_tsa));
52 memcpy(ets->prio_tc, dcbxcfg->etscfg.prio_table, sizeof(ets->prio_tc));
53 memcpy(ets->tc_reco_bw, dcbxcfg->etsrec.tcbwtable,
54 sizeof(ets->tc_reco_bw));
55 memcpy(ets->tc_reco_tsa, dcbxcfg->etsrec.tsatable,
56 sizeof(ets->tc_reco_tsa));
57 memcpy(ets->reco_prio_tc, dcbxcfg->etscfg.prio_table,
58 sizeof(ets->reco_prio_tc));
64 * ice_dcbnl_setets - set IEEE ETS configuration
65 * @netdev: pointer to relevant netdev
66 * @ets: struct to hold ETS configuration
68 static int ice_dcbnl_setets(struct net_device *netdev, struct ieee_ets *ets)
70 struct ice_pf *pf = ice_netdev_to_pf(netdev);
71 struct ice_dcbx_cfg *new_cfg;
72 int bwcfg = 0, bwrec = 0;
73 int err, i, max_tc = 0;
75 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
76 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
79 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
81 mutex_lock(&pf->tc_mutex);
83 new_cfg->etscfg.willing = ets->willing;
84 new_cfg->etscfg.cbs = ets->cbs;
85 ice_for_each_traffic_class(i) {
86 new_cfg->etscfg.tcbwtable[i] = ets->tc_tx_bw[i];
87 bwcfg += ets->tc_tx_bw[i];
88 new_cfg->etscfg.tsatable[i] = ets->tc_tsa[i];
89 new_cfg->etscfg.prio_table[i] = ets->prio_tc[i];
90 if (ets->prio_tc[i] > max_tc)
91 max_tc = ets->prio_tc[i];
92 new_cfg->etsrec.tcbwtable[i] = ets->tc_reco_bw[i];
93 bwrec += ets->tc_reco_bw[i];
94 new_cfg->etsrec.tsatable[i] = ets->tc_reco_tsa[i];
95 new_cfg->etsrec.prio_table[i] = ets->reco_prio_tc[i];
98 /* max_tc is a 1-8 value count of number of TC's, not a 0-7 value
99 * for the TC's index number. Add one to value if not zero, and
100 * for zero set it to the FW's default value
105 max_tc = IEEE_8021QAZ_MAX_TCS;
107 new_cfg->etscfg.maxtcs = max_tc;
110 new_cfg->etscfg.tcbwtable[0] = 100;
113 new_cfg->etsrec.tcbwtable[0] = 100;
115 err = ice_pf_dcb_cfg(pf, new_cfg, true);
116 /* return of zero indicates new cfg applied */
117 if (err == ICE_DCB_HW_CHG_RST)
118 ice_dcbnl_devreset(netdev);
119 if (err == ICE_DCB_NO_HW_CHG)
120 err = ICE_DCB_HW_CHG_RST;
122 mutex_unlock(&pf->tc_mutex);
127 * ice_dcbnl_getnumtcs - Get max number of traffic classes supported
128 * @dev: pointer to netdev struct
130 * @num: total number of TCs supported by the adapter
132 * Return the total number of TCs supported
135 ice_dcbnl_getnumtcs(struct net_device *dev, int __always_unused tcid, u8 *num)
137 struct ice_pf *pf = ice_netdev_to_pf(dev);
139 if (!test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags))
142 *num = IEEE_8021QAZ_MAX_TCS;
147 * ice_dcbnl_getdcbx - retrieve current DCBX capability
148 * @netdev: pointer to the netdev struct
150 static u8 ice_dcbnl_getdcbx(struct net_device *netdev)
152 struct ice_pf *pf = ice_netdev_to_pf(netdev);
158 * ice_dcbnl_setdcbx - set required DCBX capability
159 * @netdev: the corresponding netdev
160 * @mode: required mode
162 static u8 ice_dcbnl_setdcbx(struct net_device *netdev, u8 mode)
164 struct ice_pf *pf = ice_netdev_to_pf(netdev);
166 /* No support for LLD_MANAGED modes or CEE+IEEE */
167 if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
168 ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
169 !(mode & DCB_CAP_DCBX_HOST))
170 return ICE_DCB_NO_HW_CHG;
172 /* Already set to the given mode no change */
173 if (mode == pf->dcbx_cap)
174 return ICE_DCB_NO_HW_CHG;
177 if (mode & DCB_CAP_DCBX_VER_CEE)
178 pf->hw.port_info->local_dcbx_cfg.dcbx_mode = ICE_DCBX_MODE_CEE;
180 pf->hw.port_info->local_dcbx_cfg.dcbx_mode = ICE_DCBX_MODE_IEEE;
182 dev_info(ice_pf_to_dev(pf), "DCBx mode = 0x%x\n", mode);
183 return ICE_DCB_HW_CHG_RST;
187 * ice_dcbnl_get_perm_hw_addr - MAC address used by DCBX
188 * @netdev: pointer to netdev struct
189 * @perm_addr: buffer to return permanent MAC address
191 static void ice_dcbnl_get_perm_hw_addr(struct net_device *netdev, u8 *perm_addr)
193 struct ice_pf *pf = ice_netdev_to_pf(netdev);
194 struct ice_port_info *pi = pf->hw.port_info;
197 memset(perm_addr, 0xff, MAX_ADDR_LEN);
199 for (i = 0; i < netdev->addr_len; i++)
200 perm_addr[i] = pi->mac.perm_addr[i];
202 for (j = 0; j < netdev->addr_len; j++, i++)
203 perm_addr[i] = pi->mac.perm_addr[j];
207 * ice_get_pfc_delay - Retrieve PFC Link Delay
208 * @hw: pointer to HW struct
209 * @delay: holds the PFC Link Delay value
211 static void ice_get_pfc_delay(struct ice_hw *hw, u16 *delay)
215 val = rd32(hw, PRTDCB_GENC);
216 *delay = (u16)((val & PRTDCB_GENC_PFCLDA_M) >> PRTDCB_GENC_PFCLDA_S);
220 * ice_dcbnl_getpfc - retrieve local IEEE PFC config
221 * @netdev: pointer to netdev struct
222 * @pfc: struct to hold PFC info
224 static int ice_dcbnl_getpfc(struct net_device *netdev, struct ieee_pfc *pfc)
226 struct ice_pf *pf = ice_netdev_to_pf(netdev);
227 struct ice_port_info *pi = pf->hw.port_info;
228 struct ice_dcbx_cfg *dcbxcfg;
231 dcbxcfg = &pi->local_dcbx_cfg;
232 pfc->pfc_cap = dcbxcfg->pfc.pfccap;
233 pfc->pfc_en = dcbxcfg->pfc.pfcena;
234 pfc->mbc = dcbxcfg->pfc.mbc;
235 ice_get_pfc_delay(&pf->hw, &pfc->delay);
237 ice_for_each_traffic_class(i) {
238 pfc->requests[i] = pf->stats.priority_xoff_tx[i];
239 pfc->indications[i] = pf->stats.priority_xoff_rx[i];
246 * ice_dcbnl_setpfc - set local IEEE PFC config
247 * @netdev: pointer to relevant netdev
248 * @pfc: pointer to struct holding PFC config
250 static int ice_dcbnl_setpfc(struct net_device *netdev, struct ieee_pfc *pfc)
252 struct ice_pf *pf = ice_netdev_to_pf(netdev);
253 struct ice_dcbx_cfg *new_cfg;
256 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
257 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
260 mutex_lock(&pf->tc_mutex);
262 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
265 new_cfg->pfc.pfccap = pfc->pfc_cap;
267 new_cfg->pfc.pfccap = pf->hw.func_caps.common_cap.maxtc;
269 new_cfg->pfc.pfcena = pfc->pfc_en;
271 err = ice_pf_dcb_cfg(pf, new_cfg, true);
272 if (err == ICE_DCB_HW_CHG_RST)
273 ice_dcbnl_devreset(netdev);
274 if (err == ICE_DCB_NO_HW_CHG)
275 err = ICE_DCB_HW_CHG_RST;
276 mutex_unlock(&pf->tc_mutex);
281 * ice_dcbnl_get_pfc_cfg - Get CEE PFC config
282 * @netdev: pointer to netdev struct
283 * @prio: corresponding user priority
284 * @setting: the PFC setting for given priority
287 ice_dcbnl_get_pfc_cfg(struct net_device *netdev, int prio, u8 *setting)
289 struct ice_pf *pf = ice_netdev_to_pf(netdev);
290 struct ice_port_info *pi = pf->hw.port_info;
292 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
293 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
296 if (prio >= ICE_MAX_USER_PRIORITY)
299 *setting = (pi->local_dcbx_cfg.pfc.pfcena >> prio) & 0x1;
300 dev_dbg(ice_pf_to_dev(pf),
301 "Get PFC Config up=%d, setting=%d, pfcenable=0x%x\n",
302 prio, *setting, pi->local_dcbx_cfg.pfc.pfcena);
306 * ice_dcbnl_set_pfc_cfg - Set CEE PFC config
307 * @netdev: the corresponding netdev
308 * @prio: User Priority
309 * @set: PFC setting to apply
311 static void ice_dcbnl_set_pfc_cfg(struct net_device *netdev, int prio, u8 set)
313 struct ice_pf *pf = ice_netdev_to_pf(netdev);
314 struct ice_dcbx_cfg *new_cfg;
316 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
317 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
320 if (prio >= ICE_MAX_USER_PRIORITY)
323 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
325 new_cfg->pfc.pfccap = pf->hw.func_caps.common_cap.maxtc;
327 new_cfg->pfc.pfcena |= BIT(prio);
329 new_cfg->pfc.pfcena &= ~BIT(prio);
331 dev_dbg(ice_pf_to_dev(pf), "Set PFC config UP:%d set:%d pfcena:0x%x\n",
332 prio, set, new_cfg->pfc.pfcena);
336 * ice_dcbnl_getpfcstate - get CEE PFC mode
337 * @netdev: pointer to netdev struct
339 static u8 ice_dcbnl_getpfcstate(struct net_device *netdev)
341 struct ice_pf *pf = ice_netdev_to_pf(netdev);
342 struct ice_port_info *pi = pf->hw.port_info;
344 /* Return enabled if any UP enabled for PFC */
345 if (pi->local_dcbx_cfg.pfc.pfcena)
352 * ice_dcbnl_getstate - get DCB enabled state
353 * @netdev: pointer to netdev struct
355 static u8 ice_dcbnl_getstate(struct net_device *netdev)
357 struct ice_pf *pf = ice_netdev_to_pf(netdev);
360 state = test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
362 dev_dbg(ice_pf_to_dev(pf), "DCB enabled state = %d\n", state);
367 * ice_dcbnl_setstate - Set CEE DCB state
368 * @netdev: pointer to relevant netdev
369 * @state: state value to set
371 static u8 ice_dcbnl_setstate(struct net_device *netdev, u8 state)
373 struct ice_pf *pf = ice_netdev_to_pf(netdev);
375 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
376 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
377 return ICE_DCB_NO_HW_CHG;
380 if (!!state == test_bit(ICE_FLAG_DCB_ENA, pf->flags))
381 return ICE_DCB_NO_HW_CHG;
384 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
385 memcpy(&pf->hw.port_info->desired_dcbx_cfg,
386 &pf->hw.port_info->local_dcbx_cfg,
387 sizeof(struct ice_dcbx_cfg));
389 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
392 return ICE_DCB_HW_CHG;
396 * ice_dcbnl_get_pg_tc_cfg_tx - get CEE PG Tx config
397 * @netdev: pointer to netdev struct
398 * @prio: the corresponding user priority
399 * @prio_type: traffic priority type
400 * @pgid: the BW group ID the traffic class belongs to
401 * @bw_pct: BW percentage for the corresponding BWG
402 * @up_map: prio mapped to corresponding TC
405 ice_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int prio,
406 u8 __always_unused *prio_type, u8 *pgid,
407 u8 __always_unused *bw_pct,
408 u8 __always_unused *up_map)
410 struct ice_pf *pf = ice_netdev_to_pf(netdev);
411 struct ice_port_info *pi = pf->hw.port_info;
413 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
414 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
417 if (prio >= ICE_MAX_USER_PRIORITY)
420 *pgid = pi->local_dcbx_cfg.etscfg.prio_table[prio];
421 dev_dbg(ice_pf_to_dev(pf),
422 "Get PG config prio=%d tc=%d\n", prio, *pgid);
426 * ice_dcbnl_set_pg_tc_cfg_tx - set CEE PG Tx config
427 * @netdev: pointer to relevant netdev
428 * @tc: the corresponding traffic class
429 * @prio_type: the traffic priority type
430 * @bwg_id: the BW group ID the TC belongs to
431 * @bw_pct: the BW perventage for the BWG
432 * @up_map: prio mapped to corresponding TC
435 ice_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
436 u8 __always_unused prio_type,
437 u8 __always_unused bwg_id,
438 u8 __always_unused bw_pct, u8 up_map)
440 struct ice_pf *pf = ice_netdev_to_pf(netdev);
441 struct ice_dcbx_cfg *new_cfg;
444 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
445 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
448 if (tc >= ICE_MAX_TRAFFIC_CLASS)
451 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
453 /* prio_type, bwg_id and bw_pct per UP are not supported */
455 ice_for_each_traffic_class(i) {
457 new_cfg->etscfg.prio_table[i] = tc;
459 new_cfg->etscfg.tsatable[tc] = ICE_IEEE_TSA_ETS;
463 * ice_dcbnl_get_pg_bwg_cfg_tx - Get CEE PGBW config
464 * @netdev: pointer to the netdev struct
465 * @pgid: corresponding traffic class
466 * @bw_pct: the BW percentage for the corresponding TC
469 ice_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int pgid, u8 *bw_pct)
471 struct ice_pf *pf = ice_netdev_to_pf(netdev);
472 struct ice_port_info *pi = pf->hw.port_info;
474 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
475 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
478 if (pgid >= ICE_MAX_TRAFFIC_CLASS)
481 *bw_pct = pi->local_dcbx_cfg.etscfg.tcbwtable[pgid];
482 dev_dbg(ice_pf_to_dev(pf), "Get PG BW config tc=%d bw_pct=%d\n",
487 * ice_dcbnl_set_pg_bwg_cfg_tx - set CEE PG Tx BW config
488 * @netdev: the corresponding netdev
489 * @pgid: Correspongind traffic class
490 * @bw_pct: the BW percentage for the specified TC
493 ice_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int pgid, u8 bw_pct)
495 struct ice_pf *pf = ice_netdev_to_pf(netdev);
496 struct ice_dcbx_cfg *new_cfg;
498 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
499 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
502 if (pgid >= ICE_MAX_TRAFFIC_CLASS)
505 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
507 new_cfg->etscfg.tcbwtable[pgid] = bw_pct;
511 * ice_dcbnl_get_pg_tc_cfg_rx - Get CEE PG Rx config
512 * @netdev: pointer to netdev struct
513 * @prio: the corresponding user priority
514 * @prio_type: the traffic priority type
516 * @bw_pct: the BW percentage for the corresponding BWG
517 * @up_map: prio mapped to corresponding TC
520 ice_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int prio,
521 u8 __always_unused *prio_type, u8 *pgid,
522 u8 __always_unused *bw_pct,
523 u8 __always_unused *up_map)
525 struct ice_pf *pf = ice_netdev_to_pf(netdev);
526 struct ice_port_info *pi = pf->hw.port_info;
528 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
529 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
532 if (prio >= ICE_MAX_USER_PRIORITY)
535 *pgid = pi->local_dcbx_cfg.etscfg.prio_table[prio];
539 * ice_dcbnl_get_pg_bwg_cfg_rx - Get CEE PG BW Rx config
540 * @netdev: pointer to netdev struct
541 * @pgid: the corresponding traffic class
542 * @bw_pct: the BW percentage for the corresponding TC
545 ice_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int __always_unused pgid,
548 struct ice_pf *pf = ice_netdev_to_pf(netdev);
550 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
551 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
558 * ice_dcbnl_get_cap - Get DCBX capabilities of adapter
559 * @netdev: pointer to netdev struct
560 * @capid: the capability type
561 * @cap: the capability value
563 static u8 ice_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
565 struct ice_pf *pf = ice_netdev_to_pf(netdev);
567 if (!(test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags)))
568 return ICE_DCB_NO_HW_CHG;
571 case DCB_CAP_ATTR_PG:
574 case DCB_CAP_ATTR_PFC:
577 case DCB_CAP_ATTR_UP2TC:
580 case DCB_CAP_ATTR_PG_TCS:
583 case DCB_CAP_ATTR_PFC_TCS:
586 case DCB_CAP_ATTR_GSP:
589 case DCB_CAP_ATTR_BCN:
592 case DCB_CAP_ATTR_DCBX:
600 dev_dbg(ice_pf_to_dev(pf), "DCBX Get Capability cap=%d capval=0x%x\n",
606 * ice_dcbnl_getapp - get CEE APP
607 * @netdev: pointer to netdev struct
608 * @idtype: the App selector
609 * @id: the App ethtype or port number
611 static int ice_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
613 struct ice_pf *pf = ice_netdev_to_pf(netdev);
614 struct dcb_app app = {
619 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
620 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
623 return dcb_getapp(netdev, &app);
627 * ice_dcbnl_find_app - Search for APP in given DCB config
628 * @cfg: struct to hold DCBX config
629 * @app: struct to hold app data to look for
632 ice_dcbnl_find_app(struct ice_dcbx_cfg *cfg,
633 struct ice_dcb_app_priority_table *app)
637 for (i = 0; i < cfg->numapps; i++) {
638 if (app->selector == cfg->app[i].selector &&
639 app->prot_id == cfg->app[i].prot_id &&
640 app->priority == cfg->app[i].priority)
648 * ice_dcbnl_setapp - set local IEEE App config
649 * @netdev: relevant netdev struct
650 * @app: struct to hold app config info
652 static int ice_dcbnl_setapp(struct net_device *netdev, struct dcb_app *app)
654 struct ice_pf *pf = ice_netdev_to_pf(netdev);
655 struct ice_dcb_app_priority_table new_app;
656 struct ice_dcbx_cfg *old_cfg, *new_cfg;
659 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
660 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
663 mutex_lock(&pf->tc_mutex);
665 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
667 old_cfg = &pf->hw.port_info->local_dcbx_cfg;
669 if (old_cfg->numapps == ICE_DCBX_MAX_APPS) {
674 ret = dcb_ieee_setapp(netdev, app);
678 new_app.selector = app->selector;
679 new_app.prot_id = app->protocol;
680 new_app.priority = app->priority;
681 if (ice_dcbnl_find_app(old_cfg, &new_app)) {
686 new_cfg->app[new_cfg->numapps++] = new_app;
687 ret = ice_pf_dcb_cfg(pf, new_cfg, true);
688 /* return of zero indicates new cfg applied */
689 if (ret == ICE_DCB_HW_CHG_RST)
690 ice_dcbnl_devreset(netdev);
691 if (ret == ICE_DCB_NO_HW_CHG)
692 ret = ICE_DCB_HW_CHG_RST;
695 mutex_unlock(&pf->tc_mutex);
700 * ice_dcbnl_delapp - Delete local IEEE App config
701 * @netdev: relevant netdev
702 * @app: struct to hold app too delete
704 * Will not delete first application required by the FW
706 static int ice_dcbnl_delapp(struct net_device *netdev, struct dcb_app *app)
708 struct ice_pf *pf = ice_netdev_to_pf(netdev);
709 struct ice_dcbx_cfg *old_cfg, *new_cfg;
712 if (pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED)
715 mutex_lock(&pf->tc_mutex);
716 ret = dcb_ieee_delapp(netdev, app);
720 old_cfg = &pf->hw.port_info->local_dcbx_cfg;
722 if (old_cfg->numapps == 1)
725 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
727 for (i = 1; i < new_cfg->numapps; i++) {
728 if (app->selector == new_cfg->app[i].selector &&
729 app->protocol == new_cfg->app[i].prot_id &&
730 app->priority == new_cfg->app[i].priority) {
731 new_cfg->app[i].selector = 0;
732 new_cfg->app[i].prot_id = 0;
733 new_cfg->app[i].priority = 0;
738 /* Did not find DCB App */
739 if (i == new_cfg->numapps) {
746 for (j = i; j < new_cfg->numapps; j++) {
747 new_cfg->app[i].selector = old_cfg->app[j + 1].selector;
748 new_cfg->app[i].prot_id = old_cfg->app[j + 1].prot_id;
749 new_cfg->app[i].priority = old_cfg->app[j + 1].priority;
752 ret = ice_pf_dcb_cfg(pf, new_cfg, true);
753 /* return of zero indicates new cfg applied */
754 if (ret == ICE_DCB_HW_CHG_RST)
755 ice_dcbnl_devreset(netdev);
756 if (ret == ICE_DCB_NO_HW_CHG)
757 ret = ICE_DCB_HW_CHG_RST;
760 mutex_unlock(&pf->tc_mutex);
765 * ice_dcbnl_cee_set_all - Commit CEE DCB settings to HW
766 * @netdev: the corresponding netdev
768 static u8 ice_dcbnl_cee_set_all(struct net_device *netdev)
770 struct ice_pf *pf = ice_netdev_to_pf(netdev);
771 struct ice_dcbx_cfg *new_cfg;
774 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
775 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
776 return ICE_DCB_NO_HW_CHG;
778 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
780 mutex_lock(&pf->tc_mutex);
782 err = ice_pf_dcb_cfg(pf, new_cfg, true);
784 mutex_unlock(&pf->tc_mutex);
785 return (err != ICE_DCB_HW_CHG_RST) ? ICE_DCB_NO_HW_CHG : err;
788 static const struct dcbnl_rtnl_ops dcbnl_ops = {
789 /* IEEE 802.1Qaz std */
790 .ieee_getets = ice_dcbnl_getets,
791 .ieee_setets = ice_dcbnl_setets,
792 .ieee_getpfc = ice_dcbnl_getpfc,
793 .ieee_setpfc = ice_dcbnl_setpfc,
794 .ieee_setapp = ice_dcbnl_setapp,
795 .ieee_delapp = ice_dcbnl_delapp,
798 .getstate = ice_dcbnl_getstate,
799 .setstate = ice_dcbnl_setstate,
800 .getpermhwaddr = ice_dcbnl_get_perm_hw_addr,
801 .setpgtccfgtx = ice_dcbnl_set_pg_tc_cfg_tx,
802 .setpgbwgcfgtx = ice_dcbnl_set_pg_bwg_cfg_tx,
803 .getpgtccfgtx = ice_dcbnl_get_pg_tc_cfg_tx,
804 .getpgbwgcfgtx = ice_dcbnl_get_pg_bwg_cfg_tx,
805 .getpgtccfgrx = ice_dcbnl_get_pg_tc_cfg_rx,
806 .getpgbwgcfgrx = ice_dcbnl_get_pg_bwg_cfg_rx,
807 .setpfccfg = ice_dcbnl_set_pfc_cfg,
808 .getpfccfg = ice_dcbnl_get_pfc_cfg,
809 .setall = ice_dcbnl_cee_set_all,
810 .getcap = ice_dcbnl_get_cap,
811 .getnumtcs = ice_dcbnl_getnumtcs,
812 .getpfcstate = ice_dcbnl_getpfcstate,
813 .getapp = ice_dcbnl_getapp,
815 /* DCBX configuration */
816 .getdcbx = ice_dcbnl_getdcbx,
817 .setdcbx = ice_dcbnl_setdcbx,
821 * ice_dcbnl_set_all - set all the apps and ieee data from DCBX config
822 * @vsi: pointer to VSI struct
824 void ice_dcbnl_set_all(struct ice_vsi *vsi)
826 struct net_device *netdev = vsi->netdev;
827 struct ice_dcbx_cfg *dcbxcfg;
828 struct ice_port_info *pi;
836 pf = ice_netdev_to_pf(netdev);
837 pi = pf->hw.port_info;
839 /* SW DCB taken care of by SW Default Config */
840 if (pf->dcbx_cap & DCB_CAP_DCBX_HOST)
843 /* DCB not enabled */
844 if (!test_bit(ICE_FLAG_DCB_ENA, pf->flags))
847 dcbxcfg = &pi->local_dcbx_cfg;
849 for (i = 0; i < dcbxcfg->numapps; i++) {
852 prio = dcbxcfg->app[i].priority;
853 tc_map = BIT(dcbxcfg->etscfg.prio_table[prio]);
855 /* Add APP only if the TC is enabled for this VSI */
856 if (tc_map & vsi->tc_cfg.ena_tc) {
857 sapp.selector = dcbxcfg->app[i].selector;
858 sapp.protocol = dcbxcfg->app[i].prot_id;
859 sapp.priority = prio;
860 dcb_ieee_setapp(netdev, &sapp);
863 /* Notify user-space of the changes */
864 dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, 0, 0);
868 * ice_dcbnl_vsi_del_app - Delete APP on all VSIs
869 * @vsi: pointer to the main VSI
870 * @app: APP to delete
872 * Delete given APP from all the VSIs for given PF
875 ice_dcbnl_vsi_del_app(struct ice_vsi *vsi,
876 struct ice_dcb_app_priority_table *app)
881 sapp.selector = app->selector;
882 sapp.protocol = app->prot_id;
883 sapp.priority = app->priority;
884 err = ice_dcbnl_delapp(vsi->netdev, &sapp);
885 dev_dbg(&vsi->back->pdev->dev,
886 "Deleting app for VSI idx=%d err=%d sel=%d proto=0x%x, prio=%d\n",
887 vsi->idx, err, app->selector, app->prot_id, app->priority);
891 * ice_dcbnl_flush_apps - Delete all removed APPs
892 * @pf: the corresponding PF
893 * @old_cfg: old DCBX configuration data
894 * @new_cfg: new DCBX configuration data
896 * Find and delete all APPS that are not present in the passed
900 ice_dcbnl_flush_apps(struct ice_pf *pf, struct ice_dcbx_cfg *old_cfg,
901 struct ice_dcbx_cfg *new_cfg)
903 struct ice_vsi *main_vsi = ice_get_main_vsi(pf);
909 for (i = 0; i < old_cfg->numapps; i++) {
910 struct ice_dcb_app_priority_table app = old_cfg->app[i];
912 /* The APP is not available anymore delete it */
913 if (!ice_dcbnl_find_app(new_cfg, &app))
914 ice_dcbnl_vsi_del_app(main_vsi, &app);
919 * ice_dcbnl_setup - setup DCBNL
920 * @vsi: VSI to get associated netdev from
922 void ice_dcbnl_setup(struct ice_vsi *vsi)
924 struct net_device *netdev = vsi->netdev;
927 pf = ice_netdev_to_pf(netdev);
928 if (!test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags))
931 netdev->dcbnl_ops = &dcbnl_ops;
932 ice_dcbnl_set_all(vsi);