Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * tcp.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Function prototypes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2004 Oracle.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #ifndef O2CLUSTER_TCP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define O2CLUSTER_TCP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #ifdef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <sys/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct o2net_msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	__be16 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	__be16 data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	__be16 msg_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	__be16 pad1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	__be32 sys_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	__be32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	__be32 key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	__be32 msg_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	__u8  buf[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 				     void **ret_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) typedef void (o2net_post_msg_handler_func)(int status, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 					   void *ret_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define O2NET_MAX_PAYLOAD_BYTES  (4096 - sizeof(struct o2net_msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* same as hb delay, we're waiting for another node to recognize our hb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define O2NET_RECONNECT_DELAY_MS_DEFAULT	2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT	2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define O2NET_IDLE_TIMEOUT_MS_DEFAULT		30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define O2NET_TCP_USER_TIMEOUT			0x7fffffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /* TODO: figure this out.... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static inline int o2net_link_down(int err, struct socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (sock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		if (sock->sk->sk_state != TCP_ESTABLISHED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	    	    sock->sk->sk_state != TCP_CLOSE_WAIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (err >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	switch (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		/* ????????????????????????? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		case -EBADF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		/* When the server has died, an ICMP port unreachable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		 * message prompts ECONNREFUSED. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		case -ECONNREFUSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		case -ENOTCONN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		case -EPIPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	O2NET_DRIVER_UNINITED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	O2NET_DRIVER_READY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		       u8 target_node, int *status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			   size_t veclen, u8 target_node, int *status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			   o2net_msg_handler_func *func, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			   o2net_post_msg_handler_func *post_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			   struct list_head *unreg_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) void o2net_unregister_handler_list(struct list_head *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) void o2net_fill_node_map(unsigned long *map, unsigned bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) struct o2nm_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) int o2net_register_hb_callbacks(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) void o2net_unregister_hb_callbacks(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int o2net_start_listening(struct o2nm_node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void o2net_stop_listening(struct o2nm_node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void o2net_disconnect_node(struct o2nm_node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int o2net_num_connected_peers(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int o2net_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void o2net_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct o2net_send_tracking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct o2net_sock_container;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) void o2net_debugfs_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) void o2net_debugfs_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void o2net_debug_add_nst(struct o2net_send_tracking *nst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void o2net_debug_del_nst(struct o2net_send_tracking *nst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) void o2net_debug_add_sc(struct o2net_sock_container *sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) void o2net_debug_del_sc(struct o2net_sock_container *sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static inline void o2net_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static inline void o2net_debugfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static inline void o2net_debug_add_nst(struct o2net_send_tracking *nst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static inline void o2net_debug_del_nst(struct o2net_send_tracking *nst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static inline void o2net_debug_add_sc(struct o2net_sock_container *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static inline void o2net_debug_del_sc(struct o2net_sock_container *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif	/* CONFIG_DEBUG_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #endif /* O2CLUSTER_TCP_H */