[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250205151950.25268-13-alucerop@amd.com>
Date: Wed, 5 Feb 2025 15:19:36 +0000
From: <alucerop@....com>
To: <linux-cxl@...r.kernel.org>, <netdev@...r.kernel.org>,
<dan.j.williams@...el.com>, <edward.cree@....com>, <davem@...emloft.net>,
<kuba@...nel.org>, <pabeni@...hat.com>, <edumazet@...gle.com>,
<dave.jiang@...el.com>
CC: Alejandro Lucero <alucerop@....com>
Subject: [PATCH v10 12/26] cxl: prepare memdev creation for type2
From: Alejandro Lucero <alucerop@....com>
Current cxl core is relying on a CXL_DEVTYPE_CLASSMEM type device when
creating a memdev leading to problems when obtaining cxl_memdev_state
references from a CXL_DEVTYPE_DEVMEM type.
Modify check for obtaining cxl_memdev_state adding CXL_DEVTYPE_DEVMEM
support.
Make devm_cxl_add_memdev accesible from a accel driver.
Signed-off-by: Alejandro Lucero <alucerop@....com>
---
drivers/cxl/core/memdev.c | 17 ++++++++++++++---
drivers/cxl/cxlmem.h | 5 ++---
drivers/cxl/pci.c | 2 +-
include/cxl/cxl.h | 2 ++
4 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index 7113a51b3a93..9a414980b550 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -562,9 +562,16 @@ static const struct device_type cxl_memdev_type = {
.groups = cxl_memdev_attribute_groups,
};
+static const struct device_type cxl_accel_memdev_type = {
+ .name = "cxl_accel_memdev",
+ .release = cxl_memdev_release,
+ .devnode = cxl_memdev_devnode,
+};
+
bool is_cxl_memdev(const struct device *dev)
{
- return dev->type == &cxl_memdev_type;
+ return (dev->type == &cxl_memdev_type ||
+ dev->type == &cxl_accel_memdev_type);
}
EXPORT_SYMBOL_NS_GPL(is_cxl_memdev, "CXL");
@@ -691,7 +698,10 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
dev->parent = cxlds->dev;
dev->bus = &cxl_bus_type;
dev->devt = MKDEV(cxl_mem_major, cxlmd->id);
- dev->type = &cxl_memdev_type;
+ if (cxlds->type == CXL_DEVTYPE_DEVMEM)
+ dev->type = &cxl_accel_memdev_type;
+ else
+ dev->type = &cxl_memdev_type;
device_set_pm_not_required(dev);
INIT_WORK(&cxlmd->detach_work, detach_memdev);
@@ -1069,8 +1079,9 @@ static const struct file_operations cxl_memdev_fops = {
};
struct cxl_memdev *devm_cxl_add_memdev(struct device *host,
- struct cxl_dev_state *cxlds)
+ struct cxl_memdev_state *cxlmds)
{
+ struct cxl_dev_state *cxlds = &cxlmds->cxlds;
struct cxl_memdev *cxlmd;
struct device *dev;
struct cdev *cdev;
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index a5994061780c..760f7e16a6a4 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -88,8 +88,6 @@ static inline bool is_cxl_endpoint(struct cxl_port *port)
return is_cxl_memdev(port->uport_dev);
}
-struct cxl_memdev *devm_cxl_add_memdev(struct device *host,
- struct cxl_dev_state *cxlds);
int devm_cxl_sanitize_setup_notifier(struct device *host,
struct cxl_memdev *cxlmd);
struct cxl_memdev_state;
@@ -514,7 +512,8 @@ struct cxl_memdev_state {
static inline struct cxl_memdev_state *
to_cxl_memdev_state(struct cxl_dev_state *cxlds)
{
- if (cxlds->type != CXL_DEVTYPE_CLASSMEM)
+ if (cxlds->type != CXL_DEVTYPE_CLASSMEM &&
+ cxlds->type != CXL_DEVTYPE_DEVMEM)
return NULL;
return container_of(cxlds, struct cxl_memdev_state, cxlds);
}
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index bcfa3d86c37b..485e60f60288 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -959,7 +959,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (rc)
return rc;
- cxlmd = devm_cxl_add_memdev(&pdev->dev, cxlds);
+ cxlmd = devm_cxl_add_memdev(&pdev->dev, mds);
if (IS_ERR(cxlmd))
return PTR_ERR(cxlmd);
diff --git a/include/cxl/cxl.h b/include/cxl/cxl.h
index ec56a82966c0..592aa5e75bc2 100644
--- a/include/cxl/cxl.h
+++ b/include/cxl/cxl.h
@@ -78,4 +78,6 @@ void cxl_set_media_ready(struct cxl_memdev_state *mds);
void cxl_dev_state_setup(struct cxl_memdev_state *mds, struct mds_info *info);
int cxl_mem_dpa_fetch(struct cxl_memdev_state *mds, struct cxl_dpa_info *info);
int cxl_dpa_setup(struct cxl_memdev_state *cxlmds, const struct cxl_dpa_info *info);
+struct cxl_memdev *devm_cxl_add_memdev(struct device *host,
+ struct cxl_memdev_state *cxlmds);
#endif
--
2.17.1
Powered by blists - more mailing lists