netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sean.hefty@intel.com
To: roland@purestorage.com, linux-rdma@vger.kernel.org,
	netdev@vger.kernel.org
Cc: Sean Hefty <sean.hefty@intel.com>
Subject: [PATCH v5 17/28] rdma/cm: Set qkey for AF_IB
Date: Wed, 29 May 2013 10:09:23 -0700	[thread overview]
Message-ID: <1369847374-12176-18-git-send-email-sean.hefty@intel.com> (raw)
In-Reply-To: <1369847374-12176-1-git-send-email-sean.hefty@intel.com>

From: Sean Hefty <sean.hefty@intel.com>

Allow the user to specify the qkey when using AF_IB.  The
qkey is added to struct rdma_ucm_conn_param in place of a reserved
field, but for backwards compatability, is only accessed if the
associated rdma_cm_id is using AF_IB.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
---
 drivers/infiniband/core/cma.c    |   35 +++++++++++++++++++++--------------
 drivers/infiniband/core/ucma.c   |    8 +++++---
 include/rdma/rdma_cm.h           |    1 +
 include/uapi/rdma/rdma_user_cm.h |    2 +-
 4 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index a807b18..6ea5ce7 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -293,16 +293,25 @@ static inline unsigned short cma_family(struct rdma_id_private *id_priv)
 	return id_priv->id.route.addr.src_addr.ss_family;
 }
 
-static int cma_set_qkey(struct rdma_id_private *id_priv)
+static int cma_set_qkey(struct rdma_id_private *id_priv, u32 qkey)
 {
 	struct ib_sa_mcmember_rec rec;
 	int ret = 0;
 
-	if (id_priv->qkey)
+	if (id_priv->qkey) {
+		if (qkey && id_priv->qkey != qkey)
+			return -EINVAL;
 		return 0;
+	}
+
+	if (qkey) {
+		id_priv->qkey = qkey;
+		return 0;
+	}
 
 	switch (id_priv->id.ps) {
 	case RDMA_PS_UDP:
+	case RDMA_PS_IB:
 		id_priv->qkey = RDMA_UDP_QKEY;
 		break;
 	case RDMA_PS_IPOIB:
@@ -689,7 +698,7 @@ static int cma_ib_init_qp_attr(struct rdma_id_private *id_priv,
 	*qp_attr_mask = IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT;
 
 	if (id_priv->id.qp_type == IB_QPT_UD) {
-		ret = cma_set_qkey(id_priv);
+		ret = cma_set_qkey(id_priv, 0);
 		if (ret)
 			return ret;
 
@@ -2624,15 +2633,10 @@ static int cma_sidr_rep_handler(struct ib_cm_id *cm_id,
 			event.status = ib_event->param.sidr_rep_rcvd.status;
 			break;
 		}
-		ret = cma_set_qkey(id_priv);
+		ret = cma_set_qkey(id_priv, rep->qkey);
 		if (ret) {
 			event.event = RDMA_CM_EVENT_ADDR_ERROR;
-			event.status = -EINVAL;
-			break;
-		}
-		if (id_priv->qkey != rep->qkey) {
-			event.event = RDMA_CM_EVENT_UNREACHABLE;
-			event.status = -EINVAL;
+			event.status = ret;
 			break;
 		}
 		ib_init_ah_from_path(id_priv->id.device, id_priv->id.port_num,
@@ -2922,7 +2926,7 @@ static int cma_accept_iw(struct rdma_id_private *id_priv,
 }
 
 static int cma_send_sidr_rep(struct rdma_id_private *id_priv,
-			     enum ib_cm_sidr_status status,
+			     enum ib_cm_sidr_status status, u32 qkey,
 			     const void *private_data, int private_data_len)
 {
 	struct ib_cm_sidr_rep_param rep;
@@ -2931,7 +2935,7 @@ static int cma_send_sidr_rep(struct rdma_id_private *id_priv,
 	memset(&rep, 0, sizeof rep);
 	rep.status = status;
 	if (status == IB_SIDR_SUCCESS) {
-		ret = cma_set_qkey(id_priv);
+		ret = cma_set_qkey(id_priv, qkey);
 		if (ret)
 			return ret;
 		rep.qp_num = id_priv->qp_num;
@@ -2965,11 +2969,12 @@ int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
 		if (id->qp_type == IB_QPT_UD) {
 			if (conn_param)
 				ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS,
+							conn_param->qkey,
 							conn_param->private_data,
 							conn_param->private_data_len);
 			else
 				ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS,
-							NULL, 0);
+							0, NULL, 0);
 		} else {
 			if (conn_param)
 				ret = cma_accept_ib(id_priv, conn_param);
@@ -3030,7 +3035,7 @@ int rdma_reject(struct rdma_cm_id *id, const void *private_data,
 	switch (rdma_node_get_transport(id->device->node_type)) {
 	case RDMA_TRANSPORT_IB:
 		if (id->qp_type == IB_QPT_UD)
-			ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT,
+			ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT, 0,
 						private_data, private_data_len);
 		else
 			ret = ib_send_cm_rej(id_priv->cm_id.ib,
@@ -3091,6 +3096,8 @@ static int cma_ib_mc_handler(int status, struct ib_sa_multicast *multicast)
 	    cma_disable_callback(id_priv, RDMA_CM_ADDR_RESOLVED))
 		return 0;
 
+	if (!status)
+		status = cma_set_qkey(id_priv, be32_to_cpu(multicast->rec.qkey));
 	mutex_lock(&id_priv->qp_mutex);
 	if (!status && id_priv->id.qp)
 		status = ib_attach_mcast(id_priv->id.qp, &multicast->rec.mgid,
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index 5ca44cd..e813774 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -709,7 +709,8 @@ out:
 	return ret;
 }
 
-static void ucma_copy_conn_param(struct rdma_conn_param *dst,
+static void ucma_copy_conn_param(struct rdma_cm_id *id,
+				 struct rdma_conn_param *dst,
 				 struct rdma_ucm_conn_param *src)
 {
 	dst->private_data = src->private_data;
@@ -721,6 +722,7 @@ static void ucma_copy_conn_param(struct rdma_conn_param *dst,
 	dst->rnr_retry_count = src->rnr_retry_count;
 	dst->srq = src->srq;
 	dst->qp_num = src->qp_num;
+	dst->qkey = (id->route.addr.src_addr.ss_family == AF_IB) ? src->qkey : 0;
 }
 
 static ssize_t ucma_connect(struct ucma_file *file, const char __user *inbuf,
@@ -741,7 +743,7 @@ static ssize_t ucma_connect(struct ucma_file *file, const char __user *inbuf,
 	if (IS_ERR(ctx))
 		return PTR_ERR(ctx);
 
-	ucma_copy_conn_param(&conn_param, &cmd.conn_param);
+	ucma_copy_conn_param(ctx->cm_id, &conn_param, &cmd.conn_param);
 	ret = rdma_connect(ctx->cm_id, &conn_param);
 	ucma_put_ctx(ctx);
 	return ret;
@@ -784,7 +786,7 @@ static ssize_t ucma_accept(struct ucma_file *file, const char __user *inbuf,
 		return PTR_ERR(ctx);
 
 	if (cmd.conn_param.valid) {
-		ucma_copy_conn_param(&conn_param, &cmd.conn_param);
+		ucma_copy_conn_param(ctx->cm_id, &conn_param, &cmd.conn_param);
 		mutex_lock(&file->mut);
 		ret = rdma_accept(ctx->cm_id, &conn_param);
 		if (!ret)
diff --git a/include/rdma/rdma_cm.h b/include/rdma/rdma_cm.h
index 1e6c3c7..966f90b 100644
--- a/include/rdma/rdma_cm.h
+++ b/include/rdma/rdma_cm.h
@@ -98,6 +98,7 @@ struct rdma_conn_param {
 	/* Fields below ignored if a QP is created on the rdma_cm_id. */
 	u8 srq;
 	u32 qp_num;
+	u32 qkey;
 };
 
 struct rdma_ud_param {
diff --git a/include/uapi/rdma/rdma_user_cm.h b/include/uapi/rdma/rdma_user_cm.h
index 1ee9239..29de08f 100644
--- a/include/uapi/rdma/rdma_user_cm.h
+++ b/include/uapi/rdma/rdma_user_cm.h
@@ -131,7 +131,7 @@ struct rdma_ucm_query_route_resp {
 
 struct rdma_ucm_conn_param {
 	__u32 qp_num;
-	__u32 reserved;
+	__u32 qkey;
 	__u8  private_data[RDMA_MAX_PRIVATE_DATA];
 	__u8  private_data_len;
 	__u8  srq;
-- 
1.7.3

  parent reply	other threads:[~2013-05-29 17:09 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29 17:09 [PATCH v5 00/28] rdma/cm: Add support for native IB addressing sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09 ` [PATCH v5 08/28] rdma/cm: Add helper functions to return id address information sean.hefty
     [not found] ` <1369847374-12176-1-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-05-29 17:09   ` [PATCH v5 01/28] rdma/cm: define native IB address sean.hefty-ral2JQCrhuEAvxtiuMwx3w
     [not found]     ` <1369847374-12176-2-git-send-email-sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-06-10 17:49       ` Hefty, Sean
2013-05-29 17:09   ` [PATCH v5 02/28] rdma/cm: Allow enabling reuseaddr in any state sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 03/28] rdma/cm: Include AF_IB in loopback and any address checks sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 04/28] ib/addr: Add AF_IB support to ip_addr_size sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 05/28] rdma/cm: Update port reservation to support AF_IB sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 06/28] rdma/cm: Allow user to specify AF_IB when binding sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 07/28] rdma/cm: Do not modify sa_family when setting loopback address sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 09/28] rdma/cm: Restrict AF_IB loopback to binding to IB devices only sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 10/28] rdma/cm: Verify that source and dest sa_family are the same sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 11/28] rdma/cm: Add support for AF_IB to rdma_resolve_addr sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 12/28] rdma/cm: Add support for AF_IB to rdma_resolve_route sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 14/28] rdma/cm: Remove unused SDP related code sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 15/28] rdma/cm: Merge cma_get/save_net_info sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 16/28] rdma/cm: Expose private data when using AF_IB sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 18/28] rdma/cm: Only listen on IB devices " sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 19/28] rdma/ucm: Support querying for AF_IB addresses sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 20/28] ib/sa: Export function to pack a path record into wire format sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 21/28] rdma/ucm: Support querying when IB paths are not reversible sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 22/28] rdma/cm: Export cma_get_service_id sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 26/28] rdma/ucm: Allow user space to pass AF_IB into resolve sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 27/28] rdma/ucm: Allow user space to specify AF_IB when joining multicast sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09   ` [PATCH v5 28/28] rdma/cm: Export AF_IB statistics sean.hefty-ral2JQCrhuEAvxtiuMwx3w
2013-05-29 17:09 ` [PATCH v5 13/28] rdma/cm: Add support for AF_IB to cma_get_service_id sean.hefty
2013-05-29 17:09 ` sean.hefty [this message]
2013-05-29 17:09 ` [PATCH v5 23/28] rdma/ucm: Add ability to query GID addresses sean.hefty
2013-05-29 17:09 ` [PATCH v5 24/28] rdma/ucm: Name changes to indicate only IP addresses supported sean.hefty
2013-05-29 17:09 ` [PATCH v5 25/28] rdma/ucm: Allow user space to bind to AF_IB sean.hefty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1369847374-12176-18-git-send-email-sean.hefty@intel.com \
    --to=sean.hefty@intel.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=roland@purestorage.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).