Skip to content

Commit

Permalink
net: stmmac: configure FPE via ethtool-mm
Browse files Browse the repository at this point in the history
Implement ethtool --show-mm and --set-mm callbacks.

NIC up/down, link up/down, suspend/resume, kselftest-ethtool_mm,
all tested okay.

Signed-off-by: Furong Xu <0x1207@gmail.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Link: https://patch.msgid.link/06ed409314fe0ee37b78b800922f2c0cce762532.1725631883.git.0x1207@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Furong Xu authored and Jakub Kicinski committed Sep 10, 2024
1 parent 8d43e99 commit 0f156ac
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,8 @@ const struct stmmac_ops dwmac410_ops = {
.fpe_configure = dwmac5_fpe_configure,
.fpe_send_mpacket = dwmac5_fpe_send_mpacket,
.fpe_irq_status = dwmac5_fpe_irq_status,
.fpe_get_add_frag_size = dwmac5_fpe_get_add_frag_size,
.fpe_set_add_frag_size = dwmac5_fpe_set_add_frag_size,
.add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
.del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
.restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
Expand Down Expand Up @@ -1316,6 +1318,8 @@ const struct stmmac_ops dwmac510_ops = {
.fpe_configure = dwmac5_fpe_configure,
.fpe_send_mpacket = dwmac5_fpe_send_mpacket,
.fpe_irq_status = dwmac5_fpe_irq_status,
.fpe_get_add_frag_size = dwmac5_fpe_get_add_frag_size,
.fpe_set_add_frag_size = dwmac5_fpe_set_add_frag_size,
.add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
.del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
.restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
Expand Down
14 changes: 14 additions & 0 deletions drivers/net/ethernet/stmicro/stmmac/dwmac5.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,17 @@ void dwmac5_fpe_send_mpacket(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg,

writel(value, ioaddr + MAC_FPE_CTRL_STS);
}

int dwmac5_fpe_get_add_frag_size(const void __iomem *ioaddr)
{
return FIELD_GET(DWMAC5_ADD_FRAG_SZ, readl(ioaddr + MTL_FPE_CTRL_STS));
}

void dwmac5_fpe_set_add_frag_size(void __iomem *ioaddr, u32 add_frag_size)
{
u32 value;

value = readl(ioaddr + MTL_FPE_CTRL_STS);
writel(u32_replace_bits(value, add_frag_size, DWMAC5_ADD_FRAG_SZ),
ioaddr + MTL_FPE_CTRL_STS);
}
6 changes: 6 additions & 0 deletions drivers/net/ethernet/stmicro/stmmac/dwmac5.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#define MAC_PPSx_INTERVAL(x) (0x00000b88 + ((x) * 0x10))
#define MAC_PPSx_WIDTH(x) (0x00000b8c + ((x) * 0x10))

#define MTL_FPE_CTRL_STS 0x00000c90
/* Additional Fragment Size of preempted frames */
#define DWMAC5_ADD_FRAG_SZ GENMASK(1, 0)

#define MTL_RXP_CONTROL_STATUS 0x00000ca0
#define RXPI BIT(31)
#define NPE GENMASK(23, 16)
Expand Down Expand Up @@ -109,5 +113,7 @@ void dwmac5_fpe_send_mpacket(void __iomem *ioaddr,
struct stmmac_fpe_cfg *cfg,
enum stmmac_mpacket_type type);
int dwmac5_fpe_irq_status(void __iomem *ioaddr, struct net_device *dev);
int dwmac5_fpe_get_add_frag_size(const void __iomem *ioaddr);
void dwmac5_fpe_set_add_frag_size(void __iomem *ioaddr, u32 add_frag_size);

#endif /* __DWMAC5_H__ */
6 changes: 6 additions & 0 deletions drivers/net/ethernet/stmicro/stmmac/hwif.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ struct stmmac_ops {
struct stmmac_fpe_cfg *cfg,
enum stmmac_mpacket_type type);
int (*fpe_irq_status)(void __iomem *ioaddr, struct net_device *dev);
int (*fpe_get_add_frag_size)(const void __iomem *ioaddr);
void (*fpe_set_add_frag_size)(void __iomem *ioaddr, u32 add_frag_size);
};

#define stmmac_core_init(__priv, __args...) \
Expand Down Expand Up @@ -530,6 +532,10 @@ struct stmmac_ops {
stmmac_do_void_callback(__priv, mac, fpe_send_mpacket, __args)
#define stmmac_fpe_irq_status(__priv, __args...) \
stmmac_do_callback(__priv, mac, fpe_irq_status, __args)
#define stmmac_fpe_get_add_frag_size(__priv, __args...) \
stmmac_do_callback(__priv, mac, fpe_get_add_frag_size, __args)
#define stmmac_fpe_set_add_frag_size(__priv, __args...) \
stmmac_do_void_callback(__priv, mac, fpe_set_add_frag_size, __args)

/* PTP and HW Timer helpers */
struct stmmac_hwtimestamp {
Expand Down
96 changes: 96 additions & 0 deletions drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "stmmac.h"
#include "dwmac_dma.h"
#include "dwxgmac2.h"
#include "dwmac5.h"

#define REG_SPACE_SIZE 0x1060
#define GMAC4_REG_SPACE_SIZE 0x116C
Expand Down Expand Up @@ -1263,6 +1264,98 @@ static int stmmac_set_tunable(struct net_device *dev,
return ret;
}

static int stmmac_get_mm(struct net_device *ndev,
struct ethtool_mm_state *state)
{
struct stmmac_priv *priv = netdev_priv(ndev);
unsigned long flags;
u32 frag_size;

if (!priv->dma_cap.fpesel)
return -EOPNOTSUPP;

spin_lock_irqsave(&priv->fpe_cfg.lock, flags);

state->max_verify_time = STMMAC_FPE_MM_MAX_VERIFY_TIME_MS;
state->verify_enabled = priv->fpe_cfg.verify_enabled;
state->pmac_enabled = priv->fpe_cfg.pmac_enabled;
state->verify_time = priv->fpe_cfg.verify_time;
state->tx_enabled = priv->fpe_cfg.tx_enabled;
state->verify_status = priv->fpe_cfg.status;
state->rx_min_frag_size = ETH_ZLEN;

/* FPE active if common tx_enabled and
* (verification success or disabled(forced))
*/
if (state->tx_enabled &&
(state->verify_status == ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED ||
state->verify_status == ETHTOOL_MM_VERIFY_STATUS_DISABLED))
state->tx_active = true;
else
state->tx_active = false;

frag_size = stmmac_fpe_get_add_frag_size(priv, priv->ioaddr);
state->tx_min_frag_size = ethtool_mm_frag_size_add_to_min(frag_size);

spin_unlock_irqrestore(&priv->fpe_cfg.lock, flags);

return 0;
}

static int stmmac_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg,
struct netlink_ext_ack *extack)
{
struct stmmac_priv *priv = netdev_priv(ndev);
struct stmmac_fpe_cfg *fpe_cfg = &priv->fpe_cfg;
unsigned long flags;
u32 frag_size;
int err;

err = ethtool_mm_frag_size_min_to_add(cfg->tx_min_frag_size,
&frag_size, extack);
if (err)
return err;

/* Wait for the verification that's currently in progress to finish */
timer_shutdown_sync(&fpe_cfg->verify_timer);

spin_lock_irqsave(&fpe_cfg->lock, flags);

fpe_cfg->verify_enabled = cfg->verify_enabled;
fpe_cfg->pmac_enabled = cfg->pmac_enabled;
fpe_cfg->verify_time = cfg->verify_time;
fpe_cfg->tx_enabled = cfg->tx_enabled;

if (!cfg->verify_enabled)
fpe_cfg->status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;

stmmac_fpe_set_add_frag_size(priv, priv->ioaddr, frag_size);
stmmac_fpe_apply(priv);

spin_unlock_irqrestore(&fpe_cfg->lock, flags);

return 0;
}

static void stmmac_get_mm_stats(struct net_device *ndev,
struct ethtool_mm_stats *s)
{
struct stmmac_priv *priv = netdev_priv(ndev);
struct stmmac_counters *mmc = &priv->mmc;

if (!priv->dma_cap.rmon)
return;

stmmac_mmc_read(priv, priv->mmcaddr, mmc);

s->MACMergeFrameAssErrorCount = mmc->mmc_rx_packet_assembly_err_cntr;
s->MACMergeFrameAssOkCount = mmc->mmc_rx_packet_assembly_ok_cntr;
s->MACMergeFrameSmdErrorCount = mmc->mmc_rx_packet_smd_err_cntr;
s->MACMergeFragCountRx = mmc->mmc_rx_fpe_fragment_cntr;
s->MACMergeFragCountTx = mmc->mmc_tx_fpe_fragment_cntr;
s->MACMergeHoldCount = mmc->mmc_tx_hold_req_cntr;
}

static const struct ethtool_ops stmmac_ethtool_ops = {
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
ETHTOOL_COALESCE_MAX_FRAMES,
Expand Down Expand Up @@ -1301,6 +1394,9 @@ static const struct ethtool_ops stmmac_ethtool_ops = {
.set_tunable = stmmac_set_tunable,
.get_link_ksettings = stmmac_ethtool_get_link_ksettings,
.set_link_ksettings = stmmac_ethtool_set_link_ksettings,
.get_mm = stmmac_get_mm,
.set_mm = stmmac_set_mm,
.get_mm_stats = stmmac_get_mm_stats,
};

void stmmac_set_ethtool_ops(struct net_device *netdev)
Expand Down

0 comments on commit 0f156ac

Please sign in to comment.