xref: /openbmc/linux/net/smc/smc_clc.h (revision 0936cdfb)
1 /* SPDX-License-Identifier: GPL-2.0 */
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>
17 
18 #include "smc.h"
19 
20 #define SMC_CLC_PROPOSAL	0x01
21 #define SMC_CLC_ACCEPT		0x02
22 #define SMC_CLC_CONFIRM		0x03
23 #define SMC_CLC_DECLINE		0x04
24 
25 #define SMC_CLC_V1		0x1		/* SMC version                */
26 #define SMC_TYPE_R		0		/* SMC-R only		      */
27 #define SMC_TYPE_D		1		/* SMC-D only		      */
28 #define SMC_TYPE_N		2		/* neither SMC-R nor SMC-D    */
29 #define SMC_TYPE_B		3		/* SMC-R and SMC-D	      */
30 #define CLC_WAIT_TIME		(6 * HZ)	/* max. wait time on clcsock  */
31 #define CLC_WAIT_TIME_SHORT	HZ		/* short wait time on clcsock */
32 #define SMC_CLC_DECL_MEM	0x01010000  /* insufficient memory resources  */
33 #define SMC_CLC_DECL_TIMEOUT_CL	0x02010000  /* timeout w4 QP confirm link     */
34 #define SMC_CLC_DECL_TIMEOUT_AL	0x02020000  /* timeout w4 QP add link	      */
35 #define SMC_CLC_DECL_CNFERR	0x03000000  /* configuration error            */
36 #define SMC_CLC_DECL_PEERNOSMC	0x03010000  /* peer did not indicate SMC      */
37 #define SMC_CLC_DECL_IPSEC	0x03020000  /* IPsec usage		      */
38 #define SMC_CLC_DECL_NOSMCDEV	0x03030000  /* no SMC device found (R or D)   */
39 #define SMC_CLC_DECL_NOSMCDDEV	0x03030001  /* no SMC-D device found	      */
40 #define SMC_CLC_DECL_NOSMCRDEV	0x03030002  /* no SMC-R device found	      */
41 #define SMC_CLC_DECL_SMCDNOTALK	0x03030003  /* SMC-D dev can't talk to peer   */
42 #define SMC_CLC_DECL_MODEUNSUPP	0x03040000  /* smc modes do not match (R or D)*/
43 #define SMC_CLC_DECL_RMBE_EC	0x03050000  /* peer has eyecatcher in RMBE    */
44 #define SMC_CLC_DECL_OPTUNSUPP	0x03060000  /* fastopen sockopt not supported */
45 #define SMC_CLC_DECL_DIFFPREFIX	0x03070000  /* IP prefix / subnet mismatch    */
46 #define SMC_CLC_DECL_GETVLANERR	0x03080000  /* err to get vlan id of ip device*/
47 #define SMC_CLC_DECL_ISMVLANERR	0x03090000  /* err to reg vlan id on ism dev  */
48 #define SMC_CLC_DECL_NOACTLINK	0x030a0000  /* no active smc-r link in lgr    */
49 #define SMC_CLC_DECL_NOSRVLINK	0x030b0000  /* SMC-R link from srv not found  */
50 #define SMC_CLC_DECL_VERSMISMAT	0x030c0000  /* SMC version mismatch	      */
51 #define SMC_CLC_DECL_SYNCERR	0x04000000  /* synchronization error          */
52 #define SMC_CLC_DECL_PEERDECL	0x05000000  /* peer declined during handshake */
53 #define SMC_CLC_DECL_INTERR	0x09990000  /* internal error		      */
54 #define SMC_CLC_DECL_ERR_RTOK	0x09990001  /*	 rtoken handling failed       */
55 #define SMC_CLC_DECL_ERR_RDYLNK	0x09990002  /*	 ib ready link failed	      */
56 #define SMC_CLC_DECL_ERR_REGRMB	0x09990003  /*	 reg rmb failed		      */
57 
58 struct smc_clc_msg_hdr {	/* header1 of clc messages */
59 	u8 eyecatcher[4];	/* eye catcher */
60 	u8 type;		/* proposal / accept / confirm / decline */
61 	__be16 length;
62 #if defined(__BIG_ENDIAN_BITFIELD)
63 	u8 version : 4,
64 	   flag    : 1,
65 	   rsvd	   : 1,
66 	   path	   : 2;
67 #elif defined(__LITTLE_ENDIAN_BITFIELD)
68 	u8 path    : 2,
69 	   rsvd    : 1,
70 	   flag    : 1,
71 	   version : 4;
72 #endif
73 } __packed;			/* format defined in RFC7609 */
74 
75 struct smc_clc_msg_trail {	/* trailer of clc messages */
76 	u8 eyecatcher[4];
77 };
78 
79 struct smc_clc_msg_local {	/* header2 of clc messages */
80 	u8 id_for_peer[SMC_SYSTEMID_LEN]; /* unique system id */
81 	u8 gid[16];		/* gid of ib_device port */
82 	u8 mac[6];		/* mac of ib_device port */
83 };
84 
85 #define SMC_CLC_MAX_V6_PREFIX	8
86 
87 /* Struct would be 4 byte aligned, but it is used in an array that is sent
88  * to peers and must conform to RFC7609, hence we need to use packed here.
89  */
90 struct smc_clc_ipv6_prefix {
91 	struct in6_addr prefix;
92 	u8 prefix_len;
93 } __packed;			/* format defined in RFC7609 */
94 
95 struct smc_clc_msg_proposal_prefix {	/* prefix part of clc proposal message*/
96 	__be32 outgoing_subnet;	/* subnet mask */
97 	u8 prefix_len;		/* number of significant bits in mask */
98 	u8 reserved[2];
99 	u8 ipv6_prefixes_cnt;	/* number of IPv6 prefixes in prefix array */
100 } __aligned(4);
101 
102 struct smc_clc_msg_smcd {	/* SMC-D GID information */
103 	u64 gid;		/* ISM GID of requestor */
104 	u8 res[32];
105 };
106 
107 struct smc_clc_msg_proposal {	/* clc proposal message sent by Linux */
108 	struct smc_clc_msg_hdr hdr;
109 	struct smc_clc_msg_local lcl;
110 	__be16 iparea_offset;	/* offset to IP address information area */
111 } __aligned(4);
112 
113 #define SMC_CLC_PROPOSAL_MAX_OFFSET	0x28
114 #define SMC_CLC_PROPOSAL_MAX_PREFIX	(SMC_CLC_MAX_V6_PREFIX * \
115 					 sizeof(struct smc_clc_ipv6_prefix))
116 #define SMC_CLC_MAX_LEN		(sizeof(struct smc_clc_msg_proposal) + \
117 				 SMC_CLC_PROPOSAL_MAX_OFFSET + \
118 				 sizeof(struct smc_clc_msg_proposal_prefix) + \
119 				 SMC_CLC_PROPOSAL_MAX_PREFIX + \
120 				 sizeof(struct smc_clc_msg_trail))
121 
122 struct smc_clc_msg_accept_confirm {	/* clc accept / confirm message */
123 	struct smc_clc_msg_hdr hdr;
124 	union {
125 		struct { /* SMC-R */
126 			struct smc_clc_msg_local lcl;
127 			u8 qpn[3];		/* QP number */
128 			__be32 rmb_rkey;	/* RMB rkey */
129 			u8 rmbe_idx;		/* Index of RMBE in RMB */
130 			__be32 rmbe_alert_token;/* unique connection id */
131 #if defined(__BIG_ENDIAN_BITFIELD)
132 			u8 rmbe_size : 4,	/* buf size (compressed) */
133 			   qp_mtu   : 4;	/* QP mtu */
134 #elif defined(__LITTLE_ENDIAN_BITFIELD)
135 			u8 qp_mtu   : 4,
136 			   rmbe_size : 4;
137 #endif
138 			u8 reserved;
139 			__be64 rmb_dma_addr;	/* RMB virtual address */
140 			u8 reserved2;
141 			u8 psn[3];		/* packet sequence number */
142 			struct smc_clc_msg_trail smcr_trl;
143 						/* eye catcher "SMCR" EBCDIC */
144 		} __packed;
145 		struct { /* SMC-D */
146 			u64 gid;		/* Sender GID */
147 			u64 token;		/* DMB token */
148 			u8 dmbe_idx;		/* DMBE index */
149 #if defined(__BIG_ENDIAN_BITFIELD)
150 			u8 dmbe_size : 4,	/* buf size (compressed) */
151 			   reserved3 : 4;
152 #elif defined(__LITTLE_ENDIAN_BITFIELD)
153 			u8 reserved3 : 4,
154 			   dmbe_size : 4;
155 #endif
156 			u16 reserved4;
157 			u32 linkid;		/* Link identifier */
158 			u32 reserved5[3];
159 			struct smc_clc_msg_trail smcd_trl;
160 						/* eye catcher "SMCD" EBCDIC */
161 		} __packed;
162 	};
163 } __packed;			/* format defined in RFC7609 */
164 
165 struct smc_clc_msg_decline {	/* clc decline message */
166 	struct smc_clc_msg_hdr hdr;
167 	u8 id_for_peer[SMC_SYSTEMID_LEN]; /* sender peer_id */
168 	__be32 peer_diagnosis;	/* diagnosis information */
169 	u8 reserved2[4];
170 	struct smc_clc_msg_trail trl; /* eye catcher "SMCR" EBCDIC */
171 } __aligned(4);
172 
173 /* determine start of the prefix area within the proposal message */
174 static inline struct smc_clc_msg_proposal_prefix *
175 smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc)
176 {
177 	return (struct smc_clc_msg_proposal_prefix *)
178 	       ((u8 *)pclc + sizeof(*pclc) + ntohs(pclc->iparea_offset));
179 }
180 
181 /* get SMC-D info from proposal message */
182 static inline struct smc_clc_msg_smcd *
183 smc_get_clc_msg_smcd(struct smc_clc_msg_proposal *prop)
184 {
185 	if (ntohs(prop->iparea_offset) != sizeof(struct smc_clc_msg_smcd))
186 		return NULL;
187 
188 	return (struct smc_clc_msg_smcd *)(prop + 1);
189 }
190 
191 struct smcd_dev;
192 struct smc_init_info;
193 
194 int smc_clc_prfx_match(struct socket *clcsock,
195 		       struct smc_clc_msg_proposal_prefix *prop);
196 int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen,
197 		     u8 expected_type, unsigned long timeout);
198 int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info);
199 int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
200 			  struct smc_init_info *ini);
201 int smc_clc_send_confirm(struct smc_sock *smc);
202 int smc_clc_send_accept(struct smc_sock *smc, int srv_first_contact);
203 
204 #endif
205