understanding switchdev notifications

From: Chris Packham
Date: Wed Aug 07 2024 - 20:55:32 EST


Hi,

I'm trying to get to grips with how the switchdev notifications are supposed to be used when developing a switchdev driver.

I have been reading through https://www.kernel.org/doc/html/latest/networking/switchdev.html which covers a few things but doesn't go into detail around the notifiers that one needs to implement for a new switchdev driver (which is probably very dependent on what the hardware is capable of).

Specifically right now I'm looking at having a switch port join a vlan aware bridge. I have a configuration something like this

    ip link add br0 type bridge vlan_filtering 1
    ip link set sw1p5 master br0
    ip link set sw1p1 master br0
    bridge vlan add vid 2 dev br0 self
    ip link add link br0 br0.2 type vlan id 2
    ip addr add dev br0.2 192.168.2.1/24
    bridge vlan add vid 2 dev lan5 pvid untagged
    bridge vlan add vid 2 dev lan1
    ip link set sw1p5 up
    ip link set sw1p1 up
    ip link set br0 up
    ip link set br0.2 up

Then I'm testing by sending a ping to a nonexistent host on the 192.168.2.0/24 subnet and looking at the traffic with tcpdump on another device connected to sw1p5.

I'm a bit confused about how I should be calling switchdev_bridge_port_offload(). It takes two netdevs (brport_dev and dev) but as far as I've been able to see all the callers end up passing the same netdev for both of these (some create a driver specific brport but this still ends up with brport->dev and dev being the same object).

I've figured out that I need to set tx_fwd_offload=true so that the bridge software only sends one packet to the hardware. That makes sense as a way of saying the my hardware can take care of sending the packet out the right ports.

I do have a problem that what I get from the bridge has a vlan tag inserted (which makes sense in sw when the packet goes from br0.2 to br0). But I don't actually need it as the hardware will insert a tag for me if the port is setup for egress tagging. I can shuffle the Ethernet header up but I was wondering if there was a way of telling the bridge not to insert the tag?

Finally I'm confused about the atomic_nb/atomic_nb parameters. Some drivers just pass NULL and others pass the same notifier blocks that they've already registered with register_switchdev_notifier()/register_switchdev_notifier(). If notifiers are registered why does switchdev_bridge_port_offload() take them as parameters?

Thanks,
Chris