From patchwork Wed Mar 8 09:03:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13165473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9746CC6FD1F for ; Wed, 8 Mar 2023 09:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbjCHJEg (ORCPT ); Wed, 8 Mar 2023 04:04:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjCHJEc (ORCPT ); Wed, 8 Mar 2023 04:04:32 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C82CB13DD3 for ; Wed, 8 Mar 2023 01:04:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266267; x=1709802267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fRrs/340bIvCq/+Ph+3JgCm2ZB+BGr+A5wzPz1zbALc=; b=OoGQBym/+oMsffsQTgAHrPvmCV4KDc6RZ57MXePHH5J4FnbAvDLKHdwT MkYpwXRL+Zy2h8mDwBWG7oWsJyc2mDSYqSkYiXDutakF30d8wAk/DIQ27 NnEWg4Vh5quZZe1QGulFOJ+g4SkJJTxzrfhPNuvdlhzPurmiVkxYHp3we ZpACC+qWlv42nesUc/HUvLlKbZonELN+tSzXr/czRFFf0bznaqoaZPQJQ zjW8YNxwPu/crq+KZCDRv4iH5g9JjGVZhRiONzwL9e6AXGG1bt2QovDch CPDeZCLhWvHGiZLpOWo2EDRyHOFmVUCUvLX4ABEw41WpCtBQ1L3C0WEKN A==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880561" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:32 +0800 IronPort-SDR: jPqAhkaJRSWnTCapLbCw8wk55UDCemJIHknk78p5xE/ULmEa4CvFkPVWUhN9vktTodMgGhDArr iPXhSsaZ2yqePuGsYOPl0r9NJt8SHRHm1MT/J5CxWx94JkC8EHMJUFPrhU96PXRTBLffIg4ZOZ e78HGv7rGIHNQ8ZFI2vvAvTj8G1baAhYBD/Imm1kKikeq7/zB2F4B3oidC3hzGQzqi7AUABGBB 4C4oqysKLncSJTywpqTS9O3KCvJZLIv/1ZZWhMNTqWVwRKt6cfHn6V5usbtEaNyALvsVidBAoS ap0= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:29 -0800 IronPort-SDR: QC3TpMyI/W/Pe8/cbX8QVeKXoQNBNlYc8sbawRDxTf339giMLGskFD1MvkereqT9O2H2rMfDQy 9kPXbQHqwVMaHINZYwWUQ5Wk/SM1+RHdWCAGrTDzTVat0wd3AYqRzntz72/3E0DFEw85n/roqV FgjtHtC2LLM5OYeqzSRYHBG7qZVnttf/ewbEwq1w+wIQh4JQfMBL72ztIvxNiQrwEXF67cp9E1 ofiPJ9bP4Q5E2NdG/73JIa+2A4v2jPpx6Nq+gjWSKEbKipsp5gQmuQGWB366KNMSMGpcy7tZ4B aX4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:33 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZD1Xqqz1Rwtl for ; Wed, 8 Mar 2023 01:03:32 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266211; x=1680858212; bh=fRrs/340bIvCq/+Ph+ 3JgCm2ZB+BGr+A5wzPz1zbALc=; b=LLDOb8s2b++pJl0bnRKn+tF68bwafaFH2B g2cYOQw45lwDb+usErfnkYgbNLrDwza0oTI0mbVBzDDwQKP4Iv1ui83Arxkw4Qiw LZwxpF9+dpGKSNLob6i7eUvqTjHWyp4Xqu3LkHr8m3mBhOfihkR9k9OZ/NiHeDKb i5XETXWPCZyE8pjxl6c1z2+dN9f+ljXuuzYljSH8RRQypc+6tn4qCO7fpOSyoq8R 6SH8CXmLHy6rdmHHUJWrmtqQaQiqu4r32b+CuYpknRd2uKvuL2nFBwd8+a+eQpMx rLD2Jh7jp/9uxU5WM5m32HQx58bawZ+rrw2UxUfKZSD9np50qeIQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xs_yrhurhnjG for ; Wed, 8 Mar 2023 01:03:31 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZ95dgHz1RvLy; Wed, 8 Mar 2023 01:03:29 -0800 (PST) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v2 08/16] PCI: epf-test: Simplify IRQ test commands execution Date: Wed, 8 Mar 2023 18:03:05 +0900 Message-Id: <20230308090313.1653-9-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org For the commands COMMAND_RAISE_LEGACY_IRQ, COMMAND_RAISE_MSI_IRQ and COMMAND_RAISE_MSIX_IRQ, the function pci_epf_test_cmd_handler() sets the STATUS_IRQ_RAISED status flag and calls the epc function pci_epc_raise_irq() directly. However, this is also exactly what the pci_epf_test_raise_irq() function does. Avoid duplicating these operations by directly using pci_epf_test_raise_irq() for the IRQ test commands. It is OK to do so as the host side endpoint test driver always set the correct irq type for the IRQ test commands. At the same time, the irq number check done for the COMMAND_RAISE_MSI_IRQ and COMMAND_RAISE_MSIX_IRQ commands can also be moved to pci_epf_test_raise_irq() to also check the IRQ number requested by the host for other test commands. Overall, this significantly simplifies the pci_epf_test_cmd_handler() function. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 6f4ef5251452..43d623682850 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -615,6 +615,7 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; + int count; reg->status |= STATUS_IRQ_RAISED; @@ -624,10 +625,22 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, PCI_EPC_IRQ_LEGACY, 0); break; case IRQ_TYPE_MSI: + count = pci_epc_get_msi(epc, epf->func_no, epf->vfunc_no); + if (reg->irq_number > count || count <= 0) { + dev_err(dev, "Invalid MSI IRQ number %d / %d\n", + reg->irq_number, count); + return; + } pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_MSI, reg->irq_number); break; case IRQ_TYPE_MSIX: + count = pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no); + if (reg->irq_number > count || count <= 0) { + dev_err(dev, "Invalid MSIX IRQ number %d / %d\n", + reg->irq_number, count); + return; + } pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_MSIX, reg->irq_number); break; @@ -640,13 +653,11 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, static void pci_epf_test_cmd_handler(struct work_struct *work) { int ret; - int count; u32 command; struct pci_epf_test *epf_test = container_of(work, struct pci_epf_test, cmd_handler.work); struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; - struct pci_epc *epc = epf->epc; enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; @@ -662,10 +673,10 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) goto reset_handler; } - if (command & COMMAND_RAISE_LEGACY_IRQ) { - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_LEGACY, 0); + if ((command & COMMAND_RAISE_LEGACY_IRQ) || + (command & COMMAND_RAISE_MSI_IRQ) || + (command & COMMAND_RAISE_MSIX_IRQ)) { + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } @@ -699,26 +710,6 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) goto reset_handler; } - if (command & COMMAND_RAISE_MSI_IRQ) { - count = pci_epc_get_msi(epc, epf->func_no, epf->vfunc_no); - if (reg->irq_number > count || count <= 0) - goto reset_handler; - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSI, reg->irq_number); - goto reset_handler; - } - - if (command & COMMAND_RAISE_MSIX_IRQ) { - count = pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no); - if (reg->irq_number > count || count <= 0) - goto reset_handler; - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSIX, reg->irq_number); - goto reset_handler; - } - reset_handler: queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, msecs_to_jiffies(1));