From nobody Mon Feb 9 12:24:31 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 21696331A7E for ; Tue, 27 Jan 2026 09:07: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=1769504825; cv=none; b=XM2Hj1kmafUsHtlv6/y3cYLo+llns59R5PybzIpNzFKiusgZsr2qFMlhE6kZ2DyP0nPH53wWjcUFtYU+gLUgHdNPH00hd5QZAhnmaihQJrmwkCTSUHkUQTPdnaqCmckPuoz7FUN6HQ2CQD+6gUIiywDN7OImGCe2QU1a1N0oPgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769504825; c=relaxed/simple; bh=NXBqTeRrMdmbv9KNJEvENd/g8zIiTw3uvoCmEedoIqM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RLd6pgCyGkYmT76mPDbu5dA9CDmcz8fyGidm9aXPCeS8nX6rkRPED8jTGoxXqhz4rNXsRjkHSZPbIQLsqLrR4oQ1h6vZBetGQ9s0MZie6ZiHHH+p6N1TQ5pEk/VtoJu/0TfLWsM7BSISCkfXI9LoD+8RjKiTYel9xRPtfJzkxYw= 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=OZwTOJjT; 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="OZwTOJjT" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id C493D1A2A6C; Tue, 27 Jan 2026 09:07:02 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 901B9606F5; Tue, 27 Jan 2026 09:07:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id EE7AF119A867E; Tue, 27 Jan 2026 10:06:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1769504821; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=mAdxSZE83xUC1VcdJ9laK4kQl5LwI5jSzJL0hyvTGo8=; b=OZwTOJjTivWyivf9AVGyHUFR/afyOM/m89r+rLBC3D8W1vLTUx7GS1KOGt/H29MEsTvLsE cZZs38lDRgsc5FSJiKLkkaC0XpDYP2WinEAPMNNXZ3yHK/0eAJeFWHMLDaz7ZrBmDOqsoF JCaMRjtdFxrA788ylqHbRhyA3/gddvVfTVDH5SyzUL/T17vhJFA5Cz36rqB0dnYI60Jirk ieYN7zmnvF7cB5vaObhRK/frzvBhs1/gGI7ixTRsFRgXtbC9tyLSm/TNc2QhFgdRj5bkHK fj+0E5LLDscdTL/nbkz8BirkvciK851nNoTQUgSqaDem+dId/KdpfdkeZTc3gw== From: "Bastien Curutchet (Schneider Electric)" Date: Tue, 27 Jan 2026 10:06:47 +0100 Subject: [PATCH net-next v4 5/8] net: dsa: microchip: Add KSZ8463 tail tag handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260127-ksz8463-ptp-v4-5-652e021aae86@bootlin.com> References: <20260127-ksz8463-ptp-v4-0-652e021aae86@bootlin.com> In-Reply-To: <20260127-ksz8463-ptp-v4-0-652e021aae86@bootlin.com> To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Simon Horman Cc: Pascal Eberhard , =?utf-8?q?Miqu=C3=A8l_Raynal?= , Thomas Petazzoni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Bastien Curutchet (Schneider Electric)" X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 KSZ8463 uses the KSZ9893 DSA TAG driver. However, the KSZ8463 doesn't use the tail tag to convey timestamps to the host as KSZ9893 does. It uses the reserved fields in the PTP header instead. Add a KSZ8463-specifig DSA_TAG driver to handle KSZ8463 timestamps. There is no information in the tail tag to distinguish PTP packets from others so use the ptp_classify_raw() helper to find the PTP packets and extract the timestamp from their PTP headers. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 5 ++- include/net/dsa.h | 2 + net/dsa/tag_ksz.c | 70 ++++++++++++++++++++++++++++++= ++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 224be307b3417bf30d62da5c94efc6714d914dc6..5141343d2f40bbd380c0b52f691= 9b842fb71a8fd 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3580,8 +3580,10 @@ static enum dsa_tag_protocol ksz_get_tag_protocol(st= ruct dsa_switch *ds, if (ksz_is_ksz87xx(dev) || ksz_is_8895_family(dev)) proto =3D DSA_TAG_PROTO_KSZ8795; =20 + if (dev->chip_id =3D=3D KSZ8463_CHIP_ID) + proto =3D DSA_TAG_PROTO_KSZ8463; + if (dev->chip_id =3D=3D KSZ88X3_CHIP_ID || - dev->chip_id =3D=3D KSZ8463_CHIP_ID || dev->chip_id =3D=3D KSZ8563_CHIP_ID || dev->chip_id =3D=3D KSZ9893_CHIP_ID || dev->chip_id =3D=3D KSZ9563_CHIP_ID) @@ -3611,6 +3613,7 @@ static int ksz_connect_tag_protocol(struct dsa_switch= *ds, return 0; case DSA_TAG_PROTO_KSZ9893: case DSA_TAG_PROTO_KSZ9477: + case DSA_TAG_PROTO_KSZ8463: case DSA_TAG_PROTO_LAN937X: tagger_data =3D ksz_tagger_data(ds); tagger_data->xmit_work_fn =3D ksz_port_deferred_xmit; diff --git a/include/net/dsa.h b/include/net/dsa.h index 6b2b5ed64ea4cee6ab59c9e6eaab30f07f82816a..5b5fed6e6f9171f5875d61c1395= 758065ac5808a 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -57,6 +57,7 @@ struct tc_action; #define DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE 29 #define DSA_TAG_PROTO_YT921X_VALUE 30 #define DSA_TAG_PROTO_MXL_GSW1XX_VALUE 31 +#define DSA_TAG_PROTO_KSZ8463_VALUE 32 =20 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE =3D DSA_TAG_PROTO_NONE_VALUE, @@ -91,6 +92,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_VSC73XX_8021Q =3D DSA_TAG_PROTO_VSC73XX_8021Q_VALUE, DSA_TAG_PROTO_YT921X =3D DSA_TAG_PROTO_YT921X_VALUE, DSA_TAG_PROTO_MXL_GSW1XX =3D DSA_TAG_PROTO_MXL_GSW1XX_VALUE, + DSA_TAG_PROTO_KSZ8463 =3D DSA_TAG_PROTO_KSZ8463_VALUE, }; =20 struct dsa_switch; diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index 9170a0148cc43b4213ec4bd8e81d338589671f23..f6590549908e016ca224501e6bc= 296c9c5feafb3 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -16,6 +16,7 @@ #define KSZ9477_NAME "ksz9477" #define KSZ9893_NAME "ksz9893" #define LAN937X_NAME "lan937x" +#define KSZ8463_NAME "ksz8463" =20 /* Typically only one byte is used for tail tag. */ #define KSZ_PTP_TAG_LEN 4 @@ -383,6 +384,74 @@ static const struct dsa_device_ops ksz9893_netdev_ops = =3D { DSA_TAG_DRIVER(ksz9893_netdev_ops); MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9893, KSZ9893_NAME); =20 +#define KSZ8463_TAIL_TAG_PRIO GENMASK(4, 3) +#define KSZ8463_TAIL_TAG_EG_PORT_M GENMASK(2, 0) + +static struct sk_buff *ksz8463_xmit(struct sk_buff *skb, + struct net_device *dev) +{ + u16 queue_mapping =3D skb_get_queue_mapping(skb); + u8 prio =3D netdev_txq_to_tc(dev, queue_mapping); + struct dsa_port *dp =3D dsa_user_to_port(dev); + u8 *tag; + + if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL && skb_checksum_help(skb)) + return NULL; + + tag =3D skb_put(skb, KSZ_INGRESS_TAG_LEN); + + *tag =3D BIT(dp->index); + *tag |=3D FIELD_PREP(KSZ8463_TAIL_TAG_PRIO, prio); + + return ksz_defer_xmit(dp, skb); +} + +static struct sk_buff *ksz8463_rcv(struct sk_buff *skb, struct net_device = *dev) +{ + unsigned int len =3D KSZ_EGRESS_TAG_LEN; + struct ptp_header *ptp_hdr; + unsigned int ptp_class; + unsigned int port; + ktime_t tstamp; + u8 *tag; + + if (skb_linearize(skb)) + return NULL; + + /* Tag decoding */ + tag =3D skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN; + port =3D tag[0] & KSZ8463_TAIL_TAG_EG_PORT_M; + + __skb_push(skb, ETH_HLEN); + ptp_class =3D ptp_classify_raw(skb); + __skb_pull(skb, ETH_HLEN); + if (ptp_class =3D=3D PTP_CLASS_NONE) + goto common_rcv; + + ptp_hdr =3D ptp_parse_header(skb, ptp_class); + if (ptp_hdr) { + tstamp =3D ksz_decode_tstamp(get_unaligned_be32(&ptp_hdr->reserved2)); + KSZ_SKB_CB(skb)->tstamp =3D tstamp; + ptp_hdr->reserved2 =3D 0; + } + +common_rcv: + return ksz_common_rcv(skb, dev, port, len); +} + +static const struct dsa_device_ops ksz8463_netdev_ops =3D { + .name =3D KSZ8463_NAME, + .proto =3D DSA_TAG_PROTO_KSZ8463, + .xmit =3D ksz8463_xmit, + .rcv =3D ksz8463_rcv, + .connect =3D ksz_connect, + .disconnect =3D ksz_disconnect, + .needed_tailroom =3D KSZ_INGRESS_TAG_LEN, +}; + +DSA_TAG_DRIVER(ksz8463_netdev_ops); +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ8463, KSZ8463_NAME); + /* For xmit, 2/6 bytes are added before FCS. * -----------------------------------------------------------------------= ---- * DA(6bytes)|SA(6bytes)|....|Data(nbytes)|ts(4bytes)|tag0(1byte)|tag1(1by= te)| @@ -457,6 +526,7 @@ static struct dsa_tag_driver *dsa_tag_driver_array[] = =3D { &DSA_TAG_DRIVER_NAME(ksz9477_netdev_ops), &DSA_TAG_DRIVER_NAME(ksz9893_netdev_ops), &DSA_TAG_DRIVER_NAME(lan937x_netdev_ops), + &DSA_TAG_DRIVER_NAME(ksz8463_netdev_ops), }; =20 module_dsa_tag_drivers(dsa_tag_driver_array); --=20 2.52.0