Received: by 10.192.165.148 with SMTP id m20csp3987145imm; Mon, 23 Apr 2018 16:35:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx48ZgqzQjV8rA4ASYCd/PGQlRCl0zkNSX58I7jc5CVKQWhoySMYre67AsSdAcSXyYG1Z6tU8 X-Received: by 10.98.157.90 with SMTP id i87mr17007146pfd.190.1524526549949; Mon, 23 Apr 2018 16:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524526549; cv=none; d=google.com; s=arc-20160816; b=FneJP8SpGIfwahFWRYfmTQZfbzglAiBUXnUrFr+nfxkEY1KOyvnQcTHTS79RMR73PO enmMT/liLwEF4D+odbEH8tfL4Ptd0T6yLqFe2lzQSTEGlvO4s/Sye367JNuYaUhppPwt o8WhLB92MeYRXmm0EgOjWajUwv0ZSl2rji9LpJJY7fhQM06zCTZVuwf1ZZ31P9UV8sHR DC15StJyGLnD1hgGBgpsgn40kyvRPgA1S7t80qAJ6+8JZrGRVRezyC456wptgvykdVzi 1QHkGNK5iDHaFZNi/bPkoPZJY6DfE/ctgOQ6+GCnFItauqPITLhRHjBcpPAubZ8WfrNR 6GDg== 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=i1IJeCZWbp/msEhiJr0TagVeZpsDvX3LadwsahCXXxU=; b=A3Iyn+hKFXpp1kcOhOhC3op09KG1o1o9Ymty1B3kYKa9FR4cTaDsr6TPctA7a/TrRx Ssn9hchkplR+yayTvsQcCSb8xay5ks54wzLVD1jvO1gxuBA854UOCKKrN1LS2xJRFR55 38EAasGRPyHAoWbLIexF8fBUN9Gk/EBTGW/GBz786y+/Sb0G/bn2/cG+KflMoxALhw45 S1PqEpoH5bUvaA5m46VeJzzdnYCy/27YHuLcF2ITg0JgQDoaj+IER1L0d2vWg0gHrZIp 6YhgC7HrNfA9qTD4p7e5o1H7zbFS5+LBL1GARdZcrLCGB/2R3OMEkJBOQpZ6ZDD8Uy2a fYZw== 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 92-v6si12453535pli.354.2018.04.23.16.35.35; Mon, 23 Apr 2018 16:35:49 -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 S932837AbeDWXck (ORCPT + 99 others); Mon, 23 Apr 2018 19:32:40 -0400 Received: from ale.deltatee.com ([207.54.116.67]:41938 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932643AbeDWXbF (ORCPT ); Mon, 23 Apr 2018 19:31:05 -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 1fAkvB-0006JB-Oq; Mon, 23 Apr 2018 17:31:00 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1fAkv4-0005bs-1A; Mon, 23 Apr 2018 17:30:50 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org, linux-nvdimm@lists.01.org, linux-block@vger.kernel.org Cc: Stephen Bates , Christoph Hellwig , Jens Axboe , Keith Busch , Sagi Grimberg , Bjorn Helgaas , Jason Gunthorpe , Max Gurtovoy , Dan Williams , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Benjamin Herrenschmidt , Alex Williamson , =?UTF-8?q?Christian=20K=C3=B6nig?= , Logan Gunthorpe Date: Mon, 23 Apr 2018 17:30:44 -0600 Message-Id: <20180423233046.21476-13-logang@deltatee.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180423233046.21476-1-logang@deltatee.com> References: <20180423233046.21476-1-logang@deltatee.com> X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org, linux-block@vger.kernel.org, sbates@raithlin.com, hch@lst.de, axboe@kernel.dk, sagi@grimberg.me, bhelgaas@google.com, jgg@mellanox.com, maxg@mellanox.com, keith.busch@intel.com, dan.j.williams@intel.com, benh@kernel.crashing.org, jglisse@redhat.com, alex.williamson@redhat.com, christian.koenig@amd.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=-6.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_FREE,MYRULES_NO_TEXT autolearn=no autolearn_force=no version=3.4.1 Subject: [PATCH v4 12/14] 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 DMAs 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 | 18 ++++++++++++++++++ drivers/nvme/target/nvmet.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index e95424f172fd..75d44bc3e8d3 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -575,6 +575,24 @@ 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); + req->sg = NULL; + req->sg_cnt = 0; +} +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 15fd84ab21f8..10b162615a5e 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -273,6 +273,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