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 */
39 struct smc_sock { /* smc sock container */
41 struct socket *clcsock; /* internal tcp socket */
42 struct smc_connection conn; /* smc connection */
43 struct sockaddr *addr; /* inet connect address */
44 struct smc_sock *listen_smc; /* listen parent */
45 struct work_struct tcp_listen_work;/* handle tcp socket accepts */
46 struct work_struct smc_listen_work;/* prepare new accept socket */
47 struct list_head accept_q; /* sockets to be accepted */
48 spinlock_t accept_q_lock; /* protects accept_q */
49 bool use_fallback; /* fallback to tcp */
52 static inline struct smc_sock *smc_sk(const struct sock *sk)
54 return (struct smc_sock *)sk;
57 #define SMC_SYSTEMID_LEN 8
59 extern u8 local_systemid[SMC_SYSTEMID_LEN]; /* unique system identifier */
61 /* convert an u32 value into network byte order, store it into a 3 byte field */
62 static inline void hton24(u8 *net, u32 host)
66 t = cpu_to_be32(host);
67 memcpy(net, ((u8 *)&t) + 1, 3);
70 /* convert a received 3 byte field into host byte order*/
71 static inline u32 ntoh24(u8 *net)
75 memcpy(((u8 *)&t) + 1, net, 3);
76 return be32_to_cpu(t);
80 static inline bool using_ipsec(struct smc_sock *smc)
82 return (smc->clcsock->sk->sk_policy[0] ||
83 smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
86 static inline bool using_ipsec(struct smc_sock *smc)
92 struct smc_clc_msg_local;
94 int smc_netinfo_by_tcpsk(struct socket *clcsock, __be32 *subnet,
96 void smc_conn_free(struct smc_connection *conn);
97 int smc_conn_create(struct smc_sock *smc, __be32 peer_in_addr,
98 struct smc_ib_device *smcibdev, u8 ibport,
99 struct smc_clc_msg_local *lcl, int srv_first_contact);