From patchwork Mon Nov 5 11:35:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Heib X-Patchwork-Id: 10667877 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 416AE15A6 for ; Mon, 5 Nov 2018 11:35:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 311D128DB6 for ; Mon, 5 Nov 2018 11:35:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25C7129782; Mon, 5 Nov 2018 11:35:56 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 7BEAE28DB6 for ; Mon, 5 Nov 2018 11:35:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727558AbeKEUzL (ORCPT ); Mon, 5 Nov 2018 15:55:11 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50274 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKEUzL (ORCPT ); Mon, 5 Nov 2018 15:55:11 -0500 Received: by mail-wm1-f67.google.com with SMTP id 124-v6so3028435wmw.0 for ; Mon, 05 Nov 2018 03:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nNLwcrZ5n8bqSphq7KygO2jDuDEYu0SYa8Cf8mU2bBs=; b=uXuHYUKs5wb33CIDKNOQKXK7id+0wvN9rBSD6ee0EoDTzRPJyFXMAe76txE4iqYTsB QnjXBT7vfpjIGcfScA8W+bZYNVDQSIoleoy4dUAML6eCMH5gUlD3xokFK8jHeCUbER6w f4rIhcr7RlLJzp94AXqx/+ttdjdz9PfKKWs1PQP4q+7eZJZw7bKSY0ILRHV8/pLmWF/3 U+sqS+mU0YR6KGY17JduH++Ejo+zoRS9+VaPoC/eOSrBQJXNed2t+0eZlH1EYpM4wC4D CpEHhD5nC5EVe82Hvz53rl94grDC59iLb9VlRgH014e6xota4gT1vIPQnq3pE9xRmz+I cjMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nNLwcrZ5n8bqSphq7KygO2jDuDEYu0SYa8Cf8mU2bBs=; b=meZ/yIc8Q1id1QLk7WE0ILOp/idDANC5ffqcGWifcT1QAdJwtk/U5UoO+b8rK8XOIw 1q436pgoVDk9/f5kt23ckDd46TUFmxD5pYLiQXlW2CryErBtSkz+3FpKavRMoEtejED6 Sd22ocGElpa5bnw9D16kDvxQJSm9DL86ba7hq+MCYEKAQJgxsrFg5wg+9PmD0eJOBGjm 5lOmTnvKMhCnonR+vh7Qmhj+7rCnE/Zj3UbETuNNnLk3r1jf0qczS1qwpKYES3HPrVxB iX5KV9PWXOVhmnliJvNgZHBpBhEssw7C8ck/bVke4ZYx5RiUCKUvFMSMYYhybxXKzTq8 g/DA== X-Gm-Message-State: AGRZ1gIyy0TvPN5i6HJQ3oEKAapDja4xVoIyzst6f+qUdUeNOyGoGBoX Xh2PKCxJ6fgOL7G1NndJciE= X-Google-Smtp-Source: AJdET5e/l5meAyxUTGwXUJgbECyZ2gyl68+n/IWEJbUSk8pzPTWzX+u9W8S+kpUVbf9bjEbVIToXVg== X-Received: by 2002:a1c:8604:: with SMTP id i4-v6mr1866084wmd.23.1541417751920; Mon, 05 Nov 2018 03:35:51 -0800 (PST) Received: from kheib-workstation.redhat.com ([192.116.94.216]) by smtp.gmail.com with ESMTPSA id z18-v6sm10762147wru.83.2018.11.05.03.35.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Nov 2018 03:35:51 -0800 (PST) From: Kamal Heib To: Doug Ledford , Jason Gunthorpe Cc: linux-rdma@vger.kernel.org, kamalheib1@gmail.com Subject: [PATCH rdma-next v3 06/20] RDMA/hns: Initialize ib_device_ops struct Date: Mon, 5 Nov 2018 13:35:14 +0200 Message-Id: <20181105113528.8317-7-kamalheib1@gmail.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20181105113528.8317-1-kamalheib1@gmail.com> References: <20181105113528.8317-1-kamalheib1@gmail.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 Initialize ib_device_ops with the supported operations using ib_set_device_ops(). Signed-off-by: Kamal Heib --- drivers/infiniband/hw/hns/hns_roce_device.h | 1 + drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 13 ++++ drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 13 ++++ drivers/infiniband/hw/hns/hns_roce_main.c | 112 +++++++++++++++------------- 4 files changed, 86 insertions(+), 53 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h index d39bdfdb5de9..01ca1550d04c 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -805,6 +805,7 @@ struct hns_roce_hw { int (*modify_cq)(struct ib_cq *cq, u16 cq_count, u16 cq_period); int (*init_eq)(struct hns_roce_dev *hr_dev); void (*cleanup_eq)(struct hns_roce_dev *hr_dev); + const struct ib_device_ops *hns_roce_dev_ops; }; struct hns_roce_dev { diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c index ca05810c92dc..79056e4e9ebf 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c @@ -4793,6 +4793,18 @@ static void hns_roce_v1_cleanup_eq_table(struct hns_roce_dev *hr_dev) kfree(eq_table->eq); } +static const struct ib_device_ops hns_roce_v1_dev_ops = { + /* QP operations */ + .query_qp = hns_roce_v1_query_qp, + .destroy_qp = hns_roce_v1_destroy_qp, + .post_send = hns_roce_v1_post_send, + .post_recv = hns_roce_v1_post_recv, + /* CQ operations */ + .modify_cq = hns_roce_v1_modify_cq, + .req_notify_cq = hns_roce_v1_req_notify_cq, + .poll_cq = hns_roce_v1_poll_cq, +}; + static const struct hns_roce_hw hns_roce_hw_v1 = { .reset = hns_roce_v1_reset, .hw_profile = hns_roce_v1_profile, @@ -4818,6 +4830,7 @@ static const struct hns_roce_hw hns_roce_hw_v1 = { .destroy_cq = hns_roce_v1_destroy_cq, .init_eq = hns_roce_v1_init_eq_table, .cleanup_eq = hns_roce_v1_cleanup_eq_table, + .hns_roce_dev_ops = &hns_roce_v1_dev_ops, }; static const struct of_device_id hns_roce_of_match[] = { diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index a4c62ae23a9a..1802113750ac 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -5340,6 +5340,18 @@ static void hns_roce_v2_cleanup_eq_table(struct hns_roce_dev *hr_dev) destroy_workqueue(hr_dev->irq_workq); } +static const struct ib_device_ops hns_roce_v2_dev_ops = { + /* QP operations */ + .query_qp = hns_roce_v2_query_qp, + .destroy_qp = hns_roce_v2_destroy_qp, + .post_send = hns_roce_v2_post_send, + .post_recv = hns_roce_v2_post_recv, + /* CQ operations */ + .modify_cq = hns_roce_v2_modify_cq, + .req_notify_cq = hns_roce_v2_req_notify_cq, + .poll_cq = hns_roce_v2_poll_cq, +}; + static const struct hns_roce_hw hns_roce_hw_v2 = { .cmq_init = hns_roce_v2_cmq_init, .cmq_exit = hns_roce_v2_cmq_exit, @@ -5367,6 +5379,7 @@ static const struct hns_roce_hw hns_roce_hw_v2 = { .poll_cq = hns_roce_v2_poll_cq, .init_eq = hns_roce_v2_init_eq_table, .cleanup_eq = hns_roce_v2_cleanup_eq_table, + .hns_roce_dev_ops = &hns_roce_v2_dev_ops, }; static const struct pci_device_id hns_roce_hw_v2_pci_tbl[] = { diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c index 1b3ee514f2ef..addbe443b130 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -440,6 +440,59 @@ static void hns_roce_unregister_device(struct hns_roce_dev *hr_dev) ib_unregister_device(&hr_dev->ib_dev); } +static const struct ib_device_ops hns_roce_dev_ops = { + /* Device operations */ + .modify_device = hns_roce_modify_device, + .query_device = hns_roce_query_device, + /* Port operations */ + .query_port = hns_roce_query_port, + .modify_port = hns_roce_modify_port, + .get_link_layer = hns_roce_get_link_layer, + .get_netdev = hns_roce_get_netdev, + .get_port_immutable = hns_roce_port_immutable, + /* GID operations */ + .add_gid = hns_roce_add_gid, + .del_gid = hns_roce_del_gid, + /* PKey operations */ + .query_pkey = hns_roce_query_pkey, + /* Ucontext operations */ + .alloc_ucontext = hns_roce_alloc_ucontext, + .dealloc_ucontext = hns_roce_dealloc_ucontext, + .mmap = hns_roce_mmap, + .disassociate_ucontext = hns_roce_disassociate_ucontext, + /* PD operations */ + .alloc_pd = hns_roce_alloc_pd, + .dealloc_pd = hns_roce_dealloc_pd, + /* AH operations */ + .create_ah = hns_roce_create_ah, + .query_ah = hns_roce_query_ah, + .destroy_ah = hns_roce_destroy_ah, + /* QP operations */ + .create_qp = hns_roce_create_qp, + .modify_qp = hns_roce_modify_qp, + /* CQ operations */ + .create_cq = hns_roce_ib_create_cq, + .destroy_cq = hns_roce_ib_destroy_cq, + /* MR operations */ + .get_dma_mr = hns_roce_get_dma_mr, + .reg_user_mr = hns_roce_reg_user_mr, + .dereg_mr = hns_roce_dereg_mr, +}; + +static const struct ib_device_ops hns_roce_dev_mr_ops = { + .rereg_user_mr = hns_roce_rereg_user_mr, +}; + +static const struct ib_device_ops hns_roce_dev_mw_ops = { + .alloc_mw = hns_roce_alloc_mw, + .dealloc_mw = hns_roce_dealloc_mw, +}; + +static const struct ib_device_ops hns_roce_dev_frmr_ops = { + .alloc_mr = hns_roce_alloc_mr, + .map_mr_sg = hns_roce_map_mr_sg, +}; + static int hns_roce_register_device(struct hns_roce_dev *hr_dev) { int ret; @@ -479,73 +532,26 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev) ib_dev->uverbs_ex_cmd_mask |= (1ULL << IB_USER_VERBS_EX_CMD_MODIFY_CQ); - /* HCA||device||port */ - ib_dev->modify_device = hns_roce_modify_device; - ib_dev->query_device = hns_roce_query_device; - ib_dev->query_port = hns_roce_query_port; - ib_dev->modify_port = hns_roce_modify_port; - ib_dev->get_link_layer = hns_roce_get_link_layer; - ib_dev->get_netdev = hns_roce_get_netdev; - ib_dev->add_gid = hns_roce_add_gid; - ib_dev->del_gid = hns_roce_del_gid; - ib_dev->query_pkey = hns_roce_query_pkey; - ib_dev->alloc_ucontext = hns_roce_alloc_ucontext; - ib_dev->dealloc_ucontext = hns_roce_dealloc_ucontext; - ib_dev->mmap = hns_roce_mmap; - - /* PD */ - ib_dev->alloc_pd = hns_roce_alloc_pd; - ib_dev->dealloc_pd = hns_roce_dealloc_pd; - - /* AH */ - ib_dev->create_ah = hns_roce_create_ah; - ib_dev->query_ah = hns_roce_query_ah; - ib_dev->destroy_ah = hns_roce_destroy_ah; - - /* QP */ - ib_dev->create_qp = hns_roce_create_qp; - ib_dev->modify_qp = hns_roce_modify_qp; - ib_dev->query_qp = hr_dev->hw->query_qp; - ib_dev->destroy_qp = hr_dev->hw->destroy_qp; - ib_dev->post_send = hr_dev->hw->post_send; - ib_dev->post_recv = hr_dev->hw->post_recv; - - /* CQ */ - ib_dev->create_cq = hns_roce_ib_create_cq; - ib_dev->modify_cq = hr_dev->hw->modify_cq; - ib_dev->destroy_cq = hns_roce_ib_destroy_cq; - ib_dev->req_notify_cq = hr_dev->hw->req_notify_cq; - ib_dev->poll_cq = hr_dev->hw->poll_cq; - - /* MR */ - ib_dev->get_dma_mr = hns_roce_get_dma_mr; - ib_dev->reg_user_mr = hns_roce_reg_user_mr; - ib_dev->dereg_mr = hns_roce_dereg_mr; if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_REREG_MR) { - ib_dev->rereg_user_mr = hns_roce_rereg_user_mr; ib_dev->uverbs_cmd_mask |= (1ULL << IB_USER_VERBS_CMD_REREG_MR); + ib_set_device_ops(ib_dev, &hns_roce_dev_mr_ops); } /* MW */ if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_MW) { - ib_dev->alloc_mw = hns_roce_alloc_mw; - ib_dev->dealloc_mw = hns_roce_dealloc_mw; ib_dev->uverbs_cmd_mask |= (1ULL << IB_USER_VERBS_CMD_ALLOC_MW) | (1ULL << IB_USER_VERBS_CMD_DEALLOC_MW); + ib_set_device_ops(ib_dev, &hns_roce_dev_mw_ops); } /* FRMR */ - if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_FRMR) { - ib_dev->alloc_mr = hns_roce_alloc_mr; - ib_dev->map_mr_sg = hns_roce_map_mr_sg; - } - - /* OTHERS */ - ib_dev->get_port_immutable = hns_roce_port_immutable; - ib_dev->disassociate_ucontext = hns_roce_disassociate_ucontext; + if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_FRMR) + ib_set_device_ops(ib_dev, &hns_roce_dev_frmr_ops); ib_dev->driver_id = RDMA_DRIVER_HNS; + ib_set_device_ops(ib_dev, hr_dev->hw->hns_roce_dev_ops); + ib_set_device_ops(ib_dev, &hns_roce_dev_ops); ret = ib_register_device(ib_dev, "hns_%d", NULL); if (ret) { dev_err(dev, "ib_register_device failed!\n");