All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: Davidlohr Bueso <dave@stgolabs.net>,
	 Jonathan Cameron <jonathan.cameron@huawei.com>,
	 Dave Jiang <dave.jiang@intel.com>,
	 Alison Schofield <alison.schofield@intel.com>,
	 Vishal Verma <vishal.l.verma@intel.com>,
	 Dan Williams <dan.j.williams@intel.com>
Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Ira Weiny <ira.weiny@intel.com>
Subject: [PATCH RFC] cxl/pci: Skip irq features if irq's are not supported
Date: Mon, 08 Jan 2024 23:51:13 -0800	[thread overview]
Message-ID: <20240108-dont-fail-irq-v1-1-4407228debd2@intel.com> (raw)

CXL 3.1 Section 3.1.1 states:

	"A Function on a CXL device must not generate INTx messages if
	that Function participates in CXL.cache protocol or CXL.mem
	protocols."

The generic CXL memory driver only supports devices which use the
CXL.mem protocol.  The current driver attempts to allocate MSI/MSI-X
vectors in anticipation of their need for mailbox interrupts or event
processing.  However, the above requirement does not require a device to
support interrupts at all.  A device may not use mailbox interrupts and
may be configured for firmware first event processing.

Rather than fail device probe if interrupts are not supported; flag such
that irqs are not supported and do not enable features which require
interrupts.  dev_warn() in those cases which require interrupts but they
were not supported.

It is possible for a device to have host based event processing through
polling but this patch does not support the addition of such polling.
Leave that to the future if such a device comes along.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
Compile tested only.

This is an RFC based on errors seen by Dave Larson and reported on
discord.  Dan requested that the driver not fail if irqs are not
required.
---
 drivers/cxl/cxlmem.h |  2 ++
 drivers/cxl/pci.c    | 25 +++++++++++++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index a2fcbca253f3..422bc9657e5c 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -410,6 +410,7 @@ enum cxl_devtype {
  * @ram_res: Active Volatile memory capacity configuration
  * @serial: PCIe Device Serial Number
  * @type: Generic Memory Class device or Vendor Specific Memory device
+ * @irq_supported: Flag if irqs are supported by the device
  */
 struct cxl_dev_state {
 	struct device *dev;
@@ -424,6 +425,7 @@ struct cxl_dev_state {
 	struct resource ram_res;
 	u64 serial;
 	enum cxl_devtype type;
+	bool irq_supported;
 };
 
 /**
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index 0155fb66b580..bb90ac011290 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -443,6 +443,12 @@ static int cxl_pci_setup_mailbox(struct cxl_memdev_state *mds)
 	if (!(cap & CXLDEV_MBOX_CAP_BG_CMD_IRQ))
 		return 0;
 
+	if (!cxlds->irq_supported) {
+		dev_err(cxlds->dev, "Mailbox interrupts enabled but device indicates no interrupt vectors supported.\n");
+		dev_err(cxlds->dev, "Skip mailbox iterrupt configuration.\n");
+		return 0;
+	}
+
 	msgnum = FIELD_GET(CXLDEV_MBOX_CAP_IRQ_MSGNUM_MASK, cap);
 	irq = pci_irq_vector(to_pci_dev(cxlds->dev), msgnum);
 	if (irq < 0)
@@ -587,7 +593,8 @@ static int cxl_mem_alloc_event_buf(struct cxl_memdev_state *mds)
 	return devm_add_action_or_reset(mds->cxlds.dev, free_event_buf, buf);
 }
 
-static int cxl_alloc_irq_vectors(struct pci_dev *pdev)
+static void cxl_alloc_irq_vectors(struct pci_dev *pdev,
+				  struct cxl_dev_state *cxlds)
 {
 	int nvecs;
 
@@ -604,9 +611,10 @@ static int cxl_alloc_irq_vectors(struct pci_dev *pdev)
 				      PCI_IRQ_MSIX | PCI_IRQ_MSI);
 	if (nvecs < 1) {
 		dev_dbg(&pdev->dev, "Failed to alloc irq vectors: %d\n", nvecs);
-		return -ENXIO;
+		return;
 	}
-	return 0;
+
+	cxlds->irq_supported = true;
 }
 
 static irqreturn_t cxl_event_thread(int irq, void *id)
@@ -754,6 +762,13 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,
 	if (!host_bridge->native_cxl_error)
 		return 0;
 
+	/* Polling not supported */
+	if (!mds->cxlds.irq_supported) {
+		dev_err(mds->cxlds.dev, "Host events enabled but device indicates no interrupt vectors supported.\n");
+		dev_err(mds->cxlds.dev, "Event polling is not supported, skip event processing.\n");
+		return 0;
+	}
+
 	rc = cxl_mem_alloc_event_buf(mds);
 	if (rc)
 		return rc;
@@ -845,9 +860,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	else
 		dev_warn(&pdev->dev, "Media not active (%d)\n", rc);
 
-	rc = cxl_alloc_irq_vectors(pdev);
-	if (rc)
-		return rc;
+	cxl_alloc_irq_vectors(pdev, cxlds);
 
 	rc = cxl_pci_setup_mailbox(mds);
 	if (rc)

---
base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a
change-id: 20240108-dont-fail-irq-a96310368f0f

Best regards,
-- 
Ira Weiny <ira.weiny@intel.com>


             reply	other threads:[~2024-01-09  7:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09  7:51 Ira Weiny [this message]
2024-01-09 23:29 ` [PATCH RFC] cxl/pci: Skip irq features if irq's are not supported Alison Schofield
2024-01-10 16:51   ` Ira Weiny
2024-01-10  0:22 ` Dan Williams
2024-01-10 17:13   ` Ira Weiny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240108-dont-fail-irq-v1-1-4407228debd2@intel.com \
    --to=ira.weiny@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.