From patchwork Sat Nov 27 01:22:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 1560550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=DmOUQuxv; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=jaJQQqCv; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4J1DY464NLz9sRR for ; Sat, 27 Nov 2021 12:29:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348870AbhK0BcY (ORCPT ); Fri, 26 Nov 2021 20:32:24 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:40092 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348884AbhK0BaT (ORCPT ); Fri, 26 Nov 2021 20:30:19 -0500 Message-ID: <20211126232734.648760382@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1637976157; 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=phsDsJYjfoR3d/2omr75zeGkFrat6spindIKlhhyIqc=; b=DmOUQuxv6UKxw8VDYa2FE3yQkmpSZ/ZayeVc4frXCrqWuOePFEOX1GUDAQNDqVit/nYrZ2 R3pYIKnPNjocxc/CRDYUprCu75cFez7UwF2501Cuz1TkCYoMTqOLkyG564VSjKqUhbfRz8 NGNLzuwi2PfMadoo+iN2aCKtA2q1jf1FaoMEnYHKi3uVnZNAv/ezXNyW4WDJeR12aDWoyk xbPEzPAdrS33+I/b1kGsGm2j8LPLZsA1oWzZU65MXfouEy+5MFZf1Hie292irrDzcSxFg8 eeDsnHBwVSUE9LNlimZ8DTwosJ6zT0lYAhogqkMcaZhh2hzcEsA4g4S1VWPbLw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1637976157; 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=phsDsJYjfoR3d/2omr75zeGkFrat6spindIKlhhyIqc=; b=jaJQQqCvcRPwcpWBmZCrEF6oIqzFsG5BaKPoxivHL7lF9k1QmfTQpzfI6eOzG8+nfjmF08 vHs2dFFwPXcdhcDw== From: Thomas Gleixner To: LKML Cc: Bjorn Helgaas , Marc Zygnier , Alex Williamson , Kevin Tian , Jason Gunthorpe , Megha Dey , Ashok Raj , linux-pci@vger.kernel.org, Greg Kroah-Hartman , linux-s390@vger.kernel.org, Heiko Carstens , Christian Borntraeger , Jon Mason , Dave Jiang , Allen Hubbe , linux-ntb@googlegroups.com Subject: [patch 06/32] genirq/msi: Provide domain flags to allocate/free MSI descriptors automatically References: <20211126230957.239391799@linutronix.de> MIME-Version: 1.0 Date: Sat, 27 Nov 2021 02:22:36 +0100 (CET) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Provide domain info flags which tell the core to allocate simple descriptors or to free descriptors when the interrupts are freed and implement the required functionality. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 15 +++++++++++++++ kernel/irq/msi.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -303,6 +303,17 @@ static inline void pci_write_msi_msg(uns #endif /* CONFIG_PCI_MSI */ int msi_add_msi_desc(struct device *dev, struct msi_desc *init_desc); +void msi_free_msi_descs_range(struct device *dev, enum msi_desc_filter filter, + unsigned int base_index, unsigned int ndesc); + +/** + * msi_free_msi_descs - Free MSI descriptors of a device + * @dev: Device to free the descriptors + */ +static inline void msi_free_msi_descs(struct device *dev) +{ + msi_free_msi_descs_range(dev, MSI_DESC_ALL, 0, UINT_MAX); +} struct msi_desc *alloc_msi_entry(struct device *dev, int nvec, const struct irq_affinity_desc *affinity); @@ -463,6 +474,10 @@ enum { MSI_FLAG_DEV_SYSFS = (1 << 7), /* MSI-X entries must be contiguous */ MSI_FLAG_MSIX_CONTIGUOUS = (1 << 8), + /* Allocate simple MSI descriptors */ + MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS = (1 << 9), + /* Free MSI descriptors */ + MSI_FLAG_FREE_MSI_DESCS = (1 << 10), }; int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask, --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -120,6 +120,32 @@ static int msi_add_simple_msi_descs(stru } /** + * msi_free_msi_descs_range - Free MSI descriptors of a device + * @dev: Device to free the descriptors + * @filter: Descriptor state filter + * @base_index: Index to start freeing from + * @ndesc: Number of descriptors to free + */ +void msi_free_msi_descs_range(struct device *dev, enum msi_desc_filter filter, + unsigned int base_index, unsigned int ndesc) +{ + struct msi_desc *desc; + + lockdep_assert_held(&dev->msi.data->mutex); + + msi_for_each_desc(desc, dev, filter) { + /* + * Stupid for now to handle MSI device domain until the + * storage is switched over to an xarray. + */ + if (desc->msi_index < base_index || desc->msi_index >= base_index + ndesc) + continue; + list_del(&desc->list); + free_msi_entry(desc); + } +} + +/** * msi_device_has_property - Check whether a device has a specific MSI property * @dev: Pointer to the device which is queried * @prop: Property to check for @@ -905,6 +931,16 @@ int __msi_domain_alloc_irqs(struct irq_d return 0; } +static int msi_domain_add_simple_msi_descs(struct msi_domain_info *info, + struct device *dev, + unsigned int num_descs) +{ + if (!(info->flags & MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS)) + return 0; + + return msi_add_simple_msi_descs(dev, 0, num_descs); +} + /** * msi_domain_alloc_irqs_descs_locked - Allocate interrupts from a MSI interrupt domain * @domain: The domain to allocate from @@ -927,6 +963,10 @@ int msi_domain_alloc_irqs_descs_locked(s lockdep_assert_held(&dev->msi.data->mutex); + ret = msi_domain_add_simple_msi_descs(info, dev, nvec); + if (ret) + return ret; + ret = ops->domain_alloc_irqs(domain, dev, nvec); if (ret) goto cleanup; @@ -988,6 +1028,13 @@ void __msi_domain_free_irqs(struct irq_d } } +static void msi_domain_free_msi_descs(struct msi_domain_info *info, + struct device *dev) +{ + if (info->flags & MSI_FLAG_FREE_MSI_DESCS) + msi_free_msi_descs(dev); +} + /** * msi_domain_free_irqs_descs_locked - Free interrupts from a MSI interrupt @domain associated to @dev * @domain: The domain to managing the interrupts @@ -1008,6 +1055,7 @@ void msi_domain_free_irqs_descs_locked(s if (info->flags & MSI_FLAG_DEV_SYSFS) msi_device_destroy_sysfs(dev); ops->domain_free_irqs(domain, dev); + msi_domain_free_msi_descs(info, dev); } /**