18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _NET_MRP_H 38c2ecf20Sopenharmony_ci#define _NET_MRP_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#define MRP_END_MARK 0x0 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_cistruct mrp_pdu_hdr { 88c2ecf20Sopenharmony_ci u8 version; 98c2ecf20Sopenharmony_ci}; 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_cistruct mrp_msg_hdr { 128c2ecf20Sopenharmony_ci u8 attrtype; 138c2ecf20Sopenharmony_ci u8 attrlen; 148c2ecf20Sopenharmony_ci}; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistruct mrp_vecattr_hdr { 178c2ecf20Sopenharmony_ci __be16 lenflags; 188c2ecf20Sopenharmony_ci unsigned char firstattrvalue[]; 198c2ecf20Sopenharmony_ci#define MRP_VECATTR_HDR_LEN_MASK cpu_to_be16(0x1FFF) 208c2ecf20Sopenharmony_ci#define MRP_VECATTR_HDR_FLAG_LA cpu_to_be16(0x2000) 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cienum mrp_vecattr_event { 248c2ecf20Sopenharmony_ci MRP_VECATTR_EVENT_NEW, 258c2ecf20Sopenharmony_ci MRP_VECATTR_EVENT_JOIN_IN, 268c2ecf20Sopenharmony_ci MRP_VECATTR_EVENT_IN, 278c2ecf20Sopenharmony_ci MRP_VECATTR_EVENT_JOIN_MT, 288c2ecf20Sopenharmony_ci MRP_VECATTR_EVENT_MT, 298c2ecf20Sopenharmony_ci MRP_VECATTR_EVENT_LV, 308c2ecf20Sopenharmony_ci __MRP_VECATTR_EVENT_MAX 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistruct mrp_skb_cb { 348c2ecf20Sopenharmony_ci struct mrp_msg_hdr *mh; 358c2ecf20Sopenharmony_ci struct mrp_vecattr_hdr *vah; 368c2ecf20Sopenharmony_ci unsigned char attrvalue[]; 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic inline struct mrp_skb_cb *mrp_cb(struct sk_buff *skb) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci BUILD_BUG_ON(sizeof(struct mrp_skb_cb) > 428c2ecf20Sopenharmony_ci sizeof_field(struct sk_buff, cb)); 438c2ecf20Sopenharmony_ci return (struct mrp_skb_cb *)skb->cb; 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cienum mrp_applicant_state { 478c2ecf20Sopenharmony_ci MRP_APPLICANT_INVALID, 488c2ecf20Sopenharmony_ci MRP_APPLICANT_VO, 498c2ecf20Sopenharmony_ci MRP_APPLICANT_VP, 508c2ecf20Sopenharmony_ci MRP_APPLICANT_VN, 518c2ecf20Sopenharmony_ci MRP_APPLICANT_AN, 528c2ecf20Sopenharmony_ci MRP_APPLICANT_AA, 538c2ecf20Sopenharmony_ci MRP_APPLICANT_QA, 548c2ecf20Sopenharmony_ci MRP_APPLICANT_LA, 558c2ecf20Sopenharmony_ci MRP_APPLICANT_AO, 568c2ecf20Sopenharmony_ci MRP_APPLICANT_QO, 578c2ecf20Sopenharmony_ci MRP_APPLICANT_AP, 588c2ecf20Sopenharmony_ci MRP_APPLICANT_QP, 598c2ecf20Sopenharmony_ci __MRP_APPLICANT_MAX 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci#define MRP_APPLICANT_MAX (__MRP_APPLICANT_MAX - 1) 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cienum mrp_event { 648c2ecf20Sopenharmony_ci MRP_EVENT_NEW, 658c2ecf20Sopenharmony_ci MRP_EVENT_JOIN, 668c2ecf20Sopenharmony_ci MRP_EVENT_LV, 678c2ecf20Sopenharmony_ci MRP_EVENT_TX, 688c2ecf20Sopenharmony_ci MRP_EVENT_R_NEW, 698c2ecf20Sopenharmony_ci MRP_EVENT_R_JOIN_IN, 708c2ecf20Sopenharmony_ci MRP_EVENT_R_IN, 718c2ecf20Sopenharmony_ci MRP_EVENT_R_JOIN_MT, 728c2ecf20Sopenharmony_ci MRP_EVENT_R_MT, 738c2ecf20Sopenharmony_ci MRP_EVENT_R_LV, 748c2ecf20Sopenharmony_ci MRP_EVENT_R_LA, 758c2ecf20Sopenharmony_ci MRP_EVENT_REDECLARE, 768c2ecf20Sopenharmony_ci MRP_EVENT_PERIODIC, 778c2ecf20Sopenharmony_ci __MRP_EVENT_MAX 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci#define MRP_EVENT_MAX (__MRP_EVENT_MAX - 1) 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cienum mrp_tx_action { 828c2ecf20Sopenharmony_ci MRP_TX_ACTION_NONE, 838c2ecf20Sopenharmony_ci MRP_TX_ACTION_S_NEW, 848c2ecf20Sopenharmony_ci MRP_TX_ACTION_S_JOIN_IN, 858c2ecf20Sopenharmony_ci MRP_TX_ACTION_S_JOIN_IN_OPTIONAL, 868c2ecf20Sopenharmony_ci MRP_TX_ACTION_S_IN_OPTIONAL, 878c2ecf20Sopenharmony_ci MRP_TX_ACTION_S_LV, 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistruct mrp_attr { 918c2ecf20Sopenharmony_ci struct rb_node node; 928c2ecf20Sopenharmony_ci enum mrp_applicant_state state; 938c2ecf20Sopenharmony_ci u8 type; 948c2ecf20Sopenharmony_ci u8 len; 958c2ecf20Sopenharmony_ci unsigned char value[]; 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cienum mrp_applications { 998c2ecf20Sopenharmony_ci MRP_APPLICATION_MVRP, 1008c2ecf20Sopenharmony_ci __MRP_APPLICATION_MAX 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ci#define MRP_APPLICATION_MAX (__MRP_APPLICATION_MAX - 1) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistruct mrp_application { 1058c2ecf20Sopenharmony_ci enum mrp_applications type; 1068c2ecf20Sopenharmony_ci unsigned int maxattr; 1078c2ecf20Sopenharmony_ci struct packet_type pkttype; 1088c2ecf20Sopenharmony_ci unsigned char group_address[ETH_ALEN]; 1098c2ecf20Sopenharmony_ci u8 version; 1108c2ecf20Sopenharmony_ci}; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistruct mrp_applicant { 1138c2ecf20Sopenharmony_ci struct mrp_application *app; 1148c2ecf20Sopenharmony_ci struct net_device *dev; 1158c2ecf20Sopenharmony_ci struct timer_list join_timer; 1168c2ecf20Sopenharmony_ci struct timer_list periodic_timer; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci spinlock_t lock; 1198c2ecf20Sopenharmony_ci struct sk_buff_head queue; 1208c2ecf20Sopenharmony_ci struct sk_buff *pdu; 1218c2ecf20Sopenharmony_ci struct rb_root mad; 1228c2ecf20Sopenharmony_ci struct rcu_head rcu; 1238c2ecf20Sopenharmony_ci bool active; 1248c2ecf20Sopenharmony_ci}; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistruct mrp_port { 1278c2ecf20Sopenharmony_ci struct mrp_applicant __rcu *applicants[MRP_APPLICATION_MAX + 1]; 1288c2ecf20Sopenharmony_ci struct rcu_head rcu; 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ciint mrp_register_application(struct mrp_application *app); 1328c2ecf20Sopenharmony_civoid mrp_unregister_application(struct mrp_application *app); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciint mrp_init_applicant(struct net_device *dev, struct mrp_application *app); 1358c2ecf20Sopenharmony_civoid mrp_uninit_applicant(struct net_device *dev, struct mrp_application *app); 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciint mrp_request_join(const struct net_device *dev, 1388c2ecf20Sopenharmony_ci const struct mrp_application *app, 1398c2ecf20Sopenharmony_ci const void *value, u8 len, u8 type); 1408c2ecf20Sopenharmony_civoid mrp_request_leave(const struct net_device *dev, 1418c2ecf20Sopenharmony_ci const struct mrp_application *app, 1428c2ecf20Sopenharmony_ci const void *value, u8 len, u8 type); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#endif /* _NET_MRP_H */ 145