From patchwork Thu Oct 19 14:41:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10017315 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 A7DE9600CC for ; Thu, 19 Oct 2017 14:43:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BD3A28D90 for ; Thu, 19 Oct 2017 14:43:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 908A028D94; Thu, 19 Oct 2017 14:43:28 +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 3120428D90 for ; Thu, 19 Oct 2017 14:43:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752077AbdJSOn0 (ORCPT ); Thu, 19 Oct 2017 10:43:26 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:54820 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752471AbdJSOmu (ORCPT ); Thu, 19 Oct 2017 10:42:50 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 19 Oct 2017 16:42:42 +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 v9JEggR9032304; Thu, 19 Oct 2017 17:42:42 +0300 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 v9JEggMn027365; Thu, 19 Oct 2017 17:42:42 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id v9JEggWD027364; Thu, 19 Oct 2017 17:42:42 +0300 From: Yishai Hadas To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, yishaih@mellanox.com, raeds@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-next 05/16] IB/core: Introduce counter set object and its create/destroy verbs Date: Thu, 19 Oct 2017 17:41:47 +0300 Message-Id: <1508424118-27205-6-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1508424118-27205-1-git-send-email-yishaih@mellanox.com> References: <1508424118-27205-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: Raed Salem Counter set instance is allocated on an IB context and belongs to that context. Upon successful creation the counter set hardware resources are allocated and are ready to be bound to its counted type IB object. Post the bind operation the hardware related counters could be queried. Downstream patches in this series will introduce the bind and the query functionality. Counter set instance can be de-allocated, upon successful destruction the related hardware resources are released. Prior to calling the destroy verb the user must first make sure that the counter set is not being used by its IB object, in other words not bound to any of its counted objects. Signed-off-by: Raed Salem Reviewed-by: Yishai Hadas --- drivers/infiniband/core/verbs.c | 42 +++++++++++++++++++++++++++++++++++++++++ include/rdma/ib_verbs.h | 15 +++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index eda389a..ea71393 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -2310,3 +2310,45 @@ int ib_describe_counter_set(struct ib_device *device, NULL); } EXPORT_SYMBOL(ib_describe_counter_set); + +/** + * ib_create_counter_set - Creates a Counter Set + * @device: The device on which to create the counter set. + * @cs_id: counter set id required to + * create the counter set. + */ +struct ib_counter_set *ib_create_counter_set(struct ib_device *device, + u16 cs_id) +{ + struct ib_counter_set *cs; + + if (!device->create_counter_set) + return ERR_PTR(-ENOSYS); + + cs = device->create_counter_set(device, cs_id, NULL); + if (!IS_ERR(cs)) { + cs->device = device; + cs->uobject = NULL; + cs->cs_id = cs_id; + atomic_set(&cs->usecnt, 0); + } + + return cs; +} +EXPORT_SYMBOL(ib_create_counter_set); + +/** + * ib_destroy_counter_set - Destroys the specified counter set. + * @cs: The counter set to destroy. + **/ +int ib_destroy_counter_set(struct ib_counter_set *cs) +{ + if (!cs->device->destroy_counter_set) + return -ENOSYS; + + if (atomic_read(&cs->usecnt)) + return -EBUSY; + + return cs->device->destroy_counter_set(cs); +} +EXPORT_SYMBOL(ib_destroy_counter_set); diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 44f92c3..1c78db7 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2077,6 +2077,14 @@ struct ib_counter_set_describe_attr { char *counters_names_buff; }; +struct ib_counter_set { + struct ib_device *device; + struct ib_uobject *uobject; + u16 cs_id; + /* num of objects attached */ + atomic_t usecnt; +}; + struct ib_device { /* Do not access @dma_device directly from ULP nor from HW drivers. */ struct device *dma_device; @@ -2336,6 +2344,10 @@ struct ib_device { u16 cs_id, struct ib_counter_set_describe_attr *cs_describe_attr, struct ib_udata *udata); + struct ib_counter_set * (*create_counter_set)(struct ib_device *device, + u16 cs_id, + struct ib_udata *udata); + int (*destroy_counter_set)(struct ib_counter_set *cs); /** * rdma netdev operation @@ -3647,6 +3659,9 @@ struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device, int ib_describe_counter_set(struct ib_device *device, u16 cs_id, struct ib_counter_set_describe_attr *cs_describe_attr); +struct ib_counter_set *ib_create_counter_set(struct ib_device *device, + u16 cs_id); +int ib_destroy_counter_set(struct ib_counter_set *cs); int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents, unsigned int *sg_offset, unsigned int page_size);