Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f5461c27 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'dsa-pass-bridge-to-drivers'

Vivien Didelot says:

====================
net: dsa: pass bridge device to drivers

This patchset simplifies the DSA layer.

A switch may support multiple bridges with the same hardware VLAN. Thus a check
such as dsa_bridge_check_vlan_range must be moved from the DSA layer to the
concerned driver.

The first purpose of this patchset is to help moving this check to the
mv88e6xxx driver, which is the only one affected at the moment.

To do that, pass directly the bridge net_device structure down to the DSA
drivers, instead of calculating a bitmask of bridge members.

The second purpose is to prepare the replacement of the complex
port_vlan_getnext approach. A second patchset is ready to follow, implementing
port_vlan_dump and thus simplifying the DSA slave code one more time.

Note that this patchset applies on top of https://lkml.org/lkml/2016/2/5/532

.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 9b69d206 9d2dd736
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -524,17 +524,14 @@ Bridge layer
- port_join_bridge: bridge layer function invoked when a given switch port is
  added to a bridge, this function should be doing the necessary at the switch
  level to permit the joining port from being added to the relevant logical
  domain for it to ingress/egress traffic with other members of the bridge. DSA
  does nothing but calculate a bitmask of switch ports currently members of the
  specified bridge being requested the join
  domain for it to ingress/egress traffic with other members of the bridge.

- port_leave_bridge: bridge layer function invoked when a given switch port is
  removed from a bridge, this function should be doing the necessary at the
  switch level to deny the leaving port from ingress/egress traffic from the
  remaining bridge members. When the port leaves the bridge, it should be aged
  out at the switch hardware for the switch to (re) learn MAC addresses behind
  this port. DSA calculates the bitmask of ports still members of the bridge
  being left
  this port.

- port_stp_update: bridge layer function invoked when a given switch port STP
  state is computed by the bridge layer and should be propagated to switch
+7 −5
Original line number Diff line number Diff line
@@ -483,16 +483,17 @@ static int bcm_sf2_sw_fast_age_port(struct dsa_switch *ds, int port)
}

static int bcm_sf2_sw_br_join(struct dsa_switch *ds, int port,
			      u32 br_port_mask)
			      struct net_device *bridge)
{
	struct bcm_sf2_priv *priv = ds_to_priv(ds);
	unsigned int i;
	u32 reg, p_ctl;

	priv->port_sts[port].bridge_dev = bridge;
	p_ctl = core_readl(priv, CORE_PORT_VLAN_CTL_PORT(port));

	for (i = 0; i < priv->hw_params.num_ports; i++) {
		if (!((1 << i) & br_port_mask))
		if (priv->port_sts[i].bridge_dev != bridge)
			continue;

		/* Add this local port to the remote port VLAN control
@@ -515,10 +516,10 @@ static int bcm_sf2_sw_br_join(struct dsa_switch *ds, int port,
	return 0;
}

static int bcm_sf2_sw_br_leave(struct dsa_switch *ds, int port,
			       u32 br_port_mask)
static int bcm_sf2_sw_br_leave(struct dsa_switch *ds, int port)
{
	struct bcm_sf2_priv *priv = ds_to_priv(ds);
	struct net_device *bridge = priv->port_sts[port].bridge_dev;
	unsigned int i;
	u32 reg, p_ctl;

@@ -526,7 +527,7 @@ static int bcm_sf2_sw_br_leave(struct dsa_switch *ds, int port,

	for (i = 0; i < priv->hw_params.num_ports; i++) {
		/* Don't touch the remaining ports */
		if (!((1 << i) & br_port_mask))
		if (priv->port_sts[i].bridge_dev != bridge)
			continue;

		reg = core_readl(priv, CORE_PORT_VLAN_CTL_PORT(i));
@@ -541,6 +542,7 @@ static int bcm_sf2_sw_br_leave(struct dsa_switch *ds, int port,

	core_writel(priv, p_ctl, CORE_PORT_VLAN_CTL_PORT(port));
	priv->port_sts[port].vlan_ctl_mask = p_ctl;
	priv->port_sts[port].bridge_dev = NULL;

	return 0;
}
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ struct bcm_sf2_port_status {
	struct ethtool_eee eee;

	u32 vlan_ctl_mask;

	struct net_device *bridge_dev;
};

struct bcm_sf2_arl_entry {
+77 −4
Original line number Diff line number Diff line
@@ -1131,7 +1131,7 @@ int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state)
	/* mv88e6xxx_port_stp_update may be called with softirqs disabled,
	 * so we can not update the port state directly but need to schedule it.
	 */
	ps->port_state[port] = stp_state;
	ps->ports[port].state = stp_state;
	set_bit(port, &ps->port_state_update_mask);
	schedule_work(&ps->bridge_work);

@@ -1471,14 +1471,78 @@ static int _mv88e6xxx_vlan_init(struct dsa_switch *ds, u16 vid,
	return 0;
}

static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
	struct mv88e6xxx_vtu_stu_entry vlan;
	int i, err;

	if (!vid_begin)
		return -EOPNOTSUPP;

	mutex_lock(&ps->smi_mutex);

	err = _mv88e6xxx_vtu_vid_write(ds, vid_begin - 1);
	if (err)
		goto unlock;

	do {
		err = _mv88e6xxx_vtu_getnext(ds, &vlan);
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

		for (i = 0; i < ps->num_ports; ++i) {
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

			if (vlan.data[i] ==
			    GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
				continue;

			if (ps->ports[i].bridge_dev ==
			    ps->ports[port].bridge_dev)
				break; /* same bridge, check next VLAN */

			netdev_warn(ds->ports[port],
				    "hardware VLAN %d already used by %s\n",
				    vlan.vid,
				    netdev_name(ps->ports[i].bridge_dev));
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
	mutex_unlock(&ps->smi_mutex);

	return err;
}

int mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
				const struct switchdev_obj_port_vlan *vlan,
				struct switchdev_trans *trans)
{
	int err;

	/* We reserve a few VLANs to isolate unbridged ports */
	if (vlan->vid_end >= 4000)
		return -EOPNOTSUPP;

	/* If the requested port doesn't belong to the same bridge as the VLAN
	 * members, do not support it (yet) and fallback to software VLAN.
	 */
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
	if (err)
		return err;

	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
@@ -1889,13 +1953,22 @@ int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
	return err;
}

int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, u32 members)
int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
			       struct net_device *bridge)
{
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);

	ps->ports[port].bridge_dev = bridge;

	return 0;
}

int mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port, u32 members)
int mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);

	ps->ports[port].bridge_dev = NULL;

	return 0;
}

@@ -1925,7 +1998,7 @@ static void mv88e6xxx_bridge_work(struct work_struct *work)
	while (ps->port_state_update_mask) {
		port = __ffs(ps->port_state_update_mask);
		clear_bit(port, &ps->port_state_update_mask);
		mv88e6xxx_set_port_state(ds, port, ps->port_state[port]);
		mv88e6xxx_set_port_state(ds, port, ps->ports[port].state);
	}
}

+10 −3
Original line number Diff line number Diff line
@@ -379,6 +379,11 @@ struct mv88e6xxx_vtu_stu_entry {
	u8	data[DSA_MAX_PORTS];
};

struct mv88e6xxx_priv_port {
	struct net_device *bridge_dev;
	u8 state;
};

struct mv88e6xxx_priv_state {
	/* When using multi-chip addressing, this mutex protects
	 * access to the indirect access registers.  (In single-chip
@@ -415,8 +420,9 @@ struct mv88e6xxx_priv_state {
	int		id; /* switch product id */
	int		num_ports;	/* number of switch ports */

	struct mv88e6xxx_priv_port	ports[DSA_MAX_PORTS];

	unsigned long port_state_update_mask;
	u8 port_state[DSA_MAX_PORTS];

	struct work_struct bridge_work;
};
@@ -476,8 +482,9 @@ int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
		      struct phy_device *phydev, struct ethtool_eee *e);
int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, u32 members);
int mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port, u32 members);
int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
			       struct net_device *bridge);
int mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port);
int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state);
int mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
				const struct switchdev_obj_port_vlan *vlan,
Loading