Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3729681iob; Tue, 17 May 2022 06:15:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO6atqlsb8AQj1Xd7sig4b0ysY+0edYMIphcXGR0y/y/DDhwNXKKyX0eaiObNgXnomfJOQ X-Received: by 2002:a17:903:2310:b0:15e:bc9c:18b9 with SMTP id d16-20020a170903231000b0015ebc9c18b9mr23150773plh.58.1652793312753; Tue, 17 May 2022 06:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652793312; cv=none; d=google.com; s=arc-20160816; b=fLPR21j9+OcBdrv5RWhNjiFWuFvft1cqaoe+v9XaXFL0P/DCBih5KlGANUbJOWHLsT BSR890LmOlbo0rrEhJbff2wl3U3FKXpttaAaOQ5RyAjBWbQVsChis1jDHuwTtR9KzrN/ GtMegZ2ViOVTZwq7DBsg5rjlCcPYlbjPpVWOPZYu0ewFKKkt4K26R3CVGpJ39W+8LyMl kXqrh7OdiPdTL/7dp5l4R6VnOfNZAWaMz3kFRsaA/wWt4tNRglT0vOVtIokLbTraLF2F T5OtqPvs9s/5eOtBAJdZk+HkXKeFN8Fb7gmY7K1fnuRJlys1K6ftI/ViYBE+QP7H7yhT R9kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=hEF94zBhhFc6cjWkWz8qz+16QCWVZ8PWfrlcF7EcnHA=; b=Boq7ptKVi7Il1KC5wozv5YZ4W2RnLiM8i55c1A1d30Hc3qLPFaKH3pFWScQ9hd4B4U ig3QB8XN89uXldSbO6xvRjOmFy4lXfMxSXFTWlqZ2R5qZ0BQfp0EjZGevLqQKGwgw6Pz u23aL5Zbuz3P3+brrHg0h8QNYAyvopE95yTWLcyKFh8luLIEdZbGU+Qe53/1D5WGVgCJ mZJY1YW7GdMMz40UhzpnVRuNl1oVCK+unrMR0yITQvVzdUErCLbQY95HKms/cKDNe+jR 55s1olY1iPTXSIj5SBZCuV9F9mdNqaYS4g1JU5Q5fIMWtHabGBqi+pSehxUSIuJxb1Ja UzIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b=Pyan3u3t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxonhyperv.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020a655c04000000b003abada69f69si13583996pgr.282.2022.05.17.06.14.59; Tue, 17 May 2022 06:15:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b=Pyan3u3t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxonhyperv.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237076AbiEQJHH (ORCPT + 99 others); Tue, 17 May 2022 05:07:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244142AbiEQJEw (ORCPT ); Tue, 17 May 2022 05:04:52 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 04E3548E6C; Tue, 17 May 2022 02:04:49 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1004) id CE71A20F7227; Tue, 17 May 2022 02:04:48 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CE71A20F7227 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1652778288; bh=hEF94zBhhFc6cjWkWz8qz+16QCWVZ8PWfrlcF7EcnHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To:From; b=Pyan3u3tvxDtmd5lOVAfm3I8LnNm4GqSnHV94Napn2Yy23L4EFqYx7RrXOWhTINx5 +bZFYnkeeoyFs73Od3p8ppkPbg1QSScx1bqECWb3gft+2sgPt3Rb1YgpInt7M5LlN8 jSaUMjjEsGBg9r+hG5OD/+UJJGZr7yW0D4VwThho= From: longli@linuxonhyperv.com To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Jason Gunthorpe , Leon Romanovsky Cc: linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Long Li Subject: [PATCH 04/12] net: mana: Add functions for allocating doorbell page from GDMA Date: Tue, 17 May 2022 02:04:28 -0700 Message-Id: <1652778276-2986-5-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1652778276-2986-1-git-send-email-longli@linuxonhyperv.com> References: <1652778276-2986-1-git-send-email-longli@linuxonhyperv.com> Reply-To: longli@microsoft.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Long Li The RDMA device needs to allocate doorbell pages for each user context. Implement those functions and expose them for use by the RDMA driver. Signed-off-by: Long Li --- drivers/net/ethernet/microsoft/mana/gdma.h | 29 ++++++++++ .../net/ethernet/microsoft/mana/gdma_main.c | 54 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/drivers/net/ethernet/microsoft/mana/gdma.h b/drivers/net/ethernet/microsoft/mana/gdma.h index c724ca410fcb..f945755760dc 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma.h +++ b/drivers/net/ethernet/microsoft/mana/gdma.h @@ -22,11 +22,15 @@ enum gdma_request_type { GDMA_GENERATE_TEST_EQE = 10, GDMA_CREATE_QUEUE = 12, GDMA_DISABLE_QUEUE = 13, + GDMA_ALLOCATE_RESOURCE_RANGE = 22, + GDMA_DESTROY_RESOURCE_RANGE = 24, GDMA_CREATE_DMA_REGION = 25, GDMA_DMA_REGION_ADD_PAGES = 26, GDMA_DESTROY_DMA_REGION = 27, }; +#define GDMA_RESOURCE_DOORBELL_PAGE 27 + enum gdma_queue_type { GDMA_INVALID_QUEUE, GDMA_SQ, @@ -568,6 +572,26 @@ struct gdma_register_device_resp { u32 db_id; }; /* HW DATA */ +struct gdma_allocate_resource_range_req { + struct gdma_req_hdr hdr; + u32 resource_type; + u32 num_resources; + u32 alignment; + u32 allocated_resources; +}; + +struct gdma_allocate_resource_range_resp { + struct gdma_resp_hdr hdr; + u32 allocated_resources; +}; + +struct gdma_destroy_resource_range_req { + struct gdma_req_hdr hdr; + u32 resource_type; + u32 num_resources; + u32 allocated_resources; +}; + /* GDMA_CREATE_QUEUE */ struct gdma_create_queue_req { struct gdma_req_hdr hdr; @@ -676,4 +700,9 @@ void mana_gd_free_memory(struct gdma_mem_info *gmi); int mana_gd_send_request(struct gdma_context *gc, u32 req_len, const void *req, u32 resp_len, void *resp); + +int mana_gd_allocate_doorbell_page(struct gdma_context *gc, int *doorbell_page); + +int mana_gd_destroy_doorbell_page(struct gdma_context *gc, int doorbell_page); + #endif /* _GDMA_H */ diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c index 9fafaa0c8e76..86ffe0e39df0 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -153,6 +153,60 @@ void mana_gd_free_memory(struct gdma_mem_info *gmi) gmi->dma_handle); } +int mana_gd_destroy_doorbell_page(struct gdma_context *gc, int doorbell_page) +{ + struct gdma_destroy_resource_range_req req = {}; + struct gdma_resp_hdr resp = {}; + int err; + + mana_gd_init_req_hdr(&req.hdr, GDMA_DESTROY_RESOURCE_RANGE, + sizeof(req), sizeof(resp)); + + req.resource_type = GDMA_RESOURCE_DOORBELL_PAGE; + req.num_resources = 1; + req.allocated_resources = doorbell_page; + + err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp); + if (err || resp.status) { + dev_err(gc->dev, + "Failed to destroy doorbell page: ret %d, 0x%x\n", + err, resp.status); + return err ? err : -EPROTO; + } + + return 0; +} +EXPORT_SYMBOL(mana_gd_destroy_doorbell_page); + +int mana_gd_allocate_doorbell_page(struct gdma_context *gc, + int *doorbell_page) +{ + struct gdma_allocate_resource_range_req req = {}; + struct gdma_allocate_resource_range_resp resp = {}; + int err; + + mana_gd_init_req_hdr(&req.hdr, GDMA_ALLOCATE_RESOURCE_RANGE, + sizeof(req), sizeof(resp)); + + req.resource_type = GDMA_RESOURCE_DOORBELL_PAGE; + req.num_resources = 1; + req.alignment = 0; + req.allocated_resources = 0; // have GDMA start searching from 0 + + err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp); + if (err || resp.hdr.status) { // resp.hdr.status should be >=0 + dev_err(gc->dev, + "Failed to allocate doorbell page: ret %d, 0x%x\n", + err, resp.hdr.status); + return err ? err : -EPROTO; + } + + *doorbell_page = resp.allocated_resources; + + return 0; +} +EXPORT_SYMBOL(mana_gd_allocate_doorbell_page); + static int mana_gd_create_hw_eq(struct gdma_context *gc, struct gdma_queue *queue) { -- 2.17.1