Skip to content

Commit 1fc7261

Browse files
committed
Merge branch 'dsa-port-vlan-dump'
Vivien Didelot says: ==================== net: dsa: add port VLAN dump operation The VLAN GetNext approach is specific to some switches and thus hard to implement for others. This patchset replaces it with a simpler port VLAN dump operation, similar to the corresponding FDB operation. The mv88e6xxx driver is the only one currently affected by the change. The documentation is updated accordingly. Note: this patchset uses http://www.spinics.net/lists/kernel/msg2186705.html ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 2a04c7b + 477b184 commit 1fc7261

File tree

7 files changed

+65
-110
lines changed

7 files changed

+65
-110
lines changed

Documentation/networking/dsa/dsa.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,20 +542,15 @@ Bridge layer
542542
Bridge VLAN filtering
543543
---------------------
544544

545-
- port_pvid_get: bridge layer function invoked when a Port-based VLAN ID is
546-
queried for the given switch port
547-
548-
- port_pvid_set: bridge layer function invoked when a Port-based VLAN ID needs
549-
to be configured on the given switch port
550-
551545
- port_vlan_add: bridge layer function invoked when a VLAN is configured
552546
(tagged or untagged) for the given switch port
553547

554548
- port_vlan_del: bridge layer function invoked when a VLAN is removed from the
555549
given switch port
556550

557-
- vlan_getnext: bridge layer function invoked to query the next configured VLAN
558-
in the switch, i.e. returns the bitmaps of members and untagged ports
551+
- port_vlan_dump: bridge layer function invoked with a switchdev callback
552+
function that the driver has to call for each VLAN the given port is a member
553+
of. A switchdev object is used to carry the VID and bridge flags.
559554

560555
- port_fdb_add: bridge layer function invoked when the bridge wants to install a
561556
Forwarding Database entry, the switch hardware should be programmed with the

drivers/net/dsa/mv88e6171.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,10 @@ struct dsa_switch_driver mv88e6171_switch_driver = {
106106
.port_join_bridge = mv88e6xxx_port_bridge_join,
107107
.port_leave_bridge = mv88e6xxx_port_bridge_leave,
108108
.port_stp_update = mv88e6xxx_port_stp_update,
109-
.port_pvid_get = mv88e6xxx_port_pvid_get,
110109
.port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
111110
.port_vlan_add = mv88e6xxx_port_vlan_add,
112111
.port_vlan_del = mv88e6xxx_port_vlan_del,
113-
.vlan_getnext = mv88e6xxx_vlan_getnext,
112+
.port_vlan_dump = mv88e6xxx_port_vlan_dump,
114113
.port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
115114
.port_fdb_add = mv88e6xxx_port_fdb_add,
116115
.port_fdb_del = mv88e6xxx_port_fdb_del,

drivers/net/dsa/mv88e6352.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,10 @@ struct dsa_switch_driver mv88e6352_switch_driver = {
327327
.port_join_bridge = mv88e6xxx_port_bridge_join,
328328
.port_leave_bridge = mv88e6xxx_port_bridge_leave,
329329
.port_stp_update = mv88e6xxx_port_stp_update,
330-
.port_pvid_get = mv88e6xxx_port_pvid_get,
331330
.port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
332331
.port_vlan_add = mv88e6xxx_port_vlan_add,
333332
.port_vlan_del = mv88e6xxx_port_vlan_del,
334-
.vlan_getnext = mv88e6xxx_vlan_getnext,
333+
.port_vlan_dump = mv88e6xxx_port_vlan_dump,
335334
.port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
336335
.port_fdb_add = mv88e6xxx_port_fdb_add,
337336
.port_fdb_del = mv88e6xxx_port_fdb_del,

drivers/net/dsa/mv88e6xxx.c

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,19 +1151,6 @@ static int _mv88e6xxx_port_pvid_get(struct dsa_switch *ds, int port, u16 *pvid)
11511151
return 0;
11521152
}
11531153

1154-
int mv88e6xxx_port_pvid_get(struct dsa_switch *ds, int port, u16 *pvid)
1155-
{
1156-
int ret;
1157-
1158-
ret = mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_DEFAULT_VLAN);
1159-
if (ret < 0)
1160-
return ret;
1161-
1162-
*pvid = ret & PORT_DEFAULT_VLAN_MASK;
1163-
1164-
return 0;
1165-
}
1166-
11671154
static int _mv88e6xxx_port_pvid_set(struct dsa_switch *ds, int port, u16 pvid)
11681155
{
11691156
return _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_DEFAULT_VLAN,
@@ -1306,6 +1293,57 @@ static int _mv88e6xxx_vtu_getnext(struct dsa_switch *ds,
13061293
return 0;
13071294
}
13081295

1296+
int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1297+
struct switchdev_obj_port_vlan *vlan,
1298+
int (*cb)(struct switchdev_obj *obj))
1299+
{
1300+
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1301+
struct mv88e6xxx_vtu_stu_entry next;
1302+
u16 pvid;
1303+
int err;
1304+
1305+
mutex_lock(&ps->smi_mutex);
1306+
1307+
err = _mv88e6xxx_port_pvid_get(ds, port, &pvid);
1308+
if (err)
1309+
goto unlock;
1310+
1311+
err = _mv88e6xxx_vtu_vid_write(ds, GLOBAL_VTU_VID_MASK);
1312+
if (err)
1313+
goto unlock;
1314+
1315+
do {
1316+
err = _mv88e6xxx_vtu_getnext(ds, &next);
1317+
if (err)
1318+
break;
1319+
1320+
if (!next.valid)
1321+
break;
1322+
1323+
if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1324+
continue;
1325+
1326+
/* reinit and dump this VLAN obj */
1327+
vlan->vid_begin = vlan->vid_end = next.vid;
1328+
vlan->flags = 0;
1329+
1330+
if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1331+
vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1332+
1333+
if (next.vid == pvid)
1334+
vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1335+
1336+
err = cb(&vlan->obj);
1337+
if (err)
1338+
break;
1339+
} while (next.vid < GLOBAL_VTU_VID_MASK);
1340+
1341+
unlock:
1342+
mutex_unlock(&ps->smi_mutex);
1343+
1344+
return err;
1345+
}
1346+
13091347
static int _mv88e6xxx_vtu_loadpurge(struct dsa_switch *ds,
13101348
struct mv88e6xxx_vtu_stu_entry *entry)
13111349
{
@@ -1675,52 +1713,6 @@ int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
16751713
return err;
16761714
}
16771715

1678-
int mv88e6xxx_vlan_getnext(struct dsa_switch *ds, u16 *vid,
1679-
unsigned long *ports, unsigned long *untagged)
1680-
{
1681-
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1682-
struct mv88e6xxx_vtu_stu_entry next;
1683-
int port;
1684-
int err;
1685-
1686-
if (*vid == 4095)
1687-
return -ENOENT;
1688-
1689-
mutex_lock(&ps->smi_mutex);
1690-
err = _mv88e6xxx_vtu_vid_write(ds, *vid);
1691-
if (err)
1692-
goto unlock;
1693-
1694-
err = _mv88e6xxx_vtu_getnext(ds, &next);
1695-
unlock:
1696-
mutex_unlock(&ps->smi_mutex);
1697-
1698-
if (err)
1699-
return err;
1700-
1701-
if (!next.valid)
1702-
return -ENOENT;
1703-
1704-
*vid = next.vid;
1705-
1706-
for (port = 0; port < ps->num_ports; ++port) {
1707-
clear_bit(port, ports);
1708-
clear_bit(port, untagged);
1709-
1710-
if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1711-
continue;
1712-
1713-
if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED ||
1714-
next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1715-
set_bit(port, ports);
1716-
1717-
if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1718-
set_bit(port, untagged);
1719-
}
1720-
1721-
return 0;
1722-
}
1723-
17241716
static int _mv88e6xxx_atu_mac_write(struct dsa_switch *ds,
17251717
const unsigned char *addr)
17261718
{

drivers/net/dsa/mv88e6xxx.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,9 @@ int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
494494
struct switchdev_trans *trans);
495495
int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
496496
const struct switchdev_obj_port_vlan *vlan);
497-
int mv88e6xxx_port_pvid_get(struct dsa_switch *ds, int port, u16 *vid);
498-
int mv88e6xxx_vlan_getnext(struct dsa_switch *ds, u16 *vid,
499-
unsigned long *ports, unsigned long *untagged);
497+
int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
498+
struct switchdev_obj_port_vlan *vlan,
499+
int (*cb)(struct switchdev_obj *obj));
500500
int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
501501
const struct switchdev_obj_port_fdb *fdb,
502502
struct switchdev_trans *trans);

include/net/dsa.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ struct dsa_switch_driver {
313313
struct switchdev_trans *trans);
314314
int (*port_vlan_del)(struct dsa_switch *ds, int port,
315315
const struct switchdev_obj_port_vlan *vlan);
316-
int (*port_pvid_get)(struct dsa_switch *ds, int port, u16 *pvid);
317-
int (*vlan_getnext)(struct dsa_switch *ds, u16 *vid,
318-
unsigned long *ports, unsigned long *untagged);
316+
int (*port_vlan_dump)(struct dsa_switch *ds, int port,
317+
struct switchdev_obj_port_vlan *vlan,
318+
int (*cb)(struct switchdev_obj *obj));
319319

320320
/*
321321
* Forwarding database

net/dsa/slave.c

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -243,41 +243,11 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
243243
{
244244
struct dsa_slave_priv *p = netdev_priv(dev);
245245
struct dsa_switch *ds = p->parent;
246-
DECLARE_BITMAP(members, DSA_MAX_PORTS);
247-
DECLARE_BITMAP(untagged, DSA_MAX_PORTS);
248-
u16 pvid, vid = 0;
249-
int err;
250-
251-
if (!ds->drv->vlan_getnext || !ds->drv->port_pvid_get)
252-
return -EOPNOTSUPP;
253-
254-
err = ds->drv->port_pvid_get(ds, p->port, &pvid);
255-
if (err)
256-
return err;
257-
258-
for (;;) {
259-
err = ds->drv->vlan_getnext(ds, &vid, members, untagged);
260-
if (err)
261-
break;
262-
263-
if (!test_bit(p->port, members))
264-
continue;
265246

266-
memset(vlan, 0, sizeof(*vlan));
267-
vlan->vid_begin = vlan->vid_end = vid;
247+
if (ds->drv->port_vlan_dump)
248+
return ds->drv->port_vlan_dump(ds, p->port, vlan, cb);
268249

269-
if (vid == pvid)
270-
vlan->flags |= BRIDGE_VLAN_INFO_PVID;
271-
272-
if (test_bit(p->port, untagged))
273-
vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
274-
275-
err = cb(&vlan->obj);
276-
if (err)
277-
break;
278-
}
279-
280-
return err == -ENOENT ? 0 : err;
250+
return -EOPNOTSUPP;
281251
}
282252

283253
static int dsa_slave_port_fdb_add(struct net_device *dev,

0 commit comments

Comments
 (0)