Skip to content

Commit 6c2c1dc

Browse files
Arkadi Sharshevskydavem330
authored andcommitted
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: Arkadi Sharshevsky <arkadis@mellanox.com> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 511aeaf commit 6c2c1dc

File tree

8 files changed

+49
-62
lines changed

8 files changed

+49
-62
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,7 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
12141214
}
12151215

12161216
int b53_fdb_prepare(struct dsa_switch *ds, int port,
1217-
const struct switchdev_obj_port_fdb *fdb,
1218-
struct switchdev_trans *trans)
1217+
const unsigned char *addr, u16 vid)
12191218
{
12201219
struct b53_device *priv = ds->priv;
12211220

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

12321231
void b53_fdb_add(struct dsa_switch *ds, int port,
1233-
const struct switchdev_obj_port_fdb *fdb,
1234-
struct switchdev_trans *trans)
1232+
const unsigned char *addr, u16 vid)
12351233
{
12361234
struct b53_device *priv = ds->priv;
12371235

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

12431241
int b53_fdb_del(struct dsa_switch *ds, int port,
1244-
const struct switchdev_obj_port_fdb *fdb)
1242+
const unsigned char *addr, u16 vid)
12451243
{
12461244
struct b53_device *priv = ds->priv;
12471245

1248-
return b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, false);
1246+
return b53_arl_op(priv, 0, port, addr, vid, false);
12491247
}
12501248
EXPORT_SYMBOL(b53_fdb_del);
12511249

drivers/net/dsa/b53/b53_priv.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,11 @@ int b53_vlan_dump(struct dsa_switch *ds, int port,
397397
struct switchdev_obj_port_vlan *vlan,
398398
switchdev_obj_dump_cb_t *cb);
399399
int b53_fdb_prepare(struct dsa_switch *ds, int port,
400-
const struct switchdev_obj_port_fdb *fdb,
401-
struct switchdev_trans *trans);
400+
const unsigned char *addr, u16 vid);
402401
void b53_fdb_add(struct dsa_switch *ds, int port,
403-
const struct switchdev_obj_port_fdb *fdb,
404-
struct switchdev_trans *trans);
402+
const unsigned char *addr, u16 vid);
405403
int b53_fdb_del(struct dsa_switch *ds, int port,
406-
const struct switchdev_obj_port_fdb *fdb);
404+
const unsigned char *addr, u16 vid);
407405
int b53_fdb_dump(struct dsa_switch *ds, int port,
408406
struct switchdev_obj_port_fdb *fdb,
409407
switchdev_obj_dump_cb_t *cb);

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ static int ksz_port_vlan_dump(struct dsa_switch *ds, int port,
679679
}
680680

681681
static int ksz_port_fdb_prepare(struct dsa_switch *ds, int port,
682-
const struct switchdev_obj_port_fdb *fdb,
683-
struct switchdev_trans *trans)
682+
const unsigned char *addr, u16 vid)
684683
{
685684
/* nothing needed */
686685

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

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

719717
/* find any entry with mac & vid */
720-
data = fdb->vid << ALU_FID_INDEX_S;
721-
data |= ((fdb->addr[0] << 8) | fdb->addr[1]);
718+
data = vid << ALU_FID_INDEX_S;
719+
data |= ((addr[0] << 8) | addr[1]);
722720
ksz_write32(dev, REG_SW_ALU_INDEX_0, data);
723721

724-
data = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16));
725-
data |= ((fdb->addr[4] << 8) | fdb->addr[5]);
722+
data = ((addr[2] << 24) | (addr[3] << 16));
723+
data |= ((addr[4] << 8) | addr[5]);
726724
ksz_write32(dev, REG_SW_ALU_INDEX_1, data);
727725

728726
/* start read operation */
@@ -740,12 +738,12 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
740738
/* update ALU entry */
741739
alu_table[0] = ALU_V_STATIC_VALID;
742740
alu_table[1] |= BIT(port);
743-
if (fdb->vid)
741+
if (vid)
744742
alu_table[1] |= ALU_V_USE_FID;
745-
alu_table[2] = (fdb->vid << ALU_V_FID_S);
746-
alu_table[2] |= ((fdb->addr[0] << 8) | fdb->addr[1]);
747-
alu_table[3] = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16));
748-
alu_table[3] |= ((fdb->addr[4] << 8) | fdb->addr[5]);
743+
alu_table[2] = (vid << ALU_V_FID_S);
744+
alu_table[2] |= ((addr[0] << 8) | addr[1]);
745+
alu_table[3] = ((addr[2] << 24) | (addr[3] << 16));
746+
alu_table[3] |= ((addr[4] << 8) | addr[5]);
749747

750748
write_table(ds, alu_table);
751749

@@ -760,7 +758,7 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
760758
}
761759

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

772770
/* read any entry with mac & vid */
773-
data = fdb->vid << ALU_FID_INDEX_S;
774-
data |= ((fdb->addr[0] << 8) | fdb->addr[1]);
771+
data = vid << ALU_FID_INDEX_S;
772+
data |= ((addr[0] << 8) | addr[1]);
775773
ksz_write32(dev, REG_SW_ALU_INDEX_0, data);
776774

777-
data = ((fdb->addr[2] << 24) | (fdb->addr[3] << 16));
778-
data |= ((fdb->addr[4] << 8) | fdb->addr[5]);
775+
data = ((addr[2] << 24) | (addr[3] << 16));
776+
data |= ((addr[4] << 8) | addr[5]);
779777
ksz_write32(dev, REG_SW_ALU_INDEX_1, data);
780778

781779
/* start read operation */

drivers/net/dsa/mt7530.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,7 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port,
802802

803803
static int
804804
mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,
805-
const struct switchdev_obj_port_fdb *fdb,
806-
struct switchdev_trans *trans)
805+
const unsigned char *addr, u16 vid)
807806
{
808807
struct mt7530_priv *priv = ds->priv;
809808
int ret;
@@ -813,7 +812,7 @@ mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,
813812
* is called while the entry is still available.
814813
*/
815814
mutex_lock(&priv->reg_mutex);
816-
mt7530_fdb_write(priv, fdb->vid, 0, fdb->addr, -1, STATIC_ENT);
815+
mt7530_fdb_write(priv, vid, 0, addr, -1, STATIC_ENT);
817816
ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
818817
mutex_unlock(&priv->reg_mutex);
819818

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

823822
static void
824823
mt7530_port_fdb_add(struct dsa_switch *ds, int port,
825-
const struct switchdev_obj_port_fdb *fdb,
826-
struct switchdev_trans *trans)
824+
const unsigned char *addr, u16 vid)
827825
{
828826
struct mt7530_priv *priv = ds->priv;
829827
u8 port_mask = BIT(port);
830828

831829
mutex_lock(&priv->reg_mutex);
832-
mt7530_fdb_write(priv, fdb->vid, port_mask, fdb->addr, -1, STATIC_ENT);
830+
mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT);
833831
mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
834832
mutex_unlock(&priv->reg_mutex);
835833
}
836834

837835
static int
838836
mt7530_port_fdb_del(struct dsa_switch *ds, int port,
839-
const struct switchdev_obj_port_fdb *fdb)
837+
const unsigned char *addr, u16 vid)
840838
{
841839
struct mt7530_priv *priv = ds->priv;
842840
int ret;
843841
u8 port_mask = BIT(port);
844842

845843
mutex_lock(&priv->reg_mutex);
846-
mt7530_fdb_write(priv, fdb->vid, port_mask, fdb->addr, -1, STATIC_EMP);
844+
mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_EMP);
847845
ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
848846
mutex_unlock(&priv->reg_mutex);
849847

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,7 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
14071407
}
14081408

14091409
static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1410-
const struct switchdev_obj_port_fdb *fdb,
1411-
struct switchdev_trans *trans)
1410+
const unsigned char *addr, u16 vid)
14121411
{
14131412
/* We don't need any dynamic resource from the kernel (yet),
14141413
* so skip the prepare phase.
@@ -1417,27 +1416,26 @@ static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
14171416
}
14181417

14191418
static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1420-
const struct switchdev_obj_port_fdb *fdb,
1421-
struct switchdev_trans *trans)
1419+
const unsigned char *addr, u16 vid)
14221420
{
14231421
struct mv88e6xxx_chip *chip = ds->priv;
14241422

14251423
mutex_lock(&chip->reg_lock);
1426-
if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1424+
if (mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
14271425
MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC))
14281426
dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
14291427
port);
14301428
mutex_unlock(&chip->reg_lock);
14311429
}
14321430

14331431
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1434-
const struct switchdev_obj_port_fdb *fdb)
1432+
const unsigned char *addr, u16 vid)
14351433
{
14361434
struct mv88e6xxx_chip *chip = ds->priv;
14371435
int err;
14381436

14391437
mutex_lock(&chip->reg_lock);
1440-
err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1438+
err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
14411439
MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
14421440
mutex_unlock(&chip->reg_lock);
14431441

drivers/net/dsa/qca8k.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,7 @@ qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr,
778778

779779
static int
780780
qca8k_port_fdb_prepare(struct dsa_switch *ds, int port,
781-
const struct switchdev_obj_port_fdb *fdb,
782-
struct switchdev_trans *trans)
781+
const unsigned char *addr, u16 vid)
783782
{
784783
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
785784

@@ -788,33 +787,31 @@ qca8k_port_fdb_prepare(struct dsa_switch *ds, int port,
788787
* when port_fdb_add is called an entry is still available. Otherwise
789788
* the last free entry might have been used up by auto learning
790789
*/
791-
return qca8k_port_fdb_insert(priv, fdb->addr, 0, fdb->vid);
790+
return qca8k_port_fdb_insert(priv, addr, 0, vid);
792791
}
793792

794793
static void
795794
qca8k_port_fdb_add(struct dsa_switch *ds, int port,
796-
const struct switchdev_obj_port_fdb *fdb,
797-
struct switchdev_trans *trans)
795+
const unsigned char *addr, u16 vid)
798796
{
799797
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
800798
u16 port_mask = BIT(port);
801799

802800
/* Update the FDB entry adding the port_mask */
803-
qca8k_port_fdb_insert(priv, fdb->addr, port_mask, fdb->vid);
801+
qca8k_port_fdb_insert(priv, addr, port_mask, vid);
804802
}
805803

806804
static int
807805
qca8k_port_fdb_del(struct dsa_switch *ds, int port,
808-
const struct switchdev_obj_port_fdb *fdb)
806+
const unsigned char *addr, u16 vid)
809807
{
810808
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
811809
u16 port_mask = BIT(port);
812-
u16 vid = fdb->vid;
813810

814811
if (!vid)
815812
vid = 1;
816813

817-
return qca8k_fdb_del(priv, fdb->addr, port_mask, vid);
814+
return qca8k_fdb_del(priv, addr, port_mask, vid);
818815
}
819816

820817
static int

include/net/dsa.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,11 @@ struct dsa_switch_ops {
386386
* Forwarding database
387387
*/
388388
int (*port_fdb_prepare)(struct dsa_switch *ds, int port,
389-
const struct switchdev_obj_port_fdb *fdb,
390-
struct switchdev_trans *trans);
389+
const unsigned char *addr, u16 vid);
391390
void (*port_fdb_add)(struct dsa_switch *ds, int port,
392-
const struct switchdev_obj_port_fdb *fdb,
393-
struct switchdev_trans *trans);
391+
const unsigned char *addr, u16 vid);
394392
int (*port_fdb_del)(struct dsa_switch *ds, int port,
395-
const struct switchdev_obj_port_fdb *fdb);
393+
const unsigned char *addr, u16 vid);
396394
int (*port_fdb_dump)(struct dsa_switch *ds, int port,
397395
struct switchdev_obj_port_fdb *fdb,
398396
switchdev_obj_dump_cb_t *cb);

net/dsa/switch.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ static int dsa_switch_fdb_add(struct dsa_switch *ds,
9494
if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add)
9595
return -EOPNOTSUPP;
9696

97-
return ds->ops->port_fdb_prepare(ds, info->port, fdb, trans);
97+
return ds->ops->port_fdb_prepare(ds, info->port, fdb->addr,
98+
fdb->vid);
9899
}
99100

100-
ds->ops->port_fdb_add(ds, info->port, fdb, trans);
101+
ds->ops->port_fdb_add(ds, info->port, fdb->addr, fdb->vid);
101102

102103
return 0;
103104
}
@@ -114,7 +115,8 @@ static int dsa_switch_fdb_del(struct dsa_switch *ds,
114115
if (!ds->ops->port_fdb_del)
115116
return -EOPNOTSUPP;
116117

117-
return ds->ops->port_fdb_del(ds, info->port, fdb);
118+
return ds->ops->port_fdb_del(ds, info->port, fdb->addr,
119+
fdb->vid);
118120
}
119121

120122
static int dsa_switch_mdb_add(struct dsa_switch *ds,

0 commit comments

Comments
 (0)