smc_clc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. #ifndef _SMC_CLC_H
  13. #define _SMC_CLC_H
  14. #include <rdma/ib_verbs.h>
  15. #include "smc.h"
  16. #define SMC_CLC_PROPOSAL 0x01
  17. #define SMC_CLC_ACCEPT 0x02
  18. #define SMC_CLC_CONFIRM 0x03
  19. #define SMC_CLC_DECLINE 0x04
  20. #define SMC_TYPE_R 0 /* SMC-R only */
  21. #define SMC_TYPE_D 1 /* SMC-D only */
  22. #define SMC_TYPE_N 2 /* neither SMC-R nor SMC-D */
  23. #define SMC_TYPE_B 3 /* SMC-R and SMC-D */
  24. #define CLC_WAIT_TIME (6 * HZ) /* max. wait time on clcsock */
  25. #define CLC_WAIT_TIME_SHORT HZ /* short wait time on clcsock */
  26. #define SMC_CLC_DECL_MEM 0x01010000 /* insufficient memory resources */
  27. #define SMC_CLC_DECL_TIMEOUT_CL 0x02010000 /* timeout w4 QP confirm link */
  28. #define SMC_CLC_DECL_TIMEOUT_AL 0x02020000 /* timeout w4 QP add link */
  29. #define SMC_CLC_DECL_CNFERR 0x03000000 /* configuration error */
  30. #define SMC_CLC_DECL_PEERNOSMC 0x03010000 /* peer did not indicate SMC */
  31. #define SMC_CLC_DECL_IPSEC 0x03020000 /* IPsec usage */
  32. #define SMC_CLC_DECL_NOSMCDEV 0x03030000 /* no SMC device found (R or D) */
  33. #define SMC_CLC_DECL_NOSMCDDEV 0x03030001 /* no SMC-D device found */
  34. #define SMC_CLC_DECL_NOSMCRDEV 0x03030002 /* no SMC-R device found */
  35. #define SMC_CLC_DECL_MODEUNSUPP 0x03040000 /* smc modes do not match (R or D)*/
  36. #define SMC_CLC_DECL_RMBE_EC 0x03050000 /* peer has eyecatcher in RMBE */
  37. #define SMC_CLC_DECL_OPTUNSUPP 0x03060000 /* fastopen sockopt not supported */
  38. #define SMC_CLC_DECL_DIFFPREFIX 0x03070000 /* IP prefix / subnet mismatch */
  39. #define SMC_CLC_DECL_GETVLANERR 0x03080000 /* err to get vlan id of ip device*/
  40. #define SMC_CLC_DECL_ISMVLANERR 0x03090000 /* err to reg vlan id on ism dev */
  41. #define SMC_CLC_DECL_NOACTLINK 0x030a0000 /* no active smc-r link in lgr */
  42. #define SMC_CLC_DECL_NOSRVLINK 0x030b0000 /* SMC-R link from srv not found */
  43. #define SMC_CLC_DECL_VERSMISMAT 0x030c0000 /* SMC version mismatch */
  44. #define SMC_CLC_DECL_MAX_DMB 0x030d0000 /* SMC-D DMB limit exceeded */
  45. #define SMC_CLC_DECL_SYNCERR 0x04000000 /* synchronization error */
  46. #define SMC_CLC_DECL_PEERDECL 0x05000000 /* peer declined during handshake */
  47. #define SMC_CLC_DECL_INTERR 0x09990000 /* internal error */
  48. #define SMC_CLC_DECL_ERR_RTOK 0x09990001 /* rtoken handling failed */
  49. #define SMC_CLC_DECL_ERR_RDYLNK 0x09990002 /* ib ready link failed */
  50. #define SMC_CLC_DECL_ERR_REGRMB 0x09990003 /* reg rmb failed */
  51. #define SMC_FIRST_CONTACT_MASK 0b10 /* first contact bit within typev2 */
  52. struct smc_clc_msg_hdr { /* header1 of clc messages */
  53. u8 eyecatcher[4]; /* eye catcher */
  54. u8 type; /* proposal / accept / confirm / decline */
  55. __be16 length;
  56. #if defined(__BIG_ENDIAN_BITFIELD)
  57. u8 version : 4,
  58. typev2 : 2,
  59. typev1 : 2;
  60. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  61. u8 typev1 : 2,
  62. typev2 : 2,
  63. version : 4;
  64. #endif
  65. } __packed; /* format defined in RFC7609 */
  66. struct smc_clc_msg_trail { /* trailer of clc messages */
  67. u8 eyecatcher[4];
  68. };
  69. struct smc_clc_msg_local { /* header2 of clc messages */
  70. u8 id_for_peer[SMC_SYSTEMID_LEN]; /* unique system id */
  71. u8 gid[16]; /* gid of ib_device port */
  72. u8 mac[6]; /* mac of ib_device port */
  73. };
  74. /* Struct would be 4 byte aligned, but it is used in an array that is sent
  75. * to peers and must conform to RFC7609, hence we need to use packed here.
  76. */
  77. struct smc_clc_ipv6_prefix {
  78. struct in6_addr prefix;
  79. u8 prefix_len;
  80. } __packed; /* format defined in RFC7609 */
  81. #if defined(__BIG_ENDIAN_BITFIELD)
  82. struct smc_clc_v2_flag {
  83. u8 release : 4,
  84. rsvd : 3,
  85. seid : 1;
  86. };
  87. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  88. struct smc_clc_v2_flag {
  89. u8 seid : 1,
  90. rsvd : 3,
  91. release : 4;
  92. };
  93. #endif
  94. struct smc_clnt_opts_area_hdr {
  95. u8 eid_cnt; /* number of user defined EIDs */
  96. u8 ism_gid_cnt; /* number of ISMv2 GIDs */
  97. u8 reserved1;
  98. struct smc_clc_v2_flag flag;
  99. u8 reserved2[2];
  100. __be16 smcd_v2_ext_offset; /* SMC-Dv2 Extension Offset */
  101. };
  102. struct smc_clc_smcd_gid_chid {
  103. __be64 gid; /* ISM GID */
  104. __be16 chid; /* ISMv2 CHID */
  105. } __packed; /* format defined in
  106. * IBM Shared Memory Communications Version 2
  107. * (https://www.ibm.com/support/pages/node/6326337)
  108. */
  109. struct smc_clc_v2_extension {
  110. struct smc_clnt_opts_area_hdr hdr;
  111. u8 roce[16]; /* RoCEv2 GID */
  112. u8 reserved[16];
  113. u8 user_eids[][SMC_MAX_EID_LEN];
  114. };
  115. struct smc_clc_msg_proposal_prefix { /* prefix part of clc proposal message*/
  116. __be32 outgoing_subnet; /* subnet mask */
  117. u8 prefix_len; /* number of significant bits in mask */
  118. u8 reserved[2];
  119. u8 ipv6_prefixes_cnt; /* number of IPv6 prefixes in prefix array */
  120. } __aligned(4);
  121. struct smc_clc_msg_smcd { /* SMC-D GID information */
  122. struct smc_clc_smcd_gid_chid ism; /* ISM native GID+CHID of requestor */
  123. __be16 v2_ext_offset; /* SMC Version 2 Extension Offset */
  124. u8 reserved[28];
  125. };
  126. struct smc_clc_smcd_v2_extension {
  127. u8 system_eid[SMC_MAX_EID_LEN];
  128. u8 reserved[16];
  129. struct smc_clc_smcd_gid_chid gidchid[];
  130. };
  131. struct smc_clc_msg_proposal { /* clc proposal message sent by Linux */
  132. struct smc_clc_msg_hdr hdr;
  133. struct smc_clc_msg_local lcl;
  134. __be16 iparea_offset; /* offset to IP address information area */
  135. } __aligned(4);
  136. #define SMC_CLC_MAX_V6_PREFIX 8
  137. struct smc_clc_msg_proposal_area {
  138. struct smc_clc_msg_proposal pclc_base;
  139. struct smc_clc_msg_smcd pclc_smcd;
  140. struct smc_clc_msg_proposal_prefix pclc_prfx;
  141. struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX];
  142. struct smc_clc_v2_extension pclc_v2_ext;
  143. struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext;
  144. struct smc_clc_smcd_gid_chid pclc_gidchids[SMC_MAX_ISM_DEVS];
  145. struct smc_clc_msg_trail pclc_trl;
  146. };
  147. struct smcr_clc_msg_accept_confirm { /* SMCR accept/confirm */
  148. struct smc_clc_msg_local lcl;
  149. u8 qpn[3]; /* QP number */
  150. __be32 rmb_rkey; /* RMB rkey */
  151. u8 rmbe_idx; /* Index of RMBE in RMB */
  152. __be32 rmbe_alert_token; /* unique connection id */
  153. #if defined(__BIG_ENDIAN_BITFIELD)
  154. u8 rmbe_size : 4, /* buf size (compressed) */
  155. qp_mtu : 4; /* QP mtu */
  156. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  157. u8 qp_mtu : 4,
  158. rmbe_size : 4;
  159. #endif
  160. u8 reserved;
  161. __be64 rmb_dma_addr; /* RMB virtual address */
  162. u8 reserved2;
  163. u8 psn[3]; /* packet sequence number */
  164. } __packed;
  165. struct smcd_clc_msg_accept_confirm_common { /* SMCD accept/confirm */
  166. u64 gid; /* Sender GID */
  167. u64 token; /* DMB token */
  168. u8 dmbe_idx; /* DMBE index */
  169. #if defined(__BIG_ENDIAN_BITFIELD)
  170. u8 dmbe_size : 4, /* buf size (compressed) */
  171. reserved3 : 4;
  172. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  173. u8 reserved3 : 4,
  174. dmbe_size : 4;
  175. #endif
  176. u16 reserved4;
  177. __be32 linkid; /* Link identifier */
  178. } __packed;
  179. #define SMC_CLC_OS_ZOS 1
  180. #define SMC_CLC_OS_LINUX 2
  181. #define SMC_CLC_OS_AIX 3
  182. struct smc_clc_first_contact_ext {
  183. u8 reserved1;
  184. #if defined(__BIG_ENDIAN_BITFIELD)
  185. u8 os_type : 4,
  186. release : 4;
  187. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  188. u8 release : 4,
  189. os_type : 4;
  190. #endif
  191. u8 reserved2[2];
  192. u8 hostname[SMC_MAX_HOSTNAME_LEN];
  193. };
  194. struct smc_clc_msg_accept_confirm { /* clc accept / confirm message */
  195. struct smc_clc_msg_hdr hdr;
  196. union {
  197. struct smcr_clc_msg_accept_confirm r0; /* SMC-R */
  198. struct { /* SMC-D */
  199. struct smcd_clc_msg_accept_confirm_common d0;
  200. u32 reserved5[3];
  201. };
  202. };
  203. } __packed; /* format defined in RFC7609 */
  204. struct smc_clc_msg_accept_confirm_v2 { /* clc accept / confirm message */
  205. struct smc_clc_msg_hdr hdr;
  206. union {
  207. struct smcr_clc_msg_accept_confirm r0; /* SMC-R */
  208. struct { /* SMC-D */
  209. struct smcd_clc_msg_accept_confirm_common d0;
  210. __be16 chid;
  211. u8 eid[SMC_MAX_EID_LEN];
  212. u8 reserved5[8];
  213. };
  214. };
  215. };
  216. struct smc_clc_msg_decline { /* clc decline message */
  217. struct smc_clc_msg_hdr hdr;
  218. u8 id_for_peer[SMC_SYSTEMID_LEN]; /* sender peer_id */
  219. __be32 peer_diagnosis; /* diagnosis information */
  220. #if defined(__BIG_ENDIAN_BITFIELD)
  221. u8 os_type : 4,
  222. reserved : 4;
  223. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  224. u8 reserved : 4,
  225. os_type : 4;
  226. #endif
  227. u8 reserved2[3];
  228. struct smc_clc_msg_trail trl; /* eye catcher "SMCD" or "SMCR" EBCDIC */
  229. } __aligned(4);
  230. /* determine start of the prefix area within the proposal message */
  231. static inline struct smc_clc_msg_proposal_prefix *
  232. smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc)
  233. {
  234. return (struct smc_clc_msg_proposal_prefix *)
  235. ((u8 *)pclc + sizeof(*pclc) + ntohs(pclc->iparea_offset));
  236. }
  237. static inline bool smcr_indicated(int smc_type)
  238. {
  239. return smc_type == SMC_TYPE_R || smc_type == SMC_TYPE_B;
  240. }
  241. static inline bool smcd_indicated(int smc_type)
  242. {
  243. return smc_type == SMC_TYPE_D || smc_type == SMC_TYPE_B;
  244. }
  245. /* get SMC-D info from proposal message */
  246. static inline struct smc_clc_msg_smcd *
  247. smc_get_clc_msg_smcd(struct smc_clc_msg_proposal *prop)
  248. {
  249. if (smcd_indicated(prop->hdr.typev1) &&
  250. ntohs(prop->iparea_offset) != sizeof(struct smc_clc_msg_smcd))
  251. return NULL;
  252. return (struct smc_clc_msg_smcd *)(prop + 1);
  253. }
  254. static inline struct smc_clc_v2_extension *
  255. smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)
  256. {
  257. struct smc_clc_msg_smcd *prop_smcd = smc_get_clc_msg_smcd(prop);
  258. if (!prop_smcd || !ntohs(prop_smcd->v2_ext_offset))
  259. return NULL;
  260. return (struct smc_clc_v2_extension *)
  261. ((u8 *)prop_smcd +
  262. offsetof(struct smc_clc_msg_smcd, v2_ext_offset) +
  263. sizeof(prop_smcd->v2_ext_offset) +
  264. ntohs(prop_smcd->v2_ext_offset));
  265. }
  266. static inline struct smc_clc_smcd_v2_extension *
  267. smc_get_clc_smcd_v2_ext(struct smc_clc_v2_extension *prop_v2ext)
  268. {
  269. if (!prop_v2ext)
  270. return NULL;
  271. if (!ntohs(prop_v2ext->hdr.smcd_v2_ext_offset))
  272. return NULL;
  273. return (struct smc_clc_smcd_v2_extension *)
  274. ((u8 *)prop_v2ext +
  275. offsetof(struct smc_clc_v2_extension, hdr) +
  276. offsetof(struct smc_clnt_opts_area_hdr, smcd_v2_ext_offset) +
  277. sizeof(prop_v2ext->hdr.smcd_v2_ext_offset) +
  278. ntohs(prop_v2ext->hdr.smcd_v2_ext_offset));
  279. }
  280. struct smcd_dev;
  281. struct smc_init_info;
  282. int smc_clc_prfx_match(struct socket *clcsock,
  283. struct smc_clc_msg_proposal_prefix *prop);
  284. int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen,
  285. u8 expected_type, unsigned long timeout);
  286. int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info, u8 version);
  287. int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini);
  288. int smc_clc_send_confirm(struct smc_sock *smc, bool clnt_first_contact,
  289. u8 version);
  290. int smc_clc_send_accept(struct smc_sock *smc, bool srv_first_contact,
  291. u8 version);
  292. void smc_clc_init(void) __init;
  293. #endif