Skip to content

Commit 1b6dd55

Browse files
Arkadi Sharshevskydavem330
authored andcommitted
net: dsa: Remove prepare phase for FDB
The prepare phase for FDB add is unneeded because most of DSA devices can have failures during bus transactions (SPI, I2C, etc.), thus, the prepare phase cannot guarantee success of the commit stage. The support for learning FDB through notification chain, which will be introduced in the following patches, will provide the ability to notify back the bridge about successful offload. 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 6c2c1dc commit 1b6dd55

File tree

12 files changed

+36
-108
lines changed

12 files changed

+36
-108
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,8 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
12131213
return b53_arl_rw_op(dev, 0);
12141214
}
12151215

1216-
int b53_fdb_prepare(struct dsa_switch *ds, int port,
1217-
const unsigned char *addr, u16 vid)
1216+
int b53_fdb_add(struct dsa_switch *ds, int port,
1217+
const unsigned char *addr, u16 vid)
12181218
{
12191219
struct b53_device *priv = ds->priv;
12201220

@@ -1224,17 +1224,7 @@ int b53_fdb_prepare(struct dsa_switch *ds, int port,
12241224
if (is5325(priv) || is5365(priv))
12251225
return -EOPNOTSUPP;
12261226

1227-
return 0;
1228-
}
1229-
EXPORT_SYMBOL(b53_fdb_prepare);
1230-
1231-
void b53_fdb_add(struct dsa_switch *ds, int port,
1232-
const unsigned char *addr, u16 vid)
1233-
{
1234-
struct b53_device *priv = ds->priv;
1235-
1236-
if (b53_arl_op(priv, 0, port, addr, vid, true))
1237-
pr_err("%s: failed to add MAC address\n", __func__);
1227+
return b53_arl_op(priv, 0, port, addr, vid, true);
12381228
}
12391229
EXPORT_SYMBOL(b53_fdb_add);
12401230

@@ -1563,7 +1553,6 @@ static const struct dsa_switch_ops b53_switch_ops = {
15631553
.port_vlan_add = b53_vlan_add,
15641554
.port_vlan_del = b53_vlan_del,
15651555
.port_vlan_dump = b53_vlan_dump,
1566-
.port_fdb_prepare = b53_fdb_prepare,
15671556
.port_fdb_dump = b53_fdb_dump,
15681557
.port_fdb_add = b53_fdb_add,
15691558
.port_fdb_del = b53_fdb_del,

drivers/net/dsa/b53/b53_priv.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,8 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
396396
int b53_vlan_dump(struct dsa_switch *ds, int port,
397397
struct switchdev_obj_port_vlan *vlan,
398398
switchdev_obj_dump_cb_t *cb);
399-
int b53_fdb_prepare(struct dsa_switch *ds, int port,
400-
const unsigned char *addr, u16 vid);
401-
void b53_fdb_add(struct dsa_switch *ds, int port,
402-
const unsigned char *addr, u16 vid);
399+
int b53_fdb_add(struct dsa_switch *ds, int port,
400+
const unsigned char *addr, u16 vid);
403401
int b53_fdb_del(struct dsa_switch *ds, int port,
404402
const unsigned char *addr, u16 vid);
405403
int b53_fdb_dump(struct dsa_switch *ds, int port,

drivers/net/dsa/bcm_sf2.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,6 @@ static const struct dsa_switch_ops bcm_sf2_ops = {
10221022
.port_vlan_add = b53_vlan_add,
10231023
.port_vlan_del = b53_vlan_del,
10241024
.port_vlan_dump = b53_vlan_dump,
1025-
.port_fdb_prepare = b53_fdb_prepare,
10261025
.port_fdb_dump = b53_fdb_dump,
10271026
.port_fdb_add = b53_fdb_add,
10281027
.port_fdb_del = b53_fdb_del,

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,6 @@ static int ksz_port_vlan_dump(struct dsa_switch *ds, int port,
678678
return err;
679679
}
680680

681-
static int ksz_port_fdb_prepare(struct dsa_switch *ds, int port,
682-
const unsigned char *addr, u16 vid)
683-
{
684-
/* nothing needed */
685-
686-
return 0;
687-
}
688-
689681
struct alu_struct {
690682
/* entry 1 */
691683
u8 is_static:1;
@@ -705,12 +697,13 @@ struct alu_struct {
705697
u8 mac[ETH_ALEN];
706698
};
707699

708-
static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
709-
const unsigned char *addr, u16 vid)
700+
static int ksz_port_fdb_add(struct dsa_switch *ds, int port,
701+
const unsigned char *addr, u16 vid)
710702
{
711703
struct ksz_device *dev = ds->priv;
712704
u32 alu_table[4];
713705
u32 data;
706+
int ret = 0;
714707

715708
mutex_lock(&dev->alu_mutex);
716709

@@ -727,7 +720,8 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
727720
ksz_write32(dev, REG_SW_ALU_CTRL__4, ALU_READ | ALU_START);
728721

729722
/* wait to be finished */
730-
if (wait_alu_ready(dev, ALU_START, 1000) < 0) {
723+
ret = wait_alu_ready(dev, ALU_START, 1000);
724+
if (ret < 0) {
731725
dev_dbg(dev->dev, "Failed to read ALU\n");
732726
goto exit;
733727
}
@@ -750,11 +744,14 @@ static void ksz_port_fdb_add(struct dsa_switch *ds, int port,
750744
ksz_write32(dev, REG_SW_ALU_CTRL__4, ALU_WRITE | ALU_START);
751745

752746
/* wait to be finished */
753-
if (wait_alu_ready(dev, ALU_START, 1000) < 0)
754-
dev_dbg(dev->dev, "Failed to read ALU\n");
747+
ret = wait_alu_ready(dev, ALU_START, 1000);
748+
if (ret < 0)
749+
dev_dbg(dev->dev, "Failed to write ALU\n");
755750

756751
exit:
757752
mutex_unlock(&dev->alu_mutex);
753+
754+
return ret;
758755
}
759756

760757
static int ksz_port_fdb_del(struct dsa_switch *ds, int port,
@@ -1128,7 +1125,6 @@ static const struct dsa_switch_ops ksz_switch_ops = {
11281125
.port_vlan_add = ksz_port_vlan_add,
11291126
.port_vlan_del = ksz_port_vlan_del,
11301127
.port_vlan_dump = ksz_port_vlan_dump,
1131-
.port_fdb_prepare = ksz_port_fdb_prepare,
11321128
.port_fdb_dump = ksz_port_fdb_dump,
11331129
.port_fdb_add = ksz_port_fdb_add,
11341130
.port_fdb_del = ksz_port_fdb_del,

drivers/net/dsa/mt7530.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -801,35 +801,19 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port,
801801
}
802802

803803
static int
804-
mt7530_port_fdb_prepare(struct dsa_switch *ds, int port,
805-
const unsigned char *addr, u16 vid)
806-
{
807-
struct mt7530_priv *priv = ds->priv;
808-
int ret;
809-
810-
/* Because auto-learned entrie shares the same FDB table.
811-
* an entry is reserved with no port_mask to make sure fdb_add
812-
* is called while the entry is still available.
813-
*/
814-
mutex_lock(&priv->reg_mutex);
815-
mt7530_fdb_write(priv, vid, 0, addr, -1, STATIC_ENT);
816-
ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
817-
mutex_unlock(&priv->reg_mutex);
818-
819-
return ret;
820-
}
821-
822-
static void
823804
mt7530_port_fdb_add(struct dsa_switch *ds, int port,
824805
const unsigned char *addr, u16 vid)
825806
{
826807
struct mt7530_priv *priv = ds->priv;
808+
int ret;
827809
u8 port_mask = BIT(port);
828810

829811
mutex_lock(&priv->reg_mutex);
830812
mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT);
831-
mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
813+
ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, 0);
832814
mutex_unlock(&priv->reg_mutex);
815+
816+
return ret;
833817
}
834818

835819
static int
@@ -1013,7 +997,6 @@ static struct dsa_switch_ops mt7530_switch_ops = {
1013997
.port_stp_state_set = mt7530_stp_state_set,
1014998
.port_bridge_join = mt7530_port_bridge_join,
1015999
.port_bridge_leave = mt7530_port_bridge_leave,
1016-
.port_fdb_prepare = mt7530_port_fdb_prepare,
10171000
.port_fdb_add = mt7530_port_fdb_add,
10181001
.port_fdb_del = mt7530_port_fdb_del,
10191002
.port_fdb_dump = mt7530_port_fdb_dump,

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,26 +1406,18 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
14061406
return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
14071407
}
14081408

1409-
static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1410-
const unsigned char *addr, u16 vid)
1411-
{
1412-
/* We don't need any dynamic resource from the kernel (yet),
1413-
* so skip the prepare phase.
1414-
*/
1415-
return 0;
1416-
}
1417-
1418-
static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1419-
const unsigned char *addr, u16 vid)
1409+
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1410+
const unsigned char *addr, u16 vid)
14201411
{
14211412
struct mv88e6xxx_chip *chip = ds->priv;
1413+
int err;
14221414

14231415
mutex_lock(&chip->reg_lock);
1424-
if (mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1425-
MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC))
1426-
dev_err(ds->dev, "p%d: failed to load unicast MAC address\n",
1427-
port);
1416+
err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1417+
MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
14281418
mutex_unlock(&chip->reg_lock);
1419+
1420+
return err;
14291421
}
14301422

14311423
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
@@ -3905,7 +3897,6 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
39053897
.port_vlan_add = mv88e6xxx_port_vlan_add,
39063898
.port_vlan_del = mv88e6xxx_port_vlan_del,
39073899
.port_vlan_dump = mv88e6xxx_port_vlan_dump,
3908-
.port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
39093900
.port_fdb_add = mv88e6xxx_port_fdb_add,
39103901
.port_fdb_del = mv88e6xxx_port_fdb_del,
39113902
.port_fdb_dump = mv88e6xxx_port_fdb_dump,

drivers/net/dsa/qca8k.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -777,28 +777,13 @@ qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr,
777777
}
778778

779779
static int
780-
qca8k_port_fdb_prepare(struct dsa_switch *ds, int port,
781-
const unsigned char *addr, u16 vid)
782-
{
783-
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
784-
785-
/* The FDB table for static and auto learned entries is the same. We
786-
* need to reserve an entry with no port_mask set to make sure that
787-
* when port_fdb_add is called an entry is still available. Otherwise
788-
* the last free entry might have been used up by auto learning
789-
*/
790-
return qca8k_port_fdb_insert(priv, addr, 0, vid);
791-
}
792-
793-
static void
794780
qca8k_port_fdb_add(struct dsa_switch *ds, int port,
795781
const unsigned char *addr, u16 vid)
796782
{
797783
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
798784
u16 port_mask = BIT(port);
799785

800-
/* Update the FDB entry adding the port_mask */
801-
qca8k_port_fdb_insert(priv, addr, port_mask, vid);
786+
return qca8k_port_fdb_insert(priv, addr, port_mask, vid);
802787
}
803788

804789
static int
@@ -866,7 +851,6 @@ static const struct dsa_switch_ops qca8k_switch_ops = {
866851
.port_stp_state_set = qca8k_port_stp_state_set,
867852
.port_bridge_join = qca8k_port_bridge_join,
868853
.port_bridge_leave = qca8k_port_bridge_leave,
869-
.port_fdb_prepare = qca8k_port_fdb_prepare,
870854
.port_fdb_add = qca8k_port_fdb_add,
871855
.port_fdb_del = qca8k_port_fdb_del,
872856
.port_fdb_dump = qca8k_port_fdb_dump,

include/net/dsa.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,7 @@ struct dsa_switch_ops {
385385
/*
386386
* Forwarding database
387387
*/
388-
int (*port_fdb_prepare)(struct dsa_switch *ds, int port,
389-
const unsigned char *addr, u16 vid);
390-
void (*port_fdb_add)(struct dsa_switch *ds, int port,
388+
int (*port_fdb_add)(struct dsa_switch *ds, int port,
391389
const unsigned char *addr, u16 vid);
392390
int (*port_fdb_del)(struct dsa_switch *ds, int port,
393391
const unsigned char *addr, u16 vid);

net/dsa/dsa_priv.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ struct dsa_notifier_bridge_info {
4444
/* DSA_NOTIFIER_FDB_* */
4545
struct dsa_notifier_fdb_info {
4646
const struct switchdev_obj_port_fdb *fdb;
47-
struct switchdev_trans *trans;
4847
int sw_index;
4948
int port;
5049
};
@@ -122,8 +121,7 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
122121
int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
123122
struct switchdev_trans *trans);
124123
int dsa_port_fdb_add(struct dsa_port *dp,
125-
const struct switchdev_obj_port_fdb *fdb,
126-
struct switchdev_trans *trans);
124+
const struct switchdev_obj_port_fdb *fdb);
127125
int dsa_port_fdb_del(struct dsa_port *dp,
128126
const struct switchdev_obj_port_fdb *fdb);
129127
int dsa_port_fdb_dump(struct dsa_port *dp, struct switchdev_obj_port_fdb *fdb,

net/dsa/port.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,11 @@ int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
147147
}
148148

149149
int dsa_port_fdb_add(struct dsa_port *dp,
150-
const struct switchdev_obj_port_fdb *fdb,
151-
struct switchdev_trans *trans)
150+
const struct switchdev_obj_port_fdb *fdb)
152151
{
153152
struct dsa_notifier_fdb_info info = {
154153
.sw_index = dp->ds->index,
155154
.port = dp->index,
156-
.trans = trans,
157155
.fdb = fdb,
158156
};
159157

net/dsa/slave.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
251251

252252
switch (obj->id) {
253253
case SWITCHDEV_OBJ_ID_PORT_FDB:
254-
err = dsa_port_fdb_add(dp, SWITCHDEV_OBJ_PORT_FDB(obj), trans);
254+
if (switchdev_trans_ph_prepare(trans))
255+
return 0;
256+
err = dsa_port_fdb_add(dp, SWITCHDEV_OBJ_PORT_FDB(obj));
255257
break;
256258
case SWITCHDEV_OBJ_ID_PORT_MDB:
257259
err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj), trans);

net/dsa/switch.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,15 @@ static int dsa_switch_fdb_add(struct dsa_switch *ds,
8484
struct dsa_notifier_fdb_info *info)
8585
{
8686
const struct switchdev_obj_port_fdb *fdb = info->fdb;
87-
struct switchdev_trans *trans = info->trans;
8887

8988
/* Do not care yet about other switch chips of the fabric */
9089
if (ds->index != info->sw_index)
9190
return 0;
9291

93-
if (switchdev_trans_ph_prepare(trans)) {
94-
if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add)
95-
return -EOPNOTSUPP;
96-
97-
return ds->ops->port_fdb_prepare(ds, info->port, fdb->addr,
98-
fdb->vid);
99-
}
100-
101-
ds->ops->port_fdb_add(ds, info->port, fdb->addr, fdb->vid);
92+
if (!ds->ops->port_fdb_add)
93+
return -EOPNOTSUPP;
10294

103-
return 0;
95+
return ds->ops->port_fdb_add(ds, info->port, fdb->addr, fdb->vid);
10496
}
10597

10698
static int dsa_switch_fdb_del(struct dsa_switch *ds,

0 commit comments

Comments
 (0)