From patchwork Mon Nov 28 21:39:14 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: 9450559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 960226071C for ; Mon, 28 Nov 2016 21:43:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 874B927BFF for ; Mon, 28 Nov 2016 21:43:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C32827EE9; Mon, 28 Nov 2016 21:43:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEBFD27BFF for ; Mon, 28 Nov 2016 21:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755580AbcK1Vnr (ORCPT ); Mon, 28 Nov 2016 16:43:47 -0500 Received: from mail-wj0-f193.google.com ([209.85.210.193]:35936 "EHLO mail-wj0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755661AbcK1VkE (ORCPT ); Mon, 28 Nov 2016 16:40:04 -0500 Received: by mail-wj0-f193.google.com with SMTP id jb2so15789890wjb.3 for ; Mon, 28 Nov 2016 13:39:58 -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-transfer-encoding; bh=BugNmLSUVcrpqIJ5aCCsUGF7c61WfQ+qDXZwh1ehSA4=; b=kc35OtiseXMm4NdPFUprQN+pD6aMYr9X8CHsYio0LoAtsaXUlD3NC+sUnTBr05q8RY pY5I9DcrGJOiZUFJjS0tjUjbP3QaN5IM4qbMmOTCjbSkA+JRil0cxTXXuRMemIdZVUUz W0+CYk2CnXR5PRQYXAZbMKcgN4WyZhDWUL2Mk= 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=BugNmLSUVcrpqIJ5aCCsUGF7c61WfQ+qDXZwh1ehSA4=; b=fhstcKgUgl6vsuEfegO7r9DXe1FZ60m200z5nNbK5dT1JlGYy1E3zldvAaYtoFNsbR 85itq3mQHf7vnxtZurKpWzXk97nPuOrCNBe+2gFfejepZHl9DKQQ0CD0z6F7vit5emNY l93c4vEEPuTjnzqcNj1+gu9PXyJgGFBXmEhVfHjeSx3M30sIsWdSa2mx+/xlaZvCPKAF O0WFZYSRL8cD4eHBNVC2DQHEEopjOISZtrsiSCp7HaaflMkgcPV0l5TS3CYCcuVXCPzX DvcNweTWAL2959sbjYj1PjYXqGY9eh092rdQt/JBJdT3kdlxR1GLtBaqc0nzNbea53sf fOsg== X-Gm-Message-State: AKaTC02+g8voH/TYIvNG7vB1+tqvXyppWp0SDw5a3o5yct4y8kHFIkTJw6sMav8rsRyLmA== X-Received: by 10.194.10.72 with SMTP id g8mr24460994wjb.57.1480369197534; Mon, 28 Nov 2016 13:39:57 -0800 (PST) Received: from Macroninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id w79sm30825843wmw.0.2016.11.28.13.39.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2016 13:39:57 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: axboe@fb.com, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 23/23] lightnvm: transform target get/set bad block Date: Mon, 28 Nov 2016 22:39:14 +0100 Message-Id: <20161128213914.12516-24-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161128213914.12516-1-m@bjorling.me> References: <20161128213914.12516-1-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-Virus-Scanned: ClamAV using ClamSMTP From: Javier González Since targets are given a virtual target device, it is necessary to translate all communication between targets and the backend device. Implement the translation layer for get/set bad block table. Signed-off-by: Javier González Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/gennvm.c | 19 +++++++++++----- drivers/lightnvm/rrpc.c | 4 ++-- include/linux/lightnvm.h | 15 +++++++++--- 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 07bf989..7622e3d 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -175,6 +175,26 @@ static struct nvm_dev *nvm_find_nvm_dev(const char *name) return NULL; } +static void nvm_tgt_generic_to_addr_mode(struct nvm_tgt_dev *tgt_dev, + struct nvm_rq *rqd) +{ + struct nvm_dev *dev = tgt_dev->parent; + int i; + + if (rqd->nr_ppas > 1) { + for (i = 0; i < rqd->nr_ppas; i++) { + rqd->ppa_list[i] = dev->mt->trans_ppa(tgt_dev, + rqd->ppa_list[i], TRANS_TGT_TO_DEV); + rqd->ppa_list[i] = generic_to_dev_addr(dev, + rqd->ppa_list[i]); + } + } else { + rqd->ppa_addr = dev->mt->trans_ppa(tgt_dev, rqd->ppa_addr, + TRANS_TGT_TO_DEV); + rqd->ppa_addr = generic_to_dev_addr(dev, rqd->ppa_addr); + } +} + int nvm_set_bb_tbl(struct nvm_dev *dev, struct ppa_addr *ppas, int nr_ppas, int type) { @@ -202,6 +222,34 @@ int nvm_set_bb_tbl(struct nvm_dev *dev, struct ppa_addr *ppas, int nr_ppas, } EXPORT_SYMBOL(nvm_set_bb_tbl); +int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *ppas, + int nr_ppas, int type) +{ + struct nvm_dev *dev = tgt_dev->parent; + struct nvm_rq rqd; + int ret; + + if (nr_ppas > dev->ops->max_phys_sect) { + pr_err("nvm: unable to update all blocks atomically\n"); + return -EINVAL; + } + + memset(&rqd, 0, sizeof(struct nvm_rq)); + + nvm_set_rqd_ppalist(dev, &rqd, ppas, nr_ppas, 1); + nvm_tgt_generic_to_addr_mode(tgt_dev, &rqd); + + ret = dev->ops->set_bb_tbl(dev, &rqd.ppa_addr, rqd.nr_ppas, type); + nvm_free_rqd_ppalist(dev, &rqd); + if (ret) { + pr_err("nvm: sysblk failed bb mark\n"); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL(nvm_set_tgt_bb_tbl); + int nvm_max_phys_sects(struct nvm_tgt_dev *tgt_dev) { struct nvm_dev *dev = tgt_dev->parent; @@ -519,6 +567,16 @@ int nvm_get_bb_tbl(struct nvm_dev *dev, struct ppa_addr ppa, u8 *blks) } EXPORT_SYMBOL(nvm_get_bb_tbl); +int nvm_get_tgt_bb_tbl(struct nvm_tgt_dev *tgt_dev, struct ppa_addr ppa, + u8 *blks) +{ + struct nvm_dev *dev = tgt_dev->parent; + + ppa = dev->mt->trans_ppa(tgt_dev, ppa, TRANS_TGT_TO_DEV); + return nvm_get_bb_tbl(dev, ppa, blks); +} +EXPORT_SYMBOL(nvm_get_tgt_bb_tbl); + static int nvm_init_slc_tbl(struct nvm_dev *dev, struct nvm_id_group *grp) { struct nvm_geo *geo = &dev->geo; diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c index befa828..ca78800 100644 --- a/drivers/lightnvm/gennvm.c +++ b/drivers/lightnvm/gennvm.c @@ -482,12 +482,6 @@ static void gen_unregister(struct nvm_dev *dev) module_put(THIS_MODULE); } -enum { - TRANS_TGT_TO_DEV = 0x0, - TRANS_DEV_TO_TGT = 0x1, -}; - - static int gen_map_to_dev(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *p) { struct gen_dev_map *dev_map = tgt_dev->map; @@ -584,6 +578,18 @@ static int gen_erase_blk(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *p, return nvm_erase_ppa(tgt_dev->parent, p, 1, flags); } +static struct ppa_addr gen_trans_ppa(struct nvm_tgt_dev *tgt_dev, + struct ppa_addr p, int direction) +{ + gen_trans_fn *f; + struct ppa_addr ppa = p; + + f = (direction == TRANS_TGT_TO_DEV) ? gen_map_to_dev : gen_map_to_tgt; + f(tgt_dev, &ppa); + + return ppa; +} + static void gen_part_to_tgt(struct nvm_dev *dev, sector_t *entries, int len) { @@ -631,6 +637,7 @@ static struct nvmm_type gen = { .get_area = gen_get_area, .put_area = gen_put_area, + .trans_ppa = gen_trans_ppa, .part_to_tgt = gen_part_to_tgt, }; diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c index 8a27bcc..9fb7de3 100644 --- a/drivers/lightnvm/rrpc.c +++ b/drivers/lightnvm/rrpc.c @@ -735,7 +735,7 @@ static void __rrpc_mark_bad_block(struct rrpc *rrpc, struct ppa_addr ppa) rblk = &rlun->blocks[ppa.g.blk]; rblk->state = NVM_BLK_ST_BAD; - nvm_set_bb_tbl(dev->parent, &ppa, 1, NVM_BLK_T_GRWN_BAD); + nvm_set_tgt_bb_tbl(dev, &ppa, 1, NVM_BLK_T_GRWN_BAD); } static void rrpc_mark_bad_block(struct rrpc *rrpc, struct nvm_rq *rqd) @@ -1267,7 +1267,7 @@ static int rrpc_bb_discovery(struct nvm_tgt_dev *dev, struct rrpc_lun *rlun) ppa.g.ch = rlun->bppa.g.ch; ppa.g.lun = rlun->bppa.g.lun; - ret = nvm_get_bb_tbl(dev->parent, ppa, blks); + ret = nvm_get_tgt_bb_tbl(dev, ppa, blks); if (ret) { pr_err("rrpc: could not get BB table\n"); goto out; diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index e76f9c4..7c273bb 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -496,8 +496,15 @@ typedef int (nvmm_submit_io_fn)(struct nvm_tgt_dev *, struct nvm_rq *); typedef int (nvmm_erase_blk_fn)(struct nvm_tgt_dev *, struct ppa_addr *, int); typedef int (nvmm_get_area_fn)(struct nvm_dev *, sector_t *, sector_t); typedef void (nvmm_put_area_fn)(struct nvm_dev *, sector_t); +typedef struct ppa_addr (nvmm_trans_ppa_fn)(struct nvm_tgt_dev *, + struct ppa_addr, int); typedef void (nvmm_part_to_tgt_fn)(struct nvm_dev *, sector_t*, int); +enum { + TRANS_TGT_TO_DEV = 0x0, + TRANS_DEV_TO_TGT = 0x1, +}; + struct nvmm_type { const char *name; unsigned int version[3]; @@ -514,6 +521,7 @@ struct nvmm_type { nvmm_get_area_fn *get_area; nvmm_put_area_fn *put_area; + nvmm_trans_ppa_fn *trans_ppa; nvmm_part_to_tgt_fn *part_to_tgt; struct list_head list; @@ -526,9 +534,9 @@ extern struct nvm_dev *nvm_alloc_dev(int); extern int nvm_register(struct nvm_dev *); extern void nvm_unregister(struct nvm_dev *); -extern int nvm_set_bb_tbl(struct nvm_dev *dev, struct ppa_addr *ppas, - int nr_ppas, int type); - +extern int nvm_set_bb_tbl(struct nvm_dev *, struct ppa_addr *, int, int); +extern int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr *, + int, int); extern int nvm_max_phys_sects(struct nvm_tgt_dev *); extern int nvm_submit_io(struct nvm_tgt_dev *, struct nvm_rq *); extern void nvm_generic_to_addr_mode(struct nvm_dev *, struct nvm_rq *); @@ -549,6 +557,7 @@ extern int nvm_submit_ppa_list(struct nvm_dev *, struct ppa_addr *, int, int, int, void *, int); extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int); extern int nvm_get_bb_tbl(struct nvm_dev *, struct ppa_addr, u8 *); +extern int nvm_get_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr, u8 *); /* sysblk.c */ #define NVM_SYSBLK_MAGIC 0x4E564D53 /* "NVMS" */