Skip to contentSkip to conversation

net: xilinx: axienet: Multicast fixes and improvements

PATCH Superseded Sean Anderson 3 participants 14 messages Aug 15, 2024 – Aug 22, 2024

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover net: xilinx: axienet: Multicast fixes and improvements

This series has a few small patches improving the handling of multicast addresses. In particular, it makes the driver a whole lot less spammy, and adjusts things so we aren't in promiscuous mode when we have more than four multicast addresses (a common occurance on modern systems).

As the hardware has a 4-entry CAM, the ideal method would be to "pack" multiple addresses into one CAM entry. Something like:

entry.address = address[0] | address[1];
entry.mask = ~(address[0] ^ address[1]);

Which would make the entry match both addresses (along with some others that would need to be filtered in software).

Mapping addresses to entries in an efficient way is a bit tricky. If anyone knows of an in-tree example of something like this, I'd be glad to hear about it.

Changes in v2:
- Split off IFF_PROMISC change from printing changes

Sean Anderson (5):
net: xilinx: axienet: Always disable promiscuous mode
net: xilinx: axienet: Fix dangling multicast addresses
net: xilinx: axienet: Don't print if we go into promiscuous mode
net: xilinx: axienet: Don't set IFF_PROMISC in ndev->flags
net: xilinx: axienet: Support IFF_ALLMULTI

 drivers/net/ethernet/xilinx/xilinx_axienet.h  |  3 ++
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 52 +++++++++----------
 2 files changed, 29 insertions(+), 26 deletions(-)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#1 lore raw

PATCH v2 1/5 net: xilinx: axienet: Always disable promiscuous mode

If promiscuous mode is disabled when there are fewer than four multicast addresses, then it will to be reflected in the hardware. Fix this by always clearing the promiscuous mode flag even when we program multicast addresses.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

---

(no changes since v1)

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +4 -0
index ca04c298daa2..e664611c29cf 100644
@@ -451,6 +451,10 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 	} else if (!netdev_mc_empty(ndev)) {
 		struct netdev_hw_addr *ha;
 
+		reg = axienet_ior(lp, XAE_FMI_OFFSET);
+		reg &= ~XAE_FMI_PM_MASK;
+		axienet_iow(lp, XAE_FMI_OFFSET, reg);
+
 		i = 0;
 		netdev_for_each_mc_addr(ha, ndev) {
 			if (i >= XAE_MULTICAST_CAM_TABLE_NUM)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
maintainer
#2 lore raw

Re: [PATCH net-next v2 1/5] net: xilinx: axienet: Always disable promiscuous mode

Quoted 2 lines · On Thu, 15 Aug 2024 15:36:10 -0400 Sean Anderson wrote:

If promiscuous mode is disabled when there are fewer than four multicast addresses, then it will to be reflected in the hardware. Fix this by

it will *not* be reflected?
Something is off with this commit messages, or at least I can't parse

Quoted 4 lines

always clearing the promiscuous mode flag even when we program multicast addresses.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

I think we should ship it as a fix to net?

#3 lore raw

Re: [PATCH net-next v2 1/5] net: xilinx: axienet: Always disable promiscuous mode

Quoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 15 Aug 2024 15:36:10 -0400 Sean Anderson wrote:

If promiscuous mode is disabled when there are fewer than four multicast addresses, then it will to be reflected in the hardware. Fix this by

it will *not* be reflected?
Something is off with this commit messages, or at least I can't parse

Quoted 6 lines
Quoted 4 lines

always clearing the promiscuous mode flag even when we program multicast addresses.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

I think we should ship it as a fix to net?

Yes, probably. I put these patches first so they could be easily cherry-picked.

--Sean

#4 lore raw

Re: [PATCH net-next v2 1/5] net: xilinx: axienet: Always disable promiscuous mode

Quoted 8 lines · Sean Anderson
Quoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 15 Aug 2024 15:36:10 -0400 Sean Anderson wrote:

If promiscuous mode is disabled when there are fewer than four multicast addresses, then it will to be reflected in the hardware. Fix this by

it will *not* be reflected?
Something is off with this commit messages, or at least I can't parse

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

always clearing the promiscuous mode flag even when we program multicast addresses.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

I think we should ship it as a fix to net?

Yes, probably. I put these patches first so they could be easily cherry-picked.

OK, so to be clear: how should I send these patches?

--Sean

maintainer
#5 lore raw

Re: [PATCH net-next v2 1/5] net: xilinx: axienet: Always disable promiscuous mode

Quoted 3 lines · On Thu, 22 Aug 2024 10:25:06 -0400 Sean Anderson wrote:
Quoted 1 line

Yes, probably. I put these patches first so they could be easily cherry-picked.

OK, so to be clear: how should I send these patches?

You gotta rebase and repost the first two -- I would have taken them directly to net from this posting but there is a conflict on patch 2 (as mentioned there).

Could you repost the first two rebased ASAP? (You can leave the rename of i for the net-next series). I'm literally prepping the PR net->Linus right now, if you post soon they will be cross-merged into net-next by EOD, making it easier to merge the rest.

#6 lore raw

PATCH v2 2/5 net: xilinx: axienet: Fix dangling multicast addresses

In reply to Sean Anderson

If a multicast address is removed but there are still some multicast addresses, that address would remain programmed into the frame filter. Fix this by explicitly setting the enable bit for each filter.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

---

(no changes since v1)

 drivers/net/ethernet/xilinx/xilinx_axienet.h  |  1 +
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 21 ++++++++-----------
 2 files changed, 10 insertions(+), 12 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +1 -0
index 0d5b300107e0..03fef656478e 100644
@@ -170,6 +170,7 @@
 #define XAE_UAW0_OFFSET		0x00000700 /* Unicast address word 0 */
 #define XAE_UAW1_OFFSET		0x00000704 /* Unicast address word 1 */
 #define XAE_FMI_OFFSET		0x00000708 /* Filter Mask Index */
+#define XAE_FFE_OFFSET		0x0000070C /* Frame Filter Enable */
 #define XAE_AF0_OFFSET		0x00000710 /* Address Filter 0 */
 #define XAE_AF1_OFFSET		0x00000714 /* Address Filter 1 */
 
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +9 -12
index e664611c29cf..1bcabb016ca9 100644
@@ -433,7 +433,7 @@ static int netdev_set_mac_address(struct net_device *ndev, void *p)
  */
 static void axienet_set_multicast_list(struct net_device *ndev)
 {
-	int i;
+	int i = 0;
 	u32 reg, af0reg, af1reg;
 	struct axienet_local *lp = netdev_priv(ndev);
 
@@ -455,7 +455,6 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 		reg &= ~XAE_FMI_PM_MASK;
 		axienet_iow(lp, XAE_FMI_OFFSET, reg);
 
-		i = 0;
 		netdev_for_each_mc_addr(ha, ndev) {
 			if (i >= XAE_MULTICAST_CAM_TABLE_NUM)
 				break;
@@ -474,6 +473,7 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 			axienet_iow(lp, XAE_FMI_OFFSET, reg);
 			axienet_iow(lp, XAE_AF0_OFFSET, af0reg);
 			axienet_iow(lp, XAE_AF1_OFFSET, af1reg);
+			axienet_iow(lp, XAE_FFE_OFFSET, 1);
 			i++;
 		}
 	} else {
@@ -481,18 +481,15 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 		reg &= ~XAE_FMI_PM_MASK;
 
 		axienet_iow(lp, XAE_FMI_OFFSET, reg);
-
-		for (i = 0; i < XAE_MULTICAST_CAM_TABLE_NUM; i++) {
-			reg = axienet_ior(lp, XAE_FMI_OFFSET) & 0xFFFFFF00;
-			reg |= i;
-
-			axienet_iow(lp, XAE_FMI_OFFSET, reg);
-			axienet_iow(lp, XAE_AF0_OFFSET, 0);
-			axienet_iow(lp, XAE_AF1_OFFSET, 0);
-		}
-
 		dev_info(&ndev->dev, "Promiscuous mode disabled.\n");
 	}
+
+	for (; i < XAE_MULTICAST_CAM_TABLE_NUM; i++) {
+		reg = axienet_ior(lp, XAE_FMI_OFFSET) & 0xFFFFFF00;
+		reg |= i;
+		axienet_iow(lp, XAE_FMI_OFFSET, reg);
+		axienet_iow(lp, XAE_FFE_OFFSET, 0);
+	}
 }
 
 /**
Signature · 1 line
2.35.1.1320.gc452695387.dirty
maintainer
#7 lore raw

Re: [PATCH net-next v2 2/5] net: xilinx: axienet: Fix dangling multicast addresses

Quoted 7 lines · On Thu, 15 Aug 2024 15:36:11 -0400 Sean Anderson wrote:

If a multicast address is removed but there are still some multicast addresses, that address would remain programmed into the frame filter. Fix this by explicitly setting the enable bit for each filter.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

Again, I'd go for net.

drivers/net/ethernet/xilinx/xilinx_axienet.h line 175

Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet.h +1 -0
index 0d5b300107e0..03fef656478e 100644
@@ -170,6 +170,7 @@
 #define XAE_UAW0_OFFSET		0x00000700 /* Unicast address word 0 */
 #define XAE_UAW1_OFFSET		0x00000704 /* Unicast address word 1 */
 #define XAE_FMI_OFFSET		0x00000708 /* Filter Mask Index */
+#define XAE_FFE_OFFSET		0x0000070C /* Frame Filter Enable */
 #define XAE_AF0_OFFSET		0x00000710 /* Address Filter 0 */
 #define XAE_AF1_OFFSET		0x00000714 /* Address Filter 1 */

There is a conflict with current net / net-next here, because of 9ff2f816e2aa65ca9, you'll need to rebase / repost (which is why I'm allowing myself the nit picks ;))

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int netdev_set_mac_address(struct net_device *ndev, void *p) · line 436

Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
index e664611c29cf..1bcabb016ca9 100644
@@ -433,7 +433,7 @@ static int netdev_set_mac_address(struct net_device *ndev, void *p)
  */
 static void axienet_set_multicast_list(struct net_device *ndev)
 {
-	int i;
+	int i = 0;

Consider renaming i to addr_cnt ? or addr_num ?

#8 lore raw

Re: [PATCH net-next v2 2/5] net: xilinx: axienet: Fix dangling multicast addresses

Quoted 27 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 15 Aug 2024 15:36:11 -0400 Sean Anderson wrote:

If a multicast address is removed but there are still some multicast addresses, that address would remain programmed into the frame filter. Fix this by explicitly setting the enable bit for each filter.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

Again, I'd go for net.

drivers/net/ethernet/xilinx/xilinx_axienet.h line 175

Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet.h +1 -0
index 0d5b300107e0..03fef656478e 100644
@@ -170,6 +170,7 @@
 #define XAE_UAW0_OFFSET		0x00000700 /* Unicast address word 0 */
 #define XAE_UAW1_OFFSET		0x00000704 /* Unicast address word 1 */
 #define XAE_FMI_OFFSET		0x00000708 /* Filter Mask Index */
+#define XAE_FFE_OFFSET		0x0000070C /* Frame Filter Enable */
 #define XAE_AF0_OFFSET		0x00000710 /* Address Filter 0 */
 #define XAE_AF1_OFFSET		0x00000714 /* Address Filter 1 */

There is a conflict with current net / net-next here, because of 9ff2f816e2aa65ca9, you'll need to rebase / repost (which is why I'm allowing myself the nit picks ;))

Quoted 12 lines

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int netdev_set_mac_address(struct net_device *ndev, void *p) · line 436

Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
index e664611c29cf..1bcabb016ca9 100644
@@ -433,7 +433,7 @@ static int netdev_set_mac_address(struct net_device *ndev, void *p)
  */
 static void axienet_set_multicast_list(struct net_device *ndev)
 {
-	int i;
+	int i = 0;

Consider renaming i to addr_cnt ? or addr_num ?

Well, this doesn't really have anything to do with addresses. It selects the "Filter Index" (as named by the datasheet) so I'd rename it filter if anything.

This hardware is actually really unusual since the CAM acts on the entire first 64 bytes of the packet. So you could theoretically filter for the source address too, but I don't know why you'd want to since all you can do is drop the packet. Seems like a big waste of resources to me.

--Sean

#9 lore raw

PATCH v2 3/5 net: xilinx: axienet: Don't print if we go into promiscuous mode

In reply to Sean Anderson

A message about being in promiscuous mode is printed every time each additional multicast address beyond four is added. Suppress this message like is done in other drivers.

---

Changes in v2:
- Split off IFF_PROMISC change

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -2
index 1bcabb016ca9..9382ce50aeb2 100644
@@ -447,7 +447,6 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 		reg = axienet_ior(lp, XAE_FMI_OFFSET);
 		reg |= XAE_FMI_PM_MASK;
 		axienet_iow(lp, XAE_FMI_OFFSET, reg);
-		dev_info(&ndev->dev, "Promiscuous mode enabled.\n");
 	} else if (!netdev_mc_empty(ndev)) {
 		struct netdev_hw_addr *ha;
 
@@ -481,7 +480,6 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 		reg &= ~XAE_FMI_PM_MASK;
 
 		axienet_iow(lp, XAE_FMI_OFFSET, reg);
-		dev_info(&ndev->dev, "Promiscuous mode disabled.\n");
 	}
 
 	for (; i < XAE_MULTICAST_CAM_TABLE_NUM; i++) {
Signature · 1 line
2.35.1.1320.gc452695387.dirty
reviewer Reviewed-by on v2 3/5
#10 lore raw

Re: [PATCH net-next v2 3/5] net: xilinx: axienet: Don't print if we go into promiscuous mode

Quoted 9 lines · Sean Anderson

A message about being in promiscuous mode is printed every time each additional multicast address beyond four is added. Suppress this message like is done in other drivers.

---

Changes in v2:
- Split off IFF_PROMISC change

#11 lore raw

PATCH v2 4/5 net: xilinx: axienet: Don't set IFF_PROMISC in ndev->flags

In reply to Sean Anderson

Contrary to the comment, we don't have to inform the net subsystem.

---

Changes in v2:
- Split off from printing changes

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -5
index 9382ce50aeb2..9bcad515f156 100644
@@ -439,11 +439,6 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 
 	if (ndev->flags & (IFF_ALLMULTI | IFF_PROMISC) ||
 	    netdev_mc_count(ndev) > XAE_MULTICAST_CAM_TABLE_NUM) {
-		/* We must make the kernel realize we had to move into
-		 * promiscuous mode. If it was a promiscuous mode request
-		 * the flag is already set. If not we set it.
-		 */
-		ndev->flags |= IFF_PROMISC;
 		reg = axienet_ior(lp, XAE_FMI_OFFSET);
 		reg |= XAE_FMI_PM_MASK;
 		axienet_iow(lp, XAE_FMI_OFFSET, reg);
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#13 lore raw

PATCH v2 5/5 net: xilinx: axienet: Support IFF_ALLMULTI

In reply to Sean Anderson

Add support for IFF_ALLMULTI by configuring a single filter to match the multicast address bit. This allows us to keep promiscuous mode disabled, even when we have more than four multicast addresses. An even better solution would be to "pack" addresses into the available CAM registers, but that can wait for a future series.

---

(no changes since v1)

 drivers/net/ethernet/xilinx/xilinx_axienet.h  |  2 ++
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 34 +++++++++++--------
 2 files changed, 22 insertions(+), 14 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -0
index 03fef656478e..d1b68a040f5a 100644
@@ -173,6 +173,8 @@
 #define XAE_FFE_OFFSET		0x0000070C /* Frame Filter Enable */
 #define XAE_AF0_OFFSET		0x00000710 /* Address Filter 0 */
 #define XAE_AF1_OFFSET		0x00000714 /* Address Filter 1 */
+#define XAE_AM0_OFFSET		0x00000750 /* Frame Filter Mask Value Bytes 3-0 */
+#define XAE_AM1_OFFSET		0x00000754 /* Frame Filter Mask Value Bytes 7-4 */
 
 #define XAE_TX_VLAN_DATA_OFFSET 0x00004000 /* TX VLAN data table address */
 #define XAE_RX_VLAN_DATA_OFFSET 0x00008000 /* RX VLAN data table address */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +20 -14
index 9bcad515f156..c420bc753750 100644
@@ -437,18 +437,27 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 	u32 reg, af0reg, af1reg;
 	struct axienet_local *lp = netdev_priv(ndev);
 
-	if (ndev->flags & (IFF_ALLMULTI | IFF_PROMISC) ||
-	    netdev_mc_count(ndev) > XAE_MULTICAST_CAM_TABLE_NUM) {
-		reg = axienet_ior(lp, XAE_FMI_OFFSET);
+	reg = axienet_ior(lp, XAE_FMI_OFFSET);
+	reg &= ~XAE_FMI_PM_MASK;
+	if (ndev->flags & IFF_PROMISC)
 		reg |= XAE_FMI_PM_MASK;
+	else
+		reg &= ~XAE_FMI_PM_MASK;
+	axienet_iow(lp, XAE_FMI_OFFSET, reg);
+
+	if (ndev->flags & IFF_ALLMULTI ||
+	    netdev_mc_count(ndev) > XAE_MULTICAST_CAM_TABLE_NUM) {
+		reg &= 0xFFFFFF00;
 		axienet_iow(lp, XAE_FMI_OFFSET, reg);
+		axienet_iow(lp, XAE_AF0_OFFSET, 1); /* Multicast bit */
+		axienet_iow(lp, XAE_AF1_OFFSET, 0);
+		axienet_iow(lp, XAE_AM0_OFFSET, 1); /* ditto */
+		axienet_iow(lp, XAE_AM1_OFFSET, 0);
+		axienet_iow(lp, XAE_FFE_OFFSET, 1);
+		i = 1;
 	} else if (!netdev_mc_empty(ndev)) {
 		struct netdev_hw_addr *ha;
 
-		reg = axienet_ior(lp, XAE_FMI_OFFSET);
-		reg &= ~XAE_FMI_PM_MASK;
-		axienet_iow(lp, XAE_FMI_OFFSET, reg);
-
 		netdev_for_each_mc_addr(ha, ndev) {
 			if (i >= XAE_MULTICAST_CAM_TABLE_NUM)
 				break;
@@ -461,24 +470,21 @@ static void axienet_set_multicast_list(struct net_device *ndev)
 			af1reg = (ha->addr[4]);
 			af1reg |= (ha->addr[5] << 8);
 
-			reg = axienet_ior(lp, XAE_FMI_OFFSET) & 0xFFFFFF00;
+			reg &= 0xFFFFFF00;
 			reg |= i;
 
 			axienet_iow(lp, XAE_FMI_OFFSET, reg);
 			axienet_iow(lp, XAE_AF0_OFFSET, af0reg);
 			axienet_iow(lp, XAE_AF1_OFFSET, af1reg);
+			axienet_iow(lp, XAE_AM0_OFFSET, 0xffffffff);
+			axienet_iow(lp, XAE_AM1_OFFSET, 0x0000ffff);
 			axienet_iow(lp, XAE_FFE_OFFSET, 1);
 			i++;
 		}
-	} else {
-		reg = axienet_ior(lp, XAE_FMI_OFFSET);
-		reg &= ~XAE_FMI_PM_MASK;
-
-		axienet_iow(lp, XAE_FMI_OFFSET, reg);
 	}
 
 	for (; i < XAE_MULTICAST_CAM_TABLE_NUM; i++) {
-		reg = axienet_ior(lp, XAE_FMI_OFFSET) & 0xFFFFFF00;
+		reg &= 0xFFFFFF00;
 		reg |= i;
 		axienet_iow(lp, XAE_FMI_OFFSET, reg);
 		axienet_iow(lp, XAE_FFE_OFFSET, 0);
Signature · 1 line
2.35.1.1320.gc452695387.dirty