Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c707d2c

Browse files
Murali Karicherigregkh
authored andcommitted
net: hsr: Add VLAN CTAG filter support
[ Upstream commit 1a8a63a ] This patch adds support for VLAN ctag based filtering at slave devices. The slave ethernet device may be capable of filtering ethernet packets based on VLAN ID. This requires that when the VLAN interface is created over an HSR/PRP interface, it passes the VID information to the associated slave ethernet devices so that it updates the hardware filters to filter ethernet frames based on VID. This patch adds the required functions to propagate the vid information to the slave devices. Signed-off-by: Murali Karicheri <[email protected]> Signed-off-by: MD Danish Anwar <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Stable-dep-of: 8884c69 ("hsr: use rtnl lock when iterating over ports") Signed-off-by: Sasha Levin <[email protected]>
1 parent d74b49b commit c707d2c

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

net/hsr/hsr_device.c

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,77 @@ static void hsr_change_rx_flags(struct net_device *dev, int change)
522522
}
523523
}
524524

525+
static int hsr_ndo_vlan_rx_add_vid(struct net_device *dev,
526+
__be16 proto, u16 vid)
527+
{
528+
bool is_slave_a_added = false;
529+
bool is_slave_b_added = false;
530+
struct hsr_port *port;
531+
struct hsr_priv *hsr;
532+
int ret = 0;
533+
534+
hsr = netdev_priv(dev);
535+
536+
hsr_for_each_port(hsr, port) {
537+
if (port->type == HSR_PT_MASTER ||
538+
port->type == HSR_PT_INTERLINK)
539+
continue;
540+
541+
ret = vlan_vid_add(port->dev, proto, vid);
542+
switch (port->type) {
543+
case HSR_PT_SLAVE_A:
544+
if (ret) {
545+
/* clean up Slave-B */
546+
netdev_err(dev, "add vid failed for Slave-A\n");
547+
if (is_slave_b_added)
548+
vlan_vid_del(port->dev, proto, vid);
549+
return ret;
550+
}
551+
552+
is_slave_a_added = true;
553+
break;
554+
555+
case HSR_PT_SLAVE_B:
556+
if (ret) {
557+
/* clean up Slave-A */
558+
netdev_err(dev, "add vid failed for Slave-B\n");
559+
if (is_slave_a_added)
560+
vlan_vid_del(port->dev, proto, vid);
561+
return ret;
562+
}
563+
564+
is_slave_b_added = true;
565+
break;
566+
default:
567+
break;
568+
}
569+
}
570+
571+
return 0;
572+
}
573+
574+
static int hsr_ndo_vlan_rx_kill_vid(struct net_device *dev,
575+
__be16 proto, u16 vid)
576+
{
577+
struct hsr_port *port;
578+
struct hsr_priv *hsr;
579+
580+
hsr = netdev_priv(dev);
581+
582+
hsr_for_each_port(hsr, port) {
583+
switch (port->type) {
584+
case HSR_PT_SLAVE_A:
585+
case HSR_PT_SLAVE_B:
586+
vlan_vid_del(port->dev, proto, vid);
587+
break;
588+
default:
589+
break;
590+
}
591+
}
592+
593+
return 0;
594+
}
595+
525596
static const struct net_device_ops hsr_device_ops = {
526597
.ndo_change_mtu = hsr_dev_change_mtu,
527598
.ndo_open = hsr_dev_open,
@@ -530,6 +601,8 @@ static const struct net_device_ops hsr_device_ops = {
530601
.ndo_change_rx_flags = hsr_change_rx_flags,
531602
.ndo_fix_features = hsr_fix_features,
532603
.ndo_set_rx_mode = hsr_set_rx_mode,
604+
.ndo_vlan_rx_add_vid = hsr_ndo_vlan_rx_add_vid,
605+
.ndo_vlan_rx_kill_vid = hsr_ndo_vlan_rx_kill_vid,
533606
};
534607

535608
static const struct device_type hsr_type = {
@@ -578,7 +651,8 @@ void hsr_dev_setup(struct net_device *dev)
578651

579652
dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
580653
NETIF_F_GSO_MASK | NETIF_F_HW_CSUM |
581-
NETIF_F_HW_VLAN_CTAG_TX;
654+
NETIF_F_HW_VLAN_CTAG_TX |
655+
NETIF_F_HW_VLAN_CTAG_FILTER;
582656

583657
dev->features = dev->hw_features;
584658

@@ -661,6 +735,10 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
661735
(slave[1]->features & NETIF_F_HW_HSR_FWD))
662736
hsr->fwd_offloaded = true;
663737

738+
if ((slave[0]->features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
739+
(slave[1]->features & NETIF_F_HW_VLAN_CTAG_FILTER))
740+
hsr_dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
741+
664742
res = register_netdevice(hsr_dev);
665743
if (res)
666744
goto err_unregister;

0 commit comments

Comments
 (0)