Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: tag_ksz: use the dsa_xmit_port_mask() helper

The "ksz8795", "ksz9893", "ksz9477" and "lan937x" tagging protocols
populate a bit mask for the TX ports.

Unlike the others, "ksz9477" also accelerates HSR packet duplication.

Make the HSR duplication logic available generically to all 4 taggers by
using the dsa_xmit_port_mask() function to set the TX port mask.

Cc: Woojung Huh <woojung.huh@microchip.com>
Cc: UNGLinuxDriver@microchip.com
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20251127120902.292555-6-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
ea659a92 f59e44cc

+4 -16
+4 -16
net/dsa/tag_ksz.c
··· 120 120 121 121 static struct sk_buff *ksz8795_xmit(struct sk_buff *skb, struct net_device *dev) 122 122 { 123 - struct dsa_port *dp = dsa_user_to_port(dev); 124 123 struct ethhdr *hdr; 125 124 u8 *tag; 126 125 ··· 130 131 tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); 131 132 hdr = skb_eth_hdr(skb); 132 133 133 - *tag = 1 << dp->index; 134 + *tag = dsa_xmit_port_mask(skb, dev); 134 135 if (is_link_local_ether_addr(hdr->h_dest)) 135 136 *tag |= KSZ8795_TAIL_TAG_OVERRIDE; 136 137 ··· 293 294 tag = skb_put(skb, KSZ9477_INGRESS_TAG_LEN); 294 295 hdr = skb_eth_hdr(skb); 295 296 296 - val = BIT(dp->index); 297 - 297 + val = dsa_xmit_port_mask(skb, dev); 298 298 val |= FIELD_PREP(KSZ9477_TAIL_TAG_PRIO, prio); 299 299 300 300 if (is_link_local_ether_addr(hdr->h_dest)) 301 301 val |= KSZ9477_TAIL_TAG_OVERRIDE; 302 - 303 - if (dev->features & NETIF_F_HW_HSR_DUP) { 304 - struct net_device *hsr_dev = dp->hsr_dev; 305 - struct dsa_port *other_dp; 306 - 307 - dsa_hsr_foreach_port(other_dp, dp->ds, hsr_dev) 308 - val |= BIT(other_dp->index); 309 - } 310 302 311 303 *tag = cpu_to_be16(val); 312 304 ··· 361 371 tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); 362 372 hdr = skb_eth_hdr(skb); 363 373 364 - *tag = BIT(dp->index); 365 - 374 + *tag = dsa_xmit_port_mask(skb, dev); 366 375 *tag |= FIELD_PREP(KSZ9893_TAIL_TAG_PRIO, prio); 367 376 368 377 if (is_link_local_ether_addr(hdr->h_dest)) ··· 425 436 426 437 tag = skb_put(skb, LAN937X_EGRESS_TAG_LEN); 427 438 428 - val = BIT(dp->index); 429 - 439 + val = dsa_xmit_port_mask(skb, dev); 430 440 val |= FIELD_PREP(LAN937X_TAIL_TAG_PRIO, prio); 431 441 432 442 if (is_link_local_ether_addr(hdr->h_dest))