124f52149SLeon Romanovsky /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2a977049dSHal Rosenstock /* 3ef700446SSean Hefty * Copyright (c) 2004, 2011 Intel Corporation. All rights reserved. 4a977049dSHal Rosenstock * Copyright (c) 2004 Topspin Corporation. All rights reserved. 5a977049dSHal Rosenstock * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 624f52149SLeon Romanovsky * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved. 7a977049dSHal Rosenstock */ 8a9160511SLeon Romanovsky #ifndef CM_MSGS_H 9a977049dSHal Rosenstock #define CM_MSGS_H 10a977049dSHal Rosenstock 11d05d4ac4SLeon Romanovsky #include <rdma/ibta_vol1_c12.h> 12a4d61e84SRoland Dreier #include <rdma/ib_mad.h> 135d861be8SSean Hefty #include <rdma/ib_cm.h> 14a977049dSHal Rosenstock 15a977049dSHal Rosenstock /* 16a977049dSHal Rosenstock * Parameters to routines below should be in network-byte order, and values 17a977049dSHal Rosenstock * are returned in network-byte order. 18a977049dSHal Rosenstock */ 19a977049dSHal Rosenstock 20a977049dSHal Rosenstock #define IB_CM_CLASS_VERSION 2 /* IB specification 1.2 */ 21a977049dSHal Rosenstock 22a977049dSHal Rosenstock struct cm_req_msg { 23a977049dSHal Rosenstock struct ib_mad_hdr hdr; 24a977049dSHal Rosenstock 2597f52eb4SSean Hefty __be32 local_comm_id; 2697f52eb4SSean Hefty __be32 rsvd4; 2797f52eb4SSean Hefty __be64 service_id; 2897f52eb4SSean Hefty __be64 local_ca_guid; 2997f52eb4SSean Hefty __be32 rsvd24; 3097f52eb4SSean Hefty __be32 local_qkey; 31a977049dSHal Rosenstock /* local QPN:24, responder resources:8 */ 3297f52eb4SSean Hefty __be32 offset32; 33a977049dSHal Rosenstock /* local EECN:24, initiator depth:8 */ 3497f52eb4SSean Hefty __be32 offset36; 35a977049dSHal Rosenstock /* 36a977049dSHal Rosenstock * remote EECN:24, remote CM response timeout:5, 37a977049dSHal Rosenstock * transport service type:2, end-to-end flow control:1 38a977049dSHal Rosenstock */ 3997f52eb4SSean Hefty __be32 offset40; 40a977049dSHal Rosenstock /* starting PSN:24, local CM response timeout:5, retry count:3 */ 4197f52eb4SSean Hefty __be32 offset44; 4297f52eb4SSean Hefty __be16 pkey; 43a977049dSHal Rosenstock /* path MTU:4, RDC exists:1, RNR retry count:3. */ 44a977049dSHal Rosenstock u8 offset50; 45d26a360bSSean Hefty /* max CM Retries:4, SRQ:1, extended transport type:3 */ 46a977049dSHal Rosenstock u8 offset51; 47a977049dSHal Rosenstock 4897f52eb4SSean Hefty __be16 primary_local_lid; 4997f52eb4SSean Hefty __be16 primary_remote_lid; 50a977049dSHal Rosenstock union ib_gid primary_local_gid; 51a977049dSHal Rosenstock union ib_gid primary_remote_gid; 52a977049dSHal Rosenstock /* flow label:20, rsvd:6, packet rate:6 */ 5397f52eb4SSean Hefty __be32 primary_offset88; 54a977049dSHal Rosenstock u8 primary_traffic_class; 55a977049dSHal Rosenstock u8 primary_hop_limit; 56a977049dSHal Rosenstock /* SL:4, subnet local:1, rsvd:3 */ 57a977049dSHal Rosenstock u8 primary_offset94; 58a977049dSHal Rosenstock /* local ACK timeout:5, rsvd:3 */ 59a977049dSHal Rosenstock u8 primary_offset95; 60a977049dSHal Rosenstock 6197f52eb4SSean Hefty __be16 alt_local_lid; 6297f52eb4SSean Hefty __be16 alt_remote_lid; 63a977049dSHal Rosenstock union ib_gid alt_local_gid; 64a977049dSHal Rosenstock union ib_gid alt_remote_gid; 65a977049dSHal Rosenstock /* flow label:20, rsvd:6, packet rate:6 */ 6697f52eb4SSean Hefty __be32 alt_offset132; 67a977049dSHal Rosenstock u8 alt_traffic_class; 68a977049dSHal Rosenstock u8 alt_hop_limit; 69a977049dSHal Rosenstock /* SL:4, subnet local:1, rsvd:3 */ 70a977049dSHal Rosenstock u8 alt_offset138; 71a977049dSHal Rosenstock /* local ACK timeout:5, rsvd:3 */ 72a977049dSHal Rosenstock u8 alt_offset139; 73a977049dSHal Rosenstock 740d0f738fSDavid Ahern u32 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE / sizeof(u32)]; 75a977049dSHal Rosenstock 7619b1a294SErez Alfasi } __packed; 77a977049dSHal Rosenstock 78a977049dSHal Rosenstock static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg) 79a977049dSHal Rosenstock { 80b6bbee68SJason Gunthorpe u8 transport_type = IBA_GET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg); 81a977049dSHal Rosenstock switch(transport_type) { 82a977049dSHal Rosenstock case 0: return IB_QPT_RC; 83a977049dSHal Rosenstock case 1: return IB_QPT_UC; 84d26a360bSSean Hefty case 3: 85b6bbee68SJason Gunthorpe switch (IBA_GET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg)) { 86d26a360bSSean Hefty case 1: return IB_QPT_XRC_TGT; 87d26a360bSSean Hefty default: return 0; 88d26a360bSSean Hefty } 89a977049dSHal Rosenstock default: return 0; 90a977049dSHal Rosenstock } 91a977049dSHal Rosenstock } 92a977049dSHal Rosenstock 93a977049dSHal Rosenstock static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg, 94a977049dSHal Rosenstock enum ib_qp_type qp_type) 95a977049dSHal Rosenstock { 96a977049dSHal Rosenstock switch(qp_type) { 97a977049dSHal Rosenstock case IB_QPT_UC: 98b6bbee68SJason Gunthorpe IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 1); 993910f44dSRoland Dreier break; 100d26a360bSSean Hefty case IB_QPT_XRC_INI: 101b6bbee68SJason Gunthorpe IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 3); 102b6bbee68SJason Gunthorpe IBA_SET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg, 1); 103d26a360bSSean Hefty break; 104a977049dSHal Rosenstock default: 105b6bbee68SJason Gunthorpe IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 0); 106a977049dSHal Rosenstock } 107a977049dSHal Rosenstock } 108a977049dSHal Rosenstock 109a977049dSHal Rosenstock /* Message REJected or MRAed */ 110a977049dSHal Rosenstock enum cm_msg_response { 111a977049dSHal Rosenstock CM_MSG_RESPONSE_REQ = 0x0, 112a977049dSHal Rosenstock CM_MSG_RESPONSE_REP = 0x1, 113a977049dSHal Rosenstock CM_MSG_RESPONSE_OTHER = 0x2 114a977049dSHal Rosenstock }; 115a977049dSHal Rosenstock 116a977049dSHal Rosenstock struct cm_mra_msg { 117a977049dSHal Rosenstock struct ib_mad_hdr hdr; 118a977049dSHal Rosenstock 11997f52eb4SSean Hefty __be32 local_comm_id; 12097f52eb4SSean Hefty __be32 remote_comm_id; 121a977049dSHal Rosenstock /* message MRAed:2, rsvd:6 */ 122a977049dSHal Rosenstock u8 offset8; 123a977049dSHal Rosenstock /* service timeout:5, rsvd:3 */ 124a977049dSHal Rosenstock u8 offset9; 125a977049dSHal Rosenstock 126a977049dSHal Rosenstock u8 private_data[IB_CM_MRA_PRIVATE_DATA_SIZE]; 127a977049dSHal Rosenstock 12819b1a294SErez Alfasi } __packed; 129a977049dSHal Rosenstock 130a977049dSHal Rosenstock struct cm_rej_msg { 131a977049dSHal Rosenstock struct ib_mad_hdr hdr; 132a977049dSHal Rosenstock 13397f52eb4SSean Hefty __be32 local_comm_id; 13497f52eb4SSean Hefty __be32 remote_comm_id; 135a977049dSHal Rosenstock /* message REJected:2, rsvd:6 */ 136a977049dSHal Rosenstock u8 offset8; 137a977049dSHal Rosenstock /* reject info length:7, rsvd:1. */ 138a977049dSHal Rosenstock u8 offset9; 13997f52eb4SSean Hefty __be16 reason; 140a977049dSHal Rosenstock u8 ari[IB_CM_REJ_ARI_LENGTH]; 141a977049dSHal Rosenstock 142a977049dSHal Rosenstock u8 private_data[IB_CM_REJ_PRIVATE_DATA_SIZE]; 143a977049dSHal Rosenstock 14419b1a294SErez Alfasi } __packed; 145a977049dSHal Rosenstock 146a977049dSHal Rosenstock struct cm_rep_msg { 147a977049dSHal Rosenstock struct ib_mad_hdr hdr; 148a977049dSHal Rosenstock 14997f52eb4SSean Hefty __be32 local_comm_id; 15097f52eb4SSean Hefty __be32 remote_comm_id; 15197f52eb4SSean Hefty __be32 local_qkey; 152a977049dSHal Rosenstock /* local QPN:24, rsvd:8 */ 15397f52eb4SSean Hefty __be32 offset12; 154a977049dSHal Rosenstock /* local EECN:24, rsvd:8 */ 15597f52eb4SSean Hefty __be32 offset16; 156a977049dSHal Rosenstock /* starting PSN:24 rsvd:8 */ 15797f52eb4SSean Hefty __be32 offset20; 158a977049dSHal Rosenstock u8 resp_resources; 159a977049dSHal Rosenstock u8 initiator_depth; 160a977049dSHal Rosenstock /* target ACK delay:5, failover accepted:2, end-to-end flow control:1 */ 161a977049dSHal Rosenstock u8 offset26; 162a977049dSHal Rosenstock /* RNR retry count:3, SRQ:1, rsvd:5 */ 163a977049dSHal Rosenstock u8 offset27; 16497f52eb4SSean Hefty __be64 local_ca_guid; 165a977049dSHal Rosenstock 166a977049dSHal Rosenstock u8 private_data[IB_CM_REP_PRIVATE_DATA_SIZE]; 167a977049dSHal Rosenstock 16819b1a294SErez Alfasi } __packed; 169a977049dSHal Rosenstock 170ef700446SSean Hefty static inline __be32 cm_rep_get_qpn(struct cm_rep_msg *rep_msg, enum ib_qp_type qp_type) 171ef700446SSean Hefty { 172ef700446SSean Hefty return (qp_type == IB_QPT_XRC_INI) ? 17301adb7f4SJason Gunthorpe cpu_to_be32(IBA_GET(CM_REP_LOCAL_EE_CONTEXT_NUMBER, 17401adb7f4SJason Gunthorpe rep_msg)) : 17501adb7f4SJason Gunthorpe cpu_to_be32(IBA_GET(CM_REP_LOCAL_QPN, rep_msg)); 176a977049dSHal Rosenstock } 177a977049dSHal Rosenstock 178a977049dSHal Rosenstock struct cm_rtu_msg { 179a977049dSHal Rosenstock struct ib_mad_hdr hdr; 180a977049dSHal Rosenstock 18197f52eb4SSean Hefty __be32 local_comm_id; 18297f52eb4SSean Hefty __be32 remote_comm_id; 183a977049dSHal Rosenstock 184a977049dSHal Rosenstock u8 private_data[IB_CM_RTU_PRIVATE_DATA_SIZE]; 185a977049dSHal Rosenstock 18619b1a294SErez Alfasi } __packed; 187a977049dSHal Rosenstock 188a977049dSHal Rosenstock struct cm_dreq_msg { 189a977049dSHal Rosenstock struct ib_mad_hdr hdr; 190a977049dSHal Rosenstock 19197f52eb4SSean Hefty __be32 local_comm_id; 19297f52eb4SSean Hefty __be32 remote_comm_id; 193a977049dSHal Rosenstock /* remote QPN/EECN:24, rsvd:8 */ 19497f52eb4SSean Hefty __be32 offset8; 195a977049dSHal Rosenstock 196a977049dSHal Rosenstock u8 private_data[IB_CM_DREQ_PRIVATE_DATA_SIZE]; 197a977049dSHal Rosenstock 19819b1a294SErez Alfasi } __packed; 199a977049dSHal Rosenstock 200a977049dSHal Rosenstock struct cm_drep_msg { 201a977049dSHal Rosenstock struct ib_mad_hdr hdr; 202a977049dSHal Rosenstock 20397f52eb4SSean Hefty __be32 local_comm_id; 20497f52eb4SSean Hefty __be32 remote_comm_id; 205a977049dSHal Rosenstock 206a977049dSHal Rosenstock u8 private_data[IB_CM_DREP_PRIVATE_DATA_SIZE]; 207a977049dSHal Rosenstock 20819b1a294SErez Alfasi } __packed; 209a977049dSHal Rosenstock 210a977049dSHal Rosenstock struct cm_lap_msg { 211a977049dSHal Rosenstock struct ib_mad_hdr hdr; 212a977049dSHal Rosenstock 21397f52eb4SSean Hefty __be32 local_comm_id; 21497f52eb4SSean Hefty __be32 remote_comm_id; 215a977049dSHal Rosenstock 21697f52eb4SSean Hefty __be32 rsvd8; 217a977049dSHal Rosenstock /* remote QPN/EECN:24, remote CM response timeout:5, rsvd:3 */ 21897f52eb4SSean Hefty __be32 offset12; 21997f52eb4SSean Hefty __be32 rsvd16; 220a977049dSHal Rosenstock 22197f52eb4SSean Hefty __be16 alt_local_lid; 22297f52eb4SSean Hefty __be16 alt_remote_lid; 223a977049dSHal Rosenstock union ib_gid alt_local_gid; 224a977049dSHal Rosenstock union ib_gid alt_remote_gid; 225a977049dSHal Rosenstock /* flow label:20, rsvd:4, traffic class:8 */ 22697f52eb4SSean Hefty __be32 offset56; 227a977049dSHal Rosenstock u8 alt_hop_limit; 228a977049dSHal Rosenstock /* rsvd:2, packet rate:6 */ 22997f52eb4SSean Hefty u8 offset61; 230a977049dSHal Rosenstock /* SL:4, subnet local:1, rsvd:3 */ 23197f52eb4SSean Hefty u8 offset62; 232a977049dSHal Rosenstock /* local ACK timeout:5, rsvd:3 */ 23397f52eb4SSean Hefty u8 offset63; 234a977049dSHal Rosenstock 235a977049dSHal Rosenstock u8 private_data[IB_CM_LAP_PRIVATE_DATA_SIZE]; 23619b1a294SErez Alfasi } __packed; 237a977049dSHal Rosenstock 238a977049dSHal Rosenstock struct cm_apr_msg { 239a977049dSHal Rosenstock struct ib_mad_hdr hdr; 240a977049dSHal Rosenstock 24197f52eb4SSean Hefty __be32 local_comm_id; 24297f52eb4SSean Hefty __be32 remote_comm_id; 243a977049dSHal Rosenstock 244a977049dSHal Rosenstock u8 info_length; 245a977049dSHal Rosenstock u8 ap_status; 2466f233d30SEli Cohen __be16 rsvd; 247a977049dSHal Rosenstock u8 info[IB_CM_APR_INFO_LENGTH]; 248a977049dSHal Rosenstock 249a977049dSHal Rosenstock u8 private_data[IB_CM_APR_PRIVATE_DATA_SIZE]; 25019b1a294SErez Alfasi } __packed; 251a977049dSHal Rosenstock 252a977049dSHal Rosenstock struct cm_sidr_req_msg { 253a977049dSHal Rosenstock struct ib_mad_hdr hdr; 254a977049dSHal Rosenstock 25597f52eb4SSean Hefty __be32 request_id; 25697f52eb4SSean Hefty __be16 pkey; 25797f52eb4SSean Hefty __be16 rsvd; 25897f52eb4SSean Hefty __be64 service_id; 259a977049dSHal Rosenstock 2600d0f738fSDavid Ahern u32 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE / sizeof(u32)]; 26119b1a294SErez Alfasi } __packed; 262a977049dSHal Rosenstock 263a977049dSHal Rosenstock struct cm_sidr_rep_msg { 264a977049dSHal Rosenstock struct ib_mad_hdr hdr; 265a977049dSHal Rosenstock 26697f52eb4SSean Hefty __be32 request_id; 267a977049dSHal Rosenstock u8 status; 268a977049dSHal Rosenstock u8 info_length; 26997f52eb4SSean Hefty __be16 rsvd; 270a977049dSHal Rosenstock /* QPN:24, rsvd:8 */ 27197f52eb4SSean Hefty __be32 offset8; 27297f52eb4SSean Hefty __be64 service_id; 27397f52eb4SSean Hefty __be32 qkey; 274a977049dSHal Rosenstock u8 info[IB_CM_SIDR_REP_INFO_LENGTH]; 275a977049dSHal Rosenstock 276a977049dSHal Rosenstock u8 private_data[IB_CM_SIDR_REP_PRIVATE_DATA_SIZE]; 27719b1a294SErez Alfasi } __packed; 278a977049dSHal Rosenstock 279a977049dSHal Rosenstock #endif /* CM_MSGS_H */ 280