Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1568091imm; Fri, 6 Jul 2018 02:28:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdWwYcoMC712pLOwemzUke9XbE60oCSfliC88SgbLEyHxQlq73YTDK17YP8+91Gs6XfyXX7 X-Received: by 2002:a62:9bc5:: with SMTP id e66-v6mr9818839pfk.84.1530869329520; Fri, 06 Jul 2018 02:28:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530869329; cv=none; d=google.com; s=arc-20160816; b=d8Ryqz80fhldkadcH8SpJpuxwJWtQPvxUmGupTtUueCggPdKyl7jHSE1IHICqygt2s mFeWCs5wEvA6zYuDAf3BlOnrfTFiQfKSbHjeqZLJC/rup/hgANyrt0B0P7kZp9By2/u+ QNsbCk09CEWLPk1hosBmcgL24ORuenXtSFIy+Nz+7WGadkcS0+ppfPe9jL0oBB2/lilV UsprHxkghAn+omNQB9hjCZDqFpsWnBohnWocX9ErVs69IQ76BJN+NeVWz6cDQRGhjwUU Ex1kJPFaAm3obtlBXHlf8HuLHY8NbJw7IaLxZrLNXNU6QEaDQr+F0MB0gm6ds6cWQNas UbWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:dkim-signature:arc-authentication-results; bh=O/RIsdtJtMx3qlrnafpYmFiGYePeKwW81A7fzOxeTX8=; b=NOuVUPzRGZq/qkG0Mwj6bBx/dPmu6zCC0KY2E5DEnXtQhf1b1wxWu04tXPtX4oDmP/ z8pimUikrWvBxBi1iVAFQO8v8SMsrowc25xSRH1iPS4YtyDjY7CLWa3c+IwcNstXs6Bv 1QlgD0Dy2lTSlHl5wEeiblQL6PVjpKVETe2faGPcefLJ1Z0kQ2SotOgdT38SmGOnX59x ue6rBA+BtLzKAP+ZSHpgLiI7w1HxEQR5IZsDsvUchchXhHyrOTwEzPva25LMhYUncPps 4On16jUPubAm6GH9KZA+GXZX+EkDOJlHaxoyTEOQbbywKu77FZu7p5+XmkmyqqROg5Qa G3ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=r3TVAUY2; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15-v6si7723247pff.91.2018.07.06.02.28.34; Fri, 06 Jul 2018 02:28:49 -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=@ti.com header.s=ti-com-17Q1 header.b=r3TVAUY2; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753674AbeGFJ1m (ORCPT + 99 others); Fri, 6 Jul 2018 05:27:42 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:59386 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753075AbeGFJ1j (ORCPT ); Fri, 6 Jul 2018 05:27:39 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id w669ROxv060797; Fri, 6 Jul 2018 04:27:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1530869244; bh=O/RIsdtJtMx3qlrnafpYmFiGYePeKwW81A7fzOxeTX8=; h=Subject:To:References:CC:From:Date:In-Reply-To; b=r3TVAUY2+ORpBEhK9ztW/mItUYPN+ZAmvg5F7ba3cZZf8yvcjpVFkwUVTTv+Kquu+ kGkXZ/cOOcTfss+LOza+7T714U8QDZ/n/GRh6iuX3lODTX1zZ1fSGEQ7wQeaOEUr0S DjTOJDQVr/2eccZBy4CCgUHV3xFiAcqFcr84KCv0= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w669ROJA012583; Fri, 6 Jul 2018 04:27:24 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 6 Jul 2018 04:27:23 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 6 Jul 2018 04:27:23 -0500 Received: from [172.24.190.233] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w669RKwi005724; Fri, 6 Jul 2018 04:27:20 -0500 Subject: Re: [PATCH v6 09/11] pci_endpoint_test: Add 2 ioctl commands To: Gustavo Pimentel , , , , , , , References: <848ce0dbff24fcdd6bb7b45cb14a766820d4e9fb.1529595907.git.gustavo.pimentel@synopsys.com> CC: , , From: Kishon Vijay Abraham I Message-ID: <5afaae45-c20b-27fd-3dce-474ee893b0ce@ti.com> Date: Fri, 6 Jul 2018 14:57:19 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <848ce0dbff24fcdd6bb7b45cb14a766820d4e9fb.1529595907.git.gustavo.pimentel@synopsys.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thursday 21 June 2018 09:31 PM, Gustavo Pimentel wrote: > 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. | -------------------------------------------------------------------------------------------- > Change v3->v4: | -------------------------------------------------------------------------------------------- > - Rebased to Lorenzo's master branch v4.18-rc1. > Change v4->v5: > - Nothing changed, just to follow the patch set version. > Change v5->v6: > - Moved PCITEST_SET_IRQTYPE and PCITEST_GET_IRQTYPE ioctl entries > from patch #10 to here. > - Increased ioctl parameters range associated to > drivers/misc/pci_endpoint_test.c driver. > > Documentation/ioctl/ioctl-number.txt | 2 +- > Documentation/misc-devices/pci-endpoint-test.txt | 3 + > drivers/misc/pci_endpoint_test.c | 177 +++++++++++++++++------ > include/uapi/linux/pcitest.h | 2 + > 4 files changed, 135 insertions(+), 49 deletions(-) > > diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt > index 65259d4..c15c4f3 100644 > --- a/Documentation/ioctl/ioctl-number.txt > +++ b/Documentation/ioctl/ioctl-number.txt > @@ -166,7 +166,7 @@ Code Seq#(hex) Include File Comments > 'P' all linux/soundcard.h conflict! > 'P' 60-6F sound/sscape_ioctl.h conflict! > 'P' 00-0F drivers/usb/class/usblp.c conflict! > -'P' 01-07 drivers/misc/pci_endpoint_test.c conflict! > +'P' 01-09 drivers/misc/pci_endpoint_test.c conflict! > 'Q' all linux/soundcard.h > 'R' 00-1F linux/random.h conflict! > 'R' 01 linux/rfkill.h conflict! > 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 2b58887..82fa0c2 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; This should be added just before return in this function. Thanks Kishon