Backports Archive on lore.kernel.org
 help / color / Atom feed
From: Omer Dagan <omer.dagan@tandemg.com>
To: "hauke@hauke-m.de" <hauke@hauke-m.de>,
	"mcgrof@kernel.org" <mcgrof@kernel.org>
Cc: "backports@vger.kernel.org" <backports@vger.kernel.org>,
	Omer Dagan <omer.dagan@tandemg.com>
Subject: [PATCH] add support for pci_alloc_irq_vectors
Date: Wed, 3 Oct 2018 09:18:09 +0000
Message-ID: <20181003091746.28511-1-omer.dagan@tandemg.com> (raw)

From: Omer Dagan <omer.dagan@tandemg.com>

    add support for function in kernels under 4.8
    function is a wrapper around 'pci_enable_msi_block' or
    'pci_enable_msi_range' depending on the kernel version
    the min\max number of interrupts was overridden to always use the
    max number of interrupts which seems correct since it was not
    supported in the old APIs

Signed-off-by: Omer Dagan <omer.dagan@tandemg.com>
---
 backport/backport-include/linux/pci.h | 19 +++++++++++++++++++
 backport/compat/backport-4.8.c        | 25 +++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/backport/backport-include/linux/pci.h b/backport/backport-include/linux/pci.h
index 67ac40fc..531f5a47 100644
--- a/backport/backport-include/linux/pci.h
+++ b/backport/backport-include/linux/pci.h
@@ -134,6 +134,25 @@ static inline int pci_vfs_assigned(struct pci_dev *dev)
 
 #endif /* LINUX_VERSION_IS_LESS(3,10,0) */
 
+#if LINUX_VERSION_IS_LESS(4,8,0)
+#define pci_alloc_irq_vectors LINUX_BACKPORT(pci_alloc_irq_vectors)
+#ifdef CONFIG_PCI_MSI
+int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
+		unsigned int max_vecs, unsigned int flags);
+#else
+static inline int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
+		unsigned int max_vecs, unsigned int flags)
+{ return -ENOSYS; }
+#endif
+#endif
+
+#if LINUX_VERSION_IS_LESS(4,8,0)
+#define pci_free_irq_vectors LINUX_BACKPORT(pci_free_irq_vectors)
+static inline void pci_free_irq_vectors(struct pci_dev *dev)
+{
+}
+#endif
+
 #if LINUX_VERSION_IS_LESS(3,14,0)
 #define pci_enable_msi_range LINUX_BACKPORT(pci_enable_msi_range)
 #ifdef CONFIG_PCI_MSI
diff --git a/backport/compat/backport-4.8.c b/backport/compat/backport-4.8.c
index 7d056444..706bd067 100644
--- a/backport/compat/backport-4.8.c
+++ b/backport/compat/backport-4.8.c
@@ -9,6 +9,7 @@
  */
 #include <linux/usb.h>
 #include <linux/usb/cdc.h>
+#include <linux/pci.h>
 
 int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr,
 			 struct usb_interface *intf,
@@ -144,3 +145,27 @@ next_desc:
 	return cnt;
 }
 EXPORT_SYMBOL_GPL(cdc_parse_cdc_header);
+
+#if LINUX_VERSION_IS_LESS(4,8,0)
+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;
+
+	if (max_vecs < min_vecs)
+		return -ERANGE;
+
+#if LINUX_VERSION_IS_LESS(3,15,0)
+	res = pci_enable_msi_block(dev, msi_nvect);
+	if (res == 0) {
+		return msi_nvect;
+	}
+#else
+	res = pci_enable_msi_range(dev, msi_nvect, msi_nvect);
+	return msi_nvect;
+#endif /*LINUX_VERSION_IS_LESS(3,15,0)*/
+	return -ENOSPC;
+}
+EXPORT_SYMBOL(pci_alloc_irq_vectors);
+#endif /*LINUX_VERSION_IS_LESS(4,8,0)*/
-- 
2.17.1

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

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-03  9:18 Omer Dagan [this message]
     [not found] <AM0PR02MB36506A5694D9DEFB288445F093160@AM0PR02MB3650.eurprd02.prod.outlook.com>
2018-09-25 19:13 ` Subject: " Hauke Mehrtens
     [not found]   ` <AM0PR02MB365025326A06C3B60C28036093150@AM0PR02MB3650.eurprd02.prod.outlook.com>
2018-09-30 22:04     ` 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=20181003091746.28511-1-omer.dagan@tandemg.com \
    --to=omer.dagan@tandemg.com \
    --cc=backports@vger.kernel.org \
    --cc=hauke@hauke-m.de \
    --cc=mcgrof@kernel.org \
    /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

Backports Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/backports/0 backports/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 backports backports/ https://lore.kernel.org/backports \
		backports@vger.kernel.org
	public-inbox-index backports

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.backports


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git