[openib-general] [PATCH] [RFC] new CM API to format QP attributes

Sean Hefty mshefty at ichips.intel.com
Tue Jan 25 11:11:19 PST 2005


Here's a new API to the CM to format QP attributes required to transition
a QP to a specified state.  Only a transition to the INIT state is coded
currently.  I'll add in the other transitions shortly.

- Sean

Index: include/ib_cm.h
===================================================================
--- include/ib_cm.h	(revision 1636)
+++ include/ib_cm.h	(working copy)
@@ -473,6 +473,26 @@
 		   u8 private_data_len);
 
 /**
+ * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
+ *   to a specified QP state.
+ * @cm_id: Communication identifier associated with the QP attributes to
+ *   initialize.
+ * @qp_attr: On input, specifies the desired QP state.  On output, the
+ *   mandatory and desired optional attributes will be set in order to
+ *   modify the QP to the specified state.
+ * @qp_attr_mask: The QP attribute mask that may be used to transition the
+ *   QP to the specified state.
+ *
+ * Users must set the @qp_attr->qp_state to the desired QP state.  This call
+ * will set all required attributes for the given transition, along with
+ * known optional attributes.  Users may override the attributes returned from
+ * this call before calling ib_modify_qp.
+ */
+int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
+		       struct ib_qp_attr *qp_attr,
+		       int *qp_attr_mask);
+
+/**
  * ib_send_cm_apr - Sends an alternate path response message in response to
  *   a load alternate path request.
  * @cm_id: Connection identifier associated with the alternate path response.
Index: core/cm.c
===================================================================
--- core/cm.c	(revision 1637)
+++ core/cm.c	(working copy)
@@ -111,6 +111,8 @@
 	u8 max_cm_retries;
 	u8 passive;
 	u8 peer_to_peer;
+	u8 responder_resources;
+	u8 initiator_depth;
 
 	struct list_head work_list;
 	atomic_t work_count;
@@ -779,6 +781,7 @@
 				    param->remote_cm_response_timeout);
 	cm_id_priv->max_cm_retries = param->max_cm_retries;
 	cm_id_priv->local_qpn = cpu_to_be32(param->qp->qp_num);
+	cm_id_priv->initiator_depth = param->initiator_depth;
 	path = param->primary_path;
 	cm_set_ah_attr(&cm_id_priv->ah_attr, cm_id_priv->port->port_num,
 		       path->dlid, path->sl, path->slid & 0x7F);
@@ -2464,6 +2467,80 @@
 	queue_work(cm.wq, &work->work);
 }
 
+static int cm_init_qp_init_attr(struct cm_id_private *cm_id_priv,
+				struct ib_qp_attr *qp_attr,
+				int *qp_attr_mask)
+{
+	unsigned long flags;
+	int ret;
+
+	spin_lock_irqsave(&cm_id_priv->lock, flags);
+	switch (cm_id_priv->id.state) {
+	case IB_CM_REQ_SENT:
+	case IB_CM_MRA_REQ_RCVD:
+	case IB_CM_REQ_RCVD:
+	case IB_CM_MRA_REQ_SENT:
+	case IB_CM_REP_RCVD:
+	case IB_CM_MRA_REP_SENT:
+	case IB_CM_REP_SENT:
+	case IB_CM_MRA_REP_RCVD:
+		qp_attr->pkey_index = cm_id_priv->pkey_index;
+		qp_attr->port_num = cm_id_priv->port->port_num;
+		*qp_attr_mask = IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT;
+		if (cm_id_priv->initiator_depth) {
+			qp_attr->max_rd_atomic = cm_id_priv->initiator_depth;
+			*qp_attr_mask |= IB_QP_MAX_QP_RD_ATOMIC;
+		}
+		ret = 0;
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+	spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+	return ret;
+}
+
+static int cm_init_qp_rtr_attr(struct cm_id_private *cm_id_priv,
+			       struct ib_qp_attr *qp_attr,
+			       int *qp_attr_mask)
+{
+	return -EINVAL;
+}
+
+static int cm_init_qp_rts_attr(struct cm_id_private *cm_id_priv,
+			       struct ib_qp_attr *qp_attr,
+			       int *qp_attr_mask)
+{
+	return -EINVAL;
+}
+
+int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
+		       struct ib_qp_attr *qp_attr,
+		       int *qp_attr_mask)
+{
+	struct cm_id_private *cm_id_priv;
+	int ret;
+
+	cm_id_priv = container_of(cm_id, struct cm_id_private, id);
+	switch (qp_attr->qp_state) {
+	case IB_QPS_INIT:
+		ret = cm_init_qp_init_attr(cm_id_priv, qp_attr, qp_attr_mask);
+		break;
+	case IB_QPS_RTR:
+		ret = cm_init_qp_rtr_attr(cm_id_priv, qp_attr, qp_attr_mask);
+		break;
+	case IB_QPS_RTS:
+		ret = cm_init_qp_rts_attr(cm_id_priv, qp_attr, qp_attr_mask);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+	return ret;
+}
+EXPORT_SYMBOL(ib_cm_init_qp_attr);
+
 static u64 cm_get_ca_guid(struct ib_device *device)
 {
 	struct ib_device_attr *device_attr;



More information about the general mailing list