From nobody Fri Sep 25 01:20:30 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 767E64A43E6 for ; Thu, 17 Sep 2026 21:54:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682047; cv=none; b=j023FrJ8VPMKuYWTX8Mq53PLbCDjzOSKbn84WnNo9BKPV8sHtQBvQJvl/FiadS/R5Q5/1psVWwpGXy8gOlk1u0io4a8ps0pI0eWjNT1Pf6HDMH/HYA8d7j9hs3D2ph5cP6r98NeH6w3T45RXamrAoOMDGIK0CBUqLni8yUQn2tM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682047; c=relaxed/simple; bh=stgNm0O4ytBVO2Qf5KmpkH2AAV6qIzrLws8hJ0x7w+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G7691tx4kZVmyToghqL3VQeMdBgJwiBSlX9Ue2vdWYD8EXuYyw3vM8wfNKobWw1fNdR/42VDu5qCBOhBSA23eypTiH2oSXwoVDc5KY8VEN2PfFnLLQodhMSxwaFV8TJkbWju+ZS/wAgVfhtiOXuCq8zc2Z52e4iNrEwZxUuw6ss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=iDG/h88J; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="iDG/h88J" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 7B6761A094C; Thu, 17 Sep 2026 21:54:01 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 489A05FF03; Thu, 17 Sep 2026 21:54:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 143A311C7B091; Thu, 17 Sep 2026 23:53:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1789682039; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=uIhy92caf8rb2pE2pQEh/B0RxW7n2vIPP1k1H/MMpmk=; b=iDG/h88JAV3wULAnjI9JiqDAeDdMx02cHP51jyts9M61+lxL/omSBedspqDrxEXrCIZg1u gehfCa9A7vAGkL+YP3uxtFEqfUQcCh/EE+ErjLrr5r2IfIWgqdGwv2venGwRp3xkiaehGg u/xrErN6DML9qAM8jwvfc0Wh/yNyACw4mRbMvH7KwJu5DhP2+ml5lM84x9j6NOTsMbL3Wd bOBHM0BUy7yYOxIZFS7JQDpnldU/EMF5neN+jQJdEz4rrp9wi0vtMvpuM08olKjoc19em7 oA7WsuQ45cIBCgSKyp9xzWRd3uPlsByUOJXFJPltrkCX8qGK0hbMGokgv/C90w== From: Maxime Chevallier To: Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Heiner Kallweit , =?UTF-8?q?Alexis=20Lothor=C3=A9?= , Maxime Coquelin , Alexandre Torgue , Emil Renner Berthing , Minda Chen , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Jan Petrous , Ovidiu Panait , Jose.Abreu@synopsys.com, Nicolai Buchwitz Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, PKneuper@dspace.de, David Laight Subject: [PATCH net v4 1/7] net: stmmac: selftests: Support running selftests on DSA conduits Date: Thu, 17 Sep 2026 23:53:32 +0200 Message-ID: <20260917215339.2022523-2-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> References: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Most stmmac selftests rely on dev_add_pack() to add custom handlers, that validate the packets sent to ourselves through MAC loopback. However, when the stmmac-driven interface is a DSA CPU conduit, all frames that are received have ETH_P_XDSA as a protocol, even though they don't actually contain any tag as they come from the loopback and not the switch. This will prevent any incoming packet to match our packet handlers. Let's register a ETH_P_ALL packet handler when we detect that we're a DSA conduit, and use a proxy packet handler to filter the h_proto. As this allows external frames to be received through our .func(), the packet handler is added after the dev->addr field is populated in our selftest attributes. Note that we may still receive incoming packets from the switch, but these frames shouldn't interfere with the very specific frames used for selftests, and stmmac selftests in general aren't safe against external traffic interferences. This was validated on a WPQ864 devkit for IPQ8064, that has the SoC connected to a QCA8k switch. The ARP offload's packet handler is left alone, this feature is just not implemented in stmmac and due for removal. Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support") Reviewed-by: Nicolai Buchwitz Signed-off-by: Maxime Chevallier --- .../stmicro/stmmac/stmmac_selftests.c | 89 +++++++++++++++---- 1 file changed, 71 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drive= rs/net/ethernet/stmicro/stmmac/stmmac_selftests.c index 6372ec7c3f31..614b5995dec5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -237,6 +238,9 @@ struct stmmac_test_priv { struct stmmac_packet_attrs *packet; struct packet_type pt; struct completion comp; + __be16 packet_type; + int (*func)(struct sk_buff *skb, struct net_device *ndev, + struct packet_type *pt, struct net_device *orig_ndev); int double_vlan; int vlan_id; int ok; @@ -316,6 +320,50 @@ static int stmmac_test_loopback_validate(struct sk_buf= f *skb, return 0; } =20 +static int stmmac_sft_filter(struct sk_buff *skb, struct net_device *ndev, + struct packet_type *pt, + struct net_device *orig_ndev) +{ + struct stmmac_test_priv *tpriv =3D pt->af_packet_priv; + struct ethhdr *hdr =3D eth_hdr(skb); + int ret =3D 0; + + if (hdr->h_proto =3D=3D tpriv->packet_type) { + struct sk_buff *nskb =3D skb_clone(skb, GFP_ATOMIC); + + if (nskb) + ret =3D tpriv->func(nskb, ndev, pt, orig_ndev); + } + + kfree_skb(skb); + return ret; +} + +static void stmmac_sft_add_pack(struct packet_type *pt) +{ + struct stmmac_test_priv *tpriv =3D pt->af_packet_priv; + + if (netdev_uses_dsa(tpriv->pt.dev)) { + tpriv->packet_type =3D tpriv->pt.type; + tpriv->func =3D tpriv->pt.func; + + /* DSA conduit will report ETH_P_XDSA, so our packet handler + * won't match. Let's register a ETH_P_ALL match and filter + * manually in stmmac_sft_filter. + */ + tpriv->pt.type =3D htons(ETH_P_ALL); + tpriv->pt.func =3D stmmac_sft_filter; + tpriv->pt.ignore_outgoing =3D true; + } + + dev_add_pack(pt); +} + +static void stmmac_sft_remove_pack(struct packet_type *pt) +{ + dev_remove_pack(pt); +} + static int __stmmac_test_loopback(struct stmmac_priv *priv, struct stmmac_packet_attrs *attr) { @@ -337,7 +385,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *p= riv, tpriv->packet =3D attr; =20 if (!attr->dont_wait) - dev_add_pack(&tpriv->pt); + stmmac_sft_add_pack(&tpriv->pt); =20 skb =3D stmmac_test_get_udp_skb(priv, attr); if (!skb) { @@ -360,7 +408,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *p= riv, =20 cleanup: if (!attr->dont_wait) - dev_remove_pack(&tpriv->pt); + stmmac_sft_remove_pack(&tpriv->pt); kfree(tpriv); return ret; } @@ -767,7 +815,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *pri= v) tpriv->pt.func =3D stmmac_test_flowctrl_validate; tpriv->pt.dev =3D priv->dev; tpriv->pt.af_packet_priv =3D tpriv; - dev_add_pack(&tpriv->pt); + stmmac_sft_add_pack(&tpriv->pt); =20 /* Compute minimum number of packets to make FIFO full */ pkt_count =3D rx_fifo_size; @@ -823,7 +871,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *pri= v) cleanup: dev_mc_del(priv->dev, paddr); dev_set_promiscuity(priv->dev, -1); - dev_remove_pack(&tpriv->pt); + stmmac_sft_remove_pack(&tpriv->pt); kfree(tpriv); return ret; } @@ -928,18 +976,20 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv = *priv) * HASH values. */ tpriv->vlan_id =3D 0x123; - dev_add_pack(&tpriv->pt); =20 ret =3D vlan_vid_add(priv->dev, htons(ETH_P_8021Q), tpriv->vlan_id); if (ret) goto cleanup; =20 + attr.vlan =3D 1; + attr.dst =3D priv->dev->dev_addr; + attr.sport =3D 9; + attr.dport =3D 9; + + stmmac_sft_add_pack(&tpriv->pt); + for (i =3D 0; i < 4; i++) { - attr.vlan =3D 1; attr.vlan_id_out =3D tpriv->vlan_id + i; - attr.dst =3D priv->dev->dev_addr; - attr.sport =3D 9; - attr.dport =3D 9; =20 skb =3D stmmac_test_get_udp_skb(priv, &attr); if (!skb) { @@ -966,9 +1016,9 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv *= priv) } =20 vlan_del: + stmmac_sft_remove_pack(&tpriv->pt); vlan_vid_del(priv->dev, htons(ETH_P_8021Q), tpriv->vlan_id); cleanup: - dev_remove_pack(&tpriv->pt); kfree(tpriv); return ret; } @@ -1022,18 +1072,20 @@ static int __stmmac_test_dvlanfilt(struct stmmac_pr= iv *priv) * HASH values. */ tpriv->vlan_id =3D 0x123; - dev_add_pack(&tpriv->pt); =20 ret =3D vlan_vid_add(priv->dev, htons(ETH_P_8021AD), tpriv->vlan_id); if (ret) goto cleanup; =20 + attr.vlan =3D 2; + attr.dst =3D priv->dev->dev_addr; + attr.sport =3D 9; + attr.dport =3D 9; + + stmmac_sft_add_pack(&tpriv->pt); + for (i =3D 0; i < 4; i++) { - attr.vlan =3D 2; attr.vlan_id_out =3D tpriv->vlan_id + i; - attr.dst =3D priv->dev->dev_addr; - attr.sport =3D 9; - attr.dport =3D 9; =20 skb =3D stmmac_test_get_udp_skb(priv, &attr); if (!skb) { @@ -1060,9 +1112,9 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv= *priv) } =20 vlan_del: + stmmac_sft_remove_pack(&tpriv->pt); vlan_vid_del(priv->dev, htons(ETH_P_8021AD), tpriv->vlan_id); cleanup: - dev_remove_pack(&tpriv->pt); kfree(tpriv); return ret; } @@ -1293,7 +1345,6 @@ static int stmmac_test_vlanoff_common(struct stmmac_p= riv *priv, bool svlan) tpriv->pt.af_packet_priv =3D tpriv; tpriv->packet =3D &attr; tpriv->vlan_id =3D 0x123; - dev_add_pack(&tpriv->pt); =20 ret =3D vlan_vid_add(priv->dev, htons(proto), tpriv->vlan_id); if (ret) @@ -1301,6 +1352,8 @@ static int stmmac_test_vlanoff_common(struct stmmac_p= riv *priv, bool svlan) =20 attr.dst =3D priv->dev->dev_addr; =20 + stmmac_sft_add_pack(&tpriv->pt); + skb =3D stmmac_test_get_udp_skb(priv, &attr); if (!skb) { ret =3D -ENOMEM; @@ -1318,9 +1371,9 @@ static int stmmac_test_vlanoff_common(struct stmmac_p= riv *priv, bool svlan) ret =3D tpriv->ok ? 0 : -ETIMEDOUT; =20 vlan_del: + stmmac_sft_remove_pack(&tpriv->pt); vlan_vid_del(priv->dev, htons(proto), tpriv->vlan_id); cleanup: - dev_remove_pack(&tpriv->pt); kfree(tpriv); return ret; } --=20 2.55.0 From nobody Fri Sep 25 01:20:30 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C3784A64C0 for ; Thu, 17 Sep 2026 21:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682050; cv=none; b=k75KqhUoHZf8q99Fc/NQ1sDlUPtDaGDl5+YIwDG/aej5Ti2FshGVGAqaoHuKwOOUbTSiz9sOzZW7GsipEYgyEh/PHNIcLKE4X700cc1RhSP9Iyu/RAX3X0Ut8/jsneFJjGqITXeuVZqRJme5teEuCzZ0WSiU+MS3kzCyFXxTFWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682050; c=relaxed/simple; bh=gyBDOeV6ybo8r/Smyu55opwn8QbP81D/fA+gHFGb38w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KC5D5LlVLH7Wi8aq1/cS3xqrDEHiUhvXRMLpG+ReRCI6DGrYbG/k69YS2NLh2hTewy6r+uNhFnCY2auzSYuB2KSmrVAEPLzKgQqF/55uhPHuz08Z8ZAVFbeQgvzSHO4ZT46Pl5mdbEGb4sDDaOc/GntGwbUJKLncXRvOwcyIyvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=czj1k2vk; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="czj1k2vk" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 610271A0952; Thu, 17 Sep 2026 21:54:06 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 3517F5FF03; Thu, 17 Sep 2026 21:54:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1C2BD11C7B078; Thu, 17 Sep 2026 23:53:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1789682044; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=db9kiRUqojTT6icRWrq9tkilEuRiipOUqaP3av78n68=; b=czj1k2vkY9pYJFQe8+ympcPKTYmLGy8XBl1PJrwbWoGxJxaMev1/JoX1LzRAl89+jAkrFh gfjKMLaBO1Meoj0HJqZNpYVvVCxJgTDHFVQ052PGzuU1jYgeLxnKhBSk0KJqU8FKOEjwFS BMBaZciaGHfykuH/8vRyoUpKf3J7ZvkAHjQz/211yRKt1gb5B+wiOaXMzWKCiqiPjOjQ7H etwHJ161PRuVd+MQcNfTzlI+SIikW5aIRi8GLpNVoyEy0RIik2M+Q+CqwIzF/yJp1mSXZ3 18LL0L5x7Yuh7yv0T4eqhOJ3OBzwbfYe55jBer3ak+O0ezR3eRDomfEJUKwb7w== From: Maxime Chevallier To: Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Heiner Kallweit , =?UTF-8?q?Alexis=20Lothor=C3=A9?= , Maxime Coquelin , Alexandre Torgue , Emil Renner Berthing , Minda Chen , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Jan Petrous , Ovidiu Panait , Jose.Abreu@synopsys.com, Nicolai Buchwitz Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, PKneuper@dspace.de, David Laight Subject: [PATCH net v4 2/7] net: stmmac: selftests: Validate EEE based on the actual LPI timer value Date: Thu, 17 Sep 2026 23:53:33 +0200 Message-ID: <20260917215339.2022523-3-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> References: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The EEE selftest is a 2-step test : - It validates that we enter in LPI mode with the irq_tx_path_in_lpi_mode_n counter - It then validates that we exit LPI when sending a frame, with the irq_tx_path_exit_lpi_mode_n counter. The current state of the test lacks 2 main things : - We don't know exactly when was the previous frame sent (it's from the previous selftest) - The timeout is hardcoded, while the LPI is entered after a user-configurable delay. On top of that, the timeout loop uses a pre-decrement iterator (--retries) that actually only iterate nine times, so 900ms while the default LPI value is 1 second. Let's therefore make it more deterministic : - Send a frame at the beginning of the test - Wait for more than the lpi timer value, we timeout after about twice the value, - Then send another frame, and verify that we do go out of LPI, also with a timeout. As LPI timer can get pretty high, bail out if LPI timer is over 5 seconds. Note that the test's goal isn't to validate the LPI timer value itself, only that we enter/leave LPI mode. Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support") Reviewed-by: Nicolai Buchwitz Signed-off-by: Maxime Chevallier --- .../stmicro/stmmac/stmmac_selftests.c | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drive= rs/net/ethernet/stmicro/stmmac/stmmac_selftests.c index 614b5995dec5..2f9f7746c40a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -30,6 +30,7 @@ struct stmmachdr { sizeof(struct stmmachdr)) #define STMMAC_TEST_PKT_MAGIC 0xdeadcafecafedeadULL #define STMMAC_LB_TIMEOUT msecs_to_jiffies(200) +#define STMMAC_SFT_MAX_LPI (5 * USEC_PER_SEC) =20 struct stmmac_packet_attrs { int vlan; @@ -462,12 +463,16 @@ static int stmmac_test_mmc(struct stmmac_priv *priv) static int stmmac_test_eee(struct stmmac_priv *priv) { struct stmmac_extra_stats *initial, *final; - int retries =3D 10; + unsigned long timeout, max_duration; int ret; =20 if (!priv->dma_cap.eee || !priv->eee_active) return -EOPNOTSUPP; =20 + /* Bail out if the configured LPI timer is too long */ + if (priv->tx_lpi_timer > STMMAC_SFT_MAX_LPI) + return -EOPNOTSUPP; + initial =3D kzalloc_obj(*initial); if (!initial) return -ENOMEM; @@ -478,14 +483,21 @@ static int stmmac_test_eee(struct stmmac_priv *priv) goto out_free_initial; } =20 + /* Snapshot stats, we want to count the in_lpi events. We may enter + * LPI just after the packet was sent. + */ memcpy(initial, &priv->xstats, sizeof(*initial)); =20 + /* Send a frame, then wait to enter LPI */ ret =3D stmmac_test_mac_loopback(priv); if (ret) goto out_free_final; =20 + max_duration =3D usecs_to_jiffies(2 * priv->tx_lpi_timer); + /* We have no traffic in the line so, sooner or later it will go LPI */ - while (--retries) { + timeout =3D jiffies + max_duration; + while (!time_after(jiffies, timeout)) { memcpy(final, &priv->xstats, sizeof(*final)); =20 if (final->irq_tx_path_in_lpi_mode_n > @@ -494,20 +506,38 @@ static int stmmac_test_eee(struct stmmac_priv *priv) msleep(100); } =20 - if (!retries) { + memcpy(final, &priv->xstats, sizeof(*final)); + if (final->irq_tx_path_in_lpi_mode_n <=3D + initial->irq_tx_path_in_lpi_mode_n) { ret =3D -ETIMEDOUT; goto out_free_final; } =20 - if (final->irq_tx_path_in_lpi_mode_n <=3D - initial->irq_tx_path_in_lpi_mode_n) { - ret =3D -EINVAL; + /* Re-snapshot, as we want to measure exit_lpi events. We should be + * in LPI right now. + */ + memcpy(initial, &priv->xstats, sizeof(*initial)); + + /* TX something so we go out of LPI */ + ret =3D stmmac_test_mac_loopback(priv); + if (ret) goto out_free_final; + + /* Wait for the exit LPI interrupt */ + timeout =3D jiffies + max_duration; + while (!time_after(jiffies, timeout)) { + memcpy(final, &priv->xstats, sizeof(*final)); + + if (final->irq_tx_path_exit_lpi_mode_n > + initial->irq_tx_path_exit_lpi_mode_n) + break; + msleep(100); } =20 + memcpy(final, &priv->xstats, sizeof(*final)); if (final->irq_tx_path_exit_lpi_mode_n <=3D initial->irq_tx_path_exit_lpi_mode_n) { - ret =3D -EINVAL; + ret =3D -ETIMEDOUT; goto out_free_final; } =20 --=20 2.55.0 From nobody Fri Sep 25 01:20:30 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D74024AA58F for ; Thu, 17 Sep 2026 21:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682053; cv=none; b=tx/hVJ2ACi1BdDB8qPpLfRE9HgZBqbh0kCiHsJ6Sx6+Rc4H6S0ej7XxNBvGvdyPgJBPIG4JNT5XHT5pyWpiqtEYeCjpq5Ynwn2vFFqvC0UOdfaghJsYyLz2X4GoW2mAcSylAXQsmPT6FYBiDYxNZXBqZOzvohw+zVRH/FCR9EeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682053; c=relaxed/simple; bh=Z5E8ruKxQ4jkL5iseCaDFurRPhQDnTscuRXD9azwDtM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K3d3wqAwnGKkjV+QzdXReBn3f+NDyqDB0ULhky3RaRoULXH/FwAbPM0zn9N58z3Thdg89nok2JaLu8b4fBf06PDu5/L1i6VB705AYcsrfjW4G7t4PGoXGOaONXWh6xtwUPr9U09nX490Ce8fiSV9cVBbdMuX4adpQROlyPa9dbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=gNJY8i2g; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="gNJY8i2g" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 5B1B11A094C; Thu, 17 Sep 2026 21:54:10 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2D7205FF03; Thu, 17 Sep 2026 21:54:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1C97B11C7B092; Thu, 17 Sep 2026 23:54:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1789682048; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=SP8JzxZkC9JCoDs+bzDeDTd3TbPD+u3Y7L9Dv9B3Q64=; b=gNJY8i2gTmgx1ufzB1Xbojx4kqnzAhdL9N9+aOLUNmBo0O5wRfKxSzVcDrQXmhB937JcmN 6CqwVP2GLtuH56rplrv3DQ52Nqol6reRjqMrODiubElz6Vw/i7ii81i/x1UnREBBCh9gOL S4ursRp+LffN3woLsjSKbXynWzrmGV//agCGTZcDZwXm2VpoAv5fz0QvvrPvoq2DtoJXJY aazy0y5g8ruMEvnD2QHRLSXdYi94tpGLZdYFQ7br7CL96BQStXreuNiqwfFome4YsnAgc8 /Y0ld0WsL/jouiNcGdqLnp3Y4rNg7Go2oQPhf7MzhOskyOuq8o9NMpPHMTouow== From: Maxime Chevallier To: Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Heiner Kallweit , =?UTF-8?q?Alexis=20Lothor=C3=A9?= , Maxime Coquelin , Alexandre Torgue , Emil Renner Berthing , Minda Chen , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Jan Petrous , Ovidiu Panait , Jose.Abreu@synopsys.com, Nicolai Buchwitz Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, PKneuper@dspace.de, David Laight Subject: [PATCH net v4 3/7] net: stmmac: selftests: Check the dev->features for S-TAG offload testing Date: Thu, 17 Sep 2026 23:53:34 +0200 Message-ID: <20260917215339.2022523-4-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> References: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The S-TAG offload insertion incorrectly checks the dvlan (double vlan) DMA cap, which is different than S-TAG support. Use NETIF_F_HW_VLAN_STAG_TX to check if the feature is supported instead. Note that this flag isn't set in stmmac yet, but contrary to ARP offload, this is a feature that has a chance to get there eventually so let's leave the selftest here for now. It'll report -EOPNOTSUPP in the meantime. Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support") Reviewed-by: Nicolai Buchwitz Signed-off-by: Maxime Chevallier --- drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drive= rs/net/ethernet/stmicro/stmmac/stmmac_selftests.c index 2f9f7746c40a..de02c0da56dc 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -1415,7 +1415,7 @@ static int stmmac_test_vlanoff(struct stmmac_priv *pr= iv) =20 static int stmmac_test_svlanoff(struct stmmac_priv *priv) { - if (!priv->dma_cap.dvlan) + if (!(priv->dev->features & NETIF_F_HW_VLAN_STAG_TX)) return -EOPNOTSUPP; return stmmac_test_vlanoff_common(priv, true); } --=20 2.55.0 From nobody Fri Sep 25 01:20:30 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 369C84AE8C1 for ; Thu, 17 Sep 2026 21:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682057; cv=none; b=AXIMHBRs7dtMbViwrwp9ccVPBCh4KWlzkMUXjVlZLtLWxgPyKXZMy6JA3Evvv66Qn8Jy0Iz4J2n2+jh1ISSbzrwrlYb7QJOBQH1PBwvmm6O+j//gqc6eZ8OBGsbxM+yOWSuaGSt+S57EbcekUV0mP14blocNVKCkADEVGNl2AjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682057; c=relaxed/simple; bh=ww88GYu5nGoin++YN5FI3xzUwRyGfSi1cZypY6xt1HA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EYPQtYx7LdYIS6qu2yY58egRGoZSxaOZLaW+QuH4ebulZocPSBNYzmGAS5I5MDDP/Emp8vgYQqgHCzIKUU66d0HWLM3z+gR9QIpPDiM7pYnoTdLc+iYa7Iioqeg6mH4wTnpU4NqXzTxrNl3PbUzUpXDcM5Rg6x2nOFUjo+nb+TM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ncDGFZns; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ncDGFZns" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id A3D791A093E; Thu, 17 Sep 2026 21:54:14 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 778515FF03; Thu, 17 Sep 2026 21:54:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2D93411C7B08A; Thu, 17 Sep 2026 23:54:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1789682052; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=3ws2khTiEkVn3RET/TZ4kJ8Lw2HegLOZvwO/z1SoMCE=; b=ncDGFZnsLJDpsaGWXJ0s8QdmyE0cEWrdkVJUCGJWZqrX1bXEht0TiSrtohZJ67QH6u71dU zAcEkpdJUXvi9gkVwcIlsH2IOziraqWBa01kF5x6hn3fYNOY+ZoX9g1Z/tWq3xojV1dfdC 7B1L4oakZDNyW5iEYp0QVaeMKUb+hiCSGxsJpTHfLjnujCmoUxbrtNYH8pI7wA01IM9aVA OOjfmFN0G1r6BHQnRVheB4o6HI5B3OYNrez+1tp+536w82S5aO8l2DUhkCCl3+RVME/kAY tFxN8VR3UMY0w5Lo9dv04iy8+1jErwIQ6J+sIO7V0yFADtZQDca/epSDZ1qMaA== From: Maxime Chevallier To: Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Heiner Kallweit , =?UTF-8?q?Alexis=20Lothor=C3=A9?= , Maxime Coquelin , Alexandre Torgue , Emil Renner Berthing , Minda Chen , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Jan Petrous , Ovidiu Panait , Jose.Abreu@synopsys.com, Nicolai Buchwitz Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, PKneuper@dspace.de, David Laight Subject: [PATCH net v4 4/7] net: stmmac: selftests: Capture all packets for vlan checks Date: Thu, 17 Sep 2026 23:53:35 +0200 Message-ID: <20260917215339.2022523-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> References: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" While we use vlan_vid_add to trigger the tag filtering machinery in the driver, there's no netdev associated to the VLAN. This causes the skb to arrive with empty skb->vlan_tci fields, as the packet is marked OTHERHOST in __netif_receive_skb_core(), and we fail our validation. Let's use the proxy mechanism introduced for DSA, that registers a ETH_P_ALL packet handler that runs earlier, before the vlan netdev lookup, then filters for the correct ethertype before passing an skb clone to our validation function. As we may receive external frames with the right tag from the outside, let's move the address check in the vlan validation function earlier. Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support") Reviewed-by: Nicolai Buchwitz Signed-off-by: Maxime Chevallier --- .../stmicro/stmmac/stmmac_selftests.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drive= rs/net/ethernet/stmicro/stmmac/stmmac_selftests.c index de02c0da56dc..43b8411c5112 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -242,6 +242,7 @@ struct stmmac_test_priv { __be16 packet_type; int (*func)(struct sk_buff *skb, struct net_device *ndev, struct packet_type *pt, struct net_device *orig_ndev); + bool capture_all; int double_vlan; int vlan_id; int ok; @@ -344,13 +345,15 @@ static void stmmac_sft_add_pack(struct packet_type *p= t) { struct stmmac_test_priv *tpriv =3D pt->af_packet_priv; =20 - if (netdev_uses_dsa(tpriv->pt.dev)) { + if (netdev_uses_dsa(tpriv->pt.dev) || tpriv->capture_all) { tpriv->packet_type =3D tpriv->pt.type; tpriv->func =3D tpriv->pt.func; =20 /* DSA conduit will report ETH_P_XDSA, so our packet handler * won't match. Let's register a ETH_P_ALL match and filter - * manually in stmmac_sft_filter. + * manually in stmmac_sft_filter. This is also useful for + * VLAN tests, to capture packets otherwise marked as + * OTHERHOST. */ tpriv->pt.type =3D htons(ETH_P_ALL); tpriv->pt.func =3D stmmac_sft_filter; @@ -943,6 +946,11 @@ static int stmmac_test_vlan_validate(struct sk_buff *s= kb, goto out; if (skb_headlen(skb) < (STMMAC_TEST_PKT_SIZE - ETH_HLEN)) goto out; + + ehdr =3D (struct ethhdr *)skb_mac_header(skb); + if (!ether_addr_equal_unaligned(ehdr->h_dest, tpriv->packet->dst)) + goto out; + if (tpriv->vlan_id) { if (skb->vlan_proto !=3D htons(proto)) goto out; @@ -954,10 +962,6 @@ static int stmmac_test_vlan_validate(struct sk_buff *s= kb, } } =20 - ehdr =3D (struct ethhdr *)skb_mac_header(skb); - if (!ether_addr_equal_unaligned(ehdr->h_dest, tpriv->packet->dst)) - goto out; - ihdr =3D ip_hdr(skb); if (tpriv->double_vlan) ihdr =3D (struct iphdr *)(skb_network_header(skb) + 4); @@ -999,6 +1003,7 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv *= priv) tpriv->pt.dev =3D priv->dev; tpriv->pt.af_packet_priv =3D tpriv; tpriv->packet =3D &attr; + tpriv->capture_all =3D true; =20 /* * As we use HASH filtering, false positives may appear. This is a @@ -1095,6 +1100,7 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv= *priv) tpriv->pt.dev =3D priv->dev; tpriv->pt.af_packet_priv =3D tpriv; tpriv->packet =3D &attr; + tpriv->capture_all =3D true; =20 /* * As we use HASH filtering, false positives may appear. This is a @@ -1375,6 +1381,7 @@ static int stmmac_test_vlanoff_common(struct stmmac_p= riv *priv, bool svlan) tpriv->pt.af_packet_priv =3D tpriv; tpriv->packet =3D &attr; tpriv->vlan_id =3D 0x123; + tpriv->capture_all =3D true; =20 ret =3D vlan_vid_add(priv->dev, htons(proto), tpriv->vlan_id); if (ret) --=20 2.55.0 From nobody Fri Sep 25 01:20:30 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B2ED4A6CDA for ; Thu, 17 Sep 2026 21:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682065; cv=none; b=ZEm4noMYJSX7oBQp+swTspfQv4jyHqQiwZZ92tqDeVaNugq8do/YxLk7Q1UpH3sTh3fbm+RcyF+Mg9oRw5XZODY8iX9Zy32JpOgKkLzF0HrUVJI6ahP7Q35vDgpkUGYJcI4L1+uoWeA7p09oqcBzU6o7lkTKUvCtFf0cCaDFZdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682065; c=relaxed/simple; bh=5KSzkK/qdmt94D6W++AiGtJ98f2ZydoCK0eSKHqzJ6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UG2QZirYXzHKNBhkMxgCKvE/9i2jPSG8GBIH4S+nLvQtxXPcdbwjes7FLP/7G4b/ESSAsSr+kNKcp8Edh/pYnnV/65c+BdHiupF2dyHJYAFNmAr/oB4gUltwDiFGpGKF7XGNR1r7lVyCNNIh6NK1dRA9FIABcVAyefWDDV0gn90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=IlxK1HaJ; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="IlxK1HaJ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 06E351A093E; Thu, 17 Sep 2026 21:54:23 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id CD73F5FF03; Thu, 17 Sep 2026 21:54:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7C1B111C7B097; Thu, 17 Sep 2026 23:54:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1789682057; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=LDoZLUyubI5ZtV2PPymIrG3bnffwyzsLNZlK0gUZRgs=; b=IlxK1HaJt0uQhaWltczxR0cxi12N8kvh0TKQKSJiTP6AKG96g7Bl/PP20ITvUjfAMFTcYz CwhqWr2P8n4gANkWv0hU4u++XMAEYywm/IKZSzNFCNT7iEiTQvVuVptk7vec0a78t49mHd Z2o1F0h8+aYZJrWo7y6HXyH3fDbrCYrP0KgCS5YvKROC5loOPtn/QQWcKqtDfJmTRCd1zs zI4ixPTCx5p3ojeBCAFM7oACyN3rddNNJdVfmi1NIh8Z586CToHHSGG8aPXiIQq6UfV2fF bGMYUq51PSOKMOVBYKiYaLbsGT2+4Pw4HPzBiar7Lqy3FhXeSZC97sH9wlI6bQ== From: Maxime Chevallier To: Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Heiner Kallweit , =?UTF-8?q?Alexis=20Lothor=C3=A9?= , Maxime Coquelin , Alexandre Torgue , Emil Renner Berthing , Minda Chen , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Jan Petrous , Ovidiu Panait , Jose.Abreu@synopsys.com, Nicolai Buchwitz Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, PKneuper@dspace.de, David Laight Subject: [PATCH net v4 5/7] net: stmmac: dwmac4: Use the correct bufzise when the len is exactly 8K Date: Thu, 17 Sep 2026 23:53:36 +0200 Message-ID: <20260917215339.2022523-6-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> References: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" DMA bufsize selection isn't made on the MTU but the actual frame length, so including the L2 header. On DWMAC4, if the len is exactly BUF_SIZE_8KiB, the next larger size is incorrectly selected. Lets fix the comparison and while at it, rename the parameter from len to mtu. Fixes: c3efed5ad1b0 ("net: stmmac: Enable dwmac4 jumbo frame more than 8KiB= "). Signed-off-by: Maxime Chevallier Reviewed-by: Nicolai Buchwitz --- drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 4 ++-- drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 +- drivers/net/ethernet/stmicro/stmmac/ring_mode.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c b/drivers/n= et/ethernet/stmicro/stmmac/dwmac4_descs.c index 2994df41ec2c..c6a8f8d73501 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c @@ -474,11 +474,11 @@ static void dwmac4_set_sarc(struct dma_desc *p, u32 s= arc_type) sarc_type)); } =20 -static int set_16kib_bfsize(int mtu) +static int set_16kib_bfsize(int len) { int ret =3D 0; =20 - if (unlikely(mtu >=3D BUF_SIZE_8KiB)) + if (unlikely(len > BUF_SIZE_8KiB)) ret =3D BUF_SIZE_16KiB; return ret; } diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ether= net/stmicro/stmmac/hwif.h index 04dafec021b4..de7aa6d28148 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -540,7 +540,7 @@ struct stmmac_mode_ops { bool (*is_jumbo_frm)(unsigned int len, bool enh_desc); int (*jumbo_frm)(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, int csum); - int (*set_16kib_bfsize)(int mtu); + int (*set_16kib_bfsize)(int len); void (*init_desc3)(struct dma_desc *p); void (*refill_desc3)(struct stmmac_rx_queue *rx_q, struct dma_desc *p); void (*clean_desc3)(struct stmmac_tx_queue *tx_q, struct dma_desc *p); diff --git a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c b/drivers/net/= ethernet/stmicro/stmmac/ring_mode.c index f7949419eb9f..d2f0c321661d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c +++ b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c @@ -124,10 +124,10 @@ static void clean_desc3(struct stmmac_tx_queue *tx_q,= struct dma_desc *p) p->des3 =3D 0; } =20 -static int set_16kib_bfsize(int mtu) +static int set_16kib_bfsize(int len) { int ret =3D 0; - if (unlikely(mtu > BUF_SIZE_8KiB)) + if (unlikely(len > BUF_SIZE_8KiB)) ret =3D BUF_SIZE_16KiB; return ret; } --=20 2.55.0 From nobody Fri Sep 25 01:20:30 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2E9E4DDB4A for ; Thu, 17 Sep 2026 21:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682075; cv=none; b=ED0Lz+/UNlxpXq+l+wh/aewn7p+1htBesuHaMLefJkcPhyxizOKzfFRLfNbGfMienrCIUL96KjMpCF1bXXkZaua3BiFzKQA4Jdm/vzf/MDjuerS90F6EvHTYNpFYF2ByBZIRYSUdW2dbvZpnGyF1ILzvuIEAeD1RBs03T2M/GpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682075; c=relaxed/simple; bh=atfkGnQooaE3C8akYqomn5w9W3fnkxg0fnX+3JoB/FI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NyyGXr+OoaZ1NBmABEff/gJR5Emu2byhTHIqMCo0OKfqUbBpluWKZaCgqI8rhBKU05NiNXgAUMRhEh76nkKcMu9K/nIdjjBsT6mjBcgPPmQJqH5/1A1Qs8sKGQ/CCMAiYyrRRjWBPgiW44YJbfF0iZfjr2dmWzYgoR7EyMy4qsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=lpIcWHyG; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="lpIcWHyG" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 232EAC58468; Thu, 17 Sep 2026 21:55:15 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 90E7C5FF03; Thu, 17 Sep 2026 21:54:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id EA11011C7B094; Thu, 17 Sep 2026 23:54:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1789682065; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=aZq/chfAQTg1Qmarps6/Qi4b1p0OBOOfecEi1gSFMU4=; b=lpIcWHyGPu3bDYVa4LqrY5oaADbTfxE/awHsOp0AErgYpaBJSguFApAM82dUgxKKYRZQP7 MlGWzHWkuamK2t6PBeL9leVgaRmOARzL9iGzESfAqNIDyQKgehXDXXG6rVdr/J6pm0XkUX Jusd9V7c3EgZcTz6LJHI7p0rzZsUPn0YOaoyg4hcYHGpnmZkyqrVcG+2s39waH3Y+uukjj /H0tuSFdGQvaM47uF8tzl9NLJ0zwkFMj82osc4C8pSUnAHcAiJZLdjH9wzImKnKfEFs+FT jJyKrURFRHTAtaW/VlpwN0MLQacO8h/puQeZ973UBsOJt0ejGygGIb1j5fpsPA== From: Maxime Chevallier To: Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Heiner Kallweit , =?UTF-8?q?Alexis=20Lothor=C3=A9?= , Maxime Coquelin , Alexandre Torgue , Emil Renner Berthing , Minda Chen , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Jan Petrous , Ovidiu Panait , Jose.Abreu@synopsys.com, Nicolai Buchwitz Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, PKneuper@dspace.de, David Laight Subject: [PATCH net v4 6/7] net: stmmac: size the RX buffers from the frame length, not the MTU Date: Thu, 17 Sep 2026 23:53:37 +0200 Message-ID: <20260917215339.2022523-7-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> References: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" When picking the buffsize to use based on the MTU, we shouldn't check only the MTU value, but also : - ETH_HLEN for the L2 header, - up to 2 VLAN tags, - the FCS, The default bufsize is 1536 bytes, which is enough to contain all the above so this hasn't surfaced before, but the addition of NET_IP_ALIGN to the start of buffer address tripped the Jumbo selftest, leading to this discovery. With that, we don't need the '>=3D' checks on the buffer len, we can use more consistent comparison operators in stmmac_set_bfsize. Fixes: 286a83721720 ("stmmac: add CHAINED descriptor mode support (V4)") Reviewed-by: Nicolai Buchwitz Signed-off-by: Maxime Chevallier --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 1fb5f804ea23..d5a984ad864f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1536,17 +1536,17 @@ static unsigned int stmmac_rx_offset(struct stmmac_= priv *priv) return NET_SKB_PAD + NET_IP_ALIGN; } =20 -static int stmmac_set_bfsize(int mtu) +static int stmmac_set_bfsize(int len) { int ret; =20 - if (mtu >=3D BUF_SIZE_8KiB) + if (len > BUF_SIZE_8KiB) ret =3D BUF_SIZE_16KiB; - else if (mtu >=3D BUF_SIZE_4KiB) + else if (len > BUF_SIZE_4KiB) ret =3D BUF_SIZE_8KiB; - else if (mtu >=3D BUF_SIZE_2KiB) + else if (len > BUF_SIZE_2KiB) ret =3D BUF_SIZE_4KiB; - else if (mtu > DEFAULT_BUFSIZE) + else if (len > DEFAULT_BUFSIZE) ret =3D BUF_SIZE_2KiB; else ret =3D DEFAULT_BUFSIZE; @@ -4063,7 +4063,7 @@ static struct stmmac_dma_conf * stmmac_setup_dma_desc(struct stmmac_priv *priv, unsigned int mtu) { struct stmmac_dma_conf *dma_conf; - int bfsize, ret; + int bfsize, len, ret; u8 chan; =20 dma_conf =3D kzalloc_obj(*dma_conf); @@ -4073,13 +4073,15 @@ stmmac_setup_dma_desc(struct stmmac_priv *priv, uns= igned int mtu) return ERR_PTR(-ENOMEM); } =20 - /* Returns 0 or BUF_SIZE_16KiB if mtu > 8KiB and dwmac4 or ring mode */ - bfsize =3D stmmac_set_16kib_bfsize(priv, mtu); + len =3D mtu + ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN; + + /* Returns 0 or BUF_SIZE_16KiB if len > 8KiB and dwmac4 or ring mode */ + bfsize =3D stmmac_set_16kib_bfsize(priv, len); if (bfsize < 0) bfsize =3D 0; =20 if (bfsize < BUF_SIZE_16KiB) - bfsize =3D stmmac_set_bfsize(mtu); + bfsize =3D stmmac_set_bfsize(len); =20 dma_conf->dma_buf_sz =3D bfsize; /* Chose the tx/rx size from the already defined one in the --=20 2.55.0 From nobody Fri Sep 25 01:20:30 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37AE54A92EC; Thu, 17 Sep 2026 21:54:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682079; cv=none; b=P/TbM5VOG1axy+h3nuUNrXQiqf86o5JURSYAp5dHOIZTgX4rnxNjLKeKNAQCM5qytCBrAk/X8Mki+ZYEOdwXgcy7THuSJdTZg3UB18I6vP1twvcYZpP3+V7s3MPNKEZ362qGW1ShJEDUBjTQjLwpR7JYcXNfNakUJh50iUUuJ8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789682079; c=relaxed/simple; bh=8J1+LdHkXr+CXGkVzPtjWIRfXQKURvWN0pO35srGIFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DOEAmKRxJDipMZytSneuL7lbJP7tdVDUg3d7CTRG7VWnbteupOfoyFB0A+B43GwANYqGKf1zvoNNmFAtHvAfHNehMl1q71E3vQxmH7slNz54s1wqVOOpYOrmkwbeGT4yhTkXTbG7vReVQ4OjTaQ5/om0HprXKn/YukpR/QifNwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=XjFmlySW; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="XjFmlySW" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id D7FD91A094C; Thu, 17 Sep 2026 21:54:34 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id AB4345FF03; Thu, 17 Sep 2026 21:54:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B136311C7B08A; Thu, 17 Sep 2026 23:54:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1789682073; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=cZzyzrfpRknId9EVwZC5AhWVhuoRzTCf4ta8yZE40JI=; b=XjFmlySWpOe0fLB5f4Pv9/SrlLbnqTp6Wr9Y1ciUVS9G01rwLJX2XPpExO4QWah++PV4CN ijCn4QvURzx3wIFgxpLL9YCImvo5zBvPWPjJJ92dsYUzuKp9guQQ75cBzGTeLKq1GSZ8RD s/VleuA+lUSc8fwSYyMz9qSwaPQvmPsTJdQuNx2aiRswo5EXJuDKyy9zIqFurswT2uYEu/ bIAGSkNmbP2sRghDkNDrn5Qhi80BvM7iffLl4KYJ8bMUf6CH3dHNUn5inqCNDOycSnk+y0 aT10lCw11il5nbsSLd/6nREF+8b+aUCiL3t1KrxOjLBmOFi/A11B/NIsPFv4NQ== From: Maxime Chevallier To: Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Heiner Kallweit , =?UTF-8?q?Alexis=20Lothor=C3=A9?= , Maxime Coquelin , Alexandre Torgue , Emil Renner Berthing , Minda Chen , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Jan Petrous , Ovidiu Panait , Jose.Abreu@synopsys.com, Nicolai Buchwitz Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, PKneuper@dspace.de, David Laight Subject: [PATCH net v4 7/7] net: stmmac: selftests: Account for alignment shift on dwmac1000 for Jumbo test Date: Thu, 17 Sep 2026 23:53:38 +0200 Message-ID: <20260917215339.2022523-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> References: <20260917215339.2022523-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" On dwmac1000, we currently only support single-descriptor frames. The Jumbo test started failing when NET_IP_ALIGN was added to align the IP header, as this tests tries to send the biggest possible frame. On dwmac1000 the DMA transfer is aligned on 4-bytes, so adding a 2-byte shift at the start-of-buffer address means it takes a whole extra 4-byte DMA burst to receive the Jumbo packet, causing it to spill over the next descriptor. This doesn't seem to happen on dwmac4 and xgmac that appear to correctly handle unaligned xfers (only tested on dwmac4) Let's account for that in the Jumbo test, reduce the size of our big packet by the align size. Fixes: 23680bf5f8c6 ("net: stmmac: restore NET_IP_ALIGN in the RX DMA offse= t") Reviewed-by: Nicolai Buchwitz Signed-off-by: Maxime Chevallier --- drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drive= rs/net/ethernet/stmicro/stmmac/stmmac_selftests.c index 43b8411c5112..c25dc9f89270 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -1789,6 +1789,9 @@ static int __stmmac_test_jumbo(struct stmmac_priv *pr= iv, u16 queue) struct stmmac_packet_attrs attr =3D { }; int size =3D priv->dma_conf.dma_buf_sz; =20 + if (!dwmac_is_xmac(priv->plat->core_type)) + size -=3D NET_IP_ALIGN; + attr.dst =3D priv->dev->dev_addr; attr.max_size =3D size - ETH_FCS_LEN; attr.queue_mapping =3D queue; --=20 2.55.0