Skip to content

Commit

Permalink
net: ethernet: renesas: rswitch: Fix ethernet-ports handling
Browse files Browse the repository at this point in the history
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 <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20230120001959.1059850-1-yoshihiro.shimoda.uh@renesas.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Yoshihiro Shimoda authored and Jakub Kicinski committed Jan 21, 2023
1 parent 20e3028 commit fd941bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
22 changes: 13 additions & 9 deletions drivers/net/ethernet/renesas/rswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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_continue_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_continue_reverse(priv, i)
rswitch_ether_port_deinit_one(priv->rdev[i]);

return err;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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_continue_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);

Expand Down
12 changes: 12 additions & 0 deletions drivers/net/ethernet/renesas/rswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_continue_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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fd941bd

Please sign in to comment.