aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBin Meng <bmeng.cn@gmail.com>2017-08-22 08:15:16 -0700
committerTom Rini <trini@konsulko.com>2017-08-28 07:17:14 -0400
commit18aa5a4134e8179c7c3e38675822284a2718a3d8 (patch)
tree17cd715b07568c52883f6ac7d71f8f1eee9e1b08
parentd5b7ee9c6e19993b10b549ac763aa7db8dbacee0 (diff)
downloadu-boot-18aa5a4134e8179c7c3e38675822284a2718a3d8.zip
u-boot-18aa5a4134e8179c7c3e38675822284a2718a3d8.tar.gz
u-boot-18aa5a4134e8179c7c3e38675822284a2718a3d8.tar.bz2
nvme: Get rid of the global variable nvme_info
At present the NVMe uclass driver uses a global variable nvme_info to store global information like namespace id, and NVMe controller driver's priv struct has a blk_dev_start that is used to calculate the namespace id based on the global information from nvme_info. This is not a good design in the DM world and can be replaced with the following changes: - Encode the namespace id in the NVMe block device name during the NVMe uclass post probe - Extract the namespace id from the device name during the NVMe block device probe - Let BLK uclass calculate the devnum for us by passing -1 to blk_create_devicef() as the devnum Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
-rw-r--r--drivers/nvme/nvme-uclass.c27
-rw-r--r--drivers/nvme/nvme.c11
-rw-r--r--drivers/nvme/nvme.h9
3 files changed, 12 insertions, 35 deletions
diff --git a/drivers/nvme/nvme-uclass.c b/drivers/nvme/nvme-uclass.c
index 334628c..56a6171 100644
--- a/drivers/nvme/nvme-uclass.c
+++ b/drivers/nvme/nvme-uclass.c
@@ -11,18 +11,6 @@
#include <dm/device.h>
#include "nvme.h"
-static int nvme_info_init(struct uclass *uc)
-{
- struct nvme_info *info = (struct nvme_info *)uc->priv;
-
- info->ns_num = 0;
- info->ndev_num = 0;
- INIT_LIST_HEAD(&info->dev_list);
- nvme_info = info;
-
- return 0;
-}
-
static int nvme_uclass_post_probe(struct udevice *udev)
{
char name[20];
@@ -32,16 +20,17 @@ static int nvme_uclass_post_probe(struct udevice *udev)
/* Create a blk device for each namespace */
for (i = 0; i < ndev->nn; i++) {
- sprintf(name, "blk#%d", nvme_info->ns_num);
+ /*
+ * Encode the namespace id to the device name so that
+ * we can extract it when doing the probe.
+ */
+ sprintf(name, "blk#%d", i);
/* The real blksz and size will be set by nvme_blk_probe() */
ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
- nvme_info->ns_num++, 512, 0, &ns_udev);
- if (ret) {
- nvme_info->ns_num--;
-
+ -1, 512, 0, &ns_udev);
+ if (ret)
return ret;
- }
}
return 0;
@@ -50,7 +39,5 @@ static int nvme_uclass_post_probe(struct udevice *udev)
UCLASS_DRIVER(nvme) = {
.name = "nvme",
.id = UCLASS_NVME,
- .init = nvme_info_init,
.post_probe = nvme_uclass_post_probe,
- .priv_auto_alloc_size = sizeof(struct nvme_info),
};
diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index 67f7d75..ec32d0d 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -13,8 +13,6 @@
#include <dm/device-internal.h>
#include "nvme.h"
-struct nvme_info *nvme_info;
-
#define NVME_Q_DEPTH 2
#define NVME_AQ_DEPTH 2
#define NVME_SQ_SIZE(depth) (depth * sizeof(struct nvme_command))
@@ -650,7 +648,8 @@ static int nvme_blk_probe(struct udevice *udev)
memset(ns, 0, sizeof(*ns));
ns->dev = ndev;
- ns->ns_id = desc->devnum - ndev->blk_dev_start + 1;
+ /* extract the namespace id from the block device name */
+ ns->ns_id = trailing_strtol(udev->name) + 1;
if (nvme_identify(ndev, ns->ns_id, 0, (dma_addr_t)id))
return -EIO;
@@ -762,8 +761,10 @@ U_BOOT_DRIVER(nvme_blk) = {
static int nvme_bind(struct udevice *udev)
{
+ static int ndev_num;
char name[20];
- sprintf(name, "nvme#%d", nvme_info->ndev_num++);
+
+ sprintf(name, "nvme#%d", ndev_num++);
return device_set_name(udev, name);
}
@@ -815,8 +816,6 @@ static int nvme_probe(struct udevice *udev)
goto free_queue;
nvme_get_info_from_identify(ndev);
- ndev->blk_dev_start = nvme_info->ns_num;
- list_add(&ndev->node, &nvme_info->dev_list);
return 0;
diff --git a/drivers/nvme/nvme.h b/drivers/nvme/nvme.h
index f0fa639..67bf6e1 100644
--- a/drivers/nvme/nvme.h
+++ b/drivers/nvme/nvme.h
@@ -628,13 +628,6 @@ struct nvme_dev {
u64 *prp_pool;
u32 prp_entry_num;
u32 nn;
- u32 blk_dev_start;
-};
-
-struct nvme_info {
- int ns_num; /*the number of nvme namespaces*/
- int ndev_num; /*the number of nvme devices*/
- struct list_head dev_list;
};
/*
@@ -652,6 +645,4 @@ struct nvme_ns {
u32 mode_select_block_len;
};
-extern struct nvme_info *nvme_info;
-
#endif /* __DRIVER_NVME_H__ */