Skip to contentSkip to conversation

net: sparx5: add mrouter support

PATCH Applied Casper Andersson 3 participants 6 messages Aug 25, 2022 – Aug 29, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover net: sparx5: add mrouter support

This series adds support for multicast router ports to SparX5. To manage mrouter ports the driver must keep track of mdb entries. When adding an mrouter port the driver has to iterate over all mdb entries and modify them accordingly.

v2:
- add bailout in free_mdb
- re-arrange mdb struct to avoid holes
- change devm_kzalloc -> kzalloc
- change GFP_ATOMIC -> GFP_KERNEL
- fix spelling

Casper Andersson (3):
ethernet: Add helpers to recognize addresses mapped to IP multicast
net: sparx5: add list for mdb entries in driver
net: sparx5: add support for mrouter ports

 .../ethernet/microchip/sparx5/sparx5_main.c   |   4 +
 .../ethernet/microchip/sparx5/sparx5_main.h   |  15 +
 .../microchip/sparx5/sparx5_switchdev.c       | 271 ++++++++++++------
 .../ethernet/microchip/sparx5/sparx5_vlan.c   |   7 +
 include/linux/etherdevice.h                   |  22 ++
 5 files changed, 232 insertions(+), 87 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 ethernet: Add helpers to recognize addresses mapped to IP multicast

IP multicast must sometimes be discriminated from non-IP multicast, e.g. when determining the forwarding behavior of a given group in the presence of multicast router ports on an offloaded bridge. Therefore, provide helpers to identify these groups.

---
 include/linux/etherdevice.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
include/linux/etherdevice.h +22 -0
index 92b10e67d5f8..a541f0c4f146 100644
@@ -428,6 +428,28 @@ static inline bool ether_addr_equal_masked(const u8 *addr1, const u8 *addr2,
 	return true;
 }
 
+static inline bool ether_addr_is_ipv4_mcast(const u8 *addr)
+{
+	u8 base[ETH_ALEN] = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
+	u8 mask[ETH_ALEN] = { 0xff, 0xff, 0xff, 0x80, 0x00, 0x00 };
+
+	return ether_addr_equal_masked(addr, base, mask);
+}
+
+static inline bool ether_addr_is_ipv6_mcast(const u8 *addr)
+{
+	u8 base[ETH_ALEN] = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x00 };
+	u8 mask[ETH_ALEN] = { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
+
+	return ether_addr_equal_masked(addr, base, mask);
+}
+
+static inline bool ether_addr_is_ip_mcast(const u8 *addr)
+{
+	return ether_addr_is_ipv4_mcast(addr) ||
+		ether_addr_is_ipv6_mcast(addr);
+}
+
 /**
  * ether_addr_to_u64 - Convert an Ethernet address into a u64 value.
  * @addr: Pointer to a six-byte array containing the Ethernet address
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/3 net: sparx5: add list for mdb entries in driver

In reply to Casper Andersson

Keep track of all mdb entries in software for easy access.

---
 .../ethernet/microchip/sparx5/sparx5_main.c   |   3 +
 .../ethernet/microchip/sparx5/sparx5_main.h   |  13 ++
 .../microchip/sparx5/sparx5_switchdev.c       | 198 ++++++++++--------
 3 files changed, 132 insertions(+), 82 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +3 -0
index 01be7bd84181..ad598cf8ef44 100644
@@ -661,6 +661,9 @@ static int sparx5_start(struct sparx5 *sparx5)
 	queue_delayed_work(sparx5->mact_queue, &sparx5->mact_work,
 			   SPX5_MACT_PULL_DELAY);
 
+	mutex_init(&sparx5->mdb_lock);
+	INIT_LIST_HEAD(&sparx5->mdb_entries);
+
 	err = sparx5_register_netdevs(sparx5);
 	if (err)
 		return err;
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +13 -0
index b197129044b5..3d9e3585eb28 100644
@@ -215,6 +215,15 @@ struct sparx5_skb_cb {
 	unsigned long jiffies;
 };
 
+struct sparx5_mdb_entry {
+	struct list_head list;
+	DECLARE_BITMAP(port_mask, SPX5_PORTS);
+	unsigned char addr[ETH_ALEN];
+	bool cpu_copy;
+	u16 vid;
+	u16 pgid_idx;
+};
+
 #define SPARX5_PTP_TIMEOUT		msecs_to_jiffies(10)
 #define SPARX5_SKB_CB(skb) \
 	((struct sparx5_skb_cb *)((skb)->cb))
@@ -256,6 +265,10 @@ struct sparx5 {
 	struct list_head mact_entries;
 	/* mac table list (mact_entries) mutex */
 	struct mutex mact_lock;
+	/* SW MDB table */
+	struct list_head mdb_entries;
+	/* mdb list mutex */
+	struct mutex mdb_lock;
 	struct delayed_work mact_work;
 	struct workqueue_struct *mact_queue;
 	/* Board specifics */
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +116 -82

240 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/3 net: sparx5: add support for mrouter ports

In reply to Casper Andersson

All multicast should be forwarded to mrouter ports. Mrouter ports must therefore be part of all active multicast groups, and override flooding from being disabled.

---
 .../ethernet/microchip/sparx5/sparx5_main.c   |  1 +
 .../ethernet/microchip/sparx5/sparx5_main.h   |  2 +
 .../microchip/sparx5/sparx5_switchdev.c       | 77 +++++++++++++++++--
 .../ethernet/microchip/sparx5/sparx5_vlan.c   |  7 ++
 4 files changed, 80 insertions(+), 7 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +1 -0
index ad598cf8ef44..bbe41734360e 100644
@@ -277,6 +277,7 @@ static int sparx5_create_port(struct sparx5 *sparx5,
 	spx5_port->custom_etype = 0x8880; /* Vitesse */
 	spx5_port->phylink_pcs.poll = true;
 	spx5_port->phylink_pcs.ops = &sparx5_phylink_pcs_ops;
+	spx5_port->is_mrouter = false;
 	sparx5->ports[config->portno] = spx5_port;
 
 	err = sparx5_port_init(sparx5, spx5_port, &config->conf);
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +2 -0
index 3d9e3585eb28..9b4395b7a9e4 100644
@@ -190,6 +190,7 @@ struct sparx5_port {
 	u8 ptp_cmd;
 	u16 ts_id;
 	struct sk_buff_head tx_skbs;
+	bool is_mrouter;
 };
 
 enum sparx5_core_clockfreq {
@@ -338,6 +339,7 @@ void sparx5_mact_init(struct sparx5 *sparx5);
 
 /* sparx5_vlan.c */
 void sparx5_pgid_update_mask(struct sparx5_port *port, int pgid, bool enable);
+void sparx5_pgid_clear(struct sparx5 *spx5, int pgid);
 void sparx5_pgid_read_mask(struct sparx5 *sparx5, int pgid, u32 portmask[3]);
 void sparx5_update_fwd(struct sparx5 *sparx5);
 void sparx5_vlan_init(struct sparx5 *sparx5);
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +70 -7

129 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c +7 -0
index 37e4ac965849..34f954bbf815 100644
@@ -138,6 +138,13 @@ void sparx5_pgid_update_mask(struct sparx5_port *port, int pgid, bool enable)
 	}
 }
 
+void sparx5_pgid_clear(struct sparx5 *spx5, int pgid)
+{
+	spx5_wr(0, spx5, ANA_AC_PGID_CFG(pgid));
+	spx5_wr(0, spx5, ANA_AC_PGID_CFG1(pgid));
+	spx5_wr(0, spx5, ANA_AC_PGID_CFG2(pgid));
+}
+
 void sparx5_pgid_read_mask(struct sparx5 *spx5, int pgid, u32 portmask[3])
 {
 	portmask[0] = spx5_rd(spx5, ANA_AC_PGID_CFG(pgid));
Signature · 1 line
2.34.1
maintainer Reviewed-by on the v2 series
#4 lore raw
In reply to Casper Andersson

Hi Casper,

Quoted 24 lines · Casper Andersson

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

This series adds support for multicast router ports to SparX5. To manage mrouter ports the driver must keep track of mdb entries. When adding an mrouter port the driver has to iterate over all mdb entries and modify them accordingly.

v2:
- add bailout in free_mdb
- re-arrange mdb struct to avoid holes
- change devm_kzalloc -> kzalloc
- change GFP_ATOMIC -> GFP_KERNEL
- fix spelling

Casper Andersson (3):
  ethernet: Add helpers to recognize addresses mapped to IP multicast
  net: sparx5: add list for mdb entries in driver
  net: sparx5: add support for mrouter ports

 .../ethernet/microchip/sparx5/sparx5_main.c   |   4 + .../ethernet/microchip/sparx5/sparx5_main.h   |  15 + .../microchip/sparx5/sparx5_switchdev.c       | 271 ++++++++++++------ .../ethernet/microchip/sparx5/sparx5_vlan.c   |   7 + include/linux/etherdevice.h                   |  22 ++

Quoted 5 lines
 5 files changed, 232 insertions(+), 87 deletions(-)

--
2.34.1

For this series:

BR
Steen

#5 lore raw
In reply to Casper Andersson
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 5 lines · On Thu, 25 Aug 2022 11:28:34 +0200 you wrote:

This series adds support for multicast router ports to SparX5. To manage mrouter ports the driver must keep track of mdb entries. When adding an mrouter port the driver has to iterate over all mdb entries and modify them accordingly.

Quoted 8 lines

v2:
- add bailout in free_mdb
- re-arrange mdb struct to avoid holes
- change devm_kzalloc -> kzalloc
- change GFP_ATOMIC -> GFP_KERNEL
- fix spelling

[...]

Here is the summary with links:
- [v2,net-next,1/3] ethernet: Add helpers to recognize addresses mapped to IP multicast

    https://git.kernel.org/netdev/net-next/c/e8013f8edaa3
  - [v2,net-next,2/3] net: sparx5: add list for mdb entries in driver
    https://git.kernel.org/netdev/net-next/c/c8a3ea43b5cb
  - [v2,net-next,3/3] net: sparx5: add support for mrouter ports
    https://git.kernel.org/netdev/net-next/c/04e551d66dd8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html