blob: 8462de7ca26ebadcbdeae43a9b1be517bfb00763 [file] [log] [blame]
Leon Romanovsky24f52142019-10-20 10:15:56 +03001/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
Hal Rosenstocka9770492005-07-27 11:45:40 -07002/*
Sean Heftyef700442011-08-02 11:08:22 -07003 * Copyright (c) 2004, 2011 Intel Corporation. All rights reserved.
Hal Rosenstocka9770492005-07-27 11:45:40 -07004 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
5 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
Leon Romanovsky24f52142019-10-20 10:15:56 +03006 * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
Hal Rosenstocka9770492005-07-27 11:45:40 -07007 */
Leon Romanovskya9160512019-10-20 10:15:55 +03008#ifndef CM_MSGS_H
Hal Rosenstocka9770492005-07-27 11:45:40 -07009#define CM_MSGS_H
10
Leon Romanovskyd05d4ac2020-01-16 13:00:32 -040011#include <rdma/ibta_vol1_c12.h>
Roland Dreiera4d61e82005-08-25 13:40:04 -070012#include <rdma/ib_mad.h>
Sean Hefty5d861be2007-06-28 19:16:51 -070013#include <rdma/ib_cm.h>
Hal Rosenstocka9770492005-07-27 11:45:40 -070014
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
Hal Rosenstocka9770492005-07-27 11:45:40 -070022static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
23{
Jason Gunthorpeb6bbee62020-01-16 13:00:33 -040024 u8 transport_type = IBA_GET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg);
Wenpeng Liang9516b8f2021-04-07 16:15:49 +080025 switch (transport_type) {
Hal Rosenstocka9770492005-07-27 11:45:40 -070026 case 0: return IB_QPT_RC;
27 case 1: return IB_QPT_UC;
Sean Heftyd26a3602011-05-13 10:46:20 -070028 case 3:
Jason Gunthorpeb6bbee62020-01-16 13:00:33 -040029 switch (IBA_GET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg)) {
Sean Heftyd26a3602011-05-13 10:46:20 -070030 case 1: return IB_QPT_XRC_TGT;
31 default: return 0;
32 }
Hal Rosenstocka9770492005-07-27 11:45:40 -070033 default: return 0;
34 }
35}
36
37static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
38 enum ib_qp_type qp_type)
39{
Wenpeng Liang9516b8f2021-04-07 16:15:49 +080040 switch (qp_type) {
Hal Rosenstocka9770492005-07-27 11:45:40 -070041 case IB_QPT_UC:
Jason Gunthorpeb6bbee62020-01-16 13:00:33 -040042 IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 1);
Roland Dreier3910f442005-10-20 12:29:36 -070043 break;
Sean Heftyd26a3602011-05-13 10:46:20 -070044 case IB_QPT_XRC_INI:
Jason Gunthorpeb6bbee62020-01-16 13:00:33 -040045 IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 3);
46 IBA_SET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg, 1);
Sean Heftyd26a3602011-05-13 10:46:20 -070047 break;
Hal Rosenstocka9770492005-07-27 11:45:40 -070048 default:
Jason Gunthorpeb6bbee62020-01-16 13:00:33 -040049 IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 0);
Hal Rosenstocka9770492005-07-27 11:45:40 -070050 }
51}
52
Hal Rosenstocka9770492005-07-27 11:45:40 -070053/* Message REJected or MRAed */
54enum cm_msg_response {
55 CM_MSG_RESPONSE_REQ = 0x0,
56 CM_MSG_RESPONSE_REP = 0x1,
57 CM_MSG_RESPONSE_OTHER = 0x2
58};
59
Sean Heftyef700442011-08-02 11:08:22 -070060static 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) ?
Jason Gunthorpe01adb7f2020-01-16 13:00:34 -040063 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));
Hal Rosenstocka9770492005-07-27 11:45:40 -070066}
67
Hal Rosenstocka9770492005-07-27 11:45:40 -070068#endif /* CM_MSGS_H */