Skip to content

Commit 2e52b62

Browse files
committed
cxl/pmem: Add support for multiple nvdimm-bridge objects
In preparation for a mocked unit test environment for CXL objects, allow for multiple unique nvdimm-bridge objects. For now, just allow multiple bridges to be registered. Later, when there are multiple present, further updates are needed to cxl_find_nvdimm_bridge() to identify which bridge is associated with which CXL hierarchy for nvdimm registration. Note that this does change the kernel device-name for the bridge object. User space should not have any attachment to the device name at this point as it is still early days in the CXL driver development. Acked-by: Ben Widawsky <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/163164647007.2831228.2150246954620721526.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 60b8f17 commit 2e52b62

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

drivers/cxl/core/pmem.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright(c) 2020 Intel Corporation. */
33
#include <linux/device.h>
44
#include <linux/slab.h>
5+
#include <linux/idr.h>
56
#include <cxlmem.h>
67
#include <cxl.h>
78
#include "core.h"
@@ -20,10 +21,13 @@
2021
* operations, for example, namespace label access commands.
2122
*/
2223

24+
static DEFINE_IDA(cxl_nvdimm_bridge_ida);
25+
2326
static void cxl_nvdimm_bridge_release(struct device *dev)
2427
{
2528
struct cxl_nvdimm_bridge *cxl_nvb = to_cxl_nvdimm_bridge(dev);
2629

30+
ida_free(&cxl_nvdimm_bridge_ida, cxl_nvb->id);
2731
kfree(cxl_nvb);
2832
}
2933

@@ -47,16 +51,38 @@ struct cxl_nvdimm_bridge *to_cxl_nvdimm_bridge(struct device *dev)
4751
}
4852
EXPORT_SYMBOL_GPL(to_cxl_nvdimm_bridge);
4953

54+
static int match_nvdimm_bridge(struct device *dev, const void *data)
55+
{
56+
return dev->type == &cxl_nvdimm_bridge_type;
57+
}
58+
59+
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(void)
60+
{
61+
struct device *dev;
62+
63+
dev = bus_find_device(&cxl_bus_type, NULL, NULL, match_nvdimm_bridge);
64+
if (!dev)
65+
return NULL;
66+
return to_cxl_nvdimm_bridge(dev);
67+
}
68+
EXPORT_SYMBOL_GPL(cxl_find_nvdimm_bridge);
69+
5070
static struct cxl_nvdimm_bridge *
5171
cxl_nvdimm_bridge_alloc(struct cxl_port *port)
5272
{
5373
struct cxl_nvdimm_bridge *cxl_nvb;
5474
struct device *dev;
75+
int rc;
5576

5677
cxl_nvb = kzalloc(sizeof(*cxl_nvb), GFP_KERNEL);
5778
if (!cxl_nvb)
5879
return ERR_PTR(-ENOMEM);
5980

81+
rc = ida_alloc(&cxl_nvdimm_bridge_ida, GFP_KERNEL);
82+
if (rc < 0)
83+
goto err;
84+
cxl_nvb->id = rc;
85+
6086
dev = &cxl_nvb->dev;
6187
cxl_nvb->port = port;
6288
cxl_nvb->state = CXL_NVB_NEW;
@@ -67,6 +93,10 @@ cxl_nvdimm_bridge_alloc(struct cxl_port *port)
6793
dev->type = &cxl_nvdimm_bridge_type;
6894

6995
return cxl_nvb;
96+
97+
err:
98+
kfree(cxl_nvb);
99+
return ERR_PTR(rc);
70100
}
71101

72102
static void unregister_nvb(void *_cxl_nvb)
@@ -119,7 +149,7 @@ struct cxl_nvdimm_bridge *devm_cxl_add_nvdimm_bridge(struct device *host,
119149
return cxl_nvb;
120150

121151
dev = &cxl_nvb->dev;
122-
rc = dev_set_name(dev, "nvdimm-bridge");
152+
rc = dev_set_name(dev, "nvdimm-bridge%d", cxl_nvb->id);
123153
if (rc)
124154
goto err;
125155

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ enum cxl_nvdimm_brige_state {
211211
};
212212

213213
struct cxl_nvdimm_bridge {
214+
int id;
214215
struct device dev;
215216
struct cxl_port *port;
216217
struct nvdimm_bus *nvdimm_bus;
@@ -323,4 +324,5 @@ struct cxl_nvdimm_bridge *devm_cxl_add_nvdimm_bridge(struct device *host,
323324
struct cxl_nvdimm *to_cxl_nvdimm(struct device *dev);
324325
bool is_cxl_nvdimm(struct device *dev);
325326
int devm_cxl_add_nvdimm(struct device *host, struct cxl_memdev *cxlmd);
327+
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(void);
326328
#endif /* __CXL_H__ */

drivers/cxl/pmem.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ static void unregister_nvdimm(void *nvdimm)
2929
nvdimm_delete(nvdimm);
3030
}
3131

32-
static int match_nvdimm_bridge(struct device *dev, const void *data)
33-
{
34-
return strcmp(dev_name(dev), "nvdimm-bridge") == 0;
35-
}
36-
37-
static struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(void)
38-
{
39-
struct device *dev;
40-
41-
dev = bus_find_device(&cxl_bus_type, NULL, NULL, match_nvdimm_bridge);
42-
if (!dev)
43-
return NULL;
44-
return to_cxl_nvdimm_bridge(dev);
45-
}
46-
4732
static int cxl_nvdimm_probe(struct device *dev)
4833
{
4934
struct cxl_nvdimm *cxl_nvd = to_cxl_nvdimm(dev);

0 commit comments

Comments
 (0)