0001
0002
0003
0004 #include "dpaa2-eth.h"
0005
0006 static int dpaa2_eth_dcbnl_ieee_getpfc(struct net_device *net_dev,
0007 struct ieee_pfc *pfc)
0008 {
0009 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
0010
0011 if (!(priv->link_state.options & DPNI_LINK_OPT_PFC_PAUSE))
0012 return 0;
0013
0014 memcpy(pfc, &priv->pfc, sizeof(priv->pfc));
0015 pfc->pfc_cap = dpaa2_eth_tc_count(priv);
0016
0017 return 0;
0018 }
0019
0020 static inline bool dpaa2_eth_is_prio_enabled(u8 pfc_en, u8 tc)
0021 {
0022 return !!(pfc_en & (1 << tc));
0023 }
0024
0025 static int dpaa2_eth_set_pfc_cn(struct dpaa2_eth_priv *priv, u8 pfc_en)
0026 {
0027 struct dpni_congestion_notification_cfg cfg = {0};
0028 int i, err;
0029
0030 cfg.notification_mode = DPNI_CONG_OPT_FLOW_CONTROL;
0031 cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
0032 cfg.message_iova = 0ULL;
0033 cfg.message_ctx = 0ULL;
0034
0035 for (i = 0; i < dpaa2_eth_tc_count(priv); i++) {
0036 if (dpaa2_eth_is_prio_enabled(pfc_en, i)) {
0037 cfg.threshold_entry = DPAA2_ETH_CN_THRESH_ENTRY(priv);
0038 cfg.threshold_exit = DPAA2_ETH_CN_THRESH_EXIT(priv);
0039 } else {
0040
0041
0042
0043
0044 cfg.threshold_entry = 0;
0045 cfg.threshold_exit = 0;
0046 }
0047
0048 err = dpni_set_congestion_notification(priv->mc_io, 0,
0049 priv->mc_token,
0050 DPNI_QUEUE_RX, i, &cfg);
0051 if (err) {
0052 netdev_err(priv->net_dev,
0053 "dpni_set_congestion_notification failed\n");
0054 return err;
0055 }
0056 }
0057
0058 return 0;
0059 }
0060
0061 static int dpaa2_eth_dcbnl_ieee_setpfc(struct net_device *net_dev,
0062 struct ieee_pfc *pfc)
0063 {
0064 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
0065 struct dpni_link_cfg link_cfg = {0};
0066 bool tx_pause;
0067 int err;
0068
0069 if (pfc->mbc || pfc->delay)
0070 return -EOPNOTSUPP;
0071
0072
0073 if (priv->pfc.pfc_en == pfc->pfc_en)
0074 return 0;
0075
0076
0077
0078
0079 tx_pause = dpaa2_eth_tx_pause_enabled(priv->link_state.options);
0080 if (!dpaa2_eth_rx_pause_enabled(priv->link_state.options) || !tx_pause)
0081 netdev_warn(net_dev, "Pause support must be enabled in order for PFC to work!\n");
0082
0083 link_cfg.rate = priv->link_state.rate;
0084 link_cfg.options = priv->link_state.options;
0085 if (pfc->pfc_en)
0086 link_cfg.options |= DPNI_LINK_OPT_PFC_PAUSE;
0087 else
0088 link_cfg.options &= ~DPNI_LINK_OPT_PFC_PAUSE;
0089 err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &link_cfg);
0090 if (err) {
0091 netdev_err(net_dev, "dpni_set_link_cfg failed\n");
0092 return err;
0093 }
0094
0095
0096 err = dpaa2_eth_set_pfc_cn(priv, pfc->pfc_en);
0097 if (err)
0098 return err;
0099
0100 memcpy(&priv->pfc, pfc, sizeof(priv->pfc));
0101 priv->pfc_enabled = !!pfc->pfc_en;
0102
0103 dpaa2_eth_set_rx_taildrop(priv, tx_pause, priv->pfc_enabled);
0104
0105 return 0;
0106 }
0107
0108 static u8 dpaa2_eth_dcbnl_getdcbx(struct net_device *net_dev)
0109 {
0110 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
0111
0112 return priv->dcbx_mode;
0113 }
0114
0115 static u8 dpaa2_eth_dcbnl_setdcbx(struct net_device *net_dev, u8 mode)
0116 {
0117 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
0118
0119 return (mode != (priv->dcbx_mode)) ? 1 : 0;
0120 }
0121
0122 static u8 dpaa2_eth_dcbnl_getcap(struct net_device *net_dev, int capid, u8 *cap)
0123 {
0124 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
0125
0126 switch (capid) {
0127 case DCB_CAP_ATTR_PFC:
0128 *cap = true;
0129 break;
0130 case DCB_CAP_ATTR_PFC_TCS:
0131 *cap = 1 << (dpaa2_eth_tc_count(priv) - 1);
0132 break;
0133 case DCB_CAP_ATTR_DCBX:
0134 *cap = priv->dcbx_mode;
0135 break;
0136 default:
0137 *cap = false;
0138 break;
0139 }
0140
0141 return 0;
0142 }
0143
0144 const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops = {
0145 .ieee_getpfc = dpaa2_eth_dcbnl_ieee_getpfc,
0146 .ieee_setpfc = dpaa2_eth_dcbnl_ieee_setpfc,
0147 .getdcbx = dpaa2_eth_dcbnl_getdcbx,
0148 .setdcbx = dpaa2_eth_dcbnl_setdcbx,
0149 .getcap = dpaa2_eth_dcbnl_getcap,
0150 };