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