From d603c3d73bcb3df468c81dc3bdb577e80dabca9b Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 1 Nov 2013 23:30:54 +0000 Subject: [PATCH] Create a unique unit number for each controller and namespace cdev. Sponsored by: Intel MFC after: 3 days --- sys/dev/nvme/nvme_ctrlr.c | 4 ++-- sys/dev/nvme/nvme_ns.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 322d5a4b36dc..de037b7a3f8d 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -1150,8 +1150,8 @@ intx: if (status != 0) return (status); - ctrlr->cdev = make_dev(&nvme_ctrlr_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, - "nvme%d", device_get_unit(dev)); + ctrlr->cdev = make_dev(&nvme_ctrlr_cdevsw, device_get_unit(dev), + UID_ROOT, GID_WHEEL, 0600, "nvme%d", device_get_unit(dev)); if (ctrlr->cdev == NULL) return (ENXIO); diff --git a/sys/dev/nvme/nvme_ns.c b/sys/dev/nvme/nvme_ns.c index 24e07795c1ca..ed2214d68a00 100644 --- a/sys/dev/nvme/nvme_ns.c +++ b/sys/dev/nvme/nvme_ns.c @@ -492,6 +492,7 @@ nvme_ns_construct(struct nvme_namespace *ns, uint16_t id, struct nvme_controller *ctrlr) { struct nvme_completion_poll_status status; + int unit; ns->ctrlr = ctrlr; ns->id = id; @@ -553,6 +554,12 @@ nvme_ns_construct(struct nvme_namespace *ns, uint16_t id, if (ns->cdev != NULL) return (0); + /* + * Namespace IDs start at 1, so we need to subtract 1 to create a + * correct unit number. + */ + unit = device_get_unit(ctrlr->dev) * NVME_MAX_NAMESPACES + ns->id - 1; + /* * MAKEDEV_ETERNAL was added in r210923, for cdevs that will never * be destroyed. This avoids refcounting on the cdev object. @@ -560,11 +567,11 @@ nvme_ns_construct(struct nvme_namespace *ns, uint16_t id, * surprise removal nor namespace deletion. */ #ifdef MAKEDEV_ETERNAL_KLD - ns->cdev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &nvme_ns_cdevsw, 0, + ns->cdev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &nvme_ns_cdevsw, unit, NULL, UID_ROOT, GID_WHEEL, 0600, "nvme%dns%d", device_get_unit(ctrlr->dev), ns->id); #else - ns->cdev = make_dev_credf(0, &nvme_ns_cdevsw, 0, + ns->cdev = make_dev_credf(0, &nvme_ns_cdevsw, unit, NULL, UID_ROOT, GID_WHEEL, 0600, "nvme%dns%d", device_get_unit(ctrlr->dev), ns->id); #endif