All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hauke Mehrtens <hauke@hauke-m.de>
To: johannes@sipsolutions.net
Cc: backports@vger.kernel.org, Hauke Mehrtens <hauke@hauke-m.de>,
	Omer Dagan <omer.dagan@tandemg.com>
Subject: [PATCH 2/7] backports: Fix pci_alloc_irq_vectors() backport
Date: Sun,  2 Dec 2018 21:51:26 +0100	[thread overview]
Message-ID: <20181202205131.13519-3-hauke@hauke-m.de> (raw)
In-Reply-To: <20181202205131.13519-1-hauke@hauke-m.de>

Upstream commit: 55039329e10adc511eabb7cf015d88620bf49176

This copies the pci_alloc_irq_vectors() function from kernel 4.9 and
replaces the __pci_enable_msi{x}_range() calls with calls to
pci_enable_msi{x}_range(), these were backported to kernel versions <
3.14, so no need to handle the older kernels specially here.

This also adds support for MSIx IRQs and adds the PCI_IRQ_* defines.

Fixes: 162a6b312f1b ("add support for pci_alloc_irq_vectors")
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Cc: Omer Dagan <omer.dagan@tandemg.com>
---
 backport/backport-include/linux/pci.h |  8 ++++++
 backport/compat/backport-4.8.c        | 49 +++++++++++++++++++++++++----------
 2 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/backport/backport-include/linux/pci.h b/backport/backport-include/linux/pci.h
index 531f5a47..3a141bf3 100644
--- a/backport/backport-include/linux/pci.h
+++ b/backport/backport-include/linux/pci.h
@@ -224,4 +224,12 @@ static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
 
 #endif/* <4.9.0 but not >= 3.12.69, 4.4.37, 4.8.13 */
 
+#ifndef PCI_IRQ_LEGACY
+#define PCI_IRQ_LEGACY		(1 << 0) /* Allow legacy interrupts */
+#define PCI_IRQ_MSI		(1 << 1) /* Allow MSI interrupts */
+#define PCI_IRQ_MSIX		(1 << 2) /* Allow MSI-X interrupts */
+#define PCI_IRQ_ALL_TYPES \
+	(PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
+#endif
+
 #endif /* _BACKPORT_LINUX_PCI_H */
diff --git a/backport/compat/backport-4.8.c b/backport/compat/backport-4.8.c
index a53e39c9..11b2e7d7 100644
--- a/backport/compat/backport-4.8.c
+++ b/backport/compat/backport-4.8.c
@@ -148,25 +148,48 @@ EXPORT_SYMBOL_GPL(cdc_parse_cdc_header);
 
 #ifdef CONFIG_PCI
 #ifdef CONFIG_PCI_MSI
+
+/**
+ * pci_alloc_irq_vectors - allocate multiple IRQs for a device
+ * @dev:		PCI device to operate on
+ * @min_vecs:		minimum number of vectors required (must be >= 1)
+ * @max_vecs:		maximum (desired) number of vectors
+ * @flags:		flags or quirks for the allocation
+ *
+ * Allocate up to @max_vecs interrupt vectors for @dev, using MSI-X or MSI
+ * vectors if available, and fall back to a single legacy vector
+ * if neither is available.  Return the number of vectors allocated,
+ * (which might be smaller than @max_vecs) if successful, or a negative
+ * error code on error. If less than @min_vecs interrupt vectors are
+ * available for @dev the function will fail with -ENOSPC.
+ *
+ * To get the Linux IRQ number used for a vector that can be passed to
+ * request_irq() use the pci_irq_vector() helper.
+ */
 int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
 		unsigned int max_vecs, unsigned int flags)
 {
-	int res;
-	int msi_nvect = max_vecs;
+	int vecs = -ENOSPC;
 
-	if (max_vecs < min_vecs)
-		return -ERANGE;
+	if (flags & PCI_IRQ_MSIX) {
+		vecs = pci_enable_msix_range(dev, NULL, min_vecs, max_vecs);
+		if (vecs > 0)
+			return vecs;
+	}
+
+	if (flags & PCI_IRQ_MSI) {
+		vecs = pci_enable_msi_range(dev, min_vecs, max_vecs);
+		if (vecs > 0)
+			return vecs;
+	}
 
-#if LINUX_VERSION_IS_LESS(3,15,0)
-	res = pci_enable_msi_block(dev, msi_nvect);
-	if (res == 0) {
-		return msi_nvect;
+	/* use legacy irq if allowed */
+	if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1) {
+		pci_intx(dev, 1);
+		return 1;
 	}
-#else
-	res = pci_enable_msi_range(dev, msi_nvect, msi_nvect);
-	return msi_nvect;
-#endif /*LINUX_VERSION_IS_LESS(3,15,0)*/
-	return -ENOSPC;
+
+	return vecs;
 }
 EXPORT_SYMBOL_GPL(pci_alloc_irq_vectors);
 #endif /* CONFIG_PCI_MSI */
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in

  parent reply	other threads:[~2018-12-02 20:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-02 20:51 [PATCH 0/7] backports-4.19: Fixes for kernel 4.19 branch Hauke Mehrtens
2018-12-02 20:51 ` [PATCH 1/7] backports: Refresh patches on kernel 4.19.6 Hauke Mehrtens
2018-12-02 20:51 ` Hauke Mehrtens [this message]
2018-12-02 20:51 ` [PATCH 3/7] backports: Revert "dependencies: Make WIL6210 depend on kernel >= 4.8" Hauke Mehrtens
2018-12-02 20:51 ` [PATCH 4/7] backports: Remove BPAUTO_CRYPTO_SKCIPHER Hauke Mehrtens
2018-12-02 20:51 ` [PATCH 5/7] backports: Do not activate R8188EU on kernels without SKCIPHER Hauke Mehrtens
2018-12-02 20:51 ` [PATCH 6/7] backports: Add missing includes for mt76 driver Hauke Mehrtens
2018-12-02 20:51 ` [PATCH 7/7] backports: Add skcipher_request_zero() Hauke Mehrtens
2018-12-07 20:01 ` [PATCH 0/7] backports-4.19: Fixes for kernel 4.19 branch Hauke Mehrtens

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=20181202205131.13519-3-hauke@hauke-m.de \
    --to=hauke@hauke-m.de \
    --cc=backports@vger.kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=omer.dagan@tandemg.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.