WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / ethernet / intel / fm10k / fm10k_dcbnl.c
blobc45315472245978020303073d12ad065c6bb151a
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2019 Intel Corporation. */
4 #include "fm10k.h"
6 /**
7 * fm10k_dcbnl_ieee_getets - get the ETS configuration for the device
8 * @dev: netdev interface for the device
9 * @ets: ETS structure to push configuration to
10 **/
11 static int fm10k_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets)
13 int i;
15 /* we support 8 TCs in all modes */
16 ets->ets_cap = IEEE_8021QAZ_MAX_TCS;
17 ets->cbs = 0;
19 /* we only support strict priority and cannot do traffic shaping */
20 memset(ets->tc_tx_bw, 0, sizeof(ets->tc_tx_bw));
21 memset(ets->tc_rx_bw, 0, sizeof(ets->tc_rx_bw));
22 memset(ets->tc_tsa, IEEE_8021QAZ_TSA_STRICT, sizeof(ets->tc_tsa));
24 /* populate the prio map based on the netdev */
25 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
26 ets->prio_tc[i] = netdev_get_prio_tc_map(dev, i);
28 return 0;
31 /**
32 * fm10k_dcbnl_ieee_setets - set the ETS configuration for the device
33 * @dev: netdev interface for the device
34 * @ets: ETS structure to pull configuration from
35 **/
36 static int fm10k_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
38 u8 num_tc = 0;
39 int i;
41 /* verify type and determine num_tcs needed */
42 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
43 if (ets->tc_tx_bw[i] || ets->tc_rx_bw[i])
44 return -EINVAL;
45 if (ets->tc_tsa[i] != IEEE_8021QAZ_TSA_STRICT)
46 return -EINVAL;
47 if (ets->prio_tc[i] > num_tc)
48 num_tc = ets->prio_tc[i];
51 /* if requested TC is greater than 0 then num_tcs is max + 1 */
52 if (num_tc)
53 num_tc++;
55 if (num_tc > IEEE_8021QAZ_MAX_TCS)
56 return -EINVAL;
58 /* update TC hardware mapping if necessary */
59 if (num_tc != netdev_get_num_tc(dev)) {
60 int err = fm10k_setup_tc(dev, num_tc);
61 if (err)
62 return err;
65 /* update priority mapping */
66 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
67 netdev_set_prio_tc_map(dev, i, ets->prio_tc[i]);
69 return 0;
72 /**
73 * fm10k_dcbnl_ieee_getpfc - get the PFC configuration for the device
74 * @dev: netdev interface for the device
75 * @pfc: PFC structure to push configuration to
76 **/
77 static int fm10k_dcbnl_ieee_getpfc(struct net_device *dev, struct ieee_pfc *pfc)
79 struct fm10k_intfc *interface = netdev_priv(dev);
81 /* record flow control max count and state of TCs */
82 pfc->pfc_cap = IEEE_8021QAZ_MAX_TCS;
83 pfc->pfc_en = interface->pfc_en;
85 return 0;
88 /**
89 * fm10k_dcbnl_ieee_setpfc - set the PFC configuration for the device
90 * @dev: netdev interface for the device
91 * @pfc: PFC structure to pull configuration from
92 **/
93 static int fm10k_dcbnl_ieee_setpfc(struct net_device *dev, struct ieee_pfc *pfc)
95 struct fm10k_intfc *interface = netdev_priv(dev);
97 /* record PFC configuration to interface */
98 interface->pfc_en = pfc->pfc_en;
100 /* if we are running update the drop_en state for all queues */
101 if (netif_running(dev))
102 fm10k_update_rx_drop_en(interface);
104 return 0;
108 * fm10k_dcbnl_ieee_getdcbx - get the DCBX configuration for the device
109 * @dev: netdev interface for the device
111 * Returns that we support only IEEE DCB for this interface
113 static u8 fm10k_dcbnl_getdcbx(struct net_device __always_unused *dev)
115 return DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
119 * fm10k_dcbnl_ieee_setdcbx - get the DCBX configuration for the device
120 * @dev: netdev interface for the device
121 * @mode: new mode for this device
123 * Returns error on attempt to enable anything but IEEE DCB for this interface
125 static u8 fm10k_dcbnl_setdcbx(struct net_device __always_unused *dev, u8 mode)
127 return (mode != (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE)) ? 1 : 0;
130 static const struct dcbnl_rtnl_ops fm10k_dcbnl_ops = {
131 .ieee_getets = fm10k_dcbnl_ieee_getets,
132 .ieee_setets = fm10k_dcbnl_ieee_setets,
133 .ieee_getpfc = fm10k_dcbnl_ieee_getpfc,
134 .ieee_setpfc = fm10k_dcbnl_ieee_setpfc,
136 .getdcbx = fm10k_dcbnl_getdcbx,
137 .setdcbx = fm10k_dcbnl_setdcbx,
141 * fm10k_dcbnl_set_ops - Configures dcbnl ops pointer for netdev
142 * @dev: netdev interface for the device
144 * Enables PF for DCB by assigning DCBNL ops pointer.
146 void fm10k_dcbnl_set_ops(struct net_device *dev)
148 struct fm10k_intfc *interface = netdev_priv(dev);
149 struct fm10k_hw *hw = &interface->hw;
151 if (hw->mac.type == fm10k_mac_pf)
152 dev->dcbnl_ops = &fm10k_dcbnl_ops;