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

net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user()

A new tagging protocol implementation based on tag_8021q is on the
horizon, and it appears that it also has to open-code the complicated
logic of finding a source port based on a VLAN header.

Create a single dsa_tag_8021q_find_user() and make sja1105 call it.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Link: https://patch.msgid.link/20240713211620.1125910-7-paweldembicki@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
d124cf54 823e5cc1

+24 -17
+16 -3
net/dsa/tag_8021q.c
··· 468 468 } 469 469 EXPORT_SYMBOL_GPL(dsa_8021q_xmit); 470 470 471 - struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, 472 - int vbid) 471 + static struct net_device * 472 + dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid) 473 473 { 474 474 struct dsa_port *cpu_dp = conduit->dsa_ptr; 475 475 struct dsa_switch_tree *dst = cpu_dp->dst; ··· 495 495 496 496 return NULL; 497 497 } 498 - EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); 498 + 499 + struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit, 500 + int source_port, int switch_id, 501 + int vid, int vbid) 502 + { 503 + /* Always prefer precise source port information, if available */ 504 + if (source_port != -1 && switch_id != -1) 505 + return dsa_conduit_find_user(conduit, switch_id, source_port); 506 + else if (vbid >= 1) 507 + return dsa_tag_8021q_find_port_by_vbid(conduit, vbid); 508 + 509 + return dsa_find_designated_bridge_port_by_vid(conduit, vid); 510 + } 511 + EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_user); 499 512 500 513 /** 501 514 * dsa_8021q_rcv - Decode source information from tag_8021q header
+3 -2
net/dsa/tag_8021q.h
··· 16 16 void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, 17 17 int *vbid, int *vid); 18 18 19 - struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, 20 - int vbid); 19 + struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit, 20 + int source_port, int switch_id, 21 + int vid, int vbid); 21 22 22 23 int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds, 23 24 struct dsa_notifier_tag_8021q_vlan_info *info);
+5 -12
net/dsa/tag_sja1105.c
··· 509 509 */ 510 510 return NULL; 511 511 512 - if (source_port != -1 && switch_id != -1) 513 - skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); 514 - else if (vbid >= 1) 515 - skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); 516 - else 517 - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); 512 + skb->dev = dsa_tag_8021q_find_user(netdev, source_port, switch_id, 513 + vid, vbid); 518 514 if (!skb->dev) { 519 515 netdev_warn(netdev, "Couldn't decode source port\n"); 520 516 return NULL; ··· 648 652 if (likely(sja1105_skb_has_tag_8021q(skb))) 649 653 dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); 650 654 651 - if (source_port != -1 && switch_id != -1) 652 - skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); 653 - else if (vbid >= 1) 654 - skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); 655 - else 656 - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); 655 + skb->dev = dsa_tag_8021q_find_user(netdev, source_port, switch_id, 656 + vid, vbid); 657 + 657 658 if (!skb->dev) { 658 659 netdev_warn(netdev, "Couldn't decode source port\n"); 659 660 return NULL;