mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Matias Bjørling" <mb@lightnvm.io>
To: axboe@fb.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	keith.busch@intel.com, javier@cnexlabs.com,
	"Matias Bjørling" <mb@lightnvm.io>
Subject: [GIT PULL 30/37] lightnvm: implement get log report chunk helpers
Date: Fri, 30 Mar 2018 00:05:17 +0200	[thread overview]
Message-ID: <20180329220524.30363-31-mb@lightnvm.io> (raw)
In-Reply-To: <20180329220524.30363-1-mb@lightnvm.io>

From: Javier González <javier@cnexlabs.com>

The 2.0 spec provides a report chunk log page that can be retrieved
using the stangard nvme get log page. This replaces the dedicated
get/put bad block table in 1.2.

This patch implements the helper functions to allow targets retrieve the
chunk metadata using get log page. It makes nvme_get_log_ext available
outside of nvme core so that we can use it form lightnvm.

Signed-off-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <mb@lightnvm.io>
---
 drivers/lightnvm/core.c      | 11 +++++++
 drivers/nvme/host/core.c     |  4 +--
 drivers/nvme/host/lightnvm.c | 74 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/lightnvm.h     | 24 ++++++++++++++
 4 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 77901bf17416..63171cdce270 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -712,6 +712,17 @@ static void nvm_free_rqd_ppalist(struct nvm_tgt_dev *tgt_dev,
 	nvm_dev_dma_free(tgt_dev->parent, rqd->ppa_list, rqd->dma_ppa_list);
 }
 
+int nvm_get_chunk_meta(struct nvm_tgt_dev *tgt_dev, struct nvm_chk_meta *meta,
+		struct ppa_addr ppa, int nchks)
+{
+	struct nvm_dev *dev = tgt_dev->parent;
+
+	nvm_ppa_tgt_to_dev(tgt_dev, &ppa, 1);
+
+	return dev->ops->get_chk_meta(tgt_dev->parent, meta,
+						(sector_t)ppa.ppa, nchks);
+}
+EXPORT_SYMBOL(nvm_get_chunk_meta);
 
 int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *ppas,
 		       int nr_ppas, int type)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index e7ec2fb5c59a..f81e3b323366 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2219,8 +2219,8 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
 }
 
 int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
-			    u8 log_page, void *log,
-			    size_t size, size_t offset)
+		     u8 log_page, void *log,
+		     size_t size, size_t offset)
 {
 	struct nvme_command c = { };
 	unsigned long dwlen = size / 4 - 1;
diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index 08f0f6b5bc06..ffd64a83c8c3 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -35,6 +35,10 @@ enum nvme_nvm_admin_opcode {
 	nvme_nvm_admin_set_bb_tbl	= 0xf1,
 };
 
+enum nvme_nvm_log_page {
+	NVME_NVM_LOG_REPORT_CHUNK	= 0xca,
+};
+
 struct nvme_nvm_ph_rw {
 	__u8			opcode;
 	__u8			flags;
@@ -236,6 +240,16 @@ struct nvme_nvm_id20 {
 	__u8			vs[1024];
 };
 
+struct nvme_nvm_chk_meta {
+	__u8	state;
+	__u8	type;
+	__u8	wi;
+	__u8	rsvd[5];
+	__le64	slba;
+	__le64	cnlb;
+	__le64	wp;
+};
+
 /*
  * Check we didn't inadvertently grow the command struct
  */
@@ -252,6 +266,9 @@ static inline void _nvme_nvm_check_size(void)
 	BUILD_BUG_ON(sizeof(struct nvme_nvm_bb_tbl) != 64);
 	BUILD_BUG_ON(sizeof(struct nvme_nvm_id20_addrf) != 8);
 	BUILD_BUG_ON(sizeof(struct nvme_nvm_id20) != NVME_IDENTIFY_DATA_SIZE);
+	BUILD_BUG_ON(sizeof(struct nvme_nvm_chk_meta) != 32);
+	BUILD_BUG_ON(sizeof(struct nvme_nvm_chk_meta) !=
+						sizeof(struct nvm_chk_meta));
 }
 
 static void nvme_nvm_set_addr_12(struct nvm_addrf_12 *dst,
@@ -552,6 +569,61 @@ static int nvme_nvm_set_bb_tbl(struct nvm_dev *nvmdev, struct ppa_addr *ppas,
 	return ret;
 }
 
+/*
+ * Expect the lba in device format
+ */
+static int nvme_nvm_get_chk_meta(struct nvm_dev *ndev,
+				 struct nvm_chk_meta *meta,
+				 sector_t slba, int nchks)
+{
+	struct nvm_geo *geo = &ndev->geo;
+	struct nvme_ns *ns = ndev->q->queuedata;
+	struct nvme_ctrl *ctrl = ns->ctrl;
+	struct nvme_nvm_chk_meta *dev_meta = (struct nvme_nvm_chk_meta *)meta;
+	struct ppa_addr ppa;
+	size_t left = nchks * sizeof(struct nvme_nvm_chk_meta);
+	size_t log_pos, offset, len;
+	int ret, i;
+
+	/* Normalize lba address space to obtain log offset */
+	ppa.ppa = slba;
+	ppa = dev_to_generic_addr(ndev, ppa);
+
+	log_pos = ppa.m.chk;
+	log_pos += ppa.m.pu * geo->num_chk;
+	log_pos += ppa.m.grp * geo->num_lun * geo->num_chk;
+
+	offset = log_pos * sizeof(struct nvme_nvm_chk_meta);
+
+	while (left) {
+		len = min_t(unsigned int, left, ctrl->max_hw_sectors << 9);
+
+		ret = nvme_get_log_ext(ctrl, ns, NVME_NVM_LOG_REPORT_CHUNK,
+				dev_meta, len, offset);
+		if (ret) {
+			dev_err(ctrl->device, "Get REPORT CHUNK log error\n");
+			break;
+		}
+
+		for (i = 0; i < len; i += sizeof(struct nvme_nvm_chk_meta)) {
+			meta->state = dev_meta->state;
+			meta->type = dev_meta->type;
+			meta->wi = dev_meta->wi;
+			meta->slba = le64_to_cpu(dev_meta->slba);
+			meta->cnlb = le64_to_cpu(dev_meta->cnlb);
+			meta->wp = le64_to_cpu(dev_meta->wp);
+
+			meta++;
+			dev_meta++;
+		}
+
+		offset += len;
+		left -= len;
+	}
+
+	return ret;
+}
+
 static inline void nvme_nvm_rqtocmd(struct nvm_rq *rqd, struct nvme_ns *ns,
 				    struct nvme_nvm_command *c)
 {
@@ -683,6 +755,8 @@ static struct nvm_dev_ops nvme_nvm_dev_ops = {
 	.get_bb_tbl		= nvme_nvm_get_bb_tbl,
 	.set_bb_tbl		= nvme_nvm_set_bb_tbl,
 
+	.get_chk_meta		= nvme_nvm_get_chk_meta,
+
 	.submit_io		= nvme_nvm_submit_io,
 	.submit_io_sync		= nvme_nvm_submit_io_sync,
 
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index f3b273e543c3..da45efa09bb2 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -81,10 +81,13 @@ struct nvm_rq;
 struct nvm_id;
 struct nvm_dev;
 struct nvm_tgt_dev;
+struct nvm_chk_meta;
 
 typedef int (nvm_id_fn)(struct nvm_dev *);
 typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, u8 *);
 typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct ppa_addr *, int, int);
+typedef int (nvm_get_chk_meta_fn)(struct nvm_dev *, struct nvm_chk_meta *,
+								sector_t, int);
 typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
 typedef int (nvm_submit_io_sync_fn)(struct nvm_dev *, struct nvm_rq *);
 typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *);
@@ -98,6 +101,8 @@ struct nvm_dev_ops {
 	nvm_op_bb_tbl_fn	*get_bb_tbl;
 	nvm_op_set_bb_fn	*set_bb_tbl;
 
+	nvm_get_chk_meta_fn	*get_chk_meta;
+
 	nvm_submit_io_fn	*submit_io;
 	nvm_submit_io_sync_fn	*submit_io_sync;
 
@@ -227,6 +232,20 @@ struct nvm_addrf {
 	u64	rsv_mask[2];
 };
 
+/*
+ * Note: The structure size is linked to nvme_nvm_chk_meta such that the same
+ * buffer can be used when converting from little endian to cpu addressing.
+ */
+struct nvm_chk_meta {
+	u8	state;
+	u8	type;
+	u8	wi;
+	u8	rsvd[5];
+	u64	slba;
+	u64	cnlb;
+	u64	wp;
+};
+
 struct nvm_target {
 	struct list_head list;
 	struct nvm_tgt_dev *dev;
@@ -492,6 +511,11 @@ 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_get_chunk_meta(struct nvm_tgt_dev *tgt_dev,
+			      struct nvm_chk_meta *meta, struct ppa_addr ppa,
+			      int nchks);
+
 extern int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr *,
 			      int, int);
 extern int nvm_submit_io(struct nvm_tgt_dev *, struct nvm_rq *);
-- 
2.11.0

  parent reply	other threads:[~2018-03-29 22:09 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-29 22:04 [GIT PULL 00/37] lightnvm patches for 4.17 Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 01/37] lightnvm/pblk-gc: Delete an error message for a failed memory allocation in pblk_gc_line_prepare_ws() Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 02/37] lightnvm: remove chnl_offset in nvme_nvm_identity Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 03/37] lightnvm: pblk: handle bad sectors in the emeta area correctly Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 04/37] lightnvm: pblk: check data lines version on recovery Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 05/37] lightnvm: pblk: export write amplification counters to sysfs Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 06/37] lightnvm: remove mlc pairs structure Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 07/37] lightnvm: remove multiple groups in 1.2 data structure Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 08/37] lightnvm: pblk: add padding distribution sysfs attribute Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 09/37] lightnvm: pblk: delete writer kick timer before stopping thread Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 10/37] lightnvm: pblk: allow allocation of new lines during shutdown Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 11/37] lightnvm: pblk: prevent race in pblk_rb_flush_point_set Matias Bjørling
2018-03-29 22:04 ` [GIT PULL 12/37] lightnvm: pblk: refactor bad block identification Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 13/37] lightnvm: make 1.2 data structures explicit Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 14/37] lightnvm: flatten nvm_id_group into nvm_id Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 15/37] lightnvm: add 2.0 geometry identification Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 16/37] lightnvm: remove max_rq_size Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 17/37] lightnvm: remove nvm_dev_ops->max_phys_sect Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 18/37] nvme: lightnvm: add late setup of block size and metadata Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 19/37] lightnvm: fix bad block initialization Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 20/37] lightnvm: centralize permission check for lightnvm ioctl Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 21/37] lightnvm: Avoid validation of default op value Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 22/37] lightnvm: pblk: refactor init/exit sequences Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 23/37] lightnvm: simplify geometry structure Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 24/37] lightnvm: add minor version to generic geometry Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 25/37] lightnvm: add shorten OCSSD version in geo Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 26/37] lightnvm: complete geo structure with maxoc* Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 27/37] lightnvm: normalize geometry nomenclature Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 28/37] lightnvm: add support for 2.0 address format Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 29/37] lightnvm: make address conversions depend on generic device Matias Bjørling
2018-03-29 22:05 ` Matias Bjørling [this message]
2018-03-29 22:05 ` [GIT PULL 31/37] lightnvm: pblk: check for supported version Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 32/37] lightnvm: pblk: rename ppaf* to addrf* Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 33/37] lightnvm: pblk: implement get log report chunk Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 34/37] lightnvm: pblk: implement 2.0 support Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 35/37] lightnvm: pblk: don't recover unwritten lines Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 36/37] lightnvm: pblk: remove some unnecessary NULL checks Matias Bjørling
2018-03-29 22:05 ` [GIT PULL 37/37] lightnvm: remove function name in strings Matias Bjørling
2018-03-29 23:30 ` [GIT PULL 00/37] lightnvm patches for 4.17 Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180329220524.30363-31-mb@lightnvm.io \
    --to=mb@lightnvm.io \
    --cc=axboe@fb.com \
    --cc=javier@cnexlabs.com \
    --cc=keith.busch@intel.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®