1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <net/switchdev.h>
5 #include "br_private_mrp.h"
7 int br_mrp_switchdev_add(struct net_bridge
*br
, struct br_mrp
*mrp
)
9 struct switchdev_obj_mrp mrp_obj
= {
10 .obj
.orig_dev
= br
->dev
,
11 .obj
.id
= SWITCHDEV_OBJ_ID_MRP
,
12 .p_port
= rtnl_dereference(mrp
->p_port
)->dev
,
13 .s_port
= rtnl_dereference(mrp
->s_port
)->dev
,
14 .ring_id
= mrp
->ring_id
,
18 err
= switchdev_port_obj_add(br
->dev
, &mrp_obj
.obj
, NULL
);
20 if (err
&& err
!= -EOPNOTSUPP
)
26 int br_mrp_switchdev_del(struct net_bridge
*br
, struct br_mrp
*mrp
)
28 struct switchdev_obj_mrp mrp_obj
= {
29 .obj
.orig_dev
= br
->dev
,
30 .obj
.id
= SWITCHDEV_OBJ_ID_MRP
,
33 .ring_id
= mrp
->ring_id
,
37 err
= switchdev_port_obj_del(br
->dev
, &mrp_obj
.obj
);
39 if (err
&& err
!= -EOPNOTSUPP
)
45 int br_mrp_switchdev_set_ring_role(struct net_bridge
*br
,
47 enum br_mrp_ring_role_type role
)
49 struct switchdev_obj_ring_role_mrp mrp_role
= {
50 .obj
.orig_dev
= br
->dev
,
51 .obj
.id
= SWITCHDEV_OBJ_ID_RING_ROLE_MRP
,
53 .ring_id
= mrp
->ring_id
,
57 if (role
== BR_MRP_RING_ROLE_DISABLED
)
58 err
= switchdev_port_obj_del(br
->dev
, &mrp_role
.obj
);
60 err
= switchdev_port_obj_add(br
->dev
, &mrp_role
.obj
, NULL
);
65 int br_mrp_switchdev_send_ring_test(struct net_bridge
*br
,
66 struct br_mrp
*mrp
, u32 interval
,
67 u8 max_miss
, u32 period
)
69 struct switchdev_obj_ring_test_mrp test
= {
70 .obj
.orig_dev
= br
->dev
,
71 .obj
.id
= SWITCHDEV_OBJ_ID_RING_TEST_MRP
,
74 .ring_id
= mrp
->ring_id
,
80 err
= switchdev_port_obj_del(br
->dev
, &test
.obj
);
82 err
= switchdev_port_obj_add(br
->dev
, &test
.obj
, NULL
);
87 int br_mrp_switchdev_set_ring_state(struct net_bridge
*br
,
89 enum br_mrp_ring_state_type state
)
91 struct switchdev_obj_ring_state_mrp mrp_state
= {
92 .obj
.orig_dev
= br
->dev
,
93 .obj
.id
= SWITCHDEV_OBJ_ID_RING_STATE_MRP
,
95 .ring_id
= mrp
->ring_id
,
99 err
= switchdev_port_obj_add(br
->dev
, &mrp_state
.obj
, NULL
);
101 if (err
&& err
!= -EOPNOTSUPP
)
107 int br_mrp_port_switchdev_set_state(struct net_bridge_port
*p
,
108 enum br_mrp_port_state_type state
)
110 struct switchdev_attr attr
= {
112 .id
= SWITCHDEV_ATTR_ID_MRP_PORT_STATE
,
113 .u
.mrp_port_state
= state
,
117 err
= switchdev_port_attr_set(p
->dev
, &attr
);
118 if (err
&& err
!= -EOPNOTSUPP
)
119 br_warn(p
->br
, "error setting offload MRP state on port %u(%s)\n",
120 (unsigned int)p
->port_no
, p
->dev
->name
);
125 int br_mrp_port_switchdev_set_role(struct net_bridge_port
*p
,
126 enum br_mrp_port_role_type role
)
128 struct switchdev_attr attr
= {
130 .id
= SWITCHDEV_ATTR_ID_MRP_PORT_ROLE
,
131 .u
.mrp_port_role
= role
,
135 err
= switchdev_port_attr_set(p
->dev
, &attr
);
136 if (err
&& err
!= -EOPNOTSUPP
)