From patchwork Tue Apr 5 14:55:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 8752821 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 32CB8C0553 for ; Tue, 5 Apr 2016 14:57:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 28EE22037E for ; Tue, 5 Apr 2016 14:57:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7854620394 for ; Tue, 5 Apr 2016 14:57:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758711AbcDEO4R (ORCPT ); Tue, 5 Apr 2016 10:56:17 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:34759 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758676AbcDEO4P (ORCPT ); Tue, 5 Apr 2016 10:56:15 -0400 Received: by mail-wm0-f48.google.com with SMTP id l6so27326740wml.1 for ; Tue, 05 Apr 2016 07:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xJ9ijJGU09hd8tH3jQk3xfEFbWnc6d5Dgw6gV+rrfcA=; b=nV5aa7zxOsvfqmeZjKktvCIhc7UklHVmmzIRSEa6wJfm0wvDdHMv39syNt7jRYzGjN xnaVx8BBgFsnCJ5/XRt7lEZajKXoA7yXtAjScVKyvBm5E70EI1HO9KqsHt7CGrKKU9nH cbGoVyXmEwk/FXnIZGv0BuLPH2td4Ipz/xhVg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xJ9ijJGU09hd8tH3jQk3xfEFbWnc6d5Dgw6gV+rrfcA=; b=bgvhb7ngHZq2C4HYB/ChowyOuwmU4L3B5tbrRT3enBd9T0HisTUYsc2LUoKRvWAhFo vsE+L+8MAajA1rtna2nVKirH8kMATSJzNM6+Td2x+ASoqGKWPG8wyzuZKcQjkkl2cMWN UPQ+alwpRAp1uduWQMqOhKEatc8ZbunQ3E+4zLRUq+7hA00lxFH0tOdrQP+Sk1WzYuIU +2OFG7jT6eCRCcjnR9612BxrBE5867JsOqdD1JHqinvzlnA3Xc9pSTASQiMN7TAsTSuW Y/ld96G9pqdxGq2GcuX8tyxmvhlFJX9voKNx/Tso6T13lThJ2zOQYqYUIpL1ahifmMmw RbnQ== X-Gm-Message-State: AD7BkJLhaCArHxl+SYbGLva8OT/6I7cC+dLaKQpPRRtKPGgCJzz6Hko0vGGgHa8/BsfUUg== X-Received: by 10.194.185.179 with SMTP id fd19mr20676191wjc.107.1459868173616; Tue, 05 Apr 2016 07:56:13 -0700 (PDT) Received: from Macroninja.cnexlabs.com (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id av3sm35125573wjc.44.2016.04.05.07.56.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Apr 2016 07:56:12 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 2/5] lightnvm: implement nvm_submit_ppa_list Date: Tue, 5 Apr 2016 16:55:28 +0200 Message-Id: <1459868131-15133-3-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1459868131-15133-1-git-send-email-m@bjorling.me> References: <1459868131-15133-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The nvm_submit_ppa function assumes that users manage all plane blocks as a single block. Extend the API with nvm_submit_ppa_list to allow the user to send its own ppa list. If the user submits more than a single PPA, the user must take care to allocate and free the corresponding ppa list. Signed-off-by: Matias Bjørling Reviewed-by: Johannes Thumshirn --- drivers/lightnvm/core.c | 88 +++++++++++++++++++++++++++++++++++++----------- include/linux/lightnvm.h | 2 ++ 2 files changed, 71 insertions(+), 19 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index c2ef53a..f4e04a5 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -322,11 +322,10 @@ static void nvm_end_io_sync(struct nvm_rq *rqd) complete(waiting); } -int nvm_submit_ppa(struct nvm_dev *dev, struct ppa_addr *ppa, int nr_ppas, - int opcode, int flags, void *buf, int len) +int __nvm_submit_ppa(struct nvm_dev *dev, struct nvm_rq *rqd, int opcode, + int flags, void *buf, int len) { DECLARE_COMPLETION_ONSTACK(wait); - struct nvm_rq rqd; struct bio *bio; int ret; unsigned long hang_check; @@ -335,24 +334,17 @@ int nvm_submit_ppa(struct nvm_dev *dev, struct ppa_addr *ppa, int nr_ppas, if (IS_ERR_OR_NULL(bio)) return -ENOMEM; - memset(&rqd, 0, sizeof(struct nvm_rq)); - ret = nvm_set_rqd_ppalist(dev, &rqd, ppa, nr_ppas); - if (ret) { - bio_put(bio); - return ret; - } + nvm_generic_to_addr_mode(dev, rqd); - rqd.opcode = opcode; - rqd.bio = bio; - rqd.wait = &wait; - rqd.dev = dev; - rqd.end_io = nvm_end_io_sync; - rqd.flags = flags; - nvm_generic_to_addr_mode(dev, &rqd); + rqd->dev = dev; + rqd->opcode = opcode; + rqd->flags = flags; + rqd->bio = bio; + rqd->wait = &wait; + rqd->end_io = nvm_end_io_sync; - ret = dev->ops->submit_io(dev, &rqd); + ret = dev->ops->submit_io(dev, rqd); if (ret) { - nvm_free_rqd_ppalist(dev, &rqd); bio_put(bio); return ret; } @@ -364,9 +356,67 @@ int nvm_submit_ppa(struct nvm_dev *dev, struct ppa_addr *ppa, int nr_ppas, else wait_for_completion_io(&wait); + return rqd->error; +} + +/** + * nvm_submit_ppa_list - submit user-defined ppa list to device. The user must + * take to free ppa list if necessary. + * @dev: device + * @ppa_list: user created ppa_list + * @nr_ppas: length of ppa_list + * @opcode: device opcode + * @flags: device flags + * @buf: data buffer + * @len: data buffer length + */ +int nvm_submit_ppa_list(struct nvm_dev *dev, struct ppa_addr *ppa_list, + int nr_ppas, int opcode, int flags, void *buf, int len) +{ + struct nvm_rq rqd; + + if (dev->ops->max_phys_sect < nr_ppas) + return -EINVAL; + + memset(&rqd, 0, sizeof(struct nvm_rq)); + + rqd.nr_pages = nr_ppas; + if (nr_ppas > 1) + rqd.ppa_list = ppa_list; + else + rqd.ppa_addr = ppa_list[0]; + + return __nvm_submit_ppa(dev, &rqd, opcode, flags, buf, len); +} +EXPORT_SYMBOL(nvm_submit_ppa_list); + +/** + * nvm_submit_ppa - submit PPAs to device. PPAs will automatically be unfolded + * as single, dual, quad plane PPAs depending on device type. + * @dev: device + * @ppa: user created ppa_list + * @nr_ppas: length of ppa_list + * @opcode: device opcode + * @flags: device flags + * @buf: data buffer + * @len: data buffer length + */ +int nvm_submit_ppa(struct nvm_dev *dev, struct ppa_addr *ppa, int nr_ppas, + int opcode, int flags, void *buf, int len) +{ + struct nvm_rq rqd; + int ret; + + memset(&rqd, 0, sizeof(struct nvm_rq)); + ret = nvm_set_rqd_ppalist(dev, &rqd, ppa, nr_ppas); + if (ret) + return ret; + + ret = __nvm_submit_ppa(dev, &rqd, opcode, flags, buf, len); + nvm_free_rqd_ppalist(dev, &rqd); - return rqd.error; + return ret; } EXPORT_SYMBOL(nvm_submit_ppa); diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index cdcb2cc..38814e2 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -534,6 +534,8 @@ extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *); extern void nvm_end_io(struct nvm_rq *, int); extern int nvm_submit_ppa(struct nvm_dev *, struct ppa_addr *, int, int, int, void *, int); +extern int nvm_submit_ppa_list(struct nvm_dev *, struct ppa_addr *, int, int, + int, void *, int); /* sysblk.c */ #define NVM_SYSBLK_MAGIC 0x4E564D53 /* "NVMS" */