Skip to content

Commit 2b1d911

Browse files
author
Paolo Abeni
committed
Merge branch 'add-multicast-filtering-support-for-vlan-interface'
MD Danish Anwar says: ==================== Add Multicast Filtering support for VLAN interface This series adds Multicast filtering support for VLAN interfaces in dual EMAC and HSR offload mode for ICSSG driver. Patch 1/4 - Adds support for VLAN in dual EMAC mode Patch 2/4 - Adds MC filtering support for VLAN in dual EMAC mode Patch 3/4 - Create and export hsr_get_port_ndev() in hsr_device.c Patch 4/4 - Adds MC filtering support for VLAN in HSR mode [1] https://lore.kernel.org/all/[email protected]/ [2] https://lore.kernel.org/all/[email protected]/#t [3] https://lore.kernel.org/all/[email protected]/ v1 https://lore.kernel.org/all/[email protected]/ v2 https://lore.kernel.org/all/[email protected]/ v3 https://lore.kernel.org/all/[email protected]/ ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 624d7a8 + 161087d commit 2b1d911

File tree

7 files changed

+173
-59
lines changed

7 files changed

+173
-59
lines changed

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

Lines changed: 128 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -561,61 +561,134 @@ 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;
591605
}
592606

593-
static int icssg_prueth_hsr_add_mcast(struct net_device *ndev, const u8 *addr)
607+
static void icssg_prueth_hsr_fdb_add_del(struct prueth_emac *emac,
608+
const u8 *addr, u8 vid, bool add)
594609
{
595-
struct prueth_emac *emac = netdev_priv(ndev);
596-
struct prueth *prueth = emac->prueth;
597-
598-
icssg_fdb_add_del(emac, addr, prueth->default_vlan,
610+
icssg_fdb_add_del(emac, addr, vid,
599611
ICSSG_FDB_ENTRY_P0_MEMBERSHIP |
600612
ICSSG_FDB_ENTRY_P1_MEMBERSHIP |
601613
ICSSG_FDB_ENTRY_P2_MEMBERSHIP |
602-
ICSSG_FDB_ENTRY_BLOCK, true);
614+
ICSSG_FDB_ENTRY_BLOCK, add);
615+
616+
if (add)
617+
icssg_vtbl_modify(emac, vid, BIT(emac->port_id),
618+
BIT(emac->port_id), add);
619+
}
620+
621+
static int icssg_prueth_hsr_add_mcast(struct net_device *ndev, const u8 *addr)
622+
{
623+
struct net_device *real_dev;
624+
struct prueth_emac *emac;
625+
u8 vlan_id, i;
626+
627+
vlan_id = is_vlan_dev(ndev) ? vlan_dev_vlan_id(ndev) : PRUETH_DFLT_VLAN_HSR;
628+
real_dev = is_vlan_dev(ndev) ? vlan_dev_real_dev(ndev) : ndev;
629+
630+
if (is_hsr_master(real_dev)) {
631+
for (i = HSR_PT_SLAVE_A; i < HSR_PT_INTERLINK; i++) {
632+
emac = netdev_priv(hsr_get_port_ndev(real_dev, i));
633+
if (!emac)
634+
return -EINVAL;
635+
icssg_prueth_hsr_fdb_add_del(emac, addr, vlan_id,
636+
true);
637+
}
638+
} else {
639+
emac = netdev_priv(real_dev);
640+
icssg_prueth_hsr_fdb_add_del(emac, addr, vlan_id, true);
641+
}
603642

604-
icssg_vtbl_modify(emac, emac->port_vlan, BIT(emac->port_id),
605-
BIT(emac->port_id), true);
606643
return 0;
607644
}
608645

609646
static int icssg_prueth_hsr_del_mcast(struct net_device *ndev, const u8 *addr)
610647
{
611-
struct prueth_emac *emac = netdev_priv(ndev);
612-
struct prueth *prueth = emac->prueth;
648+
struct net_device *real_dev;
649+
struct prueth_emac *emac;
650+
u8 vlan_id, i;
651+
652+
vlan_id = is_vlan_dev(ndev) ? vlan_dev_vlan_id(ndev) : PRUETH_DFLT_VLAN_HSR;
653+
real_dev = is_vlan_dev(ndev) ? vlan_dev_real_dev(ndev) : ndev;
654+
655+
if (is_hsr_master(real_dev)) {
656+
for (i = HSR_PT_SLAVE_A; i < HSR_PT_INTERLINK; i++) {
657+
emac = netdev_priv(hsr_get_port_ndev(real_dev, i));
658+
if (!emac)
659+
return -EINVAL;
660+
icssg_prueth_hsr_fdb_add_del(emac, addr, vlan_id,
661+
false);
662+
}
663+
} else {
664+
emac = netdev_priv(real_dev);
665+
icssg_prueth_hsr_fdb_add_del(emac, addr, vlan_id, false);
666+
}
613667

614-
icssg_fdb_add_del(emac, addr, prueth->default_vlan,
615-
ICSSG_FDB_ENTRY_P0_MEMBERSHIP |
616-
ICSSG_FDB_ENTRY_P1_MEMBERSHIP |
617-
ICSSG_FDB_ENTRY_P2_MEMBERSHIP |
618-
ICSSG_FDB_ENTRY_BLOCK, false);
668+
return 0;
669+
}
670+
671+
static int icssg_update_vlan_mcast(struct net_device *vdev, int vid,
672+
void *args)
673+
{
674+
struct prueth_emac *emac = args;
675+
676+
if (!vdev || !vid)
677+
return 0;
678+
679+
netif_addr_lock_bh(vdev);
680+
__hw_addr_sync_multiple(&emac->vlan_mcast_list[vid], &vdev->mc,
681+
vdev->addr_len);
682+
netif_addr_unlock_bh(vdev);
683+
684+
if (emac->prueth->is_hsr_offload_mode)
685+
__hw_addr_sync_dev(&emac->vlan_mcast_list[vid], vdev,
686+
icssg_prueth_hsr_add_mcast,
687+
icssg_prueth_hsr_del_mcast);
688+
else
689+
__hw_addr_sync_dev(&emac->vlan_mcast_list[vid], vdev,
690+
icssg_prueth_add_mcast,
691+
icssg_prueth_del_mcast);
619692

620693
return 0;
621694
}
@@ -857,12 +930,22 @@ static void emac_ndo_set_rx_mode_work(struct work_struct *work)
857930
return;
858931
}
859932

860-
if (emac->prueth->is_hsr_offload_mode)
933+
if (emac->prueth->is_hsr_offload_mode) {
861934
__dev_mc_sync(ndev, icssg_prueth_hsr_add_mcast,
862935
icssg_prueth_hsr_del_mcast);
863-
else
936+
if (rtnl_trylock()) {
937+
vlan_for_each(emac->prueth->hsr_dev,
938+
icssg_update_vlan_mcast, emac);
939+
rtnl_unlock();
940+
}
941+
} else {
864942
__dev_mc_sync(ndev, icssg_prueth_add_mcast,
865943
icssg_prueth_del_mcast);
944+
if (rtnl_trylock()) {
945+
vlan_for_each(ndev, icssg_update_vlan_mcast, emac);
946+
rtnl_unlock();
947+
}
948+
}
866949
}
867950

868951
/**
@@ -907,19 +990,19 @@ static int emac_ndo_vlan_rx_add_vid(struct net_device *ndev,
907990
{
908991
struct prueth_emac *emac = netdev_priv(ndev);
909992
struct prueth *prueth = emac->prueth;
993+
int port_mask = BIT(emac->port_id);
910994
int untag_mask = 0;
911-
int port_mask;
912995

913-
if (prueth->is_hsr_offload_mode) {
914-
port_mask = BIT(PRUETH_PORT_HOST) | BIT(emac->port_id);
915-
untag_mask = 0;
996+
if (prueth->is_hsr_offload_mode)
997+
port_mask |= BIT(PRUETH_PORT_HOST);
916998

917-
netdev_dbg(emac->ndev, "VID add vid:%u port_mask:%X untag_mask %X\n",
918-
vid, port_mask, untag_mask);
999+
__hw_addr_init(&emac->vlan_mcast_list[vid]);
1000+
netdev_dbg(emac->ndev, "VID add vid:%u port_mask:%X untag_mask %X\n",
1001+
vid, port_mask, untag_mask);
1002+
1003+
icssg_vtbl_modify(emac, vid, port_mask, untag_mask, true);
1004+
icssg_set_pvid(emac->prueth, vid, emac->port_id);
9191005

920-
icssg_vtbl_modify(emac, vid, port_mask, untag_mask, true);
921-
icssg_set_pvid(emac->prueth, vid, emac->port_id);
922-
}
9231006
return 0;
9241007
}
9251008

@@ -928,18 +1011,16 @@ static int emac_ndo_vlan_rx_del_vid(struct net_device *ndev,
9281011
{
9291012
struct prueth_emac *emac = netdev_priv(ndev);
9301013
struct prueth *prueth = emac->prueth;
1014+
int port_mask = BIT(emac->port_id);
9311015
int untag_mask = 0;
932-
int port_mask;
9331016

934-
if (prueth->is_hsr_offload_mode) {
1017+
if (prueth->is_hsr_offload_mode)
9351018
port_mask = BIT(PRUETH_PORT_HOST);
936-
untag_mask = 0;
9371019

938-
netdev_dbg(emac->ndev, "VID del vid:%u port_mask:%X untag_mask %X\n",
939-
vid, port_mask, untag_mask);
1020+
netdev_dbg(emac->ndev, "VID del vid:%u port_mask:%X untag_mask %X\n",
1021+
vid, port_mask, untag_mask);
1022+
icssg_vtbl_modify(emac, vid, port_mask, untag_mask, false);
9401023

941-
icssg_vtbl_modify(emac, vid, port_mask, untag_mask, false);
942-
}
9431024
return 0;
9441025
}
9451026

@@ -1254,7 +1335,7 @@ static int prueth_netdevice_port_link(struct net_device *ndev,
12541335
if (prueth->br_members & BIT(PRUETH_PORT_MII0) &&
12551336
prueth->br_members & BIT(PRUETH_PORT_MII1)) {
12561337
prueth->is_switch_mode = true;
1257-
prueth->default_vlan = 1;
1338+
prueth->default_vlan = PRUETH_DFLT_VLAN_SW;
12581339
emac->port_vlan = prueth->default_vlan;
12591340
icssg_change_mode(prueth);
12601341
}
@@ -1312,7 +1393,7 @@ static int prueth_hsr_port_link(struct net_device *ndev)
13121393
NETIF_PRUETH_HSR_OFFLOAD_FEATURES))
13131394
return -EOPNOTSUPP;
13141395
prueth->is_hsr_offload_mode = true;
1315-
prueth->default_vlan = 1;
1396+
prueth->default_vlan = PRUETH_DFLT_VLAN_HSR;
13161397
emac0->port_vlan = prueth->default_vlan;
13171398
emac1->port_vlan = prueth->default_vlan;
13181399
icssg_change_mode(prueth);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
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_HSR 1
88+
#define PRUETH_DFLT_VLAN_SW 1
89+
#define PRUETH_DFLT_VLAN_MAC 0
90+
#define MAX_VLAN_ID 256
91+
8692
/* In switch mode there are 3 real ports i.e. 3 mac addrs.
8793
* however Linux sees only the host side port. The other 2 ports
8894
* are the switch ports.
@@ -200,6 +206,8 @@ struct prueth_emac {
200206
/* RX IRQ Coalescing Related */
201207
struct hrtimer rx_hrtimer;
202208
unsigned long rx_pace_timeout_ns;
209+
210+
struct netdev_hw_addr_list vlan_mcast_list[MAX_VLAN_ID];
203211
};
204212

205213
/**

include/linux/if_hsr.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ enum hsr_version {
1313
PRP_V1,
1414
};
1515

16+
enum hsr_port_type {
17+
HSR_PT_NONE = 0, /* Must be 0, used by framereg */
18+
HSR_PT_SLAVE_A,
19+
HSR_PT_SLAVE_B,
20+
HSR_PT_INTERLINK,
21+
HSR_PT_MASTER,
22+
HSR_PT_PORTS, /* This must be the last item in the enum */
23+
};
24+
1625
/* HSR Tag.
1726
* As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB,
1827
* path, LSDU_size, sequence Nr }. But we let eth_header() create { h_dest,
@@ -32,6 +41,8 @@ struct hsr_tag {
3241
#if IS_ENABLED(CONFIG_HSR)
3342
extern bool is_hsr_master(struct net_device *dev);
3443
extern int hsr_get_version(struct net_device *dev, enum hsr_version *ver);
44+
struct net_device *hsr_get_port_ndev(struct net_device *ndev,
45+
enum hsr_port_type pt);
3546
#else
3647
static inline bool is_hsr_master(struct net_device *dev)
3748
{
@@ -42,6 +53,12 @@ static inline int hsr_get_version(struct net_device *dev,
4253
{
4354
return -EINVAL;
4455
}
56+
57+
static inline struct net_device *hsr_get_port_ndev(struct net_device *ndev,
58+
enum hsr_port_type pt)
59+
{
60+
return ERR_PTR(-EINVAL);
61+
}
4562
#endif /* CONFIG_HSR */
4663

4764
#endif /*_LINUX_IF_HSR_H_*/

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

net/hsr/hsr_device.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,19 @@ bool is_hsr_master(struct net_device *dev)
663663
}
664664
EXPORT_SYMBOL(is_hsr_master);
665665

666+
struct net_device *hsr_get_port_ndev(struct net_device *ndev,
667+
enum hsr_port_type pt)
668+
{
669+
struct hsr_priv *hsr = netdev_priv(ndev);
670+
struct hsr_port *port;
671+
672+
hsr_for_each_port(hsr, port)
673+
if (port->type == pt)
674+
return port->dev;
675+
return NULL;
676+
}
677+
EXPORT_SYMBOL(hsr_get_port_ndev);
678+
666679
/* Default multicast address for HSR Supervision frames */
667680
static const unsigned char def_multicast_addr[ETH_ALEN] __aligned(2) = {
668681
0x01, 0x15, 0x4e, 0x00, 0x01, 0x00

net/hsr/hsr_main.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,6 @@ struct hsrv1_ethhdr_sp {
121121
struct hsr_sup_tag hsr_sup;
122122
} __packed;
123123

124-
enum hsr_port_type {
125-
HSR_PT_NONE = 0, /* Must be 0, used by framereg */
126-
HSR_PT_SLAVE_A,
127-
HSR_PT_SLAVE_B,
128-
HSR_PT_INTERLINK,
129-
HSR_PT_MASTER,
130-
HSR_PT_PORTS, /* This must be the last item in the enum */
131-
};
132-
133124
/* PRP Redunancy Control Trailor (RCT).
134125
* As defined in IEC-62439-4:2012, the PRP RCT is really { sequence Nr,
135126
* Lan indentifier (LanId), LSDU_size and PRP_suffix = 0x88FB }.

0 commit comments

Comments
 (0)