Received: by 10.213.65.68 with SMTP id h4csp1689203imn; Thu, 29 Mar 2018 09:10:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx48BgFFTE6JxSDUgcNPaAoz8Qbkgqnxs3myuHZ3TpfIRQthBZMaR8fd8IDwV5agkUOgprrAW X-Received: by 10.98.80.5 with SMTP id e5mr6868685pfb.131.1522339848931; Thu, 29 Mar 2018 09:10:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522339848; cv=none; d=google.com; s=arc-20160816; b=I16BHICSe75mzbFzVkN6T9w+38d7uuVcvD9esDl74ED7bKXohpJFEwB7VJ/YLa73BI EVooptHIqfkmJohFrntwoErm0I6CzoBapiae4Dij2YkTgqWXNBbeVpI7Y4noNKMjnXXM gWuxq6OErfvg6tK8UUAvyjnCDEYt7PhSbnYzy1fvF7lGH0iL4DfOskJfarpb8iA+SXyn hFtQBzguyeKw2qyShIX3DqJoB2nmCje3BbbfasEXecCwdjgNW/LDkL5UQGgDRnm6NDCT 1oeeevOSy+1X5qwRqOF7dwI6Jlqr56rj3CqF+NUhbb8l1ZqlPgJaJMFs2MJ6nRm9uVYt +2tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=JQYs/vHH8hqV8OjdwF+yV0RNv96h17IJXNhUbV5/zxQ=; b=pqRyetkb17FnMvtmyxiKMWXh5TfC9P0i2rD87KGl2r3QNcKOyyk85Tt9uoP782QYZ6 XwTNedmQ6opYq3tOaptQULO4LCx/BoVScFlzMFWcQLJ4np619Q7nZahALJyANkSsPIwm DFkMU1Q5Fu84Pu+4JqBkFb5x6ykUTAoPFM699bf6vmSsw/iu6ZLB0XkHnTvxKSigB48n 7HAt+cBumGVDCRtEILUEo44raZ4kmVGTD/zldPSH6dNr9byhvG3VcbDaReg2wpn6f2U4 f4e+4JAl6HdfentjFe79uraeESB5bHpUSyn5nKCtPLtWGOfZ1VKtow8/lTdcid/nFRDa Fj8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l14si4226647pgs.309.2018.03.29.09.10.35; Thu, 29 Mar 2018 09:10:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752663AbeC2QIf (ORCPT + 99 others); Thu, 29 Mar 2018 12:08:35 -0400 Received: from ale.deltatee.com ([207.54.116.67]:46334 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751714AbeC2QHd (ORCPT ); Thu, 29 Mar 2018 12:07:33 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1f1a5K-0005mf-OA; Thu, 29 Mar 2018 10:07:32 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1f1a5I-0001ES-V1; Thu, 29 Mar 2018 10:07:28 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org Cc: Christoph Hellwig , Sagi Grimberg , James Smart , Logan Gunthorpe Date: Thu, 29 Mar 2018 10:07:18 -0600 Message-Id: <20180329160721.4691-2-logang@deltatee.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180329160721.4691-1-logang@deltatee.com> References: <20180329160721.4691-1-logang@deltatee.com> X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, hch@lst.de, sagi@grimberg.me, james.smart@broadcom.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_FREE,MYRULES_NO_TEXT,T_RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 Subject: [PATCH 1/4] nvmet: Introduce helper functions to allocate and free request SGLs X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add helpers to allocate and free the SGL in a struct nvmet_req: int nvmet_req_alloc_sgl(struct nvmet_req *req, struct nvmet_sq *sq) void nvmet_req_free_sgl(struct nvmet_req *req) This will be expanded in a future patch to implement peer-to-peer memory and should be common with all target drivers. The presently unused sq argument in the alloc function will be necessary to decide whether to use peer-to-peer memory and obtain the correct provider to allocate the memory. Signed-off-by: Logan Gunthorpe Cc: Christoph Hellwig Cc: Sagi Grimberg --- drivers/nvme/target/core.c | 16 ++++++++++++++++ drivers/nvme/target/nvmet.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index a78029e4e5f4..3770fb812657 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -575,6 +575,22 @@ void nvmet_req_execute(struct nvmet_req *req) } EXPORT_SYMBOL_GPL(nvmet_req_execute); +int nvmet_req_alloc_sgl(struct nvmet_req *req, struct nvmet_sq *sq) +{ + req->sg = sgl_alloc(req->transfer_len, GFP_KERNEL, &req->sg_cnt); + if (!req->sg) + return -ENOMEM; + + return 0; +} +EXPORT_SYMBOL_GPL(nvmet_req_alloc_sgl); + +void nvmet_req_free_sgl(struct nvmet_req *req) +{ + sgl_free(req->sg); +} +EXPORT_SYMBOL_GPL(nvmet_req_free_sgl); + static inline bool nvmet_cc_en(u32 cc) { return (cc >> NVME_CC_EN_SHIFT) & 0x1; diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 417f6c0331cc..6f74cb2b7e37 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -271,6 +271,8 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq, void nvmet_req_uninit(struct nvmet_req *req); void nvmet_req_execute(struct nvmet_req *req); void nvmet_req_complete(struct nvmet_req *req, u16 status); +int nvmet_req_alloc_sgl(struct nvmet_req *req, struct nvmet_sq *sq); +void nvmet_req_free_sgl(struct nvmet_req *req); void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq, u16 qid, u16 size); -- 2.11.0