From patchwork Fri Nov 11 13:54:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 18765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp753106wru; Fri, 11 Nov 2022 05:57:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf46dNvy98V/egVgVVbkbzprmNXcaCJiGm9sL498HvE2mPxamBjUuSu7141KV4gu5SQzj03Q X-Received: by 2002:a50:fd91:0:b0:463:ff10:4ff with SMTP id o17-20020a50fd91000000b00463ff1004ffmr1552677edt.290.1668175060903; Fri, 11 Nov 2022 05:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668175060; cv=none; d=google.com; s=arc-20160816; b=L2tiLWFh6IIde3i9/nTv6abGDmCqxL6FpTgu9c/Xp6RwDdfoNLfYIyc1HxgrZ9amDg +tvJXPZ4169to0ICucXwp92zAxLe4f7Yuw5yssZMLouQ7NcCRfoTz1a8WNsicrIdOkxB cBM/LkolGYKWpSJOpBax7BeGXZ9QdqtZurQ+rg9R1bamdMdvyZMcPsxRErSUFMcZGEZb HPCO8UoicnMLeH0E/oYZfKG29O6PAp2EOEXa8jP/Vv1EcW9h4ivqEaPUUBaH79JEc+Zn ChaJCmloGQvQluCUlyVVwpRTixrt8nbrpRQKlYTRRuAC4He9CX6zjajcTWP5ka0Y+3yk 60IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:content-transfer-encoding:mime-version :references:subject:cc:to:from:dkim-signature:dkim-signature :message-id; bh=5KmJKzZwAqMF//R5CEolBMOEBU8yD776C3UNuDuLpFo=; b=IeBOOjZW8BOI3fHFy5gO10oc64i3oqOUmQkcK2XvmiZlo1C2vCcVBXsrQpnZImcBXq sr5pHK95ITNoUW8UnLB9HOI18GC8ay/ZPqUACwW/HiWhEIFrehTtyUnUWeesZOSQnMNq bkwy5qOQL9dOf3ggsbtz2Fz2IWM072j4HKrhh1zz64WwAZs9gRlywcdsPQdIS1t5XWnK rR1uxBFONrXAjR14rV6ioKokTR2RW4Ti6eH2qjL9tsqu1ySSZHIIekl0WRQR5DzafoFx u3yMTg8tJKJsSM/snrJG0ftv9lzYspylesHvga4FlPZ5JVkqiDgEQmtr6WW2WgalYCE3 hzXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aW9aT9GT; dkim=neutral (no key) header.i=@linutronix.de; 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 nc33-20020a1709071c2100b0078d9db99f5esi2449901ejc.39.2022.11.11.05.57.16; Fri, 11 Nov 2022 05:57:40 -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=aW9aT9GT; dkim=neutral (no key) header.i=@linutronix.de; 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 S233977AbiKKN4S (ORCPT + 99 others); Fri, 11 Nov 2022 08:56:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233803AbiKKNzn (ORCPT ); Fri, 11 Nov 2022 08:55:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FF487BE68; Fri, 11 Nov 2022 05:54:47 -0800 (PST) Message-ID: <20221111122014.696798036@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668174885; 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: content-transfer-encoding:content-transfer-encoding: references:references; bh=5KmJKzZwAqMF//R5CEolBMOEBU8yD776C3UNuDuLpFo=; b=aW9aT9GTxHiSQ01KmcKcVAR5Gtgm712AnUUjXcf/UAU+la1n84AAR2UKavCv+FV0EdOi0K GE+J5zNuoTimGlHv/TN11mzW0TcFOY96fSWBMrIxXfggJTwyt7FmyztYuREP2otV0Z2jLQ IelQtk6sZZ09STPmn+MIp6DLZcrUKcdLoJC25gD9iFwF8u9f1XqLIDyLpy7cr5fGjczJhJ T0cZWHq3/mtFCYeSlRoCya3GS0B8WNJMTYLwfLgvdnUTK1rPDUwOOh/5qYA5cT6J2+QM6v TVcpvC5MGQKsQcE/3PRdo4upSRBHB9Fu/+qY/awa/RURaoefAG4DEOKwiugMBQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668174885; 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: content-transfer-encoding:content-transfer-encoding: references:references; bh=5KmJKzZwAqMF//R5CEolBMOEBU8yD776C3UNuDuLpFo=; b=JuaZZ0BRz9HXURKAI+Kmjfz/8OWWG3gRuOmSlo8r2Ql9shwrIORF/7ph03FmrEt4obqVVr pkNOSQC7YlHDVyCg== 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 19/39] PCI/MSI: Move pci_disable_msi() to api.c References: <20221111120501.026511281@linutronix.de> MIME-Version: 1.0 Date: Fri, 11 Nov 2022 14:54:45 +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?1749208332295854448?= X-GMAIL-MSGID: =?utf-8?q?1749208332295854448?= From: Ahmed S. Darwish msi.c is a maze of randomly sorted functions which makes the code unreadable. As a first step split the driver visible API and the internal implementation which also allows proper API documentation via one file. Create drivers/pci/msi/api.c to group all exported device-driver PCI/MSI APIs in one C file. Begin by moving pci_disable_msi() there and add kernel-doc for the function as appropriate. Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas --- drivers/pci/msi/Makefile | 3 +-- drivers/pci/msi/api.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/pci/msi/msi.c | 22 +++++----------------- drivers/pci/msi/msi.h | 4 ++++ 4 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 drivers/pci/msi/api.c --- diff --git a/drivers/pci/msi/Makefile b/drivers/pci/msi/Makefile index 4e0a7e07965e..839ff72d72a8 100644 --- a/drivers/pci/msi/Makefile +++ b/drivers/pci/msi/Makefile @@ -2,6 +2,5 @@ # # Makefile for the PCI/MSI obj-$(CONFIG_PCI) += pcidev_msi.o -obj-$(CONFIG_PCI_MSI) += msi.o -obj-$(CONFIG_PCI_MSI) += irqdomain.o +obj-$(CONFIG_PCI_MSI) += api.o msi.o irqdomain.o obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.o diff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c new file mode 100644 index 000000000000..7485942cbe5d --- /dev/null +++ b/drivers/pci/msi/api.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PCI MSI/MSI-X — Exported APIs for device drivers + * + * Copyright (C) 2003-2004 Intel + * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) + * Copyright (C) 2016 Christoph Hellwig. + * Copyright (C) 2022 Linutronix GmbH + */ + +#include + +#include "msi.h" + +/** + * pci_disable_msi() - Disable MSI interrupt mode on device + * @dev: the PCI device to operate on + * + * Legacy device driver API to disable MSI interrupt mode on device, + * free earlier allocated interrupt vectors, and restore INTx emulation. + * The PCI device Linux IRQ (@dev->irq) is restored to its default + * pin-assertion IRQ. This is the cleanup pair of pci_enable_msi(). + * + * NOTE: The newer pci_alloc_irq_vectors() / pci_free_irq_vectors() API + * pair should, in general, be used instead. + */ +void pci_disable_msi(struct pci_dev *dev) +{ + if (!pci_msi_enabled() || !dev || !dev->msi_enabled) + return; + + msi_lock_descs(&dev->dev); + pci_msi_shutdown(dev); + pci_free_msi_irqs(dev); + msi_unlock_descs(&dev->dev); +} +EXPORT_SYMBOL(pci_disable_msi); diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c index 5c310df55d0d..4a1300b74518 100644 --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -163,7 +163,7 @@ void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg) } EXPORT_SYMBOL_GPL(pci_write_msi_msg); -static void free_msi_irqs(struct pci_dev *dev) +void pci_free_msi_irqs(struct pci_dev *dev) { pci_msi_teardown_msi_irqs(dev); @@ -413,7 +413,7 @@ static int msi_capability_init(struct pci_dev *dev, int nvec, err: pci_msi_unmask(entry, msi_multi_mask(entry)); - free_msi_irqs(dev); + pci_free_msi_irqs(dev); fail: dev->msi_enabled = 0; unlock: @@ -531,7 +531,7 @@ static int msix_setup_interrupts(struct pci_dev *dev, void __iomem *base, goto out_unlock; out_free: - free_msi_irqs(dev); + pci_free_msi_irqs(dev); out_unlock: msi_unlock_descs(&dev->dev); kfree(masks); @@ -680,7 +680,7 @@ int pci_msi_vec_count(struct pci_dev *dev) } EXPORT_SYMBOL(pci_msi_vec_count); -static void pci_msi_shutdown(struct pci_dev *dev) +void pci_msi_shutdown(struct pci_dev *dev) { struct msi_desc *desc; @@ -701,18 +701,6 @@ static void pci_msi_shutdown(struct pci_dev *dev) pcibios_alloc_irq(dev); } -void pci_disable_msi(struct pci_dev *dev) -{ - if (!pci_msi_enable || !dev || !dev->msi_enabled) - return; - - msi_lock_descs(&dev->dev); - pci_msi_shutdown(dev); - free_msi_irqs(dev); - msi_unlock_descs(&dev->dev); -} -EXPORT_SYMBOL(pci_disable_msi); - /** * pci_msix_vec_count - return the number of device's MSI-X table entries * @dev: pointer to the pci_dev data structure of MSI-X device function @@ -797,7 +785,7 @@ void pci_disable_msix(struct pci_dev *dev) msi_lock_descs(&dev->dev); pci_msix_shutdown(dev); - free_msi_irqs(dev); + pci_free_msi_irqs(dev); msi_unlock_descs(&dev->dev); } EXPORT_SYMBOL(pci_disable_msix); diff --git a/drivers/pci/msi/msi.h b/drivers/pci/msi/msi.h index d8f62d911f08..634879277349 100644 --- a/drivers/pci/msi/msi.h +++ b/drivers/pci/msi/msi.h @@ -84,6 +84,10 @@ static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc) return (1 << (1 << desc->pci.msi_attrib.multi_cap)) - 1; } +/* MSI internal functions invoked from the public APIs */ +void pci_msi_shutdown(struct pci_dev *dev); +void pci_free_msi_irqs(struct pci_dev *dev); + /* Legacy (!IRQDOMAIN) fallbacks */ #ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS int pci_msi_legacy_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);