Skip to content

Commit 2b239f6

Browse files
pmachatadavem330
authored andcommitted
net: dsa: slave: Handle SWITCHDEV_PORT_OBJ_ADD/_DEL
Following patches will change the way of distributing port object changes from a switchdev operation to a switchdev notifier. The switchdev code currently recursively descends through layers of lower devices, eventually calling the op on a front-panel port device. The notifier will instead be sent referencing the bridge port device, which may be a stacking device that's one of front-panel ports uppers, or a completely unrelated device. DSA currently doesn't support any other uppers than bridge. SWITCHDEV_OBJ_ID_HOST_MDB and _PORT_MDB objects are always notified on the bridge port device. Thus the only case that a stacked device could be validly referenced by port object notifications are bridge notifications for VLAN objects added to the bridge itself. But the driver explicitly rejects such notifications in dsa_port_vlan_add(). It is therefore safe to assume that the only interesting case is that the notification is on a front-panel port netdevice. Therefore keep the filtering by dsa_slave_dev_check() in place. To handle SWITCHDEV_PORT_OBJ_ADD and _DEL, subscribe to the blocking notifier chain. Dispatch to rocker_port_obj_add() resp. _del() to maintain the behavior that the switchdev operation based code currently has. Signed-off-by: Petr Machata <petrm@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c6fa35b commit 2b239f6

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎net/dsa/slave.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,44 @@ static int dsa_slave_switchdev_event(struct notifier_block *unused,
15571557
return NOTIFY_BAD;
15581558
}
15591559

1560+
static int
1561+
dsa_slave_switchdev_port_obj_event(unsigned long event,
1562+
struct net_device *netdev,
1563+
struct switchdev_notifier_port_obj_info *port_obj_info)
1564+
{
1565+
int err = -EOPNOTSUPP;
1566+
1567+
switch (event) {
1568+
case SWITCHDEV_PORT_OBJ_ADD:
1569+
err = dsa_slave_port_obj_add(netdev, port_obj_info->obj,
1570+
port_obj_info->trans);
1571+
break;
1572+
case SWITCHDEV_PORT_OBJ_DEL:
1573+
err = dsa_slave_port_obj_del(netdev, port_obj_info->obj);
1574+
break;
1575+
}
1576+
1577+
port_obj_info->handled = true;
1578+
return notifier_from_errno(err);
1579+
}
1580+
1581+
static int dsa_slave_switchdev_blocking_event(struct notifier_block *unused,
1582+
unsigned long event, void *ptr)
1583+
{
1584+
struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1585+
1586+
if (!dsa_slave_dev_check(dev))
1587+
return NOTIFY_DONE;
1588+
1589+
switch (event) {
1590+
case SWITCHDEV_PORT_OBJ_ADD: /* fall through */
1591+
case SWITCHDEV_PORT_OBJ_DEL:
1592+
return dsa_slave_switchdev_port_obj_event(event, dev, ptr);
1593+
}
1594+
1595+
return NOTIFY_DONE;
1596+
}
1597+
15601598
static struct notifier_block dsa_slave_nb __read_mostly = {
15611599
.notifier_call = dsa_slave_netdevice_event,
15621600
};
@@ -1565,8 +1603,13 @@ static struct notifier_block dsa_slave_switchdev_notifier = {
15651603
.notifier_call = dsa_slave_switchdev_event,
15661604
};
15671605

1606+
static struct notifier_block dsa_slave_switchdev_blocking_notifier = {
1607+
.notifier_call = dsa_slave_switchdev_blocking_event,
1608+
};
1609+
15681610
int dsa_slave_register_notifier(void)
15691611
{
1612+
struct notifier_block *nb;
15701613
int err;
15711614

15721615
err = register_netdevice_notifier(&dsa_slave_nb);
@@ -1577,17 +1620,30 @@ int dsa_slave_register_notifier(void)
15771620
if (err)
15781621
goto err_switchdev_nb;
15791622

1623+
nb = &dsa_slave_switchdev_blocking_notifier;
1624+
err = register_switchdev_blocking_notifier(nb);
1625+
if (err)
1626+
goto err_switchdev_blocking_nb;
1627+
15801628
return 0;
15811629

1630+
err_switchdev_blocking_nb:
1631+
unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
15821632
err_switchdev_nb:
15831633
unregister_netdevice_notifier(&dsa_slave_nb);
15841634
return err;
15851635
}
15861636

15871637
void dsa_slave_unregister_notifier(void)
15881638
{
1639+
struct notifier_block *nb;
15891640
int err;
15901641

1642+
nb = &dsa_slave_switchdev_blocking_notifier;
1643+
err = unregister_switchdev_blocking_notifier(nb);
1644+
if (err)
1645+
pr_err("DSA: failed to unregister switchdev blocking notifier (%d)\n", err);
1646+
15911647
err = unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
15921648
if (err)
15931649
pr_err("DSA: failed to unregister switchdev notifier (%d)\n", err);

0 commit comments

Comments
 (0)