30 ComplQueue* send_cq,
int send_depth,
int max_send_sge,
31 ComplQueue* recv_cq,
int recv_depth,
int max_recv_sge) :
39 fNumSendSegs(max_send_sge)
41 if ((send_cq==0) || (recv_cq==0)) {
42 EOUT(
"No COMPLETION QUEUE WAS SPECIFIED");
46 struct ibv_qp_init_attr attr;
47 memset(&attr, 0,
sizeof(
struct ibv_qp_init_attr));
48 attr.send_cq = send_cq->
cq();
49 attr.recv_cq = recv_cq->
cq();
52 attr.cap.max_send_wr = send_depth;
53 attr.cap.max_send_sge = max_send_sge;
55 attr.cap.max_recv_wr = recv_depth;
56 attr.cap.max_recv_sge = max_recv_sge;
63 EOUT(
"Couldn't create queue pair (QP)");
67 struct ibv_qp_attr qp_attr;
68 qp_attr.qp_state = IBV_QPS_INIT;
69 qp_attr.pkey_index = 0;
75 res = ibv_modify_qp(
f_qp, &qp_attr, (ibv_qp_attr_mask)
83 qp_attr.qp_access_flags =
84 IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE |
85 IBV_ACCESS_REMOTE_READ;
86 res = ibv_modify_qp(
f_qp, &qp_attr, (ibv_qp_attr_mask)
90 IBV_QP_ACCESS_FLAGS));
94 EOUT(
"Failed to modify QP to INIT state");
101 DOUT4(
"Create QueuePair %p",
this);
106 DOUT4(
"Destroy QueuePair %p",
this);
108 ibv_destroy_qp(f_qp);
110 DOUT4(
"Destroy QueuePair %p done",
this);
115 struct ibv_qp_attr attr;
116 memset(&attr, 0,
sizeof attr);
118 attr.qp_state = IBV_QPS_RTR;
119 attr.path_mtu = fContext.mtu();
121 if (ibv_modify_qp(qp(), &attr, IBV_QP_STATE )) {
122 EOUT(
"Failed to modify UD QP to RTR");
126 attr.qp_state = IBV_QPS_RTS;
127 attr.sq_psn = local_psn();
128 if (ibv_modify_qp(qp(), &attr, (ibv_qp_attr_mask)
129 (IBV_QP_STATE | IBV_QP_SQ_PSN))) {
130 EOUT(
"Failed to modify UC/UD QP to RTS");
143 if (qp_type() == IBV_QPT_UD) {
144 EOUT(
"QueuePair::Connect not supported for unreliable datagram connection. Use InitUD() instead");
148 DOUT3(
"Start QP connect with %x:%x:%x", dest_lid, dest_qpn, dest_psn);
150 struct ibv_qp_attr attr;
151 memset(&attr, 0,
sizeof attr);
153 attr.qp_state = IBV_QPS_RTR;
154 attr.path_mtu = fContext.mtu();
170 attr.dest_qp_num = dest_qpn;
171 attr.rq_psn = dest_psn;
172 if (qp_type() == IBV_QPT_RC) {
173 attr.max_dest_rd_atomic = 1;
174 attr.min_rnr_timer = 12;
177 attr.ah_attr.is_global = 0;
178 attr.ah_attr.dlid = dest_lid;
182 attr.ah_attr.src_path_bits = src_path_bits;
183 attr.ah_attr.port_num = fContext.IbPort();
185 DOUT3(
"Modify to RTR");
187 if (qp_type() == IBV_QPT_RC) {
188 if (ibv_modify_qp(qp(), &attr, (ibv_qp_attr_mask)
194 IBV_QP_MIN_RNR_TIMER |
195 IBV_QP_MAX_DEST_RD_ATOMIC))) {
196 EOUT(
"Failed here to modify RC QP to RTR lid: %x, qpn: %x, psn:%x", dest_lid, dest_qpn, dest_psn);
201 if (qp_type() == IBV_QPT_UC) {
202 if (ibv_modify_qp(qp(), &attr, (ibv_qp_attr_mask)
208 EOUT(
"Failed to modify UC QP to RTR");
213 if (qp_type() == IBV_QPT_UD) {
214 if (ibv_modify_qp(qp(), &attr,
216 EOUT(
"Failed to modify UD QP to RTR");
221 DOUT3(
"Modify to RTS");
223 attr.qp_state = IBV_QPS_RTS;
224 attr.sq_psn = local_psn();
225 if (qp_type() == IBV_QPT_RC) {
229 attr.max_rd_atomic = 1;
230 if (ibv_modify_qp(qp(), &attr, (ibv_qp_attr_mask)
236 IBV_QP_MAX_QP_RD_ATOMIC))) {
237 EOUT(
"Failed to modify RC QP to RTS");
241 if (ibv_modify_qp(qp(), &attr, (ibv_qp_attr_mask)
244 EOUT(
"Failed to modify UC/UD QP to RTS");
249 f_remote_lid = dest_lid;
250 f_remote_qpn = dest_qpn;
251 f_remote_psn = dest_psn;
253 DOUT3(
"QP connected !!!");
263 struct ibv_send_wr* bad_swr = 0;
265 if (ibv_post_send(qp(), swr, &bad_swr)) {
266 EOUT(
"ibv_post_send fails arg %lx", bad_swr->wr_id);
275 struct ibv_recv_wr* bad_rwr = 0;
277 if (ibv_post_recv(qp(), rwr, &bad_rwr)) {
278 EOUT(
"ibv_post_recv fails arg = %lx", bad_rwr->wr_id);
287 return ibv_attach_mcast(qp(), mgid, mlid) == 0;
292 return ibv_detach_mcast(qp(), mgid, mlid) == 0;
#define VERBS_DEFAULT_QKEY
Wrapper for IB VERBS completion queue
struct ibv_cq * cq() const
Reference to verbs::Context
struct ibv_pd * pd() const
QueuePair(ContextRef ctx, ibv_qp_type qp_type, ComplQueue *send_cq, int send_depth, int max_send_sge, ComplQueue *recv_cq, int recv_depth, int max_recv_sge)
static uint32_t fQPCounter
bool InitUD()
Initialize QP for unreliable datagram protocol.
bool Post_Send(struct ibv_send_wr *swr)
bool Post_Recv(struct ibv_recv_wr *rwr)
ibv_qp_type qp_type() const
bool DetachMcast(ibv_gid *mgid, uint16_t mlid)
bool AttachMcast(ibv_gid *mgid, uint16_t mlid)
uint32_t f_local_psn
number used in connection
bool Connect(uint16_t lid, uint32_t qpn, uint32_t psn, uint8_t src_path_bits=0)
Connect QP to specified remote queue pair.