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);
21 set_bit(__ICE_DCBNL_DEVRESET, pf->state);
23 netdev_state_change(netdev);
24 dev_open(netdev, NULL);
25 netdev_state_change(netdev);
26 clear_bit(__ICE_DCBNL_DEVRESET, pf->state);
30 * ice_dcbnl_getets - retrieve local ETS configuration
31 * @netdev: the relevant netdev
32 * @ets: struct to hold ETS configuration
34 static int ice_dcbnl_getets(struct net_device *netdev, struct ieee_ets *ets)
36 struct ice_dcbx_cfg *dcbxcfg;
37 struct ice_port_info *pi;
40 pf = ice_netdev_to_pf(netdev);
41 pi = pf->hw.port_info;
42 dcbxcfg = &pi->local_dcbx_cfg;
44 ets->willing = dcbxcfg->etscfg.willing;
45 ets->ets_cap = dcbxcfg->etscfg.maxtcs;
46 ets->cbs = dcbxcfg->etscfg.cbs;
47 memcpy(ets->tc_tx_bw, dcbxcfg->etscfg.tcbwtable, sizeof(ets->tc_tx_bw));
48 memcpy(ets->tc_rx_bw, dcbxcfg->etscfg.tcbwtable, sizeof(ets->tc_rx_bw));
49 memcpy(ets->tc_tsa, dcbxcfg->etscfg.tsatable, sizeof(ets->tc_tsa));
50 memcpy(ets->prio_tc, dcbxcfg->etscfg.prio_table, sizeof(ets->prio_tc));
51 memcpy(ets->tc_reco_bw, dcbxcfg->etsrec.tcbwtable,
52 sizeof(ets->tc_reco_bw));
53 memcpy(ets->tc_reco_tsa, dcbxcfg->etsrec.tsatable,
54 sizeof(ets->tc_reco_tsa));
55 memcpy(ets->reco_prio_tc, dcbxcfg->etscfg.prio_table,
56 sizeof(ets->reco_prio_tc));
62 * ice_dcbnl_setets - set IEEE ETS configuration
63 * @netdev: pointer to relevant netdev
64 * @ets: struct to hold ETS configuration
66 static int ice_dcbnl_setets(struct net_device *netdev, struct ieee_ets *ets)
68 struct ice_pf *pf = ice_netdev_to_pf(netdev);
69 struct ice_dcbx_cfg *new_cfg;
70 int bwcfg = 0, bwrec = 0;
71 int err, i, max_tc = 0;
73 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
74 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
77 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
79 mutex_lock(&pf->tc_mutex);
81 new_cfg->etscfg.willing = ets->willing;
82 new_cfg->etscfg.cbs = ets->cbs;
83 ice_for_each_traffic_class(i) {
84 new_cfg->etscfg.tcbwtable[i] = ets->tc_tx_bw[i];
85 bwcfg += ets->tc_tx_bw[i];
86 new_cfg->etscfg.tsatable[i] = ets->tc_tsa[i];
87 new_cfg->etscfg.prio_table[i] = ets->prio_tc[i];
88 if (ets->prio_tc[i] > max_tc)
89 max_tc = ets->prio_tc[i];
90 new_cfg->etsrec.tcbwtable[i] = ets->tc_reco_bw[i];
91 bwrec += ets->tc_reco_bw[i];
92 new_cfg->etsrec.tsatable[i] = ets->tc_reco_tsa[i];
93 new_cfg->etsrec.prio_table[i] = ets->reco_prio_tc[i];
96 if (ice_dcb_bwchk(pf, new_cfg)) {
101 max_tc = pf->hw.func_caps.common_cap.maxtc;
103 new_cfg->etscfg.maxtcs = max_tc;
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 = IEEE_8021QAZ_MAX_TCS;
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);
163 /* No support for LLD_MANAGED modes or CEE+IEEE */
164 if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
165 ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
166 !(mode & DCB_CAP_DCBX_HOST))
167 return ICE_DCB_NO_HW_CHG;
169 /* Already set to the given mode no change */
170 if (mode == pf->dcbx_cap)
171 return ICE_DCB_NO_HW_CHG;
174 if (mode & DCB_CAP_DCBX_VER_CEE)
175 pf->hw.port_info->local_dcbx_cfg.dcbx_mode = ICE_DCBX_MODE_CEE;
177 pf->hw.port_info->local_dcbx_cfg.dcbx_mode = ICE_DCBX_MODE_IEEE;
179 dev_info(ice_pf_to_dev(pf), "DCBx mode = 0x%x\n", mode);
180 return ICE_DCB_HW_CHG_RST;
184 * ice_dcbnl_get_perm_hw_addr - MAC address used by DCBX
185 * @netdev: pointer to netdev struct
186 * @perm_addr: buffer to return permanent MAC address
188 static void ice_dcbnl_get_perm_hw_addr(struct net_device *netdev, u8 *perm_addr)
190 struct ice_pf *pf = ice_netdev_to_pf(netdev);
191 struct ice_port_info *pi = pf->hw.port_info;
194 memset(perm_addr, 0xff, MAX_ADDR_LEN);
196 for (i = 0; i < netdev->addr_len; i++)
197 perm_addr[i] = pi->mac.perm_addr[i];
199 for (j = 0; j < netdev->addr_len; j++, i++)
200 perm_addr[i] = pi->mac.perm_addr[j];
204 * ice_get_pfc_delay - Retrieve PFC Link Delay
205 * @hw: pointer to HW struct
206 * @delay: holds the PFC Link Delay value
208 static void ice_get_pfc_delay(struct ice_hw *hw, u16 *delay)
212 val = rd32(hw, PRTDCB_GENC);
213 *delay = (u16)((val & PRTDCB_GENC_PFCLDA_M) >> PRTDCB_GENC_PFCLDA_S);
217 * ice_dcbnl_getpfc - retrieve local IEEE PFC config
218 * @netdev: pointer to netdev struct
219 * @pfc: struct to hold PFC info
221 static int ice_dcbnl_getpfc(struct net_device *netdev, struct ieee_pfc *pfc)
223 struct ice_pf *pf = ice_netdev_to_pf(netdev);
224 struct ice_port_info *pi = pf->hw.port_info;
225 struct ice_dcbx_cfg *dcbxcfg;
228 dcbxcfg = &pi->local_dcbx_cfg;
229 pfc->pfc_cap = dcbxcfg->pfc.pfccap;
230 pfc->pfc_en = dcbxcfg->pfc.pfcena;
231 pfc->mbc = dcbxcfg->pfc.mbc;
232 ice_get_pfc_delay(&pf->hw, &pfc->delay);
234 ice_for_each_traffic_class(i) {
235 pfc->requests[i] = pf->stats.priority_xoff_tx[i];
236 pfc->indications[i] = pf->stats.priority_xoff_rx[i];
243 * ice_dcbnl_setpfc - set local IEEE PFC config
244 * @netdev: pointer to relevant netdev
245 * @pfc: pointer to struct holding PFC config
247 static int ice_dcbnl_setpfc(struct net_device *netdev, struct ieee_pfc *pfc)
249 struct ice_pf *pf = ice_netdev_to_pf(netdev);
250 struct ice_dcbx_cfg *new_cfg;
253 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
254 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
257 mutex_lock(&pf->tc_mutex);
259 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
262 new_cfg->pfc.pfccap = pfc->pfc_cap;
264 new_cfg->pfc.pfccap = pf->hw.func_caps.common_cap.maxtc;
266 new_cfg->pfc.pfcena = pfc->pfc_en;
268 err = ice_pf_dcb_cfg(pf, new_cfg, true);
269 if (err == ICE_DCB_HW_CHG_RST)
270 ice_dcbnl_devreset(netdev);
271 if (err == ICE_DCB_NO_HW_CHG)
272 err = ICE_DCB_HW_CHG_RST;
273 mutex_unlock(&pf->tc_mutex);
278 * ice_dcbnl_get_pfc_cfg - Get CEE PFC config
279 * @netdev: pointer to netdev struct
280 * @prio: corresponding user priority
281 * @setting: the PFC setting for given priority
284 ice_dcbnl_get_pfc_cfg(struct net_device *netdev, int prio, u8 *setting)
286 struct ice_pf *pf = ice_netdev_to_pf(netdev);
287 struct ice_port_info *pi = pf->hw.port_info;
289 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
290 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
293 if (prio >= ICE_MAX_USER_PRIORITY)
296 *setting = (pi->local_dcbx_cfg.pfc.pfcena >> prio) & 0x1;
297 dev_dbg(ice_pf_to_dev(pf), "Get PFC Config up=%d, setting=%d, pfcenable=0x%x\n",
298 prio, *setting, pi->local_dcbx_cfg.pfc.pfcena);
302 * ice_dcbnl_set_pfc_cfg - Set CEE PFC config
303 * @netdev: the corresponding netdev
304 * @prio: User Priority
305 * @set: PFC setting to apply
307 static void ice_dcbnl_set_pfc_cfg(struct net_device *netdev, int prio, u8 set)
309 struct ice_pf *pf = ice_netdev_to_pf(netdev);
310 struct ice_dcbx_cfg *new_cfg;
312 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
313 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
316 if (prio >= ICE_MAX_USER_PRIORITY)
319 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
321 new_cfg->pfc.pfccap = pf->hw.func_caps.common_cap.maxtc;
323 new_cfg->pfc.pfcena |= BIT(prio);
325 new_cfg->pfc.pfcena &= ~BIT(prio);
327 dev_dbg(ice_pf_to_dev(pf), "Set PFC config UP:%d set:%d pfcena:0x%x\n",
328 prio, set, new_cfg->pfc.pfcena);
332 * ice_dcbnl_getpfcstate - get CEE PFC mode
333 * @netdev: pointer to netdev struct
335 static u8 ice_dcbnl_getpfcstate(struct net_device *netdev)
337 struct ice_pf *pf = ice_netdev_to_pf(netdev);
338 struct ice_port_info *pi = pf->hw.port_info;
340 /* Return enabled if any UP enabled for PFC */
341 if (pi->local_dcbx_cfg.pfc.pfcena)
348 * ice_dcbnl_getstate - get DCB enabled state
349 * @netdev: pointer to netdev struct
351 static u8 ice_dcbnl_getstate(struct net_device *netdev)
353 struct ice_pf *pf = ice_netdev_to_pf(netdev);
356 state = test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
358 dev_dbg(ice_pf_to_dev(pf), "DCB enabled state = %d\n", state);
363 * ice_dcbnl_setstate - Set CEE DCB state
364 * @netdev: pointer to relevant netdev
365 * @state: state value to set
367 static u8 ice_dcbnl_setstate(struct net_device *netdev, u8 state)
369 struct ice_pf *pf = ice_netdev_to_pf(netdev);
371 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
372 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
373 return ICE_DCB_NO_HW_CHG;
376 if (!!state == test_bit(ICE_FLAG_DCB_ENA, pf->flags))
377 return ICE_DCB_NO_HW_CHG;
380 set_bit(ICE_FLAG_DCB_ENA, pf->flags);
381 memcpy(&pf->hw.port_info->desired_dcbx_cfg,
382 &pf->hw.port_info->local_dcbx_cfg,
383 sizeof(struct ice_dcbx_cfg));
385 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
388 return ICE_DCB_HW_CHG;
392 * ice_dcbnl_get_pg_tc_cfg_tx - get CEE PG Tx config
393 * @netdev: pointer to netdev struct
394 * @prio: the corresponding user priority
395 * @prio_type: traffic priority type
396 * @pgid: the BW group ID the traffic class belongs to
397 * @bw_pct: BW percentage for the corresponding BWG
398 * @up_map: prio mapped to corresponding TC
401 ice_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int prio,
402 u8 __always_unused *prio_type, u8 *pgid,
403 u8 __always_unused *bw_pct,
404 u8 __always_unused *up_map)
406 struct ice_pf *pf = ice_netdev_to_pf(netdev);
407 struct ice_port_info *pi = pf->hw.port_info;
409 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
410 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
413 if (prio >= ICE_MAX_USER_PRIORITY)
416 *pgid = pi->local_dcbx_cfg.etscfg.prio_table[prio];
417 dev_dbg(ice_pf_to_dev(pf), "Get PG config prio=%d tc=%d\n", prio,
422 * ice_dcbnl_set_pg_tc_cfg_tx - set CEE PG Tx config
423 * @netdev: pointer to relevant netdev
424 * @tc: the corresponding traffic class
425 * @prio_type: the traffic priority type
426 * @bwg_id: the BW group ID the TC belongs to
427 * @bw_pct: the BW perventage for the BWG
428 * @up_map: prio mapped to corresponding TC
431 ice_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
432 u8 __always_unused prio_type,
433 u8 __always_unused bwg_id,
434 u8 __always_unused bw_pct, u8 up_map)
436 struct ice_pf *pf = ice_netdev_to_pf(netdev);
437 struct ice_dcbx_cfg *new_cfg;
440 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
441 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
444 if (tc >= ICE_MAX_TRAFFIC_CLASS)
447 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
449 /* prio_type, bwg_id and bw_pct per UP are not supported */
451 ice_for_each_traffic_class(i) {
453 new_cfg->etscfg.prio_table[i] = tc;
455 new_cfg->etscfg.tsatable[tc] = ICE_IEEE_TSA_ETS;
459 * ice_dcbnl_get_pg_bwg_cfg_tx - Get CEE PGBW config
460 * @netdev: pointer to the netdev struct
461 * @pgid: corresponding traffic class
462 * @bw_pct: the BW percentage for the corresponding TC
465 ice_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int pgid, u8 *bw_pct)
467 struct ice_pf *pf = ice_netdev_to_pf(netdev);
468 struct ice_port_info *pi = pf->hw.port_info;
470 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
471 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
474 if (pgid >= ICE_MAX_TRAFFIC_CLASS)
477 *bw_pct = pi->local_dcbx_cfg.etscfg.tcbwtable[pgid];
478 dev_dbg(ice_pf_to_dev(pf), "Get PG BW config tc=%d bw_pct=%d\n",
483 * ice_dcbnl_set_pg_bwg_cfg_tx - set CEE PG Tx BW config
484 * @netdev: the corresponding netdev
485 * @pgid: Correspongind traffic class
486 * @bw_pct: the BW percentage for the specified TC
489 ice_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int pgid, u8 bw_pct)
491 struct ice_pf *pf = ice_netdev_to_pf(netdev);
492 struct ice_dcbx_cfg *new_cfg;
494 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
495 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
498 if (pgid >= ICE_MAX_TRAFFIC_CLASS)
501 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
503 new_cfg->etscfg.tcbwtable[pgid] = bw_pct;
507 * ice_dcbnl_get_pg_tc_cfg_rx - Get CEE PG Rx config
508 * @netdev: pointer to netdev struct
509 * @prio: the corresponding user priority
510 * @prio_type: the traffic priority type
512 * @bw_pct: the BW percentage for the corresponding BWG
513 * @up_map: prio mapped to corresponding TC
516 ice_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int prio,
517 u8 __always_unused *prio_type, u8 *pgid,
518 u8 __always_unused *bw_pct,
519 u8 __always_unused *up_map)
521 struct ice_pf *pf = ice_netdev_to_pf(netdev);
522 struct ice_port_info *pi = pf->hw.port_info;
524 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
525 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
528 if (prio >= ICE_MAX_USER_PRIORITY)
531 *pgid = pi->local_dcbx_cfg.etscfg.prio_table[prio];
535 * ice_dcbnl_set_pg_tc_cfg_rx
536 * @netdev: relevant netdev struct
537 * @prio: corresponding user priority
538 * @prio_type: the traffic priority type
540 * @bw_pct: BW percentage for corresponding BWG
541 * @up_map: prio mapped to corresponding TC
543 * lldpad requires this function pointer to be non-NULL to complete CEE config.
546 ice_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev,
547 int __always_unused prio,
548 u8 __always_unused prio_type,
549 u8 __always_unused pgid,
550 u8 __always_unused bw_pct,
551 u8 __always_unused up_map)
553 struct ice_pf *pf = ice_netdev_to_pf(netdev);
555 dev_dbg(ice_pf_to_dev(pf), "Rx TC PG Config Not Supported.\n");
559 * ice_dcbnl_get_pg_bwg_cfg_rx - Get CEE PG BW Rx config
560 * @netdev: pointer to netdev struct
561 * @pgid: the corresponding traffic class
562 * @bw_pct: the BW percentage for the corresponding TC
565 ice_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int __always_unused pgid,
568 struct ice_pf *pf = ice_netdev_to_pf(netdev);
570 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
571 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
578 * ice_dcbnl_set_pg_bwg_cfg_rx
579 * @netdev: the corresponding netdev
580 * @pgid: corresponding TC
581 * @bw_pct: BW percentage for given TC
583 * lldpad requires this function pointer to be non-NULL to complete CEE config.
586 ice_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int __always_unused pgid,
587 u8 __always_unused bw_pct)
589 struct ice_pf *pf = ice_netdev_to_pf(netdev);
591 dev_dbg(ice_pf_to_dev(pf), "Rx BWG PG Config Not Supported.\n");
595 * ice_dcbnl_get_cap - Get DCBX capabilities of adapter
596 * @netdev: pointer to netdev struct
597 * @capid: the capability type
598 * @cap: the capability value
600 static u8 ice_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
602 struct ice_pf *pf = ice_netdev_to_pf(netdev);
604 if (!(test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags)))
605 return ICE_DCB_NO_HW_CHG;
608 case DCB_CAP_ATTR_PG:
611 case DCB_CAP_ATTR_PFC:
614 case DCB_CAP_ATTR_UP2TC:
617 case DCB_CAP_ATTR_PG_TCS:
620 case DCB_CAP_ATTR_PFC_TCS:
623 case DCB_CAP_ATTR_GSP:
626 case DCB_CAP_ATTR_BCN:
629 case DCB_CAP_ATTR_DCBX:
637 dev_dbg(ice_pf_to_dev(pf), "DCBX Get Capability cap=%d capval=0x%x\n",
643 * ice_dcbnl_getapp - get CEE APP
644 * @netdev: pointer to netdev struct
645 * @idtype: the App selector
646 * @id: the App ethtype or port number
648 static int ice_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
650 struct ice_pf *pf = ice_netdev_to_pf(netdev);
651 struct dcb_app app = {
656 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
657 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
660 return dcb_getapp(netdev, &app);
664 * ice_dcbnl_find_app - Search for APP in given DCB config
665 * @cfg: struct to hold DCBX config
666 * @app: struct to hold app data to look for
669 ice_dcbnl_find_app(struct ice_dcbx_cfg *cfg,
670 struct ice_dcb_app_priority_table *app)
674 for (i = 0; i < cfg->numapps; i++) {
675 if (app->selector == cfg->app[i].selector &&
676 app->prot_id == cfg->app[i].prot_id &&
677 app->priority == cfg->app[i].priority)
685 * ice_dcbnl_setapp - set local IEEE App config
686 * @netdev: relevant netdev struct
687 * @app: struct to hold app config info
689 static int ice_dcbnl_setapp(struct net_device *netdev, struct dcb_app *app)
691 struct ice_pf *pf = ice_netdev_to_pf(netdev);
692 struct ice_dcb_app_priority_table new_app;
693 struct ice_dcbx_cfg *old_cfg, *new_cfg;
696 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
697 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
700 mutex_lock(&pf->tc_mutex);
702 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
704 old_cfg = &pf->hw.port_info->local_dcbx_cfg;
706 if (old_cfg->numapps == ICE_DCBX_MAX_APPS) {
711 ret = dcb_ieee_setapp(netdev, app);
715 new_app.selector = app->selector;
716 new_app.prot_id = app->protocol;
717 new_app.priority = app->priority;
718 if (ice_dcbnl_find_app(old_cfg, &new_app)) {
723 new_cfg->app[new_cfg->numapps++] = new_app;
724 ret = ice_pf_dcb_cfg(pf, new_cfg, true);
725 /* return of zero indicates new cfg applied */
726 if (ret == ICE_DCB_HW_CHG_RST)
727 ice_dcbnl_devreset(netdev);
728 if (ret == ICE_DCB_NO_HW_CHG)
729 ret = ICE_DCB_HW_CHG_RST;
732 mutex_unlock(&pf->tc_mutex);
737 * ice_dcbnl_delapp - Delete local IEEE App config
738 * @netdev: relevant netdev
739 * @app: struct to hold app too delete
741 * Will not delete first application required by the FW
743 static int ice_dcbnl_delapp(struct net_device *netdev, struct dcb_app *app)
745 struct ice_pf *pf = ice_netdev_to_pf(netdev);
746 struct ice_dcbx_cfg *old_cfg, *new_cfg;
750 if (pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED)
753 mutex_lock(&pf->tc_mutex);
754 old_cfg = &pf->hw.port_info->local_dcbx_cfg;
756 if (old_cfg->numapps <= 1)
759 ret = dcb_ieee_delapp(netdev, app);
763 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
765 for (i = 1; i < new_cfg->numapps; i++) {
766 if (app->selector == new_cfg->app[i].selector &&
767 app->protocol == new_cfg->app[i].prot_id &&
768 app->priority == new_cfg->app[i].priority) {
769 new_cfg->app[i].selector = 0;
770 new_cfg->app[i].prot_id = 0;
771 new_cfg->app[i].priority = 0;
776 /* Did not find DCB App */
777 if (i == new_cfg->numapps) {
784 for (j = i; j < new_cfg->numapps; j++) {
785 new_cfg->app[i].selector = old_cfg->app[j + 1].selector;
786 new_cfg->app[i].prot_id = old_cfg->app[j + 1].prot_id;
787 new_cfg->app[i].priority = old_cfg->app[j + 1].priority;
790 ret = ice_pf_dcb_cfg(pf, new_cfg, true);
791 /* return of zero indicates new cfg applied */
792 if (ret == ICE_DCB_HW_CHG_RST)
793 ice_dcbnl_devreset(netdev);
794 if (ret == ICE_DCB_NO_HW_CHG)
795 ret = ICE_DCB_HW_CHG_RST;
798 mutex_unlock(&pf->tc_mutex);
803 * ice_dcbnl_cee_set_all - Commit CEE DCB settings to HW
804 * @netdev: the corresponding netdev
806 static u8 ice_dcbnl_cee_set_all(struct net_device *netdev)
808 struct ice_pf *pf = ice_netdev_to_pf(netdev);
809 struct ice_dcbx_cfg *new_cfg;
812 if ((pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) ||
813 !(pf->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
814 return ICE_DCB_NO_HW_CHG;
816 new_cfg = &pf->hw.port_info->desired_dcbx_cfg;
818 mutex_lock(&pf->tc_mutex);
820 err = ice_pf_dcb_cfg(pf, new_cfg, true);
822 mutex_unlock(&pf->tc_mutex);
823 return (err != ICE_DCB_HW_CHG_RST) ? ICE_DCB_NO_HW_CHG : err;
826 static const struct dcbnl_rtnl_ops dcbnl_ops = {
827 /* IEEE 802.1Qaz std */
828 .ieee_getets = ice_dcbnl_getets,
829 .ieee_setets = ice_dcbnl_setets,
830 .ieee_getpfc = ice_dcbnl_getpfc,
831 .ieee_setpfc = ice_dcbnl_setpfc,
832 .ieee_setapp = ice_dcbnl_setapp,
833 .ieee_delapp = ice_dcbnl_delapp,
836 .getstate = ice_dcbnl_getstate,
837 .setstate = ice_dcbnl_setstate,
838 .getpermhwaddr = ice_dcbnl_get_perm_hw_addr,
839 .setpgtccfgtx = ice_dcbnl_set_pg_tc_cfg_tx,
840 .setpgbwgcfgtx = ice_dcbnl_set_pg_bwg_cfg_tx,
841 .setpgtccfgrx = ice_dcbnl_set_pg_tc_cfg_rx,
842 .setpgbwgcfgrx = ice_dcbnl_set_pg_bwg_cfg_rx,
843 .getpgtccfgtx = ice_dcbnl_get_pg_tc_cfg_tx,
844 .getpgbwgcfgtx = ice_dcbnl_get_pg_bwg_cfg_tx,
845 .getpgtccfgrx = ice_dcbnl_get_pg_tc_cfg_rx,
846 .getpgbwgcfgrx = ice_dcbnl_get_pg_bwg_cfg_rx,
847 .setpfccfg = ice_dcbnl_set_pfc_cfg,
848 .getpfccfg = ice_dcbnl_get_pfc_cfg,
849 .setall = ice_dcbnl_cee_set_all,
850 .getcap = ice_dcbnl_get_cap,
851 .getnumtcs = ice_dcbnl_getnumtcs,
852 .getpfcstate = ice_dcbnl_getpfcstate,
853 .getapp = ice_dcbnl_getapp,
855 /* DCBX configuration */
856 .getdcbx = ice_dcbnl_getdcbx,
857 .setdcbx = ice_dcbnl_setdcbx,
861 * ice_dcbnl_set_all - set all the apps and ieee data from DCBX config
862 * @vsi: pointer to VSI struct
864 void ice_dcbnl_set_all(struct ice_vsi *vsi)
866 struct net_device *netdev = vsi->netdev;
867 struct ice_dcbx_cfg *dcbxcfg;
868 struct ice_port_info *pi;
876 pf = ice_netdev_to_pf(netdev);
877 pi = pf->hw.port_info;
879 /* SW DCB taken care of by SW Default Config */
880 if (pf->dcbx_cap & DCB_CAP_DCBX_HOST)
883 /* DCB not enabled */
884 if (!test_bit(ICE_FLAG_DCB_ENA, pf->flags))
887 dcbxcfg = &pi->local_dcbx_cfg;
889 for (i = 0; i < dcbxcfg->numapps; i++) {
892 prio = dcbxcfg->app[i].priority;
893 tc_map = BIT(dcbxcfg->etscfg.prio_table[prio]);
895 /* Add APP only if the TC is enabled for this VSI */
896 if (tc_map & vsi->tc_cfg.ena_tc) {
897 sapp.selector = dcbxcfg->app[i].selector;
898 sapp.protocol = dcbxcfg->app[i].prot_id;
899 sapp.priority = prio;
900 dcb_ieee_setapp(netdev, &sapp);
903 /* Notify user-space of the changes */
904 dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, 0, 0);
908 * ice_dcbnl_vsi_del_app - Delete APP on all VSIs
909 * @vsi: pointer to the main VSI
910 * @app: APP to delete
912 * Delete given APP from all the VSIs for given PF
915 ice_dcbnl_vsi_del_app(struct ice_vsi *vsi,
916 struct ice_dcb_app_priority_table *app)
921 sapp.selector = app->selector;
922 sapp.protocol = app->prot_id;
923 sapp.priority = app->priority;
924 err = ice_dcbnl_delapp(vsi->netdev, &sapp);
925 dev_dbg(ice_pf_to_dev(vsi->back), "Deleting app for VSI idx=%d err=%d sel=%d proto=0x%x, prio=%d\n",
926 vsi->idx, err, app->selector, app->prot_id, app->priority);
930 * ice_dcbnl_flush_apps - Delete all removed APPs
931 * @pf: the corresponding PF
932 * @old_cfg: old DCBX configuration data
933 * @new_cfg: new DCBX configuration data
935 * Find and delete all APPS that are not present in the passed
939 ice_dcbnl_flush_apps(struct ice_pf *pf, struct ice_dcbx_cfg *old_cfg,
940 struct ice_dcbx_cfg *new_cfg)
942 struct ice_vsi *main_vsi = ice_get_main_vsi(pf);
948 for (i = 0; i < old_cfg->numapps; i++) {
949 struct ice_dcb_app_priority_table app = old_cfg->app[i];
951 /* The APP is not available anymore delete it */
952 if (!ice_dcbnl_find_app(new_cfg, &app))
953 ice_dcbnl_vsi_del_app(main_vsi, &app);
958 * ice_dcbnl_setup - setup DCBNL
959 * @vsi: VSI to get associated netdev from
961 void ice_dcbnl_setup(struct ice_vsi *vsi)
963 struct net_device *netdev = vsi->netdev;
966 pf = ice_netdev_to_pf(netdev);
967 if (!test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags))
970 netdev->dcbnl_ops = &dcbnl_ops;
971 ice_dcbnl_set_all(vsi);