Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  Shared Memory Communications over RDMA (SMC-R) and RoCE
0004  *
0005  *  CLC (connection layer control) handshake over initial TCP socket to
0006  *  prepare for RDMA traffic
0007  *
0008  *  Copyright IBM Corp. 2016
0009  *
0010  *  Author(s):  Ursula Braun <ubraun@linux.vnet.ibm.com>
0011  */
0012 
0013 #ifndef _SMC_CLC_H
0014 #define _SMC_CLC_H
0015 
0016 #include <rdma/ib_verbs.h>
0017 #include <linux/smc.h>
0018 
0019 #include "smc.h"
0020 #include "smc_netlink.h"
0021 
0022 #define SMC_CLC_PROPOSAL    0x01
0023 #define SMC_CLC_ACCEPT      0x02
0024 #define SMC_CLC_CONFIRM     0x03
0025 #define SMC_CLC_DECLINE     0x04
0026 
0027 #define SMC_TYPE_R      0       /* SMC-R only             */
0028 #define SMC_TYPE_D      1       /* SMC-D only             */
0029 #define SMC_TYPE_N      2       /* neither SMC-R nor SMC-D    */
0030 #define SMC_TYPE_B      3       /* SMC-R and SMC-D        */
0031 #define CLC_WAIT_TIME       (6 * HZ)    /* max. wait time on clcsock  */
0032 #define CLC_WAIT_TIME_SHORT HZ      /* short wait time on clcsock */
0033 #define SMC_CLC_DECL_MEM    0x01010000  /* insufficient memory resources  */
0034 #define SMC_CLC_DECL_TIMEOUT_CL 0x02010000  /* timeout w4 QP confirm link     */
0035 #define SMC_CLC_DECL_TIMEOUT_AL 0x02020000  /* timeout w4 QP add link         */
0036 #define SMC_CLC_DECL_CNFERR 0x03000000  /* configuration error            */
0037 #define SMC_CLC_DECL_PEERNOSMC  0x03010000  /* peer did not indicate SMC      */
0038 #define SMC_CLC_DECL_IPSEC  0x03020000  /* IPsec usage            */
0039 #define SMC_CLC_DECL_NOSMCDEV   0x03030000  /* no SMC device found (R or D)   */
0040 #define SMC_CLC_DECL_NOSMCDDEV  0x03030001  /* no SMC-D device found          */
0041 #define SMC_CLC_DECL_NOSMCRDEV  0x03030002  /* no SMC-R device found          */
0042 #define SMC_CLC_DECL_NOISM2SUPP 0x03030003  /* hardware has no ISMv2 support  */
0043 #define SMC_CLC_DECL_NOV2EXT    0x03030004  /* peer sent no clc v2 extension  */
0044 #define SMC_CLC_DECL_NOV2DEXT   0x03030005  /* peer sent no clc SMC-Dv2 ext.  */
0045 #define SMC_CLC_DECL_NOSEID 0x03030006  /* peer sent no SEID          */
0046 #define SMC_CLC_DECL_NOSMCD2DEV 0x03030007  /* no SMC-Dv2 device found        */
0047 #define SMC_CLC_DECL_NOUEID 0x03030008  /* peer sent no UEID          */
0048 #define SMC_CLC_DECL_MODEUNSUPP 0x03040000  /* smc modes do not match (R or D)*/
0049 #define SMC_CLC_DECL_RMBE_EC    0x03050000  /* peer has eyecatcher in RMBE    */
0050 #define SMC_CLC_DECL_OPTUNSUPP  0x03060000  /* fastopen sockopt not supported */
0051 #define SMC_CLC_DECL_DIFFPREFIX 0x03070000  /* IP prefix / subnet mismatch    */
0052 #define SMC_CLC_DECL_GETVLANERR 0x03080000  /* err to get vlan id of ip device*/
0053 #define SMC_CLC_DECL_ISMVLANERR 0x03090000  /* err to reg vlan id on ism dev  */
0054 #define SMC_CLC_DECL_NOACTLINK  0x030a0000  /* no active smc-r link in lgr    */
0055 #define SMC_CLC_DECL_NOSRVLINK  0x030b0000  /* SMC-R link from srv not found  */
0056 #define SMC_CLC_DECL_VERSMISMAT 0x030c0000  /* SMC version mismatch       */
0057 #define SMC_CLC_DECL_MAX_DMB    0x030d0000  /* SMC-D DMB limit exceeded       */
0058 #define SMC_CLC_DECL_NOROUTE    0x030e0000  /* SMC-Rv2 conn. no route to peer */
0059 #define SMC_CLC_DECL_NOINDIRECT 0x030f0000  /* SMC-Rv2 conn. indirect mismatch*/
0060 #define SMC_CLC_DECL_SYNCERR    0x04000000  /* synchronization error          */
0061 #define SMC_CLC_DECL_PEERDECL   0x05000000  /* peer declined during handshake */
0062 #define SMC_CLC_DECL_INTERR 0x09990000  /* internal error             */
0063 #define SMC_CLC_DECL_ERR_RTOK   0x09990001  /*   rtoken handling failed       */
0064 #define SMC_CLC_DECL_ERR_RDYLNK 0x09990002  /*   ib ready link failed         */
0065 #define SMC_CLC_DECL_ERR_REGBUF 0x09990003  /*   reg rdma bufs failed         */
0066 
0067 #define SMC_FIRST_CONTACT_MASK  0b10    /* first contact bit within typev2 */
0068 
0069 struct smc_clc_msg_hdr {    /* header1 of clc messages */
0070     u8 eyecatcher[4];   /* eye catcher */
0071     u8 type;        /* proposal / accept / confirm / decline */
0072     __be16 length;
0073 #if defined(__BIG_ENDIAN_BITFIELD)
0074     u8 version : 4,
0075        typev2  : 2,
0076        typev1  : 2;
0077 #elif defined(__LITTLE_ENDIAN_BITFIELD)
0078     u8 typev1  : 2,
0079        typev2  : 2,
0080        version : 4;
0081 #endif
0082 } __packed;         /* format defined in RFC7609 */
0083 
0084 struct smc_clc_msg_trail {  /* trailer of clc messages */
0085     u8 eyecatcher[4];
0086 };
0087 
0088 struct smc_clc_msg_local {  /* header2 of clc messages */
0089     u8 id_for_peer[SMC_SYSTEMID_LEN]; /* unique system id */
0090     u8 gid[16];     /* gid of ib_device port */
0091     u8 mac[6];      /* mac of ib_device port */
0092 };
0093 
0094 /* Struct would be 4 byte aligned, but it is used in an array that is sent
0095  * to peers and must conform to RFC7609, hence we need to use packed here.
0096  */
0097 struct smc_clc_ipv6_prefix {
0098     struct in6_addr prefix;
0099     u8 prefix_len;
0100 } __packed;         /* format defined in RFC7609 */
0101 
0102 #if defined(__BIG_ENDIAN_BITFIELD)
0103 struct smc_clc_v2_flag {
0104     u8 release : 4,
0105        rsvd    : 3,
0106        seid    : 1;
0107 };
0108 #elif defined(__LITTLE_ENDIAN_BITFIELD)
0109 struct smc_clc_v2_flag {
0110     u8 seid   : 1,
0111     rsvd      : 3,
0112     release   : 4;
0113 };
0114 #endif
0115 
0116 struct smc_clnt_opts_area_hdr {
0117     u8 eid_cnt;     /* number of user defined EIDs */
0118     u8 ism_gid_cnt;     /* number of ISMv2 GIDs */
0119     u8 reserved1;
0120     struct smc_clc_v2_flag flag;
0121     u8 reserved2[2];
0122     __be16 smcd_v2_ext_offset; /* SMC-Dv2 Extension Offset */
0123 };
0124 
0125 struct smc_clc_smcd_gid_chid {
0126     __be64 gid;     /* ISM GID */
0127     __be16 chid;        /* ISMv2 CHID */
0128 } __packed;     /* format defined in
0129              * IBM Shared Memory Communications Version 2
0130              * (https://www.ibm.com/support/pages/node/6326337)
0131              */
0132 
0133 struct smc_clc_v2_extension {
0134     struct smc_clnt_opts_area_hdr hdr;
0135     u8 roce[16];        /* RoCEv2 GID */
0136     u8 reserved[16];
0137     u8 user_eids[][SMC_MAX_EID_LEN];
0138 };
0139 
0140 struct smc_clc_msg_proposal_prefix {    /* prefix part of clc proposal message*/
0141     __be32 outgoing_subnet; /* subnet mask */
0142     u8 prefix_len;      /* number of significant bits in mask */
0143     u8 reserved[2];
0144     u8 ipv6_prefixes_cnt;   /* number of IPv6 prefixes in prefix array */
0145 } __aligned(4);
0146 
0147 struct smc_clc_msg_smcd {   /* SMC-D GID information */
0148     struct smc_clc_smcd_gid_chid ism; /* ISM native GID+CHID of requestor */
0149     __be16 v2_ext_offset;   /* SMC Version 2 Extension Offset */
0150     u8 reserved[28];
0151 };
0152 
0153 struct smc_clc_smcd_v2_extension {
0154     u8 system_eid[SMC_MAX_EID_LEN];
0155     u8 reserved[16];
0156     struct smc_clc_smcd_gid_chid gidchid[];
0157 };
0158 
0159 struct smc_clc_msg_proposal {   /* clc proposal message sent by Linux */
0160     struct smc_clc_msg_hdr hdr;
0161     struct smc_clc_msg_local lcl;
0162     __be16 iparea_offset;   /* offset to IP address information area */
0163 } __aligned(4);
0164 
0165 #define SMC_CLC_MAX_V6_PREFIX       8
0166 #define SMC_CLC_MAX_UEID        8
0167 
0168 struct smc_clc_msg_proposal_area {
0169     struct smc_clc_msg_proposal     pclc_base;
0170     struct smc_clc_msg_smcd         pclc_smcd;
0171     struct smc_clc_msg_proposal_prefix  pclc_prfx;
0172     struct smc_clc_ipv6_prefix  pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX];
0173     struct smc_clc_v2_extension     pclc_v2_ext;
0174     u8          user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];
0175     struct smc_clc_smcd_v2_extension    pclc_smcd_v2_ext;
0176     struct smc_clc_smcd_gid_chid        pclc_gidchids[SMC_MAX_ISM_DEVS];
0177     struct smc_clc_msg_trail        pclc_trl;
0178 };
0179 
0180 struct smcr_clc_msg_accept_confirm {    /* SMCR accept/confirm */
0181     struct smc_clc_msg_local lcl;
0182     u8 qpn[3];          /* QP number */
0183     __be32 rmb_rkey;        /* RMB rkey */
0184     u8 rmbe_idx;            /* Index of RMBE in RMB */
0185     __be32 rmbe_alert_token;    /* unique connection id */
0186  #if defined(__BIG_ENDIAN_BITFIELD)
0187     u8 rmbe_size : 4,       /* buf size (compressed) */
0188        qp_mtu   : 4;        /* QP mtu */
0189 #elif defined(__LITTLE_ENDIAN_BITFIELD)
0190     u8 qp_mtu   : 4,
0191        rmbe_size : 4;
0192 #endif
0193     u8 reserved;
0194     __be64 rmb_dma_addr;    /* RMB virtual address */
0195     u8 reserved2;
0196     u8 psn[3];      /* packet sequence number */
0197 } __packed;
0198 
0199 struct smcd_clc_msg_accept_confirm_common { /* SMCD accept/confirm */
0200     u64 gid;        /* Sender GID */
0201     u64 token;      /* DMB token */
0202     u8 dmbe_idx;        /* DMBE index */
0203 #if defined(__BIG_ENDIAN_BITFIELD)
0204     u8 dmbe_size : 4,   /* buf size (compressed) */
0205        reserved3 : 4;
0206 #elif defined(__LITTLE_ENDIAN_BITFIELD)
0207     u8 reserved3 : 4,
0208        dmbe_size : 4;
0209 #endif
0210     u16 reserved4;
0211     __be32 linkid;      /* Link identifier */
0212 } __packed;
0213 
0214 #define SMC_CLC_OS_ZOS      1
0215 #define SMC_CLC_OS_LINUX    2
0216 #define SMC_CLC_OS_AIX      3
0217 
0218 struct smc_clc_first_contact_ext {
0219 #if defined(__BIG_ENDIAN_BITFIELD)
0220     u8 v2_direct : 1,
0221        reserved  : 7;
0222     u8 os_type : 4,
0223        release : 4;
0224 #elif defined(__LITTLE_ENDIAN_BITFIELD)
0225     u8 reserved  : 7,
0226        v2_direct : 1;
0227     u8 release : 4,
0228        os_type : 4;
0229 #endif
0230     u8 reserved2[2];
0231     u8 hostname[SMC_MAX_HOSTNAME_LEN];
0232 };
0233 
0234 struct smc_clc_fce_gid_ext {
0235     u8 reserved[16];
0236     u8 gid_cnt;
0237     u8 reserved2[3];
0238     u8 gid[][SMC_GID_SIZE];
0239 };
0240 
0241 struct smc_clc_msg_accept_confirm { /* clc accept / confirm message */
0242     struct smc_clc_msg_hdr hdr;
0243     union {
0244         struct smcr_clc_msg_accept_confirm r0; /* SMC-R */
0245         struct { /* SMC-D */
0246             struct smcd_clc_msg_accept_confirm_common d0;
0247             u32 reserved5[3];
0248         };
0249     };
0250 } __packed;         /* format defined in RFC7609 */
0251 
0252 struct smc_clc_msg_accept_confirm_v2 {  /* clc accept / confirm message */
0253     struct smc_clc_msg_hdr hdr;
0254     union {
0255         struct { /* SMC-R */
0256             struct smcr_clc_msg_accept_confirm r0;
0257             u8 eid[SMC_MAX_EID_LEN];
0258             u8 reserved6[8];
0259         } r1;
0260         struct { /* SMC-D */
0261             struct smcd_clc_msg_accept_confirm_common d0;
0262             __be16 chid;
0263             u8 eid[SMC_MAX_EID_LEN];
0264             u8 reserved5[8];
0265         } d1;
0266     };
0267 };
0268 
0269 struct smc_clc_msg_decline {    /* clc decline message */
0270     struct smc_clc_msg_hdr hdr;
0271     u8 id_for_peer[SMC_SYSTEMID_LEN]; /* sender peer_id */
0272     __be32 peer_diagnosis;  /* diagnosis information */
0273 #if defined(__BIG_ENDIAN_BITFIELD)
0274     u8 os_type  : 4,
0275        reserved : 4;
0276 #elif defined(__LITTLE_ENDIAN_BITFIELD)
0277     u8 reserved : 4,
0278        os_type  : 4;
0279 #endif
0280     u8 reserved2[3];
0281     struct smc_clc_msg_trail trl; /* eye catcher "SMCD" or "SMCR" EBCDIC */
0282 } __aligned(4);
0283 
0284 #define SMC_DECL_DIAG_COUNT_V2  4 /* no. of additional peer diagnosis codes */
0285 
0286 struct smc_clc_msg_decline_v2 { /* clc decline message */
0287     struct smc_clc_msg_hdr hdr;
0288     u8 id_for_peer[SMC_SYSTEMID_LEN]; /* sender peer_id */
0289     __be32 peer_diagnosis;  /* diagnosis information */
0290 #if defined(__BIG_ENDIAN_BITFIELD)
0291     u8 os_type  : 4,
0292        reserved : 4;
0293 #elif defined(__LITTLE_ENDIAN_BITFIELD)
0294     u8 reserved : 4,
0295        os_type  : 4;
0296 #endif
0297     u8 reserved2[3];
0298     __be32 peer_diagnosis_v2[SMC_DECL_DIAG_COUNT_V2];
0299     struct smc_clc_msg_trail trl; /* eye catcher "SMCD" or "SMCR" EBCDIC */
0300 } __aligned(4);
0301 
0302 /* determine start of the prefix area within the proposal message */
0303 static inline struct smc_clc_msg_proposal_prefix *
0304 smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc)
0305 {
0306     return (struct smc_clc_msg_proposal_prefix *)
0307            ((u8 *)pclc + sizeof(*pclc) + ntohs(pclc->iparea_offset));
0308 }
0309 
0310 static inline bool smcr_indicated(int smc_type)
0311 {
0312     return smc_type == SMC_TYPE_R || smc_type == SMC_TYPE_B;
0313 }
0314 
0315 static inline bool smcd_indicated(int smc_type)
0316 {
0317     return smc_type == SMC_TYPE_D || smc_type == SMC_TYPE_B;
0318 }
0319 
0320 static inline u8 smc_indicated_type(int is_smcd, int is_smcr)
0321 {
0322     if (is_smcd && is_smcr)
0323         return SMC_TYPE_B;
0324     if (is_smcd)
0325         return SMC_TYPE_D;
0326     if (is_smcr)
0327         return SMC_TYPE_R;
0328     return SMC_TYPE_N;
0329 }
0330 
0331 /* get SMC-D info from proposal message */
0332 static inline struct smc_clc_msg_smcd *
0333 smc_get_clc_msg_smcd(struct smc_clc_msg_proposal *prop)
0334 {
0335     if (smcd_indicated(prop->hdr.typev1) &&
0336         ntohs(prop->iparea_offset) != sizeof(struct smc_clc_msg_smcd))
0337         return NULL;
0338 
0339     return (struct smc_clc_msg_smcd *)(prop + 1);
0340 }
0341 
0342 static inline struct smc_clc_v2_extension *
0343 smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)
0344 {
0345     struct smc_clc_msg_smcd *prop_smcd = smc_get_clc_msg_smcd(prop);
0346 
0347     if (!prop_smcd || !ntohs(prop_smcd->v2_ext_offset))
0348         return NULL;
0349 
0350     return (struct smc_clc_v2_extension *)
0351            ((u8 *)prop_smcd +
0352            offsetof(struct smc_clc_msg_smcd, v2_ext_offset) +
0353            sizeof(prop_smcd->v2_ext_offset) +
0354            ntohs(prop_smcd->v2_ext_offset));
0355 }
0356 
0357 static inline struct smc_clc_smcd_v2_extension *
0358 smc_get_clc_smcd_v2_ext(struct smc_clc_v2_extension *prop_v2ext)
0359 {
0360     if (!prop_v2ext)
0361         return NULL;
0362     if (!ntohs(prop_v2ext->hdr.smcd_v2_ext_offset))
0363         return NULL;
0364 
0365     return (struct smc_clc_smcd_v2_extension *)
0366         ((u8 *)prop_v2ext +
0367          offsetof(struct smc_clc_v2_extension, hdr) +
0368          offsetof(struct smc_clnt_opts_area_hdr, smcd_v2_ext_offset) +
0369          sizeof(prop_v2ext->hdr.smcd_v2_ext_offset) +
0370          ntohs(prop_v2ext->hdr.smcd_v2_ext_offset));
0371 }
0372 
0373 struct smcd_dev;
0374 struct smc_init_info;
0375 
0376 int smc_clc_prfx_match(struct socket *clcsock,
0377                struct smc_clc_msg_proposal_prefix *prop);
0378 int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen,
0379              u8 expected_type, unsigned long timeout);
0380 int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info, u8 version);
0381 int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini);
0382 int smc_clc_send_confirm(struct smc_sock *smc, bool clnt_first_contact,
0383              u8 version, u8 *eid, struct smc_init_info *ini);
0384 int smc_clc_send_accept(struct smc_sock *smc, bool srv_first_contact,
0385             u8 version, u8 *negotiated_eid);
0386 void smc_clc_init(void) __init;
0387 void smc_clc_exit(void);
0388 void smc_clc_get_hostname(u8 **host);
0389 bool smc_clc_match_eid(u8 *negotiated_eid,
0390                struct smc_clc_v2_extension *smc_v2_ext,
0391                u8 *peer_eid, u8 *local_eid);
0392 int smc_clc_ueid_count(void);
0393 int smc_nl_dump_ueid(struct sk_buff *skb, struct netlink_callback *cb);
0394 int smc_nl_add_ueid(struct sk_buff *skb, struct genl_info *info);
0395 int smc_nl_remove_ueid(struct sk_buff *skb, struct genl_info *info);
0396 int smc_nl_flush_ueid(struct sk_buff *skb, struct genl_info *info);
0397 int smc_nl_dump_seid(struct sk_buff *skb, struct netlink_callback *cb);
0398 int smc_nl_enable_seid(struct sk_buff *skb, struct genl_info *info);
0399 int smc_nl_disable_seid(struct sk_buff *skb, struct genl_info *info);
0400 
0401 #endif