Packet captures on sun8i cannot currently inspect frames the driver discards for Ethernet errors. Add opt-in rx-all support for complete frames with a reported wire error and for runts the MAC can forward. Set the runt-forwarding bit at hardware initialization and when rx-all changes. Serialize live updates with the DMA controls in the same register. Deliver these frames without claiming a verified checksum or including them in the good-packet and good-byte totals. Keep counting the wire errors even when the frames are delivered. Signed-off-by: James Hilliard --- drivers/net/ethernet/stmicro/stmmac/common.h | 2 + drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 73 +++++++++++++---------- drivers/net/ethernet/stmicro/stmmac/hwif.h | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 52 +++++++++++----- 4 files changed, 80 insertions(+), 48 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index 706feb7bcbed..ab959ee3a5dd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -360,6 +360,8 @@ enum rx_frame_status { llc_snap = 0x4, dma_own = 0x8, rx_not_ls = 0x10, + /* Complete frame with a wire error, deliverable only with RXALL. */ + rx_error_frame = 0x20, }; /* Tx status */ diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index 0ad2203f76c3..8398788d334e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -21,16 +21,12 @@ #include #include #include +#include #include #include "stmmac.h" #include "stmmac_platform.h" -/* General notes on dwmac-sun8i: - * Locking: no locking is necessary in this file because all necessary locking - * is done in the "stmmac files" - */ - /* struct emac_variant - Describe dwmac-sun8i hardware variant * @syscon_field reg_field for the syscon's gmac register * @soc_has_internal_phy: Does the MAC embed an internal PHY @@ -73,6 +69,7 @@ struct sunxi_priv_data { bool internal_phy_powered; bool use_internal_phy; void *mux_handle; + spinlock_t rx_ctl1_lock; /* Protects live RX_CTL1 updates */ }; /* EMAC clock register @ 0x30 in the "system control" address range */ @@ -198,6 +195,7 @@ static const struct emac_variant emac_variant_h616_emac1 = { /* Used in RX_CTL1*/ #define EMAC_RX_MD BIT(1) +#define EMAC_RX_RUNT_FRM BIT(2) #define EMAC_RX_ERR_FRM BIT(3) #define EMAC_RX_TH_MASK GENMASK(5, 4) #define EMAC_RX_TH_32 0 @@ -442,25 +440,32 @@ static void sun8i_dwmac_dma_stop_tx(struct stmmac_priv *priv, writel(v, ioaddr + EMAC_TX_CTL1); } -static void sun8i_dwmac_dma_start_rx(struct stmmac_priv *priv, - void __iomem *ioaddr, u32 chan) +static void sun8i_dwmac_update_rx_ctl1(struct stmmac_priv *priv, u32 clear, u32 set) { + struct sunxi_priv_data *gmac = priv->plat->bsp_priv; u32 v; - v = readl(ioaddr + EMAC_RX_CTL1); - v |= EMAC_RX_DMA_START; - v |= EMAC_RX_DMA_EN; - writel(v, ioaddr + EMAC_RX_CTL1); + guard(spinlock_irqsave)(&gmac->rx_ctl1_lock); + v = readl(priv->ioaddr + EMAC_RX_CTL1); + writel((v & ~clear) | set, priv->ioaddr + EMAC_RX_CTL1); +} + +static void sun8i_dwmac_dma_start_rx(struct stmmac_priv *priv, + void __iomem *ioaddr, u32 chan) +{ + sun8i_dwmac_update_rx_ctl1(priv, 0, EMAC_RX_DMA_START | EMAC_RX_DMA_EN); } static void sun8i_dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan) { - u32 v; + sun8i_dwmac_update_rx_ctl1(priv, EMAC_RX_DMA_EN, 0); +} - v = readl(ioaddr + EMAC_RX_CTL1); - v &= ~EMAC_RX_DMA_EN; - writel(v, ioaddr + EMAC_RX_CTL1); +static void sun8i_dwmac_set_rx_all(struct stmmac_priv *priv, bool enable) +{ + sun8i_dwmac_update_rx_ctl1(priv, EMAC_RX_RUNT_FRM, + enable ? EMAC_RX_RUNT_FRM : 0); } static int sun8i_dwmac_dma_interrupt(struct stmmac_priv *priv, @@ -539,24 +544,23 @@ static void sun8i_dwmac_dma_operation_mode_rx(struct stmmac_priv *priv, void __iomem *ioaddr, int mode, u32 channel, int fifosz, u8 qmode) { - u32 v; + u32 threshold = 0; - v = readl(ioaddr + EMAC_RX_CTL1); if (mode == SF_DMA_MODE) { - v |= EMAC_RX_MD; - } else { - v &= ~EMAC_RX_MD; - v &= ~EMAC_RX_TH_MASK; - if (mode < 32) - v |= EMAC_RX_TH_32; - else if (mode < 64) - v |= EMAC_RX_TH_64; - else if (mode < 96) - v |= EMAC_RX_TH_96; - else if (mode < 128) - v |= EMAC_RX_TH_128; + sun8i_dwmac_update_rx_ctl1(priv, 0, EMAC_RX_MD); + return; } - writel(v, ioaddr + EMAC_RX_CTL1); + + if (mode < 32) + threshold = EMAC_RX_TH_32; + else if (mode < 64) + threshold = EMAC_RX_TH_64; + else if (mode < 96) + threshold = EMAC_RX_TH_96; + else if (mode < 128) + threshold = EMAC_RX_TH_128; + + sun8i_dwmac_update_rx_ctl1(priv, EMAC_RX_MD | EMAC_RX_TH_MASK, threshold); } static void sun8i_dwmac_dma_operation_mode_tx(struct stmmac_priv *priv, @@ -648,7 +652,10 @@ static void sun8i_dwmac_core_init(struct mac_device_info *hw, writel(v, ioaddr + EMAC_BASIC_CTL1); /* Forward checksum failures to software before starting RX. */ - writel(EMAC_RX_ERR_FRM, ioaddr + EMAC_RX_CTL1); + v = EMAC_RX_ERR_FRM; + if (dev->features & NETIF_F_RXALL) + v |= EMAC_RX_RUNT_FRM; + writel(v, ioaddr + EMAC_RX_CTL1); } static void sun8i_dwmac_set_mac(void __iomem *ioaddr, bool enable) @@ -1052,6 +1059,7 @@ static const struct stmmac_ops sun8i_dwmac_ops = { .set_mac = sun8i_dwmac_set_mac, .dump_regs = sun8i_dwmac_dump_mac_regs, .rx_ipc = sun8i_dwmac_rx_ipc, + .set_rx_all = sun8i_dwmac_set_rx_all, .set_filter = sun8i_dwmac_set_filter, .flow_ctrl = sun8i_dwmac_flow_ctrl, .set_umac_addr = sun8i_dwmac_set_umac_addr, @@ -1126,7 +1134,7 @@ static int sun8i_dwmac_rx_status(struct stmmac_extra_stats *x, struct dma_desc * if (unlikely(runt || (status & wire_errors))) { if (runt && !(status & RDES0_LENGTH_ERROR)) x->rx_length++; - return discard_frame; + return rx_error_frame | csum_none; } /* Only a checked IP frame is eligible for CHECKSUM_UNNECESSARY. */ @@ -1218,6 +1226,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev) if (!gmac) return -ENOMEM; + spin_lock_init(&gmac->rx_ctl1_lock); gmac->variant = of_device_get_match_data(&pdev->dev); if (!gmac->variant) { dev_err(&pdev->dev, "Missing dwmac-sun8i variant\n"); diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 047d809b8b88..2cfadc686104 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -319,6 +319,7 @@ struct stmmac_ops { void (*set_mac)(void __iomem *ioaddr, bool enable); /* Enable and verify that the IPC module is supported */ int (*rx_ipc)(struct mac_device_info *hw); + void (*set_rx_all)(struct stmmac_priv *priv, bool enable); /* Enable RX Queues */ void (*rx_queue_enable)(struct mac_device_info *hw, u8 mode, u32 queue); /* RX Queues Priority */ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 2f33fc0126b1..0a893c2cea78 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5655,10 +5655,12 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue, skb_record_rx_queue(skb, queue); napi_gro_receive(&ch->rxtx_napi, skb); - u64_stats_update_begin(&rxq_stats->napi_syncp); - u64_stats_inc(&rxq_stats->napi.rx_packets); - u64_stats_add(&rxq_stats->napi.rx_bytes, len); - u64_stats_update_end(&rxq_stats->napi_syncp); + if (likely(!(status & rx_error_frame))) { + u64_stats_update_begin(&rxq_stats->napi_syncp); + u64_stats_inc(&rxq_stats->napi.rx_packets); + u64_stats_add(&rxq_stats->napi.rx_bytes, len); + u64_stats_update_end(&rxq_stats->napi_syncp); + } } static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget) @@ -5716,6 +5718,21 @@ static struct stmmac_xdp_buff *xsk_buff_to_stmmac_ctx(struct xdp_buff *xdp) return (struct stmmac_xdp_buff *)xdp; } +static bool stmmac_rx_discard(struct stmmac_priv *priv, int status, u32 *rx_errors) +{ + if (likely(!(status & (discard_frame | rx_error_frame)))) + return false; + + if (status & discard_frame) { + if (!priv->hwts_rx_en) + (*rx_errors)++; + return true; + } + + (*rx_errors)++; + return !(READ_ONCE(priv->dev->features) & NETIF_F_RXALL); +} + static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) { struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[queue]; @@ -5806,11 +5823,8 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) status); } - if (unlikely(!error && (status & discard_frame))) { - error = 1; - if (!priv->hwts_rx_en) - rx_errors++; - } + if (!error) + error = stmmac_rx_discard(priv, status, &rx_errors); if (unlikely(error)) { xsk_buff_free(buf->xdp); @@ -6004,11 +6018,8 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) status); } - if (unlikely(!error && (status & discard_frame))) { - error = 1; - if (!priv->hwts_rx_en) - rx_errors++; - } + if (!error) + error = stmmac_rx_discard(priv, status, &rx_errors); /* We do not support SG in XDP mode */ if (unlikely(!error && (status & rx_not_ls) && @@ -6170,8 +6181,10 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) skb_record_rx_queue(skb, queue); napi_gro_receive(&ch->rx_napi, skb); - rx_packets++; - rx_bytes += len; + if (likely(!(status & rx_error_frame))) { + rx_packets++; + rx_bytes += len; + } next: in_progress = false; skb = NULL; @@ -6453,6 +6466,11 @@ static int stmmac_set_features(struct net_device *netdev, { struct stmmac_priv *priv = netdev_priv(netdev); + if (((netdev->features ^ features) & NETIF_F_RXALL) && + netif_running(netdev) && netif_device_present(netdev) && + priv->hw->mac->set_rx_all) + priv->hw->mac->set_rx_all(priv, features & NETIF_F_RXALL); + /* Keep the COE Type in case of csum is supporting */ if (features & NETIF_F_RXCSUM) priv->hw->rx_csum = priv->plat->rx_coe; @@ -8285,6 +8303,8 @@ static int __stmmac_dvr_probe(struct device *device, } ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; + if (priv->hw->mac->set_rx_all) + ndev->hw_features |= NETIF_F_RXALL; ndev->watchdog_timeo = msecs_to_jiffies(watchdog); #ifdef STMMAC_VLAN_TAG_USED /* Both mac100 and gmac support receive VLAN tag detection */ -- 2.53.0