From patchwork Thu May 12 07:35:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9077021 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 308C2BF29F for ; Thu, 12 May 2016 07:35:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 50967201E4 for ; Thu, 12 May 2016 07:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7EFC8201D3 for ; Thu, 12 May 2016 07:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752484AbcELHfz (ORCPT ); Thu, 12 May 2016 03:35:55 -0400 Received: from verein.lst.de ([213.95.11.211]:48290 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752480AbcELHfy (ORCPT ); Thu, 12 May 2016 03:35:54 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 9EDC968C6B; Thu, 12 May 2016 09:35:52 +0200 (CEST) Date: Thu, 12 May 2016 09:35:52 +0200 From: Christoph Hellwig To: Alexander Gordeev Cc: Christoph Hellwig , helgaas@kernel.org, pjw@netapp.com, axboe@fb.com, keith.busch@intel.com, linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org Subject: Re: [PATCH 1/2] PCI: Provide sensible irq vector alloc/free routines Message-ID: <20160512073552.GA4027@lst.de> References: <1462457096-19795-1-git-send-email-hch@lst.de> <1462457096-19795-2-git-send-email-hch@lst.de> <20160511074527.GA31347@agordeev.lab.eng.brq.redhat.com> <20160511085049.GA20279@lst.de> <20160511094432.GB31347@agordeev.lab.eng.brq.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160511094432.GB31347@agordeev.lab.eng.brq.redhat.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Alex, what do you think about the incremental patch below? This should address the concerns about the strange PPC bridges, although I don't have a way to test one: --- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index a510484..32ce65e 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -1177,6 +1177,7 @@ int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int nr_vecs, if (WARN_ON_ONCE(dev->msi_enabled || dev->msix_enabled)) return -EINVAL; +retry: if (!pci_msi_supported(dev, 1)) goto use_legacy_irq; @@ -1191,17 +1192,26 @@ int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int nr_vecs, if (!dev->irqs) return -ENOMEM; - if (dev->msix_cap && !(flags & PCI_IRQ_NOMSIX)) + if (dev->msix_cap && !(flags & PCI_IRQ_NOMSIX)) { ret = __pci_enable_msix(dev, nr_vecs); - else + if (ret < 0) + flags |= PCI_IRQ_NOMSIX; + } else { ret = __pci_enable_msi(dev, nr_vecs); - if (ret) - goto out_free_irqs; + } - return 0; + /* if we succeeded getting all vectors return the number we got: */ + if (!ret) + return nr_vecs; -out_free_irqs: kfree(dev->irqs); + /* if ret is positive it's the numbers of vectors we can use, retry: */ + if (ret > 0) { + nr_vecs = ret; + goto retry; + } + + /* no MSI or MSI-X vectors available, fall back to the legacy IRQ: */ use_legacy_irq: dev->irqs = &dev->irq; return 1;