From patchwork Sun Dec 23 17:14:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10741777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB87F746 for ; Sun, 23 Dec 2018 17:15:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D60C283B1 for ; Sun, 23 Dec 2018 17:15:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81C7228736; Sun, 23 Dec 2018 17:15:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C322B283B1 for ; Sun, 23 Dec 2018 17:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725819AbeLWRPW (ORCPT ); Sun, 23 Dec 2018 12:15:22 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:41678 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725798AbeLWRPW (ORCPT ); Sun, 23 Dec 2018 12:15:22 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 23 Dec 2018 19:21:37 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id wBNHFDTe030324; Sun, 23 Dec 2018 19:15:13 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id wBNHFDcf007164; Sun, 23 Dec 2018 19:15:13 +0200 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id wBNHFDBO007163; Sun, 23 Dec 2018 19:15:13 +0200 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, michaelgur@mellanox.com, jgg@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-core 2/6] verbs: Migrate ibv_cmd_query_port to run over ioctl Date: Sun, 23 Dec 2018 19:14:53 +0200 Message-Id: <1545585297-6677-3-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1545585297-6677-1-git-send-email-yishaih@mellanox.com> References: <1545585297-6677-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michael Guralnik 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 Signed-off-by: Yishai Hadas --- 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 --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 + +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; +} +