When split header is enabled, XGMAC2 only splits IP packets that are untagged or VLAN stripped, at the L3/L4 header boundary. Other packets, such as tagged AV packets, can't use the split-header path. Add a config_l2_split MAC callback for the MAC-global part of split header and implement it for XGMAC2: select split at the L2 header offset (SPLM = L2OFST) and enable Split AV (SAVE_EN) in XGMAC_EXT_CFG1, extending the dwmac4 sequence added by commit d10f1a4e44c3 ("net: stmmac: Programming sequence for VLAN packets with split header") to XGMAC2. The databook states that L2 split is not supported for packets with variable preamble, so also clear VPRE in XGMAC_EXT_CFG0 while L2 split is enabled. The callback is called once, only on split header capable cores, and reverts SPLM/SAVE_EN when split header is disabled, e.g. when RX checksum offload is turned off. VPRE is left cleared, as it is reserved on cores without variable preamble support. The callback is not implemented for XLGMAC, which shares the XGMAC2 DMA ops but uses offset 0x140 for XLGMAC_RXQ_ENABLE_CTRL0. Also make dwxgmac2_get_rx_header_len() follow the databook's "Header Length Availability in RDES2" table: HL is only valid on the first descriptor, and L34T is only valid on the last one. For non-IP packets RDES2[1:0] carry AV status, so HL is RDES2[9:2]. Co-developed-by: Abhishek Chauhan Signed-off-by: Abhishek Chauhan Co-developed-by: Sarosh Hasan Signed-off-by: Sarosh Hasan Signed-off-by: Sagar Cheluvegowda --- v5: - Move the XGMAC_EXT_CFG0/EXT_CFG1 programming out of the DMA enable_sph op into a new config_l2_split MAC op implemented only for XGMAC2. The shared DMA op also ran on XLGMAC, where 0x140 is XLGMAC_RXQ_ENABLE_CTRL0, and cleared the RX queue 4 enable bit (Sashiko) - Program it once instead of per RX channel, only when sph_capable, and revert SPLM/SAVE_EN when split header is disabled (Sashiko) - Clear the SPLM field before setting it (Sashiko) - Describe the FD/LD handling as following the databook rather than as a fix - Fix line length warning v4: https://lore.kernel.org/netdev/20261015221215.1714047-1-sagar.cheluvegowda@oss.qualcomm.com/ - Only read the header length on the first descriptor (FD=1) v3: https://lore.kernel.org/netdev/20261013192759.776537-1-sagar.cheluvegowda@oss.qualcomm.com/ - Use zero-padded 0x00000140 for XGMAC_EXT_CFG0 v2: https://lore.kernel.org/netdev/20261007183905.2582759-1-sagar.cheluvegowda@oss.qualcomm.com/ - Add XGMAC_CONFIG1_SPLM_MASK and use it in XGMAC_CONFIG1_SPLM() v1: https://lore.kernel.org/netdev/20260922232116.889630-1-sagar.cheluvegowda@oss.qualcomm.com/ .../net/ethernet/stmicro/stmmac/dwxgmac2.h | 9 +++++++++ .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 20 +++++++++++++++++++ .../ethernet/stmicro/stmmac/dwxgmac2_descs.c | 16 ++++++++++++++- drivers/net/ethernet/stmicro/stmmac/hwif.h | 4 ++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h index f8ab347f7b5b..7f43a0b17083 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h @@ -167,6 +167,12 @@ #define XGMAC_HW_FEATURE4 0x0000012c #define XGMAC_HWFEAT_EASP BIT(4) #define XGMAC_HWFEAT_PCSEL GENMASK(1, 0) +#define XGMAC_EXT_CFG0 0x00000140 +#define XGMAC_EXT_CFG0_VPRE BIT(8) +#define XGMAC_EXT_CFG1 0x00000144 +#define XGMAC_CONFIG1_SAVE_EN BIT(24) +#define XGMAC_CONFIG1_SPLM_MASK GENMASK(9, 8) +#define XGMAC_CONFIG1_SPLM(v) FIELD_PREP(XGMAC_CONFIG1_SPLM_MASK, v) #define XGMAC_MAC_DPP_FSM_INT_STATUS 0x00000150 #define XGMAC_MAC_FSM_CONTROL 0x00000158 #define XGMAC_PRTYEN BIT(1) @@ -434,13 +440,16 @@ #define XGMAC_RDES2_L4FM BIT(28) #define XGMAC_RDES2_L3FM BIT(27) #define XGMAC_RDES2_HL GENMASK(9, 0) +#define XGMAC_RDES2_NONIPHL GENMASK(9, 2) #define XGMAC_RDES3_OWN BIT(31) #define XGMAC_RDES3_CTXT BIT(30) #define XGMAC_RDES3_IOC BIT(30) +#define XGMAC_RDES3_FD BIT(29) #define XGMAC_RDES3_LD BIT(28) #define XGMAC_RDES3_CDA BIT(27) #define XGMAC_RDES3_RSV BIT(26) #define XGMAC_RDES3_L34T GENMASK(23, 20) +#define XGMAC_RDES3_L2T GENMASK(19, 16) #define XGMAC_RDES3_ET_LT GENMASK(19, 16) #define XGMAC_L34T_IP4TCP 0x1 #define XGMAC_L34T_IP4UDP 0x2 diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c index 09194b9d8322..58d7433e8b17 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c @@ -1412,6 +1412,25 @@ static int dwxgmac2_config_l4_filter(struct mac_device_info *hw, u32 filter_no, return 0; } +static void dwxgmac2_config_l2_split(struct mac_device_info *hw, bool en) +{ + void __iomem *ioaddr = hw->pcsr; + u32 value; + + /* L2 split is not supported for packets with variable preamble */ + if (en) { + value = readl(ioaddr + XGMAC_EXT_CFG0); + value &= ~XGMAC_EXT_CFG0_VPRE; + writel(value, ioaddr + XGMAC_EXT_CFG0); + } + + value = readl(ioaddr + XGMAC_EXT_CFG1); + value &= ~(XGMAC_CONFIG1_SPLM_MASK | XGMAC_CONFIG1_SAVE_EN); + if (en) + value |= XGMAC_CONFIG1_SPLM(1) | XGMAC_CONFIG1_SAVE_EN; + writel(value, ioaddr + XGMAC_EXT_CFG1); +} + const struct stmmac_ops dwxgmac210_ops = { .core_init = dwxgmac2_core_init, .irq_modify = dwxgmac2_irq_modify, @@ -1451,6 +1470,7 @@ const struct stmmac_ops dwxgmac210_ops = { .config_l3_filter = dwxgmac2_config_l3_filter, .config_l4_filter = dwxgmac2_config_l4_filter, .fpe_map_preemption_class = dwxgmac3_fpe_map_preemption_class, + .config_l2_split = dwxgmac2_config_l2_split, }; static void dwxlgmac2_rx_queue_enable(struct mac_device_info *hw, u8 mode, diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c index 6719ac6e395b..b28aa39f9947 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c @@ -292,8 +292,22 @@ static int dwxgmac2_get_rx_hash(struct dma_desc *p, u32 *hash, static void dwxgmac2_get_rx_header_len(struct dma_desc *p, unsigned int *len) { - if (le32_to_cpu(p->des3) & XGMAC_RDES3_L34T) + u32 rdes3 = le32_to_cpu(p->des3); + + /* HL is only defined on the first descriptor */ + if (!(rdes3 & XGMAC_RDES3_FD)) + return; + + /* when FD=1 and LD=0, HL is RDES2[9:0] */ + if (!(rdes3 & XGMAC_RDES3_LD)) { + *len = le32_to_cpu(p->des2) & XGMAC_RDES2_HL; + return; + } + + if (rdes3 & XGMAC_RDES3_L34T) *len = le32_to_cpu(p->des2) & XGMAC_RDES2_HL; + else if (rdes3 & XGMAC_RDES3_L2T) + *len = (le32_to_cpu(p->des2) & XGMAC_RDES2_NONIPHL) >> 2; } static void dwxgmac2_set_sec_addr(struct dma_desc *p, dma_addr_t addr, bool is_valid) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 8ae95e91a36a..80131fdda2d5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -410,6 +410,8 @@ struct stmmac_ops { int (*fpe_map_preemption_class)(struct net_device *ndev, struct netlink_ext_ack *extack, u32 pclass); + /* L2 header split, MAC-global part of split header */ + void (*config_l2_split)(struct mac_device_info *hw, bool en); }; #define stmmac_mac_pcs_init(__priv) \ @@ -492,6 +494,8 @@ struct stmmac_ops { stmmac_do_callback(__priv, mac, config_l4_filter, __args) #define stmmac_fpe_map_preemption_class(__priv, __args...) \ stmmac_do_callback(__priv, mac, fpe_map_preemption_class, __args) +#define stmmac_config_l2_split(__priv, __args...) \ + stmmac_do_void_callback(__priv, mac, config_l2_split, __args) struct ptp_system_timestamp; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index f256244ce0d1..0c333d14be4d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3832,6 +3832,8 @@ static int stmmac_hw_setup(struct net_device *dev) /* Enable Split Header */ sph_en = (priv->hw->rx_csum > 0) && priv->sph_active; + if (priv->sph_capable) + stmmac_config_l2_split(priv, priv->hw, sph_en); for (chan = 0; chan < rx_cnt; chan++) stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan); @@ -6467,6 +6469,7 @@ static int stmmac_set_features(struct net_device *netdev, bool sph_en = (priv->hw->rx_csum > 0) && priv->sph_active; u8 chan; + stmmac_config_l2_split(priv, priv->hw, sph_en); for (chan = 0; chan < priv->plat->rx_queues_to_use; chan++) stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan); } @@ -7430,6 +7433,8 @@ int stmmac_xdp_open(struct net_device *dev) /* Adjust Split header */ sph_en = (priv->hw->rx_csum > 0) && priv->sph_active; + if (priv->sph_capable) + stmmac_config_l2_split(priv, priv->hw, sph_en); /* DMA RX Channel Configuration */ for (chan = 0; chan < rx_cnt; chan++) { -- 2.34.1