Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: DENG Qingfang <dqfext@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	netdev@vger.kernel.org (open list:NETWORKING DRIVERS),
	linux-kernel@vger.kernel.org (open list)
Cc: "Ansuel Smith" <ansuelsmth@gmail.com>,
	"Jonathan McDowell" <noodles@earth.li>,
	"Michal Vokáč" <vokac.m@gmail.com>,
	"Christian Lamparter" <chunkeey@gmail.com>,
	"Nishka Dasgupta" <nishkadg.linux@gmail.com>,
	"Xiaofei Shen" <xiaofeis@codeaurora.org>,
	"John Crispin" <john@phrozen.org>,
	"Stefan Lippers-Hollmann" <s.l-h@gmx.de>,
	"Hannu Nyman" <hannu.nyman@iki.fi>,
	"Imran Khan" <gururug@gmail.com>,
	"Frank Wunderlich" <frank-w@public-files.de>,
	"Nick Lowe" <nick.lowe@gmail.com>,
	"André Valentin" <avalentin@vmh.kalnet.hooya.de>
Subject: [RFC net-next 1/3] net: dsa: qca8k: offload bridge flags
Date: Sat,  7 Aug 2021 20:07:24 +0800	[thread overview]
Message-ID: <20210807120726.1063225-2-dqfext@gmail.com> (raw)
In-Reply-To: <20210807120726.1063225-1-dqfext@gmail.com>

The hardware supports controlling per-port flooding and learning.
Do not enable learning by default, instead configure them in
.port_bridge_flags function.

Signed-off-by: DENG Qingfang <dqfext@gmail.com>
---
 drivers/net/dsa/qca8k.c | 60 +++++++++++++++++++++++++++++++++++------
 1 file changed, 52 insertions(+), 8 deletions(-)

diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index 1f63f50f73f1..798bc548e5b0 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -987,10 +987,11 @@ qca8k_setup(struct dsa_switch *ds)
 		return ret;
 	}
 
-	/* Disable forwarding by default on all ports */
+	/* Disable forwarding and learning by default on all ports */
 	for (i = 0; i < QCA8K_NUM_PORTS; i++) {
 		ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
-				QCA8K_PORT_LOOKUP_MEMBER, 0);
+				QCA8K_PORT_LOOKUP_MEMBER |
+				QCA8K_PORT_LOOKUP_LEARN, 0);
 		if (ret)
 			return ret;
 	}
@@ -1028,12 +1029,6 @@ qca8k_setup(struct dsa_switch *ds)
 			if (ret)
 				return ret;
 
-			/* Enable ARP Auto-learning by default */
-			ret = qca8k_reg_set(priv, QCA8K_PORT_LOOKUP_CTRL(i),
-					    QCA8K_PORT_LOOKUP_LEARN);
-			if (ret)
-				return ret;
-
 			/* For port based vlans to work we need to set the
 			 * default egress vid
 			 */
@@ -1504,6 +1499,53 @@ qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
 		  QCA8K_PORT_LOOKUP_STATE_MASK, stp_state);
 }
 
+static int
+qca8k_port_pre_bridge_flags(struct dsa_switch *ds, int port,
+			    struct switchdev_brport_flags flags,
+			    struct netlink_ext_ack *extack)
+{
+	if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
+			   BR_BCAST_FLOOD))
+		return -EINVAL;
+
+	return 0;
+}
+
+static int
+qca8k_port_bridge_flags(struct dsa_switch *ds, int port,
+			struct switchdev_brport_flags flags,
+			struct netlink_ext_ack *extack)
+{
+	struct qca8k_priv *priv = ds->priv;
+	int ret = 0;
+
+	if (!ret && flags.mask & BR_LEARNING)
+		ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
+				QCA8K_PORT_LOOKUP_LEARN,
+				flags.val & BR_LEARNING ?
+				QCA8K_PORT_LOOKUP_LEARN : 0);
+
+	if (!ret && flags.mask & BR_FLOOD)
+		ret = qca8k_rmw(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
+				BIT(port + QCA8K_GLOBAL_FW_CTRL1_UC_DP_S),
+				flags.val & BR_FLOOD ?
+				BIT(port + QCA8K_GLOBAL_FW_CTRL1_UC_DP_S) : 0);
+
+	if (!ret && flags.mask & BR_MCAST_FLOOD)
+		ret = qca8k_rmw(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
+				BIT(port + QCA8K_GLOBAL_FW_CTRL1_MC_DP_S),
+				flags.val & BR_MCAST_FLOOD ?
+				BIT(port + QCA8K_GLOBAL_FW_CTRL1_MC_DP_S) : 0);
+
+	if (!ret && flags.mask & BR_BCAST_FLOOD)
+		ret = qca8k_rmw(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
+				BIT(port + QCA8K_GLOBAL_FW_CTRL1_BC_DP_S),
+				flags.val & BR_BCAST_FLOOD ?
+				BIT(port + QCA8K_GLOBAL_FW_CTRL1_BC_DP_S) : 0);
+
+	return ret;
+}
+
 static int
 qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br)
 {
@@ -1764,6 +1806,8 @@ static const struct dsa_switch_ops qca8k_switch_ops = {
 	.port_change_mtu	= qca8k_port_change_mtu,
 	.port_max_mtu		= qca8k_port_max_mtu,
 	.port_stp_state_set	= qca8k_port_stp_state_set,
+	.port_pre_bridge_flags	= qca8k_port_pre_bridge_flags,
+	.port_bridge_flags	= qca8k_port_bridge_flags,
 	.port_bridge_join	= qca8k_port_bridge_join,
 	.port_bridge_leave	= qca8k_port_bridge_leave,
 	.port_fdb_add		= qca8k_port_fdb_add,
-- 
2.25.1


  reply	other threads:[~2021-08-07 12:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-07 12:07 [RFC net-next 0/3] qca8k bridge flags offload DENG Qingfang
2021-08-07 12:07 ` DENG Qingfang [this message]
2021-08-07 20:45   ` [RFC net-next 1/3] net: dsa: qca8k: offload bridge flags Vladimir Oltean
2021-08-07 12:07 ` [RFC net-next 2/3] net: dsa: qca8k: enable assisted learning on CPU port DENG Qingfang
2021-08-07 22:25   ` Vladimir Oltean
2021-08-08 16:05     ` DENG Qingfang
2021-08-08 21:10       ` Vladimir Oltean
2021-08-10 17:27       ` Andre Valentin
2021-08-10 17:53         ` Vladimir Oltean
2021-08-10 21:09           ` Andre Valentin
2021-08-10 23:33             ` Vladimir Oltean
2021-08-07 12:07 ` [RFC net-next 3/3] net: dsa: tag_qca: set offload_fwd_mark DENG Qingfang
2021-08-07 22:57   ` Vladimir Oltean
2021-08-08 16:12     ` DENG Qingfang
2021-08-08 21:14       ` Vladimir Oltean
2021-08-10  6:57 ` [RFC net-next 0/3] qca8k bridge flags offload Jonathan McDowell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210807120726.1063225-2-dqfext@gmail.com \
    --to=dqfext@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=ansuelsmth@gmail.com \
    --cc=avalentin@vmh.kalnet.hooya.de \
    --cc=chunkeey@gmail.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=frank-w@public-files.de \
    --cc=gururug@gmail.com \
    --cc=hannu.nyman@iki.fi \
    --cc=john@phrozen.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=nick.lowe@gmail.com \
    --cc=nishkadg.linux@gmail.com \
    --cc=noodles@earth.li \
    --cc=olteanv@gmail.com \
    --cc=s.l-h@gmx.de \
    --cc=vivien.didelot@gmail.com \
    --cc=vokac.m@gmail.com \
    --cc=xiaofeis@codeaurora.org \
    --subject='Re: [RFC net-next 1/3] net: dsa: qca8k: offload bridge flags' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).