Linux-RDMA Archive on lore.kernel.org
 help / color / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: linux-rdma@vger.kernel.org, Leon Romanovsky <leonro@mellanox.com>
Cc: Jason Gunthorpe <jgg@mellanox.com>
Subject: [PATCH 1/7] RDMA/cm: Add accessors for CM_REQ transport_type
Date: Thu, 16 Jan 2020 13:00:31 -0400
Message-ID: <20200116170037.30109-2-jgg@ziepe.ca> (raw)
In-Reply-To: <20200116170037.30109-1-jgg@ziepe.ca>

From: Jason Gunthorpe <jgg@mellanox.com>

Access the two fields through wrappers, like all other fields, to make it
clearer what is happening.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Tested-by: Leon Romanovsky <leonro@mellanox.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
---
 drivers/infiniband/core/cm_msgs.h | 41 ++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/drivers/infiniband/core/cm_msgs.h b/drivers/infiniband/core/cm_msgs.h
index 23e3d0c6a67c3c..9af9a321207423 100644
--- a/drivers/infiniband/core/cm_msgs.h
+++ b/drivers/infiniband/core/cm_msgs.h
@@ -124,14 +124,37 @@ static inline void cm_req_set_remote_resp_timeout(struct cm_req_msg *req_msg,
 					  0xFFFFFF07));
 }
 
+static inline u8 cm_req_get_transport_type(struct cm_req_msg *req_msg)
+{
+	return (u8) ((be32_to_cpu(req_msg->offset40) & 0x06) >> 1);
+}
+
+static inline void cm_req_set_transport_type(struct cm_req_msg *req_msg, u8 val)
+{
+	req_msg->offset40 =
+		cpu_to_be32((be32_to_cpu(req_msg->offset40) & 0xFFFFFFF9) |
+		(val << 1));
+}
+
+static inline u8 cm_req_get_transport_type_ex(struct cm_req_msg *req_msg)
+{
+	return req_msg->offset51 & 0x7;
+}
+
+static inline void cm_req_set_transport_type_ex(struct cm_req_msg *req_msg,
+						u8 val)
+{
+	req_msg->offset51 = (req_msg->offset51 & 0xF8) | val;
+}
+
 static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
 {
-	u8 transport_type = (u8) (be32_to_cpu(req_msg->offset40) & 0x06) >> 1;
+	u8 transport_type = cm_req_get_transport_type(req_msg);
 	switch(transport_type) {
 	case 0: return IB_QPT_RC;
 	case 1: return IB_QPT_UC;
 	case 3:
-		switch (req_msg->offset51 & 0x7) {
+		switch (cm_req_get_transport_type_ex(req_msg)) {
 		case 1: return IB_QPT_XRC_TGT;
 		default: return 0;
 		}
@@ -144,20 +167,14 @@ static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
 {
 	switch(qp_type) {
 	case IB_QPT_UC:
-		req_msg->offset40 = cpu_to_be32((be32_to_cpu(
-						  req_msg->offset40) &
-						   0xFFFFFFF9) | 0x2);
+		cm_req_set_transport_type(req_msg, 1);
 		break;
 	case IB_QPT_XRC_INI:
-		req_msg->offset40 = cpu_to_be32((be32_to_cpu(
-						 req_msg->offset40) &
-						   0xFFFFFFF9) | 0x6);
-		req_msg->offset51 = (req_msg->offset51 & 0xF8) | 1;
+		cm_req_set_transport_type(req_msg, 3);
+		cm_req_set_transport_type_ex(req_msg, 1);
 		break;
 	default:
-		req_msg->offset40 = cpu_to_be32(be32_to_cpu(
-						 req_msg->offset40) &
-						  0xFFFFFFF9);
+		cm_req_set_transport_type(req_msg, 0);
 	}
 }
 
-- 
2.24.1


  reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16 17:00 [PATCH 0/7] RDMA/cm: Remove open coded structure pack/unpack Jason Gunthorpe
2020-01-16 17:00 ` Jason Gunthorpe [this message]
2020-01-16 17:00 ` [PATCH 2/7] RDMA/cm: Add SET/GET implementations to hide IBA wire format Jason Gunthorpe
2020-01-16 17:00 ` [PATCH 3/7] RDMA/cm: Use IBA functions for simple get/set acessors Jason Gunthorpe
2020-01-16 17:00 ` [PATCH 4/7] RDMA/cm: Use IBA functions for swapping " Jason Gunthorpe
2020-01-16 17:00 ` [PATCH 5/7] RDMA/cm: Use IBA functions for simple structure members Jason Gunthorpe
2020-01-16 17:00 ` [PATCH 6/7] RDMA/cm: Use IBA functions for complex " Jason Gunthorpe
2020-01-16 17:00 ` [PATCH 7/7] RDMA/cm: Remove CM message structs Jason Gunthorpe
2020-01-25 19:24 ` [PATCH 0/7] RDMA/cm: Remove open coded structure pack/unpack Jason

Reply instructions:

You may reply publically 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=20200116170037.30109-2-jgg@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=jgg@mellanox.com \
    --cc=leonro@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    /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

Linux-RDMA Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rdma/0 linux-rdma/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rdma linux-rdma/ https://lore.kernel.org/linux-rdma \
		linux-rdma@vger.kernel.org
	public-inbox-index linux-rdma

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rdma


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git