]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - net/smc/smc_clc.h
net/smc: add SMC-Rv2 connection establishment
[mirror_ubuntu-jammy-kernel.git] / net / smc / smc_clc.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
a046d57d
UB
2/*
3 * Shared Memory Communications over RDMA (SMC-R) and RoCE
4 *
5 * CLC (connection layer control) handshake over initial TCP socket to
6 * prepare for RDMA traffic
7 *
8 * Copyright IBM Corp. 2016
9 *
10 * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
11 */
12
13#ifndef _SMC_CLC_H
14#define _SMC_CLC_H
15
16#include <rdma/ib_verbs.h>
fefefe10 17#include <linux/smc.h>
a046d57d
UB
18
19#include "smc.h"
fefefe10 20#include "smc_netlink.h"
a046d57d
UB
21
22#define SMC_CLC_PROPOSAL 0x01
23#define SMC_CLC_ACCEPT 0x02
24#define SMC_CLC_CONFIRM 0x03
25#define SMC_CLC_DECLINE 0x04
26
c758dfdd
HW
27#define SMC_TYPE_R 0 /* SMC-R only */
28#define SMC_TYPE_D 1 /* SMC-D only */
fb4f7926 29#define SMC_TYPE_N 2 /* neither SMC-R nor SMC-D */
c758dfdd 30#define SMC_TYPE_B 3 /* SMC-R and SMC-D */
a046d57d 31#define CLC_WAIT_TIME (6 * HZ) /* max. wait time on clcsock */
2b59f58e 32#define CLC_WAIT_TIME_SHORT HZ /* short wait time on clcsock */
a046d57d 33#define SMC_CLC_DECL_MEM 0x01010000 /* insufficient memory resources */
603cc149
KG
34#define SMC_CLC_DECL_TIMEOUT_CL 0x02010000 /* timeout w4 QP confirm link */
35#define SMC_CLC_DECL_TIMEOUT_AL 0x02020000 /* timeout w4 QP add link */
a046d57d 36#define SMC_CLC_DECL_CNFERR 0x03000000 /* configuration error */
603cc149
KG
37#define SMC_CLC_DECL_PEERNOSMC 0x03010000 /* peer did not indicate SMC */
38#define SMC_CLC_DECL_IPSEC 0x03020000 /* IPsec usage */
9aa68d29
KG
39#define SMC_CLC_DECL_NOSMCDEV 0x03030000 /* no SMC device found (R or D) */
40#define SMC_CLC_DECL_NOSMCDDEV 0x03030001 /* no SMC-D device found */
41#define SMC_CLC_DECL_NOSMCRDEV 0x03030002 /* no SMC-R device found */
3752404a
KG
42#define SMC_CLC_DECL_NOISM2SUPP 0x03030003 /* hardware has no ISMv2 support */
43#define SMC_CLC_DECL_NOV2EXT 0x03030004 /* peer sent no clc v2 extension */
44#define SMC_CLC_DECL_NOV2DEXT 0x03030005 /* peer sent no clc SMC-Dv2 ext. */
45#define SMC_CLC_DECL_NOSEID 0x03030006 /* peer sent no SEID */
46#define SMC_CLC_DECL_NOSMCD2DEV 0x03030007 /* no SMC-Dv2 device found */
603cc149
KG
47#define SMC_CLC_DECL_MODEUNSUPP 0x03040000 /* smc modes do not match (R or D)*/
48#define SMC_CLC_DECL_RMBE_EC 0x03050000 /* peer has eyecatcher in RMBE */
49#define SMC_CLC_DECL_OPTUNSUPP 0x03060000 /* fastopen sockopt not supported */
59886697 50#define SMC_CLC_DECL_DIFFPREFIX 0x03070000 /* IP prefix / subnet mismatch */
fba7e8ef 51#define SMC_CLC_DECL_GETVLANERR 0x03080000 /* err to get vlan id of ip device*/
7a62725a 52#define SMC_CLC_DECL_ISMVLANERR 0x03090000 /* err to reg vlan id on ism dev */
b9247544 53#define SMC_CLC_DECL_NOACTLINK 0x030a0000 /* no active smc-r link in lgr */
0fb0b02b 54#define SMC_CLC_DECL_NOSRVLINK 0x030b0000 /* SMC-R link from srv not found */
fb4f7926 55#define SMC_CLC_DECL_VERSMISMAT 0x030c0000 /* SMC version mismatch */
72b7f6c4 56#define SMC_CLC_DECL_MAX_DMB 0x030d0000 /* SMC-D DMB limit exceeded */
ea9478b7
KG
57#define SMC_CLC_DECL_NOROUTE 0x030e0000 /* SMC-Rv2 conn. no route to peer */
58#define SMC_CLC_DECL_NOINDIRECT 0x030f0000 /* SMC-Rv2 conn. indirect mismatch*/
a046d57d 59#define SMC_CLC_DECL_SYNCERR 0x04000000 /* synchronization error */
603cc149 60#define SMC_CLC_DECL_PEERDECL 0x05000000 /* peer declined during handshake */
4ada81fd
KG
61#define SMC_CLC_DECL_INTERR 0x09990000 /* internal error */
62#define SMC_CLC_DECL_ERR_RTOK 0x09990001 /* rtoken handling failed */
63#define SMC_CLC_DECL_ERR_RDYLNK 0x09990002 /* ib ready link failed */
64#define SMC_CLC_DECL_ERR_REGRMB 0x09990003 /* reg rmb failed */
a046d57d 65
f1eb02f9
UB
66#define SMC_FIRST_CONTACT_MASK 0b10 /* first contact bit within typev2 */
67
a046d57d
UB
68struct smc_clc_msg_hdr { /* header1 of clc messages */
69 u8 eyecatcher[4]; /* eye catcher */
70 u8 type; /* proposal / accept / confirm / decline */
71 __be16 length;
72#if defined(__BIG_ENDIAN_BITFIELD)
73 u8 version : 4,
f1eb02f9
UB
74 typev2 : 2,
75 typev1 : 2;
a046d57d 76#elif defined(__LITTLE_ENDIAN_BITFIELD)
f1eb02f9
UB
77 u8 typev1 : 2,
78 typev2 : 2,
a046d57d
UB
79 version : 4;
80#endif
81} __packed; /* format defined in RFC7609 */
82
83struct smc_clc_msg_trail { /* trailer of clc messages */
84 u8 eyecatcher[4];
85};
86
87struct smc_clc_msg_local { /* header2 of clc messages */
88 u8 id_for_peer[SMC_SYSTEMID_LEN]; /* unique system id */
89 u8 gid[16]; /* gid of ib_device port */
90 u8 mac[6]; /* mac of ib_device port */
91};
92
1a26d020
KG
93/* Struct would be 4 byte aligned, but it is used in an array that is sent
94 * to peers and must conform to RFC7609, hence we need to use packed here.
95 */
e7b7a64a 96struct smc_clc_ipv6_prefix {
1a26d020 97 struct in6_addr prefix;
e7b7a64a 98 u8 prefix_len;
1a26d020 99} __packed; /* format defined in RFC7609 */
e7b7a64a 100
8c3dca34
UB
101#if defined(__BIG_ENDIAN_BITFIELD)
102struct smc_clc_v2_flag {
103 u8 release : 4,
104 rsvd : 3,
105 seid : 1;
106};
107#elif defined(__LITTLE_ENDIAN_BITFIELD)
108struct smc_clc_v2_flag {
109 u8 seid : 1,
110 rsvd : 3,
111 release : 4;
112};
113#endif
114
115struct smc_clnt_opts_area_hdr {
116 u8 eid_cnt; /* number of user defined EIDs */
117 u8 ism_gid_cnt; /* number of ISMv2 GIDs */
118 u8 reserved1;
119 struct smc_clc_v2_flag flag;
120 u8 reserved2[2];
121 __be16 smcd_v2_ext_offset; /* SMC-Dv2 Extension Offset */
122};
123
124struct smc_clc_smcd_gid_chid {
125 __be64 gid; /* ISM GID */
126 __be16 chid; /* ISMv2 CHID */
127} __packed; /* format defined in
128 * IBM Shared Memory Communications Version 2
129 * (https://www.ibm.com/support/pages/node/6326337)
130 */
131
132struct smc_clc_v2_extension {
133 struct smc_clnt_opts_area_hdr hdr;
134 u8 roce[16]; /* RoCEv2 GID */
135 u8 reserved[16];
7206d58a 136 u8 user_eids[][SMC_MAX_EID_LEN];
8c3dca34
UB
137};
138
e7b7a64a 139struct smc_clc_msg_proposal_prefix { /* prefix part of clc proposal message*/
a046d57d
UB
140 __be32 outgoing_subnet; /* subnet mask */
141 u8 prefix_len; /* number of significant bits in mask */
142 u8 reserved[2];
143 u8 ipv6_prefixes_cnt; /* number of IPv6 prefixes in prefix array */
a046d57d
UB
144} __aligned(4);
145
c758dfdd 146struct smc_clc_msg_smcd { /* SMC-D GID information */
8c3dca34
UB
147 struct smc_clc_smcd_gid_chid ism; /* ISM native GID+CHID of requestor */
148 __be16 v2_ext_offset; /* SMC Version 2 Extension Offset */
149 u8 reserved[28];
150};
151
152struct smc_clc_smcd_v2_extension {
153 u8 system_eid[SMC_MAX_EID_LEN];
154 u8 reserved[16];
7206d58a 155 struct smc_clc_smcd_gid_chid gidchid[];
c758dfdd
HW
156};
157
e7b7a64a
UB
158struct smc_clc_msg_proposal { /* clc proposal message sent by Linux */
159 struct smc_clc_msg_hdr hdr;
160 struct smc_clc_msg_local lcl;
161 __be16 iparea_offset; /* offset to IP address information area */
162} __aligned(4);
163
8c3dca34 164#define SMC_CLC_MAX_V6_PREFIX 8
fefefe10 165#define SMC_CLC_MAX_UEID 8
8c3dca34 166
6bb14e48
UB
167struct smc_clc_msg_proposal_area {
168 struct smc_clc_msg_proposal pclc_base;
169 struct smc_clc_msg_smcd pclc_smcd;
170 struct smc_clc_msg_proposal_prefix pclc_prfx;
171 struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX];
8c3dca34 172 struct smc_clc_v2_extension pclc_v2_ext;
fefefe10 173 u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];
8c3dca34
UB
174 struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext;
175 struct smc_clc_smcd_gid_chid pclc_gidchids[SMC_MAX_ISM_DEVS];
6bb14e48
UB
176 struct smc_clc_msg_trail pclc_trl;
177};
e7b7a64a 178
3d9725a6
UB
179struct smcr_clc_msg_accept_confirm { /* SMCR accept/confirm */
180 struct smc_clc_msg_local lcl;
181 u8 qpn[3]; /* QP number */
182 __be32 rmb_rkey; /* RMB rkey */
183 u8 rmbe_idx; /* Index of RMBE in RMB */
184 __be32 rmbe_alert_token; /* unique connection id */
185 #if defined(__BIG_ENDIAN_BITFIELD)
186 u8 rmbe_size : 4, /* buf size (compressed) */
187 qp_mtu : 4; /* QP mtu */
a046d57d 188#elif defined(__LITTLE_ENDIAN_BITFIELD)
3d9725a6
UB
189 u8 qp_mtu : 4,
190 rmbe_size : 4;
a046d57d 191#endif
3d9725a6
UB
192 u8 reserved;
193 __be64 rmb_dma_addr; /* RMB virtual address */
194 u8 reserved2;
195 u8 psn[3]; /* packet sequence number */
3d9725a6
UB
196} __packed;
197
a7c9c5f4 198struct smcd_clc_msg_accept_confirm_common { /* SMCD accept/confirm */
3d9725a6
UB
199 u64 gid; /* Sender GID */
200 u64 token; /* DMB token */
201 u8 dmbe_idx; /* DMBE index */
c758dfdd 202#if defined(__BIG_ENDIAN_BITFIELD)
3d9725a6
UB
203 u8 dmbe_size : 4, /* buf size (compressed) */
204 reserved3 : 4;
c758dfdd 205#elif defined(__LITTLE_ENDIAN_BITFIELD)
3d9725a6
UB
206 u8 reserved3 : 4,
207 dmbe_size : 4;
c758dfdd 208#endif
3d9725a6 209 u16 reserved4;
e15c6c46 210 __be32 linkid; /* Link identifier */
3d9725a6
UB
211} __packed;
212
b81a5eb7
UB
213#define SMC_CLC_OS_ZOS 1
214#define SMC_CLC_OS_LINUX 2
215#define SMC_CLC_OS_AIX 3
216
217struct smc_clc_first_contact_ext {
b81a5eb7 218#if defined(__BIG_ENDIAN_BITFIELD)
ea9478b7
KG
219 u8 v2_direct : 1,
220 reserved : 7;
b81a5eb7
UB
221 u8 os_type : 4,
222 release : 4;
223#elif defined(__LITTLE_ENDIAN_BITFIELD)
ea9478b7
KG
224 u8 reserved : 7,
225 v2_direct : 1;
b81a5eb7
UB
226 u8 release : 4,
227 os_type : 4;
228#endif
229 u8 reserved2[2];
230 u8 hostname[SMC_MAX_HOSTNAME_LEN];
231};
232
ea9478b7
KG
233struct smc_clc_fce_gid_ext {
234 u8 reserved[16];
235 u8 gid_cnt;
236 u8 reserved2[3];
237 u8 gid[][SMC_GID_SIZE];
238};
239
3d9725a6
UB
240struct smc_clc_msg_accept_confirm { /* clc accept / confirm message */
241 struct smc_clc_msg_hdr hdr;
242 union {
243 struct smcr_clc_msg_accept_confirm r0; /* SMC-R */
a7c9c5f4
UB
244 struct { /* SMC-D */
245 struct smcd_clc_msg_accept_confirm_common d0;
246 u32 reserved5[3];
247 };
c758dfdd 248 };
a046d57d
UB
249} __packed; /* format defined in RFC7609 */
250
a7c9c5f4
UB
251struct smc_clc_msg_accept_confirm_v2 { /* clc accept / confirm message */
252 struct smc_clc_msg_hdr hdr;
253 union {
ea9478b7
KG
254 struct { /* SMC-R */
255 struct smcr_clc_msg_accept_confirm r0;
256 u8 eid[SMC_MAX_EID_LEN];
257 u8 reserved6[8];
258 } r1;
a7c9c5f4
UB
259 struct { /* SMC-D */
260 struct smcd_clc_msg_accept_confirm_common d0;
261 __be16 chid;
262 u8 eid[SMC_MAX_EID_LEN];
263 u8 reserved5[8];
ea9478b7 264 } d1;
a7c9c5f4
UB
265 };
266};
267
a046d57d
UB
268struct smc_clc_msg_decline { /* clc decline message */
269 struct smc_clc_msg_hdr hdr;
270 u8 id_for_peer[SMC_SYSTEMID_LEN]; /* sender peer_id */
271 __be32 peer_diagnosis; /* diagnosis information */
e8d726c8
UB
272#if defined(__BIG_ENDIAN_BITFIELD)
273 u8 os_type : 4,
274 reserved : 4;
275#elif defined(__LITTLE_ENDIAN_BITFIELD)
276 u8 reserved : 4,
277 os_type : 4;
278#endif
279 u8 reserved2[3];
280 struct smc_clc_msg_trail trl; /* eye catcher "SMCD" or "SMCR" EBCDIC */
a046d57d
UB
281} __aligned(4);
282
e7b7a64a
UB
283/* determine start of the prefix area within the proposal message */
284static inline struct smc_clc_msg_proposal_prefix *
285smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc)
286{
287 return (struct smc_clc_msg_proposal_prefix *)
288 ((u8 *)pclc + sizeof(*pclc) + ntohs(pclc->iparea_offset));
289}
290
7affc809
UB
291static inline bool smcr_indicated(int smc_type)
292{
293 return smc_type == SMC_TYPE_R || smc_type == SMC_TYPE_B;
294}
295
296static inline bool smcd_indicated(int smc_type)
297{
298 return smc_type == SMC_TYPE_D || smc_type == SMC_TYPE_B;
299}
300
dfc62b12
KG
301static inline u8 smc_indicated_type(int is_smcd, int is_smcr)
302{
303 if (is_smcd && is_smcr)
304 return SMC_TYPE_B;
305 if (is_smcd)
306 return SMC_TYPE_D;
307 if (is_smcr)
308 return SMC_TYPE_R;
309 return SMC_TYPE_N;
310}
311
c758dfdd
HW
312/* get SMC-D info from proposal message */
313static inline struct smc_clc_msg_smcd *
314smc_get_clc_msg_smcd(struct smc_clc_msg_proposal *prop)
315{
8c3dca34 316 if (smcd_indicated(prop->hdr.typev1) &&
7affc809 317 ntohs(prop->iparea_offset) != sizeof(struct smc_clc_msg_smcd))
c758dfdd
HW
318 return NULL;
319
320 return (struct smc_clc_msg_smcd *)(prop + 1);
321}
322
8c3dca34
UB
323static inline struct smc_clc_v2_extension *
324smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)
325{
326 struct smc_clc_msg_smcd *prop_smcd = smc_get_clc_msg_smcd(prop);
327
328 if (!prop_smcd || !ntohs(prop_smcd->v2_ext_offset))
329 return NULL;
330
331 return (struct smc_clc_v2_extension *)
332 ((u8 *)prop_smcd +
333 offsetof(struct smc_clc_msg_smcd, v2_ext_offset) +
334 sizeof(prop_smcd->v2_ext_offset) +
335 ntohs(prop_smcd->v2_ext_offset));
336}
337
5c21c4cc
UB
338static inline struct smc_clc_smcd_v2_extension *
339smc_get_clc_smcd_v2_ext(struct smc_clc_v2_extension *prop_v2ext)
340{
341 if (!prop_v2ext)
342 return NULL;
343 if (!ntohs(prop_v2ext->hdr.smcd_v2_ext_offset))
344 return NULL;
345
346 return (struct smc_clc_smcd_v2_extension *)
347 ((u8 *)prop_v2ext +
348 offsetof(struct smc_clc_v2_extension, hdr) +
349 offsetof(struct smc_clnt_opts_area_hdr, smcd_v2_ext_offset) +
350 sizeof(prop_v2ext->hdr.smcd_v2_ext_offset) +
351 ntohs(prop_v2ext->hdr.smcd_v2_ext_offset));
352}
353
c758dfdd 354struct smcd_dev;
bc36d2fc 355struct smc_init_info;
c758dfdd 356
c246d942
KG
357int smc_clc_prfx_match(struct socket *clcsock,
358 struct smc_clc_msg_proposal_prefix *prop);
a046d57d 359int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen,
2b59f58e 360 u8 expected_type, unsigned long timeout);
e8d726c8 361int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info, u8 version);
d70bf4f7 362int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini);
a7c9c5f4 363int smc_clc_send_confirm(struct smc_sock *smc, bool clnt_first_contact,
ea9478b7 364 u8 version, u8 *eid, struct smc_init_info *ini);
a7c9c5f4 365int smc_clc_send_accept(struct smc_sock *smc, bool srv_first_contact,
fefefe10 366 u8 version, u8 *negotiated_eid);
b81a5eb7 367void smc_clc_init(void) __init;
fefefe10 368void smc_clc_exit(void);
099b990b 369void smc_clc_get_hostname(u8 **host);
fefefe10
KG
370bool smc_clc_match_eid(u8 *negotiated_eid,
371 struct smc_clc_v2_extension *smc_v2_ext,
372 u8 *peer_eid, u8 *local_eid);
dfc62b12 373int smc_clc_ueid_count(void);
fefefe10
KG
374int smc_nl_dump_ueid(struct sk_buff *skb, struct netlink_callback *cb);
375int smc_nl_add_ueid(struct sk_buff *skb, struct genl_info *info);
376int smc_nl_remove_ueid(struct sk_buff *skb, struct genl_info *info);
377int smc_nl_flush_ueid(struct sk_buff *skb, struct genl_info *info);
7a56f3fa
KG
378int smc_nl_dump_seid(struct sk_buff *skb, struct netlink_callback *cb);
379int smc_nl_enable_seid(struct sk_buff *skb, struct genl_info *info);
380int smc_nl_disable_seid(struct sk_buff *skb, struct genl_info *info);
a046d57d
UB
381
382#endif