xref: /openbmc/linux/include/net/mrp.h (revision 2c64e9cb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NET_MRP_H
3 #define _NET_MRP_H
4 
5 #define MRP_END_MARK		0x0
6 
7 struct mrp_pdu_hdr {
8 	u8	version;
9 };
10 
11 struct mrp_msg_hdr {
12 	u8	attrtype;
13 	u8	attrlen;
14 };
15 
16 struct mrp_vecattr_hdr {
17 	__be16	lenflags;
18 	unsigned char	firstattrvalue[];
19 #define MRP_VECATTR_HDR_LEN_MASK cpu_to_be16(0x1FFF)
20 #define MRP_VECATTR_HDR_FLAG_LA cpu_to_be16(0x2000)
21 };
22 
23 enum mrp_vecattr_event {
24 	MRP_VECATTR_EVENT_NEW,
25 	MRP_VECATTR_EVENT_JOIN_IN,
26 	MRP_VECATTR_EVENT_IN,
27 	MRP_VECATTR_EVENT_JOIN_MT,
28 	MRP_VECATTR_EVENT_MT,
29 	MRP_VECATTR_EVENT_LV,
30 	__MRP_VECATTR_EVENT_MAX
31 };
32 
33 struct mrp_skb_cb {
34 	struct mrp_msg_hdr	*mh;
35 	struct mrp_vecattr_hdr	*vah;
36 	unsigned char		attrvalue[];
37 };
38 
39 static inline struct mrp_skb_cb *mrp_cb(struct sk_buff *skb)
40 {
41 	BUILD_BUG_ON(sizeof(struct mrp_skb_cb) >
42 		     FIELD_SIZEOF(struct sk_buff, cb));
43 	return (struct mrp_skb_cb *)skb->cb;
44 }
45 
46 enum mrp_applicant_state {
47 	MRP_APPLICANT_INVALID,
48 	MRP_APPLICANT_VO,
49 	MRP_APPLICANT_VP,
50 	MRP_APPLICANT_VN,
51 	MRP_APPLICANT_AN,
52 	MRP_APPLICANT_AA,
53 	MRP_APPLICANT_QA,
54 	MRP_APPLICANT_LA,
55 	MRP_APPLICANT_AO,
56 	MRP_APPLICANT_QO,
57 	MRP_APPLICANT_AP,
58 	MRP_APPLICANT_QP,
59 	__MRP_APPLICANT_MAX
60 };
61 #define MRP_APPLICANT_MAX	(__MRP_APPLICANT_MAX - 1)
62 
63 enum mrp_event {
64 	MRP_EVENT_NEW,
65 	MRP_EVENT_JOIN,
66 	MRP_EVENT_LV,
67 	MRP_EVENT_TX,
68 	MRP_EVENT_R_NEW,
69 	MRP_EVENT_R_JOIN_IN,
70 	MRP_EVENT_R_IN,
71 	MRP_EVENT_R_JOIN_MT,
72 	MRP_EVENT_R_MT,
73 	MRP_EVENT_R_LV,
74 	MRP_EVENT_R_LA,
75 	MRP_EVENT_REDECLARE,
76 	MRP_EVENT_PERIODIC,
77 	__MRP_EVENT_MAX
78 };
79 #define MRP_EVENT_MAX		(__MRP_EVENT_MAX - 1)
80 
81 enum mrp_tx_action {
82 	MRP_TX_ACTION_NONE,
83 	MRP_TX_ACTION_S_NEW,
84 	MRP_TX_ACTION_S_JOIN_IN,
85 	MRP_TX_ACTION_S_JOIN_IN_OPTIONAL,
86 	MRP_TX_ACTION_S_IN_OPTIONAL,
87 	MRP_TX_ACTION_S_LV,
88 };
89 
90 struct mrp_attr {
91 	struct rb_node			node;
92 	enum mrp_applicant_state	state;
93 	u8				type;
94 	u8				len;
95 	unsigned char			value[];
96 };
97 
98 enum mrp_applications {
99 	MRP_APPLICATION_MVRP,
100 	__MRP_APPLICATION_MAX
101 };
102 #define MRP_APPLICATION_MAX	(__MRP_APPLICATION_MAX - 1)
103 
104 struct mrp_application {
105 	enum mrp_applications	type;
106 	unsigned int		maxattr;
107 	struct packet_type	pkttype;
108 	unsigned char		group_address[ETH_ALEN];
109 	u8			version;
110 };
111 
112 struct mrp_applicant {
113 	struct mrp_application	*app;
114 	struct net_device	*dev;
115 	struct timer_list	join_timer;
116 	struct timer_list	periodic_timer;
117 
118 	spinlock_t		lock;
119 	struct sk_buff_head	queue;
120 	struct sk_buff		*pdu;
121 	struct rb_root		mad;
122 	struct rcu_head		rcu;
123 };
124 
125 struct mrp_port {
126 	struct mrp_applicant __rcu	*applicants[MRP_APPLICATION_MAX + 1];
127 	struct rcu_head			rcu;
128 };
129 
130 int mrp_register_application(struct mrp_application *app);
131 void mrp_unregister_application(struct mrp_application *app);
132 
133 int mrp_init_applicant(struct net_device *dev, struct mrp_application *app);
134 void mrp_uninit_applicant(struct net_device *dev, struct mrp_application *app);
135 
136 int mrp_request_join(const struct net_device *dev,
137 		     const struct mrp_application *app,
138 		     const void *value, u8 len, u8 type);
139 void mrp_request_leave(const struct net_device *dev,
140 		       const struct mrp_application *app,
141 		       const void *value, u8 len, u8 type);
142 
143 #endif /* _NET_MRP_H */
144