netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
To: "Linus Walleij" <linus.walleij@linaro.org>,
	"Alvin Šipraga" <alsi@bang-olufsen.dk>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Russell King" <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Luiz Angelo Daros de Luca <luizluca@gmail.com>
Subject: [PATCH net-next v6 11/11] net: dsa: realtek: embed dsa_switch into realtek_priv
Date: Fri, 09 Feb 2024 02:03:47 -0300	[thread overview]
Message-ID: <20240209-realtek_reverse-v6-11-0662f8cbc7b5@gmail.com> (raw)
In-Reply-To: <20240209-realtek_reverse-v6-0-0662f8cbc7b5@gmail.com>

Embed dsa_switch within realtek_priv to eliminate the need for a second
memory allocation.

Suggested-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
---
 drivers/net/dsa/realtek/realtek.h   |  2 +-
 drivers/net/dsa/realtek/rtl8365mb.c | 15 +++++++++------
 drivers/net/dsa/realtek/rtl8366rb.c |  3 ++-
 drivers/net/dsa/realtek/rtl83xx.c   | 15 +++++++--------
 4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h
index 864bb9a88f14..b80bfde1ad04 100644
--- a/drivers/net/dsa/realtek/realtek.h
+++ b/drivers/net/dsa/realtek/realtek.h
@@ -61,7 +61,7 @@ struct realtek_priv {
 	const struct realtek_variant *variant;
 
 	spinlock_t		lock; /* Locks around command writes */
-	struct dsa_switch	*ds;
+	struct dsa_switch	ds;
 	struct irq_domain	*irqdomain;
 	bool			leds_disabled;
 
diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c
index 778a962727ab..be56373e9473 100644
--- a/drivers/net/dsa/realtek/rtl8365mb.c
+++ b/drivers/net/dsa/realtek/rtl8365mb.c
@@ -870,6 +870,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,
 {
 	const struct rtl8365mb_extint *extint =
 		rtl8365mb_get_port_extint(priv, port);
+	struct dsa_switch *ds = &priv->ds;
 	struct device_node *dn;
 	struct dsa_port *dp;
 	int tx_delay = 0;
@@ -880,7 +881,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,
 	if (!extint)
 		return -ENODEV;
 
-	dp = dsa_to_port(priv->ds, port);
+	dp = dsa_to_port(ds, port);
 	dn = dp->dn;
 
 	/* Set the RGMII TX/RX delay
@@ -1533,6 +1534,7 @@ static void rtl8365mb_get_stats64(struct dsa_switch *ds, int port,
 static void rtl8365mb_stats_setup(struct realtek_priv *priv)
 {
 	struct rtl8365mb *mb = priv->chip_data;
+	struct dsa_switch *ds = &priv->ds;
 	int i;
 
 	/* Per-chip global mutex to protect MIB counter access, since doing
@@ -1543,7 +1545,7 @@ static void rtl8365mb_stats_setup(struct realtek_priv *priv)
 	for (i = 0; i < priv->num_ports; i++) {
 		struct rtl8365mb_port *p = &mb->ports[i];
 
-		if (dsa_is_unused_port(priv->ds, i))
+		if (dsa_is_unused_port(ds, i))
 			continue;
 
 		/* Per-port spinlock to protect the stats64 data */
@@ -1559,12 +1561,13 @@ static void rtl8365mb_stats_setup(struct realtek_priv *priv)
 static void rtl8365mb_stats_teardown(struct realtek_priv *priv)
 {
 	struct rtl8365mb *mb = priv->chip_data;
+	struct dsa_switch *ds = &priv->ds;
 	int i;
 
 	for (i = 0; i < priv->num_ports; i++) {
 		struct rtl8365mb_port *p = &mb->ports[i];
 
-		if (dsa_is_unused_port(priv->ds, i))
+		if (dsa_is_unused_port(ds, i))
 			continue;
 
 		cancel_delayed_work_sync(&p->mib_work);
@@ -1963,7 +1966,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 		dev_info(priv->dev, "no interrupt support\n");
 
 	/* Configure CPU tagging */
-	dsa_switch_for_each_cpu_port(cpu_dp, priv->ds) {
+	dsa_switch_for_each_cpu_port(cpu_dp, ds) {
 		cpu->mask |= BIT(cpu_dp->index);
 
 		if (cpu->trap_port == RTL8365MB_MAX_NUM_PORTS)
@@ -1978,7 +1981,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 	for (i = 0; i < priv->num_ports; i++) {
 		struct rtl8365mb_port *p = &mb->ports[i];
 
-		if (dsa_is_unused_port(priv->ds, i))
+		if (dsa_is_unused_port(ds, i))
 			continue;
 
 		/* Forward only to the CPU */
@@ -1995,7 +1998,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 		 * ports will still forward frames to the CPU despite being
 		 * administratively down by default.
 		 */
-		rtl8365mb_port_stp_state_set(priv->ds, i, BR_STATE_DISABLED);
+		rtl8365mb_port_stp_state_set(ds, i, BR_STATE_DISABLED);
 
 		/* Set up per-port private data */
 		p->priv = priv;
diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c
index 54eff9cd0c03..e10ae94cf771 100644
--- a/drivers/net/dsa/realtek/rtl8366rb.c
+++ b/drivers/net/dsa/realtek/rtl8366rb.c
@@ -1651,6 +1651,7 @@ static int rtl8366rb_get_mc_index(struct realtek_priv *priv, int port, int *val)
 
 static int rtl8366rb_set_mc_index(struct realtek_priv *priv, int port, int index)
 {
+	struct dsa_switch *ds = &priv->ds;
 	struct rtl8366rb *rb;
 	bool pvid_enabled;
 	int ret;
@@ -1675,7 +1676,7 @@ static int rtl8366rb_set_mc_index(struct realtek_priv *priv, int port, int index
 	 * not drop any untagged or C-tagged frames. Make sure to update the
 	 * filtering setting.
 	 */
-	if (dsa_port_is_vlan_filtering(dsa_to_port(priv->ds, port)))
+	if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
 		ret = rtl8366rb_drop_untagged(priv, port, !pvid_enabled);
 
 	return ret;
diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c
index 80f2c38ae55a..801873754df2 100644
--- a/drivers/net/dsa/realtek/rtl83xx.c
+++ b/drivers/net/dsa/realtek/rtl83xx.c
@@ -217,7 +217,7 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_probe, REALTEK_DSA);
  */
 int rtl83xx_register_switch(struct realtek_priv *priv)
 {
-	struct dsa_switch *ds;
+	struct dsa_switch *ds = &priv->ds;
 	int ret;
 
 	ret = priv->ops->detect(priv);
@@ -226,15 +226,10 @@ int rtl83xx_register_switch(struct realtek_priv *priv)
 		return ret;
 	}
 
-	ds = devm_kzalloc(priv->dev, sizeof(*ds), GFP_KERNEL);
-	if (!ds)
-		return -ENOMEM;
-
 	ds->priv = priv;
 	ds->dev = priv->dev;
 	ds->ops = priv->variant->ds_ops;
 	ds->num_ports = priv->num_ports;
-	priv->ds = ds;
 
 	ret = dsa_register_switch(ds);
 	if (ret) {
@@ -257,7 +252,9 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_register_switch, REALTEK_DSA);
  */
 void rtl83xx_unregister_switch(struct realtek_priv *priv)
 {
-	dsa_unregister_switch(priv->ds);
+	struct dsa_switch *ds = &priv->ds;
+
+	dsa_unregister_switch(ds);
 }
 EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_switch, REALTEK_DSA);
 
@@ -274,7 +271,9 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_switch, REALTEK_DSA);
  */
 void rtl83xx_shutdown(struct realtek_priv *priv)
 {
-	dsa_switch_shutdown(priv->ds);
+	struct dsa_switch *ds = &priv->ds;
+
+	dsa_switch_shutdown(ds);
 
 	dev_set_drvdata(priv->dev, NULL);
 }

-- 
2.43.0


  parent reply	other threads:[~2024-02-09  5:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09  5:03 [PATCH net-next v6 00/11] net: dsa: realtek: variants to drivers, interfaces to a common module Luiz Angelo Daros de Luca
2024-02-09  5:03 ` [PATCH net-next v6 01/11] net: dsa: realtek: drop cleanup from realtek_ops Luiz Angelo Daros de Luca
2024-02-09  5:03 ` [PATCH net-next v6 02/11] net: dsa: realtek: introduce REALTEK_DSA namespace Luiz Angelo Daros de Luca
2024-02-09 13:03   ` Linus Walleij
2024-02-09  5:03 ` [PATCH net-next v6 03/11] net: dsa: realtek: convert variants into real drivers Luiz Angelo Daros de Luca
2024-02-09 13:19   ` Linus Walleij
2024-02-09  5:03 ` [PATCH net-next v6 04/11] net: dsa: realtek: keep variant reference in realtek_priv Luiz Angelo Daros de Luca
2024-02-09 13:19   ` Linus Walleij
2024-02-09  5:03 ` [PATCH net-next v6 05/11] net: dsa: realtek: common rtl83xx module Luiz Angelo Daros de Luca
2024-02-09 13:20   ` Linus Walleij
2024-02-09  5:03 ` [PATCH net-next v6 06/11] net: dsa: realtek: merge rtl83xx and interface modules into realtek_dsa Luiz Angelo Daros de Luca
2024-02-09 13:20   ` Linus Walleij
2024-02-09  5:03 ` [PATCH net-next v6 07/11] net: dsa: realtek: get internal MDIO node by name Luiz Angelo Daros de Luca
2024-02-09 13:21   ` Linus Walleij
2024-02-09  5:03 ` [PATCH net-next v6 08/11] net: dsa: realtek: clean user_mii_bus setup Luiz Angelo Daros de Luca
2024-02-09 13:21   ` Linus Walleij
2024-02-09  5:03 ` [PATCH net-next v6 09/11] net: dsa: realtek: migrate user_mii_bus setup to realtek_dsa Luiz Angelo Daros de Luca
2024-02-09 13:22   ` Linus Walleij
2024-02-09  5:03 ` [PATCH net-next v6 10/11] net: dsa: realtek: use the same mii bus driver for both interfaces Luiz Angelo Daros de Luca
2024-02-09 13:23   ` Linus Walleij
2024-02-09  5:03 ` Luiz Angelo Daros de Luca [this message]
2024-02-09 13:24   ` [PATCH net-next v6 11/11] net: dsa: realtek: embed dsa_switch into realtek_priv Linus Walleij
2024-02-09 13:17 ` [PATCH net-next v6 00/11] net: dsa: realtek: variants to drivers, interfaces to a common module Linus Walleij
2024-02-12 12:43   ` Luiz Angelo Daros de Luca
2024-02-12 10:50 ` patchwork-bot+netdevbpf
2024-02-12 12:45   ` Luiz Angelo Daros de Luca
2024-02-16  1:20     ` Vladimir Oltean

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=20240209-realtek_reverse-v6-11-0662f8cbc7b5@gmail.com \
    --to=luizluca@gmail.com \
    --cc=alsi@bang-olufsen.dk \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).