Received: by 10.192.165.148 with SMTP id m20csp4726554imm; Tue, 24 Apr 2018 07:30:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx48wyvKwePBwuUzZfiwXBgkLzdzeCSVkvVJKhfiZytkh6cQyqwB1DHQv8iwVPFSTtT+9Oz+6 X-Received: by 10.101.98.90 with SMTP id q26mr20762429pgv.113.1524580212226; Tue, 24 Apr 2018 07:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524580212; cv=none; d=google.com; s=arc-20160816; b=uzSs6k4Gtbp3366TWk8ilnGBSpeUk0hqiBGMP1jhWRPQk5UBErkXRNG4tzbv0v188D LOBbQuD1y9h/qXdEZ47LEbSaidhPMiQxtHpQ4eoEuz9ZU0oSSx7gYDy+Zuwo/cB78fTN waAdsmBVJuVtjG5D4Nyb2dXVMp8UtLxR+vxYU3ObjoXey4K5axx7iA8dQO4/vQ06RH5t oidh3eItwDsDsoyBqtUWVlNAE1e/EA2/24E5CYPe0SPGOZOAq1um7SVy1BnQqUoxE3nB YNu2W8tDxyKPC39ljJKpmsxYYu3FKZaDLAY5Mvt1hBo5ixyEWW7tbh6cFicsHSk1ivoW a7ow== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=P/Ex26vJLdWwNJgf5HCIl44pifqGNGfYsU7/VUnKxZo=; b=fhTEQjRQlU+edQiCNnAjBrHnbkrhndXsyf0ApM1AS/AqUBlhFdAWWjvTCGWlvuE07E SWBFheIJOBDyz/fOnH1vxI1d45KNroTyk3tLZdfcmClPs4D72Flnh7aaEWW2NXBYvfNk l/0hjPgGXOcZg5ud9lOfIINBaC8jQTkusNqZD5RX6cAocFai00Ak5w1Qap93rGUu5+MP aacOHSvsqEbCTa7vay7t4UP/6DHpNIG4tONtAKxGKRdwyxzHWeyueoQhcr0xNaNqm9SG 9JrgSXmq5ZH5p18JhH0UkV9R9WK22tUOTik56LK2GE24ok9JJU9Ko0uLsVsdQnTfBrXK Neug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=l02dyPpv; 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 a5-v6si13319743pla.117.2018.04.24.07.29.57; Tue, 24 Apr 2018 07:30:12 -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=l02dyPpv; 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 S1756899AbeDXLND (ORCPT + 99 others); Tue, 24 Apr 2018 07:13:03 -0400 Received: from smtprelay6.synopsys.com ([198.182.37.59]:48972 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754626AbeDXLNB (ORCPT ); Tue, 24 Apr 2018 07:13:01 -0400 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id CD6431E05E7; Tue, 24 Apr 2018 13:12:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1524568380; bh=4x/RlYv/v/dH+im7o0ph4Y2bGgG4nd5k2zJf1wTZLz0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=l02dyPpvnmbzd15qQfkFjiLfl4zgy8vsMZpUBPmIPzTJamddLAY4QrfgKm2HFExt4 wfN5jwzLcV0wPvTshFDLnhnlhKGfW7qa5knHHYPlQJg849q3vtBekYtbhmQ8sP9ZX3 tvLLsb/lSSwO5gVbyf5f5gICt2XJwtw6mLT0eRo9+HnaAt9aKOGt7/EtWeCbQYV+YS coEBA9+e7hOKMTVxtxMgot4iEex+pHJSCOMbgJbuym4h1dCSiqZVwBUiaNlHS0aGSS qgWdSdFKnwetIqNCJiecvZYShVKvqTZPXpiyfgGQtfA5QjBm5iWDpXkNVKbzxsNjPH 03DCAjGJL+Ixg== Received: from pt02.synopsys.com (pt02.internal.synopsys.com [10.107.23.240]) by mailhost.synopsys.com (Postfix) with ESMTP id A5A4E3AF7; Tue, 24 Apr 2018 04:12:58 -0700 (PDT) Received: from [127.0.0.1] (gustavo-e7480.internal.synopsys.com [10.107.25.102]) by pt02.synopsys.com (Postfix) with ESMTP id C9EEE3ED1E; Tue, 24 Apr 2018 12:12:57 +0100 (WEST) Subject: Re: [RFC 06/10] misc: pci_endpoint_test: Add MSI-X support To: Alan Douglas , "bhelgaas@google.com" , "lorenzo.pieralisi@arm.com" , "Joao.Pinto@synopsys.com" , "jingoohan1@gmail.com" , "kishon@ti.com" , "jesper.nilsson@axis.com" Cc: "linux-pci@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <8b88f8c2b766f36c71659deb0fce635154b2b39f.1523379766.git.gustavo.pimentel@synopsys.com> From: Gustavo Pimentel Message-ID: <237066ef-6049-6f10-698b-9d9878b72291@synopsys.com> Date: Tue, 24 Apr 2018 12:11:49 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alan, On 24/04/2018 07:59, Alan Douglas wrote: > Hi Gustavo, > > On 10 April 2018 18:15 Gustavo Pimentel wrote: >> >> Adds the MSI-X support and updates driver documentation accordingly. >> >> Changes the driver parameter in order to allow the interruption type >> selection. >> >> Signed-off-by: Gustavo Pimentel >> --- >> Documentation/misc-devices/pci-endpoint-test.txt | 3 + >> drivers/misc/pci_endpoint_test.c | 102 +++++++++++++++++------ >> 2 files changed, 79 insertions(+), 26 deletions(-) >> >> diff --git a/Documentation/misc-devices/pci-endpoint-test.txt >> b/Documentation/misc-devices/pci-endpoint-test.txt >> index 4ebc359..fdfa0f6 100644 >> --- a/Documentation/misc-devices/pci-endpoint-test.txt >> +++ b/Documentation/misc-devices/pci-endpoint-test.txt >> @@ -10,6 +10,7 @@ The PCI driver for the test device performs the >> following tests >> *) verifying addresses programmed in BAR >> *) raise legacy IRQ >> *) raise MSI IRQ >> + *) raise MSI-X IRQ >> *) read data >> *) write data >> *) copy data >> @@ -25,6 +26,8 @@ ioctl >> PCITEST_LEGACY_IRQ: Tests legacy IRQ >> PCITEST_MSI: Tests message signalled interrupts. The MSI number >> 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_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 37db0fc..a7d9354 100644 >> --- a/drivers/misc/pci_endpoint_test.c >> +++ b/drivers/misc/pci_endpoint_test.c >> @@ -42,11 +42,16 @@ >> #define PCI_ENDPOINT_TEST_COMMAND 0x4 >> #define COMMAND_RAISE_LEGACY_IRQ BIT(0) >> #define COMMAND_RAISE_MSI_IRQ BIT(1) >> -#define MSI_NUMBER_SHIFT 2 >> -/* 6 bits for MSI number */ >> -#define COMMAND_READ BIT(8) >> -#define COMMAND_WRITE BIT(9) >> -#define COMMAND_COPY BIT(10) >> +#define COMMAND_RAISE_MSIX_IRQ BIT(2) >> +#define IRQ_TYPE_SHIFT 3 >> +#define IRQ_TYPE_LEGACY 0 >> +#define IRQ_TYPE_MSI 1 >> +#define IRQ_TYPE_MSIX 2 >> +#define MSI_NUMBER_SHIFT 5 >> +/* 12 bits for MSI number */ >> +#define COMMAND_READ BIT(17) >> +#define COMMAND_WRITE BIT(18) >> +#define COMMAND_COPY BIT(19) >> >> #define PCI_ENDPOINT_TEST_STATUS 0x8 >> #define STATUS_READ_SUCCESS BIT(0) >> @@ -73,9 +78,9 @@ static DEFINE_IDA(pci_endpoint_test_ida); >> #define to_endpoint_test(priv) container_of((priv), struct pci_endpoint_test, >> \ >> miscdev) >> >> -static bool no_msi; >> -module_param(no_msi, bool, 0444); >> -MODULE_PARM_DESC(no_msi, "Disable MSI interrupt in >> pci_endpoint_test"); >> +static int irq_type = IRQ_TYPE_MSIX; >> +module_param(irq_type, int, 0444); >> +MODULE_PARM_DESC(irq_type, "IRQ mode selection in pci_endpoint_test >> (0 >> +- Legacy, 1 - MSI, 2 - MSI-X)"); >> >> enum pci_barno { >> BAR_0, >> @@ -103,7 +108,7 @@ struct pci_endpoint_test { struct >> pci_endpoint_test_data { >> enum pci_barno test_reg_bar; >> size_t alignment; >> - bool no_msi; >> + int irq_type; >> }; >> >> static inline u32 pci_endpoint_test_readl(struct pci_endpoint_test *test, >> @@ -177,10 +182,10 @@ static bool pci_endpoint_test_bar(struct >> pci_endpoint_test *test, >> >> static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test) { >> - u32 val; >> + u32 val = COMMAND_RAISE_LEGACY_IRQ; >> >> - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, >> - COMMAND_RAISE_LEGACY_IRQ); >> + val |= (IRQ_TYPE_LEGACY << IRQ_TYPE_SHIFT); >> + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, val); >> val = wait_for_completion_timeout(&test->irq_raised, >> msecs_to_jiffies(1000)); >> if (!val) >> @@ -192,12 +197,12 @@ static bool pci_endpoint_test_legacy_irq(struct >> pci_endpoint_test *test) static bool pci_endpoint_test_msi_irq(struct >> pci_endpoint_test *test, >> u8 msi_num) >> { >> - u32 val; >> + u32 val = COMMAND_RAISE_MSI_IRQ; >> struct pci_dev *pdev = test->pdev; >> >> - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, >> - msi_num << MSI_NUMBER_SHIFT | >> - COMMAND_RAISE_MSI_IRQ); >> + val |= (msi_num << MSI_NUMBER_SHIFT); >> + val |= (IRQ_TYPE_MSI << IRQ_TYPE_SHIFT); >> + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, val); >> val = wait_for_completion_timeout(&test->irq_raised, >> msecs_to_jiffies(1000)); >> if (!val) >> @@ -209,6 +214,26 @@ static bool pci_endpoint_test_msi_irq(struct >> pci_endpoint_test *test, >> return false; >> } >> >> +static bool pci_endpoint_test_msix_irq(struct pci_endpoint_test *test, >> + u16 msix_num) >> +{ >> + u32 val = COMMAND_RAISE_MSIX_IRQ; >> + struct pci_dev *pdev = test->pdev; >> + >> + val |= (msix_num << MSI_NUMBER_SHIFT); >> + val |= (IRQ_TYPE_MSIX << IRQ_TYPE_SHIFT); >> + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, val); >> + val = wait_for_completion_timeout(&test->irq_raised, >> + msecs_to_jiffies(1000)); >> + if (!val) >> + return false; >> + >> + if (test->last_irq - pdev->irq == msix_num - 1) >> + return true; > I think we should use pci_irq_vector() to convert from device vector to Linux IRQ. > It can be done in pci_endpoint_test_irqhandler() > (With MSI, pdev->irq will be updated during MSI init, but it is not for MSI-X.) > > pci_irq_vector() should also be used for devm_request_irq() and devm_free_irq() > so some changes required in probe and remove. We could try it, sounds good. Let's see if Kishon also agrees. > > Regards, > Alan > Regards, Gustavo