From patchwork Fri Nov 11 13:54:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 18769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp753243wru; Fri, 11 Nov 2022 05:58:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ug0jUoY9hzl4NNstqiOJ7/wIzRA9LDQHccUAE9DTRwOIBh1/MWDysFreqzXQAVvtMA9Sg X-Received: by 2002:a17:906:bc42:b0:78d:7a4c:13ea with SMTP id s2-20020a170906bc4200b0078d7a4c13eamr1903327ejv.471.1668175080476; Fri, 11 Nov 2022 05:58:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668175080; cv=none; d=google.com; s=arc-20160816; b=pxSAoN/4oij39maxrVLzZ4ZItUPVIt6H47CH/7X0v0x49ikrTrwIAKBO6r3lcn+iIm RVv9XauTlPL7dregHDYrtCkmTwZP1zPXKXcsrW7LvrvjiselLcQLFBg94ZyJk8TezgQv qm1j5oj4wxTAQe9BZhojjbox/2O/DwKB2dL2+cCw/ekajpXQLnDob7nkWPITot5BTD4p zuLq4kSUibMGiOyJzWtoK8Tcdg7oLZOEryvmPzy6FK0j1EAG/sd1V3lKusXOGcxjMkOf BhSlVegdbPaspK0lmR0bv658okUc6l7Ukt57XheEMORXyrwHc86e2MbrwgmgecUVTI4A PKzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=uefv1SQ/kFaCIoG5nEqNjtgMsMbRPxf/+/AfGMMS3ME=; b=yd44vkFEqMu2UyjcfK/pQaYoYi9Y7adwApGxc0EYE57fDQ3HeCJaM5E3NHCu/JkR1V WMiEI8UbZapiU7mfUEcKG/35Xz8k8OS5mwYEVhDBBOlJ15WgyNbiMkefURkEEd0aW9SQ EU5AgXNy2SerdHjMLEEYuj5kmT03qu3j3OjRxUnR2Js8nb9aVIWpRUzDq7/JA8ezSrXy QUH2NApdHSmqYhOrXHBeOSYnMqkGtn6bGNwNNQwnxuJ11/eQngCHLT7yOYAFNKq8/yNU 4FWBqz3ivNFmB94V+U+Nrp2LaSrxscqDw0q1XAHWXY/dB8inHl9mXYamv+55H8zUm4tv 1B6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pRX56ARt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=AJ1J3mtq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt40-20020a1709072da800b0078dce38525asi2402502ejc.896.2022.11.11.05.57.36; Fri, 11 Nov 2022 05:58:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pRX56ARt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=AJ1J3mtq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233528AbiKKN4t (ORCPT + 99 others); Fri, 11 Nov 2022 08:56:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233613AbiKKN4B (ORCPT ); Fri, 11 Nov 2022 08:56:01 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F21F60698; Fri, 11 Nov 2022 05:54:53 -0800 (PST) Message-ID: <20221111122014.927531290@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668174892; 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=uefv1SQ/kFaCIoG5nEqNjtgMsMbRPxf/+/AfGMMS3ME=; b=pRX56ARtPVj6OyQEIMCqiah6CjQfsbUUjLKE1htpO78jveI+lbUJsRZyFxv6ZjkAjUyoAN OmuwsBOTCOZcYbdo31sYBZJJ2JMMjsySbe+r7TtEcQbauOlB6obK1AaxPUm0xLZPC4vEfj fcveslvLUX0yyTCArZBpUr0GgvLaxk/Zt48uV76R6Xz6gsOtk073eqv6iPhtoDfylIPEcH 5WvyxYOkjFBFl2nOpoe9vzRcON0FKzSVhz9TXniJi/Fp6trJaG8/k4uD/ZGjZ0rqx/oUuu l8gSGVtbJBM/cwnAWhdq2WZdx3Vm6vpnKMcgPrP6Bm73HGnTvINn1tgoOm64CA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668174892; 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=uefv1SQ/kFaCIoG5nEqNjtgMsMbRPxf/+/AfGMMS3ME=; b=AJ1J3mtq3gNBb0E5N58gtI7ISk9ECj7NVJw8fMFn44Fh4eLBVHxpY55lAGhoZtOWr1SC8R peJFrH/L1nyrdiAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , "Ahmed S. Darwish" , Reinette Chatre , Michael Ellerman , Christophe Leroy , linuxppc-dev@lists.ozlabs.org Subject: [patch 23/39] PCI/MSI: Move pci_alloc_irq_vectors_affinity() to api.c References: <20221111120501.026511281@linutronix.de> MIME-Version: 1.0 Date: Fri, 11 Nov 2022 14:54:51 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749208353487196089?= X-GMAIL-MSGID: =?utf-8?q?1749208353487196089?= From: Ahmed S. Darwish To distangle the maze in msi.c, all exported device-driver MSI APIs are now to be grouped in one file, api.c. Move pci_alloc_irq_vectors_affinity() and let its kernel-doc reference pci_alloc_irq_vectors() documentation added in parent commit. Signed-off-by: Ahmed S. Darwish Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas --- drivers/pci/msi/api.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++- drivers/pci/msi/msi.c | 65 +---------------------------------------------------- 2 files changed, 59 insertions(+), 65 deletions(-) --- diff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c index 1714905943fb..8546749afa6e 100644 --- a/drivers/pci/msi/api.c +++ b/drivers/pci/msi/api.c @@ -123,3 +123,62 @@ int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, flags, NULL); } EXPORT_SYMBOL(pci_alloc_irq_vectors); + +/** + * pci_alloc_irq_vectors_affinity() - Allocate multiple device interrupt + * vectors with affinity requirements + * @dev: the PCI device to operate on + * @min_vecs: minimum required number of vectors (must be >= 1) + * @max_vecs: maximum desired number of vectors + * @flags: allocation flags, as in pci_alloc_irq_vectors() + * @affd: affinity requirements (can be %NULL). + * + * Same as pci_alloc_irq_vectors(), but with the extra @affd parameter. + * Check that function docs, and &struct irq_affinity, for more details. + */ +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) +{ + struct irq_affinity msi_default_affd = {0}; + int nvecs = -ENOSPC; + + if (flags & PCI_IRQ_AFFINITY) { + if (!affd) + affd = &msi_default_affd; + } else { + if (WARN_ON(affd)) + affd = NULL; + } + + if (flags & PCI_IRQ_MSIX) { + nvecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs, + affd, flags); + if (nvecs > 0) + return nvecs; + } + + if (flags & PCI_IRQ_MSI) { + nvecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, affd); + if (nvecs > 0) + return nvecs; + } + + /* use legacy IRQ if allowed */ + if (flags & PCI_IRQ_LEGACY) { + if (min_vecs == 1 && dev->irq) { + /* + * Invoke the affinity spreading logic to ensure that + * the device driver can adjust queue configuration + * for the single interrupt case. + */ + if (affd) + irq_create_affinity_masks(1, affd); + pci_intx(dev, 1); + return 1; + } + } + + return nvecs; +} +EXPORT_SYMBOL(pci_alloc_irq_vectors_affinity); diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c index 6700ef1c734e..a028774f438d 100644 --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -887,71 +887,6 @@ int __pci_enable_msix_range(struct pci_dev *dev, } /** - * pci_alloc_irq_vectors_affinity - allocate multiple IRQs for a device - * @dev: PCI device to operate on - * @min_vecs: minimum number of vectors required (must be >= 1) - * @max_vecs: maximum (desired) number of vectors - * @flags: flags or quirks for the allocation - * @affd: optional description of the affinity requirements - * - * Allocate up to @max_vecs interrupt vectors for @dev, using MSI-X or MSI - * vectors if available, and fall back to a single legacy vector - * if neither is available. Return the number of vectors allocated, - * (which might be smaller than @max_vecs) if successful, or a negative - * error code on error. If less than @min_vecs interrupt vectors are - * available for @dev the function will fail with -ENOSPC. - * - * To get the Linux IRQ number used for a vector that can be passed to - * request_irq() use the pci_irq_vector() helper. - */ -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) -{ - struct irq_affinity msi_default_affd = {0}; - int nvecs = -ENOSPC; - - if (flags & PCI_IRQ_AFFINITY) { - if (!affd) - affd = &msi_default_affd; - } else { - if (WARN_ON(affd)) - affd = NULL; - } - - if (flags & PCI_IRQ_MSIX) { - nvecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs, - affd, flags); - if (nvecs > 0) - return nvecs; - } - - if (flags & PCI_IRQ_MSI) { - nvecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, affd); - if (nvecs > 0) - return nvecs; - } - - /* use legacy IRQ if allowed */ - if (flags & PCI_IRQ_LEGACY) { - if (min_vecs == 1 && dev->irq) { - /* - * Invoke the affinity spreading logic to ensure that - * the device driver can adjust queue configuration - * for the single interrupt case. - */ - if (affd) - irq_create_affinity_masks(1, affd); - pci_intx(dev, 1); - return 1; - } - } - - return nvecs; -} -EXPORT_SYMBOL(pci_alloc_irq_vectors_affinity); - -/** * pci_free_irq_vectors - free previously allocated IRQs for a device * @dev: PCI device to operate on *