2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 #include <linux/cpumask.h>
14 #include <linux/module.h>
15 #include <linux/device.h>
19 static int nd_region_probe(struct device
*dev
)
22 static unsigned long once
;
23 struct nd_region_data
*ndrd
;
24 struct nd_region
*nd_region
= to_nd_region(dev
);
26 if (nd_region
->num_lanes
> num_online_cpus()
27 && nd_region
->num_lanes
< num_possible_cpus()
28 && !test_and_set_bit(0, &once
)) {
29 dev_info(dev
, "online cpus (%d) < concurrent i/o lanes (%d) < possible cpus (%d)\n",
30 num_online_cpus(), nd_region
->num_lanes
,
32 dev_info(dev
, "setting nr_cpus=%d may yield better libnvdimm device performance\n",
33 nd_region
->num_lanes
);
36 rc
= nd_region_activate(nd_region
);
40 rc
= nd_blk_region_init(nd_region
);
44 rc
= nd_region_register_namespaces(nd_region
, &err
);
48 ndrd
= dev_get_drvdata(dev
);
50 ndrd
->ns_count
= rc
+ err
;
52 if (rc
&& err
&& rc
== err
)
55 nd_region
->btt_seed
= nd_btt_create(nd_region
);
56 nd_region
->pfn_seed
= nd_pfn_create(nd_region
);
57 nd_region
->dax_seed
= nd_dax_create(nd_region
);
62 * Given multiple namespaces per region, we do not want to
63 * disable all the successfully registered peer namespaces upon
64 * a single registration failure. If userspace is missing a
65 * namespace that it expects it can disable/re-enable the region
66 * to retry discovery after correcting the failure.
67 * <regionX>/namespaces returns the current
68 * "<async-registered>/<total>" namespace count.
70 dev_err(dev
, "failed to register %d namespace%s, continuing...\n",
71 err
, err
== 1 ? "" : "s");
75 static int child_unregister(struct device
*dev
, void *data
)
77 nd_device_unregister(dev
, ND_SYNC
);
81 static int nd_region_remove(struct device
*dev
)
83 struct nd_region
*nd_region
= to_nd_region(dev
);
85 device_for_each_child(dev
, NULL
, child_unregister
);
87 /* flush attribute readers and disable */
89 nd_region
->ns_seed
= NULL
;
90 nd_region
->btt_seed
= NULL
;
91 nd_region
->pfn_seed
= NULL
;
92 nd_region
->dax_seed
= NULL
;
93 dev_set_drvdata(dev
, NULL
);
94 nvdimm_bus_unlock(dev
);
99 static int child_notify(struct device
*dev
, void *data
)
101 nd_device_notify(dev
, *(enum nvdimm_event
*) data
);
105 static void nd_region_notify(struct device
*dev
, enum nvdimm_event event
)
107 device_for_each_child(dev
, &event
, child_notify
);
110 static struct nd_device_driver nd_region_driver
= {
111 .probe
= nd_region_probe
,
112 .remove
= nd_region_remove
,
113 .notify
= nd_region_notify
,
117 .type
= ND_DRIVER_REGION_BLK
| ND_DRIVER_REGION_PMEM
,
120 int __init
nd_region_init(void)
122 return nd_driver_register(&nd_region_driver
);
125 void nd_region_exit(void)
127 driver_unregister(&nd_region_driver
.drv
);
130 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_REGION_PMEM
);
131 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_REGION_BLK
);