]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
cxl/mem: Introduce cxl_memdev_attach for CXL-dependent operation
authorDan Williams <dan.j.williams@intel.com>
Tue, 16 Dec 2025 00:56:16 +0000 (16:56 -0800)
committerDave Jiang <dave.jiang@intel.com>
Mon, 5 Jan 2026 17:58:04 +0000 (10:58 -0700)
commit29317f8dc6ed601ec54575689c2cd55cc470bcce
tree56a6b9ab0cd58445035cd8e7b58716e7bf153a3f
parentf2546eba53bbe38c4bb950f78625ccf4b1a2cbc8
cxl/mem: Introduce cxl_memdev_attach for CXL-dependent operation

Unlike the cxl_pci class driver that opportunistically enables memory
expansion with no other dependent functionality, CXL accelerator drivers
have distinct PCIe-only and CXL-enhanced operation states. If CXL is
available some additional coherent memory/cache operations can be enabled,
otherwise traditional DMA+MMIO over PCIe/CXL.io is a fallback.

This constitutes a new mode of operation where the caller of
devm_cxl_add_memdev() wants to make a "go/no-go" decision about running
in CXL accelerated mode or falling back to PCIe-only operation. Part of
that decision making process likely also includes additional
CXL-acceleration-specific resource setup. Encapsulate both of those
requirements into 'struct cxl_memdev_attach' that provides a ->probe()
callback. The probe callback runs in cxl_mem_probe() context, after the
port topology is successfully attached for the given memdev. It supports
a contract where, upon successful return from devm_cxl_add_memdev(),
everything needed for CXL accelerated operation has been enabled.

Additionally the presence of @cxlmd->attach indicates that the accelerator
driver be detached when CXL operation ends. This conceptually makes a CXL
link loss event mirror a PCIe link loss event which results in triggering
the ->remove() callback of affected devices+drivers. A driver can re-attach
to recover back to PCIe-only operation. Live recovery, i.e. without a
->remove()/->probe() cycle, is left as a future consideration.

[ dj: Repalce with updated commit log from Dan ]

Cc: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
Reviewed-by: Ben Cheatham <benjamin.cheatham@amd.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/20251216005616.3090129-7-dan.j.williams@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/memdev.c
drivers/cxl/cxlmem.h
drivers/cxl/mem.c
drivers/cxl/pci.c
tools/testing/cxl/test/mem.c