Skip to content

Commit 04508d2

Browse files
danish-tiPaolo Abeni
authored andcommitted
net: ti: icssg-prueth: Add Multicast Filtering support for VLAN in MAC mode
Add multicast filtering support for VLAN interfaces in dual EMAC mode for ICSSG driver. The driver uses vlan_for_each() API to get the list of available vlans. The driver then sync mc addr of vlan interface with a locally mainatined list emac->vlan_mcast_list[vid] using __hw_addr_sync_multiple() API. __hw_addr_sync_multiple() is used instead of __hw_addr_sync() to sync vdev->mc with local list because the sync_cnt for addresses in vdev->mc will already be set by the vlan_dev_set_rx_mode() [net/8021q/vlan_dev.c] and __hw_addr_sync() only syncs when the sync_cnt == 0. Whereas __hw_addr_sync_multiple() can sync addresses even if sync_cnt is not 0. Export __hw_addr_sync_multiple() so that driver can use it. Once the local list is synced, driver calls __hw_addr_sync_dev() with the local list, vdev, sync and unsync callbacks. __hw_addr_sync_dev() is used with the local maintained list as the list to synchronize instead of using __dev_mc_sync() on vdev because __dev_mc_sync() on vdev will call __hw_addr_sync_dev() on vdev->mc and sync_cnt for addresses in vdev->mc will already be set by the vlan_dev_set_rx_mode() [net/8021q/vlan_dev.c] and __hw_addr_sync_dev() only syncs if the sync_cnt of addresses in the list (vdev->mc in this case) is 0. Whereas __hw_addr_sync_dev() on local list will work fine as the sync_cnt for addresses in the local list will still be 0. Based on change in addresses in the local list, sync / unsync callbacks are invoked. In the sync / unsync API in driver, based on whether the ndev is vlan or not, driver passes appropriate vid to FDB helper functions. Signed-off-by: MD Danish Anwar <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 816b02e commit 04508d2

File tree

4 files changed

+66
-17
lines changed

4 files changed

+66
-17
lines changed

drivers/net/ethernet/ti/icssg/icssg_prueth.c

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -561,30 +561,44 @@ const struct icss_iep_clockops prueth_iep_clockops = {
561561

562562
static int icssg_prueth_add_mcast(struct net_device *ndev, const u8 *addr)
563563
{
564-
struct prueth_emac *emac = netdev_priv(ndev);
565-
int port_mask = BIT(emac->port_id);
564+
struct net_device *real_dev;
565+
struct prueth_emac *emac;
566+
int port_mask;
567+
u8 vlan_id;
566568

567-
port_mask |= icssg_fdb_lookup(emac, addr, 0);
568-
icssg_fdb_add_del(emac, addr, 0, port_mask, true);
569-
icssg_vtbl_modify(emac, 0, port_mask, port_mask, true);
569+
vlan_id = is_vlan_dev(ndev) ? vlan_dev_vlan_id(ndev) : PRUETH_DFLT_VLAN_MAC;
570+
real_dev = is_vlan_dev(ndev) ? vlan_dev_real_dev(ndev) : ndev;
571+
emac = netdev_priv(real_dev);
572+
573+
port_mask = BIT(emac->port_id) | icssg_fdb_lookup(emac, addr, vlan_id);
574+
icssg_fdb_add_del(emac, addr, vlan_id, port_mask, true);
575+
icssg_vtbl_modify(emac, vlan_id, port_mask, port_mask, true);
570576

571577
return 0;
572578
}
573579

574580
static int icssg_prueth_del_mcast(struct net_device *ndev, const u8 *addr)
575581
{
576-
struct prueth_emac *emac = netdev_priv(ndev);
577-
int port_mask = BIT(emac->port_id);
582+
struct net_device *real_dev;
583+
struct prueth_emac *emac;
578584
int other_port_mask;
585+
int port_mask;
586+
u8 vlan_id;
587+
588+
vlan_id = is_vlan_dev(ndev) ? vlan_dev_vlan_id(ndev) : PRUETH_DFLT_VLAN_MAC;
589+
real_dev = is_vlan_dev(ndev) ? vlan_dev_real_dev(ndev) : ndev;
590+
emac = netdev_priv(real_dev);
579591

580-
other_port_mask = port_mask ^ icssg_fdb_lookup(emac, addr, 0);
592+
port_mask = BIT(emac->port_id);
593+
other_port_mask = port_mask ^ icssg_fdb_lookup(emac, addr, vlan_id);
581594

582-
icssg_fdb_add_del(emac, addr, 0, port_mask, false);
583-
icssg_vtbl_modify(emac, 0, port_mask, port_mask, false);
595+
icssg_fdb_add_del(emac, addr, vlan_id, port_mask, false);
596+
icssg_vtbl_modify(emac, vlan_id, port_mask, port_mask, false);
584597

585598
if (other_port_mask) {
586-
icssg_fdb_add_del(emac, addr, 0, other_port_mask, true);
587-
icssg_vtbl_modify(emac, 0, other_port_mask, other_port_mask, true);
599+
icssg_fdb_add_del(emac, addr, vlan_id, other_port_mask, true);
600+
icssg_vtbl_modify(emac, vlan_id, other_port_mask,
601+
other_port_mask, true);
588602
}
589603

590604
return 0;
@@ -620,6 +634,25 @@ static int icssg_prueth_hsr_del_mcast(struct net_device *ndev, const u8 *addr)
620634
return 0;
621635
}
622636

637+
static int icssg_update_vlan_mcast(struct net_device *vdev, int vid,
638+
void *args)
639+
{
640+
struct prueth_emac *emac = args;
641+
642+
if (!vdev || !vid)
643+
return 0;
644+
645+
netif_addr_lock_bh(vdev);
646+
__hw_addr_sync_multiple(&emac->vlan_mcast_list[vid], &vdev->mc,
647+
vdev->addr_len);
648+
netif_addr_unlock_bh(vdev);
649+
650+
__hw_addr_sync_dev(&emac->vlan_mcast_list[vid], vdev,
651+
icssg_prueth_add_mcast, icssg_prueth_del_mcast);
652+
653+
return 0;
654+
}
655+
623656
/**
624657
* emac_ndo_open - EMAC device open
625658
* @ndev: network adapter device
@@ -857,12 +890,17 @@ static void emac_ndo_set_rx_mode_work(struct work_struct *work)
857890
return;
858891
}
859892

860-
if (emac->prueth->is_hsr_offload_mode)
893+
if (emac->prueth->is_hsr_offload_mode) {
861894
__dev_mc_sync(ndev, icssg_prueth_hsr_add_mcast,
862895
icssg_prueth_hsr_del_mcast);
863-
else
896+
} else {
864897
__dev_mc_sync(ndev, icssg_prueth_add_mcast,
865898
icssg_prueth_del_mcast);
899+
if (rtnl_trylock()) {
900+
vlan_for_each(ndev, icssg_update_vlan_mcast, emac);
901+
rtnl_unlock();
902+
}
903+
}
866904
}
867905

868906
/**
@@ -913,6 +951,7 @@ static int emac_ndo_vlan_rx_add_vid(struct net_device *ndev,
913951
if (prueth->is_hsr_offload_mode)
914952
port_mask |= BIT(PRUETH_PORT_HOST);
915953

954+
__hw_addr_init(&emac->vlan_mcast_list[vid]);
916955
netdev_dbg(emac->ndev, "VID add vid:%u port_mask:%X untag_mask %X\n",
917956
vid, port_mask, untag_mask);
918957

drivers/net/ethernet/ti/icssg/icssg_prueth.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
#define ICSS_CMD_ADD_FILTER 0x7
8484
#define ICSS_CMD_ADD_MAC 0x8
8585

86+
/* VLAN Filtering Related MACROs */
87+
#define PRUETH_DFLT_VLAN_MAC 0
88+
#define MAX_VLAN_ID 256
89+
8690
/* In switch mode there are 3 real ports i.e. 3 mac addrs.
8791
* however Linux sees only the host side port. The other 2 ports
8892
* are the switch ports.
@@ -200,6 +204,8 @@ struct prueth_emac {
200204
/* RX IRQ Coalescing Related */
201205
struct hrtimer rx_hrtimer;
202206
unsigned long rx_pace_timeout_ns;
207+
208+
struct netdev_hw_addr_list vlan_mcast_list[MAX_VLAN_ID];
203209
};
204210

205211
/**

include/linux/netdevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,6 +4687,9 @@ int devm_register_netdev(struct device *dev, struct net_device *ndev);
46874687
/* General hardware address lists handling functions */
46884688
int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
46894689
struct netdev_hw_addr_list *from_list, int addr_len);
4690+
int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
4691+
struct netdev_hw_addr_list *from_list,
4692+
int addr_len);
46904693
void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
46914694
struct netdev_hw_addr_list *from_list, int addr_len);
46924695
int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,

net/core/dev_addr_lists.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ static void __hw_addr_unsync_one(struct netdev_hw_addr_list *to_list,
242242
__hw_addr_del_entry(from_list, ha, false, false);
243243
}
244244

245-
static int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
246-
struct netdev_hw_addr_list *from_list,
247-
int addr_len)
245+
int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
246+
struct netdev_hw_addr_list *from_list,
247+
int addr_len)
248248
{
249249
int err = 0;
250250
struct netdev_hw_addr *ha, *tmp;
@@ -260,6 +260,7 @@ static int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
260260
}
261261
return err;
262262
}
263+
EXPORT_SYMBOL(__hw_addr_sync_multiple);
263264

264265
/* This function only works where there is a strict 1-1 relationship
265266
* between source and destination of they synch. If you ever need to

0 commit comments

Comments
 (0)