Commit 6c2c1dcb authored by Arkadi Sharshevsky's avatar Arkadi Sharshevsky Committed by David S. Miller
Browse files

net: dsa: Change DSA slave FDB API to be switchdev independent



In order to support FDB add/del to be on a notifier chain the slave
API need to be changed to be switchdev independent.

Signed-off-by: default avatarArkadi Sharshevsky <arkadis@mellanox.com>
Reviewed-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 511aeaf4
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -1214,8 +1214,7 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
}

int b53_fdb_prepare(struct dsa_switch *ds, int port,
		    const struct switchdev_obj_port_fdb *fdb,
		    struct switchdev_trans *trans)
		    const unsigned char *addr, u16 vid)
{
	struct b53_device *priv = ds->priv;

@@ -1230,22 +1229,21 @@ int b53_fdb_prepare(struct dsa_switch *ds, int port,
EXPORT_SYMBOL(b53_fdb_prepare);

void b53_fdb_add(struct dsa_switch *ds, int port,
		 const struct switchdev_obj_port_fdb *fdb,
		 struct switchdev_trans *trans)
		 const unsigned char *addr, u16 vid)
{
	struct b53_device *priv = ds->priv;

	if (b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, true))
	if (b53_arl_op(priv, 0, port, addr, vid, true))
		pr_err("%s: failed to add MAC address\n", __func__);
}
EXPORT_SYMBOL(b53_fdb_add);

int b53_fdb_del(struct dsa_switch *ds, int port,
		const struct switchdev_obj_port_fdb *fdb)
		const unsigned char *addr, u16 vid)
{
	struct b53_device *priv = ds->priv;

	return b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, false);
	return b53_arl_op(priv, 0, port, addr, vid, false);
}
EXPORT_SYMBOL(b53_fdb_del);

+3 −5
Original line number Diff line number Diff line
@@ -397,13 +397,11 @@ int b53_vlan_dump(struct dsa_switch *ds, int port,
		  struct switchdev_obj_port_vlan *vlan,
		  switchdev_obj_dump_cb_t *cb);
int b53_fdb_prepare(struct dsa_switch *ds, int port,
		    const struct switchdev_obj_port_fdb *fdb,
		    struct switchdev_trans *trans);
		    const unsigned char *addr, u16 vid);
void b53_fdb_add(struct dsa_switch *ds, int port,
		 const struct switchdev_obj_port_fdb *fdb,
		 struct switchdev_trans *trans);
		 const unsigned char *addr, u16 vid);
int b53_fdb_del(struct dsa_switch *ds, int port,
		const struct switchdev_obj_port_fdb *fdb);
		const unsigned char *addr, u16 vid);
int b53_fdb_dump(struct dsa_switch *ds, int port,
		 struct switchdev_obj_port_fdb *fdb,
		 switchdev_obj_dump_cb_t *cb);
+16 −18
Original line number Diff line number Diff line
@@ -679,8 +679,7 @@ static int ksz_port_vlan_dump(struct dsa_switch *ds, int port,
}

static int ksz_port_fdb_prepare(struct dsa_switch *ds, int port,
				const struct switchdev_obj_port_fdb *fdb,
				struct switchdev_trans *trans)
				const unsigned char *addr, u16 vid)
{
	/* nothing needed */

@@ -707,8 +706,7 @@ struct alu_struct {
};

static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
			     const struct switchdev_obj_port_fdb *fdb,
			     struct switchdev_trans *trans)
			     const unsigned char *addr, u16 vid)
{
	struct ksz_device *dev = ds->priv;
	u32 alu_table[4];
@@ -717,12 +715,12 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
	mutex_lock(&dev->alu_mutex);

	/* find any entry with mac & vid */
	data = fdb->vid << ALU_FID_INDEX_S;
	data |= ((fdb->addr[0] << 8) | fdb->addr[1]);
	data = vid << ALU_FID_INDEX_S;
	data |= ((addr[0] << 8) | addr[1]);
	ksz_write32(dev, REG_SW_ALU_INDEX_0, data);

	data = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16));
	data |= ((fdb->addr[4] << 8) | fdb->addr[5]);
	data = ((addr[2] << 24) | (addr[3] << 16));
	data |= ((addr[4] << 8) | addr[5]);
	ksz_write32(dev, REG_SW_ALU_INDEX_1, data);

	/* start read operation */
@@ -740,12 +738,12 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
	/* update ALU entry */
	alu_table[0] = ALU_V_STATIC_VALID;
	alu_table[1] |= BIT(port);
	if (fdb->vid)
	if (vid)
		alu_table[1] |= ALU_V_USE_FID;
	alu_table[2] = (fdb->vid << ALU_V_FID_S);
	alu_table[2] |= ((fdb->addr[0] << 8) | fdb->addr[1]);
	alu_table[3] = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16));
	alu_table[3] |= ((fdb->addr[4] << 8) | fdb->addr[5]);
	alu_table[2] = (vid << ALU_V_FID_S);
	alu_table[2] |= ((addr[0] << 8) | addr[1]);
	alu_table[3] = ((addr[2] << 24) | (addr[3] << 16));
	alu_table[3] |= ((addr[4] << 8) | addr[5]);

	write_table(ds, alu_table);

@@ -760,7 +758,7 @@ exit:
}

static int ksz_port_fdb_del(struct dsa_switch *ds, int port,
			    const struct switchdev_obj_port_fdb *fdb)
			    const unsigned char *addr, u16 vid)
{
	struct ksz_device *dev = ds->priv;
	u32 alu_table[4];
@@ -770,12 +768,12 @@ static int ksz_port_fdb_del(struct dsa_switch *ds, int port,
	mutex_lock(&dev->alu_mutex);

	/* read any entry with mac & vid */
	data = fdb->vid << ALU_FID_INDEX_S;
	data |= ((fdb->addr[0] << 8) | fdb->addr[1]);
	data = vid << ALU_FID_INDEX_S;
	data |= ((addr[0] << 8) | addr[1]);
	ksz_write32(dev, REG_SW_ALU_INDEX_0, data);

	data = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16));
	data |= ((fdb->addr[4] << 8) | fdb->addr[5]);
	data = ((addr[2] << 24) | (addr[3] << 16));
	data |= ((addr[4] << 8) | addr[5]);
	ksz_write32(dev, REG_SW_ALU_INDEX_1, data);

	/* start read operation */
+6 −8
Original line number Diff line number Diff line
@@ -802,8 +802,7 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port,

static int
mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,
			const struct switchdev_obj_port_fdb *fdb,
			struct switchdev_trans *trans)
			const unsigned char *addr, u16 vid)
{
	struct mt7530_priv *priv = ds->priv;
	int ret;
@@ -813,7 +812,7 @@ mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,
	 * is called while the entry is still available.
	 */
	mutex_lock(&priv->reg_mutex);
	mt7530_fdb_write(priv, fdb->vid, 0, fdb->addr, -1, STATIC_ENT);
	mt7530_fdb_write(priv, vid, 0, addr, -1, STATIC_ENT);
	ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
	mutex_unlock(&priv->reg_mutex);

@@ -822,28 +821,27 @@ mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,

static void
mt7530_port_fdb_add(struct dsa_switch *ds, int port,
		    const struct switchdev_obj_port_fdb *fdb,
		    struct switchdev_trans *trans)
		    const unsigned char *addr, u16 vid)
{
	struct mt7530_priv *priv = ds->priv;
	u8 port_mask = BIT(port);

	mutex_lock(&priv->reg_mutex);
	mt7530_fdb_write(priv, fdb->vid, port_mask, fdb->addr, -1, STATIC_ENT);
	mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT);
	mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
	mutex_unlock(&priv->reg_mutex);
}

static int
mt7530_port_fdb_del(struct dsa_switch *ds, int port,
		    const struct switchdev_obj_port_fdb *fdb)
		    const unsigned char *addr, u16 vid)
{
	struct mt7530_priv *priv = ds->priv;
	int ret;
	u8 port_mask = BIT(port);

	mutex_lock(&priv->reg_mutex);
	mt7530_fdb_write(priv, fdb->vid, port_mask, fdb->addr, -1, STATIC_EMP);
	mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_EMP);
	ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
	mutex_unlock(&priv->reg_mutex);

+5 −7
Original line number Diff line number Diff line
@@ -1407,8 +1407,7 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
}

static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
				      const struct switchdev_obj_port_fdb *fdb,
				      struct switchdev_trans *trans)
				      const unsigned char *addr, u16 vid)
{
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
@@ -1417,13 +1416,12 @@ static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
}

static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_fdb *fdb,
				   struct switchdev_trans *trans)
				   const unsigned char *addr, u16 vid)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
	if (mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC))
		dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
			port);
@@ -1431,13 +1429,13 @@ static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
}

static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
				  const struct switchdev_obj_port_fdb *fdb)
				  const unsigned char *addr, u16 vid)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
	mutex_unlock(&chip->reg_lock);

Loading