0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
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
0028 #define SMC_TYPE_D 1
0029 #define SMC_TYPE_N 2
0030 #define SMC_TYPE_B 3
0031 #define CLC_WAIT_TIME (6 * HZ)
0032 #define CLC_WAIT_TIME_SHORT HZ
0033 #define SMC_CLC_DECL_MEM 0x01010000
0034 #define SMC_CLC_DECL_TIMEOUT_CL 0x02010000
0035 #define SMC_CLC_DECL_TIMEOUT_AL 0x02020000
0036 #define SMC_CLC_DECL_CNFERR 0x03000000
0037 #define SMC_CLC_DECL_PEERNOSMC 0x03010000
0038 #define SMC_CLC_DECL_IPSEC 0x03020000
0039 #define SMC_CLC_DECL_NOSMCDEV 0x03030000
0040 #define SMC_CLC_DECL_NOSMCDDEV 0x03030001
0041 #define SMC_CLC_DECL_NOSMCRDEV 0x03030002
0042 #define SMC_CLC_DECL_NOISM2SUPP 0x03030003
0043 #define SMC_CLC_DECL_NOV2EXT 0x03030004
0044 #define SMC_CLC_DECL_NOV2DEXT 0x03030005
0045 #define SMC_CLC_DECL_NOSEID 0x03030006
0046 #define SMC_CLC_DECL_NOSMCD2DEV 0x03030007
0047 #define SMC_CLC_DECL_NOUEID 0x03030008
0048 #define SMC_CLC_DECL_MODEUNSUPP 0x03040000
0049 #define SMC_CLC_DECL_RMBE_EC 0x03050000
0050 #define SMC_CLC_DECL_OPTUNSUPP 0x03060000
0051 #define SMC_CLC_DECL_DIFFPREFIX 0x03070000
0052 #define SMC_CLC_DECL_GETVLANERR 0x03080000
0053 #define SMC_CLC_DECL_ISMVLANERR 0x03090000
0054 #define SMC_CLC_DECL_NOACTLINK 0x030a0000
0055 #define SMC_CLC_DECL_NOSRVLINK 0x030b0000
0056 #define SMC_CLC_DECL_VERSMISMAT 0x030c0000
0057 #define SMC_CLC_DECL_MAX_DMB 0x030d0000
0058 #define SMC_CLC_DECL_NOROUTE 0x030e0000
0059 #define SMC_CLC_DECL_NOINDIRECT 0x030f0000
0060 #define SMC_CLC_DECL_SYNCERR 0x04000000
0061 #define SMC_CLC_DECL_PEERDECL 0x05000000
0062 #define SMC_CLC_DECL_INTERR 0x09990000
0063 #define SMC_CLC_DECL_ERR_RTOK 0x09990001
0064 #define SMC_CLC_DECL_ERR_RDYLNK 0x09990002
0065 #define SMC_CLC_DECL_ERR_REGBUF 0x09990003
0066
0067 #define SMC_FIRST_CONTACT_MASK 0b10
0068
0069 struct smc_clc_msg_hdr {
0070 u8 eyecatcher[4];
0071 u8 type;
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;
0083
0084 struct smc_clc_msg_trail {
0085 u8 eyecatcher[4];
0086 };
0087
0088 struct smc_clc_msg_local {
0089 u8 id_for_peer[SMC_SYSTEMID_LEN];
0090 u8 gid[16];
0091 u8 mac[6];
0092 };
0093
0094
0095
0096
0097 struct smc_clc_ipv6_prefix {
0098 struct in6_addr prefix;
0099 u8 prefix_len;
0100 } __packed;
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;
0118 u8 ism_gid_cnt;
0119 u8 reserved1;
0120 struct smc_clc_v2_flag flag;
0121 u8 reserved2[2];
0122 __be16 smcd_v2_ext_offset;
0123 };
0124
0125 struct smc_clc_smcd_gid_chid {
0126 __be64 gid;
0127 __be16 chid;
0128 } __packed;
0129
0130
0131
0132
0133 struct smc_clc_v2_extension {
0134 struct smc_clnt_opts_area_hdr hdr;
0135 u8 roce[16];
0136 u8 reserved[16];
0137 u8 user_eids[][SMC_MAX_EID_LEN];
0138 };
0139
0140 struct smc_clc_msg_proposal_prefix {
0141 __be32 outgoing_subnet;
0142 u8 prefix_len;
0143 u8 reserved[2];
0144 u8 ipv6_prefixes_cnt;
0145 } __aligned(4);
0146
0147 struct smc_clc_msg_smcd {
0148 struct smc_clc_smcd_gid_chid ism;
0149 __be16 v2_ext_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 {
0160 struct smc_clc_msg_hdr hdr;
0161 struct smc_clc_msg_local lcl;
0162 __be16 iparea_offset;
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 {
0181 struct smc_clc_msg_local lcl;
0182 u8 qpn[3];
0183 __be32 rmb_rkey;
0184 u8 rmbe_idx;
0185 __be32 rmbe_alert_token;
0186 #if defined(__BIG_ENDIAN_BITFIELD)
0187 u8 rmbe_size : 4,
0188 qp_mtu : 4;
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;
0195 u8 reserved2;
0196 u8 psn[3];
0197 } __packed;
0198
0199 struct smcd_clc_msg_accept_confirm_common {
0200 u64 gid;
0201 u64 token;
0202 u8 dmbe_idx;
0203 #if defined(__BIG_ENDIAN_BITFIELD)
0204 u8 dmbe_size : 4,
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;
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 {
0242 struct smc_clc_msg_hdr hdr;
0243 union {
0244 struct smcr_clc_msg_accept_confirm r0;
0245 struct {
0246 struct smcd_clc_msg_accept_confirm_common d0;
0247 u32 reserved5[3];
0248 };
0249 };
0250 } __packed;
0251
0252 struct smc_clc_msg_accept_confirm_v2 {
0253 struct smc_clc_msg_hdr hdr;
0254 union {
0255 struct {
0256 struct smcr_clc_msg_accept_confirm r0;
0257 u8 eid[SMC_MAX_EID_LEN];
0258 u8 reserved6[8];
0259 } r1;
0260 struct {
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 {
0270 struct smc_clc_msg_hdr hdr;
0271 u8 id_for_peer[SMC_SYSTEMID_LEN];
0272 __be32 peer_diagnosis;
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;
0282 } __aligned(4);
0283
0284 #define SMC_DECL_DIAG_COUNT_V2 4
0285
0286 struct smc_clc_msg_decline_v2 {
0287 struct smc_clc_msg_hdr hdr;
0288 u8 id_for_peer[SMC_SYSTEMID_LEN];
0289 __be32 peer_diagnosis;
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;
0300 } __aligned(4);
0301
0302
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
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