xref: /linux/drivers/infiniband/core/cm_msgs.h (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /*
3  * Copyright (c) 2004, 2011 Intel Corporation.  All rights reserved.
4  * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
5  * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
6  * Copyright (c) 2019, Mellanox Technologies inc.  All rights reserved.
7  */
8 #ifndef CM_MSGS_H
9 #define CM_MSGS_H
10 
11 #include <rdma/ibta_vol1_c12.h>
12 #include <rdma/ib_mad.h>
13 #include <rdma/ib_cm.h>
14 
15 /*
16  * Parameters to routines below should be in network-byte order, and values
17  * are returned in network-byte order.
18  */
19 
20 #define IB_CM_CLASS_VERSION	2 /* IB specification 1.2 */
21 
cm_req_get_qp_type(struct cm_req_msg * req_msg)22 static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
23 {
24 	u8 transport_type = IBA_GET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg);
25 	switch (transport_type) {
26 	case 0: return IB_QPT_RC;
27 	case 1: return IB_QPT_UC;
28 	case 3:
29 		switch (IBA_GET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg)) {
30 		case 1: return IB_QPT_XRC_TGT;
31 		default: return 0;
32 		}
33 	default: return 0;
34 	}
35 }
36 
cm_req_set_qp_type(struct cm_req_msg * req_msg,enum ib_qp_type qp_type)37 static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
38 				      enum ib_qp_type qp_type)
39 {
40 	switch (qp_type) {
41 	case IB_QPT_UC:
42 		IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 1);
43 		break;
44 	case IB_QPT_XRC_INI:
45 		IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 3);
46 		IBA_SET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg, 1);
47 		break;
48 	default:
49 		IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 0);
50 	}
51 }
52 
53 /* Message REJected or MRAed */
54 enum cm_msg_response {
55 	CM_MSG_RESPONSE_REQ = 0x0,
56 	CM_MSG_RESPONSE_REP = 0x1,
57 	CM_MSG_RESPONSE_OTHER = 0x2
58 };
59 
cm_rep_get_qpn(struct cm_rep_msg * rep_msg,enum ib_qp_type qp_type)60 static inline __be32 cm_rep_get_qpn(struct cm_rep_msg *rep_msg, enum ib_qp_type qp_type)
61 {
62 	return (qp_type == IB_QPT_XRC_INI) ?
63 		       cpu_to_be32(IBA_GET(CM_REP_LOCAL_EE_CONTEXT_NUMBER,
64 					   rep_msg)) :
65 		       cpu_to_be32(IBA_GET(CM_REP_LOCAL_QPN, rep_msg));
66 }
67 
68 #endif /* CM_MSGS_H */
69