Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright(c) 2013 - 2019 Intel Corporation. */
0003 
0004 #include "fm10k.h"
0005 
0006 /**
0007  * fm10k_dcbnl_ieee_getets - get the ETS configuration for the device
0008  * @dev: netdev interface for the device
0009  * @ets: ETS structure to push configuration to
0010  **/
0011 static int fm10k_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets)
0012 {
0013     int i;
0014 
0015     /* we support 8 TCs in all modes */
0016     ets->ets_cap = IEEE_8021QAZ_MAX_TCS;
0017     ets->cbs = 0;
0018 
0019     /* we only support strict priority and cannot do traffic shaping */
0020     memset(ets->tc_tx_bw, 0, sizeof(ets->tc_tx_bw));
0021     memset(ets->tc_rx_bw, 0, sizeof(ets->tc_rx_bw));
0022     memset(ets->tc_tsa, IEEE_8021QAZ_TSA_STRICT, sizeof(ets->tc_tsa));
0023 
0024     /* populate the prio map based on the netdev */
0025     for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
0026         ets->prio_tc[i] = netdev_get_prio_tc_map(dev, i);
0027 
0028     return 0;
0029 }
0030 
0031 /**
0032  * fm10k_dcbnl_ieee_setets - set the ETS configuration for the device
0033  * @dev: netdev interface for the device
0034  * @ets: ETS structure to pull configuration from
0035  **/
0036 static int fm10k_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
0037 {
0038     u8 num_tc = 0;
0039     int i;
0040 
0041     /* verify type and determine num_tcs needed */
0042     for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
0043         if (ets->tc_tx_bw[i] || ets->tc_rx_bw[i])
0044             return -EINVAL;
0045         if (ets->tc_tsa[i] != IEEE_8021QAZ_TSA_STRICT)
0046             return -EINVAL;
0047         if (ets->prio_tc[i] > num_tc)
0048             num_tc = ets->prio_tc[i];
0049     }
0050 
0051     /* if requested TC is greater than 0 then num_tcs is max + 1 */
0052     if (num_tc)
0053         num_tc++;
0054 
0055     if (num_tc > IEEE_8021QAZ_MAX_TCS)
0056         return -EINVAL;
0057 
0058     /* update TC hardware mapping if necessary */
0059     if (num_tc != netdev_get_num_tc(dev)) {
0060         int err = fm10k_setup_tc(dev, num_tc);
0061         if (err)
0062             return err;
0063     }
0064 
0065     /* update priority mapping */
0066     for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
0067         netdev_set_prio_tc_map(dev, i, ets->prio_tc[i]);
0068 
0069     return 0;
0070 }
0071 
0072 /**
0073  * fm10k_dcbnl_ieee_getpfc - get the PFC configuration for the device
0074  * @dev: netdev interface for the device
0075  * @pfc: PFC structure to push configuration to
0076  **/
0077 static int fm10k_dcbnl_ieee_getpfc(struct net_device *dev, struct ieee_pfc *pfc)
0078 {
0079     struct fm10k_intfc *interface = netdev_priv(dev);
0080 
0081     /* record flow control max count and state of TCs */
0082     pfc->pfc_cap = IEEE_8021QAZ_MAX_TCS;
0083     pfc->pfc_en = interface->pfc_en;
0084 
0085     return 0;
0086 }
0087 
0088 /**
0089  * fm10k_dcbnl_ieee_setpfc - set the PFC configuration for the device
0090  * @dev: netdev interface for the device
0091  * @pfc: PFC structure to pull configuration from
0092  **/
0093 static int fm10k_dcbnl_ieee_setpfc(struct net_device *dev, struct ieee_pfc *pfc)
0094 {
0095     struct fm10k_intfc *interface = netdev_priv(dev);
0096 
0097     /* record PFC configuration to interface */
0098     interface->pfc_en = pfc->pfc_en;
0099 
0100     /* if we are running update the drop_en state for all queues */
0101     if (netif_running(dev))
0102         fm10k_update_rx_drop_en(interface);
0103 
0104     return 0;
0105 }
0106 
0107 /**
0108  * fm10k_dcbnl_getdcbx - get the DCBX configuration for the device
0109  * @dev: netdev interface for the device
0110  *
0111  * Returns that we support only IEEE DCB for this interface
0112  **/
0113 static u8 fm10k_dcbnl_getdcbx(struct net_device __always_unused *dev)
0114 {
0115     return DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
0116 }
0117 
0118 /**
0119  * fm10k_dcbnl_setdcbx - get the DCBX configuration for the device
0120  * @dev: netdev interface for the device
0121  * @mode: new mode for this device
0122  *
0123  * Returns error on attempt to enable anything but IEEE DCB for this interface
0124  **/
0125 static u8 fm10k_dcbnl_setdcbx(struct net_device __always_unused *dev, u8 mode)
0126 {
0127     return (mode != (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE)) ? 1 : 0;
0128 }
0129 
0130 static const struct dcbnl_rtnl_ops fm10k_dcbnl_ops = {
0131     .ieee_getets    = fm10k_dcbnl_ieee_getets,
0132     .ieee_setets    = fm10k_dcbnl_ieee_setets,
0133     .ieee_getpfc    = fm10k_dcbnl_ieee_getpfc,
0134     .ieee_setpfc    = fm10k_dcbnl_ieee_setpfc,
0135 
0136     .getdcbx    = fm10k_dcbnl_getdcbx,
0137     .setdcbx    = fm10k_dcbnl_setdcbx,
0138 };
0139 
0140 /**
0141  * fm10k_dcbnl_set_ops - Configures dcbnl ops pointer for netdev
0142  * @dev: netdev interface for the device
0143  *
0144  * Enables PF for DCB by assigning DCBNL ops pointer.
0145  **/
0146 void fm10k_dcbnl_set_ops(struct net_device *dev)
0147 {
0148     struct fm10k_intfc *interface = netdev_priv(dev);
0149     struct fm10k_hw *hw = &interface->hw;
0150 
0151     if (hw->mac.type == fm10k_mac_pf)
0152         dev->dcbnl_ops = &fm10k_dcbnl_ops;
0153 }