All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] nvme: don't create block device for inactive namespace
       [not found] <20210617110435.66400-1-xypron.glpk@gmx.de>
@ 2021-06-17 18:17 ` Simon Glass
       [not found] ` <CAEUhbmUzcVQrfkBQxft5ebzctB_-2yyEte_skMCgN0cohV6jxg@mail.gmail.com>
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Glass @ 2021-06-17 18:17 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Tom Rini, Bin Meng, U-Boot Mailing List

+U-Boot Mailing List


On Thu, 17 Jun 2021 at 05:04, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> QEMU returns the highest supported namespace number NN as 255. This does
> not imply that there are 255 active namespaces.
>
> If a namespace is not active, the namespace identify command returns a zero
> filled data structure. We can use field NSZE (namespace size) to decide if
> a block device should be created.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  drivers/nvme/nvme-uclass.c | 30 +++++++++++++++++++++++++++++-
>  1 file changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvme/nvme-uclass.c b/drivers/nvme/nvme-uclass.c
> index 277e31e1f3..f7861f5287 100644
> --- a/drivers/nvme/nvme-uclass.c
> +++ b/drivers/nvme/nvme-uclass.c
> @@ -4,22 +4,50 @@
>   * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
>   */
>
> +#define LOG_CATEGORY UCLASS_NVME
> +
>  #include <common.h>
>  #include <blk.h>
>  #include <errno.h>
>  #include <dm.h>
>  #include <dm/device.h>
> +#include <log.h>
> +#include <memalign.h>
> +#include <nvme.h>
>  #include "nvme.h"
>
> +/**
> + * nvme_probe_namespace() - check if namespace is active
> + *
> + * @dev:       NVMe controller device
> + * @ns_id:     namespace ID
> + * Return:     0 if namespace exists, -ve on error
> + */
> +static int nvme_probe_namespace(struct nvme_dev *dev, unsigned int ns_id)
> +{
> +       ALLOC_CACHE_ALIGN_BUFFER(char, buf_ns, sizeof(struct nvme_id_ns));
> +       struct nvme_id_ns *id = (struct nvme_id_ns *)buf_ns;
> +
> +       if (nvme_identify(dev, ns_id, 0, (dma_addr_t)(long)id))
> +               return -EIO;
> +       log_debug("ns_id %u, nsze %llu\n", ns_id, id->nsze);
> +       if (!id->nsze)
> +               return -ENOENT;
> +       return 0;
> +}
> +
>  static int nvme_uclass_post_probe(struct udevice *udev)
>  {
>         char name[20];
>         struct udevice *ns_udev;
> -       int i, ret;
> +       unsigned int i;
> +       int ret;
>         struct nvme_dev *ndev = dev_get_priv(udev);
>
>         /* Create a blk device for each namespace */
>         for (i = 0; i < ndev->nn; i++) {
> +               if (nvme_probe_namespace(ndev, i + 1))
> +                       continue;
>                 /*
>                  * Encode the namespace id to the device name so that
>                  * we can extract it when doing the probe.
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvme: don't create block device for inactive namespace
       [not found] ` <CAEUhbmUzcVQrfkBQxft5ebzctB_-2yyEte_skMCgN0cohV6jxg@mail.gmail.com>
@ 2021-06-18  5:47   ` Bin Meng
  2021-06-18 20:39     ` Heinrich Schuchardt
  0 siblings, 1 reply; 4+ messages in thread
From: Bin Meng @ 2021-06-18  5:47 UTC (permalink / raw)
  To: Heinrich Schuchardt, U-Boot Mailing List; +Cc: Tom Rini, Simon Glass

+ML

On Fri, Jun 18, 2021 at 1:47 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Heinrich,
>
> On Thu, Jun 17, 2021 at 7:04 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >
> > QEMU returns the highest supported namespace number NN as 255. This does
> > not imply that there are 255 active namespaces.
> >
> > If a namespace is not active, the namespace identify command returns a zero
> > filled data structure. We can use field NSZE (namespace size) to decide if
> > a block device should be created.
>
> Thanks for the fix. Apparently QEMU has changed its behavior of namespaces.
>
> >
> > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> > ---
> >  drivers/nvme/nvme-uclass.c | 30 +++++++++++++++++++++++++++++-
> >  1 file changed, 29 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/nvme/nvme-uclass.c b/drivers/nvme/nvme-uclass.c
> > index 277e31e1f3..f7861f5287 100644
> > --- a/drivers/nvme/nvme-uclass.c
> > +++ b/drivers/nvme/nvme-uclass.c
> > @@ -4,22 +4,50 @@
> >   * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
> >   */
> >
> > +#define LOG_CATEGORY UCLASS_NVME
> > +
> >  #include <common.h>
> >  #include <blk.h>
> >  #include <errno.h>
> >  #include <dm.h>
> >  #include <dm/device.h>
> > +#include <log.h>
> > +#include <memalign.h>
> > +#include <nvme.h>
> >  #include "nvme.h"
> >
> > +/**
> > + * nvme_probe_namespace() - check if namespace is active
> > + *
> > + * @dev:       NVMe controller device
> > + * @ns_id:     namespace ID
> > + * Return:     0 if namespace exists, -ve on error
> > + */
> > +static int nvme_probe_namespace(struct nvme_dev *dev, unsigned int ns_id)
> > +{
> > +       ALLOC_CACHE_ALIGN_BUFFER(char, buf_ns, sizeof(struct nvme_id_ns));
> > +       struct nvme_id_ns *id = (struct nvme_id_ns *)buf_ns;
> > +
> > +       if (nvme_identify(dev, ns_id, 0, (dma_addr_t)(long)id))
> > +               return -EIO;
> > +       log_debug("ns_id %u, nsze %llu\n", ns_id, id->nsze);
> > +       if (!id->nsze)
> > +               return -ENOENT;
> > +       return 0;
> > +}
> > +
> >  static int nvme_uclass_post_probe(struct udevice *udev)
> >  {
> >         char name[20];
> >         struct udevice *ns_udev;
> > -       int i, ret;
> > +       unsigned int i;
> > +       int ret;
> >         struct nvme_dev *ndev = dev_get_priv(udev);
> >
> >         /* Create a blk device for each namespace */
> >         for (i = 0; i < ndev->nn; i++) {
>
> I suggest we assign correct number of namespaces in
> nvme_get_info_from_identify() instead.
>
> > +               if (nvme_probe_namespace(ndev, i + 1))
> > +                       continue;
> >                 /*
> >                  * Encode the namespace id to the device name so that
> >                  * we can extract it when doing the probe.
>
> Regards,
> Bin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvme: don't create block device for inactive namespace
  2021-06-18  5:47   ` Bin Meng
@ 2021-06-18 20:39     ` Heinrich Schuchardt
  2021-06-21  9:59       ` Bin Meng
  0 siblings, 1 reply; 4+ messages in thread
From: Heinrich Schuchardt @ 2021-06-18 20:39 UTC (permalink / raw)
  To: Bin Meng, U-Boot Mailing List; +Cc: Tom Rini, Simon Glass

Am 18. Juni 2021 07:47:37 MESZ schrieb Bin Meng <bmeng.cn@gmail.com>:
>+ML
>
>On Fri, Jun 18, 2021 at 1:47 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> Hi Heinrich,
>>
>> On Thu, Jun 17, 2021 at 7:04 PM Heinrich Schuchardt
><xypron.glpk@gmx.de> wrote:
>> >
>> > QEMU returns the highest supported namespace number NN as 255. This
>does
>> > not imply that there are 255 active namespaces.
>> >
>> > If a namespace is not active, the namespace identify command
>returns a zero
>> > filled data structure. We can use field NSZE (namespace size) to
>decide if
>> > a block device should be created.
>>
>> Thanks for the fix. Apparently QEMU has changed its behavior of
>namespaces.
>>
>> >
>> > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> > ---
>> >  drivers/nvme/nvme-uclass.c | 30 +++++++++++++++++++++++++++++-
>> >  1 file changed, 29 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/nvme/nvme-uclass.c
>b/drivers/nvme/nvme-uclass.c
>> > index 277e31e1f3..f7861f5287 100644
>> > --- a/drivers/nvme/nvme-uclass.c
>> > +++ b/drivers/nvme/nvme-uclass.c
>> > @@ -4,22 +4,50 @@
>> >   * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
>> >   */
>> >
>> > +#define LOG_CATEGORY UCLASS_NVME
>> > +
>> >  #include <common.h>
>> >  #include <blk.h>
>> >  #include <errno.h>
>> >  #include <dm.h>
>> >  #include <dm/device.h>
>> > +#include <log.h>
>> > +#include <memalign.h>
>> > +#include <nvme.h>
>> >  #include "nvme.h"
>> >
>> > +/**
>> > + * nvme_probe_namespace() - check if namespace is active
>> > + *
>> > + * @dev:       NVMe controller device
>> > + * @ns_id:     namespace ID
>> > + * Return:     0 if namespace exists, -ve on error
>> > + */
>> > +static int nvme_probe_namespace(struct nvme_dev *dev, unsigned int
>ns_id)
>> > +{
>> > +       ALLOC_CACHE_ALIGN_BUFFER(char, buf_ns, sizeof(struct
>nvme_id_ns));
>> > +       struct nvme_id_ns *id = (struct nvme_id_ns *)buf_ns;
>> > +
>> > +       if (nvme_identify(dev, ns_id, 0, (dma_addr_t)(long)id))
>> > +               return -EIO;
>> > +       log_debug("ns_id %u, nsze %llu\n", ns_id, id->nsze);
>> > +       if (!id->nsze)
>> > +               return -ENOENT;
>> > +       return 0;
>> > +}
>> > +
>> >  static int nvme_uclass_post_probe(struct udevice *udev)
>> >  {
>> >         char name[20];
>> >         struct udevice *ns_udev;
>> > -       int i, ret;
>> > +       unsigned int i;
>> > +       int ret;
>> >         struct nvme_dev *ndev = dev_get_priv(udev);
>> >
>> >         /* Create a blk device for each namespace */
>> >         for (i = 0; i < ndev->nn; i++) {
>>
>> I suggest we assign correct number of namespaces in
>> nvme_get_info_from_identify() instead.
>>

The active mamespaces could be 23, 78, 167. In what way would it help here to know there are three of them?

It might make sense to eliminate the offset of one.

Best regards

Heinrich


>> > +               if (nvme_probe_namespace(ndev, i + 1))
>> > +                       continue;
>> >                 /*
>> >                  * Encode the namespace id to the device name so
>that
>> >                  * we can extract it when doing the probe.
>>
>> Regards,
>> Bin


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvme: don't create block device for inactive namespace
  2021-06-18 20:39     ` Heinrich Schuchardt
@ 2021-06-21  9:59       ` Bin Meng
  0 siblings, 0 replies; 4+ messages in thread
From: Bin Meng @ 2021-06-21  9:59 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: U-Boot Mailing List, Tom Rini, Simon Glass

Hi Heinrich,

On Sat, Jun 19, 2021 at 4:39 AM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Am 18. Juni 2021 07:47:37 MESZ schrieb Bin Meng <bmeng.cn@gmail.com>:
> >+ML
> >
> >On Fri, Jun 18, 2021 at 1:47 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >>
> >> Hi Heinrich,
> >>
> >> On Thu, Jun 17, 2021 at 7:04 PM Heinrich Schuchardt
> ><xypron.glpk@gmx.de> wrote:
> >> >
> >> > QEMU returns the highest supported namespace number NN as 255. This
> >does
> >> > not imply that there are 255 active namespaces.
> >> >
> >> > If a namespace is not active, the namespace identify command
> >returns a zero
> >> > filled data structure. We can use field NSZE (namespace size) to
> >decide if
> >> > a block device should be created.
> >>
> >> Thanks for the fix. Apparently QEMU has changed its behavior of
> >namespaces.
> >>
> >> >
> >> > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> >> > ---
> >> >  drivers/nvme/nvme-uclass.c | 30 +++++++++++++++++++++++++++++-
> >> >  1 file changed, 29 insertions(+), 1 deletion(-)
> >> >
> >> > diff --git a/drivers/nvme/nvme-uclass.c
> >b/drivers/nvme/nvme-uclass.c
> >> > index 277e31e1f3..f7861f5287 100644
> >> > --- a/drivers/nvme/nvme-uclass.c
> >> > +++ b/drivers/nvme/nvme-uclass.c
> >> > @@ -4,22 +4,50 @@
> >> >   * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
> >> >   */
> >> >
> >> > +#define LOG_CATEGORY UCLASS_NVME
> >> > +
> >> >  #include <common.h>
> >> >  #include <blk.h>
> >> >  #include <errno.h>
> >> >  #include <dm.h>
> >> >  #include <dm/device.h>
> >> > +#include <log.h>
> >> > +#include <memalign.h>
> >> > +#include <nvme.h>
> >> >  #include "nvme.h"
> >> >
> >> > +/**
> >> > + * nvme_probe_namespace() - check if namespace is active
> >> > + *
> >> > + * @dev:       NVMe controller device
> >> > + * @ns_id:     namespace ID
> >> > + * Return:     0 if namespace exists, -ve on error
> >> > + */
> >> > +static int nvme_probe_namespace(struct nvme_dev *dev, unsigned int
> >ns_id)
> >> > +{
> >> > +       ALLOC_CACHE_ALIGN_BUFFER(char, buf_ns, sizeof(struct
> >nvme_id_ns));
> >> > +       struct nvme_id_ns *id = (struct nvme_id_ns *)buf_ns;
> >> > +
> >> > +       if (nvme_identify(dev, ns_id, 0, (dma_addr_t)(long)id))
> >> > +               return -EIO;
> >> > +       log_debug("ns_id %u, nsze %llu\n", ns_id, id->nsze);
> >> > +       if (!id->nsze)
> >> > +               return -ENOENT;
> >> > +       return 0;
> >> > +}
> >> > +
> >> >  static int nvme_uclass_post_probe(struct udevice *udev)
> >> >  {
> >> >         char name[20];
> >> >         struct udevice *ns_udev;
> >> > -       int i, ret;
> >> > +       unsigned int i;
> >> > +       int ret;
> >> >         struct nvme_dev *ndev = dev_get_priv(udev);
> >> >
> >> >         /* Create a blk device for each namespace */
> >> >         for (i = 0; i < ndev->nn; i++) {
> >>
> >> I suggest we assign correct number of namespaces in
> >> nvme_get_info_from_identify() instead.
> >>
>
> The active mamespaces could be 23, 78, 167. In what way would it help here to know there are three of them?

Ah, yes.

>
> It might make sense to eliminate the offset of one.

This was changed due to QEMU commit:

commit 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces")

I will see if I can do some refactoring of the existing codes to fix this.

Regards,
Bin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-21  9:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210617110435.66400-1-xypron.glpk@gmx.de>
2021-06-17 18:17 ` [PATCH] nvme: don't create block device for inactive namespace Simon Glass
     [not found] ` <CAEUhbmUzcVQrfkBQxft5ebzctB_-2yyEte_skMCgN0cohV6jxg@mail.gmail.com>
2021-06-18  5:47   ` Bin Meng
2021-06-18 20:39     ` Heinrich Schuchardt
2021-06-21  9:59       ` Bin Meng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.