]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
libnvdimm: Fix nvdimm_probe error on NVDIMM-N
authorToshi Kani <toshi.kani@hpe.com>
Tue, 16 Aug 2016 19:08:40 +0000 (13:08 -0600)
committerDan Williams <dan.j.williams@intel.com>
Fri, 2 Sep 2016 01:20:39 +0000 (18:20 -0700)
'ndctl list --buses --dimms' does not list any NVDIMM-Ns since
they are considered as idle.  ndctl checks if any driver is
attached to nmem device.  nvdimm_probe() always fails in
nvdimm_init_nsarea() since NVDIMM-Ns do not implement optinal
ND_CMD_GET_CONFIG_DATA command.

Change nvdimm_probe() to accept the case that the CONFIG_DATA
command is not implemented for NVDIMM-Ns.  The driver attaches
without ndd, which keeps it no-op to the device.

Reported-by: Brian Boylston <brian.boylston@hpe.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Tested-by: Johannes Thumshirn <jthumshirn@suse.de>
Acked-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/nvdimm/dimm.c
drivers/nvdimm/dimm_devs.c
drivers/nvdimm/nd.h

index 71d12bb67339148bac8edc2e70c907aff1852f5a..619834e144d1e65e2314cde9356c86cff44d5053 100644 (file)
@@ -26,6 +26,14 @@ static int nvdimm_probe(struct device *dev)
        struct nvdimm_drvdata *ndd;
        int rc;
 
+       rc = nvdimm_check_config_data(dev);
+       if (rc) {
+               /* not required for non-aliased nvdimm, ex. NVDIMM-N */
+               if (rc == -ENOTTY)
+                       rc = 0;
+               return rc;
+       }
+
        ndd = kzalloc(sizeof(*ndd), GFP_KERNEL);
        if (!ndd)
                return -ENOMEM;
@@ -72,6 +80,9 @@ static int nvdimm_remove(struct device *dev)
 {
        struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
 
+       if (!ndd)
+               return 0;
+
        nvdimm_bus_lock(dev);
        dev_set_drvdata(dev, NULL);
        nvdimm_bus_unlock(dev);
index ce75cc3f41fb21584ae34c11113999ae68761232..cf36470e94c0d805fea2fedccb52528325e2bac8 100644 (file)
@@ -28,28 +28,30 @@ static DEFINE_IDA(dimm_ida);
  * Retrieve bus and dimm handle and return if this bus supports
  * get_config_data commands
  */
-static int __validate_dimm(struct nvdimm_drvdata *ndd)
+int nvdimm_check_config_data(struct device *dev)
 {
-       struct nvdimm *nvdimm;
-
-       if (!ndd)
-               return -EINVAL;
-
-       nvdimm = to_nvdimm(ndd->dev);
+       struct nvdimm *nvdimm = to_nvdimm(dev);
 
-       if (!nvdimm->cmd_mask)
-               return -ENXIO;
-       if (!test_bit(ND_CMD_GET_CONFIG_DATA, &nvdimm->cmd_mask))
-               return -ENXIO;
+       if (!nvdimm->cmd_mask ||
+           !test_bit(ND_CMD_GET_CONFIG_DATA, &nvdimm->cmd_mask)) {
+               if (nvdimm->flags & NDD_ALIASING)
+                       return -ENXIO;
+               else
+                       return -ENOTTY;
+       }
 
        return 0;
 }
 
 static int validate_dimm(struct nvdimm_drvdata *ndd)
 {
-       int rc = __validate_dimm(ndd);
+       int rc;
+
+       if (!ndd)
+               return -EINVAL;
 
-       if (rc && ndd)
+       rc = nvdimm_check_config_data(ndd->dev);
+       if (rc)
                dev_dbg(ndd->dev, "%pf: %s error: %d\n",
                                __builtin_return_address(0), __func__, rc);
        return rc;
index 8024a0ef86d3af9f0ba5ef169260e2e342023d8e..38d6f039234e7aae0e6a9e9923d23e979137448f 100644 (file)
@@ -191,6 +191,7 @@ void nvdimm_exit(void);
 void nd_region_exit(void);
 struct nvdimm;
 struct nvdimm_drvdata *to_ndd(struct nd_mapping *nd_mapping);
+int nvdimm_check_config_data(struct device *dev);
 int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd);
 int nvdimm_init_config_data(struct nvdimm_drvdata *ndd);
 int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,