Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cxl/pci: Create PCI DOE mailbox's for memory devices

DOE mailbox objects will be needed for various mailbox communications
with each memory device.

Iterate each DOE mailbox capability and create PCI DOE mailbox objects
as found.

It is not anticipated that this is the final resting place for the
iteration of the DOE devices. The support of switch ports will drive
this code into the PCIe side. In this imagined architecture the CXL
port driver would then query into the PCI device for the DOE mailbox
array.

For now creating the mailboxes in the CXL port is good enough for the
endpoints. Later PCIe ports will need to support this to support switch
ports more generically.

Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Link: https://lore.kernel.org/r/20220719205249.566684-5-ira.weiny@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

authored by

Ira Weiny and committed by
Dan Williams
3eddcc93 9d24322e

+48
+1
drivers/cxl/Kconfig
··· 2 2 menuconfig CXL_BUS 3 3 tristate "CXL (Compute Express Link) Devices Support" 4 4 depends on PCI 5 + select PCI_DOE 5 6 help 6 7 CXL is a bus that is electrically compatible with PCI Express, but 7 8 layers three protocols on that signalling (CXL.io, CXL.cache, and
+3
drivers/cxl/cxlmem.h
··· 192 192 * @component_reg_phys: register base of component registers 193 193 * @info: Cached DVSEC information about the device. 194 194 * @serial: PCIe Device Serial Number 195 + * @doe_mbs: PCI DOE mailbox array 195 196 * @mbox_send: @dev specific transport for transmitting mailbox commands 196 197 * 197 198 * See section 8.2.9.5.2 Capacity Configuration and Label Storage for ··· 226 225 227 226 resource_size_t component_reg_phys; 228 227 u64 serial; 228 + 229 + struct xarray doe_mbs; 229 230 230 231 int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd); 231 232 };
+44
drivers/cxl/pci.c
··· 8 8 #include <linux/mutex.h> 9 9 #include <linux/list.h> 10 10 #include <linux/pci.h> 11 + #include <linux/pci-doe.h> 11 12 #include <linux/io.h> 12 13 #include "cxlmem.h" 13 14 #include "cxlpci.h" ··· 387 386 return rc; 388 387 } 389 388 389 + static void cxl_pci_destroy_doe(void *mbs) 390 + { 391 + xa_destroy(mbs); 392 + } 393 + 394 + static void devm_cxl_pci_create_doe(struct cxl_dev_state *cxlds) 395 + { 396 + struct device *dev = cxlds->dev; 397 + struct pci_dev *pdev = to_pci_dev(dev); 398 + u16 off = 0; 399 + 400 + xa_init(&cxlds->doe_mbs); 401 + if (devm_add_action(&pdev->dev, cxl_pci_destroy_doe, &cxlds->doe_mbs)) { 402 + dev_err(dev, "Failed to create XArray for DOE's\n"); 403 + return; 404 + } 405 + 406 + /* 407 + * Mailbox creation is best effort. Higher layers must determine if 408 + * the lack of a mailbox for their protocol is a device failure or not. 409 + */ 410 + pci_doe_for_each_off(pdev, off) { 411 + struct pci_doe_mb *doe_mb; 412 + 413 + doe_mb = pcim_doe_create_mb(pdev, off); 414 + if (IS_ERR(doe_mb)) { 415 + dev_err(dev, "Failed to create MB object for MB @ %x\n", 416 + off); 417 + continue; 418 + } 419 + 420 + if (xa_insert(&cxlds->doe_mbs, off, doe_mb, GFP_KERNEL)) { 421 + dev_err(dev, "xa_insert failed to insert MB @ %x\n", 422 + off); 423 + continue; 424 + } 425 + 426 + dev_dbg(dev, "Created DOE mailbox @%x\n", off); 427 + } 428 + } 429 + 390 430 static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 391 431 { 392 432 struct cxl_register_map map; ··· 475 433 dev_warn(&pdev->dev, "No component registers (%d)\n", rc); 476 434 477 435 cxlds->component_reg_phys = cxl_regmap_to_base(pdev, &map); 436 + 437 + devm_cxl_pci_create_doe(cxlds); 478 438 479 439 rc = cxl_pci_setup_mailbox(cxlds); 480 440 if (rc)