From patchwork Thu Sep 8 19:32:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 9321973 X-Patchwork-Delegate: bhelgaas@google.com 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 1758760869 for ; Thu, 8 Sep 2016 19:33:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 056BE299C7 for ; Thu, 8 Sep 2016 19:33:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDFDF299CE; Thu, 8 Sep 2016 19:33:10 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 852B8299CA for ; Thu, 8 Sep 2016 19:33:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941359AbcIHTdJ (ORCPT ); Thu, 8 Sep 2016 15:33:09 -0400 Received: from mail-lf0-f41.google.com ([209.85.215.41]:34396 "EHLO mail-lf0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941343AbcIHTdI (ORCPT ); Thu, 8 Sep 2016 15:33:08 -0400 Received: by mail-lf0-f41.google.com with SMTP id u14so29062978lfd.1 for ; Thu, 08 Sep 2016 12:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:organization:user-agent :mime-version:content-transfer-encoding; bh=QaAVIsLpll7WJ5IW1vsqlnL9jXBSj2inNHAruOusbfk=; b=kB5a7t6rCkxGkMQGLW2KZlzbJoQKbM0wKJcL53NP/JBVf9o5e1BF8e80Js73cBihob m8aZN7OEPiq/IxYDQ1X/HrWMeYrHN9NMLwjNPD4yD6euiOl67oIabQ3l+aHYGZGKzBt0 oeSxg6WnEpjklV+cJ/V18/9rxauiMZD/IuGo3cSYWkBlEfBF9OG2erbAD45Rl1AasuIT 6bMphiVwLCZWkx6f40yUk21gjJ4J3Ku6UJ2+Y35rbhlLHXMoAH0MCb9FaxDy8tH9vbic CZBtGHXVsvsTdI61kiKbt7USd++Ks2w/J2tqlVihrA35g/LRH5GGsEwxUEGmSKJyIAT6 EaxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:organization :user-agent:mime-version:content-transfer-encoding; bh=QaAVIsLpll7WJ5IW1vsqlnL9jXBSj2inNHAruOusbfk=; b=bVrbR3fqiRYuCtmaVbSmlVX6SNq5tETm4USbt7v0sCSM9e2ocSl8weYWTq+W/HX4zd TQd/8CMxeXBtoUpgX4OaqG3bMj1x2WpjTLbebekVUjui9z7eTrfbf1Fu7CJy57m6Iq9p gswWWwLW0VJdwf7vIW8rp1L70x1QRwqKN0xaFMLWsbdovq2Rg5FWWkwD7XNQKzMM/xaI 1rRgFeu1uyAaJwTHch0wP10CoPecluAso3QC4C1Wsd/kRkVZN+IIbetqo64d4TbHzhI7 KdKi9ttsy3OKDQFEJP8CqiIilRHMFgQ2VKjXew5a/UrxZzJ3Ijo071OEgcRetjnRYwsl UbtQ== X-Gm-Message-State: AE9vXwMNIOT/YDWeyFiXl3d/bMburlYsjDz3+OqDzXzJThTmqtTe35ZbjKHwnjxyYORgYw== X-Received: by 10.25.20.96 with SMTP id k93mr478440lfi.35.1473363186298; Thu, 08 Sep 2016 12:33:06 -0700 (PDT) Received: from wasted.cogentembedded.com ([31.173.85.174]) by smtp.gmail.com with ESMTPSA id v82sm1696549lfi.30.2016.09.08.12.33.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Sep 2016 12:33:05 -0700 (PDT) From: Sergei Shtylyov To: horms@verge.net.au, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH] pcie-rcar: MSI range allocation support Date: Thu, 08 Sep 2016 22:32:59 +0300 Message-ID: <2520843.q5xC3E7R5B@wasted.cogentembedded.com> Organization: Cogent Embedded Inc. User-Agent: KMail/4.14.10 (Linux/4.7.2-101.fc23.x86_64; KDE/4.14.20; x86_64; ; ) MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Grigory Kletsko Impelment MSI setup_irqs() method which enables allocation of several MSIs at once. [Sergei Shtylyov: removed unrelated/unneeded changes, fixed too long lines, reordered the variable declarations, reworded the summary/description.] Signed-off-by: Grigory Kletsko Signed-off-by: Sergei Shtylyov Acked-by: Simon Horman --- The patch is against the 'next' branch of Bjorn Helgaas' 'pci.git' repo plus the patch posted yesterday. drivers/pci/host/pcie-rcar.c | 72 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) -- 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 Index: pci/drivers/pci/host/pcie-rcar.c =================================================================== --- pci.orig/drivers/pci/host/pcie-rcar.c +++ pci/drivers/pci/host/pcie-rcar.c @@ -673,6 +673,18 @@ static int rcar_msi_alloc(struct rcar_ms return msi; } +static int rcar_msi_alloc_region(struct rcar_msi *chip, int no_irqs) +{ + int msi; + + mutex_lock(&chip->lock); + msi = bitmap_find_free_region(chip->used, INT_PCI_MSI_NR, + order_base_2(no_irqs)); + mutex_unlock(&chip->lock); + + return msi; +} + static void rcar_msi_free(struct rcar_msi *chip, unsigned long irq) { mutex_lock(&chip->lock); @@ -768,7 +780,7 @@ static int rcar_msi_setup_irq(struct msi if (hwirq < 0) return hwirq; - irq = irq_create_mapping(msi->domain, hwirq); + irq = irq_find_mapping(msi->domain, hwirq); if (!irq) { rcar_msi_free(msi, hwirq); return -EINVAL; @@ -785,6 +797,58 @@ static int rcar_msi_setup_irq(struct msi return 0; } +static int rcar_msi_setup_irqs(struct msi_controller *chip, + struct pci_dev *pdev, int nvec, int type) +{ + struct rcar_pcie *pcie = container_of(chip, struct rcar_pcie, msi.chip); + struct rcar_msi *msi = to_rcar_msi(chip); + struct msi_desc *desc; + struct msi_msg msg; + unsigned int irq; + int hwirq; + int i; + + /* MSI-X interrupts are not supported */ + if (type == PCI_CAP_ID_MSIX) + return -EINVAL; + + WARN_ON(!list_is_singular(&pdev->dev.msi_list)); + desc = list_entry(pdev->dev.msi_list.next, struct msi_desc, list); + + hwirq = rcar_msi_alloc_region(msi, nvec); + if (hwirq < 0) + return -ENOSPC; + + irq = irq_find_mapping(msi->domain, hwirq); + if (!irq) + return -ENOSPC; + + for (i = 0; i < nvec; i++) { + /* + * irq_create_mapping() called from rcar_pcie_probe() pre- + * allocates descs, so there is no need to allocate descs here. + * We can therefore assume that if irq_find_mapping() above + * returns non-zero, then the descs are also successfully + * allocated. + */ + if (irq_set_msi_desc_off(irq, i, desc)) { + /* TODO: clear */ + return -EINVAL; + } + } + + desc->nvec_used = nvec; + desc->msi_attrib.multiple = order_base_2(nvec); + + msg.address_lo = rcar_pci_read_reg(pcie, PCIEMSIALR) & ~MSIFE; + msg.address_hi = rcar_pci_read_reg(pcie, PCIEMSIAUR); + msg.data = hwirq; + + pci_write_msi_msg(irq, &msg); + + return 0; +} + static void rcar_msi_teardown_irq(struct msi_controller *chip, unsigned int irq) { struct rcar_msi *msi = to_rcar_msi(chip); @@ -819,12 +883,13 @@ static int rcar_pcie_enable_msi(struct r struct platform_device *pdev = to_platform_device(pcie->dev); struct rcar_msi *msi = &pcie->msi; unsigned long base; - int err; + int err, i; mutex_init(&msi->lock); msi->chip.dev = pcie->dev; msi->chip.setup_irq = rcar_msi_setup_irq; + msi->chip.setup_irqs = rcar_msi_setup_irqs; msi->chip.teardown_irq = rcar_msi_teardown_irq; msi->domain = irq_domain_add_linear(pcie->dev->of_node, INT_PCI_MSI_NR, @@ -834,6 +899,9 @@ static int rcar_pcie_enable_msi(struct r return -ENOMEM; } + for (i = 0; i < INT_PCI_MSI_NR; i++) + irq_create_mapping(msi->domain, i); + /* Two irqs are for MSI, but they are also used for non-MSI irqs */ err = devm_request_irq(&pdev->dev, msi->irq1, rcar_pcie_msi_irq, IRQF_SHARED | IRQF_NO_THREAD,