From patchwork Mon Dec 14 13:17:03 2015 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: 7844531 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 09DFCBEEE1 for ; Mon, 14 Dec 2015 13:19:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 011BC203AE for ; Mon, 14 Dec 2015 13:19:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC726203AB for ; Mon, 14 Dec 2015 13:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932537AbbLNNSs (ORCPT ); Mon, 14 Dec 2015 08:18:48 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:36578 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932315AbbLNNRc (ORCPT ); Mon, 14 Dec 2015 08:17:32 -0500 Received: by mail-wm0-f45.google.com with SMTP id n186so117865192wmn.1 for ; Mon, 14 Dec 2015 05:17:31 -0800 (PST) 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-type:content-transfer-encoding; bh=OjEhafskwRKKxdRxbw5tEwKRKtR9eGiO9m5IzO9wISg=; b=SlCNH0lVvTgHnQ+/5Bpu2Dee+/eJS6hQSYBrA8KIVXNmh1/NVHh3doiNvoJ8SF0IO5 UG+t/i9+ZCYCq1+d0ccJhoaBxISlPfrjIn7ld4LOcsVzipBTTGPS4CvQfe3BDgUeInCT lVDQFsMxUPX5SVMfa/pdyh1UBJpyujt1Wb0io= 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-type:content-transfer-encoding; bh=OjEhafskwRKKxdRxbw5tEwKRKtR9eGiO9m5IzO9wISg=; b=K3ZNud/5QwX6v7CqGUtnBFHBDn+MyDroxN9PFu6rMO8mI/D11NMZivze2wL/EndUEI 6vgJrxPY3NvZ8sBjy7d+sDX8GHXoJLUyWQmkcXRTuLvAt4K6AMrcu7+oP9sjLLN33nOI uFhh9ExrRkMOKakFn4I9KgvxXfkRH7EAlZyKUAI7jVnn3qHygX90GRGN/eNeYgTR5agJ TRSL/HwTc3RfxA0FPBCQ/aa6vl75wwRo4x8OqGTQdd6ejYngVc7eAR9gAUlrW25jCCFi KFrRwADwEWaHJj08niBk6EVcKTdL4URD5yM92xpmsaDduhQxxdcBPKksK4y564X4lTL0 vSOg== X-Gm-Message-State: ALoCoQmMOE5XJS+GRxMomYzaYdmRwV6ODKn+IasGWULoPL0LOWUkDxqK6ZJy+j6qciHL35lzaL1KKDI4q84TDPlMHPA7UInibw== X-Received: by 10.194.201.134 with SMTP id ka6mr37948042wjc.116.1450099050780; Mon, 14 Dec 2015 05:17:30 -0800 (PST) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id u139sm16080298wmu.22.2015.12.14.05.17.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Dec 2015 05:17:30 -0800 (PST) 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 RFC 1/5] lightnvm: move ppa erase logic to core Date: Mon, 14 Dec 2015 14:17:03 +0100 Message-Id: <1450099027-24745-2-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1450099027-24745-1-git-send-email-m@bjorling.me> References: <1450099027-24745-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=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,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 A device may function in single, dual or quad plane mode. The gennvm media manager manages this with explicit helpers. They convert a single ppa to 1, 2 or 4 separate ppas in a ppa list. To aid implementation of recovery and system blocks, this functionality can be moved directly into the core. Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/gennvm.c | 68 +++-------------------------------------------- include/linux/lightnvm.h | 3 +++ 3 files changed, 74 insertions(+), 64 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 8f41b24..6134339 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -192,6 +192,73 @@ int nvm_erase_blk(struct nvm_dev *dev, struct nvm_block *blk) } EXPORT_SYMBOL(nvm_erase_blk); +void nvm_addr_to_generic_mode(struct nvm_dev *dev, struct nvm_rq *rqd) +{ + int i; + + if (rqd->nr_pages > 1) { + for (i = 0; i < rqd->nr_pages; i++) + rqd->ppa_list[i] = dev_to_generic_addr(dev, + rqd->ppa_list[i]); + } else { + rqd->ppa_addr = dev_to_generic_addr(dev, rqd->ppa_addr); + } +} +EXPORT_SYMBOL(nvm_addr_to_generic_mode); + +void nvm_generic_to_addr_mode(struct nvm_dev *dev, struct nvm_rq *rqd) +{ + int i; + + if (rqd->nr_pages > 1) { + for (i = 0; i < rqd->nr_pages; i++) + rqd->ppa_list[i] = generic_to_dev_addr(dev, + rqd->ppa_list[i]); + } else { + rqd->ppa_addr = generic_to_dev_addr(dev, rqd->ppa_addr); + } +} +EXPORT_SYMBOL(nvm_generic_to_addr_mode); + +int nvm_erase_ppa(struct nvm_dev *dev, struct ppa_addr ppa) +{ + int plane_cnt = 0, pl_idx, ret; + struct nvm_rq rqd; + + if (!dev->ops->erase_block) + return 0; + + if (dev->plane_mode == NVM_PLANE_SINGLE) { + rqd.nr_pages = 1; + rqd.ppa_addr = ppa; + } else { + plane_cnt = (1 << dev->plane_mode); + rqd.nr_pages = plane_cnt; + + rqd.ppa_list = nvm_dev_dma_alloc(dev, GFP_KERNEL, + &rqd.dma_ppa_list); + if (!rqd.ppa_list) { + pr_err("nvm: failed to allocate dma memory\n"); + return -ENOMEM; + } + + for (pl_idx = 0; pl_idx < plane_cnt; pl_idx++) { + ppa.g.pl = pl_idx; + rqd.ppa_list[pl_idx] = ppa; + } + } + + nvm_generic_to_addr_mode(dev, &rqd); + + ret = dev->ops->erase_block(dev, &rqd); + + if (plane_cnt) + nvm_dev_dma_free(dev, rqd.ppa_list, rqd.dma_ppa_list); + + return ret; +} +EXPORT_SYMBOL(nvm_erase_ppa); + static int nvm_core_init(struct nvm_dev *dev) { struct nvm_id *id = &dev->identity; diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c index f434e89..ba1e671 100644 --- a/drivers/lightnvm/gennvm.c +++ b/drivers/lightnvm/gennvm.c @@ -316,39 +316,13 @@ static void gennvm_put_blk(struct nvm_dev *dev, struct nvm_block *blk) spin_unlock(&vlun->lock); } -static void gennvm_addr_to_generic_mode(struct nvm_dev *dev, struct nvm_rq *rqd) -{ - int i; - - if (rqd->nr_pages > 1) { - for (i = 0; i < rqd->nr_pages; i++) - rqd->ppa_list[i] = dev_to_generic_addr(dev, - rqd->ppa_list[i]); - } else { - rqd->ppa_addr = dev_to_generic_addr(dev, rqd->ppa_addr); - } -} - -static void gennvm_generic_to_addr_mode(struct nvm_dev *dev, struct nvm_rq *rqd) -{ - int i; - - if (rqd->nr_pages > 1) { - for (i = 0; i < rqd->nr_pages; i++) - rqd->ppa_list[i] = generic_to_dev_addr(dev, - rqd->ppa_list[i]); - } else { - rqd->ppa_addr = generic_to_dev_addr(dev, rqd->ppa_addr); - } -} - static int gennvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd) { if (!dev->ops->submit_io) return 0; /* Convert address space */ - gennvm_generic_to_addr_mode(dev, rqd); + nvm_generic_to_addr_mode(dev, rqd); rqd->dev = dev; return dev->ops->submit_io(dev, rqd); @@ -390,7 +364,7 @@ static void gennvm_mark_blk_bad(struct nvm_dev *dev, struct nvm_rq *rqd) if (dev->ops->set_bb_tbl(dev, rqd, 1)) return; - gennvm_addr_to_generic_mode(dev, rqd); + nvm_addr_to_generic_mode(dev, rqd); /* look up blocks and mark them as bad */ if (rqd->nr_pages > 1) @@ -424,43 +398,9 @@ static int gennvm_end_io(struct nvm_rq *rqd, int error) static int gennvm_erase_blk(struct nvm_dev *dev, struct nvm_block *blk, unsigned long flags) { - int plane_cnt = 0, pl_idx, ret; - struct ppa_addr addr; - struct nvm_rq rqd; + struct ppa_addr addr = block_to_ppa(dev, blk); - if (!dev->ops->erase_block) - return 0; - - addr = block_to_ppa(dev, blk); - - if (dev->plane_mode == NVM_PLANE_SINGLE) { - rqd.nr_pages = 1; - rqd.ppa_addr = addr; - } else { - plane_cnt = (1 << dev->plane_mode); - rqd.nr_pages = plane_cnt; - - rqd.ppa_list = nvm_dev_dma_alloc(dev, GFP_KERNEL, - &rqd.dma_ppa_list); - if (!rqd.ppa_list) { - pr_err("gennvm: failed to allocate dma memory\n"); - return -ENOMEM; - } - - for (pl_idx = 0; pl_idx < plane_cnt; pl_idx++) { - addr.g.pl = pl_idx; - rqd.ppa_list[pl_idx] = addr; - } - } - - gennvm_generic_to_addr_mode(dev, &rqd); - - ret = dev->ops->erase_block(dev, &rqd); - - if (plane_cnt) - nvm_dev_dma_free(dev, rqd.ppa_list, rqd.dma_ppa_list); - - return ret; + return nvm_erase_ppa(dev, addr); } static struct nvm_lun *gennvm_get_lun(struct nvm_dev *dev, int lunid) diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index 034117b..c228dbc 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -427,6 +427,9 @@ extern int nvm_register(struct request_queue *, char *, extern void nvm_unregister(char *); extern int nvm_submit_io(struct nvm_dev *, struct nvm_rq *); +extern void nvm_generic_to_addr_mode(struct nvm_dev *, struct nvm_rq *); +extern void nvm_addr_to_generic_mode(struct nvm_dev *, struct nvm_rq *); +extern int nvm_erase_ppa(struct nvm_dev *, struct ppa_addr); extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *); #else /* CONFIG_NVM */ struct nvm_dev_ops;