blob: 11265bde465538be7648ed10718651a84bef9be4 [file] [log] [blame]
Ursula Braunac713872017-01-09 16:55:13 +01001/*
2 * Shared Memory Communications over RDMA (SMC-R) and RoCE
3 *
4 * Definitions for the SMC module (socket related)
5 *
6 * Copyright IBM Corp. 2016
7 *
8 * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
9 */
10#ifndef __SMC_H
11#define __SMC_H
12
13#include <linux/socket.h>
14#include <linux/types.h>
15#include <net/sock.h>
16
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010017#include "smc_ib.h"
18
Ursula Braunac713872017-01-09 16:55:13 +010019#define SMCPROTO_SMC 0 /* SMC protocol */
20
Ursula Brauna4cf0442017-01-09 16:55:14 +010021#define SMC_MAX_PORTS 2 /* Max # of ports */
22
Ursula Braunac713872017-01-09 16:55:13 +010023enum smc_state { /* possible states of an SMC socket */
24 SMC_ACTIVE = 1,
25 SMC_INIT = 2,
26 SMC_CLOSED = 7,
27 SMC_LISTEN = 10,
28};
29
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010030struct smc_link_group;
31
32struct 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};
38
Ursula Braunac713872017-01-09 16:55:13 +010039struct smc_sock { /* smc sock container */
40 struct sock sk;
41 struct socket *clcsock; /* internal tcp socket */
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010042 struct smc_connection conn; /* smc connection */
Ursula Brauna046d572017-01-09 16:55:16 +010043 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 */
Ursula Braunac713872017-01-09 16:55:13 +010049 bool use_fallback; /* fallback to tcp */
50};
51
52static inline struct smc_sock *smc_sk(const struct sock *sk)
53{
54 return (struct smc_sock *)sk;
55}
56
Ursula Brauna4cf0442017-01-09 16:55:14 +010057#define SMC_SYSTEMID_LEN 8
58
59extern u8 local_systemid[SMC_SYSTEMID_LEN]; /* unique system identifier */
60
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010061/* convert an u32 value into network byte order, store it into a 3 byte field */
62static inline void hton24(u8 *net, u32 host)
63{
64 __be32 t;
65
66 t = cpu_to_be32(host);
67 memcpy(net, ((u8 *)&t) + 1, 3);
68}
69
70/* convert a received 3 byte field into host byte order*/
71static inline u32 ntoh24(u8 *net)
72{
73 __be32 t = 0;
74
75 memcpy(((u8 *)&t) + 1, net, 3);
76 return be32_to_cpu(t);
77}
78
Ursula Brauna046d572017-01-09 16:55:16 +010079#ifdef CONFIG_XFRM
80static inline bool using_ipsec(struct smc_sock *smc)
81{
82 return (smc->clcsock->sk->sk_policy[0] ||
83 smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
84}
85#else
86static inline bool using_ipsec(struct smc_sock *smc)
87{
88 return 0;
89}
90#endif
91
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010092struct smc_clc_msg_local;
93
Ursula Brauna046d572017-01-09 16:55:16 +010094int smc_netinfo_by_tcpsk(struct socket *clcsock, __be32 *subnet,
95 u8 *prefix_len);
Ursula Braun0cfdd8f2017-01-09 16:55:17 +010096void smc_conn_free(struct smc_connection *conn);
97int 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);
Ursula Brauna046d572017-01-09 16:55:16 +0100100
Ursula Braunac713872017-01-09 16:55:13 +0100101#endif /* __SMC_H */