]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - net/smc/smc.h
smc: remote memory buffers (RMBs)
[mirror_ubuntu-focal-kernel.git] / net / smc / smc.h
CommitLineData
ac713874
UB
1/*
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
0cfdd8f9
UB
17#include "smc_ib.h"
18
ac713874
UB
19#define SMCPROTO_SMC 0 /* SMC protocol */
20
a4cf0443
UB
21#define SMC_MAX_PORTS 2 /* Max # of ports */
22
ac713874
UB
23enum 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
0cfdd8f9
UB
30struct 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 */
cd6851f3
UB
37 int peer_rmbe_size; /* size of peer rx buffer */
38 atomic_t peer_rmbe_space;/* remaining free bytes in peer
39 * rmbe
40 */
41
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 */
0cfdd8f9
UB
47};
48
ac713874
UB
49struct smc_sock { /* smc sock container */
50 struct sock sk;
51 struct socket *clcsock; /* internal tcp socket */
0cfdd8f9 52 struct smc_connection conn; /* smc connection */
a046d57d
UB
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 */
ac713874
UB
59 bool use_fallback; /* fallback to tcp */
60};
61
62static inline struct smc_sock *smc_sk(const struct sock *sk)
63{
64 return (struct smc_sock *)sk;
65}
66
a4cf0443
UB
67#define SMC_SYSTEMID_LEN 8
68
69extern u8 local_systemid[SMC_SYSTEMID_LEN]; /* unique system identifier */
70
0cfdd8f9
UB
71/* convert an u32 value into network byte order, store it into a 3 byte field */
72static inline void hton24(u8 *net, u32 host)
73{
74 __be32 t;
75
76 t = cpu_to_be32(host);
77 memcpy(net, ((u8 *)&t) + 1, 3);
78}
79
80/* convert a received 3 byte field into host byte order*/
81static inline u32 ntoh24(u8 *net)
82{
83 __be32 t = 0;
84
85 memcpy(((u8 *)&t) + 1, net, 3);
86 return be32_to_cpu(t);
87}
88
cd6851f3
UB
89#define SMC_BUF_MIN_SIZE 16384 /* minimum size of an RMB */
90
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)
95 */
96
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.
100 */
101static inline u8 smc_compress_bufsize(int size)
102{
103 u8 compressed;
104
105 if (size <= SMC_BUF_MIN_SIZE)
106 return 0;
107
108 size = (size - 1) >> 14;
109 compressed = ilog2(size) + 1;
110 if (compressed >= SMC_RMBE_SIZES)
111 compressed = SMC_RMBE_SIZES - 1;
112 return compressed;
113}
114
115/* convert the RMB size from compressed notation into integer */
116static inline int smc_uncompress_bufsize(u8 compressed)
117{
118 u32 size;
119
120 size = 0x00000001 << (((int)compressed) + 14);
121 return (int)size;
122}
123
a046d57d
UB
124#ifdef CONFIG_XFRM
125static inline bool using_ipsec(struct smc_sock *smc)
126{
127 return (smc->clcsock->sk->sk_policy[0] ||
128 smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
129}
130#else
131static inline bool using_ipsec(struct smc_sock *smc)
132{
133 return 0;
134}
135#endif
136
0cfdd8f9
UB
137struct smc_clc_msg_local;
138
a046d57d
UB
139int smc_netinfo_by_tcpsk(struct socket *clcsock, __be32 *subnet,
140 u8 *prefix_len);
0cfdd8f9
UB
141void smc_conn_free(struct smc_connection *conn);
142int 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);
a046d57d 145
ac713874 146#endif /* __SMC_H */