From patchwork Thu Aug 16 14:49:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Gordeev X-Patchwork-Id: 1333081 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id C89363FC33 for ; Thu, 16 Aug 2012 14:50:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932678Ab2HPOuK (ORCPT ); Thu, 16 Aug 2012 10:50:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54200 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756861Ab2HPOuI (ORCPT ); Thu, 16 Aug 2012 10:50:08 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7GEnuic014728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 16 Aug 2012 10:49:56 -0400 Received: from dhcp-26-207.brq.redhat.com (dhcp-26-207.brq.redhat.com [10.34.26.207]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7GEnnvX024148 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 16 Aug 2012 10:49:53 -0400 Date: Thu, 16 Aug 2012 16:49:49 +0200 From: Alexander Gordeev To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Thomas Gleixner , Bjorn Helgaas , Suresh Siddha , Yinghai Lu , Jeff Garzik , Matthew Wilcox , x86@kernel.org, linux-pci@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH 5/5] AHCI: Support multiple MSIs Message-ID: <4c1c9f01b8241c76ad2fab64ff3eace6af3f8f9b.1345124063.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.68 on 10.5.11.22 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Take advantage of multiple MSIs implementation on x86 - on systems with IRQ remapping AHCI ports not only get assigned separate MSI vectors - but also separate IRQs. As result, interrupts generated by different ports could be serviced on different CPUs rather than on a single one. In cases when number of allocated MSIs is less than requested the Sharing Last MSI mode does not get used, no matter implemented in hardware or not. Instead, the driver assumes the advantage of multiple MSIs is negated and falls back to the single MSI mode as if MRSM bit was set (some Intel chips implement this strategy anyway - MRSM bit gets set even if the number of allocated MSIs exceeds the number of implemented ports). Signed-off-by: Alexander Gordeev --- drivers/ata/ahci.c | 11 +++---- drivers/ata/ahci.h | 1 + drivers/ata/libahci.c | 24 ++++++++++++++++ drivers/ata/libata-core.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/libata.h | 3 ++ 5 files changed, 99 insertions(+), 6 deletions(-) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index ebaf67e..4bc2cc2 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -1044,7 +1044,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) struct device *dev = &pdev->dev; struct ahci_host_priv *hpriv; struct ata_host *host; - int n_ports, i, rc; + int n_ports, n_msis, i, rc; int ahci_pci_bar = AHCI_PCI_BAR_STANDARD; VPRINTK("ENTER\n"); @@ -1129,11 +1129,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (ahci_sb600_enable_64bit(pdev)) hpriv->flags &= ~AHCI_HFLAG_32BIT_ONLY; - if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev)) - pci_intx(pdev, 1); - hpriv->mmio = pcim_iomap_table(pdev)[ahci_pci_bar]; + n_msis = ahci_init_interrupts(pdev, hpriv); + /* save initial config */ ahci_pci_save_initial_config(pdev, hpriv); @@ -1229,8 +1228,8 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ahci_pci_print_info(host); pci_set_master(pdev); - return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED, - &ahci_sht); + return ata_ahci_host_activate(host, pdev->irq, n_msis, ahci_interrupt, + IRQF_SHARED, &ahci_sht); } static int __init ahci_init(void) diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index c2594dd..0f2d557 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h @@ -328,6 +328,7 @@ void ahci_save_initial_config(struct device *dev, unsigned int mask_port_map); void ahci_init_controller(struct ata_host *host); int ahci_reset_controller(struct ata_host *host); +int ahci_init_interrupts(struct pci_dev *pdev, struct ahci_host_priv *hpriv); int ahci_do_softreset(struct ata_link *link, unsigned int *class, int pmp, unsigned long deadline, diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index f9eaa82..d08ef77 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -1128,6 +1129,29 @@ void ahci_init_controller(struct ata_host *host) } EXPORT_SYMBOL_GPL(ahci_init_controller); +int ahci_init_interrupts(struct pci_dev *pdev, struct ahci_host_priv *hpriv) +{ + int rc; + unsigned int nvec; + + if (!(hpriv->flags & AHCI_HFLAG_NO_MSI)) { + rc = pci_enable_msi_block_auto(pdev, &nvec); + if ((rc == 0) || (rc == 1)) { + return nvec; + } else if (rc > 0) { + /* assume that advantage of multipe MSIs is negated, + * so fallback to single MSI mode to save resources */ + pci_disable_msi(pdev); + if (!pci_enable_msi(pdev)) + return 1; + } + } + + pci_intx(pdev, 1); + return 0; +} +EXPORT_SYMBOL_GPL(ahci_init_interrupts); + static void ahci_dev_config(struct ata_device *dev) { struct ahci_host_priv *hpriv = dev->link->ap->host->private_data; diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index cece3a4..3f5e735 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6154,6 +6154,71 @@ int ata_host_activate(struct ata_host *host, int irq, } /** + * ata_ahci_host_activate - start AHCI host, request IRQs and register it + * @host: target ATA host + * @irq: base IRQ number to request + * @n_msis: number of MSIs allocated for this host + * @irq_handler: irq_handler used when requesting IRQs + * @irq_flags: irq_flags used when requesting IRQs + * @sht: scsi_host_template to use when registering the host + * + * Similar to ata_host_activate, but requests IRQs according to AHCI-1.1 + * when multiple MSIs were allocated. That is one MSI per port, starting + * from @irq. Also, when number of MSIs is less than number of ports, + * last MSI is shared among those ports which did not get their personal + * MSI vector - see 10.6.2.3.1. + * + * LOCKING: + * Inherited from calling layer (may sleep). + * + * RETURNS: + * 0 on success, -errno otherwise. + */ +int ata_ahci_host_activate(struct ata_host *host, int irq, unsigned int n_msis, + irq_handler_t irq_handler, unsigned long irq_flags, + struct scsi_host_template *sht) +{ + int i, rc; + unsigned int n_irqs; + + if (!irq || (n_msis < 2)) + return ata_host_activate(host, irq, irq_handler, irq_flags, sht); + + rc = ata_host_start(host); + if (rc) + return rc; + + n_irqs = min(host->n_ports, n_msis); + + for (i = 0; i < n_irqs; i++) { + rc = devm_request_irq(host->dev, + irq + i, irq_handler, irq_flags, + dev_driver_string(host->dev), host); + if (rc) + goto out_free_irqs; + } + + for (i = 0; i < n_irqs; i++) + ata_port_desc(host->ports[i], "irq %d", irq + i); + for (; i < host->n_ports; i++) + ata_port_desc(host->ports[i], "irq %d", n_irqs - 1); + + rc = ata_host_register(host, sht); + if (rc) + goto out_free_all_irqs; + + return 0; + +out_free_all_irqs: + i = n_irqs; +out_free_irqs: + for (; i; i--) + devm_free_irq(host->dev, irq + i - 1, host); + + return rc; +} + +/** * ata_port_detach - Detach ATA port in prepration of device removal * @ap: ATA port to be detached * @@ -6748,6 +6813,7 @@ EXPORT_SYMBOL_GPL(ata_slave_link_init); EXPORT_SYMBOL_GPL(ata_host_start); EXPORT_SYMBOL_GPL(ata_host_register); EXPORT_SYMBOL_GPL(ata_host_activate); +EXPORT_SYMBOL_GPL(ata_ahci_host_activate); EXPORT_SYMBOL_GPL(ata_host_detach); EXPORT_SYMBOL_GPL(ata_sg_init); EXPORT_SYMBOL_GPL(ata_qc_complete); diff --git a/include/linux/libata.h b/include/linux/libata.h index 6e887c7..c6b40f5 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -986,6 +986,9 @@ extern int ata_host_register(struct ata_host *host, extern int ata_host_activate(struct ata_host *host, int irq, irq_handler_t irq_handler, unsigned long irq_flags, struct scsi_host_template *sht); +extern int ata_ahci_host_activate(struct ata_host *host, int irq, + unsigned int n_msis, irq_handler_t irq_handler, + unsigned long irq_flags, struct scsi_host_template *sht); extern void ata_host_detach(struct ata_host *host); extern void ata_host_init(struct ata_host *, struct device *, unsigned long, struct ata_port_operations *);