From mboxrd@z Thu Jan 1 00:00:00 1970 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 9DCD836AB5A for ; Mon, 13 Jul 2026 07:11:47 +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=1783926709; cv=none; b=otNsdb+ip+DEzvVMYzIBKyOzuVoTSZQ+vH3Sy3oDWStlyI5hvTsW5f2vLXikEaGmk+Y53AV5sr1lWzRJ6UxA9oU6QT6GYIgou/lFfqmBUGfawLMSt7Yohln/pFuS3PayAb+l1Q2SzZ2D6vDfvAoQAiN2QggMPLUoFa9zJALoDH8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783926709; c=relaxed/simple; bh=KcRnAacbUb1U1qpPj32Xg0y3dcBts07hc7eNi6V5GcI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Eug3KbcPGwr7EBUT7FopIJ7SV1JqA/OJ/MbtwqL9fS+5028jNfQ+z+hCgV110vQt+GesiN7et/Bs5JiukjvJ/jk6ct2C6Hr2o3crsIQfoa94Oivh52KefEbcCP0Zdh9R/j0KsN0rOhupGTzjvSjijbDp5x7BQJE3Stncd0mDJk8= 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=Y8C0t6Zl; 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="Y8C0t6Zl" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 59BAA1A0F8F; Mon, 13 Jul 2026 07:11:42 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2850960341; Mon, 13 Jul 2026 07:11:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 628C311BD3A1E; Mon, 13 Jul 2026 09:11:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1783926701; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=DB/AuADM3cKTTPWyDwbhPOvmCpqeymWC83FnlPAt0eM=; b=Y8C0t6ZlIDOkOVoIQCUBAi2GUlG5tXhA+pzLuqoyIwnwk3NF5LTPTXt7kli8bLNOyO0q07 wN/eKoQFtWYSISWCUsqZCyU3+DozT8r7L4hl5hQu7ZgnZZwo4/C7wgrZVunGtAlEuorJsn omJmc/39vL8PsxWLiLhR91qOgOKcHcR88KwA9os5aPgcxfWYjrt6wuuve40U4WiWVyYYtY KSrvWBlZ76mKsrOyBrb+0agsNc3hOX4yHkAfWgTsv+v7Rd8dP0lysFf6pHtBIkQENLwqUE eFDo6WcJtOnRoMjLTFCh9DVDcMeJtgMBfXkpFo+lJxVNus5whuqr+3LyKaTCJw== From: "Bastien Curutchet (Schneider Electric)" Date: Mon, 13 Jul 2026 09:11:26 +0200 Subject: [PATCH net-next v2 07/10] net: dsa: tag_ksz: share code for KSZ8795 and KSZ9893 xmit operations 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: 7bit Message-Id: <20260713-ksz-new-ptp-v2-7-7209c05058ef@bootlin.com> References: <20260713-ksz-new-ptp-v2-0-7209c05058ef@bootlin.com> In-Reply-To: <20260713-ksz-new-ptp-v2-0-7209c05058ef@bootlin.com> To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Russell King , Simon Horman , Maxime Chevallier 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.3 X-Last-TLS-Session-Version: TLSv1.3 KSZ8795 and KSZ9893 have very similar tag handling in the xmit path, leading to code duplication. There are only two differences between the two ksz*_xmit(): - the KSZ8795 doesn't handle priorities between frames - ksz8795_xmit() directly returns the SKB instead of calling ksz_defer_xmit(). Yet, ksz_defer_xmit() also returns directly the SKB if no clone is present inside the SKB. Clones are only created by the KSZ driver when the PTP feature is enabled. Since KSZ8795 doesn't support PTP, returning the SKB directly or ksz_defer_xmit() is the same. The upcoming support for the KSZ8463 also requires a similar xmit(). Gather the common code from ksz8795_xmit() and ksz9893_xmit() into a new ksz_common_xmit() function that takes three input arguments: - do_tstamp to tell whether ksz_xmit_timestamp() should be called - prio to give the priority tag (if any) - override_mask to give the location of the override bit (if any) Signed-off-by: Bastien Curutchet (Schneider Electric) --- net/dsa/tag_ksz.c | 73 ++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index f58ce0f0e9e4..f8b40437c5fa 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -218,6 +218,37 @@ static struct sk_buff *ksz_defer_xmit(struct dsa_port *dp, struct sk_buff *skb) return NULL; } +static struct sk_buff *ksz_common_xmit(struct sk_buff *skb, + struct net_device *dev, + bool do_tstamp, + u8 prio, + u8 override_mask) +{ + struct dsa_port *dp = dsa_user_to_port(dev); + struct ethhdr *hdr; + u8 *tag; + + if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb)) { + kfree_skb(skb); + return NULL; + } + + /* Tag encoding */ + if (do_tstamp) + ksz_xmit_timestamp(dp, skb); + + tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); + hdr = skb_eth_hdr(skb); + + *tag = dsa_xmit_port_mask(skb, dev); + *tag |= prio; + + if (is_link_local_ether_addr(hdr->h_dest)) + *tag |= override_mask; + + return ksz_defer_xmit(dp, skb); +} + static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, struct net_device *dev) { @@ -308,23 +339,7 @@ MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9477, KSZ9477_NAME); static struct sk_buff *ksz8795_xmit(struct sk_buff *skb, struct net_device *dev) { - struct ethhdr *hdr; - u8 *tag; - - if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb)) { - kfree_skb(skb); - return NULL; - } - - /* Tag encoding */ - tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); - hdr = skb_eth_hdr(skb); - - *tag = dsa_xmit_port_mask(skb, dev); - if (is_link_local_ether_addr(hdr->h_dest)) - *tag |= KSZ8795_TAIL_TAG_OVERRIDE; - - return skb; + return ksz_common_xmit(skb, dev, false, 0, KSZ8795_TAIL_TAG_OVERRIDE); } static struct sk_buff *ksz8795_rcv(struct sk_buff *skb, struct net_device *dev) @@ -362,28 +377,10 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb, { u16 queue_mapping = skb_get_queue_mapping(skb); u8 prio = netdev_txq_to_tc(dev, queue_mapping); - struct dsa_port *dp = dsa_user_to_port(dev); - struct ethhdr *hdr; - u8 *tag; - - if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb)) { - kfree_skb(skb); - return NULL; - } - - /* Tag encoding */ - ksz_xmit_timestamp(dp, skb); - - tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); - hdr = skb_eth_hdr(skb); - - *tag = dsa_xmit_port_mask(skb, dev); - *tag |= FIELD_PREP(KSZ9893_TAIL_TAG_PRIO, prio); - if (is_link_local_ether_addr(hdr->h_dest)) - *tag |= KSZ9893_TAIL_TAG_OVERRIDE; - - return ksz_defer_xmit(dp, skb); + return ksz_common_xmit(skb, dev, true, + FIELD_PREP(KSZ9893_TAIL_TAG_PRIO, prio), + KSZ9893_TAIL_TAG_OVERRIDE); } static const struct dsa_device_ops ksz9893_netdev_ops = { -- 2.54.0