Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp657416imm; Fri, 1 Jun 2018 07:27:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLTVemdt4vKdmaoqWLkMoSOzBnvGZSfgRO6sGp1T9z1h7v3yfJgP0jwvJPb1kHja1eQN9KO X-Received: by 2002:a62:84e:: with SMTP id c75-v6mr7384821pfd.35.1527863277845; Fri, 01 Jun 2018 07:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527863277; cv=none; d=google.com; s=arc-20160816; b=sk5ooOxkwbltt4w1rrr/nuLAg9RHAx49QkbTPgWfH0i7OOkzPMF9SIZjNly2PvE8ms yAzteyQWP0l33xiahMICwquFm9NJDXonWXDmEUyPA7HosZanXxSkIPKewMWBvYAIM1X9 UaNYcJF6efgGCwx8RbHd+o29S0FNeVddCaNKNV4GkNmVbFSa1VoBujmW6R1aTSzrzAn+ fV0ArkvUiXuQzE3IhT9kyyafMmQ+Tg8fGaVWrhVTBF1HOatW/e6LFWpVBvH04XeTMBT+ c+0suAMIJrhhMd76/opTfKWVjYS6d+srz1NRvkklR4vZv9O1rVNtp4Zn+qgOpo2fLtcy RnNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=jYqDZn8acTgEvOp8CoexXqrReRFfrkXQ/om37mLnMWo=; b=YGe4jXfBEYv8u9hmpXRiI8+dj5MrZSHBnXiccDLK5SH9sp9U/+DcfIE3ojp412z+6J 03rPukgkLGGyYgxlnl1HEemlVDmtfWxRxesI0pr0PdVm/mcPQf2hneOtlMECnK5oFnFm 23P1/bDjxn5nr6v9hB4rweBALrl6DlBsPcz2xRgcyn8PXQS1awmcrQRNWPLUy15iBawF eM2RkK8K24SX9839/h2Zp+AZDhbyaSMqVvLFWi4ojIaF7jlG5OlmCkLqrvw6FCy/yPzO 5LYmOtaZScHv/YN9Db9J4iTd3Uj2CnQPxqz00yHp8W4ujTzjm8OEquFWNR1eTZx1j6Wf PB5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=MMo8lxc1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9-v6si1360258pfh.358.2018.06.01.07.27.35; Fri, 01 Jun 2018 07:27:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=MMo8lxc1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752330AbeFAOZd (ORCPT + 99 others); Fri, 1 Jun 2018 10:25:33 -0400 Received: from smtprelay.synopsys.com ([198.182.37.59]:42603 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751687AbeFAOZG (ORCPT ); Fri, 1 Jun 2018 10:25:06 -0400 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id 2D8DC1E15E4; Fri, 1 Jun 2018 16:25:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1527863103; bh=APxvrE1KxqLaqVQL868YdQF6TTbDi+xDLPxQ6ohsw9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=MMo8lxc15sYeKRSTunczzq0PB+Q7HtIabE4qR2wUvVt+7X/+AZMLkURhJO7nGKTbt HF5/CeQtvszVcGcFtcDtt2JqnczZvTR/nDwNzi3eOZ/EOToGy/aVBGQ91K9zGUJ+iA rfHiwUAIq6mgw5rXWQ1+eK9f5o0IWZjYJH+GtLiD090oBpKZdnvgkD4zp92sG9+TFj GSp+PQ6W+mFUhCWUZaE6sIeANw6YDoP5cnDIFoQLnDdiHpAZZPkutY5FK9QMkdOm2r mMBZgxDsKE4l9l5cER0r5myyhRn5yr8+dkg4lIfoU8Q5uUX3rmmdWrFb4PLmvTHMV4 1beDH8BAeiP5w== Received: from pt02.synopsys.com (pt02.synopsys.com [10.107.23.240]) by mailhost.synopsys.com (Postfix) with ESMTP id 1B6B73C23; Fri, 1 Jun 2018 07:25:02 -0700 (PDT) Received: from UbuntuMate-64Bits.internal.synopsys.com (gustavo-e7480.internal.synopsys.com [10.107.25.102]) by pt02.synopsys.com (Postfix) with ESMTP id 93EF33D7A6; Fri, 1 Jun 2018 15:25:00 +0100 (WEST) From: Gustavo Pimentel To: bhelgaas@google.com, lorenzo.pieralisi@arm.com, Joao.Pinto@synopsys.com, jingoohan1@gmail.com, kishon@ti.com, adouglas@cadence.com, jesper.nilsson@axis.com Cc: linux-pci@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Gustavo Pimentel Subject: [PATCH v3 09/10] pci_endpoint_test: Add 2 ioctl commands Date: Fri, 1 Jun 2018 15:24:51 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add MSI-X support and update driver documentation accordingly. Add 2 new IOCTL commands: - Allow to reconfigure driver IRQ type in runtime. - Allow to retrieve current driver IRQ type configured. Signed-off-by: Gustavo Pimentel --- Change v2->v3: - New patch file created base on the previous patch "misc: pci_endpoint_test: Add MSI-X support" patch file following Kishon's suggestion. Documentation/misc-devices/pci-endpoint-test.txt | 3 + drivers/misc/pci_endpoint_test.c | 177 +++++++++++++++++------ 2 files changed, 132 insertions(+), 48 deletions(-) diff --git a/Documentation/misc-devices/pci-endpoint-test.txt b/Documentation/misc-devices/pci-endpoint-test.txt index fdfa0f6..58ccca4 100644 --- a/Documentation/misc-devices/pci-endpoint-test.txt +++ b/Documentation/misc-devices/pci-endpoint-test.txt @@ -28,6 +28,9 @@ ioctl to be tested should be passed as argument. PCITEST_MSIX: Tests message signalled interrupts. The MSI-X number to be tested should be passed as argument. + PCITEST_SET_IRQTYPE: Changes driver IRQ type configuration. The IRQ type + should be passed as argument (0: Legacy, 1:MSI, 2:MSI-X). + PCITEST_GET_IRQTYPE: Gets driver IRQ type configuration. PCITEST_WRITE: Perform write tests. The size of the buffer should be passed as argument. PCITEST_READ: Perform read tests. The size of the buffer should be passed diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 8d15dbe..df2017f 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -157,6 +157,87 @@ static irqreturn_t pci_endpoint_test_irqhandler(int irq, void *dev_id) return IRQ_HANDLED; } +static void pci_endpoint_test_free_irq_vectors(struct pci_endpoint_test *test) +{ + int i; + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + + for (i = 0; i < test->num_irqs; i++) + devm_free_irq(dev, pci_irq_vector(pdev, i), test); + + test->num_irqs = 0; +} + +static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test) +{ + int irq = -1; + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + bool res = true; + + switch (irq_type) { + case IRQ_TYPE_LEGACY: + irq = 0; + break; + case IRQ_TYPE_MSI: + irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI); + if (irq < 0) + dev_err(dev, "Failed to get MSI interrupts\n"); + break; + case IRQ_TYPE_MSIX: + irq = pci_alloc_irq_vectors(pdev, 1, 2048, PCI_IRQ_MSIX); + if (irq < 0) + dev_err(dev, "Failed to get MSI-X interrupts\n"); + break; + default: + dev_err(dev, "Invalid IRQ type selected\n"); + } + + if (irq < 0) { + irq = 0; + res = false; + } + test->num_irqs = irq; + + return res; +} + +static void pci_endpoint_test_release_irq(struct pci_endpoint_test *test) +{ + struct pci_dev *pdev = test->pdev; + + pci_disable_msi(pdev); + pci_disable_msix(pdev); +} + +static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test) +{ + int i; + int err; + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + + err = devm_request_irq(dev, pdev->irq, pci_endpoint_test_irqhandler, + IRQF_SHARED, DRV_MODULE_NAME, test); + if (err) { + dev_err(dev, "Failed to request IRQ %d\n", pdev->irq); + return false; + } + + for (i = 1; i < test->num_irqs; i++) { + err = devm_request_irq(dev, pci_irq_vector(pdev, i), + pci_endpoint_test_irqhandler, + IRQF_SHARED, DRV_MODULE_NAME, test); + if (err) + dev_err(dev, "Failed to request IRQ %d for MSI%s %d\n", + pci_irq_vector(pdev, i), + irq_type == IRQ_TYPE_MSIX ? "-X" : "", i + 1); + } + + return true; +} + static bool pci_endpoint_test_bar(struct pci_endpoint_test *test, enum pci_barno barno) { @@ -440,6 +521,38 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size) return ret; } +static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, + int req_irq_type) +{ + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + + if (req_irq_type < IRQ_TYPE_LEGACY || req_irq_type > IRQ_TYPE_MSIX) { + dev_err(dev, "Invalid IRQ type option\n"); + return false; + } + + if (irq_type == req_irq_type) + return true; + + irq_type = req_irq_type; + + pci_endpoint_test_free_irq_vectors(test); + pci_endpoint_test_release_irq(test); + + if (!pci_endpoint_test_alloc_irq_vectors(test)) { + pci_endpoint_test_release_irq(test); + return false; + } + + if (!pci_endpoint_test_request_irq(test)) { + pci_endpoint_test_release_irq(test); + return false; + } + + return true; +} + static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -471,6 +584,12 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, case PCITEST_COPY: ret = pci_endpoint_test_copy(test, arg); break; + case PCITEST_SET_IRQTYPE: + ret = pci_endpoint_test_set_irq(test, arg); + break; + case PCITEST_GET_IRQTYPE: + ret = irq_type; + break; } ret: @@ -486,9 +605,7 @@ static const struct file_operations pci_endpoint_test_fops = { static int pci_endpoint_test_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { - int i; int err; - int irq = 0; int id; char name[20]; enum pci_barno bar; @@ -537,43 +654,11 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, pci_set_master(pdev); - switch (irq_type) { - case IRQ_TYPE_LEGACY: - irq = 0; - break; - case IRQ_TYPE_MSI: - irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI); - if (irq < 0) - dev_err(dev, "Failed to get MSI interrupts\n"); - test->num_irqs = irq; - break; - case IRQ_TYPE_MSIX: - irq = pci_alloc_irq_vectors(pdev, 1, 2048, PCI_IRQ_MSIX); - if (irq < 0) - dev_err(dev, "Failed to get MSI-X interrupts\n"); - test->num_irqs = irq; - break; - default: - dev_err(dev, "Invalid IRQ type selected\n"); - } - - - err = devm_request_irq(dev, pdev->irq, pci_endpoint_test_irqhandler, - IRQF_SHARED, DRV_MODULE_NAME, test); - if (err) { - dev_err(dev, "Failed to request IRQ %d\n", pdev->irq); - goto err_disable_msi; - } + if (!pci_endpoint_test_alloc_irq_vectors(test)) + goto err_disable_irq; - for (i = 1; i < irq; i++) { - err = devm_request_irq(dev, pci_irq_vector(pdev, i), - pci_endpoint_test_irqhandler, - IRQF_SHARED, DRV_MODULE_NAME, test); - if (err) - dev_err(dev, "Failed to request IRQ %d for MSI%s %d\n", - pci_irq_vector(pdev, i), - irq_type == IRQ_TYPE_MSIX ? "-X" : "", i + 1); - } + if (!pci_endpoint_test_request_irq(test)) + goto err_disable_irq; for (bar = BAR_0; bar <= BAR_5; bar++) { if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) { @@ -633,12 +718,10 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, pci_iounmap(pdev, test->bar[bar]); } - for (i = 0; i < irq; i++) - devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i), test); + pci_endpoint_test_free_irq_vectors(test); -err_disable_msi: - pci_disable_msi(pdev); - pci_disable_msix(pdev); +err_disable_irq: + pci_endpoint_test_release_irq(test); pci_release_regions(pdev); err_disable_pdev: @@ -650,7 +733,6 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, static void pci_endpoint_test_remove(struct pci_dev *pdev) { int id; - int i; enum pci_barno bar; struct pci_endpoint_test *test = pci_get_drvdata(pdev); struct miscdevice *misc_device = &test->miscdev; @@ -667,10 +749,9 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) if (test->bar[bar]) pci_iounmap(pdev, test->bar[bar]); } - for (i = 0; i < test->num_irqs; i++) - devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i), test); - pci_disable_msi(pdev); - pci_disable_msix(pdev); + pci_endpoint_test_free_irq_vectors(test); + + pci_endpoint_test_release_irq(test); pci_release_regions(pdev); pci_disable_device(pdev); } -- 2.7.4