Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2382208pxj; Sun, 6 Jun 2021 00:09:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt+N75sm5CSt3paRw3fSsBSKuLjyPo+JuBhhpWd9YwqMxQWuGvMyckppWcG1oEsBeInzoY X-Received: by 2002:a17:906:914f:: with SMTP id y15mr12815135ejw.354.1622963394486; Sun, 06 Jun 2021 00:09:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622963394; cv=none; d=google.com; s=arc-20160816; b=t+h/mIdoq5irq3ITwxep9Phc1mVfloPMTdgLg/qx1hY/OzMCxueRy5V8CaXUQkKmJS 5cncwdRY/zebNlbNvUYJ+R3l/G+bRhjdGyg3ivnJV8vYjqqGn9xpLYvraWJS6Q3bzjou Y2+6skVZLXozSC0Lja5t1+6VyV/voLn/NZwLQP1Y+Mc3feb/LzxDip+oP6/GersCUlUo 3vhUwCYs5EMp1+g3qr7j9mvczObOXIgApxGHZx2o8GZ3HnMcsuHfEEHUdi+Q/06AGiVF zoA6IzXvI2mu6pZmI9GDogmCKeuqlimYQa2MWMB4U5zGnzx8q+UHLdA8HQrkvAaGWdLD /S3w== 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=ameoA/1J9JC1e+hvEKFvbOF1rkxU/AqC4eK5zMBiLI8=; b=m8v1QKnMqOcN004t6cW37iPVrrjJGcyahDvHAbBBw2ftK9mi94VjkOcrz0WO8gtrBq JZkeYz/Ziizt+/6WlUvReHgmLNMbyv1iayRGIVlGPjEd/ZpzD8/0an8R35R7aOLCJn5D sbOycmucMVaPrazieWbhX4FdZ6dAOTuJiU3UBdNH5LhcqZynPZchYv8DLICMNIfzAvv8 /XkPF1TrZmFuqB8FLPeopXxL1bG8qpKpJCxHv536SSvXxh7CkgQZRXD57+Wb1SegCrKu I36BbhNU/zB9S+dXZ3k59SdM8L8y9S47wD0MD6+eJo6Q5IHAQac8jUk6/D+Ozz8m9MI4 0l0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I4SEo+19; 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 f16si1802edy.74.2021.06.06.00.09.31; Sun, 06 Jun 2021 00:09:54 -0700 (PDT) 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=I4SEo+19; 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 S230200AbhFFHIT (ORCPT + 99 others); Sun, 6 Jun 2021 03:08:19 -0400 Received: from mail-pj1-f41.google.com ([209.85.216.41]:43524 "EHLO mail-pj1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbhFFHIT (ORCPT ); Sun, 6 Jun 2021 03:08:19 -0400 Received: by mail-pj1-f41.google.com with SMTP id l10-20020a17090a150ab0290162974722f2so8452113pja.2; Sun, 06 Jun 2021 00:06:20 -0700 (PDT) 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=ameoA/1J9JC1e+hvEKFvbOF1rkxU/AqC4eK5zMBiLI8=; b=I4SEo+19gR7uX9BiDaAf3R15E3yDqb+EV6ziZYDIJXRO07fB9OD6xDdqpFPin5sVEL tIHCOyHpLzWuwGTxtlnPH+c8Vln56msa0lcNYx1XVIUbUQTKxVDN9yNGQGOWJyRl9oWo c/YJ3OlSHtio7SxHwij4mojXn4NZQ1ckrP4TvhQbrv5+VjDLE+p0jt3q2FmY0XTB82/M NAlr8bvLOdlkwxGr+/EXaRiEytlwOzqbrF3jYJTHq5liAKUdMQZkle23XkOtPIh24gaA mJLML7Ja8HCNywIBONrFEQFsOQYNUPNz0v9sSjOWhowyz29KIGfxxuZVkvDHNTSjctD0 oTgw== 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=ameoA/1J9JC1e+hvEKFvbOF1rkxU/AqC4eK5zMBiLI8=; b=UHu4QxpFQb0QBHYvrWscIysbAqsQEkwdxaSivgc+DoLP5MaLgRXN8zBCXhWWDsQuHi kCUv8nNwmmOPstH1gU4CNevHgcQq6H2qN6FwK2FC6LDbv/LWUIr92y9R2fV11Oh7To2j a8vgaPjjDnmuvWYBXC79AxkC/x8XZNE69OGI0UPW95YHnGUrcaRJQeDzNHNUL6je6gpV N4VqahZOeo0YzSmr1qVqUBj3R5/WQeP+6NuH4W88krudOgOHlR8YSFZaC7TKRmdEso41 2ZDBZ8mS5Poi5/nKPfVz5Qf/IiaWerWH5RCj0HVCLf1VrhM0CXXH/PLpnecyJUTG7JK4 qSoQ== X-Gm-Message-State: AOAM533JnUWkYt42co784n6eDSKFhQVDyyJc80YVi4B7IzjPqPRDGiyN xOR8oP1zuGweDyXS8fDR12Y= X-Received: by 2002:a17:90a:17ad:: with SMTP id q42mr26334023pja.181.1622963120512; Sun, 06 Jun 2021 00:05:20 -0700 (PDT) Received: from localhost (185.212.56.112.16clouds.com. [185.212.56.112]) by smtp.gmail.com with ESMTPSA id 21sm5081227pfh.103.2021.06.06.00.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Jun 2021 00:05:20 -0700 (PDT) From: Dejin Zheng To: helgaas@kernel.org, corbet@lwn.net, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, rric@kernel.org, bhelgaas@google.com, linux-doc@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Dejin Zheng Subject: [PATCH v6 1/4] PCI: Introduce pcim_alloc_irq_vectors() Date: Sun, 6 Jun 2021 15:05:08 +0800 Message-Id: <20210606070511.778487-2-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210606070511.778487-1-zhengdejin5@gmail.com> References: <20210606070511.778487-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 Reviewed-by: Robert Richter Reviewed-by: Andy Shevchenko Acked-by: Bjorn Helgaas Signed-off-by: Dejin Zheng --- v5 -> v6: - rebase to 5.13-rc4 v4 -> v5: - Remove the check of enable device in pcim_alloc_irq_vectors() and make it as a static line function. v3 -> v4: - No change 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 | 5 +---- include/linux/pci.h | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b717680377a9..6319e5889688 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1989,10 +1989,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)) diff --git a/include/linux/pci.h b/include/linux/pci.h index c20211e59a57..e9c95cab2540 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1825,6 +1825,30 @@ pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, NULL); } +/** + * 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. + */ +static inline int +pcim_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, + unsigned int max_vecs, unsigned int flags) +{ + if (!pci_is_managed(dev)) + return -EINVAL; + return pci_alloc_irq_vectors(dev, min_vecs, max_vecs, flags); +} + /* Include architecture-dependent settings and functions */ #include -- 2.30.1