[PATCH net-next 2/2] net: stmmac: dwmac-sun8i: support ethtool rx-all
James Hilliard
james.hilliard1 at gmail.com
Sat Nov 21 23:45:47 PST 2026
Enable packet captures of complete frames with wire errors on sun8i.
Report these frames to the core with an unverified checksum so it
can deliver them when rx-all is enabled. DMA and incomplete-frame
errors still require dropping the frame.
Program runt forwarding at initialization and when rx-all changes.
Serialize live updates of RX_CTL1 so changing the receive mode cannot
overwrite a concurrent DMA start, stop or threshold update.
Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 73 +++++++++++++----------
1 file changed, 41 insertions(+), 32 deletions(-)
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 <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
#include <linux/regmap.h>
+#include <linux/spinlock.h>
#include <linux/stmmac.h>
#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");
--
2.53.0
More information about the linux-arm-kernel
mailing list