[PATCH] nvme: don't create block device for inactive namespace

Simon Glass sjg at chromium.org
Thu Jun 17 20:17:49 CEST 2021


+U-Boot Mailing List


On Thu, 17 Jun 2021 at 05:04, Heinrich Schuchardt <xypron.glpk at 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 at 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 at 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
>


More information about the U-Boot mailing list