From patchwork Sat Nov 27 01:24:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 12642011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0972C43217 for ; Sat, 27 Nov 2021 01:25:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.233615.405553 (Exim 4.92) (envelope-from ) id 1mqmSN-0006i2-Sb; Sat, 27 Nov 2021 01:24:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 233615.405553; Sat, 27 Nov 2021 01:24:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mqmSN-0006ga-GM; Sat, 27 Nov 2021 01:24:47 +0000 Received: by outflank-mailman (input) for mailman id 233615; Sat, 27 Nov 2021 01:24:45 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mqmSL-0003uw-JR for xen-devel@lists.xenproject.org; Sat, 27 Nov 2021 01:24:45 +0000 Received: from galois.linutronix.de (galois.linutronix.de [193.142.43.55]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cd8ccc73-4f20-11ec-9787-a32c541c8605; Sat, 27 Nov 2021 02:24:44 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cd8ccc73-4f20-11ec-9787-a32c541c8605 Message-ID: <20211127000919.004572849@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1637976284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=iXWx8ngjVm94paCMjL44qtncyzw3jmQTRYweVvwdUTE=; b=twc9E/k5sGMn2fquLHv5+7zfix6uLYi9RH9SGLZSSA3ABcOvbp0/gPOpQlesgzHkbj1UVu fxR6AoIcwrtz/nn3bycIRy8P9kAGaK0ECHfhbEqIdbz1o3vq7H1JdPjQaWggom9fcYLCdX BOmuzr15HeqHdEIDMKSLq/WavFlqpW/xYMSc3r2wN7DXzv+PNwO5cRgSi7yjS1wpb/86Ru gJmjSdRE0skAiQjFeQ3BBC/okRhBX5BOlbe4JLQChHLlOjJiIRqAKAnL9t8GF853DwnxyU l0iBSahv+YZe+ToUNkpkfYscK/wzeDb2wgYipZlnYU4lySHkxy2LdxVpk1XRIg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1637976284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=iXWx8ngjVm94paCMjL44qtncyzw3jmQTRYweVvwdUTE=; b=Cwze/7Fqot4zxUe/5Tt8x3Rdu1Qo6xyHVQISU76a2p6ptM3z6Ii3pkLaG0Yznt5n2sNBh3 EqDN2aJVSQRqTdBA== From: Thomas Gleixner To: LKML Cc: Bjorn Helgaas , Marc Zygnier , Alex Williamson , Kevin Tian , Jason Gunthorpe , Megha Dey , Ashok Raj , Michael Ellerman , Andrew Cooper , Juergen Gross , linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [patch 09/10] PCI/MSI: Provide pci_msix_expand_vectors[_at]() References: <20211126233124.618283684@linutronix.de> MIME-Version: 1.0 Date: Sat, 27 Nov 2021 02:24:44 +0100 (CET) Provide a new interface which allows to expand the MSI-X vector space if the underlying irq domain implementation supports it. Signed-off-by: Thomas Gleixner --- drivers/pci/msi/msi.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 13 +++++++++++++ 2 files changed, 54 insertions(+) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -1025,6 +1025,47 @@ int pci_alloc_irq_vectors_affinity(struc EXPORT_SYMBOL(pci_alloc_irq_vectors_affinity); /** + * pci_msix_expand_vectors_at - Expand MSI-X interrupts for a device + * + * @dev: PCI device to operate on + * @at: Allocate at MSI-X index. If @at == PCI_MSI_EXPAND_AUTO + * the function expands automatically after the last + * active index. + * @nvec: Number of vectors to allocate + * + * Expand the MSI-X vectors of a device after an initial enablement and + * allocation. + * + * Return: 0 if the allocation was successful, an error code otherwise. + */ +int pci_msix_expand_vectors_at(struct pci_dev *dev, unsigned int at, unsigned int nvec) +{ + struct msi_device_data *md = dev->dev.msi.data; + struct msi_range range = { .ndesc = nvec, }; + unsigned int max_vecs; + int ret; + + if (!pci_msi_enable || !dev || !dev->msix_enabled || !md) + return -ENOTSUPP; + + if (!pci_msi_domain_supports_expand(dev)) + return -ENOTSUPP; + + max_vecs = pci_msix_vec_count(dev); + if (!nvec || nvec > max_vecs) + return -EINVAL; + + range.first = at == PCI_MSIX_EXPAND_AUTO ? md->num_descs : at; + + if (range.first >= max_vecs || nvec > max_vecs - range.first) + return -ENOSPC; + + ret = msix_setup_interrupts(dev, dev->msix_base, &range, NULL, NULL, true); + return ret <= 0 ? ret : -ENOSPC;; +} +EXPORT_SYMBOL_GPL(pci_msix_expand_vectors_at); + +/** * pci_free_irq_vectors - free previously allocated IRQs for a device * @dev: PCI device to operate on * --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1534,6 +1534,7 @@ static inline int pci_enable_msix_exact( int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs, unsigned int max_vecs, unsigned int flags, struct irq_affinity *affd); +int pci_msix_expand_vectors_at(struct pci_dev *dev, unsigned int at, unsigned int nvec); void pci_free_irq_vectors(struct pci_dev *dev); int pci_irq_vector(struct pci_dev *dev, unsigned int nr); @@ -1565,6 +1566,11 @@ pci_alloc_irq_vectors_affinity(struct pc return -ENOSPC; } +static inline int pci_msix_expand_vectors_at(struct pci_dev *dev, unsigned int at, unsigned int nvec) +{ + return -ENOTSUPP; +} + static inline void pci_free_irq_vectors(struct pci_dev *dev) { } @@ -1582,6 +1588,13 @@ static inline const struct cpumask *pci_ } #endif +#define PCI_MSIX_EXPAND_AUTO (UINT_MAX) + +static inline int pci_msix_expand_vectors(struct pci_dev *dev, unsigned int nvec) +{ + return pci_msix_expand_vectors_at(dev, PCI_MSIX_EXPAND_AUTO, nvec); +} + /** * pci_irqd_intx_xlate() - Translate PCI INTx value to an IRQ domain hwirq * @d: the INTx IRQ domain