From owner-dev-commits-src-all@freebsd.org Tue Jul 27 15:01:06 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 44EE3661887; Tue, 27 Jul 2021 15:01:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GZ0Nf1XBmz4cMs; Tue, 27 Jul 2021 15:01:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 11D094D92; Tue, 27 Jul 2021 15:01:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 16RF1627031743; Tue, 27 Jul 2021 15:01:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16RF16oE031742; Tue, 27 Jul 2021 15:01:06 GMT (envelope-from git) Date: Tue, 27 Jul 2021 15:01:06 GMT Message-Id: <202107271501.16RF16oE031742@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 366d68f28379 - main - LinuxKPI: add module_pci_driver() and pci_alloc_irq_vectors() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 366d68f283793df22392f9fb992c5029dfc293bb Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Jul 2021 15:01:06 -0000 The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=366d68f283793df22392f9fb992c5029dfc293bb commit 366d68f283793df22392f9fb992c5029dfc293bb Author: Bjoern A. Zeeb AuthorDate: 2021-07-01 13:33:01 +0000 Commit: Bjoern A. Zeeb CommitDate: 2021-07-27 14:57:23 +0000 LinuxKPI: add module_pci_driver() and pci_alloc_irq_vectors() Add the two new functions needed by rtw88 to register the driver and handle the module bits as well as a version of pci_alloc_irq_vectors() for what is needed. Reviewed by: hselasky MFC after: 10 days Differential Revision: https://reviews.freebsd.org/D30981 --- sys/compat/linuxkpi/common/include/linux/pci.h | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index 4784799d82b5..a80e6965915d 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -186,6 +186,10 @@ typedef int pci_power_t; #define PCI_EXT_CAP_ID_ERR PCIZ_AER +#define PCI_IRQ_LEGACY 0x01 +#define PCI_IRQ_MSI 0x02 +#define PCI_IRQ_MSIX 0x04 + struct pci_dev; struct pci_driver { @@ -221,6 +225,25 @@ extern spinlock_t pci_lock; #define __devexit_p(x) x +#define module_pci_driver(_driver) \ + \ +static inline int \ +_pci_init(void) \ +{ \ + \ + return (linux_pci_register_driver(&_driver)); \ +} \ + \ +static inline void \ +_pci_exit(void) \ +{ \ + \ + linux_pci_unregister_driver(&_driver); \ +} \ + \ +module_init(_pci_init); \ +module_exit(_pci_exit) + /* * If we find drivers accessing this from multiple KPIs we may have to * refcount objects of this structure. @@ -817,6 +840,42 @@ pci_enable_msi(struct pci_dev *pdev) return (0); } +static inline int +pci_alloc_irq_vectors(struct pci_dev *pdev, int minv, int maxv, + unsigned int flags) +{ + int error; + + if (flags & PCI_IRQ_MSIX) { + struct msix_entry *entries; + int i; + + entries = kcalloc(maxv, sizeof(*entries), GFP_KERNEL); + if (entries == NULL) { + error = -ENOMEM; + goto out; + } + for (i = 0; i < maxv; ++i) + entries[i].entry = i; + error = pci_enable_msix(pdev, entries, maxv); +out: + kfree(entries); + if (error == 0 && pdev->msix_enabled) + return (pdev->dev.irq_end - pdev->dev.irq_start); + } + if (flags & PCI_IRQ_MSI) { + error = pci_enable_msi(pdev); + if (error == 0 && pdev->msi_enabled) + return (pdev->dev.irq_end - pdev->dev.irq_start); + } + if (flags & PCI_IRQ_LEGACY) { + if (pdev->irq) + return (1); + } + + return (-EINVAL); +} + static inline int pci_channel_offline(struct pci_dev *pdev) {