Skip to content

Commit fd941bd

Browse files
shimodaykuba-moo
authored andcommitted
net: ethernet: renesas: rswitch: Fix ethernet-ports handling
If one of ports in the ethernet-ports was disabled, this driver failed to probe all ports. So, fix it. Fixes: 3590918 ("net: ethernet: renesas: Add support for "Ethernet Switch"") Signed-off-by: Yoshihiro Shimoda <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 20e3028 commit fd941bd

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

drivers/net/ethernet/renesas/rswitch.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,11 @@ static struct device_node *rswitch_get_port_node(struct rswitch_device *rdev)
10741074
port = NULL;
10751075
goto out;
10761076
}
1077-
if (index == rdev->etha->index)
1077+
if (index == rdev->etha->index) {
1078+
if (!of_device_is_available(port))
1079+
port = NULL;
10781080
break;
1081+
}
10791082
}
10801083

10811084
out:
@@ -1106,7 +1109,7 @@ static int rswitch_etha_get_params(struct rswitch_device *rdev)
11061109

11071110
port = rswitch_get_port_node(rdev);
11081111
if (!port)
1109-
return -ENODEV;
1112+
return 0; /* ignored */
11101113

11111114
err = of_get_phy_mode(port, &rdev->etha->phy_interface);
11121115
of_node_put(port);
@@ -1324,13 +1327,13 @@ static int rswitch_ether_port_init_all(struct rswitch_private *priv)
13241327
{
13251328
int i, err;
13261329

1327-
for (i = 0; i < RSWITCH_NUM_PORTS; i++) {
1330+
rswitch_for_each_enabled_port(priv, i) {
13281331
err = rswitch_ether_port_init_one(priv->rdev[i]);
13291332
if (err)
13301333
goto err_init_one;
13311334
}
13321335

1333-
for (i = 0; i < RSWITCH_NUM_PORTS; i++) {
1336+
rswitch_for_each_enabled_port(priv, i) {
13341337
err = rswitch_serdes_init(priv->rdev[i]);
13351338
if (err)
13361339
goto err_serdes;
@@ -1339,12 +1342,12 @@ static int rswitch_ether_port_init_all(struct rswitch_private *priv)
13391342
return 0;
13401343

13411344
err_serdes:
1342-
for (i--; i >= 0; i--)
1345+
rswitch_for_each_enabled_port_continue_reverse(priv, i)
13431346
rswitch_serdes_deinit(priv->rdev[i]);
13441347
i = RSWITCH_NUM_PORTS;
13451348

13461349
err_init_one:
1347-
for (i--; i >= 0; i--)
1350+
rswitch_for_each_enabled_port_continue_reverse(priv, i)
13481351
rswitch_ether_port_deinit_one(priv->rdev[i]);
13491352

13501353
return err;
@@ -1608,6 +1611,7 @@ static int rswitch_device_alloc(struct rswitch_private *priv, int index)
16081611
netif_napi_add(ndev, &rdev->napi, rswitch_poll);
16091612

16101613
port = rswitch_get_port_node(rdev);
1614+
rdev->disabled = !port;
16111615
err = of_get_ethdev_address(port, ndev);
16121616
of_node_put(port);
16131617
if (err) {
@@ -1707,16 +1711,16 @@ static int rswitch_init(struct rswitch_private *priv)
17071711
if (err)
17081712
goto err_ether_port_init_all;
17091713

1710-
for (i = 0; i < RSWITCH_NUM_PORTS; i++) {
1714+
rswitch_for_each_enabled_port(priv, i) {
17111715
err = register_netdev(priv->rdev[i]->ndev);
17121716
if (err) {
1713-
for (i--; i >= 0; i--)
1717+
rswitch_for_each_enabled_port_continue_reverse(priv, i)
17141718
unregister_netdev(priv->rdev[i]->ndev);
17151719
goto err_register_netdev;
17161720
}
17171721
}
17181722

1719-
for (i = 0; i < RSWITCH_NUM_PORTS; i++)
1723+
rswitch_for_each_enabled_port(priv, i)
17201724
netdev_info(priv->rdev[i]->ndev, "MAC address %pM\n",
17211725
priv->rdev[i]->ndev->dev_addr);
17221726

drivers/net/ethernet/renesas/rswitch.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
#define RSWITCH_MAX_NUM_QUEUES 128
1414

1515
#define RSWITCH_NUM_PORTS 3
16+
#define rswitch_for_each_enabled_port(priv, i) \
17+
for (i = 0; i < RSWITCH_NUM_PORTS; i++) \
18+
if (priv->rdev[i]->disabled) \
19+
continue; \
20+
else
21+
22+
#define rswitch_for_each_enabled_port_continue_reverse(priv, i) \
23+
for (i--; i >= 0; i--) \
24+
if (priv->rdev[i]->disabled) \
25+
continue; \
26+
else
1627

1728
#define TX_RING_SIZE 1024
1829
#define RX_RING_SIZE 1024
@@ -938,6 +949,7 @@ struct rswitch_device {
938949
struct rswitch_gwca_queue *tx_queue;
939950
struct rswitch_gwca_queue *rx_queue;
940951
u8 ts_tag;
952+
bool disabled;
941953

942954
int port;
943955
struct rswitch_etha *etha;

0 commit comments

Comments
 (0)