From patchwork Fri Mar 30 18:03:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Wise X-Patchwork-Id: 10318263 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2CBB860383 for ; Fri, 30 Mar 2018 18:09:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BEFE2A62B for ; Fri, 30 Mar 2018 18:09:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FBB42A62D; Fri, 30 Mar 2018 18:09:46 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 8E95C2A62B for ; Fri, 30 Mar 2018 18:09:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751271AbeC3SJo (ORCPT ); Fri, 30 Mar 2018 14:09:44 -0400 Received: from opengridcomputing.com ([70.118.0.34]:55303 "EHLO smtp.opengridcomputing.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751163AbeC3SJn (ORCPT ); Fri, 30 Mar 2018 14:09:43 -0400 Received: by smtp.opengridcomputing.com (Postfix, from userid 503) id 5FEE92BC5D; Fri, 30 Mar 2018 13:09:43 -0500 (CDT) Message-Id: <357679afe9921eb7e0ba3fe879e7558d11080a0e.1522433107.git.swise@opengridcomputing.com> In-Reply-To: References: From: Steve Wise Date: Fri, 30 Mar 2018 11:03:42 -0700 Subject: [PATCH v3 rdma-next 4/5] RDMA/NLDEV: helper functions to add provider attributes To: jgg@mellanox.com, dledford@redhat.com Cc: leon@kernel.org, linux-rdma@vger.kernel.org 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 These help rdma providers to fill out the provider entries. Signed-off-by: Steve Wise --- drivers/infiniband/core/nldev.c | 67 +++++++++++++++++++++++++++++++++++++++++ include/rdma/restrack.h | 13 ++++++++ 2 files changed, 80 insertions(+) diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c index 0610313..a11fd16 100644 --- a/drivers/infiniband/core/nldev.c +++ b/drivers/infiniband/core/nldev.c @@ -128,6 +128,73 @@ static int provider_fill_port_info(struct sk_buff *msg, device->res.fill_port_info(msg, device, port) : 0; } +static int put_provider_name_print_type(struct sk_buff *msg, const char *name, + enum rdma_nldev_print_type print_type) +{ + if (nla_put_string(msg, RDMA_NLDEV_ATTR_PROVIDER_STRING, name)) + return -EMSGSIZE; + if (print_type != RDMA_NLDEV_PRINT_TYPE_UNSPEC && + nla_put_u8(msg, RDMA_NLDEV_ATTR_PROVIDER_PRINT_TYPE, print_type)) + return -EMSGSIZE; + + return 0; +} + +static int _rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name, + enum rdma_nldev_print_type print_type, + u32 value) +{ + if (put_provider_name_print_type(msg, name, print_type)) + return -EMSGSIZE; + if (nla_put_u32(msg, RDMA_NLDEV_ATTR_PROVIDER_U32, value)) + return -EMSGSIZE; + + return 0; +} + +static int _rdma_nl_put_provider_u64(struct sk_buff *msg, const char *name, + enum rdma_nldev_print_type print_type, + u64 value) +{ + if (put_provider_name_print_type(msg, name, print_type)) + return -EMSGSIZE; + if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_PROVIDER_U64, value, + RDMA_NLDEV_ATTR_PAD)) + return -EMSGSIZE; + + return 0; +} + +int rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name, u32 value) +{ + return _rdma_nl_put_provider_u32(msg, name, + RDMA_NLDEV_PRINT_TYPE_UNSPEC, value); +} +EXPORT_SYMBOL(rdma_nl_put_provider_u32); + +int rdma_nl_put_provider_u32_hex(struct sk_buff *msg, const char *name, + u32 value) +{ + return _rdma_nl_put_provider_u32(msg, name, RDMA_NLDEV_PRINT_TYPE_HEX, + value); +} +EXPORT_SYMBOL(rdma_nl_put_provider_u32_hex); + +int rdma_nl_put_provider_u64(struct sk_buff *msg, const char *name, u64 value) +{ + return _rdma_nl_put_provider_u64(msg, name, + RDMA_NLDEV_PRINT_TYPE_UNSPEC, value); +} +EXPORT_SYMBOL(rdma_nl_put_provider_u64); + +int rdma_nl_put_provider_u64_hex(struct sk_buff *msg, const char *name, + u64 value) +{ + return _rdma_nl_put_provider_u64(msg, name, RDMA_NLDEV_PRINT_TYPE_HEX, + value); +} +EXPORT_SYMBOL(rdma_nl_put_provider_u64_hex); + static int fill_nldev_handle(struct sk_buff *msg, struct ib_device *device) { if (nla_put_u32(msg, RDMA_NLDEV_ATTR_DEV_INDEX, device->index)) diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h index 525f885..10cca0e 100644 --- a/include/rdma/restrack.h +++ b/include/rdma/restrack.h @@ -12,6 +12,7 @@ #include #include #include +#include /** * enum rdma_restrack_type - HW objects to track @@ -197,4 +198,16 @@ static inline void rdma_restrack_set_task(struct rdma_restrack_entry *res, res->task = task; } +/* + * Helper functions for rdma providers when filling out + * nldev provider attributes. + */ +int rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name, + u32 value); +int rdma_nl_put_provider_u32_hex(struct sk_buff *msg, const char *name, + u32 value); +int rdma_nl_put_provider_u64(struct sk_buff *msg, const char *name, + u64 value); +int rdma_nl_put_provider_u64_hex(struct sk_buff *msg, const char *name, + u64 value); #endif /* _RDMA_RESTRACK_H_ */