Re: [PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-21 Thread Javier Gonzalez

> On 21 Mar 2018, at 20.27, Matias Bjørling  wrote:
> 
>> On 03/21/2018 03:36 PM, Keith Busch wrote:
>> On Wed, Mar 21, 2018 at 03:06:05AM -0700, Matias Bjørling wrote:
 outside of nvme core so that we can use it form lightnvm.
 
 Signed-off-by: Javier González 
 ---
   drivers/lightnvm/core.c  | 11 +++
   drivers/nvme/host/core.c |  6 ++--
   drivers/nvme/host/lightnvm.c | 74 
 
   drivers/nvme/host/nvme.h |  3 ++
   include/linux/lightnvm.h | 24 ++
   5 files changed, 115 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
 index 2e9e9f973a75..af642ce6ba69 100644
 --- a/drivers/nvme/host/core.c
 +++ b/drivers/nvme/host/core.c
 @@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl 
 *ctrl, struct nvme_id_ctrl *id)
   return ret;
   }
   -static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 -u8 log_page, void *log,
 -size_t size, size_t offset)
 +int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 + 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,
   };
   
>>> 
>>> 
>>> 
   diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
 index 1ca08f4993ba..505f797f8c6c 100644
 --- a/drivers/nvme/host/nvme.h
 +++ b/drivers/nvme/host/nvme.h
 @@ -396,6 +396,9 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
   int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
   int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
   +int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 + u8 log_page, void *log, size_t size, size_t offset);
 +
   extern const struct attribute_group nvme_ns_id_attr_group;
   extern const struct block_device_operations nvme_ns_head_ops;
   
>>> 
>>> 
>>> Keith, Christoph, Sagi, Is it okay that these two changes that exposes
>>> the nvme_get_log_ext fn are carried through Jens' tree after the nvme
>>> tree for 4.17 has been pulled?
>> That's okay with me. Alteratively, if you want to split the generic nvme
>> part out, I can apply that immediately and the API will be in the first
>> nvme-4.17 pull request.
> 
> Will do. I've sent the patch in another mail. Thanks! :)

It’s fine with me.

Matias: do you take that part of the patch out directly on our tree?

Javier. 

Re: [PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-21 Thread Javier Gonzalez

> On 21 Mar 2018, at 20.27, Matias Bjørling  wrote:
> 
>> On 03/21/2018 03:36 PM, Keith Busch wrote:
>> On Wed, Mar 21, 2018 at 03:06:05AM -0700, Matias Bjørling wrote:
 outside of nvme core so that we can use it form lightnvm.
 
 Signed-off-by: Javier González 
 ---
   drivers/lightnvm/core.c  | 11 +++
   drivers/nvme/host/core.c |  6 ++--
   drivers/nvme/host/lightnvm.c | 74 
 
   drivers/nvme/host/nvme.h |  3 ++
   include/linux/lightnvm.h | 24 ++
   5 files changed, 115 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
 index 2e9e9f973a75..af642ce6ba69 100644
 --- a/drivers/nvme/host/core.c
 +++ b/drivers/nvme/host/core.c
 @@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl 
 *ctrl, struct nvme_id_ctrl *id)
   return ret;
   }
   -static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 -u8 log_page, void *log,
 -size_t size, size_t offset)
 +int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 + 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,
   };
   
>>> 
>>> 
>>> 
   diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
 index 1ca08f4993ba..505f797f8c6c 100644
 --- a/drivers/nvme/host/nvme.h
 +++ b/drivers/nvme/host/nvme.h
 @@ -396,6 +396,9 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
   int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
   int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
   +int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 + u8 log_page, void *log, size_t size, size_t offset);
 +
   extern const struct attribute_group nvme_ns_id_attr_group;
   extern const struct block_device_operations nvme_ns_head_ops;
   
>>> 
>>> 
>>> Keith, Christoph, Sagi, Is it okay that these two changes that exposes
>>> the nvme_get_log_ext fn are carried through Jens' tree after the nvme
>>> tree for 4.17 has been pulled?
>> That's okay with me. Alteratively, if you want to split the generic nvme
>> part out, I can apply that immediately and the API will be in the first
>> nvme-4.17 pull request.
> 
> Will do. I've sent the patch in another mail. Thanks! :)

It’s fine with me.

Matias: do you take that part of the patch out directly on our tree?

Javier. 

Re: [PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-21 Thread Matias Bjørling

On 03/21/2018 03:36 PM, Keith Busch wrote:

On Wed, Mar 21, 2018 at 03:06:05AM -0700, Matias Bjørling wrote:

outside of nvme core so that we can use it form lightnvm.

Signed-off-by: Javier González 
---
   drivers/lightnvm/core.c  | 11 +++
   drivers/nvme/host/core.c |  6 ++--
   drivers/nvme/host/lightnvm.c | 74 

   drivers/nvme/host/nvme.h |  3 ++
   include/linux/lightnvm.h | 24 ++
   5 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2e9e9f973a75..af642ce6ba69 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, 
struct nvme_id_ctrl *id)
return ret;
   }
   
-static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

-   u8 log_page, void *log,
-   size_t size, size_t offset)
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+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,
   };
   




   
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h

index 1ca08f4993ba..505f797f8c6c 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -396,6 +396,9 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
   int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
   int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
   
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

+u8 log_page, void *log, size_t size, size_t offset);
+
   extern const struct attribute_group nvme_ns_id_attr_group;
   extern const struct block_device_operations nvme_ns_head_ops;
   



Keith, Christoph, Sagi, Is it okay that these two changes that exposes
the nvme_get_log_ext fn are carried through Jens' tree after the nvme
tree for 4.17 has been pulled?


That's okay with me. Alteratively, if you want to split the generic nvme
part out, I can apply that immediately and the API will be in the first
nvme-4.17 pull request.



Will do. I've sent the patch in another mail. Thanks! :)


Re: [PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-21 Thread Matias Bjørling

On 03/21/2018 03:36 PM, Keith Busch wrote:

On Wed, Mar 21, 2018 at 03:06:05AM -0700, Matias Bjørling wrote:

outside of nvme core so that we can use it form lightnvm.

Signed-off-by: Javier González 
---
   drivers/lightnvm/core.c  | 11 +++
   drivers/nvme/host/core.c |  6 ++--
   drivers/nvme/host/lightnvm.c | 74 

   drivers/nvme/host/nvme.h |  3 ++
   include/linux/lightnvm.h | 24 ++
   5 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2e9e9f973a75..af642ce6ba69 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, 
struct nvme_id_ctrl *id)
return ret;
   }
   
-static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

-   u8 log_page, void *log,
-   size_t size, size_t offset)
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+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,
   };
   




   
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h

index 1ca08f4993ba..505f797f8c6c 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -396,6 +396,9 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
   int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
   int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
   
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

+u8 log_page, void *log, size_t size, size_t offset);
+
   extern const struct attribute_group nvme_ns_id_attr_group;
   extern const struct block_device_operations nvme_ns_head_ops;
   



Keith, Christoph, Sagi, Is it okay that these two changes that exposes
the nvme_get_log_ext fn are carried through Jens' tree after the nvme
tree for 4.17 has been pulled?


That's okay with me. Alteratively, if you want to split the generic nvme
part out, I can apply that immediately and the API will be in the first
nvme-4.17 pull request.



Will do. I've sent the patch in another mail. Thanks! :)


Re: [PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-21 Thread Keith Busch
On Wed, Mar 21, 2018 at 03:06:05AM -0700, Matias Bjørling wrote:
> > outside of nvme core so that we can use it form lightnvm.
> > 
> > Signed-off-by: Javier González 
> > ---
> >   drivers/lightnvm/core.c  | 11 +++
> >   drivers/nvme/host/core.c |  6 ++--
> >   drivers/nvme/host/lightnvm.c | 74 
> > 
> >   drivers/nvme/host/nvme.h |  3 ++
> >   include/linux/lightnvm.h | 24 ++
> >   5 files changed, 115 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> > index 2e9e9f973a75..af642ce6ba69 100644
> > --- a/drivers/nvme/host/core.c
> > +++ b/drivers/nvme/host/core.c
> > @@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl 
> > *ctrl, struct nvme_id_ctrl *id)
> > return ret;
> >   }
> >   
> > -static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> > -   u8 log_page, void *log,
> > -   size_t size, size_t offset)
> > +int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> > +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,
> >   };
> >   
> 
> 
> 
> >   
> > diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> > index 1ca08f4993ba..505f797f8c6c 100644
> > --- a/drivers/nvme/host/nvme.h
> > +++ b/drivers/nvme/host/nvme.h
> > @@ -396,6 +396,9 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
> >   int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
> >   int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
> >   
> > +int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> > +u8 log_page, void *log, size_t size, size_t offset);
> > +
> >   extern const struct attribute_group nvme_ns_id_attr_group;
> >   extern const struct block_device_operations nvme_ns_head_ops;
> >   
> 
> 
> Keith, Christoph, Sagi, Is it okay that these two changes that exposes 
> the nvme_get_log_ext fn are carried through Jens' tree after the nvme 
> tree for 4.17 has been pulled?

That's okay with me. Alteratively, if you want to split the generic nvme
part out, I can apply that immediately and the API will be in the first
nvme-4.17 pull request.


Re: [PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-21 Thread Keith Busch
On Wed, Mar 21, 2018 at 03:06:05AM -0700, Matias Bjørling wrote:
> > outside of nvme core so that we can use it form lightnvm.
> > 
> > Signed-off-by: Javier González 
> > ---
> >   drivers/lightnvm/core.c  | 11 +++
> >   drivers/nvme/host/core.c |  6 ++--
> >   drivers/nvme/host/lightnvm.c | 74 
> > 
> >   drivers/nvme/host/nvme.h |  3 ++
> >   include/linux/lightnvm.h | 24 ++
> >   5 files changed, 115 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> > index 2e9e9f973a75..af642ce6ba69 100644
> > --- a/drivers/nvme/host/core.c
> > +++ b/drivers/nvme/host/core.c
> > @@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl 
> > *ctrl, struct nvme_id_ctrl *id)
> > return ret;
> >   }
> >   
> > -static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> > -   u8 log_page, void *log,
> > -   size_t size, size_t offset)
> > +int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> > +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,
> >   };
> >   
> 
> 
> 
> >   
> > diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> > index 1ca08f4993ba..505f797f8c6c 100644
> > --- a/drivers/nvme/host/nvme.h
> > +++ b/drivers/nvme/host/nvme.h
> > @@ -396,6 +396,9 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
> >   int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
> >   int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
> >   
> > +int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> > +u8 log_page, void *log, size_t size, size_t offset);
> > +
> >   extern const struct attribute_group nvme_ns_id_attr_group;
> >   extern const struct block_device_operations nvme_ns_head_ops;
> >   
> 
> 
> Keith, Christoph, Sagi, Is it okay that these two changes that exposes 
> the nvme_get_log_ext fn are carried through Jens' tree after the nvme 
> tree for 4.17 has been pulled?

That's okay with me. Alteratively, if you want to split the generic nvme
part out, I can apply that immediately and the API will be in the first
nvme-4.17 pull request.


Re: [PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-21 Thread Matias Bjørling

On 03/02/2018 04:21 PM, Javier González wrote:

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 
---
  drivers/lightnvm/core.c  | 11 +++
  drivers/nvme/host/core.c |  6 ++--
  drivers/nvme/host/lightnvm.c | 74 
  drivers/nvme/host/nvme.h |  3 ++
  include/linux/lightnvm.h | 24 ++
  5 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2e9e9f973a75..af642ce6ba69 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, 
struct nvme_id_ctrl *id)
return ret;
  }
  
-static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

-   u8 log_page, void *log,
-   size_t size, size_t offset)
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+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,
  };
  




  
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h

index 1ca08f4993ba..505f797f8c6c 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -396,6 +396,9 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
  int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
  int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
  
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

+u8 log_page, void *log, size_t size, size_t offset);
+
  extern const struct attribute_group nvme_ns_id_attr_group;
  extern const struct block_device_operations nvme_ns_head_ops;
  



Keith, Christoph, Sagi, Is it okay that these two changes that exposes 
the nvme_get_log_ext fn are carried through Jens' tree after the nvme 
tree for 4.17 has been pulled?




Re: [PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-21 Thread Matias Bjørling

On 03/02/2018 04:21 PM, Javier González wrote:

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 
---
  drivers/lightnvm/core.c  | 11 +++
  drivers/nvme/host/core.c |  6 ++--
  drivers/nvme/host/lightnvm.c | 74 
  drivers/nvme/host/nvme.h |  3 ++
  include/linux/lightnvm.h | 24 ++
  5 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2e9e9f973a75..af642ce6ba69 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, 
struct nvme_id_ctrl *id)
return ret;
  }
  
-static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

-   u8 log_page, void *log,
-   size_t size, size_t offset)
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+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,
  };
  




  
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h

index 1ca08f4993ba..505f797f8c6c 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -396,6 +396,9 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
  int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
  int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
  
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

+u8 log_page, void *log, size_t size, size_t offset);
+
  extern const struct attribute_group nvme_ns_id_attr_group;
  extern const struct block_device_operations nvme_ns_head_ops;
  



Keith, Christoph, Sagi, Is it okay that these two changes that exposes 
the nvme_get_log_ext fn are carried through Jens' tree after the nvme 
tree for 4.17 has been pulled?




[PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-02 Thread Javier González
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 
---
 drivers/lightnvm/core.c  | 11 +++
 drivers/nvme/host/core.c |  6 ++--
 drivers/nvme/host/lightnvm.c | 74 
 drivers/nvme/host/nvme.h |  3 ++
 include/linux/lightnvm.h | 24 ++
 5 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index ed33e0b11788..4141871f460d 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, , 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 2e9e9f973a75..af642ce6ba69 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, 
struct nvme_id_ctrl *id)
return ret;
 }
 
-static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
-   u8 log_page, void *log,
-   size_t size, size_t offset)
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+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 {
__u8opcode;
__u8flags;
@@ -236,6 +240,16 @@ struct nvme_nvm_id20 {
__u8vs[1024];
 };
 
+struct nvme_nvm_chk_meta {
+   __u8state;
+   __u8type;
+   __u8wi;
+   __u8rsvd[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 = >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, 

[PATCH 08/12] lightnvm: implement get log report chunk helpers

2018-03-02 Thread Javier González
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 
---
 drivers/lightnvm/core.c  | 11 +++
 drivers/nvme/host/core.c |  6 ++--
 drivers/nvme/host/lightnvm.c | 74 
 drivers/nvme/host/nvme.h |  3 ++
 include/linux/lightnvm.h | 24 ++
 5 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index ed33e0b11788..4141871f460d 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, , 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 2e9e9f973a75..af642ce6ba69 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2127,9 +2127,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, 
struct nvme_id_ctrl *id)
return ret;
 }
 
-static int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
-   u8 log_page, void *log,
-   size_t size, size_t offset)
+int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+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 {
__u8opcode;
__u8flags;
@@ -236,6 +240,16 @@ struct nvme_nvm_id20 {
__u8vs[1024];
 };
 
+struct nvme_nvm_chk_meta {
+   __u8state;
+   __u8type;
+   __u8wi;
+   __u8rsvd[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 = >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