• Vladimir Oltean's avatar
    net: dsa: report and change port default priority using dcbnl · d538eca8
    Vladimir Oltean authored
    The port-based default QoS class is assigned to packets that lack a
    VLAN PCP (or the port is configured to not trust the VLAN PCP),
    an IP DSCP (or the port is configured to not trust IP DSCP), and packets
    on which no tc-skbedit action has matched.
    
    Similar to other drivers, this can be exposed to user space using the
    DCB Application Priority Table. IEEE 802.1Q-2018 specifies in Table
    D-8 - Sel field values that when the Selector is 1, the Protocol ID
    value of 0 denotes the "Default application priority. For use when
    application priority is not otherwise specified."
    
    The way in which the dcbnl integration in DSA has been designed has to
    do with its requirements. Andrew Lunn explains that SOHO switches are
    expected to come with some sort of pre-configured QoS profile, and that
    it is desirable for this to come pre-loaded into the DSA slave interfaces'
    DCB application priority table.
    
    In the dcbnl design, this is possible because calls to dcb_ieee_setapp()
    can be initiated by anyone including being self-initiated by this device
    driver.
    
    However, what makes this challenging to implement in DSA is that the DSA
    core manages the net_devices (effectively hiding them from drivers),
    while drivers manage the hardware. The DSA core has no knowledge of what
    individual drivers' QoS policies are. DSA could export to drivers a
    wrapper over dcb_ieee_setapp() and these could call that function to
    pre-populate the app priority table, however drivers don't have a good
    moment in time to do this. The dsa_switch_ops :: setup() method gets
    called before the net_devices are created (dsa_slave_create), and so is
    dsa_switch_ops :: port_setup(). What remains is dsa_switch_ops ::
    port_enable(), but this gets called upon each ndo_open. If we add app
    table entries on every open, we'd need to remove them on close, to avoid
    duplicate entry errors. But if we delete app priority entries on close,
    what we delete may not be the initial, driver pre-populated entries, but
    rather user-added entries.
    
    So it is clear that letting drivers choose the timing of the
    dcb_ieee_setapp() call is inappropriate. The alternative which was
    chosen is to introduce hardware-specific ops in dsa_switch_ops, and
    effectively hide dcbnl details from drivers as well. For pre-populating
    the application table, dsa_slave_dcbnl_init() will call
    ds->ops->port_get_default_prio() which is supposed to read from
    hardware. If the operation succeeds, DSA creates a default-prio app
    table entry. The method is called as soon as the slave_dev is
    registered, but before we release the rtnl_mutex. This is done such that
    user space sees the app table entries as soon as it sees the interface
    being registered.
    
    The fact that we populate slave_dev->dcbnl_ops with a non-NULL pointer
    changes behavior in dcb_doit() from net/dcb/dcbnl.c, which used to
    return -EOPNOTSUPP for any dcbnl operation where netdev->dcbnl_ops is
    NULL. Because there are still dcbnl-unaware DSA drivers even if they
    have dcbnl_ops populated, the way to restore the behavior is to make all
    dcbnl_ops return -EOPNOTSUPP on absence of the hardware-specific
    dsa_switch_ops method.
    
    The dcbnl framework absurdly allows there to be more than one app table
    entry for the same selector and protocol (in other words, more than one
    port-based default priority). In the iproute2 dcb program, there is a
    "replace" syntactical sugar command which performs an "add" and a "del"
    to hide this away. But we choose the largest configured priority when we
    call ds->ops->port_set_default_prio(), using __fls(). When there is no
    default-prio app table entry left, the port-default priority is restored
    to 0.
    
    Link: https://patchwork.kernel.org/project/netdevbpf/patch/20210113154139.1803705-2-olteanv@gmail.com/Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    d538eca8
slave.c 72.9 KB