diff mbox series

[rdma-core,2/6] verbs: Migrate ibv_cmd_query_port to run over ioctl

Message ID 1545585297-6677-3-git-send-email-yishaih@mellanox.com (mailing list archive)
State Not Applicable
Headers show
Series verbs: Expose the IBTA port CapabilityMask2 | expand

Commit Message

Yishai Hadas Dec. 23, 2018, 5:14 p.m. UTC
From: Michael Guralnik <michaelgur@mellanox.com>

Migrate ibv_cmd_query_port to run over ioctl with a fallback to the
write method when ioctl is not supported by the kernel.
Downstream patch in this series will extend the response over the ioctl
interface.

Signed-off-by: Michael Guralnik <michaelgur@mellanox.com>
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
---
 libibverbs/CMakeLists.txt |   1 +
 libibverbs/cmd.c          |  41 -------------------
 libibverbs/cmd_device.c   | 100 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 101 insertions(+), 41 deletions(-)
 create mode 100644 libibverbs/cmd_device.c
diff mbox series

Patch

diff --git a/libibverbs/CMakeLists.txt b/libibverbs/CMakeLists.txt
index 2ddafd6..ddc891a 100644
--- a/libibverbs/CMakeLists.txt
+++ b/libibverbs/CMakeLists.txt
@@ -32,6 +32,7 @@  rdma_library(ibverbs "${CMAKE_CURRENT_BINARY_DIR}/libibverbs.map"
   cmd.c
   cmd_counters.c
   cmd_cq.c
+  cmd_device.c
   cmd_dm.c
   cmd_fallback.c
   cmd_flow_action.c
diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c
index a824202..350210b 100644
--- a/libibverbs/cmd.c
+++ b/libibverbs/cmd.c
@@ -268,47 +268,6 @@  int ibv_cmd_query_device_ex(struct ibv_context *context,
 	return 0;
 }
 
-int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num,
-		       struct ibv_port_attr *port_attr,
-		       struct ibv_query_port *cmd, size_t cmd_size)
-{
-	struct ib_uverbs_query_port_resp resp;
-	int ret;
-
-	cmd->port_num = port_num;
-	memset(cmd->reserved, 0, sizeof cmd->reserved);
-	memset(&resp, 0, sizeof(resp));
-
-	ret = execute_cmd_write(context, IB_USER_VERBS_CMD_QUERY_PORT, cmd,
-				cmd_size, &resp, sizeof(resp));
-	if (ret)
-		return ret;
-
-	port_attr->state      	   = resp.state;
-	port_attr->max_mtu         = resp.max_mtu;
-	port_attr->active_mtu      = resp.active_mtu;
-	port_attr->gid_tbl_len     = resp.gid_tbl_len;
-	port_attr->port_cap_flags  = resp.port_cap_flags;
-	port_attr->max_msg_sz      = resp.max_msg_sz;
-	port_attr->bad_pkey_cntr   = resp.bad_pkey_cntr;
-	port_attr->qkey_viol_cntr  = resp.qkey_viol_cntr;
-	port_attr->pkey_tbl_len    = resp.pkey_tbl_len;
-	port_attr->lid 	      	   = resp.lid;
-	port_attr->sm_lid 	   = resp.sm_lid;
-	port_attr->lmc 	      	   = resp.lmc;
-	port_attr->max_vl_num      = resp.max_vl_num;
-	port_attr->sm_sl      	   = resp.sm_sl;
-	port_attr->subnet_timeout  = resp.subnet_timeout;
-	port_attr->init_type_reply = resp.init_type_reply;
-	port_attr->active_width    = resp.active_width;
-	port_attr->active_speed    = resp.active_speed;
-	port_attr->phys_state      = resp.phys_state;
-	port_attr->link_layer      = resp.link_layer;
-	port_attr->flags	   = resp.flags;
-
-	return 0;
-}
-
 int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd,
 		     struct ibv_alloc_pd *cmd, size_t cmd_size,
 		     struct ib_uverbs_alloc_pd_resp *resp, size_t resp_size)
diff --git a/libibverbs/cmd_device.c b/libibverbs/cmd_device.c
new file mode 100644
index 0000000..803d33d
--- /dev/null
+++ b/libibverbs/cmd_device.c
@@ -0,0 +1,100 @@ 
+/*
+ * Copyright (c) 2018 Mellanox Technologies, Ltd.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <infiniband/cmd_write.h>
+
+static void copy_query_port_resp_to_port_attr(struct ibv_port_attr *port_attr,
+				       struct ib_uverbs_query_port_resp *resp)
+{
+	port_attr->state	   = resp->state;
+	port_attr->max_mtu	   = resp->max_mtu;
+	port_attr->active_mtu      = resp->active_mtu;
+	port_attr->gid_tbl_len     = resp->gid_tbl_len;
+	port_attr->port_cap_flags  = resp->port_cap_flags;
+	port_attr->max_msg_sz      = resp->max_msg_sz;
+	port_attr->bad_pkey_cntr   = resp->bad_pkey_cntr;
+	port_attr->qkey_viol_cntr  = resp->qkey_viol_cntr;
+	port_attr->pkey_tbl_len    = resp->pkey_tbl_len;
+	port_attr->lid		   = resp->lid;
+	port_attr->sm_lid	   = resp->sm_lid;
+	port_attr->lmc		   = resp->lmc;
+	port_attr->max_vl_num      = resp->max_vl_num;
+	port_attr->sm_sl	   = resp->sm_sl;
+	port_attr->subnet_timeout  = resp->subnet_timeout;
+	port_attr->init_type_reply = resp->init_type_reply;
+	port_attr->active_width    = resp->active_width;
+	port_attr->active_speed    = resp->active_speed;
+	port_attr->phys_state      = resp->phys_state;
+	port_attr->link_layer      = resp->link_layer;
+	port_attr->flags	   = resp->flags;
+}
+
+int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num,
+		       struct ibv_port_attr *port_attr,
+		       struct ibv_query_port *cmd, size_t cmd_size)
+{
+	DECLARE_FBCMD_BUFFER(cmdb, UVERBS_OBJECT_DEVICE,
+			     UVERBS_METHOD_QUERY_PORT, 2, NULL);
+	int ret;
+	struct ib_uverbs_query_port_resp_ex resp_ex = {};
+
+	fill_attr_const_in(cmdb, UVERBS_ATTR_QUERY_PORT_PORT_NUM, port_num);
+	fill_attr_out_ptr(cmdb, UVERBS_ATTR_QUERY_PORT_RESP, &resp_ex);
+
+	switch (execute_ioctl_fallback(context, query_port, cmdb, &ret)) {
+	case TRY_WRITE: {
+		struct ib_uverbs_query_port_resp resp;
+
+		cmd->port_num = port_num;
+		memset(cmd->reserved, 0, sizeof(cmd->reserved));
+		memset(&resp, 0, sizeof(resp));
+
+		ret = execute_cmd_write(context,
+					IB_USER_VERBS_CMD_QUERY_PORT, cmd,
+					cmd_size, &resp, sizeof(resp));
+		if (ret)
+			return ret;
+
+		copy_query_port_resp_to_port_attr(port_attr, &resp);
+		break;
+	}
+	case SUCCESS:
+		copy_query_port_resp_to_port_attr(port_attr,
+						  &resp_ex.legacy_resp);
+		break;
+	default:
+		return ret;
+	};
+
+	return 0;
+}
+