netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: ethernet: renesas: rswitch: Fix ethernet-ports handling
@ 2023-01-10  9:55 Yoshihiro Shimoda
  2023-01-10 14:14 ` Jiri Pirko
  2023-01-12  4:18 ` Jakub Kicinski
  0 siblings, 2 replies; 4+ messages in thread
From: Yoshihiro Shimoda @ 2023-01-10  9:55 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: netdev, linux-renesas-soc, Yoshihiro Shimoda

If one of ports in the ethernet-ports was disabled, this driver
failed to probe all ports. So, fix it.

Fixes: 3590918b5d07 ("net: ethernet: renesas: Add support for "Ethernet Switch"")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 The checkpatch.pl reports the following ERROR:

    Macros with multiple statements should be enclosed in a do - while loop

 However, include/linux/cpufreq.h has similar macros and the same ERROR
 happened. So, I assume that the ERROR can be ignored.

 drivers/net/ethernet/renesas/rswitch.c | 22 +++++++++++++---------
 drivers/net/ethernet/renesas/rswitch.h | 12 ++++++++++++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c
index 6441892636db..6818216212df 100644
--- a/drivers/net/ethernet/renesas/rswitch.c
+++ b/drivers/net/ethernet/renesas/rswitch.c
@@ -1074,8 +1074,11 @@ static struct device_node *rswitch_get_port_node(struct rswitch_device *rdev)
 			port = NULL;
 			goto out;
 		}
-		if (index == rdev->etha->index)
+		if (index == rdev->etha->index) {
+			if (!of_device_is_available(port))
+				port = NULL;
 			break;
+		}
 	}
 
 out:
@@ -1106,7 +1109,7 @@ static int rswitch_etha_get_params(struct rswitch_device *rdev)
 
 	port = rswitch_get_port_node(rdev);
 	if (!port)
-		return -ENODEV;
+		return 0;	/* ignored */
 
 	err = of_get_phy_mode(port, &rdev->etha->phy_interface);
 	of_node_put(port);
@@ -1324,13 +1327,13 @@ static int rswitch_ether_port_init_all(struct rswitch_private *priv)
 {
 	int i, err;
 
-	for (i = 0; i < RSWITCH_NUM_PORTS; i++) {
+	rswitch_for_each_enabled_port(priv, i) {
 		err = rswitch_ether_port_init_one(priv->rdev[i]);
 		if (err)
 			goto err_init_one;
 	}
 
-	for (i = 0; i < RSWITCH_NUM_PORTS; i++) {
+	rswitch_for_each_enabled_port(priv, i) {
 		err = rswitch_serdes_init(priv->rdev[i]);
 		if (err)
 			goto err_serdes;
@@ -1339,12 +1342,12 @@ static int rswitch_ether_port_init_all(struct rswitch_private *priv)
 	return 0;
 
 err_serdes:
-	for (i--; i >= 0; i--)
+	rswitch_for_each_enabled_port_reverse(priv, i)
 		rswitch_serdes_deinit(priv->rdev[i]);
 	i = RSWITCH_NUM_PORTS;
 
 err_init_one:
-	for (i--; i >= 0; i--)
+	rswitch_for_each_enabled_port_reverse(priv, i)
 		rswitch_ether_port_deinit_one(priv->rdev[i]);
 
 	return err;
@@ -1608,6 +1611,7 @@ static int rswitch_device_alloc(struct rswitch_private *priv, int index)
 	netif_napi_add(ndev, &rdev->napi, rswitch_poll);
 
 	port = rswitch_get_port_node(rdev);
+	rdev->disabled = !port;
 	err = of_get_ethdev_address(port, ndev);
 	of_node_put(port);
 	if (err) {
@@ -1707,16 +1711,16 @@ static int rswitch_init(struct rswitch_private *priv)
 	if (err)
 		goto err_ether_port_init_all;
 
-	for (i = 0; i < RSWITCH_NUM_PORTS; i++) {
+	rswitch_for_each_enabled_port(priv, i) {
 		err = register_netdev(priv->rdev[i]->ndev);
 		if (err) {
-			for (i--; i >= 0; i--)
+			rswitch_for_each_enabled_port_reverse(priv, i)
 				unregister_netdev(priv->rdev[i]->ndev);
 			goto err_register_netdev;
 		}
 	}
 
-	for (i = 0; i < RSWITCH_NUM_PORTS; i++)
+	rswitch_for_each_enabled_port(priv, i)
 		netdev_info(priv->rdev[i]->ndev, "MAC address %pM\n",
 			    priv->rdev[i]->ndev->dev_addr);
 
diff --git a/drivers/net/ethernet/renesas/rswitch.h b/drivers/net/ethernet/renesas/rswitch.h
index edbdd1b98d3d..628bd5b0b3de 100644
--- a/drivers/net/ethernet/renesas/rswitch.h
+++ b/drivers/net/ethernet/renesas/rswitch.h
@@ -13,6 +13,17 @@
 #define RSWITCH_MAX_NUM_QUEUES	128
 
 #define RSWITCH_NUM_PORTS	3
+#define rswitch_for_each_enabled_port(priv, i)		\
+	for (i = 0; i < RSWITCH_NUM_PORTS; i++)		\
+		if (priv->rdev[i]->disabled)		\
+			continue;			\
+		else
+
+#define rswitch_for_each_enabled_port_reverse(priv, i)	\
+	for (i--; i >= 0; i--)				\
+		if (priv->rdev[i]->disabled)		\
+			continue;			\
+		else
 
 #define TX_RING_SIZE		1024
 #define RX_RING_SIZE		1024
@@ -938,6 +949,7 @@ struct rswitch_device {
 	struct rswitch_gwca_queue *tx_queue;
 	struct rswitch_gwca_queue *rx_queue;
 	u8 ts_tag;
+	bool disabled;
 
 	int port;
 	struct rswitch_etha *etha;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: ethernet: renesas: rswitch: Fix ethernet-ports handling
  2023-01-10  9:55 [PATCH net] net: ethernet: renesas: rswitch: Fix ethernet-ports handling Yoshihiro Shimoda
@ 2023-01-10 14:14 ` Jiri Pirko
  2023-01-12  4:18 ` Jakub Kicinski
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Pirko @ 2023-01-10 14:14 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: davem, edumazet, kuba, pabeni, netdev, linux-renesas-soc

Tue, Jan 10, 2023 at 10:55:59AM CET, yoshihiro.shimoda.uh@renesas.com wrote:
>If one of ports in the ethernet-ports was disabled, this driver
>failed to probe all ports. So, fix it.
>
>Fixes: 3590918b5d07 ("net: ethernet: renesas: Add support for "Ethernet Switch"")
>Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: ethernet: renesas: rswitch: Fix ethernet-ports handling
  2023-01-10  9:55 [PATCH net] net: ethernet: renesas: rswitch: Fix ethernet-ports handling Yoshihiro Shimoda
  2023-01-10 14:14 ` Jiri Pirko
@ 2023-01-12  4:18 ` Jakub Kicinski
  2023-01-12  7:35   ` Yoshihiro Shimoda
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2023-01-12  4:18 UTC (permalink / raw)
  To: Yoshihiro Shimoda; +Cc: davem, edumazet, pabeni, netdev, linux-renesas-soc

On Tue, 10 Jan 2023 18:55:59 +0900 Yoshihiro Shimoda wrote:
> +#define rswitch_for_each_enabled_port_reverse(priv, i)	\
> +	for (i--; i >= 0; i--)				\

nit: the typical name suffix for this sort of macro in Linux would 
be _continue_reverse - because it doesn't initialize the iterator.
It's specifically targeting error paths.

That's what list.h uses, on a quick grep I can see the same convention
is used for netdevice.h and dsa.h. Do you have counter examples?
I reckon we should throw "_continue" into the name.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH net] net: ethernet: renesas: rswitch: Fix ethernet-ports handling
  2023-01-12  4:18 ` Jakub Kicinski
@ 2023-01-12  7:35   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 4+ messages in thread
From: Yoshihiro Shimoda @ 2023-01-12  7:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org

Hi Jakub,

> From: Jakub Kicinski, Sent: Thursday, January 12, 2023 1:19 PM
> 
> On Tue, 10 Jan 2023 18:55:59 +0900 Yoshihiro Shimoda wrote:
> > +#define rswitch_for_each_enabled_port_reverse(priv, i)	\
> > +	for (i--; i >= 0; i--)				\
> 
> nit: the typical name suffix for this sort of macro in Linux would
> be _continue_reverse - because it doesn't initialize the iterator.
> It's specifically targeting error paths.
> 
> That's what list.h uses, on a quick grep I can see the same convention
> is used for netdevice.h and dsa.h. Do you have counter examples?
> I reckon we should throw "_continue" into the name.

Thank you for your comments! I didn't know suffix "__continue_" on macros.
So, I will rename this macro name with rswitch_for_each_enabled_port_continue_reverse().

Best regards,
Yoshihiro Shimoda


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-12  7:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-10  9:55 [PATCH net] net: ethernet: renesas: rswitch: Fix ethernet-ports handling Yoshihiro Shimoda
2023-01-10 14:14 ` Jiri Pirko
2023-01-12  4:18 ` Jakub Kicinski
2023-01-12  7:35   ` Yoshihiro Shimoda

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).