From patchwork Wed Jan 11 10:53:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Barak X-Patchwork-Id: 9509831 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 7BCCB60710 for ; Wed, 11 Jan 2017 10:54:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BD2E284EC for ; Wed, 11 Jan 2017 10:54:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70B9A284ED; Wed, 11 Jan 2017 10:54:47 +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, 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 1E96C28545 for ; Wed, 11 Jan 2017 10:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935720AbdAKKyo (ORCPT ); Wed, 11 Jan 2017 05:54:44 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:53556 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1760969AbdAKKyl (ORCPT ); Wed, 11 Jan 2017 05:54:41 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from matanb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 11 Jan 2017 12:54:37 +0200 Received: from gen-l-vrt-078.mtl.labs.mlnx. (gen-l-vrt-078.mtl.labs.mlnx [10.137.78.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v0BAsbJh026920; Wed, 11 Jan 2017 12:54:37 +0200 From: Matan Barak To: Doug Ledford Cc: linux-rdma@vger.kernel.org, Yishai Hadas , Jason Gunthorpe , Sean Hefty , Ira Weiny , Christoph Lameter , Majd Dibbiny , Tal Alon , Leon Romanovsky , Liran Liss , Haggai Eran , Matan Barak Subject: [PATCH for-next 5/7] IB/core: Add macros for declaring types and type groups Date: Wed, 11 Jan 2017 12:53:51 +0200 Message-Id: <1484132033-3346-6-git-send-email-matanb@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1484132033-3346-1-git-send-email-matanb@mellanox.com> References: <1484132033-3346-1-git-send-email-matanb@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 In order to initialize and destroy types in a generic way, we need to provide information about the allocation size, release function and order. This is done through a macro based DSL (domain specific language). This patch adds macros to initialize a type and a type group. When we transform the write based commands to use this new locking and allocation schema, we use these types declarations. Signed-off-by: Matan Barak Reviewed-by: Yishai Hadas --- include/rdma/uverbs_ioctl.h | 50 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h index a8b0ff9..4b569ae 100644 --- a/include/rdma/uverbs_ioctl.h +++ b/include/rdma/uverbs_ioctl.h @@ -34,8 +34,7 @@ #define _UVERBS_IOCTL_ #include - -struct ib_uobject; +#include enum uverbs_attr_type { UVERBS_ATTR_TYPE_IDR, @@ -79,4 +78,51 @@ struct uverbs_root { size_t num_groups; }; +#define UVERBS_BUILD_BUG_ON(cond) (sizeof(char[1 - 2 * !!(cond)]) - \ + sizeof(char)) +#define UVERBS_TYPE_ALLOC_FD(_order, _obj_size, _free_fn, _fops, _name, _flags)\ + ((const struct uverbs_type_alloc_action) \ + {.type = UVERBS_ATTR_TYPE_FD, \ + .order = _order, \ + .obj_size = (_obj_size) + \ + UVERBS_BUILD_BUG_ON((_obj_size) < sizeof(struct ib_uobject)), \ + .free_fn = _free_fn, \ + .fd = {.fops = _fops, \ + .name = _name, \ + .flags = _flags} }) +#define UVERBS_TYPE_ALLOC_IDR_SZ(_size, _order, _free_fn) \ + ((const struct uverbs_type_alloc_action) \ + {.type = UVERBS_ATTR_TYPE_IDR, \ + .order = _order, \ + .free_fn = _free_fn, \ + .obj_size = (_size) + \ + UVERBS_BUILD_BUG_ON((_size) < sizeof(struct ib_uobject)),}) +#define UVERBS_TYPE_ALLOC_IDR(_order, _free_fn) \ + UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uobject), _order, _free_fn) +#define DECLARE_UVERBS_TYPE(name, _alloc) \ + const struct uverbs_type name = { \ + .alloc = _alloc, \ + } +#define _UVERBS_TYPE_SZ(...) \ + (sizeof((const struct uverbs_type *[]){__VA_ARGS__}) / \ + sizeof(const struct uverbs_type *)) +#define ADD_UVERBS_TYPE(type_idx, type_ptr) \ + [type_idx] = ((const struct uverbs_type * const)&(type_ptr)) +#define UVERBS_TYPES(...) ((const struct uverbs_type_group) \ + {.num_types = _UVERBS_TYPE_SZ(__VA_ARGS__), \ + .types = (const struct uverbs_type *[]){__VA_ARGS__} }) +#define DECLARE_UVERBS_TYPES(name, ...) \ + const struct uverbs_type_group name = UVERBS_TYPES(__VA_ARGS__) + +#define _UVERBS_TYPES_SZ(...) \ + (sizeof((const struct uverbs_type_group *[]){__VA_ARGS__}) / \ + sizeof(const struct uverbs_type_group *)) + +#define UVERBS_TYPES_GROUP(...) \ + ((const struct uverbs_root){ \ + .type_groups = (const struct uverbs_type_group *[]){__VA_ARGS__},\ + .num_groups = _UVERBS_TYPES_SZ(__VA_ARGS__)}) +#define DECLARE_UVERBS_TYPES_GROUP(name, ...) \ + const struct uverbs_root name = UVERBS_TYPES_GROUP(__VA_ARGS__) + #endif