From: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Yixian Liu <liuyixian-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Cc: jgg-uk2M96/98Pc@public.gmane.org,
dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH for-next 1/4] RDMA/hns: Support rq record doorbell for the user space
Date: Mon, 22 Jan 2018 10:08:52 +0200 [thread overview]
Message-ID: <20180122080852.GI1393@mtr-leonro.local> (raw)
In-Reply-To: <1516242871-154089-2-git-send-email-liuyixian-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 12597 bytes --]
On Thu, Jan 18, 2018 at 10:34:28AM +0800, Yixian Liu wrote:
> This patch adds interfaces and definitions to support the rq record
> doorbell for the user space.
>
> Signed-off-by: Yixian Liu <liuyixian-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Lijun Ou <oulijun-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Wei Hu (Xavier) <xavier.huwei-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Shaobo Xu <xushaobo2-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> ---
> drivers/infiniband/hw/hns/Makefile | 2 +-
> drivers/infiniband/hw/hns/hns_roce_db.c | 94 +++++++++++++++++++++++++++++
> drivers/infiniband/hw/hns/hns_roce_device.h | 41 ++++++++++++-
> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 22 ++++++-
> drivers/infiniband/hw/hns/hns_roce_main.c | 5 ++
> drivers/infiniband/hw/hns/hns_roce_qp.c | 32 +++++++++-
> 6 files changed, 191 insertions(+), 5 deletions(-)
> create mode 100644 drivers/infiniband/hw/hns/hns_roce_db.c
>
> diff --git a/drivers/infiniband/hw/hns/Makefile b/drivers/infiniband/hw/hns/Makefile
> index 97bf2cd..cf03404 100644
> --- a/drivers/infiniband/hw/hns/Makefile
> +++ b/drivers/infiniband/hw/hns/Makefile
> @@ -7,7 +7,7 @@ ccflags-y := -Idrivers/net/ethernet/hisilicon/hns3
> obj-$(CONFIG_INFINIBAND_HNS) += hns-roce.o
> hns-roce-objs := hns_roce_main.o hns_roce_cmd.o hns_roce_pd.o \
> hns_roce_ah.o hns_roce_hem.o hns_roce_mr.o hns_roce_qp.o \
> - hns_roce_cq.o hns_roce_alloc.o
> + hns_roce_cq.o hns_roce_alloc.o hns_roce_db.o
> obj-$(CONFIG_INFINIBAND_HNS_HIP06) += hns-roce-hw-v1.o
> hns-roce-hw-v1-objs := hns_roce_hw_v1.o
> obj-$(CONFIG_INFINIBAND_HNS_HIP08) += hns-roce-hw-v2.o
> diff --git a/drivers/infiniband/hw/hns/hns_roce_db.c b/drivers/infiniband/hw/hns/hns_roce_db.c
> new file mode 100644
> index 0000000..0908208
> --- /dev/null
> +++ b/drivers/infiniband/hw/hns/hns_roce_db.c
> @@ -0,0 +1,94 @@
> +/*
> + * Copyright (c) 2017 Hisilicon Limited.
> + * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
Good to know
> + *
> + * This software is available to you under a choice of one of two
> + * licenses. You may choose to be licensed under the terms of the GNU
> + * General Public License (GPL) Version 2, available from the file
> + * COPYING in the main directory of this source tree, or the
> + * OpenIB.org BSD license below:
> + *
> + * Redistribution and use in source and binary forms, with or
> + * without modification, are permitted provided that the following
> + * conditions are met:
> + *
> + * - Redistributions of source code must retain the above
> + * copyright notice, this list of conditions and the following
> + * disclaimer.
> + *
> + * - Redistributions in binary form must reproduce the above
> + * copyright notice, this list of conditions and the following
> + * disclaimer in the documentation and/or other materials
> + * provided with the distribution.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
Please move to use SPDX headers for new files.
> +
> +#include <linux/platform_device.h>
> +#include <rdma/ib_umem.h>
> +#include "hns_roce_device.h"
> +
> +int hns_roce_db_map_user(struct hns_roce_ucontext *context, unsigned long virt,
> + struct hns_roce_db *db)
> +{
> + struct hns_roce_user_db_page *db_page;
> + int ret = 0;
> +
> + mutex_lock(&context->db_page_mutex);
> +
> + list_for_each_entry(db_page, &context->db_page_list, list)
> + if (db_page->user_virt == (virt & PAGE_MASK))
> + goto found;
> +
> + db_page = kmalloc(sizeof(*db_page), GFP_KERNEL);
> + if (!db_page) {
> + ret = -ENOMEM;
> + goto out;
> + }
> +
> + db_page->user_virt = (virt & PAGE_MASK);
> + db_page->refcnt = 0;
> + db_page->umem = ib_umem_get(&context->ibucontext, virt & PAGE_MASK,
> + PAGE_SIZE, 0, 0);
> + if (IS_ERR(db_page->umem)) {
> + ret = PTR_ERR(db_page->umem);
> + kfree(db_page);
> + goto out;
> + }
> +
> + list_add(&db_page->list, &context->db_page_list);
> +
> +found:
> + db->dma = sg_dma_address(db_page->umem->sg_head.sgl) +
> + (virt & ~PAGE_MASK);
> + db->u.user_page = db_page;
> + ++db_page->refcnt;
> +
> +out:
> + mutex_unlock(&context->db_page_mutex);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL(hns_roce_db_map_user);
> +
> +void hns_roce_db_unmap_user(struct hns_roce_ucontext *context,
> + struct hns_roce_db *db)
> +{
> + mutex_lock(&context->db_page_mutex);
> +
> + if (!--db->u.user_page->refcnt) {
> + list_del(&db->u.user_page->list);
> + ib_umem_release(db->u.user_page->umem);
> + kfree(db->u.user_page);
> + }
> +
> + mutex_unlock(&context->db_page_mutex);
> +}
> +EXPORT_SYMBOL(hns_roce_db_unmap_user);
> diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h
> index 42c3b5a..65c09c5 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_device.h
> +++ b/drivers/infiniband/hw/hns/hns_roce_device.h
> @@ -178,7 +178,8 @@ enum {
> enum {
> HNS_ROCE_CAP_FLAG_REREG_MR = BIT(0),
> HNS_ROCE_CAP_FLAG_ROCE_V1_V2 = BIT(1),
> - HNS_ROCE_CAP_FLAG_RQ_INLINE = BIT(2)
> + HNS_ROCE_CAP_FLAG_RQ_INLINE = BIT(2),
> + HNS_ROCE_CAP_FLAG_RECORD_DB = BIT(3)
> };
>
> enum hns_roce_mtt_type {
> @@ -186,6 +187,10 @@ enum hns_roce_mtt_type {
> MTT_TYPE_CQE,
> };
>
> +enum {
> + HNS_ROCE_DB_PER_PAGE = PAGE_SIZE / 4
> +};
> +
> #define HNS_ROCE_CMD_SUCCESS 1
>
> #define HNS_ROCE_PORT_DOWN 0
> @@ -203,6 +208,8 @@ struct hns_roce_uar {
> struct hns_roce_ucontext {
> struct ib_ucontext ibucontext;
> struct hns_roce_uar uar;
> + struct list_head db_page_list;
> + struct mutex db_page_mutex;
> };
>
> struct hns_roce_pd {
> @@ -335,6 +342,33 @@ struct hns_roce_buf {
> int page_shift;
> };
>
> +struct hns_roce_db_pgdir {
> + struct list_head list;
> + DECLARE_BITMAP(order0, HNS_ROCE_DB_PER_PAGE);
> + DECLARE_BITMAP(order1, HNS_ROCE_DB_PER_PAGE / 2);
> + unsigned long *bits[2];
I didn't see any usage of the fields from this struct in this patch,
where did you use them?
> + u32 *db_page;
> + dma_addr_t db_dma;
> +};
> +
> +struct hns_roce_user_db_page {
> + struct list_head list;
> + struct ib_umem *umem;
> + unsigned long user_virt;
> + int refcnt;
refcount_t please.
> +};
> +
> +struct hns_roce_db {
> + u32 *db_record;
> + union {
> + struct hns_roce_db_pgdir *pgdir;
> + struct hns_roce_user_db_page *user_page;
> + } u;
> + dma_addr_t dma;
> + int index;
> + int order;
> +};
> +
> struct hns_roce_cq_buf {
> struct hns_roce_buf hr_buf;
> struct hns_roce_mtt hr_mtt;
> @@ -465,6 +499,7 @@ struct hns_roce_rinl_buf {
> struct hns_roce_qp {
> struct ib_qp ibqp;
> struct hns_roce_buf hr_buf;
> + struct hns_roce_db rdb;
> struct hns_roce_wq rq;
> __le64 doorbell_qpn;
> __le32 sq_signal_bits;
> @@ -930,6 +965,10 @@ struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev,
> int hns_roce_ib_destroy_cq(struct ib_cq *ib_cq);
> void hns_roce_free_cq(struct hns_roce_dev *hr_dev, struct hns_roce_cq *hr_cq);
>
> +int hns_roce_db_map_user(struct hns_roce_ucontext *context, unsigned long virt,
> + struct hns_roce_db *db);
> +void hns_roce_db_unmap_user(struct hns_roce_ucontext *context,
> + struct hns_roce_db *db);
> void hns_roce_cq_completion(struct hns_roce_dev *hr_dev, u32 cqn);
> void hns_roce_cq_event(struct hns_roce_dev *hr_dev, u32 cqn, int event_type);
> void hns_roce_qp_event(struct hns_roce_dev *hr_dev, u32 qpn, int event_type);
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> index 256fe11..e0f4dc4 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> @@ -1140,7 +1140,8 @@ static int hns_roce_v2_profile(struct hns_roce_dev *hr_dev)
>
> caps->flags = HNS_ROCE_CAP_FLAG_REREG_MR |
> HNS_ROCE_CAP_FLAG_ROCE_V1_V2 |
> - HNS_ROCE_CAP_FLAG_RQ_INLINE;
> + HNS_ROCE_CAP_FLAG_RQ_INLINE |
> + HNS_ROCE_CAP_FLAG_RECORD_DB;
> caps->pkey_table_len[0] = 1;
> caps->gid_table_len[0] = HNS_ROCE_V2_GID_INDEX_NUM;
> caps->ceqe_depth = HNS_ROCE_V2_COMP_EQE_NUM;
> @@ -2246,6 +2247,19 @@ static void modify_qp_reset_to_init(struct ib_qp *ibqp,
> hr_qp->qkey = attr->qkey;
> }
>
> + roce_set_bit(context->byte_68_rq_db, V2_QPC_BYTE_68_RQ_RECORD_EN_S, 1);
> + roce_set_bit(qpc_mask->byte_68_rq_db, V2_QPC_BYTE_68_RQ_RECORD_EN_S, 0);
> +
> + roce_set_field(context->byte_68_rq_db,
> + V2_QPC_BYTE_68_RQ_DB_RECORD_ADDR_M,
> + V2_QPC_BYTE_68_RQ_DB_RECORD_ADDR_S,
> + ((u32)hr_qp->rdb.dma) >> 1);
> + roce_set_field(qpc_mask->byte_68_rq_db,
> + V2_QPC_BYTE_68_RQ_DB_RECORD_ADDR_M,
> + V2_QPC_BYTE_68_RQ_DB_RECORD_ADDR_S, 0);
> + context->rq_db_record_addr = hr_qp->rdb.dma >> 32;
> + qpc_mask->rq_db_record_addr = 0;
> +
> roce_set_bit(context->byte_76_srqn_op_en, V2_QPC_BYTE_76_RQIE_S, 1);
> roce_set_bit(qpc_mask->byte_76_srqn_op_en, V2_QPC_BYTE_76_RQIE_S, 0);
>
> @@ -3183,6 +3197,8 @@ static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
> hr_qp->sq.tail = 0;
> hr_qp->sq_next_wqe = 0;
> hr_qp->next_sge = 0;
> + if (hr_qp->rq.wqe_cnt)
> + *hr_qp->rdb.db_record = 0;
> }
>
> out:
> @@ -3409,6 +3425,10 @@ static int hns_roce_v2_destroy_qp_common(struct hns_roce_dev *hr_dev,
> hns_roce_mtt_cleanup(hr_dev, &hr_qp->mtt);
>
> if (is_user) {
> + if (hr_qp->rq.wqe_cnt)
> + hns_roce_db_unmap_user(
> + to_hr_ucontext(hr_qp->ibqp.uobject->context),
> + &hr_qp->rdb);
> ib_umem_release(hr_qp->umem);
> } else {
> kfree(hr_qp->sq.wrid);
> diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c
> index aa0c242..dd7d882 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_main.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_main.c
> @@ -350,6 +350,11 @@ static struct ib_ucontext *hns_roce_alloc_ucontext(struct ib_device *ib_dev,
> if (ret)
> goto error_fail_uar_alloc;
>
> + if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) {
> + INIT_LIST_HEAD(&context->db_page_list);
> + mutex_init(&context->db_page_mutex);
> + }
> +
> ret = ib_copy_to_udata(udata, &resp, sizeof(resp));
> if (ret)
> goto error_fail_copy_to_udata;
> diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c
> index 4414cea..300f760 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_qp.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c
> @@ -489,6 +489,15 @@ static int hns_roce_set_kernel_sq_size(struct hns_roce_dev *hr_dev,
> return 0;
> }
>
> +static int hns_roce_qp_has_rq(struct ib_qp_init_attr *attr)
> +{
> + if (attr->qp_type == IB_QPT_XRC_INI ||
> + attr->qp_type == IB_QPT_XRC_TGT || attr->srq)
> + return 0;
> +
> + return 1;
> +}
> +
> static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
> struct ib_pd *ib_pd,
> struct ib_qp_init_attr *init_attr,
> @@ -602,6 +611,17 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
> dev_err(dev, "hns_roce_ib_umem_write_mtt error for create qp\n");
> goto err_mtt;
> }
> +
> + if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) &&
> + hns_roce_qp_has_rq(init_attr)) {
> + ret = hns_roce_db_map_user(
> + to_hr_ucontext(ib_pd->uobject->context),
> + ucmd.db_addr, &hr_qp->rdb);
> + if (ret) {
> + dev_err(dev, "rp record doorbell map failed!\n");
> + goto err_mtt;
> + }
> + }
> } else {
> if (init_attr->create_flags &
> IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK) {
> @@ -707,8 +727,16 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
> hns_roce_release_range_qp(hr_dev, qpn, 1);
>
> err_wrid:
> - kfree(hr_qp->sq.wrid);
> - kfree(hr_qp->rq.wrid);
> + if (ib_pd->uobject) {
> + if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) &&
> + hns_roce_qp_has_rq(init_attr))
> + hns_roce_db_unmap_user(
> + to_hr_ucontext(ib_pd->uobject->context),
> + &hr_qp->rdb);
> + } else {
> + kfree(hr_qp->sq.wrid);
> + kfree(hr_qp->rq.wrid);
> + }
>
> err_mtt:
> hns_roce_mtt_cleanup(hr_dev, &hr_qp->mtt);
> --
> 1.9.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-01-22 8:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-18 2:34 [PATCH for-next 0/4] Support rq record doorbell and cq record doorbell Yixian Liu
[not found] ` <1516242871-154089-1-git-send-email-liuyixian-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2018-01-18 2:34 ` [PATCH for-next 1/4] RDMA/hns: Support rq record doorbell for the user space Yixian Liu
[not found] ` <1516242871-154089-2-git-send-email-liuyixian-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2018-01-22 8:08 ` Leon Romanovsky [this message]
[not found] ` <20180122080852.GI1393-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2018-01-22 13:33 ` Liuyixian (Eason)
2018-01-18 2:34 ` [PATCH for-next 2/4] RDMA/hns: Support cq " Yixian Liu
2018-01-18 2:34 ` [PATCH for-next 3/4] RDMA/hns: Support rq record doorbell for kernel space Yixian Liu
[not found] ` <1516242871-154089-4-git-send-email-liuyixian-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2018-01-23 11:07 ` Leon Romanovsky
[not found] ` <20180123110740.GR1393-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2018-01-24 12:40 ` Liuyixian (Eason)
[not found] ` <c5cfd489-e589-1d01-ef7a-718d3dc6d4e5-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2018-01-24 13:21 ` Leon Romanovsky
[not found] ` <20180124132139.GK1393-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2018-01-25 12:57 ` Liuyixian (Eason)
[not found] ` <443225ea-5a6a-5d7f-8136-b061e087f271-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2018-01-29 11:29 ` Leon Romanovsky
2018-01-18 2:34 ` [PATCH for-next 4/4] RDMA/hns: Support cq " Yixian Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180122080852.GI1393@mtr-leonro.local \
--to=leon-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=jgg-uk2M96/98Pc@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=liuyixian-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox