From patchwork Tue Nov 8 07:47:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 9416859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 755E460720 for ; Tue, 8 Nov 2016 08:23:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68CA1289BC for ; Tue, 8 Nov 2016 08:23:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DCCE289C1; Tue, 8 Nov 2016 08:23:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3DC4289C3 for ; Tue, 8 Nov 2016 08:23:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751969AbcKHIXx (ORCPT ); Tue, 8 Nov 2016 03:23:53 -0500 Received: from mx2.suse.de ([195.135.220.15]:46870 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752715AbcKHIXv (ORCPT ); Tue, 8 Nov 2016 03:23:51 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DD5E1AB9B; Tue, 8 Nov 2016 07:47:36 +0000 (UTC) From: Hannes Reinecke To: Thomas Gleixner Cc: Christoph Hellwig , Jens Axboe , linux-block@vger.kernel.org, linux-pci@vger.kernel.org, Linux Kernel Mailinglist , Hannes Reinecke , Hannes Reinecke Subject: [RFC PATCH] pci: add pci_irq_get_affinity_vector() Date: Tue, 8 Nov 2016 08:47:21 +0100 Message-Id: <1478591241-123356-1-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a reverse-mapping function to return the interrupt vector for any CPU if interrupt affinity is enabled. Signed-off-by: Hannes Reinecke --- drivers/pci/msi.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 37 insertions(+) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index bfdd074..de5ed32 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -1302,6 +1302,42 @@ const struct cpumask *pci_irq_get_affinity(struct pci_dev *dev, int nr) } EXPORT_SYMBOL(pci_irq_get_affinity); +/** + * pci_irq_get_affinity_vector - return the vector number for a given CPU + * @dev: PCI device to operate on + * @cpu: cpu number + * + * Returns the vector number for CPU @cpu or a negative error number + * if interrupt affinity is not set. + */ +int pci_irq_get_affinity_vector(struct pci_dev *dev, int cpu) +{ + if (dev->msix_enabled) { + struct msi_desc *entry; + + for_each_pci_msi_entry(entry, dev) { + if (cpumask_test_cpu(cpu, entry->affinity)) + return entry->irq; + } + return -EINVAL; + } else if (dev->msi_enabled) { + struct msi_desc *entry = first_pci_msi_entry(dev); + int nr; + + if (!entry) + return -ENOENT; + + for (nr = 0; nr < entry->nvec_used; nr++) { + if (cpumask_test_cpu(cpu, &entry->affinity[nr])) + return dev->irq + nr; + } + return -EINVAL; + } else { + return dev->irq; + } +} +EXPORT_SYMBOL(pci_irq_get_affinity_vector); + struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc) { return to_pci_dev(desc->dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index 0e49f70..2dd0817 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1315,6 +1315,7 @@ int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, void pci_free_irq_vectors(struct pci_dev *dev); int pci_irq_vector(struct pci_dev *dev, unsigned int nr); const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev, int vec); +int pci_irq_get_affinity_vector(struct pci_dev *pdev, int cpu); #else static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }