From patchwork Thu Mar 29 16:09:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Wise X-Patchwork-Id: 10316123 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 438D660383 for ; Thu, 29 Mar 2018 20:30:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34DE02A4F6 for ; Thu, 29 Mar 2018 20:30:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29E1B2A4F8; Thu, 29 Mar 2018 20:30:12 +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=-5.3 required=2.0 tests=BAYES_00, DATE_IN_PAST_03_06, 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 92AD62A4F6 for ; Thu, 29 Mar 2018 20:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751205AbeC2UaK (ORCPT ); Thu, 29 Mar 2018 16:30:10 -0400 Received: from opengridcomputing.com ([70.118.0.34]:49956 "EHLO smtp.opengridcomputing.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751070AbeC2UaK (ORCPT ); Thu, 29 Mar 2018 16:30:10 -0400 Received: by smtp.opengridcomputing.com (Postfix, from userid 503) id 78B2D29ECB; Thu, 29 Mar 2018 15:30:09 -0500 (CDT) Message-Id: <5974409947a16e6a7ef89d42c003cc125e44acc6.1522341686.git.swise@opengridcomputing.com> In-Reply-To: References: From: Steve Wise Date: Thu, 29 Mar 2018 09:09:54 -0700 Subject: [PATCH v2 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 | 79 +++++++++++++++++++++++++++++++++++++++++ include/rdma/restrack.h | 19 ++++++++++ 2 files changed, 98 insertions(+) diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c index 902517f..301646b 100644 --- a/drivers/infiniband/core/nldev.c +++ b/drivers/infiniband/core/nldev.c @@ -131,6 +131,85 @@ static int provider_fill_port_info(struct sk_buff *msg, device->res.fill_port_info(msg, cb, 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; +} + +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; +} +EXPORT_SYMBOL(rdma_nl_put_provider_u32); + +int rdma_nl_put_provider_s32(struct sk_buff *msg, const char *name, + enum rdma_nldev_print_type print_type, + s32 value) +{ + if (put_provider_name_print_type(msg, name, print_type)) + return -EMSGSIZE; + if (nla_put_s32(msg, RDMA_NLDEV_ATTR_PROVIDER_S32, value)) + return -EMSGSIZE; + + return 0; +} +EXPORT_SYMBOL(rdma_nl_put_provider_s32); + +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; +} +EXPORT_SYMBOL(rdma_nl_put_provider_u64); + +int rdma_nl_put_provider_s64(struct sk_buff *msg, const char *name, + enum rdma_nldev_print_type print_type, + s64 value) +{ + if (put_provider_name_print_type(msg, name, print_type)) + return -EMSGSIZE; + if (nla_put_s64(msg, RDMA_NLDEV_ATTR_PROVIDER_S64, value, + RDMA_NLDEV_ATTR_PAD)) + return -EMSGSIZE; + + return 0; +} +EXPORT_SYMBOL(rdma_nl_put_provider_s64); + +int rdma_nl_put_provider_string(struct sk_buff *msg, const char *name, + const char *value) +{ + if (put_provider_name_print_type(msg, name, + RDMA_NLDEV_PRINT_TYPE_UNSPEC)) + return -EMSGSIZE; + if (nla_put_string(msg, RDMA_NLDEV_ATTR_PROVIDER_STRING, value)) + return -EMSGSIZE; + + return 0; +} +EXPORT_SYMBOL(rdma_nl_put_provider_string); + 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 936b56f..094a209 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 @@ -199,4 +200,22 @@ 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, + enum rdma_nldev_print_type print_type, + u32 value); +int rdma_nl_put_provider_s32(struct sk_buff *msg, const char *name, + enum rdma_nldev_print_type print_type, + s32 value); +int rdma_nl_put_provider_u64(struct sk_buff *msg, const char *name, + enum rdma_nldev_print_type print_type, + u64 value); +int rdma_nl_put_provider_s64(struct sk_buff *msg, const char *name, + enum rdma_nldev_print_type print_type, + s64 value); +int rdma_nl_put_provider_string(struct sk_buff *msg, const char *name, + const char *value); #endif /* _RDMA_RESTRACK_H_ */