From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69EF7C433FE for ; Sat, 27 Nov 2021 01:34:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352334AbhK0BiG (ORCPT ); Fri, 26 Nov 2021 20:38:06 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:40764 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352462AbhK0BgE (ORCPT ); Fri, 26 Nov 2021 20:36:04 -0500 Message-ID: <20211127000919.004572849@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1637976311; 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=XMZ8+C4S5qdKr1Con79Z8ll6XVMM2fnwfUd6VibARMXKBZJmbzz2rdgHplVFzqQWoTjqXL a71t/1Td6DZLsRGHxaA0Xy69M6LynlfnUWWrPppwCpmvz1S4krQdufBQTGAqkoP0l3s8T3 5/d33e6N4qMca0wqhegVl6SB4Kg+rkn1Q5Lq3ndlMN3YDCufaLN+bpKiuw5/eO8PEddKg7 KXX4wVb7cTsJ2Tc/55bKjXTrqTb0PPVsc9nsJs/ZzoOSFGZaIbOseCSK90/VO3qoq0OR3S bX2HgbvnzX2XCKSBc8Aiz7O3JmG+aqKSvt2jQ+saMx9qcR/0zEVPXRcCgYtdXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1637976311; 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=KqCEEAwQIQ5ub2ZhfoOhVriWcwZnFHllmQP6Q5tXV21krUdnjIG0tW2/eI3ljwxV7nF3wo hBnPVTOZ03C+6jDQ== 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 Content-Type: text/plain; charset=UTF-8 Date: Sat, 27 Nov 2021 02:25:11 +0100 (CET) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93B9BC433EF for ; Sat, 27 Nov 2021 02:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351587AbhK0CWG (ORCPT ); Fri, 26 Nov 2021 21:22:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352462AbhK0CUE (ORCPT ); Fri, 26 Nov 2021 21:20:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17402C08EC3C; Fri, 26 Nov 2021 17:31:54 -0800 (PST) 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 Content-Type: text/plain; charset=UTF-8 Date: Sat, 27 Nov 2021 02:24:44 +0100 (CET) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Message-ID: <20211127012444.JT4ua-aI6V6PRfSBesFr-V9fEE1kZy2k17ocd_BI1F8@z> 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