static inline uint64_t cpu_to_be64(uint64_t x) { return x; }
#endif
-/* cma requires 16 bit SID */
+/* cma requires 16 bit SID, in network order */
#define IB_PORT_MOD 32001
#define IB_PORT_BASE (65535 - IB_PORT_MOD)
-#define MAKE_PORT(SID) \
+#define SID_TO_PORT(SID) \
(SID > 0xffff ? \
- (unsigned short)((SID % IB_PORT_MOD) + IB_PORT_BASE) :\
- (unsigned short)SID)
+ htons((unsigned short)((SID % IB_PORT_MOD) + IB_PORT_BASE)) :\
+ htons((unsigned short)SID))
+
+#define PORT_TO_SID(p) ntohs(p)
static void dapli_addr_resolve(struct dapl_cm_id *conn)
{
dapl_os_lock(&conn->lock);
conn->destroy = 1;
- if (conn->ep)
+ if (conn->ep) {
conn->ep->cm_handle = IB_INVALID_HANDLE;
+ conn->ep->qp_handle = IB_INVALID_HANDLE;
+ }
cm_id = conn->cm_id;
conn->cm_id = NULL;
/* Get requesters connect data, setup for accept */
new_conn->params.responder_resources =
- DAPL_MIN(event->param.conn.initiator_depth,
+ DAPL_MIN(event->param.conn.responder_resources,
conn->hca->ib_trans.max_rdma_rd_in);
new_conn->params.initiator_depth =
- DAPL_MIN(event->param.conn.responder_resources,
+ DAPL_MIN(event->param.conn.initiator_depth,
conn->hca->ib_trans.max_rdma_rd_out);
new_conn->params.flow_control = event->param.conn.flow_control;
&conn->cm_id->route.addr.dst_addr)->sin_addr.s_addr));
/* setup local and remote ports for ep query */
- conn->ep->param.remote_port_qual = rdma_get_dst_port(conn->cm_id);
- conn->ep->param.local_port_qual = rdma_get_src_port(conn->cm_id);
+ conn->ep->param.remote_port_qual = PORT_TO_SID(rdma_get_dst_port(conn->cm_id));
+ conn->ep->param.local_port_qual = PORT_TO_SID(rdma_get_src_port(conn->cm_id));
dapl_evd_connection_callback(conn, IB_CME_CONNECTED,
event->param.conn.private_data, conn->ep);
if (NULL == ep_ptr)
return DAT_SUCCESS;
- dapl_dbg_log(DAPL_DBG_TYPE_CM, " connect: rSID %d, pdata %p, ln %d\n",
- r_qual,p_data,p_size);
+ dapl_dbg_log(DAPL_DBG_TYPE_CM,
+ " connect: rSID 0x%llx rPort %d, pdata %p, ln %d\n",
+ r_qual,ntohs(SID_TO_PORT(r_qual)),p_data,p_size);
/* rdma conn and cm_id pre-bound; reference via qp_handle */
conn = ep_ptr->cm_handle = ep_ptr->qp_handle;
dapl_os_memcpy(&conn->r_addr, r_addr, sizeof(*r_addr));
/* Resolve remote address, src already bound during QP create */
- ((struct sockaddr_in*)&conn->r_addr)->sin_port = htons(MAKE_PORT(r_qual));
+ ((struct sockaddr_in*)&conn->r_addr)->sin_port = SID_TO_PORT(r_qual);
((struct sockaddr_in*)&conn->r_addr)->sin_family = AF_INET;
if (rdma_resolve_addr(conn->cm_id, NULL,
" disconnect(ep %p, conn %p, id %d flags %x)\n",
ep_ptr,conn, (conn?conn->cm_id:0),close_flags);
- if (conn == IB_INVALID_HANDLE)
+ if ((conn == IB_INVALID_HANDLE) || (conn->cm_id == NULL))
return DAT_SUCCESS;
/* no graceful half-pipe disconnect option */
/* open identifies the local device; per DAT specification */
/* Get family and address then set port to consumer's ServiceID */
dapl_os_memcpy(&addr, &ia_ptr->hca_ptr->hca_address, sizeof(addr));
- ((struct sockaddr_in *)&addr)->sin_port = htons(MAKE_PORT(ServiceID));
-
+ ((struct sockaddr_in *)&addr)->sin_port = SID_TO_PORT(ServiceID);
if (rdma_bind_addr(conn->cm_id,(struct sockaddr *)&addr)) {
if (errno == EBUSY)
}
dapl_dbg_log(DAPL_DBG_TYPE_CM,
- " listen(ia_ptr %p SID %d sp %p conn %p id %d)\n",
- ia_ptr, MAKE_PORT(ServiceID),
+ " listen(ia_ptr %p SID 0x%llx Port %d sp %p conn %p id %d)\n",
+ ia_ptr, ServiceID, ntohs(SID_TO_PORT(ServiceID)),
sp_ptr, conn, conn->cm_id);
sp_ptr->cm_srvc_handle = conn;
}
cr_ptr->param.local_ep_handle = ep_handle;
- ep_ptr->qp_handle = cr_conn;
- ep_ptr->cm_handle = cr_conn;
- cr_conn->ep = ep_ptr;
cr_conn->params.private_data = p_data;
cr_conn->params.private_data_len = p_size;
goto bail;
}
+ /* save accepted conn and EP reference */
+ ep_ptr->qp_handle = cr_conn;
+ ep_ptr->cm_handle = cr_conn;
+ cr_conn->ep = ep_ptr;
+
/* setup local and remote ports for ep query */
- ep_ptr->param.remote_port_qual = rdma_get_dst_port(cr_conn->cm_id);
- ep_ptr->param.local_port_qual = rdma_get_src_port(cr_conn->cm_id);
+ /* Note: port qual in network order */
+ ep_ptr->param.remote_port_qual = PORT_TO_SID(rdma_get_dst_port(cr_conn->cm_id));
+ ep_ptr->param.local_port_qual = PORT_TO_SID(rdma_get_src_port(cr_conn->cm_id));
return DAT_SUCCESS;
bail: