Skip to content

Commit a39b888

Browse files
pmachatadavem330
authored andcommitted
staging: fsl-dpaa2: ethsw: 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. ethsw currently doesn't support any uppers other 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 port_vlans_add(). It is therefore safe to assume that the only interesting case is that the notification is on a front-panel port netdevice. To handle SWITCHDEV_PORT_OBJ_ADD and _DEL, subscribe to the blocking notifier chain. Dispatch to swdev_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 bb89680 commit a39b888

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

  • drivers/staging/fsl-dpaa2/ethsw

‎drivers/staging/fsl-dpaa2/ethsw/ethsw.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,51 @@ static int port_switchdev_event(struct notifier_block *unused,
10881088
return NOTIFY_BAD;
10891089
}
10901090

1091+
static int
1092+
ethsw_switchdev_port_obj_event(unsigned long event, struct net_device *netdev,
1093+
struct switchdev_notifier_port_obj_info *port_obj_info)
1094+
{
1095+
int err = -EOPNOTSUPP;
1096+
1097+
switch (event) {
1098+
case SWITCHDEV_PORT_OBJ_ADD:
1099+
err = swdev_port_obj_add(netdev, port_obj_info->obj,
1100+
port_obj_info->trans);
1101+
break;
1102+
case SWITCHDEV_PORT_OBJ_DEL:
1103+
err = swdev_port_obj_del(netdev, port_obj_info->obj);
1104+
break;
1105+
}
1106+
1107+
port_obj_info->handled = true;
1108+
return notifier_from_errno(err);
1109+
}
1110+
1111+
static int port_switchdev_blocking_event(struct notifier_block *unused,
1112+
unsigned long event, void *ptr)
1113+
{
1114+
struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1115+
1116+
if (!ethsw_port_dev_check(dev))
1117+
return NOTIFY_DONE;
1118+
1119+
switch (event) {
1120+
case SWITCHDEV_PORT_OBJ_ADD: /* fall through */
1121+
case SWITCHDEV_PORT_OBJ_DEL:
1122+
return ethsw_switchdev_port_obj_event(event, dev, ptr);
1123+
}
1124+
1125+
return NOTIFY_DONE;
1126+
}
1127+
10911128
static struct notifier_block port_switchdev_nb = {
10921129
.notifier_call = port_switchdev_event,
10931130
};
10941131

1132+
static struct notifier_block port_switchdev_blocking_nb = {
1133+
.notifier_call = port_switchdev_blocking_event,
1134+
};
1135+
10951136
static int ethsw_register_notifier(struct device *dev)
10961137
{
10971138
int err;
@@ -1108,8 +1149,16 @@ static int ethsw_register_notifier(struct device *dev)
11081149
goto err_switchdev_nb;
11091150
}
11101151

1152+
err = register_switchdev_blocking_notifier(&port_switchdev_blocking_nb);
1153+
if (err) {
1154+
dev_err(dev, "Failed to register switchdev blocking notifier\n");
1155+
goto err_switchdev_blocking_nb;
1156+
}
1157+
11111158
return 0;
11121159

1160+
err_switchdev_blocking_nb:
1161+
unregister_switchdev_notifier(&port_switchdev_nb);
11131162
err_switchdev_nb:
11141163
unregister_netdevice_notifier(&port_nb);
11151164
return err;
@@ -1296,8 +1345,15 @@ static int ethsw_port_init(struct ethsw_port_priv *port_priv, u16 port)
12961345

12971346
static void ethsw_unregister_notifier(struct device *dev)
12981347
{
1348+
struct notifier_block *nb;
12991349
int err;
13001350

1351+
nb = &port_switchdev_blocking_nb;
1352+
err = unregister_switchdev_blocking_notifier(nb);
1353+
if (err)
1354+
dev_err(dev,
1355+
"Failed to unregister switchdev blocking notifier (%d)\n", err);
1356+
13011357
err = unregister_switchdev_notifier(&port_switchdev_nb);
13021358
if (err)
13031359
dev_err(dev,

0 commit comments

Comments
 (0)