[openib-general] [PATCH] [CM] convert CM to use MAD send helper routines

Sean Hefty sean.hefty at intel.com
Thu May 12 12:10:01 PDT 2005


Converts the CM to make use of the newer MAD send helper data structure
and helper routines.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>


Index: cm.c
===================================================================
--- cm.c	(revision 2320)
+++ cm.c	(working copy)
@@ -86,15 +86,6 @@ struct cm_device {
 	struct cm_port port[0];
 };
 
-struct cm_msg {
-	struct cm_id_private *cm_id_priv;
-	struct ib_send_wr send_wr;
-	struct ib_sge sge;
-	enum ib_cm_state sent_state;
-	DECLARE_PCI_UNMAP_ADDR(mapping)
-	struct ib_mad mad;
-};
-
 struct cm_av {
 	struct cm_port *port;
 	union ib_gid dgid;
@@ -132,7 +123,7 @@ struct cm_id_private {
 	wait_queue_head_t wait;
 	atomic_t refcount;
 
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct cm_timewait_info *timewait_info;
 	/* todo: use alternate port on send failure */
 	struct cm_av av;
@@ -165,61 +156,40 @@ static inline void cm_deref_id(struct cm
 }
 
 static int cm_alloc_msg(struct cm_id_private *cm_id_priv,
-			struct cm_msg **msg)
+			struct ib_mad_send_buf **msg)
 {
 	struct ib_mad_agent *mad_agent;
-	struct cm_msg *m;
-	int ret;
-
-	m = kmalloc(sizeof *m, GFP_ATOMIC);
-	if (!m)
-		return -ENOMEM;
-	memset(m, 0, sizeof *m);
+	struct ib_mad_send_buf *m;
+	struct ib_ah *ah;
 
 	mad_agent = cm_id_priv->av.port->mad_agent;
-	m->send_wr.wr.ud.ah = ib_create_ah(mad_agent->qp->pd,
-					   &cm_id_priv->av.ah_attr);
-	if (IS_ERR(m->send_wr.wr.ud.ah)) {
-		ret = PTR_ERR(m->send_wr.wr.ud.ah);
-		kfree(m);
-		return ret;
+	ah = ib_create_ah(mad_agent->qp->pd, &cm_id_priv->av.ah_attr);
+	if (IS_ERR(ah))
+		return PTR_ERR(ah);
+
+	m = ib_create_send_mad(mad_agent, 1, cm_id_priv->av.pkey_index,
+			       ah, 0, sizeof(struct ib_mad_hdr),
+			       sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr),
+			       GFP_ATOMIC);
+	if (IS_ERR(m)) {
+		ib_destroy_ah(ah);
+		return PTR_ERR(m);
 	}
 
-	m->sge.addr = dma_map_single(mad_agent->device->dma_device,
-				     &m->mad, sizeof m->mad,
-				     DMA_TO_DEVICE);
-	pci_unmap_addr_set(m, mapping, m->sge.addr);
-	m->sge.length = sizeof m->mad;
-	m->sge.lkey = cm_id_priv->av.port->mad_agent->mr->lkey;
-
-	m->send_wr.wr_id = (unsigned long) m;
-	m->send_wr.sg_list = &m->sge;
-	m->send_wr.num_sge = 1;
-	m->send_wr.opcode = IB_WR_SEND;
-	m->send_wr.send_flags = IB_SEND_SIGNALED;
-	m->send_wr.wr.ud.mad_hdr = &m->mad.mad_hdr;
-	m->send_wr.wr.ud.remote_qpn = 1;
-	m->send_wr.wr.ud.remote_qkey = IB_QP1_QKEY;
 	/* Timeout set by caller if response is expected. */
 	m->send_wr.wr.ud.retries = cm_id_priv->max_cm_retries;
-	m->send_wr.wr.ud.pkey_index = cm_id_priv->av.pkey_index;
 
 	atomic_inc(&cm_id_priv->refcount);
-	m->cm_id_priv = cm_id_priv;
+	m->context[0] = cm_id_priv;
 	*msg = m;
 	return 0;
 }
 
-static void cm_free_msg(struct cm_msg *msg)
+static void cm_free_msg(struct ib_mad_send_buf *msg)
 {
-	struct ib_device *device;
-
 	ib_destroy_ah(msg->send_wr.wr.ud.ah);
-	device = msg->cm_id_priv->av.port->mad_agent->device;
-	dma_unmap_single(device->dma_device, pci_unmap_addr(msg, mapping),
-			 sizeof msg->mad, DMA_TO_DEVICE);
-	cm_deref_id(msg->cm_id_priv);
-	kfree(msg);
+	cm_deref_id(msg->context[0]);
+	ib_free_send_mad(msg);
 }
 
 static void cm_set_ah_attr(struct ib_ah_attr *ah_attr, u8 port_num,
@@ -852,10 +822,10 @@ int ib_send_cm_req(struct ib_cm_id *cm_i
 	if (ret)
 		goto out;
 
-	req_msg = (struct cm_req_msg *)&cm_id_priv->msg->mad;
+	req_msg = (struct cm_req_msg *) cm_id_priv->msg->mad;
 	cm_format_req(req_msg, cm_id_priv, param);
 	cm_id_priv->msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
-	cm_id_priv->msg->sent_state = IB_CM_REQ_SENT;
+	cm_id_priv->msg->context[1] = (void *) (unsigned long) IB_CM_REQ_SENT;
 
 	cm_id_priv->local_qpn = cm_req_get_local_qpn(req_msg);
 	cm_id_priv->rq_psn = cm_req_get_starting_psn(req_msg);
@@ -1126,7 +1096,7 @@ int ib_send_cm_rep(struct ib_cm_id *cm_i
 		   struct ib_cm_rep_param *param)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct cm_rep_msg *rep_msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
@@ -1143,10 +1113,10 @@ int ib_send_cm_rep(struct ib_cm_id *cm_i
 	if (ret)
 		goto out;
 
-	rep_msg = (struct cm_rep_msg *)&msg->mad;
+	rep_msg = (struct cm_rep_msg *) msg->mad;
 	cm_format_rep(rep_msg, cm_id_priv, param);
 	msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
-	msg->sent_state = IB_CM_REP_SENT;
+	msg->context[1] = (void *) (unsigned long) IB_CM_REP_SENT;
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
 	if (cm_id->state == IB_CM_REQ_RCVD ||
@@ -1191,7 +1161,7 @@ static void cm_format_rtu(struct cm_rtu_
 
 static void cm_resend_rtu(struct cm_id_private *cm_id_priv)
 {
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	int ret;
 
@@ -1199,7 +1169,7 @@ static void cm_resend_rtu(struct cm_id_p
 	if (ret)
 		return;
 
-	cm_format_rtu((struct cm_rtu_msg *)&msg->mad, cm_id_priv, NULL, 0);
+	cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv, NULL, 0);
 	ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
 			       &msg->send_wr, &bad_send_wr);
 	if (ret)
@@ -1211,7 +1181,7 @@ int ib_send_cm_rtu(struct ib_cm_id *cm_i
 		   u8 private_data_len)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int ret;
@@ -1224,7 +1194,7 @@ int ib_send_cm_rtu(struct ib_cm_id *cm_i
 	if (ret)
 		goto out;
 
-	cm_format_rtu((struct cm_rtu_msg *)&msg->mad, cm_id_priv,
+	cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv,
 		      private_data, private_data_len);
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
@@ -1467,7 +1437,7 @@ int ib_send_cm_dreq(struct ib_cm_id *cm_
 		    u8 private_data_len)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int msg_ret, ret;
@@ -1478,10 +1448,10 @@ int ib_send_cm_dreq(struct ib_cm_id *cm_
 	cm_id_priv = container_of(cm_id, struct cm_id_private, id);
 	msg_ret = cm_alloc_msg(cm_id_priv, &msg);
 	if (!msg_ret) {
-		cm_format_dreq((struct cm_dreq_msg *)&msg->mad, cm_id_priv,
+		cm_format_dreq((struct cm_dreq_msg *) msg->mad, cm_id_priv,
 			       private_data, private_data_len);
 		msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
-		msg->sent_state = IB_CM_DREQ_SENT;
+		msg->context[1] = (void *) (unsigned long) IB_CM_DREQ_SENT;
 	}
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
@@ -1523,7 +1493,7 @@ static void cm_format_drep(struct cm_dre
 
 static void cm_resend_drep(struct cm_id_private *cm_id_priv)
 {
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	int ret;
 
@@ -1531,7 +1501,7 @@ static void cm_resend_drep(struct cm_id_
 	if (ret)
 		return;
 
-	cm_format_drep((struct cm_drep_msg *)&msg->mad, cm_id_priv, NULL, 0);
+	cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv, NULL, 0);
 	ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
 			       &msg->send_wr, &bad_send_wr);
 	if (ret)
@@ -1543,7 +1513,7 @@ int ib_send_cm_drep(struct ib_cm_id *cm_
 		    u8 private_data_len)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int msg_ret, ret;
@@ -1554,7 +1524,7 @@ int ib_send_cm_drep(struct ib_cm_id *cm_
 	cm_id_priv = container_of(cm_id, struct cm_id_private, id);
 	msg_ret = cm_alloc_msg(cm_id_priv, &msg);
 	if (!msg_ret)
-		cm_format_drep((struct cm_drep_msg *)&msg->mad, cm_id_priv,
+		cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv,
 			       private_data, private_data_len);
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
@@ -1711,7 +1681,7 @@ int ib_send_cm_rej(struct ib_cm_id *cm_i
 		   u8 private_data_len)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int msg_ret, ret;
@@ -1723,7 +1693,7 @@ int ib_send_cm_rej(struct ib_cm_id *cm_i
 	cm_id_priv = container_of(cm_id, struct cm_id_private, id);
 	msg_ret = cm_alloc_msg(cm_id_priv, &msg);
 	if (!msg_ret)
-		cm_format_rej((struct cm_rej_msg *) &msg->mad, cm_id_priv,
+		cm_format_rej((struct cm_rej_msg *) msg->mad, cm_id_priv,
 			      reason, ari, ari_length, private_data,
 			      private_data_len);
 
@@ -1910,7 +1880,7 @@ int ib_send_cm_mra(struct ib_cm_id *cm_i
 		   u8 private_data_len)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int ret;
@@ -1923,7 +1893,7 @@ int ib_send_cm_mra(struct ib_cm_id *cm_i
 	if (ret)
 		goto out;
 
-	cm_format_mra((struct cm_mra_msg *)&msg->mad, cm_id_priv,
+	cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
 		      service_timeout, private_data, private_data_len);
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
@@ -2008,7 +1978,7 @@ int ib_send_cm_lap(struct ib_cm_id *cm_i
 		   u8 private_data_len)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int ret;
@@ -2021,10 +1991,10 @@ int ib_send_cm_lap(struct ib_cm_id *cm_i
 	if (ret)
 		goto out;
 
-	cm_format_lap((struct cm_lap_msg *)&msg->mad, cm_id_priv,
+	cm_format_lap((struct cm_lap_msg *) msg->mad, cm_id_priv,
 		      alternate_path, private_data, private_data_len);
 	msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
-	msg->sent_state = IB_CM_ESTABLISHED;
+	msg->context[1] = (void *) (unsigned long) IB_CM_ESTABLISHED;
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
 	if (cm_id->state == IB_CM_ESTABLISHED &&
@@ -2144,7 +2114,7 @@ int ib_send_cm_apr(struct ib_cm_id *cm_i
 		   u8 private_data_len)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int ret;
@@ -2158,7 +2128,7 @@ int ib_send_cm_apr(struct ib_cm_id *cm_i
 	if (ret)
 		goto out;
 
-	cm_format_apr((struct cm_apr_msg *)&msg->mad, cm_id_priv, status,
+	cm_format_apr((struct cm_apr_msg *) msg->mad, cm_id_priv, status,
 		      info, info_length, private_data, private_data_len);
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
@@ -2284,7 +2254,7 @@ int ib_send_cm_sidr_req(struct ib_cm_id 
 			struct ib_cm_sidr_req_param *param)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int ret;
@@ -2306,10 +2276,10 @@ int ib_send_cm_sidr_req(struct ib_cm_id 
 	if (ret)
 		goto out;
 
-	cm_format_sidr_req((struct cm_sidr_req_msg *)&msg->mad, cm_id_priv,
+	cm_format_sidr_req((struct cm_sidr_req_msg *) msg->mad, cm_id_priv,
 			   param);
 	msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
-	msg->sent_state = IB_CM_SIDR_REQ_SENT;
+	msg->context[1] = (void *) (unsigned long) IB_CM_SIDR_REQ_SENT;
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
 	if (cm_id->state == IB_CM_IDLE)
@@ -2427,7 +2397,7 @@ int ib_send_cm_sidr_rep(struct ib_cm_id 
 			struct ib_cm_sidr_rep_param *param)
 {
 	struct cm_id_private *cm_id_priv;
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 	struct ib_send_wr *bad_send_wr;
 	unsigned long flags;
 	int ret;
@@ -2442,7 +2412,7 @@ int ib_send_cm_sidr_rep(struct ib_cm_id 
 	if (ret)
 		goto out;
 
-	cm_format_sidr_rep((struct cm_sidr_rep_msg *)&msg->mad, cm_id_priv,
+	cm_format_sidr_rep((struct cm_sidr_rep_msg *) msg->mad, cm_id_priv,
 			   param);
 
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
@@ -2514,23 +2484,25 @@ out:
 	return -EINVAL;
 }
 
-static void cm_process_send_error(struct cm_msg *msg,
+static void cm_process_send_error(struct ib_mad_send_buf *msg,
 				  enum ib_wc_status wc_status)
 {
 	struct cm_id_private *cm_id_priv;
 	struct ib_cm_event cm_event;
+	enum ib_cm_state state;
 	unsigned long flags;
 	int ret;
 
 	memset(&cm_event, 0, sizeof cm_event);
-	cm_id_priv = msg->cm_id_priv;
+	cm_id_priv = msg->context[0];
+	state = (enum ib_cm_state) (unsigned long) msg->context[1];
 
 	/* Discard old sends or ones without a response. */
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
-	if (msg != cm_id_priv->msg || msg->sent_state != cm_id_priv->id.state)
+	if (msg != cm_id_priv->msg || state != cm_id_priv->id.state)
 		goto discard;
 
-	switch (cm_id_priv->id.state) {
+	switch (state) {
 	case IB_CM_REQ_SENT:
 		cm_reset_to_idle(cm_id_priv);
 		cm_event.event = IB_CM_REQ_ERROR;
@@ -2567,9 +2539,9 @@ discard:
 static void cm_send_handler(struct ib_mad_agent *mad_agent,
 			    struct ib_mad_send_wc *mad_send_wc)
 {
-	struct cm_msg *msg;
+	struct ib_mad_send_buf *msg;
 
-	msg = (struct cm_msg *)(unsigned long)mad_send_wc->wr_id;
+	msg = (struct ib_mad_send_buf *)(unsigned long)mad_send_wc->wr_id;
 
 	switch (mad_send_wc->status) {
 	case IB_WC_SUCCESS:






More information about the general mailing list