Skip to content

Commit 516b300

Browse files
committed
cxl/memdev: Formalize endpoint port linkage
Move the endpoint port that the cxl_mem driver establishes from drvdata to a first class attribute. This is in preparation for device-memory drivers reusing the CXL core for memory region management. Those drivers need a type-safe method to retrieve their CXL port linkage. Leave drvdata for private usage of the cxl_mem driver not external consumers of a 'struct cxl_memdev' object. Reviewed-by: Fan Ni <fan.ni@samsung.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/168679264292.3436160.3901392135863405807.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent f3c8a37 commit 516b300

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

drivers/cxl/core/memdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int cxl_trigger_poison_list(struct cxl_memdev *cxlmd)
149149
struct cxl_port *port;
150150
int rc;
151151

152-
port = dev_get_drvdata(&cxlmd->dev);
152+
port = cxlmd->endpoint;
153153
if (!port || !is_cxl_endpoint(port))
154154
return -EINVAL;
155155

@@ -207,7 +207,7 @@ static struct cxl_region *cxl_dpa_to_region(struct cxl_memdev *cxlmd, u64 dpa)
207207
ctx = (struct cxl_dpa_to_region_context) {
208208
.dpa = dpa,
209209
};
210-
port = dev_get_drvdata(&cxlmd->dev);
210+
port = cxlmd->endpoint;
211211
if (port && is_cxl_endpoint(port) && port->commit_end != -1)
212212
device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region);
213213

drivers/cxl/core/pmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int match_nvdimm_bridge(struct device *dev, void *data)
6464

6565
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_memdev *cxlmd)
6666
{
67-
struct cxl_port *port = find_cxl_root(dev_get_drvdata(&cxlmd->dev));
67+
struct cxl_port *port = find_cxl_root(cxlmd->endpoint);
6868
struct device *dev;
6969

7070
if (!port)

drivers/cxl/core/port.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ static struct device *grandparent(struct device *dev)
11611161
static void delete_endpoint(void *data)
11621162
{
11631163
struct cxl_memdev *cxlmd = data;
1164-
struct cxl_port *endpoint = dev_get_drvdata(&cxlmd->dev);
1164+
struct cxl_port *endpoint = cxlmd->endpoint;
11651165
struct cxl_port *parent_port;
11661166
struct device *parent;
11671167

@@ -1176,6 +1176,7 @@ static void delete_endpoint(void *data)
11761176
devm_release_action(parent, cxl_unlink_uport, endpoint);
11771177
devm_release_action(parent, unregister_port, endpoint);
11781178
}
1179+
cxlmd->endpoint = NULL;
11791180
device_unlock(parent);
11801181
put_device(parent);
11811182
out:
@@ -1187,7 +1188,7 @@ int cxl_endpoint_autoremove(struct cxl_memdev *cxlmd, struct cxl_port *endpoint)
11871188
struct device *dev = &cxlmd->dev;
11881189

11891190
get_device(&endpoint->dev);
1190-
dev_set_drvdata(dev, endpoint);
1191+
cxlmd->endpoint = endpoint;
11911192
cxlmd->depth = endpoint->depth;
11921193
return devm_add_action_or_reset(dev, delete_endpoint, cxlmd);
11931194
}

drivers/cxl/cxlmem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @detach_work: active memdev lost a port in its ancestry
3939
* @cxl_nvb: coordinate removal of @cxl_nvd if present
4040
* @cxl_nvd: optional bridge to an nvdimm if the device supports pmem
41+
* @endpoint: connection to the CXL port topology for this memory device
4142
* @id: id number of this memdev instance.
4243
* @depth: endpoint port depth
4344
*/
@@ -48,6 +49,7 @@ struct cxl_memdev {
4849
struct work_struct detach_work;
4950
struct cxl_nvdimm_bridge *cxl_nvb;
5051
struct cxl_nvdimm *cxl_nvd;
52+
struct cxl_port *endpoint;
5153
int id;
5254
int depth;
5355
};

0 commit comments

Comments
 (0)