Skip to content

Commit c6fa35b

Browse files
pmachatadavem330
authored andcommitted
rocker: 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. rocker currently doesn't support any uppers other than bridge. 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 rocker_world_port_obj_vlan_add(). It is therefore safe to assume that the only interesting case is that the notification is on a front-panel port netdevice. Subscribe to the blocking notifier chain. In the handler, filter out notifications on any foreign netdevices. Dispatch the new notifiers 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 aa4efe2 commit c6fa35b

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

‎drivers/net/ethernet/rocker/rocker_main.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,12 +2812,54 @@ static int rocker_switchdev_event(struct notifier_block *unused,
28122812
return NOTIFY_DONE;
28132813
}
28142814

2815+
static int
2816+
rocker_switchdev_port_obj_event(unsigned long event, struct net_device *netdev,
2817+
struct switchdev_notifier_port_obj_info *port_obj_info)
2818+
{
2819+
int err = -EOPNOTSUPP;
2820+
2821+
switch (event) {
2822+
case SWITCHDEV_PORT_OBJ_ADD:
2823+
err = rocker_port_obj_add(netdev, port_obj_info->obj,
2824+
port_obj_info->trans);
2825+
break;
2826+
case SWITCHDEV_PORT_OBJ_DEL:
2827+
err = rocker_port_obj_del(netdev, port_obj_info->obj);
2828+
break;
2829+
}
2830+
2831+
port_obj_info->handled = true;
2832+
return notifier_from_errno(err);
2833+
}
2834+
2835+
static int rocker_switchdev_blocking_event(struct notifier_block *unused,
2836+
unsigned long event, void *ptr)
2837+
{
2838+
struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
2839+
2840+
if (!rocker_port_dev_check(dev))
2841+
return NOTIFY_DONE;
2842+
2843+
switch (event) {
2844+
case SWITCHDEV_PORT_OBJ_ADD:
2845+
case SWITCHDEV_PORT_OBJ_DEL:
2846+
return rocker_switchdev_port_obj_event(event, dev, ptr);
2847+
}
2848+
2849+
return NOTIFY_DONE;
2850+
}
2851+
28152852
static struct notifier_block rocker_switchdev_notifier = {
28162853
.notifier_call = rocker_switchdev_event,
28172854
};
28182855

2856+
static struct notifier_block rocker_switchdev_blocking_notifier = {
2857+
.notifier_call = rocker_switchdev_blocking_event,
2858+
};
2859+
28192860
static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)
28202861
{
2862+
struct notifier_block *nb;
28212863
struct rocker *rocker;
28222864
int err;
28232865

@@ -2933,13 +2975,22 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)
29332975
goto err_register_switchdev_notifier;
29342976
}
29352977

2978+
nb = &rocker_switchdev_blocking_notifier;
2979+
err = register_switchdev_blocking_notifier(nb);
2980+
if (err) {
2981+
dev_err(&pdev->dev, "Failed to register switchdev blocking notifier\n");
2982+
goto err_register_switchdev_blocking_notifier;
2983+
}
2984+
29362985
rocker->hw.id = rocker_read64(rocker, SWITCH_ID);
29372986

29382987
dev_info(&pdev->dev, "Rocker switch with id %*phN\n",
29392988
(int)sizeof(rocker->hw.id), &rocker->hw.id);
29402989

29412990
return 0;
29422991

2992+
err_register_switchdev_blocking_notifier:
2993+
unregister_switchdev_notifier(&rocker_switchdev_notifier);
29432994
err_register_switchdev_notifier:
29442995
unregister_fib_notifier(&rocker->fib_nb);
29452996
err_register_fib_notifier:
@@ -2971,6 +3022,10 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)
29713022
static void rocker_remove(struct pci_dev *pdev)
29723023
{
29733024
struct rocker *rocker = pci_get_drvdata(pdev);
3025+
struct notifier_block *nb;
3026+
3027+
nb = &rocker_switchdev_blocking_notifier;
3028+
unregister_switchdev_blocking_notifier(nb);
29743029

29753030
unregister_switchdev_notifier(&rocker_switchdev_notifier);
29763031
unregister_fib_notifier(&rocker->fib_nb);

0 commit comments

Comments
 (0)