Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5807157pxb; Tue, 16 Feb 2021 08:05:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRUaveVURgAR+dBZzUJQKLzq6C5YUxFb7k6lm02tcx07SkA+eDafTsa40bHOBnBbXmfTQf X-Received: by 2002:a17:906:e2ca:: with SMTP id gr10mr11903519ejb.507.1613491509692; Tue, 16 Feb 2021 08:05:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613491509; cv=none; d=google.com; s=arc-20160816; b=Lcj8BjvZpfZAYbaD1MQ9dzO3NCnS5tRLyUVzkXhXZeU2sLVMfvn3jknD9cNdU8yFbd FxNB+sO+ID0JuYH53rtJxwuyuvWa6n81ts/2DKQOhiJ20yiJfOAFCZM19extJgqzFLdb c1+yJf/YIHWu3MxyifDhA8+u/QlmRt2imkx8zKbDQywQVKgAv36PYu/Br9kET04RNwm6 4F+GA7eHIRsUMH9UrK62DvPiqMP9+K1o3jLR23m7P2QEJGO/nQcUYPTAAfqO/pMUI5tS m9cjWwJhBmP4GU51Hx4Vq5l/0oHM9yzmXirna3Wvrke2EDsr1CXQK1qits9CmzQRYkPn BqlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SEY8lEZGS42JtvMA8omGE4HeCsllkcm6O1GjxwD/puQ=; b=UK70yeK0GD/Hddm0CnI0iu1y0hlTjM89lp1M8wtxxRoyQ2ElaX6tUETDlH3VydOucJ GXOEY8ZUd8qEOptNlOe6NytcPvTWeFPoqJ6mY+NFvhdCjSJQhfp0me7EhR7PWviJQTCa 96DKiZPwhnykvY+yk4Rti6G7pkZAIIsNV4no3A79ABVPkbrAijABntvDHLUHQMHGYUx/ V/yiMOtvD7iT0ibTydO0BLrMPpdnJe18VjyUny8ScKTdi3Z8dTfbEkjYj70JKiVyBUzv fhy7nudjsXeYtI3PlK9J+b8nEZnJwgNXqttE2DS/pT/A0qXN9LCJRGXA9la/MKA9Ia4S M1Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SLvnWcWy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si15015960edt.85.2021.02.16.08.04.45; Tue, 16 Feb 2021 08:05:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SLvnWcWy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230400AbhBPQDu (ORCPT + 99 others); Tue, 16 Feb 2021 11:03:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230263AbhBPQDn (ORCPT ); Tue, 16 Feb 2021 11:03:43 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58347C06174A; Tue, 16 Feb 2021 08:03:03 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id fa16so5950209pjb.1; Tue, 16 Feb 2021 08:03:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SEY8lEZGS42JtvMA8omGE4HeCsllkcm6O1GjxwD/puQ=; b=SLvnWcWyt22Sv0apOdq4AeyyVojvsiukA1JWoFTxBpGP9pYnwlfKd56wAtUoQXKaRD x8U6cdxLWUhcM2NwoFeVTCeAJeSLeF9tQOB0faHRbJlo0QSEljEEW6gpJI3+q+HidTue ewgOzp996mf5MBgkcBkv6JvxpsJN+TceSkhkN02kLadcefpJraqa0ujZ0XwvuvknhWFC Xr+Oi6M1/Nj9M5nUJSdvc558ClRis1NDTPQV076NNxU+w8RPuMih9NasR+nvJ7uEVrg6 aoDeJBpYDe4RlK8DOIqvIsk5moiNk+fTv6u38oT6BqkDsFadgGSsKUhXWYduSxdMWKZF Inqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SEY8lEZGS42JtvMA8omGE4HeCsllkcm6O1GjxwD/puQ=; b=CwIU1bVqr5OoRiwOtDnUfsnnrERNmxC+St/SvhIdN81+5avysvqfAU3OGm4bb8tYGH 3B7qlF2GTobuOFfLeBW03dMhgtOffsMZMh9/zkvo5AE+oaG4fbZEBiayvUCDD6NkTzFq CoxNPX3HxE8qHLWMtU7VDIdl1lKHT32X45xXSowtjcwlYvPbMSdGlMd0Cpo5JkntFwPD A/TjiqFcfJm7Vr71+Nc/D1qm+t1PTZiZ0EkCCIM3u8jtdFsJB/9ZKbSf7xmlQVpSqwXt K86hGtmkmVfyMisssLHRvhtSgK9uNQE2Qow7/08s0t58rtHBH2A23FHihaMmUhkcFgpJ dp5w== X-Gm-Message-State: AOAM531j2wNFeoeh3x+T/VuDqmogaRB8RaK+d7pz9vCk7SKJdnLctzhK VUid2oURvkNb+91NOT+sjxYTdGuBX/6qBA== X-Received: by 2002:a17:90a:8c87:: with SMTP id b7mr5024018pjo.158.1613491382978; Tue, 16 Feb 2021 08:03:02 -0800 (PST) Received: from localhost (185.212.56.4.16clouds.com. [185.212.56.4]) by smtp.gmail.com with ESMTPSA id z16sm2949472pgk.13.2021.02.16.08.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 08:03:02 -0800 (PST) From: Dejin Zheng To: corbet@lwn.net, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, rric@kernel.org, bhelgaas@google.com, wsa@kernel.org, linux-doc@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pci@vger.kernel.org, kw@linux.com Cc: linux-kernel@vger.kernel.org, Dejin Zheng Subject: [PATCH v3 1/4] PCI: Introduce pcim_alloc_irq_vectors() Date: Wed, 17 Feb 2021 00:02:46 +0800 Message-Id: <20210216160249.749799-2-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20210216160249.749799-1-zhengdejin5@gmail.com> References: <20210216160249.749799-1-zhengdejin5@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce pcim_alloc_irq_vectors(), a device-managed version of pci_alloc_irq_vectors(). Introducing this function can simplify the error handling path in many drivers. And use pci_free_irq_vectors() to replace some code in pcim_release(), they are equivalent, and no functional change. It is more explicit that pcim_alloc_irq_vectors() is a device-managed function. Suggested-by: Andy Shevchenko Signed-off-by: Dejin Zheng --- v2 -> v3: - Add some commit comments for replace some codes in pcim_release() by pci_free_irq_vectors(). v1 -> v2: - Use pci_free_irq_vectors() to replace some code in pcim_release(). - Modify some commit messages. drivers/pci/pci.c | 33 +++++++++++++++++++++++++++++---- include/linux/pci.h | 3 +++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b67c4327d307..db799d089c85 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1969,10 +1969,7 @@ static void pcim_release(struct device *gendev, void *res) struct pci_devres *this = res; int i; - if (dev->msi_enabled) - pci_disable_msi(dev); - if (dev->msix_enabled) - pci_disable_msix(dev); + pci_free_irq_vectors(dev); for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) if (this->region_mask & (1 << i)) @@ -2054,6 +2051,34 @@ void pcim_pin_device(struct pci_dev *pdev) } EXPORT_SYMBOL(pcim_pin_device); +/** + * pcim_alloc_irq_vectors - a device-managed pci_alloc_irq_vectors() + * @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 + * + * 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. + * + * It depends on calling pcim_enable_device() to make IRQ resources + * manageable. + */ +int pcim_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, + unsigned int max_vecs, unsigned int flags) +{ + struct pci_devres *dr; + + dr = find_pci_dr(dev); + if (!dr || !dr->enabled) + return -EINVAL; + + return pci_alloc_irq_vectors(dev, min_vecs, max_vecs, flags); +} +EXPORT_SYMBOL(pcim_alloc_irq_vectors); + /* * pcibios_add_device - provide arch specific hooks when adding device dev * @dev: the PCI device being added diff --git a/include/linux/pci.h b/include/linux/pci.h index 86c799c97b77..d75ba85ddfc5 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1818,6 +1818,9 @@ pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, NULL); } +int pcim_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, + unsigned int max_vecs, unsigned int flags); + /* Include architecture-dependent settings and functions */ #include -- 2.25.0