2 * Shared Memory Communications over RDMA (SMC-R) and RoCE
4 * Definitions for the SMC module (socket related)
6 * Copyright IBM Corp. 2016
8 * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
13 #include <linux/socket.h>
14 #include <linux/types.h>
19 #define SMCPROTO_SMC 0 /* SMC protocol */
21 #define SMC_MAX_PORTS 2 /* Max # of ports */
23 enum smc_state { /* possible states of an SMC socket */
30 struct smc_link_group;
32 struct smc_connection {
33 struct rb_node alert_node;
34 struct smc_link_group *lgr; /* link group of connection */
35 u32 alert_token_local; /* unique conn. id */
36 u8 peer_conn_idx; /* from tcp handshake */
37 int peer_rmbe_size; /* size of peer rx buffer */
38 atomic_t peer_rmbe_space;/* remaining free bytes in peer
42 struct smc_buf_desc *sndbuf_desc; /* send buffer descriptor */
43 int sndbuf_size; /* sndbuf size <== sock wmem */
44 struct smc_buf_desc *rmb_desc; /* RMBE descriptor */
45 int rmbe_size; /* RMBE size <== sock rmem */
46 int rmbe_size_short;/* compressed notation */
49 struct smc_sock { /* smc sock container */
51 struct socket *clcsock; /* internal tcp socket */
52 struct smc_connection conn; /* smc connection */
53 struct sockaddr *addr; /* inet connect address */
54 struct smc_sock *listen_smc; /* listen parent */
55 struct work_struct tcp_listen_work;/* handle tcp socket accepts */
56 struct work_struct smc_listen_work;/* prepare new accept socket */
57 struct list_head accept_q; /* sockets to be accepted */
58 spinlock_t accept_q_lock; /* protects accept_q */
59 bool use_fallback; /* fallback to tcp */
62 static inline struct smc_sock *smc_sk(const struct sock *sk)
64 return (struct smc_sock *)sk;
67 #define SMC_SYSTEMID_LEN 8
69 extern u8 local_systemid[SMC_SYSTEMID_LEN]; /* unique system identifier */
71 /* convert an u32 value into network byte order, store it into a 3 byte field */
72 static inline void hton24(u8 *net, u32 host)
76 t = cpu_to_be32(host);
77 memcpy(net, ((u8 *)&t) + 1, 3);
80 /* convert a received 3 byte field into host byte order*/
81 static inline u32 ntoh24(u8 *net)
85 memcpy(((u8 *)&t) + 1, net, 3);
86 return be32_to_cpu(t);
89 #define SMC_BUF_MIN_SIZE 16384 /* minimum size of an RMB */
91 #define SMC_RMBE_SIZES 16 /* number of distinct sizes for an RMBE */
92 /* theoretically, the RFC states that largest size would be 512K,
93 * i.e. compressed 5 and thus 6 sizes (0..5), despite
94 * struct smc_clc_msg_accept_confirm.rmbe_size being a 4 bit value (0..15)
97 /* convert the RMB size into the compressed notation - minimum 16K.
98 * In contrast to plain ilog2, this rounds towards the next power of 2,
99 * so the socket application gets at least its desired sndbuf / rcvbuf size.
101 static inline u8 smc_compress_bufsize(int size)
105 if (size <= SMC_BUF_MIN_SIZE)
108 size = (size - 1) >> 14;
109 compressed = ilog2(size) + 1;
110 if (compressed >= SMC_RMBE_SIZES)
111 compressed = SMC_RMBE_SIZES - 1;
115 /* convert the RMB size from compressed notation into integer */
116 static inline int smc_uncompress_bufsize(u8 compressed)
120 size = 0x00000001 << (((int)compressed) + 14);
125 static inline bool using_ipsec(struct smc_sock *smc)
127 return (smc->clcsock->sk->sk_policy[0] ||
128 smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
131 static inline bool using_ipsec(struct smc_sock *smc)
137 struct smc_clc_msg_local;
139 int smc_netinfo_by_tcpsk(struct socket *clcsock, __be32 *subnet,
141 void smc_conn_free(struct smc_connection *conn);
142 int smc_conn_create(struct smc_sock *smc, __be32 peer_in_addr,
143 struct smc_ib_device *smcibdev, u8 ibport,
144 struct smc_clc_msg_local *lcl, int srv_first_contact);