]>
Commit | Line | Data |
---|---|---|
3d88002e DW |
1 | /* |
2 | * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. | |
3 | * | |
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. | |
7 | * | |
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. | |
12 | */ | |
5212e11f | 13 | #include <linux/cpumask.h> |
3d88002e DW |
14 | #include <linux/module.h> |
15 | #include <linux/device.h> | |
16 | #include <linux/nd.h> | |
17 | #include "nd.h" | |
18 | ||
19 | static int nd_region_probe(struct device *dev) | |
20 | { | |
047fc8a1 | 21 | int err, rc; |
5212e11f | 22 | static unsigned long once; |
3d88002e DW |
23 | struct nd_region_namespaces *num_ns; |
24 | struct nd_region *nd_region = to_nd_region(dev); | |
3d88002e | 25 | |
5212e11f VV |
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, | |
31 | num_possible_cpus()); | |
32 | dev_info(dev, "setting nr_cpus=%d may yield better libnvdimm device performance\n", | |
33 | nd_region->num_lanes); | |
34 | } | |
35 | ||
047fc8a1 RZ |
36 | rc = nd_blk_region_init(nd_region); |
37 | if (rc) | |
38 | return rc; | |
39 | ||
40 | rc = nd_region_register_namespaces(nd_region, &err); | |
3d88002e DW |
41 | num_ns = devm_kzalloc(dev, sizeof(*num_ns), GFP_KERNEL); |
42 | if (!num_ns) | |
43 | return -ENOMEM; | |
44 | ||
45 | if (rc < 0) | |
46 | return rc; | |
47 | ||
48 | num_ns->active = rc; | |
49 | num_ns->count = rc + err; | |
50 | dev_set_drvdata(dev, num_ns); | |
51 | ||
8c2f7e86 DW |
52 | if (rc && err && rc == err) |
53 | return -ENODEV; | |
54 | ||
55 | nd_region->btt_seed = nd_btt_create(nd_region); | |
e1455744 | 56 | nd_region->pfn_seed = nd_pfn_create(nd_region); |
3d88002e DW |
57 | if (err == 0) |
58 | return 0; | |
59 | ||
3d88002e DW |
60 | /* |
61 | * Given multiple namespaces per region, we do not want to | |
62 | * disable all the successfully registered peer namespaces upon | |
63 | * a single registration failure. If userspace is missing a | |
64 | * namespace that it expects it can disable/re-enable the region | |
65 | * to retry discovery after correcting the failure. | |
66 | * <regionX>/namespaces returns the current | |
67 | * "<async-registered>/<total>" namespace count. | |
68 | */ | |
69 | dev_err(dev, "failed to register %d namespace%s, continuing...\n", | |
70 | err, err == 1 ? "" : "s"); | |
71 | return 0; | |
72 | } | |
73 | ||
74 | static int child_unregister(struct device *dev, void *data) | |
75 | { | |
76 | nd_device_unregister(dev, ND_SYNC); | |
77 | return 0; | |
78 | } | |
79 | ||
80 | static int nd_region_remove(struct device *dev) | |
81 | { | |
bf9bccc1 DW |
82 | struct nd_region *nd_region = to_nd_region(dev); |
83 | ||
3d88002e DW |
84 | /* flush attribute readers and disable */ |
85 | nvdimm_bus_lock(dev); | |
bf9bccc1 | 86 | nd_region->ns_seed = NULL; |
8c2f7e86 | 87 | nd_region->btt_seed = NULL; |
e1455744 | 88 | nd_region->pfn_seed = NULL; |
3d88002e DW |
89 | dev_set_drvdata(dev, NULL); |
90 | nvdimm_bus_unlock(dev); | |
91 | ||
92 | device_for_each_child(dev, NULL, child_unregister); | |
93 | return 0; | |
94 | } | |
95 | ||
71999466 DW |
96 | static int child_notify(struct device *dev, void *data) |
97 | { | |
98 | nd_device_notify(dev, *(enum nvdimm_event *) data); | |
99 | return 0; | |
100 | } | |
101 | ||
102 | static void nd_region_notify(struct device *dev, enum nvdimm_event event) | |
103 | { | |
104 | device_for_each_child(dev, &event, child_notify); | |
105 | } | |
106 | ||
3d88002e DW |
107 | static struct nd_device_driver nd_region_driver = { |
108 | .probe = nd_region_probe, | |
109 | .remove = nd_region_remove, | |
71999466 | 110 | .notify = nd_region_notify, |
3d88002e DW |
111 | .drv = { |
112 | .name = "nd_region", | |
113 | }, | |
114 | .type = ND_DRIVER_REGION_BLK | ND_DRIVER_REGION_PMEM, | |
115 | }; | |
116 | ||
117 | int __init nd_region_init(void) | |
118 | { | |
119 | return nd_driver_register(&nd_region_driver); | |
120 | } | |
121 | ||
122 | void nd_region_exit(void) | |
123 | { | |
124 | driver_unregister(&nd_region_driver.drv); | |
125 | } | |
126 | ||
127 | MODULE_ALIAS_ND_DEVICE(ND_DEVICE_REGION_PMEM); | |
128 | MODULE_ALIAS_ND_DEVICE(ND_DEVICE_REGION_BLK); |