Commit 23ca3b72 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: mscc: ocelot: rebalance LAGs on link up/down events

At present there is an issue when ocelot is offloading a bonding
interface, but one of the links of the physical ports goes down. Traffic
keeps being hashed towards that destination, and of course gets dropped
on egress.

Monitor the netdev notifier events emitted by the bonding driver for
changes in the physical state of lower interfaces, to determine which
ports are active and which ones are no longer.

Then extend ocelot_get_bond_mask to return either the configured bonding
interfaces, or the active ones, depending on a boolean argument. The
code that does rebalancing only needs to do so among the active ports,
whereas the bridge forwarding mask and the logical port IDs still need
to look at the permanently bonded ports.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 21357b61
...@@ -889,7 +889,8 @@ int ocelot_get_ts_info(struct ocelot *ocelot, int port, ...@@ -889,7 +889,8 @@ int ocelot_get_ts_info(struct ocelot *ocelot, int port,
} }
EXPORT_SYMBOL(ocelot_get_ts_info); EXPORT_SYMBOL(ocelot_get_ts_info);
static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond) static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond,
bool only_active_ports)
{ {
u32 mask = 0; u32 mask = 0;
int port; int port;
...@@ -900,9 +901,13 @@ static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond) ...@@ -900,9 +901,13 @@ static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond)
if (!ocelot_port) if (!ocelot_port)
continue; continue;
if (ocelot_port->bond == bond) if (ocelot_port->bond == bond) {
if (only_active_ports && !ocelot_port->lag_tx_active)
continue;
mask |= BIT(port); mask |= BIT(port);
} }
}
return mask; return mask;
} }
...@@ -960,8 +965,10 @@ void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot) ...@@ -960,8 +965,10 @@ void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot)
struct net_device *bond = ocelot_port->bond; struct net_device *bond = ocelot_port->bond;
mask = ocelot->bridge_fwd_mask & ~BIT(port); mask = ocelot->bridge_fwd_mask & ~BIT(port);
if (bond) if (bond) {
mask &= ~ocelot_get_bond_mask(ocelot, bond); mask &= ~ocelot_get_bond_mask(ocelot, bond,
false);
}
} else { } else {
/* Standalone ports forward only to DSA tag_8021q CPU /* Standalone ports forward only to DSA tag_8021q CPU
* ports (if those exist), or to the hardware CPU port * ports (if those exist), or to the hardware CPU port
...@@ -1298,20 +1305,20 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot) ...@@ -1298,20 +1305,20 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
/* Now, set PGIDs for each active LAG */ /* Now, set PGIDs for each active LAG */
for (lag = 0; lag < ocelot->num_phys_ports; lag++) { for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
struct net_device *bond = ocelot->ports[lag]->bond; struct net_device *bond = ocelot->ports[lag]->bond;
int num_ports_in_lag = 0; int num_active_ports = 0;
unsigned long bond_mask; unsigned long bond_mask;
u8 aggr_idx[16]; u8 aggr_idx[16];
if (!bond || (visited & BIT(lag))) if (!bond || (visited & BIT(lag)))
continue; continue;
bond_mask = ocelot_get_bond_mask(ocelot, bond); bond_mask = ocelot_get_bond_mask(ocelot, bond, true);
for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) { for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
// Destination mask // Destination mask
ocelot_write_rix(ocelot, bond_mask, ocelot_write_rix(ocelot, bond_mask,
ANA_PGID_PGID, port); ANA_PGID_PGID, port);
aggr_idx[num_ports_in_lag++] = port; aggr_idx[num_active_ports++] = port;
} }
for_each_aggr_pgid(ocelot, i) { for_each_aggr_pgid(ocelot, i) {
...@@ -1319,7 +1326,11 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot) ...@@ -1319,7 +1326,11 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i); ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i);
ac &= ~bond_mask; ac &= ~bond_mask;
ac |= BIT(aggr_idx[i % num_ports_in_lag]); /* Don't do division by zero if there was no active
* port. Just make all aggregation codes zero.
*/
if (num_active_ports)
ac |= BIT(aggr_idx[i % num_active_ports]);
ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i); ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i);
} }
...@@ -1356,7 +1367,8 @@ static void ocelot_setup_logical_port_ids(struct ocelot *ocelot) ...@@ -1356,7 +1367,8 @@ static void ocelot_setup_logical_port_ids(struct ocelot *ocelot)
bond = ocelot_port->bond; bond = ocelot_port->bond;
if (bond) { if (bond) {
int lag = __ffs(ocelot_get_bond_mask(ocelot, bond)); int lag = __ffs(ocelot_get_bond_mask(ocelot, bond,
false));
ocelot_rmw_gix(ocelot, ocelot_rmw_gix(ocelot,
ANA_PORT_PORT_CFG_PORTID_VAL(lag), ANA_PORT_PORT_CFG_PORTID_VAL(lag),
...@@ -1399,6 +1411,17 @@ void ocelot_port_lag_leave(struct ocelot *ocelot, int port, ...@@ -1399,6 +1411,17 @@ void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
} }
EXPORT_SYMBOL(ocelot_port_lag_leave); EXPORT_SYMBOL(ocelot_port_lag_leave);
void ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active)
{
struct ocelot_port *ocelot_port = ocelot->ports[port];
ocelot_port->lag_tx_active = lag_tx_active;
/* Rebalance the LAGs */
ocelot_set_aggr_pgids(ocelot);
}
EXPORT_SYMBOL(ocelot_port_lag_change);
/* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu. /* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu.
* The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG. * The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG.
* In the special case that it's the NPI port that we're configuring, the * In the special case that it's the NPI port that we're configuring, the
......
...@@ -114,6 +114,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, ...@@ -114,6 +114,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port,
struct netdev_lag_upper_info *info); struct netdev_lag_upper_info *info);
void ocelot_port_lag_leave(struct ocelot *ocelot, int port, void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
struct net_device *bond); struct net_device *bond);
void ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active);
struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port); struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port);
int ocelot_netdev_to_port(struct net_device *dev); int ocelot_netdev_to_port(struct net_device *dev);
......
...@@ -1164,6 +1164,27 @@ ocelot_netdevice_lag_changeupper(struct net_device *dev, ...@@ -1164,6 +1164,27 @@ ocelot_netdevice_lag_changeupper(struct net_device *dev,
return NOTIFY_DONE; return NOTIFY_DONE;
} }
static int
ocelot_netdevice_changelowerstate(struct net_device *dev,
struct netdev_lag_lower_state_info *info)
{
struct ocelot_port_private *priv = netdev_priv(dev);
bool is_active = info->link_up && info->tx_enabled;
struct ocelot_port *ocelot_port = &priv->port;
struct ocelot *ocelot = ocelot_port->ocelot;
int port = priv->chip_port;
if (!ocelot_port->bond)
return NOTIFY_DONE;
if (ocelot_port->lag_tx_active == is_active)
return NOTIFY_DONE;
ocelot_port_lag_change(ocelot, port, is_active);
return NOTIFY_OK;
}
static int ocelot_netdevice_event(struct notifier_block *unused, static int ocelot_netdevice_event(struct notifier_block *unused,
unsigned long event, void *ptr) unsigned long event, void *ptr)
{ {
...@@ -1181,6 +1202,15 @@ static int ocelot_netdevice_event(struct notifier_block *unused, ...@@ -1181,6 +1202,15 @@ static int ocelot_netdevice_event(struct notifier_block *unused,
break; break;
} }
case NETDEV_CHANGELOWERSTATE: {
struct netdev_notifier_changelowerstate_info *info = ptr;
if (!ocelot_netdevice_dev_check(dev))
break;
return ocelot_netdevice_changelowerstate(dev,
info->lower_state_info);
}
default: default:
break; break;
} }
......
...@@ -613,6 +613,7 @@ struct ocelot_port { ...@@ -613,6 +613,7 @@ struct ocelot_port {
bool is_dsa_8021q_cpu; bool is_dsa_8021q_cpu;
struct net_device *bond; struct net_device *bond;
bool lag_tx_active;
}; };
struct ocelot { struct ocelot {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment