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

Configure Feed

Select the types of activity you want to include in your feed.

cxl: support Type2 when initializing cxl_dev_state

In preparation for type2 drivers add function and macro for
differentiating CXL memory expanders (type 3) from CXL device
accelerators (type 2) helping drivers built from public headers
to embed struct cxl_dev_state inside a private struct.

Update type3 driver for using this same initialization.

Signed-off-by: Alejandro Lucero <alucerop@amd.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/20260306164741.3796372-2-alejandro.lucero-palau@amd.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>

authored by

Alejandro Lucero and committed by
Dave Jiang
9a775c07 f338e773

+70 -17
+5 -7
drivers/cxl/core/mbox.c
··· 1521 1521 } 1522 1522 EXPORT_SYMBOL_NS_GPL(cxl_mailbox_init, "CXL"); 1523 1523 1524 - struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev) 1524 + struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial, 1525 + u16 dvsec) 1525 1526 { 1526 1527 struct cxl_memdev_state *mds; 1527 1528 int rc; 1528 1529 1529 - mds = devm_kzalloc(dev, sizeof(*mds), GFP_KERNEL); 1530 + mds = devm_cxl_dev_state_create(dev, CXL_DEVTYPE_CLASSMEM, serial, 1531 + dvsec, struct cxl_memdev_state, cxlds, 1532 + true); 1530 1533 if (!mds) { 1531 1534 dev_err(dev, "No memory available\n"); 1532 1535 return ERR_PTR(-ENOMEM); 1533 1536 } 1534 1537 1535 1538 mutex_init(&mds->event.log_lock); 1536 - mds->cxlds.dev = dev; 1537 - mds->cxlds.reg_map.host = dev; 1538 - mds->cxlds.cxl_mbox.host = dev; 1539 - mds->cxlds.reg_map.resource = CXL_RESOURCE_NONE; 1540 - mds->cxlds.type = CXL_DEVTYPE_CLASSMEM; 1541 1539 1542 1540 rc = devm_cxl_register_mce_notifier(dev, &mds->mce_notifier); 1543 1541 if (rc == -EOPNOTSUPP)
+24
drivers/cxl/core/memdev.c
··· 656 656 657 657 static struct lock_class_key cxl_memdev_key; 658 658 659 + struct cxl_dev_state *_devm_cxl_dev_state_create(struct device *dev, 660 + enum cxl_devtype type, 661 + u64 serial, u16 dvsec, 662 + size_t size, bool has_mbox) 663 + { 664 + struct cxl_dev_state *cxlds = devm_kzalloc(dev, size, GFP_KERNEL); 665 + 666 + if (!cxlds) 667 + return NULL; 668 + 669 + cxlds->dev = dev; 670 + cxlds->type = type; 671 + cxlds->serial = serial; 672 + cxlds->cxl_dvsec = dvsec; 673 + cxlds->reg_map.host = dev; 674 + cxlds->reg_map.resource = CXL_RESOURCE_NONE; 675 + 676 + if (has_mbox) 677 + cxlds->cxl_mbox.host = dev; 678 + 679 + return cxlds; 680 + } 681 + EXPORT_SYMBOL_NS_GPL(_devm_cxl_dev_state_create, "CXL"); 682 + 659 683 static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds, 660 684 const struct file_operations *fops, 661 685 const struct cxl_memdev_attach *attach)
+33 -1
drivers/cxl/cxlmem.h
··· 523 523 return container_of(cxlds, struct cxl_memdev_state, cxlds); 524 524 } 525 525 526 + struct cxl_dev_state *_devm_cxl_dev_state_create(struct device *dev, 527 + enum cxl_devtype type, 528 + u64 serial, u16 dvsec, 529 + size_t size, bool has_mbox); 530 + 531 + /** 532 + * cxl_dev_state_create - safely create and cast a cxl dev state embedded in a 533 + * driver specific struct. 534 + * 535 + * @parent: device behind the request 536 + * @type: CXL device type 537 + * @serial: device identification 538 + * @dvsec: dvsec capability offset 539 + * @drv_struct: driver struct embedding a cxl_dev_state struct 540 + * @member: name of the struct cxl_dev_state member in drv_struct 541 + * @mbox: true if mailbox supported 542 + * 543 + * Returns a pointer to the drv_struct allocated and embedding a cxl_dev_state 544 + * struct initialized. 545 + * 546 + * Introduced for Type2 driver support. 547 + */ 548 + #define devm_cxl_dev_state_create(parent, type, serial, dvsec, drv_struct, member, mbox) \ 549 + ({ \ 550 + static_assert(__same_type(struct cxl_dev_state, \ 551 + ((drv_struct *)NULL)->member)); \ 552 + static_assert(offsetof(drv_struct, member) == 0); \ 553 + (drv_struct *)_devm_cxl_dev_state_create(parent, type, serial, dvsec, \ 554 + sizeof(drv_struct), mbox); \ 555 + }) 556 + 526 557 enum cxl_opcode { 527 558 CXL_MBOX_OP_INVALID = 0x0000, 528 559 CXL_MBOX_OP_RAW = CXL_MBOX_OP_INVALID, ··· 889 858 int cxl_await_media_ready(struct cxl_dev_state *cxlds); 890 859 int cxl_enumerate_cmds(struct cxl_memdev_state *mds); 891 860 int cxl_mem_dpa_fetch(struct cxl_memdev_state *mds, struct cxl_dpa_info *info); 892 - struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev); 861 + struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial, 862 + u16 dvsec); 893 863 void set_exclusive_cxl_commands(struct cxl_memdev_state *mds, 894 864 unsigned long *cmds); 895 865 void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds,
+7 -7
drivers/cxl/pci.c
··· 865 865 int rc, pmu_count; 866 866 unsigned int i; 867 867 bool irq_avail; 868 + u16 dvsec; 868 869 869 870 rc = pcim_enable_device(pdev); 870 871 if (rc) 871 872 return rc; 872 873 pci_set_master(pdev); 873 874 874 - mds = cxl_memdev_state_create(&pdev->dev); 875 + dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL, 876 + PCI_DVSEC_CXL_DEVICE); 877 + if (!dvsec) 878 + pci_warn(pdev, "Device DVSEC not present, skip CXL.mem init\n"); 879 + 880 + mds = cxl_memdev_state_create(&pdev->dev, pci_get_dsn(pdev), dvsec); 875 881 if (IS_ERR(mds)) 876 882 return PTR_ERR(mds); 877 883 cxlds = &mds->cxlds; 878 884 pci_set_drvdata(pdev, cxlds); 879 885 880 886 cxlds->rcd = is_cxl_restricted(pdev); 881 - cxlds->serial = pci_get_dsn(pdev); 882 - cxlds->cxl_dvsec = pci_find_dvsec_capability( 883 - pdev, PCI_VENDOR_ID_CXL, PCI_DVSEC_CXL_DEVICE); 884 - if (!cxlds->cxl_dvsec) 885 - dev_warn(&pdev->dev, 886 - "Device DVSEC not present, skip CXL.mem init\n"); 887 887 888 888 rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map); 889 889 if (rc)
+1 -2
tools/testing/cxl/test/mem.c
··· 1716 1716 if (rc) 1717 1717 return rc; 1718 1718 1719 - mds = cxl_memdev_state_create(dev); 1719 + mds = cxl_memdev_state_create(dev, pdev->id + 1, 0); 1720 1720 if (IS_ERR(mds)) 1721 1721 return PTR_ERR(mds); 1722 1722 ··· 1732 1732 mds->event.buf = (struct cxl_get_event_payload *) mdata->event_buf; 1733 1733 INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mockmem_sanitize_work); 1734 1734 1735 - cxlds->serial = pdev->id + 1; 1736 1735 if (is_rcd(pdev)) 1737 1736 cxlds->rcd = true; 1738 1737