bridge: mrp: Set the priority of MRP instance
authorHoratiu Vultur <horatiu.vultur@microchip.com>
Sat, 30 May 2020 18:09:47 +0000 (18:09 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 1 Jun 2020 18:56:11 +0000 (11:56 -0700)
Each MRP instance has a priority, a lower value means a higher priority.
The priority of MRP instance is stored in MRP_Test frame in this way
all the MRP nodes in the ring can see other nodes priority.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/switchdev.h
include/uapi/linux/if_bridge.h
net/bridge/br_mrp.c
net/bridge/br_mrp_netlink.c
net/bridge/br_mrp_switchdev.c
net/bridge/br_private_mrp.h

index db51995..f82ef4c 100644 (file)
@@ -116,6 +116,7 @@ struct switchdev_obj_mrp {
        struct net_device *p_port;
        struct net_device *s_port;
        u32 ring_id;
+       u16 prio;
 };
 
 #define SWITCHDEV_OBJ_MRP(OBJ) \
index 5a43eb8..0162c13 100644 (file)
@@ -176,6 +176,7 @@ enum {
        IFLA_BRIDGE_MRP_INSTANCE_RING_ID,
        IFLA_BRIDGE_MRP_INSTANCE_P_IFINDEX,
        IFLA_BRIDGE_MRP_INSTANCE_S_IFINDEX,
+       IFLA_BRIDGE_MRP_INSTANCE_PRIO,
        __IFLA_BRIDGE_MRP_INSTANCE_MAX,
 };
 
@@ -230,6 +231,7 @@ struct br_mrp_instance {
        __u32 ring_id;
        __u32 p_ifindex;
        __u32 s_ifindex;
+       __u16 prio;
 };
 
 struct br_mrp_ring_state {
index 8ea5950..f8fd037 100644 (file)
@@ -147,7 +147,7 @@ static struct sk_buff *br_mrp_alloc_test_skb(struct br_mrp *mrp,
        br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_RING_TEST, sizeof(*hdr));
        hdr = skb_put(skb, sizeof(*hdr));
 
-       hdr->prio = cpu_to_be16(MRP_DEFAULT_PRIO);
+       hdr->prio = cpu_to_be16(mrp->prio);
        ether_addr_copy(hdr->sa, p->br->dev->dev_addr);
        hdr->port_role = cpu_to_be16(port_role);
        hdr->state = cpu_to_be16(mrp->ring_state);
@@ -290,6 +290,7 @@ int br_mrp_add(struct net_bridge *br, struct br_mrp_instance *instance)
                return -ENOMEM;
 
        mrp->ring_id = instance->ring_id;
+       mrp->prio = instance->prio;
 
        p = br_mrp_get_port(br, instance->p_ifindex);
        spin_lock_bh(&br->lock);
index d9de780..8cb67d9 100644 (file)
@@ -22,6 +22,7 @@ br_mrp_instance_policy[IFLA_BRIDGE_MRP_INSTANCE_MAX + 1] = {
        [IFLA_BRIDGE_MRP_INSTANCE_RING_ID]      = { .type = NLA_U32 },
        [IFLA_BRIDGE_MRP_INSTANCE_P_IFINDEX]    = { .type = NLA_U32 },
        [IFLA_BRIDGE_MRP_INSTANCE_S_IFINDEX]    = { .type = NLA_U32 },
+       [IFLA_BRIDGE_MRP_INSTANCE_PRIO]         = { .type = NLA_U16 },
 };
 
 static int br_mrp_instance_parse(struct net_bridge *br, struct nlattr *attr,
@@ -49,6 +50,10 @@ static int br_mrp_instance_parse(struct net_bridge *br, struct nlattr *attr,
        inst.ring_id = nla_get_u32(tb[IFLA_BRIDGE_MRP_INSTANCE_RING_ID]);
        inst.p_ifindex = nla_get_u32(tb[IFLA_BRIDGE_MRP_INSTANCE_P_IFINDEX]);
        inst.s_ifindex = nla_get_u32(tb[IFLA_BRIDGE_MRP_INSTANCE_S_IFINDEX]);
+       inst.prio = MRP_DEFAULT_PRIO;
+
+       if (tb[IFLA_BRIDGE_MRP_INSTANCE_PRIO])
+               inst.prio = nla_get_u16(tb[IFLA_BRIDGE_MRP_INSTANCE_PRIO]);
 
        if (cmd == RTM_SETLINK)
                return br_mrp_add(br, &inst);
index 51cb1d5..3a77604 100644 (file)
@@ -12,6 +12,7 @@ int br_mrp_switchdev_add(struct net_bridge *br, struct br_mrp *mrp)
                .p_port = rtnl_dereference(mrp->p_port)->dev,
                .s_port = rtnl_dereference(mrp->s_port)->dev,
                .ring_id = mrp->ring_id,
+               .prio = mrp->prio,
        };
        int err;
 
index a0f53cc..558941c 100644 (file)
@@ -14,6 +14,7 @@ struct br_mrp {
        struct net_bridge_port __rcu    *s_port;
 
        u32                             ring_id;
+       u16                             prio;
 
        enum br_mrp_ring_role_type      ring_role;
        u8                              ring_role_offloaded;