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