From patchwork Mon Apr 29 04:32:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Gordeev X-Patchwork-Id: 2498531 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 47820DF25A for ; Mon, 29 Apr 2013 04:31:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752000Ab3D2EbS (ORCPT ); Mon, 29 Apr 2013 00:31:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21458 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751882Ab3D2EbR (ORCPT ); Mon, 29 Apr 2013 00:31:17 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3T4VBA1011495 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 29 Apr 2013 00:31:11 -0400 Received: from dhcp-26-207.brq.redhat.com (vpn-57-233.rdu2.redhat.com [10.10.57.233]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r3T4V6df028448 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 29 Apr 2013 00:31:09 -0400 Date: Mon, 29 Apr 2013 06:32:34 +0200 From: Alexander Gordeev To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-pci@vger.kernel.org, Suresh Siddha , Yinghai Lu , Joerg Roedel , Jan Beulich , Ingo Molnar , Bjorn Helgaas Subject: [PATCH -tip/apic 1/2] PCI/MSI: Allocate as many multiple-MSIs as requested Message-ID: <8575dc590b819892f366852fe50835efaf579f4f.1367160713.git.agordeev@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When multiple MSIs are enabled with pci_enable_msi_block(), the requested number of interrupts 'nvec' is rounded up to the nearest power-of-two value. The result is then used for setting up the number of MSI messages in the PCI device and allocation of interrupt resources in the operating system (i.e. vector numbers). Thus, in cases when a device driver requests some number of MSIs and this number is not a power-of-two value, the extra operating system resources (allocated as the result of rounding) are wasted. This fix introduces 'msi_desc::nvec' field to address the above issue. When non-zero, it will report the actual number of MSIs the device will send, as requested by the device driver. This value should be used by architectures to properly set up and tear down associated interrupt resources. Note, although the existing 'msi_desc::multiple' field might seem redundant, in fact in does not. In general case the number of MSIs a PCI device is initialized with is not necessarily the closest power- of-two value of the number of MSIs the device will send. Thus, in theory it would not be always possible to derive the former from the latter and we need to keep them both, to stress this corner case. Besides, since 'msi_desc::multiple' is a bitfield, throwing it out would not save us any space. Signed-off-by: Alexander Gordeev --- drivers/pci/msi.c | 10 ++++++++-- include/linux/msi.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 00cc78c..014b9d5 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -79,7 +79,10 @@ void default_teardown_msi_irqs(struct pci_dev *dev) int i, nvec; if (entry->irq == 0) continue; - nvec = 1 << entry->msi_attrib.multiple; + if (entry->nvec) + nvec = entry->nvec; + else + nvec = 1 << entry->msi_attrib.multiple; for (i = 0; i < nvec; i++) arch_teardown_msi_irq(entry->irq + i); } @@ -340,7 +343,10 @@ static void free_msi_irqs(struct pci_dev *dev) int i, nvec; if (!entry->irq) continue; - nvec = 1 << entry->msi_attrib.multiple; + if (entry->nvec) + nvec = entry->nvec; + else + nvec = 1 << entry->msi_attrib.multiple; #ifdef CONFIG_GENERIC_HARDIRQS for (i = 0; i < nvec; i++) BUG_ON(irq_has_action(entry->irq + i)); diff --git a/include/linux/msi.h b/include/linux/msi.h index ce93a34..0e20dfc 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -35,6 +35,7 @@ struct msi_desc { u32 masked; /* mask bits */ unsigned int irq; + unsigned int nvec; /* number of messages */ struct list_head list; union {