cxl: Add support for reading CXL switch CDAT table
authorDave Jiang <dave.jiang@intel.com>
Thu, 12 Oct 2023 18:53:48 +0000 (11:53 -0700)
committerDan Williams <dan.j.williams@intel.com>
Sat, 28 Oct 2023 03:48:02 +0000 (20:48 -0700)
Add read_cdat_data() call in cxl_switch_port_probe() to allow
reading of CDAT data for CXL switches. read_cdat_data() needs
to be adjusted for the retrieving of the PCIe device depending
on if the passed in port is endpoint or switch.

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/169713682855.2205276.6418370379144967443.stgit@djiang5-mobl3
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/core/pci.c
drivers/cxl/port.c

index 9321a3865c30ccde750da9fa24ca5ac1c2f417da..c86bcc181a5d3fcba2538cae53493cc50f68d29f 100644 (file)
@@ -613,18 +613,30 @@ static unsigned char cdat_checksum(void *buf, size_t size)
  */
 void read_cdat_data(struct cxl_port *port)
 {
-       struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
-       struct device *host = cxlmd->dev.parent;
+       struct device *uport = port->uport_dev;
        struct device *dev = &port->dev;
        struct pci_doe_mb *cdat_doe;
+       struct pci_dev *pdev = NULL;
+       struct cxl_memdev *cxlmd;
        size_t cdat_length;
        void *cdat_table;
        int rc;
 
-       if (!dev_is_pci(host))
+       if (is_cxl_memdev(uport)) {
+               struct device *host;
+
+               cxlmd = to_cxl_memdev(uport);
+               host = cxlmd->dev.parent;
+               if (dev_is_pci(host))
+                       pdev = to_pci_dev(host);
+       } else if (dev_is_pci(uport)) {
+               pdev = to_pci_dev(uport);
+       }
+
+       if (!pdev)
                return;
-       cdat_doe = pci_find_doe_mailbox(to_pci_dev(host),
-                                       PCI_DVSEC_VENDOR_ID_CXL,
+
+       cdat_doe = pci_find_doe_mailbox(pdev, PCI_DVSEC_VENDOR_ID_CXL,
                                        CXL_DOE_PROTOCOL_TABLE_ACCESS);
        if (!cdat_doe) {
                dev_dbg(dev, "No CDAT mailbox\n");
index 6240e05b95424b9c9627fcde4a0e50171bde1761..47bc8e0b859077776c06fc1daee901ab49cbdd2d 100644 (file)
@@ -62,6 +62,9 @@ static int cxl_switch_port_probe(struct cxl_port *port)
        struct cxl_hdm *cxlhdm;
        int rc;
 
+       /* Cache the data early to ensure is_visible() works */
+       read_cdat_data(port);
+
        rc = devm_cxl_port_enumerate_dports(port);
        if (rc < 0)
                return rc;