Skip to content

Commit 8782051

Browse files
viviendavem330
authored andcommitted
net: dsa: mv88e6xxx: rework FDB add/del operations
Add a low level function for the ATU Load operation, and provide FDB add and delete wrappers functions. Signed-off-by: Vivien Didelot <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6630e23 commit 8782051

File tree

4 files changed

+80
-42
lines changed

4 files changed

+80
-42
lines changed

drivers/net/dsa/mv88e6171.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ struct dsa_switch_driver mv88e6171_switch_driver = {
116116
.port_join_bridge = mv88e6xxx_join_bridge,
117117
.port_leave_bridge = mv88e6xxx_leave_bridge,
118118
.port_stp_update = mv88e6xxx_port_stp_update,
119+
.port_fdb_add = mv88e6xxx_port_fdb_add,
120+
.port_fdb_del = mv88e6xxx_port_fdb_del,
119121
.port_fdb_getnext = mv88e6xxx_port_fdb_getnext,
120122
};
121123

drivers/net/dsa/mv88e6352.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ struct dsa_switch_driver mv88e6352_switch_driver = {
341341
.port_join_bridge = mv88e6xxx_join_bridge,
342342
.port_leave_bridge = mv88e6xxx_leave_bridge,
343343
.port_stp_update = mv88e6xxx_port_stp_update,
344+
.port_fdb_add = mv88e6xxx_port_fdb_add,
345+
.port_fdb_del = mv88e6xxx_port_fdb_del,
344346
.port_fdb_getnext = mv88e6xxx_port_fdb_getnext,
345347
};
346348

drivers/net/dsa/mv88e6xxx.c

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,59 +1214,42 @@ static int _mv88e6xxx_atu_mac_read(struct dsa_switch *ds, u8 addr[ETH_ALEN])
12141214
return 0;
12151215
}
12161216

1217-
static int __mv88e6xxx_port_fdb_cmd(struct dsa_switch *ds, int port,
1218-
const unsigned char *addr, int state)
1217+
static int _mv88e6xxx_atu_load(struct dsa_switch *ds,
1218+
struct mv88e6xxx_atu_entry *entry)
12191219
{
1220-
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1221-
u8 fid = ps->fid[port];
1220+
u16 reg = 0;
12221221
int ret;
12231222

12241223
ret = _mv88e6xxx_atu_wait(ds);
12251224
if (ret < 0)
12261225
return ret;
12271226

1228-
ret = _mv88e6xxx_atu_mac_write(ds, addr);
1227+
ret = _mv88e6xxx_atu_mac_write(ds, entry->mac);
12291228
if (ret < 0)
12301229
return ret;
12311230

1232-
ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_DATA,
1233-
(0x10 << port) | state);
1234-
if (ret)
1235-
return ret;
1231+
if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1232+
unsigned int mask, shift;
12361233

1237-
ret = _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_LOAD_DB);
1234+
if (entry->trunk) {
1235+
reg |= GLOBAL_ATU_DATA_TRUNK;
1236+
mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1237+
shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1238+
} else {
1239+
mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1240+
shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1241+
}
12381242

1239-
return ret;
1240-
}
1243+
reg |= (entry->portv_trunkid << shift) & mask;
1244+
}
12411245

1242-
int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1243-
const unsigned char *addr, u16 vid)
1244-
{
1245-
int state = is_multicast_ether_addr(addr) ?
1246-
GLOBAL_ATU_DATA_STATE_MC_STATIC :
1247-
GLOBAL_ATU_DATA_STATE_UC_STATIC;
1248-
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1249-
int ret;
1246+
reg |= entry->state & GLOBAL_ATU_DATA_STATE_MASK;
12501247

1251-
mutex_lock(&ps->smi_mutex);
1252-
ret = __mv88e6xxx_port_fdb_cmd(ds, port, addr, state);
1253-
mutex_unlock(&ps->smi_mutex);
1248+
ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_DATA, reg);
1249+
if (ret < 0)
1250+
return ret;
12541251

1255-
return ret;
1256-
}
1257-
1258-
int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1259-
const unsigned char *addr, u16 vid)
1260-
{
1261-
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1262-
int ret;
1263-
1264-
mutex_lock(&ps->smi_mutex);
1265-
ret = __mv88e6xxx_port_fdb_cmd(ds, port, addr,
1266-
GLOBAL_ATU_DATA_STATE_UNUSED);
1267-
mutex_unlock(&ps->smi_mutex);
1268-
1269-
return ret;
1252+
return _mv88e6xxx_atu_cmd(ds, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
12701253
}
12711254

12721255
static int _mv88e6xxx_atu_getnext(struct dsa_switch *ds, u16 fid,
@@ -1329,6 +1312,57 @@ static int _mv88e6xxx_port_vid_to_fid(struct dsa_switch *ds, int port, u16 vid)
13291312
return -ENOENT;
13301313
}
13311314

1315+
static int _mv88e6xxx_port_fdb_load(struct dsa_switch *ds, int port, u16 vid,
1316+
const u8 addr[ETH_ALEN], u8 state)
1317+
{
1318+
struct mv88e6xxx_atu_entry entry = { 0 };
1319+
int ret;
1320+
1321+
ret = _mv88e6xxx_port_vid_to_fid(ds, port, vid);
1322+
if (ret < 0)
1323+
return ret;
1324+
1325+
entry.fid = ret;
1326+
entry.state = state;
1327+
ether_addr_copy(entry.mac, addr);
1328+
if (state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1329+
entry.trunk = false;
1330+
entry.portv_trunkid = BIT(port);
1331+
}
1332+
1333+
return _mv88e6xxx_atu_load(ds, &entry);
1334+
}
1335+
1336+
int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port, u16 vid,
1337+
const u8 addr[ETH_ALEN])
1338+
{
1339+
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1340+
u8 state = is_multicast_ether_addr(addr) ?
1341+
GLOBAL_ATU_DATA_STATE_MC_STATIC :
1342+
GLOBAL_ATU_DATA_STATE_UC_STATIC;
1343+
int ret;
1344+
1345+
mutex_lock(&ps->smi_mutex);
1346+
ret = _mv88e6xxx_port_fdb_load(ds, port, vid, addr, state);
1347+
mutex_unlock(&ps->smi_mutex);
1348+
1349+
return ret;
1350+
}
1351+
1352+
int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port, u16 vid,
1353+
const u8 addr[ETH_ALEN])
1354+
{
1355+
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1356+
u8 state = GLOBAL_ATU_DATA_STATE_UNUSED;
1357+
int ret;
1358+
1359+
mutex_lock(&ps->smi_mutex);
1360+
ret = _mv88e6xxx_port_fdb_load(ds, port, vid, addr, state);
1361+
mutex_unlock(&ps->smi_mutex);
1362+
1363+
return ret;
1364+
}
1365+
13321366
int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port, u16 *vid,
13331367
u8 addr[ETH_ALEN], bool *is_static)
13341368
{

drivers/net/dsa/mv88e6xxx.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
422422
int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask);
423423
int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask);
424424
int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state);
425-
int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
426-
const unsigned char *addr, u16 vid);
427-
int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
428-
const unsigned char *addr, u16 vid);
429425
int mv88e6xxx_phy_page_read(struct dsa_switch *ds, int port, int page, int reg);
430426
int mv88e6xxx_phy_page_write(struct dsa_switch *ds, int port, int page,
431427
int reg, int val);
428+
int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port, u16 vid,
429+
const u8 addr[ETH_ALEN]);
430+
int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port, u16 vid,
431+
const u8 addr[ETH_ALEN]);
432432
int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port, u16 *vid,
433433
u8 addr[ETH_ALEN], bool *is_static);
434434

0 commit comments

Comments
 (0)