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

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
...@@ -1214,8 +1214,7 @@ static int b53_arl_op(struct b53_device *dev, int op, int port, ...@@ -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, int b53_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
struct b53_device *priv = ds->priv; struct b53_device *priv = ds->priv;
...@@ -1230,22 +1229,21 @@ int b53_fdb_prepare(struct dsa_switch *ds, int port, ...@@ -1230,22 +1229,21 @@ int b53_fdb_prepare(struct dsa_switch *ds, int port,
EXPORT_SYMBOL(b53_fdb_prepare); EXPORT_SYMBOL(b53_fdb_prepare);
void b53_fdb_add(struct dsa_switch *ds, int port, void b53_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
struct b53_device *priv = ds->priv; 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__); pr_err("%s: failed to add MAC address\n", __func__);
} }
EXPORT_SYMBOL(b53_fdb_add); EXPORT_SYMBOL(b53_fdb_add);
int b53_fdb_del(struct dsa_switch *ds, int port, 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; 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); EXPORT_SYMBOL(b53_fdb_del);
......
...@@ -397,13 +397,11 @@ int b53_vlan_dump(struct dsa_switch *ds, int port, ...@@ -397,13 +397,11 @@ int b53_vlan_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_vlan *vlan, struct switchdev_obj_port_vlan *vlan,
switchdev_obj_dump_cb_t *cb); switchdev_obj_dump_cb_t *cb);
int b53_fdb_prepare(struct dsa_switch *ds, int port, int b53_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid);
struct switchdev_trans *trans);
void b53_fdb_add(struct dsa_switch *ds, int port, void b53_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid);
struct switchdev_trans *trans);
int b53_fdb_del(struct dsa_switch *ds, int port, 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, int b53_fdb_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_fdb *fdb, struct switchdev_obj_port_fdb *fdb,
switchdev_obj_dump_cb_t *cb); switchdev_obj_dump_cb_t *cb);
......
...@@ -679,8 +679,7 @@ static int ksz_port_vlan_dump(struct dsa_switch *ds, int port, ...@@ -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, static int ksz_port_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
/* nothing needed */ /* nothing needed */
...@@ -707,8 +706,7 @@ struct alu_struct { ...@@ -707,8 +706,7 @@ struct alu_struct {
}; };
static void ksz_port_fdb_add(struct dsa_switch *ds, int port, static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
struct ksz_device *dev = ds->priv; struct ksz_device *dev = ds->priv;
u32 alu_table[4]; u32 alu_table[4];
...@@ -717,12 +715,12 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port, ...@@ -717,12 +715,12 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
mutex_lock(&dev->alu_mutex); mutex_lock(&dev->alu_mutex);
/* find any entry with mac & vid */ /* find any entry with mac & vid */
data = fdb->vid << ALU_FID_INDEX_S; data = vid << ALU_FID_INDEX_S;
data |= ((fdb->addr[0] << 8) | fdb->addr[1]); data |= ((addr[0] << 8) | addr[1]);
ksz_write32(dev, REG_SW_ALU_INDEX_0, data); ksz_write32(dev, REG_SW_ALU_INDEX_0, data);
data = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16)); data = ((addr[2] << 24) | (addr[3] << 16));
data |= ((fdb->addr[4] << 8) | fdb->addr[5]); data |= ((addr[4] << 8) | addr[5]);
ksz_write32(dev, REG_SW_ALU_INDEX_1, data); ksz_write32(dev, REG_SW_ALU_INDEX_1, data);
/* start read operation */ /* start read operation */
...@@ -740,12 +738,12 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port, ...@@ -740,12 +738,12 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
/* update ALU entry */ /* update ALU entry */
alu_table[0] = ALU_V_STATIC_VALID; alu_table[0] = ALU_V_STATIC_VALID;
alu_table[1] |= BIT(port); alu_table[1] |= BIT(port);
if (fdb->vid) if (vid)
alu_table[1] |= ALU_V_USE_FID; alu_table[1] |= ALU_V_USE_FID;
alu_table[2] = (fdb->vid << ALU_V_FID_S); alu_table[2] = (vid << ALU_V_FID_S);
alu_table[2] |= ((fdb->addr[0] << 8) | fdb->addr[1]); alu_table[2] |= ((addr[0] << 8) | addr[1]);
alu_table[3] = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16)); alu_table[3] = ((addr[2] << 24) | (addr[3] << 16));
alu_table[3] |= ((fdb->addr[4] << 8) | fdb->addr[5]); alu_table[3] |= ((addr[4] << 8) | addr[5]);
write_table(ds, alu_table); write_table(ds, alu_table);
...@@ -760,7 +758,7 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port, ...@@ -760,7 +758,7 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
} }
static int ksz_port_fdb_del(struct dsa_switch *ds, int port, 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; struct ksz_device *dev = ds->priv;
u32 alu_table[4]; u32 alu_table[4];
...@@ -770,12 +768,12 @@ static int ksz_port_fdb_del(struct dsa_switch *ds, int port, ...@@ -770,12 +768,12 @@ static int ksz_port_fdb_del(struct dsa_switch *ds, int port,
mutex_lock(&dev->alu_mutex); mutex_lock(&dev->alu_mutex);
/* read any entry with mac & vid */ /* read any entry with mac & vid */
data = fdb->vid << ALU_FID_INDEX_S; data = vid << ALU_FID_INDEX_S;
data |= ((fdb->addr[0] << 8) | fdb->addr[1]); data |= ((addr[0] << 8) | addr[1]);
ksz_write32(dev, REG_SW_ALU_INDEX_0, data); ksz_write32(dev, REG_SW_ALU_INDEX_0, data);
data = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16)); data = ((addr[2] << 24) | (addr[3] << 16));
data |= ((fdb->addr[4] << 8) | fdb->addr[5]); data |= ((addr[4] << 8) | addr[5]);
ksz_write32(dev, REG_SW_ALU_INDEX_1, data); ksz_write32(dev, REG_SW_ALU_INDEX_1, data);
/* start read operation */ /* start read operation */
......
...@@ -802,8 +802,7 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port, ...@@ -802,8 +802,7 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port,
static int static int
mt7530_port_fdb_prepare(struct dsa_switch *ds, int port, mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
struct mt7530_priv *priv = ds->priv; struct mt7530_priv *priv = ds->priv;
int ret; int ret;
...@@ -813,7 +812,7 @@ mt7530_port_fdb_prepare(struct dsa_switch *ds, int port, ...@@ -813,7 +812,7 @@ mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,
* is called while the entry is still available. * is called while the entry is still available.
*/ */
mutex_lock(&priv->reg_mutex); 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); ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
mutex_unlock(&priv->reg_mutex); mutex_unlock(&priv->reg_mutex);
...@@ -822,28 +821,27 @@ mt7530_port_fdb_prepare(struct dsa_switch *ds, int port, ...@@ -822,28 +821,27 @@ mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,
static void static void
mt7530_port_fdb_add(struct dsa_switch *ds, int port, mt7530_port_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
struct mt7530_priv *priv = ds->priv; struct mt7530_priv *priv = ds->priv;
u8 port_mask = BIT(port); u8 port_mask = BIT(port);
mutex_lock(&priv->reg_mutex); 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); mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
mutex_unlock(&priv->reg_mutex); mutex_unlock(&priv->reg_mutex);
} }
static int static int
mt7530_port_fdb_del(struct dsa_switch *ds, int port, 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; struct mt7530_priv *priv = ds->priv;
int ret; int ret;
u8 port_mask = BIT(port); u8 port_mask = BIT(port);
mutex_lock(&priv->reg_mutex); 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); ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
mutex_unlock(&priv->reg_mutex); mutex_unlock(&priv->reg_mutex);
......
...@@ -1407,8 +1407,7 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port, ...@@ -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, static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
/* We don't need any dynamic resource from the kernel (yet), /* We don't need any dynamic resource from the kernel (yet),
* so skip the prepare phase. * so skip the prepare phase.
...@@ -1417,13 +1416,12 @@ static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port, ...@@ -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, static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
mutex_lock(&chip->reg_lock); 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)) MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC))
dev_err(ds->dev, "p%d: failed to load unicast MAC address\n", dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
port); port);
...@@ -1431,13 +1429,13 @@ static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int 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, 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; struct mv88e6xxx_chip *chip = ds->priv;
int err; int err;
mutex_lock(&chip->reg_lock); 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); MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
mutex_unlock(&chip->reg_lock); mutex_unlock(&chip->reg_lock);
......
...@@ -778,8 +778,7 @@ qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr, ...@@ -778,8 +778,7 @@ qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr,
static int static int
qca8k_port_fdb_prepare(struct dsa_switch *ds, int port, qca8k_port_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
...@@ -788,33 +787,31 @@ qca8k_port_fdb_prepare(struct dsa_switch *ds, int port, ...@@ -788,33 +787,31 @@ qca8k_port_fdb_prepare(struct dsa_switch *ds, int port,
* when port_fdb_add is called an entry is still available. Otherwise * when port_fdb_add is called an entry is still available. Otherwise
* the last free entry might have been used up by auto learning * the last free entry might have been used up by auto learning
*/ */
return qca8k_port_fdb_insert(priv, fdb->addr, 0, fdb->vid); return qca8k_port_fdb_insert(priv, addr, 0, vid);
} }
static void static void
qca8k_port_fdb_add(struct dsa_switch *ds, int port, qca8k_port_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid)
struct switchdev_trans *trans)
{ {
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
u16 port_mask = BIT(port); u16 port_mask = BIT(port);
/* Update the FDB entry adding the port_mask */ /* Update the FDB entry adding the port_mask */
qca8k_port_fdb_insert(priv, fdb->addr, port_mask, fdb->vid); qca8k_port_fdb_insert(priv, addr, port_mask, vid);
} }
static int static int
qca8k_port_fdb_del(struct dsa_switch *ds, int port, qca8k_port_fdb_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb) const unsigned char *addr, u16 vid)
{ {
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
u16 port_mask = BIT(port); u16 port_mask = BIT(port);
u16 vid = fdb->vid;
if (!vid) if (!vid)
vid = 1; vid = 1;
return qca8k_fdb_del(priv, fdb->addr, port_mask, vid); return qca8k_fdb_del(priv, addr, port_mask, vid);
} }
static int static int
......
...@@ -386,13 +386,11 @@ struct dsa_switch_ops { ...@@ -386,13 +386,11 @@ struct dsa_switch_ops {
* Forwarding database * Forwarding database
*/ */
int (*port_fdb_prepare)(struct dsa_switch *ds, int port, int (*port_fdb_prepare)(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid);
struct switchdev_trans *trans);
void (*port_fdb_add)(struct dsa_switch *ds, int port, void (*port_fdb_add)(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb, const unsigned char *addr, u16 vid);
struct switchdev_trans *trans);
int (*port_fdb_del)(struct dsa_switch *ds, int port, int (*port_fdb_del)(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb); const unsigned char *addr, u16 vid);
int (*port_fdb_dump)(struct dsa_switch *ds, int port, int (*port_fdb_dump)(struct dsa_switch *ds, int port,
struct switchdev_obj_port_fdb *fdb, struct switchdev_obj_port_fdb *fdb,
switchdev_obj_dump_cb_t *cb); switchdev_obj_dump_cb_t *cb);
......
...@@ -94,10 +94,11 @@ static int dsa_switch_fdb_add(struct dsa_switch *ds, ...@@ -94,10 +94,11 @@ static int dsa_switch_fdb_add(struct dsa_switch *ds,
if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add) if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return ds->ops->port_fdb_prepare(ds, info->port, fdb, trans); return ds->ops->port_fdb_prepare(ds, info->port, fdb->addr,
fdb->vid);
} }
ds->ops->port_fdb_add(ds, info->port, fdb, trans); ds->ops->port_fdb_add(ds, info->port, fdb->addr, fdb->vid);
return 0; return 0;
} }
...@@ -114,7 +115,8 @@ static int dsa_switch_fdb_del(struct dsa_switch *ds, ...@@ -114,7 +115,8 @@ static int dsa_switch_fdb_del(struct dsa_switch *ds,
if (!ds->ops->port_fdb_del) if (!ds->ops->port_fdb_del)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return ds->ops->port_fdb_del(ds, info->port, fdb); return ds->ops->port_fdb_del(ds, info->port, fdb->addr,
fdb->vid);
} }
static int dsa_switch_mdb_add(struct dsa_switch *ds, static int dsa_switch_mdb_add(struct dsa_switch *ds,
......
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