On Sun, 23 Jan 2022 16:31:02 -0800 Dan Williams <dan.j.williams@xxxxxxxxx> wrote: > From: Ben Widawsky <ben.widawsky@xxxxxxxxx> > > The PCIe device DVSEC, defined in the CXL 2.0 spec, 8.1.3 is required to > be implemented by CXL 2.0 endpoint devices. Since the information > contained within this DVSEC will be critically important, it makes sense > to find the value early, and error out if it cannot be found. > > Signed-off-by: Ben Widawsky <ben.widawsky@xxxxxxxxx> > Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx> Guess the logic makes sense about checking this early though my cynical mind says, that if someone is putting in devices that claim to be CXL ones and this isn't there it is there own problem if they kernel wastes effort bringing the driver up only to find later it can't finish doing so... Reviewed-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> note that I got confused by this one when checking what it was for as you rename it in the next patch... I'll complain about that there ;) > --- > drivers/cxl/cxlmem.h | 2 ++ > drivers/cxl/pci.c | 9 +++++++++ > 2 files changed, 11 insertions(+) > > diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h > index 90d67fff5bed..cedc6d3c0448 100644 > --- a/drivers/cxl/cxlmem.h > +++ b/drivers/cxl/cxlmem.h > @@ -98,6 +98,7 @@ struct cxl_mbox_cmd { > * > * @dev: The device associated with this CXL state > * @regs: Parsed register blocks > + * @device_dvsec: Offset to the PCIe device DVSEC > * @payload_size: Size of space for payload > * (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register) > * @lsa_size: Size of Label Storage Area > @@ -126,6 +127,7 @@ struct cxl_dev_state { > struct device *dev; > > struct cxl_regs regs; > + int device_dvsec; > > size_t payload_size; > size_t lsa_size; > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > index e54dbdf9ac15..76de39b90351 100644 > --- a/drivers/cxl/pci.c > +++ b/drivers/cxl/pci.c > @@ -408,6 +408,15 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) > if (IS_ERR(cxlds)) > return PTR_ERR(cxlds); > > + cxlds->device_dvsec = pci_find_dvsec_capability(pdev, > + PCI_DVSEC_VENDOR_ID_CXL, > + CXL_DVSEC_PCIE_DEVICE); > + if (!cxlds->device_dvsec) { > + dev_err(&pdev->dev, > + "Device DVSEC not present. Expect limited functionality.\n"); > + return -ENXIO; > + } > + > rc = cxl_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map); > if (rc) > return rc; >