diff mbox series

[RFC,net-next,(resend),3/4] net: dsa: mv88e6xxx: handle member-violations

Message ID 20241108035546.2055996-4-elliot.ayrey@alliedtelesis.co.nz (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Send notifications for roaming hosts | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 82 exceeds 80 columns WARNING: line length of 95 exceeds 80 columns WARNING: line length of 96 exceeds 80 columns WARNING: line length of 97 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Elliot Ayrey Nov. 8, 2024, 3:55 a.m. UTC
Add a handler for servicing member-violations to the mv88e6xxx switch
driver.

When we receive a member-violation from the hardware first check the
ATU for the corresponding entry and only service the interrupt if the
ATU entry has a non-zero DPV and the new port that raised the
interrupt is not in the DPV.

Servicing this interrupt will send a switchdev notification for the
new port.

Signed-off-by: Elliot Ayrey <elliot.ayrey@alliedtelesis.co.nz>
---
 drivers/net/dsa/mv88e6xxx/global1_atu.c | 38 +++++++++++++++++++++++++
 drivers/net/dsa/mv88e6xxx/switchdev.c   | 33 ++++++++++++++++++++-
 drivers/net/dsa/mv88e6xxx/switchdev.h   |  2 ++
 3 files changed, 72 insertions(+), 1 deletion(-)

Comments

Andrew Lunn Nov. 8, 2024, 1:49 p.m. UTC | #1
> --- a/drivers/net/dsa/mv88e6xxx/switchdev.c
> +++ b/drivers/net/dsa/mv88e6xxx/switchdev.c
> @@ -79,5 +79,36 @@ int mv88e6xxx_handle_miss_violation(struct mv88e6xxx_chip *chip, int port,
>  				       brport, &info.info, NULL);
>  	rtnl_unlock();
>  
> -	return err;
> +	return notifier_to_errno(err);
> +}

This change does not look obviously correct to me. What has a miss
violation got to do with member violation? Is the existing code wrong?
What about the case when mv88e6xxx_find_vid() returns an error?

	Andrew
Elliot Ayrey Nov. 11, 2024, 4:39 a.m. UTC | #2
On Fri, 2024-11-08 at 14:49 +0100, Andrew Lunn wrote:
> > --- a/drivers/net/dsa/mv88e6xxx/switchdev.c
> > +++ b/drivers/net/dsa/mv88e6xxx/switchdev.c
> > @@ -79,5 +79,36 @@ int mv88e6xxx_handle_miss_violation(struct
> > mv88e6xxx_chip *chip, int port,
> >  				       brport,
> > &http://scanmail.trustwave.com/?c=20988&d=jZeu528qsdfVmICHdkZAoueog
> > WLEwsN_Wa_RILla0Q&u=http%3a%2f%2finfo%2einfo NULL);
> >  	rtnl_unlock();
> >  
> > -	return err;
> > +	return notifier_to_errno(err);
> > +}
> 
> This change does not look obviously correct to me. What has a miss
> violation got to do with member violation? Is the existing code
> wrong?
> What about the case when mv88e6xxx_find_vid() returns an error?
> 
> 	Andrew

Hi Andrew, I forgot to remove this when preparing the patches, this was
intended to be a separate bug fix.

If mv88e6xxx_find_vid() returns an error it will return early, so the
notifier_to_errno() conversion will only happen after
call_switchdev_notifiers().
diff mbox series

Patch

diff --git a/drivers/net/dsa/mv88e6xxx/global1_atu.c b/drivers/net/dsa/mv88e6xxx/global1_atu.c
index c47f068f56b3..5c5c53cb2ad0 100644
--- a/drivers/net/dsa/mv88e6xxx/global1_atu.c
+++ b/drivers/net/dsa/mv88e6xxx/global1_atu.c
@@ -399,12 +399,36 @@  int mv88e6xxx_g1_atu_remove(struct mv88e6xxx_chip *chip, u16 fid, int port,
 	return mv88e6xxx_g1_atu_move(chip, fid, from_port, to_port, all);
 }
 
+static int mv88e6xxx_g1_atu_entry_check(struct mv88e6xxx_chip *chip, u16 fid, u8 mac[ETH_ALEN],
+					bool *in_atu, u16 *dpv)
+{
+	struct mv88e6xxx_atu_entry entry;
+	int err;
+
+	entry.state = 0;
+	ether_addr_copy(entry.mac, mac);
+	eth_addr_dec(entry.mac);
+
+	mv88e6xxx_reg_lock(chip);
+	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
+	mv88e6xxx_reg_unlock(chip);
+	if (err)
+		return err;
+
+	*in_atu = ether_addr_equal(entry.mac, mac);
+	if (dpv)
+		*dpv = entry.portvec;
+
+	return err;
+}
+
 static irqreturn_t mv88e6xxx_g1_atu_prob_irq_thread_fn(int irq, void *dev_id)
 {
 	struct mv88e6xxx_chip *chip = dev_id;
 	struct mv88e6xxx_atu_entry entry;
 	int err, spid;
 	u16 val, fid;
+	bool in_atu = false;
 
 	mv88e6xxx_reg_lock(chip);
 
@@ -437,6 +461,20 @@  static irqreturn_t mv88e6xxx_g1_atu_prob_irq_thread_fn(int irq, void *dev_id)
 						     entry.portvec, entry.mac,
 						     fid);
 		chip->ports[spid].atu_member_violation++;
+
+		if (fid != MV88E6XXX_FID_STANDALONE && chip->ports[spid].mab) {
+			u16 dpv = 0;
+
+			err = mv88e6xxx_g1_atu_entry_check(chip, fid, entry.mac, &in_atu, &dpv);
+			if (err)
+				goto out;
+
+			if (in_atu && dpv != 0 && !(dpv & BIT(spid))) {
+				err = mv88e6xxx_handle_member_violation(chip, spid, &entry, fid);
+				if (err)
+					goto out;
+			}
+		}
 	}
 
 	if (val & MV88E6XXX_G1_ATU_OP_MISS_VIOLATION) {
diff --git a/drivers/net/dsa/mv88e6xxx/switchdev.c b/drivers/net/dsa/mv88e6xxx/switchdev.c
index 4c346a884fb2..88761677ff10 100644
--- a/drivers/net/dsa/mv88e6xxx/switchdev.c
+++ b/drivers/net/dsa/mv88e6xxx/switchdev.c
@@ -79,5 +79,36 @@  int mv88e6xxx_handle_miss_violation(struct mv88e6xxx_chip *chip, int port,
 				       brport, &info.info, NULL);
 	rtnl_unlock();
 
-	return err;
+	return notifier_to_errno(err);
+}
+
+int mv88e6xxx_handle_member_violation(struct mv88e6xxx_chip *chip, int port,
+				      struct mv88e6xxx_atu_entry *entry, u16 fid)
+{
+	struct switchdev_notifier_fdb_info info = {
+		.addr = entry->mac,
+	};
+	struct net_device *brport;
+	struct dsa_port *dp;
+	u16 vid;
+	int err;
+
+	err = mv88e6xxx_find_vid(chip, fid, &vid);
+	if (err)
+		return err;
+
+	info.vid = vid;
+	dp = dsa_to_port(chip->ds, port);
+
+	rtnl_lock();
+	brport = dsa_port_to_bridge_port(dp);
+	if (!brport) {
+		rtnl_unlock();
+		return -ENODEV;
+	}
+	err = call_switchdev_notifiers(SWITCHDEV_FDB_ADD_TO_BRIDGE,
+				       brport, &info.info, NULL);
+	rtnl_unlock();
+
+	return notifier_to_errno(err);
 }
diff --git a/drivers/net/dsa/mv88e6xxx/switchdev.h b/drivers/net/dsa/mv88e6xxx/switchdev.h
index 62214f9d62b0..f718dbfaf45d 100644
--- a/drivers/net/dsa/mv88e6xxx/switchdev.h
+++ b/drivers/net/dsa/mv88e6xxx/switchdev.h
@@ -15,5 +15,7 @@ 
 int mv88e6xxx_handle_miss_violation(struct mv88e6xxx_chip *chip, int port,
 				    struct mv88e6xxx_atu_entry *entry,
 				    u16 fid);
+int mv88e6xxx_handle_member_violation(struct mv88e6xxx_chip *chip, int port,
+				      struct mv88e6xxx_atu_entry *entry, u16 fid);
 
 #endif /* _MV88E6XXX_SWITCHDEV_H_ */