1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #ifndef _BR_PRIVATE_MRP_H_
4 #define _BR_PRIVATE_MRP_H_
5 
6 #include "br_private.h"
7 #include <uapi/linux/mrp_bridge.h>
8 
9 struct br_mrp {
10 	/* list of mrp instances */
11 	struct hlist_node		list;
12 
13 	struct net_bridge_port __rcu	*p_port;
14 	struct net_bridge_port __rcu	*s_port;
15 	struct net_bridge_port __rcu	*i_port;
16 
17 	u32				ring_id;
18 	u16				in_id;
19 	u16				prio;
20 
21 	enum br_mrp_ring_role_type	ring_role;
22 	u8				ring_role_offloaded;
23 	enum br_mrp_ring_state_type	ring_state;
24 	u32				ring_transitions;
25 
26 	enum br_mrp_in_role_type	in_role;
27 	u8				in_role_offloaded;
28 	enum br_mrp_in_state_type	in_state;
29 	u32				in_transitions;
30 
31 	struct delayed_work		test_work;
32 	u32				test_interval;
33 	unsigned long			test_end;
34 	u32				test_count_miss;
35 	u32				test_max_miss;
36 	bool				test_monitor;
37 
38 	struct delayed_work		in_test_work;
39 	u32				in_test_interval;
40 	unsigned long			in_test_end;
41 	u32				in_test_count_miss;
42 	u32				in_test_max_miss;
43 
44 	u32				seq_id;
45 
46 	struct rcu_head			rcu;
47 };
48 
49 /* This type is returned by br_mrp_switchdev functions that allow to have a SW
50  * backup in case the HW can't implement completely the protocol.
51  * BR_MRP_NONE - means the HW can't run at all the protocol, so the SW stops
52  *               configuring the node anymore.
53  * BR_MRP_SW - the HW can help the SW to run the protocol, by redirecting MRP
54  *             frames to CPU.
55  * BR_MRP_HW - the HW can implement completely the protocol.
56  */
57 enum br_mrp_hw_support {
58 	BR_MRP_NONE,
59 	BR_MRP_SW,
60 	BR_MRP_HW,
61 };
62 
63 /* br_mrp.c */
64 int br_mrp_add(struct net_bridge *br, struct br_mrp_instance *instance);
65 int br_mrp_del(struct net_bridge *br, struct br_mrp_instance *instance);
66 int br_mrp_set_port_state(struct net_bridge_port *p,
67 			  enum br_mrp_port_state_type state);
68 int br_mrp_set_port_role(struct net_bridge_port *p,
69 			 enum br_mrp_port_role_type role);
70 int br_mrp_set_ring_state(struct net_bridge *br,
71 			  struct br_mrp_ring_state *state);
72 int br_mrp_set_ring_role(struct net_bridge *br, struct br_mrp_ring_role *role);
73 int br_mrp_start_test(struct net_bridge *br, struct br_mrp_start_test *test);
74 int br_mrp_set_in_state(struct net_bridge *br, struct br_mrp_in_state *state);
75 int br_mrp_set_in_role(struct net_bridge *br, struct br_mrp_in_role *role);
76 int br_mrp_start_in_test(struct net_bridge *br,
77 			 struct br_mrp_start_in_test *test);
78 
79 /* br_mrp_switchdev.c */
80 int br_mrp_switchdev_add(struct net_bridge *br, struct br_mrp *mrp);
81 int br_mrp_switchdev_del(struct net_bridge *br, struct br_mrp *mrp);
82 enum br_mrp_hw_support
83 br_mrp_switchdev_set_ring_role(struct net_bridge *br, struct br_mrp *mrp,
84 			       enum br_mrp_ring_role_type role);
85 int br_mrp_switchdev_set_ring_state(struct net_bridge *br, struct br_mrp *mrp,
86 				    enum br_mrp_ring_state_type state);
87 enum br_mrp_hw_support
88 br_mrp_switchdev_send_ring_test(struct net_bridge *br, struct br_mrp *mrp,
89 				u32 interval, u8 max_miss, u32 period,
90 				bool monitor);
91 int br_mrp_port_switchdev_set_state(struct net_bridge_port *p, u32 state);
92 int br_mrp_port_switchdev_set_role(struct net_bridge_port *p,
93 				   enum br_mrp_port_role_type role);
94 enum br_mrp_hw_support
95 br_mrp_switchdev_set_in_role(struct net_bridge *br, struct br_mrp *mrp,
96 			     u16 in_id, u32 ring_id,
97 			     enum br_mrp_in_role_type role);
98 int br_mrp_switchdev_set_in_state(struct net_bridge *br, struct br_mrp *mrp,
99 				  enum br_mrp_in_state_type state);
100 enum br_mrp_hw_support
101 br_mrp_switchdev_send_in_test(struct net_bridge *br, struct br_mrp *mrp,
102 			      u32 interval, u8 max_miss, u32 period);
103 
104 /* br_mrp_netlink.c  */
105 int br_mrp_ring_port_open(struct net_device *dev, u8 loc);
106 int br_mrp_in_port_open(struct net_device *dev, u8 loc);
107 
108 /* MRP protocol data units */
109 struct br_mrp_tlv_hdr {
110 	__u8 type;
111 	__u8 length;
112 };
113 
114 struct br_mrp_common_hdr {
115 	__be16 seq_id;
116 	__u8 domain[MRP_DOMAIN_UUID_LENGTH];
117 };
118 
119 struct br_mrp_ring_test_hdr {
120 	__be16 prio;
121 	__u8 sa[ETH_ALEN];
122 	__be16 port_role;
123 	__be16 state;
124 	__be16 transitions;
125 	__be32 timestamp;
126 } __attribute__((__packed__));
127 
128 struct br_mrp_in_test_hdr {
129 	__be16 id;
130 	__u8 sa[ETH_ALEN];
131 	__be16 port_role;
132 	__be16 state;
133 	__be16 transitions;
134 	__be32 timestamp;
135 } __attribute__((__packed__));
136 
137 #endif /* _BR_PRIVATE_MRP_H */
138