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