From nobody Sun May 10 06:04:44 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F1B019D88F for ; Tue, 31 Dec 2024 13:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735650847; cv=none; b=pSH+lgQ+ksL1Hk2MX7Cz/5cvUpRCzh3ixJg6P8h6ensdPRo/Q6RBwP+ts4XmXzThsiSvDj3QOB6Hb1CRCbFhbycBN9pcSvqm7HlLwyy0pLkZpH0RWhqjeLAP6Q9UZdvkvA1qphw1ruwSP1kwZT14huIxzWyFmf8iohtRUORnMLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735650847; c=relaxed/simple; bh=U3HDpSOkIyj5jf5LHiGBdv7xQlti5+az5Yogwm2eR8U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BpIpEhAC200Eg1i+DrxHqUdSGj2yORwwEpyXdirUBIvMOZg8Cm9JaX194HIPumsTcaJTeQOd99JOlkklftB2sjyOR1ll+iVqQ0WnC5WKztOKZEUvH/ulAOdC+rjl9vaC2eNXdz0c+rC3DuPp/hlj7Awrt0ADpCNOrbzGFNikR5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=gQOiYo0m; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gQOiYo0m" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2162c0f6a39so141180265ad.0 for ; Tue, 31 Dec 2024 05:14:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735650845; x=1736255645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9rcGi5mP1INqcgXesezoYqLasiWddJIAK3AnibkerbU=; b=gQOiYo0mGlAJUWYitBjAAndg7eaL2DLgaSjjxd8WZP5FPYVhvKZrY22E6vSO0WcO9H 8o/cDOs879hVEGLT9BGYlhB/imUSxSq0hEoPJ/UI40Aaw/HckrwOIoZzDwWU6HIPnCK+ /5bTrjYJE3bSlbjFTn0YF1VcGb16xMbRz4H20oTu90rBhQsIMSHUmXsyhT10T7QoOBhi zI7Hqx97zcCHnWgd+Tw5JpbEkAqNmyXcRWvcInbowmxGYqiBIiN+cs4nwLlQQeshl+BU 6QifgnAulAi9kOmexslJ12eKSm5XdanhTehUMmcc5VUoT9S9NHCDQEpmgo40NQJKBRIa XM3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735650845; x=1736255645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9rcGi5mP1INqcgXesezoYqLasiWddJIAK3AnibkerbU=; b=Eg2je6G4sshQW7qw3pVzV/o48XcVYO2IrrENH4A0SwtSVImj258EECdUQtXiw+N/mp hkFinnQCmMWj/ud2A/SwCcEJNrtqoJtcslW+XBdJO62DvjSwbOciX8GoOjmgYVWxbUjG 7bk00AndJLmvambZBKpuCZ0SDaqQ6jAEEgqfqT0Yd+Srufg3b2pM6mjwb5EAtoajGAVc 9lvwnVKf718b+HkBbYz6kAJ4zqRMMoQm7kYgETtRuEt3P8ZJ8WyERpPcgjcG0bvD4w/Q bqhgiyyLtyAW3+yKUoFUpgHkwj9H3w5aBwKG9us1Tmxgp4kWCiz5gVGLrr0ufujrZhmc r9hA== X-Forwarded-Encrypted: i=1; AJvYcCUcJ083ognFnX6u83q1wx5KO+WTT7Q+0hpHcH7tAG5de//GKp3he67Shb4u+wI68X2a+XVZa7WUG6H46O4=@vger.kernel.org X-Gm-Message-State: AOJu0YxRgj2ky39qX95VvWHv+urVOj6Khcqf9h4awTArwYg1YnwvFgkl 7ZZ2hw6CuFG1gsAucZ1WmUgrWoLXQqiKmnZ0Xbyk7sBJNhGnzuPCvWTiCaIj8g== X-Gm-Gg: ASbGncthC85jlAGUcJMNDN9zYNv2whJyj42VUc14ALrG8vM30ArYsSS7aC0wFVzB/Y+ vH+m1vS0NWHre28Eg8hcUX1gvVJTa0uKl+gO+HIaefdfaCplnSJIm8b+JtvHFGMlByY49lgZKo2 Tku01fUkEG6t8UTwJ898+Bi87Y4lAjY3QrEIFU+Edx25jo6Jn40AMROWn6P4NVEv3l6+HdN09DH LsUv1haL7FFubrBGHo/OjswRK8XRQ6N6TL5xJnI2zfwsSEEuLr6hBxNFegm64RSDBIvRO9+R/7L kEfYGyU/yco= X-Google-Smtp-Source: AGHT+IEGf9S1NGUPbJuY2+vQG7UeSYriIH5ounufSgRn6Etu3fZUfal1eLIkxsDfxcmUiJvk/0NNKw== X-Received: by 2002:a05:6a20:8412:b0:1e0:c166:18ba with SMTP id adf61e73a8af0-1e5e1e74cf8mr54825008637.12.1735650844755; Tue, 31 Dec 2024 05:14:04 -0800 (PST) Received: from localhost.localdomain ([117.193.213.202]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad6cc885sm20994862b3a.0.2024.12.31.05.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 05:14:04 -0800 (PST) From: Manivannan Sadhasivam To: kw@linux.com, gregkh@linuxfoundation.org, arnd@arndb.de, lpieralisi@kernel.org, shuah@kernel.org Cc: kishon@kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, bhelgaas@google.com, linux-arm-msm@vger.kernel.org, robh@kernel.org, linux-kselftest@vger.kernel.org, Manivannan Sadhasivam , Damien Le Moal Subject: [PATCH v4 1/3] misc: pci_endpoint_test: Fix the return value of IOCTL Date: Tue, 31 Dec 2024 18:43:39 +0530 Message-Id: <20241231131341.39292-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241231131341.39292-1-manivannan.sadhasivam@linaro.org> References: <20241231131341.39292-1-manivannan.sadhasivam@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" IOCTLs are supposed to return 0 for success and negative error codes for failure. Currently, this driver is returning 0 for failure and 1 for success, that's not correct. Hence, fix it! Reported-by: Greg Kroah-Hartman Closes: https://lore.kernel.org/all/YvzNg5ROnxEApDgS@kroah.com Fixes: 2c156ac71c6b ("misc: Add host side PCI driver for PCI test function = device") Reviewed-by: Damien Le Moal Signed-off-by: Manivannan Sadhasivam Reviewed-by: Niklas Cassel --- drivers/misc/pci_endpoint_test.c | 250 +++++++++++++++---------------- tools/pci/pcitest.c | 51 +++---- 2 files changed, 148 insertions(+), 153 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_t= est.c index 5c99da952b7a..7d3f78b6f854 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -169,43 +169,47 @@ static void pci_endpoint_test_free_irq_vectors(struct= pci_endpoint_test *test) test->irq_type =3D IRQ_TYPE_UNDEFINED; } =20 -static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *= test, +static int pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *t= est, int type) { - int irq =3D -1; + int irq; struct pci_dev *pdev =3D test->pdev; struct device *dev =3D &pdev->dev; - bool res =3D true; =20 switch (type) { case IRQ_TYPE_INTX: irq =3D pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_INTX); - if (irq < 0) + if (irq < 0) { dev_err(dev, "Failed to get Legacy interrupt\n"); + return -ENOSPC; + } + break; case IRQ_TYPE_MSI: irq =3D pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI); - if (irq < 0) + if (irq < 0) { dev_err(dev, "Failed to get MSI interrupts\n"); + return -ENOSPC; + } + break; case IRQ_TYPE_MSIX: irq =3D pci_alloc_irq_vectors(pdev, 1, 2048, PCI_IRQ_MSIX); - if (irq < 0) + if (irq < 0) { dev_err(dev, "Failed to get MSI-X interrupts\n"); + return -ENOSPC; + } + break; default: dev_err(dev, "Invalid IRQ type selected\n"); - } - - if (irq < 0) { - irq =3D 0; - res =3D false; + return -EINVAL; } =20 test->irq_type =3D type; test->num_irqs =3D irq; =20 - return res; + return 0; } =20 static void pci_endpoint_test_release_irq(struct pci_endpoint_test *test) @@ -220,22 +224,22 @@ static void pci_endpoint_test_release_irq(struct pci_= endpoint_test *test) test->num_irqs =3D 0; } =20 -static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test) +static int pci_endpoint_test_request_irq(struct pci_endpoint_test *test) { int i; - int err; + int ret; struct pci_dev *pdev =3D test->pdev; struct device *dev =3D &pdev->dev; =20 for (i =3D 0; i < test->num_irqs; i++) { - err =3D devm_request_irq(dev, pci_irq_vector(pdev, i), + ret =3D devm_request_irq(dev, pci_irq_vector(pdev, i), pci_endpoint_test_irqhandler, IRQF_SHARED, test->name, test); - if (err) + if (ret) goto fail; } =20 - return true; + return 0; =20 fail: switch (irq_type) { @@ -255,7 +259,7 @@ static bool pci_endpoint_test_request_irq(struct pci_en= dpoint_test *test) break; } =20 - return false; + return ret; } =20 static const u32 bar_test_pattern[] =3D { @@ -280,7 +284,7 @@ static int pci_endpoint_test_bar_memcmp(struct pci_endp= oint_test *test, return memcmp(write_buf, read_buf, size); } =20 -static bool pci_endpoint_test_bar(struct pci_endpoint_test *test, +static int pci_endpoint_test_bar(struct pci_endpoint_test *test, enum pci_barno barno) { int j, bar_size, buf_size, iters, remain; @@ -289,7 +293,7 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_t= est *test, struct pci_dev *pdev =3D test->pdev; =20 if (!test->bar[barno]) - return false; + return -ENOMEM; =20 bar_size =3D pci_resource_len(pdev, barno); =20 @@ -304,25 +308,25 @@ static bool pci_endpoint_test_bar(struct pci_endpoint= _test *test, =20 write_buf =3D kmalloc(buf_size, GFP_KERNEL); if (!write_buf) - return false; + return -ENOMEM; =20 read_buf =3D kmalloc(buf_size, GFP_KERNEL); if (!read_buf) - return false; + return -ENOMEM; =20 iters =3D bar_size / buf_size; for (j =3D 0; j < iters; j++) if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * j, write_buf, read_buf, buf_size)) - return false; + return -EIO; =20 remain =3D bar_size % buf_size; if (remain) if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * iters, write_buf, read_buf, remain)) - return false; + return -EIO; =20 - return true; + return 0; } =20 static u32 bar_test_pattern_with_offset(enum pci_barno barno, int offset) @@ -337,7 +341,7 @@ static u32 bar_test_pattern_with_offset(enum pci_barno = barno, int offset) return val; } =20 -static bool pci_endpoint_test_bars_write_bar(struct pci_endpoint_test *tes= t, +static void pci_endpoint_test_bars_write_bar(struct pci_endpoint_test *tes= t, enum pci_barno barno) { struct pci_dev *pdev =3D test->pdev; @@ -351,11 +355,9 @@ static bool pci_endpoint_test_bars_write_bar(struct pc= i_endpoint_test *test, for (j =3D 0; j < size; j +=3D 4) writel_relaxed(bar_test_pattern_with_offset(barno, j), test->bar[barno] + j); - - return true; } =20 -static bool pci_endpoint_test_bars_read_bar(struct pci_endpoint_test *test, +static int pci_endpoint_test_bars_read_bar(struct pci_endpoint_test *test, enum pci_barno barno) { struct pci_dev *pdev =3D test->pdev; @@ -376,14 +378,14 @@ static bool pci_endpoint_test_bars_read_bar(struct pc= i_endpoint_test *test, dev_err(dev, "BAR%d incorrect data at offset: %#x, got: %#x expected: %#x\n", barno, j, val, expected); - return false; + return -EIO; } } =20 - return true; + return 0; } =20 -static bool pci_endpoint_test_bars(struct pci_endpoint_test *test) +static int pci_endpoint_test_bars(struct pci_endpoint_test *test) { enum pci_barno bar; bool ret; @@ -407,10 +409,10 @@ static bool pci_endpoint_test_bars(struct pci_endpoin= t_test *test) } } =20 - return true; + return 0; } =20 -static bool pci_endpoint_test_intx_irq(struct pci_endpoint_test *test) +static int pci_endpoint_test_intx_irq(struct pci_endpoint_test *test) { u32 val; =20 @@ -422,12 +424,12 @@ static bool pci_endpoint_test_intx_irq(struct pci_end= point_test *test) val =3D wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); if (!val) - return false; + return -ETIMEDOUT; =20 - return true; + return 0; } =20 -static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, +static int pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, u16 msi_num, bool msix) { u32 val; @@ -442,9 +444,12 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpo= int_test *test, val =3D wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); if (!val) - return false; + return -ETIMEDOUT; =20 - return pci_irq_vector(pdev, msi_num - 1) =3D=3D test->last_irq; + if (!(pci_irq_vector(pdev, msi_num - 1) =3D=3D test->last_irq)) + return -EIO; + + return 0; } =20 static int pci_endpoint_test_validate_xfer_params(struct device *dev, @@ -463,11 +468,10 @@ static int pci_endpoint_test_validate_xfer_params(str= uct device *dev, return 0; } =20 -static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, +static int pci_endpoint_test_copy(struct pci_endpoint_test *test, unsigned long arg) { struct pci_endpoint_test_xfer_param param; - bool ret =3D false; void *src_addr; void *dst_addr; u32 flags =3D 0; @@ -486,17 +490,17 @@ static bool pci_endpoint_test_copy(struct pci_endpoin= t_test *test, int irq_type =3D test->irq_type; u32 src_crc32; u32 dst_crc32; - int err; + int ret; =20 - err =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); - if (err) { + ret =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); + if (ret) { dev_err(dev, "Failed to get transfer param\n"); - return false; + return -EFAULT; } =20 - err =3D pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); - if (err) - return false; + ret =3D pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); + if (ret) + return ret; =20 size =3D param.size; =20 @@ -506,22 +510,21 @@ static bool pci_endpoint_test_copy(struct pci_endpoin= t_test *test, =20 if (irq_type < IRQ_TYPE_INTX || irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Invalid IRQ type option\n"); - goto err; + return -EINVAL; } =20 orig_src_addr =3D kzalloc(size + alignment, GFP_KERNEL); if (!orig_src_addr) { dev_err(dev, "Failed to allocate source buffer\n"); - ret =3D false; - goto err; + return -ENOMEM; } =20 get_random_bytes(orig_src_addr, size + alignment); orig_src_phys_addr =3D dma_map_single(dev, orig_src_addr, size + alignment, DMA_TO_DEVICE); - if (dma_mapping_error(dev, orig_src_phys_addr)) { + ret =3D dma_mapping_error(dev, orig_src_phys_addr); + if (ret) { dev_err(dev, "failed to map source buffer address\n"); - ret =3D false; goto err_src_phys_addr; } =20 @@ -545,15 +548,15 @@ static bool pci_endpoint_test_copy(struct pci_endpoin= t_test *test, orig_dst_addr =3D kzalloc(size + alignment, GFP_KERNEL); if (!orig_dst_addr) { dev_err(dev, "Failed to allocate destination address\n"); - ret =3D false; + ret =3D -ENOMEM; goto err_dst_addr; } =20 orig_dst_phys_addr =3D dma_map_single(dev, orig_dst_addr, size + alignment, DMA_FROM_DEVICE); - if (dma_mapping_error(dev, orig_dst_phys_addr)) { + ret =3D dma_mapping_error(dev, orig_dst_phys_addr); + if (ret) { dev_err(dev, "failed to map destination buffer address\n"); - ret =3D false; goto err_dst_phys_addr; } =20 @@ -586,8 +589,8 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_= test *test, DMA_FROM_DEVICE); =20 dst_crc32 =3D crc32_le(~0, dst_addr, size); - if (dst_crc32 =3D=3D src_crc32) - ret =3D true; + if (dst_crc32 !=3D src_crc32) + ret =3D -EIO; =20 err_dst_phys_addr: kfree(orig_dst_addr); @@ -598,16 +601,13 @@ static bool pci_endpoint_test_copy(struct pci_endpoin= t_test *test, =20 err_src_phys_addr: kfree(orig_src_addr); - -err: return ret; } =20 -static bool pci_endpoint_test_write(struct pci_endpoint_test *test, +static int pci_endpoint_test_write(struct pci_endpoint_test *test, unsigned long arg) { struct pci_endpoint_test_xfer_param param; - bool ret =3D false; u32 flags =3D 0; bool use_dma; u32 reg; @@ -622,17 +622,17 @@ static bool pci_endpoint_test_write(struct pci_endpoi= nt_test *test, int irq_type =3D test->irq_type; size_t size; u32 crc32; - int err; + int ret; =20 - err =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); - if (err !=3D 0) { + ret =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); + if (ret) { dev_err(dev, "Failed to get transfer param\n"); - return false; + return -EFAULT; } =20 - err =3D pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); - if (err) - return false; + ret =3D pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); + if (ret) + return ret; =20 size =3D param.size; =20 @@ -642,23 +642,22 @@ static bool pci_endpoint_test_write(struct pci_endpoi= nt_test *test, =20 if (irq_type < IRQ_TYPE_INTX || irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Invalid IRQ type option\n"); - goto err; + return -EINVAL; } =20 orig_addr =3D kzalloc(size + alignment, GFP_KERNEL); if (!orig_addr) { dev_err(dev, "Failed to allocate address\n"); - ret =3D false; - goto err; + return -ENOMEM; } =20 get_random_bytes(orig_addr, size + alignment); =20 orig_phys_addr =3D dma_map_single(dev, orig_addr, size + alignment, DMA_TO_DEVICE); - if (dma_mapping_error(dev, orig_phys_addr)) { + ret =3D dma_mapping_error(dev, orig_phys_addr); + if (ret) { dev_err(dev, "failed to map source buffer address\n"); - ret =3D false; goto err_phys_addr; } =20 @@ -691,24 +690,21 @@ static bool pci_endpoint_test_write(struct pci_endpoi= nt_test *test, wait_for_completion(&test->irq_raised); =20 reg =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); - if (reg & STATUS_READ_SUCCESS) - ret =3D true; + if (!(reg & STATUS_READ_SUCCESS)) + ret =3D -EIO; =20 dma_unmap_single(dev, orig_phys_addr, size + alignment, DMA_TO_DEVICE); =20 err_phys_addr: kfree(orig_addr); - -err: return ret; } =20 -static bool pci_endpoint_test_read(struct pci_endpoint_test *test, +static int pci_endpoint_test_read(struct pci_endpoint_test *test, unsigned long arg) { struct pci_endpoint_test_xfer_param param; - bool ret =3D false; u32 flags =3D 0; bool use_dma; size_t size; @@ -722,17 +718,17 @@ static bool pci_endpoint_test_read(struct pci_endpoin= t_test *test, size_t alignment =3D test->alignment; int irq_type =3D test->irq_type; u32 crc32; - int err; + int ret; =20 - err =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); - if (err) { + ret =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); + if (ret) { dev_err(dev, "Failed to get transfer param\n"); - return false; + return -EFAULT; } =20 - err =3D pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); - if (err) - return false; + ret =3D pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); + if (ret) + return ret; =20 size =3D param.size; =20 @@ -742,21 +738,20 @@ static bool pci_endpoint_test_read(struct pci_endpoin= t_test *test, =20 if (irq_type < IRQ_TYPE_INTX || irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Invalid IRQ type option\n"); - goto err; + return -EINVAL; } =20 orig_addr =3D kzalloc(size + alignment, GFP_KERNEL); if (!orig_addr) { dev_err(dev, "Failed to allocate destination address\n"); - ret =3D false; - goto err; + return -ENOMEM; } =20 orig_phys_addr =3D dma_map_single(dev, orig_addr, size + alignment, DMA_FROM_DEVICE); - if (dma_mapping_error(dev, orig_phys_addr)) { + ret =3D dma_mapping_error(dev, orig_phys_addr); + if (ret) { dev_err(dev, "failed to map source buffer address\n"); - ret =3D false; goto err_phys_addr; } =20 @@ -788,50 +783,51 @@ static bool pci_endpoint_test_read(struct pci_endpoin= t_test *test, DMA_FROM_DEVICE); =20 crc32 =3D crc32_le(~0, addr, size); - if (crc32 =3D=3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM= )) - ret =3D true; + if (crc32 !=3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM)) + ret =3D -EIO; =20 err_phys_addr: kfree(orig_addr); -err: return ret; } =20 -static bool pci_endpoint_test_clear_irq(struct pci_endpoint_test *test) +static int pci_endpoint_test_clear_irq(struct pci_endpoint_test *test) { pci_endpoint_test_release_irq(test); pci_endpoint_test_free_irq_vectors(test); - return true; + + return 0; } =20 -static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, +static int pci_endpoint_test_set_irq(struct pci_endpoint_test *test, int req_irq_type) { struct pci_dev *pdev =3D test->pdev; struct device *dev =3D &pdev->dev; + int ret; =20 if (req_irq_type < IRQ_TYPE_INTX || req_irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Invalid IRQ type option\n"); - return false; + return -EINVAL; } =20 if (test->irq_type =3D=3D req_irq_type) - return true; + return 0; =20 pci_endpoint_test_release_irq(test); pci_endpoint_test_free_irq_vectors(test); =20 - if (!pci_endpoint_test_alloc_irq_vectors(test, req_irq_type)) - goto err; + ret =3D pci_endpoint_test_alloc_irq_vectors(test, req_irq_type); + if (ret) + return ret; =20 - if (!pci_endpoint_test_request_irq(test)) - goto err; - - return true; + ret =3D pci_endpoint_test_request_irq(test); + if (ret) { + pci_endpoint_test_free_irq_vectors(test); + return ret; + } =20 -err: - pci_endpoint_test_free_irq_vectors(test); - return false; + return 0; } =20 static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, @@ -913,7 +909,7 @@ static void pci_endpoint_test_get_capabilities(struct p= ci_endpoint_test *test) static int pci_endpoint_test_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { - int err; + int ret; int id; char name[24]; enum pci_barno bar; @@ -952,24 +948,23 @@ static int pci_endpoint_test_probe(struct pci_dev *pd= ev, =20 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)); =20 - err =3D pci_enable_device(pdev); - if (err) { + ret =3D pci_enable_device(pdev); + if (ret) { dev_err(dev, "Cannot enable PCI device\n"); - return err; + return ret; } =20 - err =3D pci_request_regions(pdev, DRV_MODULE_NAME); - if (err) { + ret =3D pci_request_regions(pdev, DRV_MODULE_NAME); + if (ret) { dev_err(dev, "Cannot obtain PCI resources\n"); goto err_disable_pdev; } =20 pci_set_master(pdev); =20 - if (!pci_endpoint_test_alloc_irq_vectors(test, irq_type)) { - err =3D -EINVAL; + ret =3D pci_endpoint_test_alloc_irq_vectors(test, irq_type); + if (ret) goto err_disable_irq; - } =20 for (bar =3D 0; bar < PCI_STD_NUM_BARS; bar++) { if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) { @@ -984,7 +979,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, =20 test->base =3D test->bar[test_reg_bar]; if (!test->base) { - err =3D -ENOMEM; + ret =3D -ENOMEM; dev_err(dev, "Cannot perform PCI test without BAR%d\n", test_reg_bar); goto err_iounmap; @@ -994,7 +989,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, =20 id =3D ida_alloc(&pci_endpoint_test_ida, GFP_KERNEL); if (id < 0) { - err =3D id; + ret =3D id; dev_err(dev, "Unable to get id\n"); goto err_iounmap; } @@ -1002,14 +997,13 @@ static int pci_endpoint_test_probe(struct pci_dev *p= dev, snprintf(name, sizeof(name), DRV_MODULE_NAME ".%d", id); test->name =3D kstrdup(name, GFP_KERNEL); if (!test->name) { - err =3D -ENOMEM; + ret =3D -ENOMEM; goto err_ida_remove; } =20 - if (!pci_endpoint_test_request_irq(test)) { - err =3D -EINVAL; + ret =3D pci_endpoint_test_request_irq(test); + if (ret) goto err_kfree_test_name; - } =20 pci_endpoint_test_get_capabilities(test); =20 @@ -1017,14 +1011,14 @@ static int pci_endpoint_test_probe(struct pci_dev *= pdev, misc_device->minor =3D MISC_DYNAMIC_MINOR; misc_device->name =3D kstrdup(name, GFP_KERNEL); if (!misc_device->name) { - err =3D -ENOMEM; + ret =3D -ENOMEM; goto err_release_irq; } misc_device->parent =3D &pdev->dev; misc_device->fops =3D &pci_endpoint_test_fops; =20 - err =3D misc_register(misc_device); - if (err) { + ret =3D misc_register(misc_device); + if (ret) { dev_err(dev, "Failed to register device\n"); goto err_kfree_name; } @@ -1056,7 +1050,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pd= ev, err_disable_pdev: pci_disable_device(pdev); =20 - return err; + return ret; } =20 static void pci_endpoint_test_remove(struct pci_dev *pdev) diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c index 08f355083754..b96cc118839b 100644 --- a/tools/pci/pcitest.c +++ b/tools/pci/pcitest.c @@ -16,7 +16,6 @@ =20 #include =20 -static char *result[] =3D { "NOT OKAY", "OKAY" }; static char *irq[] =3D { "LEGACY", "MSI", "MSI-X" }; =20 struct pci_test { @@ -53,72 +52,74 @@ static int run_test(struct pci_test *test) ret =3D ioctl(fd, PCITEST_BAR, test->barnum); fprintf(stdout, "BAR%d:\t\t", test->barnum); if (ret < 0) - fprintf(stdout, "TEST FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->consecutive_bar_test) { ret =3D ioctl(fd, PCITEST_BARS); fprintf(stdout, "Consecutive BAR test:\t\t"); if (ret < 0) - fprintf(stdout, "TEST FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->set_irqtype) { ret =3D ioctl(fd, PCITEST_SET_IRQTYPE, test->irqtype); fprintf(stdout, "SET IRQ TYPE TO %s:\t\t", irq[test->irqtype]); if (ret < 0) - fprintf(stdout, "FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->get_irqtype) { ret =3D ioctl(fd, PCITEST_GET_IRQTYPE); fprintf(stdout, "GET IRQ TYPE:\t\t"); - if (ret < 0) - fprintf(stdout, "FAILED\n"); - else + if (ret < 0) { + fprintf(stdout, "NOT OKAY\n"); + } else { fprintf(stdout, "%s\n", irq[ret]); + ret =3D 0; + } } =20 if (test->clear_irq) { ret =3D ioctl(fd, PCITEST_CLEAR_IRQ); fprintf(stdout, "CLEAR IRQ:\t\t"); if (ret < 0) - fprintf(stdout, "FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->legacyirq) { ret =3D ioctl(fd, PCITEST_LEGACY_IRQ, 0); fprintf(stdout, "LEGACY IRQ:\t"); if (ret < 0) - fprintf(stdout, "TEST FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->msinum > 0 && test->msinum <=3D 32) { ret =3D ioctl(fd, PCITEST_MSI, test->msinum); fprintf(stdout, "MSI%u:\t\t", test->msinum); if (ret < 0) - fprintf(stdout, "TEST FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->msixnum > 0 && test->msixnum <=3D 2048) { ret =3D ioctl(fd, PCITEST_MSIX, test->msixnum); fprintf(stdout, "MSI-X%u:\t\t", test->msixnum); if (ret < 0) - fprintf(stdout, "TEST FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->write) { @@ -128,9 +129,9 @@ static int run_test(struct pci_test *test) ret =3D ioctl(fd, PCITEST_WRITE, ¶m); fprintf(stdout, "WRITE (%7lu bytes):\t\t", test->size); if (ret < 0) - fprintf(stdout, "TEST FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->read) { @@ -140,9 +141,9 @@ static int run_test(struct pci_test *test) ret =3D ioctl(fd, PCITEST_READ, ¶m); fprintf(stdout, "READ (%7lu bytes):\t\t", test->size); if (ret < 0) - fprintf(stdout, "TEST FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 if (test->copy) { @@ -152,14 +153,14 @@ static int run_test(struct pci_test *test) ret =3D ioctl(fd, PCITEST_COPY, ¶m); fprintf(stdout, "COPY (%7lu bytes):\t\t", test->size); if (ret < 0) - fprintf(stdout, "TEST FAILED\n"); + fprintf(stdout, "NOT OKAY\n"); else - fprintf(stdout, "%s\n", result[ret]); + fprintf(stdout, "OKAY\n"); } =20 fflush(stdout); close(fd); - return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ + return ret; } =20 int main(int argc, char **argv) --=20 2.25.1 From nobody Sun May 10 06:04:44 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2996E19EED3 for ; Tue, 31 Dec 2024 13:14:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735650852; cv=none; b=Q9nR3V0ryjYv82MGzLlX7HhTd4xsTCE2pGaF8YCDsBPNVV5mXRPwIgix1ZGQwUSzQvoKltANTsW1zOszQt0MjtanE5bywDezULXOhq2aEES+rao+xq3H4Pc6A3w3JnhbBwV0l/DTFnBTJ7PRqKwOFdMQbdJFG/2Z9hmroVDTum0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735650852; c=relaxed/simple; bh=v8whFl/jk7+v9u73VH0q13g2zK6IQeJsS/9Wvy4ZCpA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H37JMBp6P6Eev8Q6yNuUyFJDV4JzNh+L4Oo2Uv4maieacjc/tA7JocqJPMLaW0wpXPR6vaNBeoRijUhn1xZKH82DtCUEW1fTvg2kf1BB5CStbPrhe3EHFPGiJZUL1hUlcxRrggNDik3qkew6EWdH9c00w3mrOhgK1LhSc9GsL+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=iZPkARi5; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="iZPkARi5" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-216281bc30fso153142555ad.0 for ; Tue, 31 Dec 2024 05:14:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735650849; x=1736255649; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xa1jN/asG74sjrgB8hwyWegLPzfHxpGYS7ycWDuiTK0=; b=iZPkARi5ILpnlbjIA6sF6rkZRFmUSmelceldXdyim1pBlkmujFr054ET4conjc9LcM jqFL9If4hDJ6C6YLkmHdFrGQKuLbvni14/KfTX58cuVi86lyEK2Wp4RIa1/NG6lusp5e XtvevibR+Dx5SDgH+w7VtLtnsKf6qioMik8av+n3Vcq01lI5QCo96cwS/VyNqPtTpyp3 6LNazUmJ3dk79peWBZG2/yiui8hVJ2ca71JI5mJMmjZyoPBgNKp6GDDpGjhV1C+p3u/L NOn6oyYO73uoF/BXF1K/FyrRC3Hk1qoWdKDUSPNQWuLeJ4vJYba3PbZDLWs/427azYH8 29Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735650849; x=1736255649; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xa1jN/asG74sjrgB8hwyWegLPzfHxpGYS7ycWDuiTK0=; b=E4jr30SBl+xjB94ljyG+ysinho8UAq9Q6gBEuUaI4tTKx9FKbs0FPxEFCxtAEkVa9B MC1cm6HslpEkrAfxHgUp3DjtiLspUVyUUgQ/dXG9NrSbbB3vKi9JNXYPGBYAsJOKr/Ga rQ2UeTIq3BzBReO20BTfg6fdG045RJyIQgHtsEdJn7ced1Kt+AWuhKQODMv0p9rhuvL8 4tNqbHGhgsdxroSA/k1S9HRhGzbmzSJoII5mrvzYGXrhvQ6ylH9vp7CQ1DA0Idhv9hiC IoSJWr3WOTF2SYQXZvGGPH37XgJn46SHCbo08uirbUzagD+qhkxnB1YG1FldSKhqd8lJ hi2w== X-Forwarded-Encrypted: i=1; AJvYcCWMaEytyyivkugPIvVTvjXzOTZkVf6UeQBq/Dwg+H2TpvbOz8cTXgP886bZOyCDdQ70n98jAQwmwhNES7U=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8cU/5VEppyU1e63UrGwxfZ7bfsEt6oT/EFbidqDyMJGU2oKLs Yz5bABcWzIaBtX18LHI886PMUBdkUBy0q/m8DnUeF0EzzvFVCtDnk4tZAClNBg== X-Gm-Gg: ASbGnctzFhJi+r3p85jNanhCMxsQrUxgUr+ys/fd+kIxuGxEKfxWTautG+CEqOk+iUY hP4peOI82WGiKWnIw/ds0oyMcljsYD/fGlTr2NQFiZGvW0xPJEXMvS33WNYFwqDirg2VAWKtFLC 0phOHrIpdueOVEvl0Br68yZe4ESMJPBxbi2kVSoci9tjh7ymubTOztIb7JiE5PDqd7WuATApemT JAfvI/syFAmE9XfE3XWirtmnwEBtkw8zfM8VEM4fSa2D4sd34jVOQueeNFP6V/cZu7a9YO9Ptj+ e1hLnAdcKVk= X-Google-Smtp-Source: AGHT+IGZUa+Nt5saRgpUAg+RSZhQyxrVDXNDUEbMn6mYhhN1yi9azaKToiDiWgeEgiAtKmbQZ/2U4A== X-Received: by 2002:a05:6a00:124a:b0:725:f282:1f04 with SMTP id d2e1a72fcca58-72abde846e5mr55442921b3a.18.1735650849549; Tue, 31 Dec 2024 05:14:09 -0800 (PST) Received: from localhost.localdomain ([117.193.213.202]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad6cc885sm20994862b3a.0.2024.12.31.05.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 05:14:09 -0800 (PST) From: Manivannan Sadhasivam To: kw@linux.com, gregkh@linuxfoundation.org, arnd@arndb.de, lpieralisi@kernel.org, shuah@kernel.org Cc: kishon@kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, bhelgaas@google.com, linux-arm-msm@vger.kernel.org, robh@kernel.org, linux-kselftest@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v4 2/3] selftests: Move PCI Endpoint tests from tools/pci to Kselftests Date: Tue, 31 Dec 2024 18:43:40 +0530 Message-Id: <20241231131341.39292-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241231131341.39292-1-manivannan.sadhasivam@linaro.org> References: <20241231131341.39292-1-manivannan.sadhasivam@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This just moves the existing tests under tools/pci to tools/testing/selftests/pci_endpoint and adjusts the paths in Makefile accordingly. Migration to Kselftest framework will be done in subsequent commits. Signed-off-by: Manivannan Sadhasivam --- Documentation/PCI/endpoint/pci-test-howto.rst | 9 +++++---- MAINTAINERS | 2 +- tools/testing/selftests/pci_endpoint/.gitignore | 3 +++ tools/{pci =3D> testing/selftests/pci_endpoint}/Build | 0 tools/{pci =3D> testing/selftests/pci_endpoint}/Makefile | 10 +++++----- .../{pci =3D> testing/selftests/pci_endpoint}/pcitest.c | 0 .../{pci =3D> testing/selftests/pci_endpoint}/pcitest.sh | 0 7 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 tools/testing/selftests/pci_endpoint/.gitignore rename tools/{pci =3D> testing/selftests/pci_endpoint}/Build (100%) rename tools/{pci =3D> testing/selftests/pci_endpoint}/Makefile (83%) rename tools/{pci =3D> testing/selftests/pci_endpoint}/pcitest.c (100%) rename tools/{pci =3D> testing/selftests/pci_endpoint}/pcitest.sh (100%) diff --git a/Documentation/PCI/endpoint/pci-test-howto.rst b/Documentation/= PCI/endpoint/pci-test-howto.rst index 909f770a07d6..c4ae7af50ede 100644 --- a/Documentation/PCI/endpoint/pci-test-howto.rst +++ b/Documentation/PCI/endpoint/pci-test-howto.rst @@ -123,16 +123,17 @@ above:: Using Endpoint Test function Device ----------------------------------- =20 -pcitest.sh added in tools/pci/ can be used to run all the default PCI endp= oint -tests. To compile this tool the following commands should be used:: +pcitest.sh added in tools/testing/selftests/pci_endpoint can be used to ru= n all +the default PCI endpoint tests. To compile this tool the following commands +should be used:: =20 # cd - # make -C tools/pci + # make -C tools/testing/selftests/pci_endpoint =20 or if you desire to compile and install in your system:: =20 # cd - # make -C tools/pci install + # make -C tools/testing/selftests/pci_endpoint install =20 The tool and script will be located in /usr/bin/ =20 diff --git a/MAINTAINERS b/MAINTAINERS index 1e930c7a58b1..0e611b845d50 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18003,7 +18003,7 @@ F: Documentation/PCI/endpoint/* F: Documentation/misc-devices/pci-endpoint-test.rst F: drivers/misc/pci_endpoint_test.c F: drivers/pci/endpoint/ -F: tools/pci/ +F: tools/testing/selftests/pci_endpoint/ =20 PCI ENHANCED ERROR HANDLING (EEH) FOR POWERPC M: Mahesh J Salgaonkar diff --git a/tools/testing/selftests/pci_endpoint/.gitignore b/tools/testin= g/selftests/pci_endpoint/.gitignore new file mode 100644 index 000000000000..29ab47c48484 --- /dev/null +++ b/tools/testing/selftests/pci_endpoint/.gitignore @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +*.o +pcitest diff --git a/tools/pci/Build b/tools/testing/selftests/pci_endpoint/Build similarity index 100% rename from tools/pci/Build rename to tools/testing/selftests/pci_endpoint/Build diff --git a/tools/pci/Makefile b/tools/testing/selftests/pci_endpoint/Make= file similarity index 83% rename from tools/pci/Makefile rename to tools/testing/selftests/pci_endpoint/Makefile index 62d41f1a1e2c..3c6fe18e32cc 100644 --- a/tools/pci/Makefile +++ b/tools/testing/selftests/pci_endpoint/Makefile @@ -1,11 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 -include ../scripts/Makefile.include +include ../../../scripts/Makefile.include =20 bindir ?=3D /usr/bin =20 ifeq ($(srctree),) -srctree :=3D $(patsubst %/,%,$(dir $(CURDIR))) -srctree :=3D $(patsubst %/,%,$(dir $(srctree))) +srctree :=3D $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR))) endif =20 # Do not use make's built-in rules @@ -27,10 +26,11 @@ include $(srctree)/tools/build/Makefile.include # # We need the following to be outside of kernel tree # -$(OUTPUT)include/linux/: ../../include/uapi/linux/ +$(OUTPUT)include/linux/: ../../../../include/uapi/linux/ mkdir -p $(OUTPUT)include/linux/ 2>&1 || true - ln -sf $(CURDIR)/../../include/uapi/linux/pcitest.h $@ + ln -sf $(CURDIR)/../../../../include/uapi/linux/pcitest.h $@ =20 +$(info ${CURDIR}) prepare: $(OUTPUT)include/linux/ =20 PCITEST_IN :=3D $(OUTPUT)pcitest-in.o diff --git a/tools/pci/pcitest.c b/tools/testing/selftests/pci_endpoint/pci= test.c similarity index 100% rename from tools/pci/pcitest.c rename to tools/testing/selftests/pci_endpoint/pcitest.c diff --git a/tools/pci/pcitest.sh b/tools/testing/selftests/pci_endpoint/pc= itest.sh similarity index 100% rename from tools/pci/pcitest.sh rename to tools/testing/selftests/pci_endpoint/pcitest.sh --=20 2.25.1 From nobody Sun May 10 06:04:44 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F9211A3035 for ; Tue, 31 Dec 2024 13:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735650858; cv=none; b=KfdaWMAS7BDVPm/8dtERWTUkKyjKR0tomJTQX32eJ0cxARIsGNSbbL2Mk5UaEfu7cDa905e2B3JwymbQ6BCj0ingtRWHSp4bhFKXWTjAedcc5TaDALF388xvliKzinI5XkAZSU1smvMHo1d8XHysPe5iGBvc0h/lFusaKL9CLI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735650858; c=relaxed/simple; bh=Orc7QbdlxlA8vQv7yiojJGWsXYMMbluZKciXh+pFbsY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f4XnVHIISsiefyX7B/BsPYZvEori2gCi74lV59T91EUxy/aSxmoYxd+QywEPpKHjyut382ljGIqJXe/waaqKqsdeSuoTv2iC4g/qFkmjqILddoXvM7LWiIDj850mChfnSnGsi4sFnl5nOe94jdK9ry6UeQIShoUpvfrPFjeIHmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=GvNRd3gH; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GvNRd3gH" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-215770613dbso97071905ad.2 for ; Tue, 31 Dec 2024 05:14:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735650855; x=1736255655; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2nAILpV58y0h7QN0Wd1q2R+f1PBJjtetd9BI/LbCkUs=; b=GvNRd3gHRr5PzTgdzKlRPUwuF321fg1RZ9YLrAkjtn6jpZTIUuX8YDZ6YEsn1KvksX xW2otVX5HJOq+VVEQA6QRf5fctWUJe+qEYaFCd5AzxgEYrdc/tdjUrePhcaVUGTWtaNb xKKXzBRHI4AzCC29v7vY7RIPEqIldQiXtgh18A5WgQfMflym/1iYcMEx+Ud3JSP8TLP6 4ZHYHXa8jvf/T9Z8GY1XKbNFrGhrgr7o1A2jmOLBAVFDD+VIWGYDVYY5tG71niEdFlCZ XfWP9Vc9/UdFxV/1RGNZHenUu1bLkK5UvFtj6/0iB4ceFQtufPSGghUSsLiYYMPWBFmr wqmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735650855; x=1736255655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2nAILpV58y0h7QN0Wd1q2R+f1PBJjtetd9BI/LbCkUs=; b=GOpSLxHODbjOYN6M9Qfy92wux9LVc24fUni0bPD12WYrFPRdi/WwSfndtnWakU4Dys NEJ6N3M4cyuTk+vATnfrRmPKQr91abOcYIry4XDU+DKHt4lRtgMVaD/Q8tIx416c3JGo vYDIY91Exsf8GJ8PEVGNMFNhQ2tnHnKjoAM7M/BwhoEYlbPfFqjx1YVm3GfYAPuRiiVu IOaCZATjxaqxs2j8T4oRYF2v+/Bn2CFBfKjvpsicpQiOOevlYZjF6l7DBoqkpqHqXT3O vDUJjp4CwiAG6tz7E2gWLOqkxmscPXFJEIvEltHRhl8mBMzfeOXB1wJGNil9oaWFjTI9 UZPg== X-Forwarded-Encrypted: i=1; AJvYcCWo52veNALBBBRZVhBvsFvRZ1dqrp2bvGSdsXRX8ZT7L+RlkDpbE0ldDEpiCvCc4Rp/YitRSwY3/9GrvKc=@vger.kernel.org X-Gm-Message-State: AOJu0YwMEGbhlJVeC+SzpDy68W5iTPODlZ09HzchDsy1T87GB4wsZcKh iB6tu+YvoutAal8mta1ke+qvc5+3CKwI72i3NlQhFNcXTg2pwe2ZebcYDp+ugg== X-Gm-Gg: ASbGncscSHQZL2nq0SgsjISB80D1jgjYzuHTNLXmPlhE8/FAoJJFB1OMfCqNCkuJ/CM mC4ro4UuBKvR1Mt8nEIdhXfDXUCrIDZ5O2Pm+sLz9w9Mflh57fPlj2dzzFxICXewDaX4ZoSULjv rPs9fUB+CXcFT4dNjo2v9KY3JSyT7U0e9Gd0OebeA7Q8Z4gy5HzgohcHcmQWPuDqcYC4j5IJ2i3 3znynNNIG63kd0VCiyNi5eXm6pT7UJVNNRDxSHaBj8USGm35npZdxl8uddyiIUsCkxrzm7wYzJr HWIA1x6eOVY= X-Google-Smtp-Source: AGHT+IHPZ/kQKe545SxLzPOpZJcXHhNZzM5vKlQ7svzm18XbkABBCHdyFSBt2tIcik1n+4BBxnku1w== X-Received: by 2002:a05:6a00:39a6:b0:729:1b8f:9645 with SMTP id d2e1a72fcca58-72abdebf1a1mr57781709b3a.24.1735650855303; Tue, 31 Dec 2024 05:14:15 -0800 (PST) Received: from localhost.localdomain ([117.193.213.202]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad6cc885sm20994862b3a.0.2024.12.31.05.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 05:14:14 -0800 (PST) From: Manivannan Sadhasivam To: kw@linux.com, gregkh@linuxfoundation.org, arnd@arndb.de, lpieralisi@kernel.org, shuah@kernel.org Cc: kishon@kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, bhelgaas@google.com, linux-arm-msm@vger.kernel.org, robh@kernel.org, linux-kselftest@vger.kernel.org, Manivannan Sadhasivam , Aman Gupta , Padmanabhan Rajanbabu Subject: [PATCH v4 3/3] selftests: pci_endpoint: Migrate to Kselftest framework Date: Tue, 31 Dec 2024 18:43:41 +0530 Message-Id: <20241231131341.39292-4-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241231131341.39292-1-manivannan.sadhasivam@linaro.org> References: <20241231131341.39292-1-manivannan.sadhasivam@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Migrate the PCI endpoint test to Kselftest framework. All the tests that were part of the previous pcitest.sh file were migrated. Below is the exclusive list of tests: 1. BAR Tests (BAR0 to BAR5) 2. Consecutive BAR Tests 3. Legacy IRQ Tests 4. MSI Interrupt Tests (MSI1 to MSI32) 5. MSI-X Interrupt Tests (MSI-X1 to MSI-X2048) 6. Read Tests - MEMCPY (For 1, 1024, 1025, 1024000, 1024001 Bytes) 7. Write Tests - MEMCPY (For 1, 1024, 1025, 1024000, 1024001 Bytes) 8. Copy Tests - MEMCPY (For 1, 1024, 1025, 1024000, 1024001 Bytes) 9. Read Tests - DMA (For 1, 1024, 1025, 1024000, 1024001 Bytes) 10. Write Tests - DMA (For 1, 1024, 1025, 1024000, 1024001 Bytes) 11. Copy Tests - DMA (For 1, 1024, 1025, 1024000, 1024001 Bytes) DMA and MEMCPY tests are added as fixture variants and can be executed separately as below: $ pci_endpoint_test -V dma (excluding DMA tests) $ pci_endpoint_test -V memcpy (excluding MEMCPY tests) Co-developed-by: Aman Gupta Signed-off-by: Aman Gupta Co-developed-by: Padmanabhan Rajanbabu Signed-off-by: Padmanabhan Rajanbabu [mani: reworked based on the IOCTL fix, cleanups, documentation, commit mes= sage] Signed-off-by: Manivannan Sadhasivam --- Documentation/PCI/endpoint/pci-test-howto.rst | 154 ++++------ tools/testing/selftests/Makefile | 1 + .../testing/selftests/pci_endpoint/.gitignore | 3 +- tools/testing/selftests/pci_endpoint/Build | 1 - tools/testing/selftests/pci_endpoint/Makefile | 59 +--- tools/testing/selftests/pci_endpoint/config | 4 + .../pci_endpoint/pci_endpoint_test.c | 194 +++++++++++++ .../testing/selftests/pci_endpoint/pcitest.c | 265 ------------------ .../testing/selftests/pci_endpoint/pcitest.sh | 73 ----- 9 files changed, 258 insertions(+), 496 deletions(-) delete mode 100644 tools/testing/selftests/pci_endpoint/Build create mode 100644 tools/testing/selftests/pci_endpoint/config create mode 100644 tools/testing/selftests/pci_endpoint/pci_endpoint_test.c delete mode 100644 tools/testing/selftests/pci_endpoint/pcitest.c delete mode 100644 tools/testing/selftests/pci_endpoint/pcitest.sh diff --git a/Documentation/PCI/endpoint/pci-test-howto.rst b/Documentation/= PCI/endpoint/pci-test-howto.rst index c4ae7af50ede..3d664c279c80 100644 --- a/Documentation/PCI/endpoint/pci-test-howto.rst +++ b/Documentation/PCI/endpoint/pci-test-howto.rst @@ -123,9 +123,9 @@ above:: Using Endpoint Test function Device ----------------------------------- =20 -pcitest.sh added in tools/testing/selftests/pci_endpoint can be used to ru= n all -the default PCI endpoint tests. To compile this tool the following commands -should be used:: +Kselftest added in tools/testing/selftests/pci_endpoint can be used to run= all +the default PCI endpoint tests. To build the Kselftest for PCI endpoint +subsystem, the following commands should be used:: =20 # cd # make -C tools/testing/selftests/pci_endpoint @@ -133,104 +133,58 @@ should be used:: or if you desire to compile and install in your system:: =20 # cd - # make -C tools/testing/selftests/pci_endpoint install + # make -C tools/testing/selftests/pci_endpoint INSTALL_PATH=3D/usr/bin in= stall =20 -The tool and script will be located in /usr/bin/ +The test will be located in /usr/bin/ =20 - -pcitest.sh Output -~~~~~~~~~~~~~~~~~ +Kselftest Output +~~~~~~~~~~~~~~~~ :: =20 - # pcitest.sh - BAR tests - - BAR0: OKAY - BAR1: OKAY - BAR2: OKAY - BAR3: OKAY - BAR4: NOT OKAY - BAR5: NOT OKAY - - Interrupt tests - - SET IRQ TYPE TO LEGACY: OKAY - LEGACY IRQ: NOT OKAY - SET IRQ TYPE TO MSI: OKAY - MSI1: OKAY - MSI2: OKAY - MSI3: OKAY - MSI4: OKAY - MSI5: OKAY - MSI6: OKAY - MSI7: OKAY - MSI8: OKAY - MSI9: OKAY - MSI10: OKAY - MSI11: OKAY - MSI12: OKAY - MSI13: OKAY - MSI14: OKAY - MSI15: OKAY - MSI16: OKAY - MSI17: NOT OKAY - MSI18: NOT OKAY - MSI19: NOT OKAY - MSI20: NOT OKAY - MSI21: NOT OKAY - MSI22: NOT OKAY - MSI23: NOT OKAY - MSI24: NOT OKAY - MSI25: NOT OKAY - MSI26: NOT OKAY - MSI27: NOT OKAY - MSI28: NOT OKAY - MSI29: NOT OKAY - MSI30: NOT OKAY - MSI31: NOT OKAY - MSI32: NOT OKAY - SET IRQ TYPE TO MSI-X: OKAY - MSI-X1: OKAY - MSI-X2: OKAY - MSI-X3: OKAY - MSI-X4: OKAY - MSI-X5: OKAY - MSI-X6: OKAY - MSI-X7: OKAY - MSI-X8: OKAY - MSI-X9: NOT OKAY - MSI-X10: NOT OKAY - MSI-X11: NOT OKAY - MSI-X12: NOT OKAY - MSI-X13: NOT OKAY - MSI-X14: NOT OKAY - MSI-X15: NOT OKAY - MSI-X16: NOT OKAY - [...] - MSI-X2047: NOT OKAY - MSI-X2048: NOT OKAY - - Read Tests - - SET IRQ TYPE TO MSI: OKAY - READ ( 1 bytes): OKAY - READ ( 1024 bytes): OKAY - READ ( 1025 bytes): OKAY - READ (1024000 bytes): OKAY - READ (1024001 bytes): OKAY - - Write Tests - - WRITE ( 1 bytes): OKAY - WRITE ( 1024 bytes): OKAY - WRITE ( 1025 bytes): OKAY - WRITE (1024000 bytes): OKAY - WRITE (1024001 bytes): OKAY - - Copy Tests - - COPY ( 1 bytes): OKAY - COPY ( 1024 bytes): OKAY - COPY ( 1025 bytes): OKAY - COPY (1024000 bytes): OKAY - COPY (1024001 bytes): OKAY + # pci_endpoint_test + TAP version 13 + 1..11 + # Starting 11 tests from 3 test cases. + # RUN pci_ep_basic.BAR_TEST ... + # OK pci_ep_basic.BAR_TEST + ok 1 pci_ep_basic.BAR_TEST + # RUN pci_ep_basic.CONSECUTIVE_BAR_TEST ... + # OK pci_ep_basic.CONSECUTIVE_BAR_TEST + ok 2 pci_ep_basic.CONSECUTIVE_BAR_TEST + # RUN pci_ep_basic.LEGACY_IRQ_TEST ... + # OK pci_ep_basic.LEGACY_IRQ_TEST + ok 3 pci_ep_basic.LEGACY_IRQ_TEST + # RUN pci_ep_basic.MSI_TEST ... + # OK pci_ep_basic.MSI_TEST + ok 4 pci_ep_basic.MSI_TEST + # RUN pci_ep_basic.MSIX_TEST ... + # OK pci_ep_basic.MSIX_TEST + ok 5 pci_ep_basic.MSIX_TEST + # RUN pci_ep_data_transfer.memcpy.READ_TEST ... + # OK pci_ep_data_transfer.memcpy.READ_TEST + ok 6 pci_ep_data_transfer.memcpy.READ_TEST + # RUN pci_ep_data_transfer.memcpy.WRITE_TEST ... + # OK pci_ep_data_transfer.memcpy.WRITE_TEST + ok 7 pci_ep_data_transfer.memcpy.WRITE_TEST + # RUN pci_ep_data_transfer.memcpy.COPY_TEST ... + # OK pci_ep_data_transfer.memcpy.COPY_TEST + ok 8 pci_ep_data_transfer.memcpy.COPY_TEST + # RUN pci_ep_data_transfer.dma.READ_TEST ... + # OK pci_ep_data_transfer.dma.READ_TEST + ok 9 pci_ep_data_transfer.dma.READ_TEST + # RUN pci_ep_data_transfer.dma.WRITE_TEST ... + # OK pci_ep_data_transfer.dma.WRITE_TEST + ok 10 pci_ep_data_transfer.dma.WRITE_TEST + # RUN pci_ep_data_transfer.dma.COPY_TEST ... + # OK pci_ep_data_transfer.dma.COPY_TEST + ok 11 pci_ep_data_transfer.dma.COPY_TEST + # PASSED: 11 / 11 tests passed. + # Totals: pass:11 fail:0 xfail:0 xpass:0 skip:0 error:0 + + +Testcase 11 (pci_ep_data_transfer.dma.COPY_TEST) will fail for most of the= DMA +capable endpoint controllers due to the absence of the MEMCPY over DMA. Fo= r such +controllers, it is advisable to skip the forementioned testcase using below +command:: + + # pci_endpoint_test -f pci_ep_basic -v memcpy -T COPY_TEST -v dma diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Mak= efile index 2401e973c359..50931cd6aff2 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -72,6 +72,7 @@ TARGETS +=3D net/packetdrill TARGETS +=3D net/rds TARGETS +=3D net/tcp_ao TARGETS +=3D nsfs +TARGETS +=3D pci_endpoint TARGETS +=3D pcie_bwctrl TARGETS +=3D perf_events TARGETS +=3D pidfd diff --git a/tools/testing/selftests/pci_endpoint/.gitignore b/tools/testin= g/selftests/pci_endpoint/.gitignore index 29ab47c48484..6a4837a3e034 100644 --- a/tools/testing/selftests/pci_endpoint/.gitignore +++ b/tools/testing/selftests/pci_endpoint/.gitignore @@ -1,3 +1,2 @@ # SPDX-License-Identifier: GPL-2.0-only -*.o -pcitest +pci_endpoint_test diff --git a/tools/testing/selftests/pci_endpoint/Build b/tools/testing/sel= ftests/pci_endpoint/Build deleted file mode 100644 index c375aea21790..000000000000 --- a/tools/testing/selftests/pci_endpoint/Build +++ /dev/null @@ -1 +0,0 @@ -pcitest-y +=3D pcitest.o diff --git a/tools/testing/selftests/pci_endpoint/Makefile b/tools/testing/= selftests/pci_endpoint/Makefile index 3c6fe18e32cc..bf21ebf20b4a 100644 --- a/tools/testing/selftests/pci_endpoint/Makefile +++ b/tools/testing/selftests/pci_endpoint/Makefile @@ -1,58 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 -include ../../../scripts/Makefile.include +CFLAGS +=3D -O2 -Wl,-no-as-needed -Wall $(KHDR_INCLUDES) +LDFLAGS +=3D -lrt -lpthread -lm =20 -bindir ?=3D /usr/bin +TEST_GEN_PROGS =3D pci_endpoint_test =20 -ifeq ($(srctree),) -srctree :=3D $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR))) -endif - -# Do not use make's built-in rules -# (this improves performance and avoids hard-to-debug behaviour); -MAKEFLAGS +=3D -r - -CFLAGS +=3D -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include - -ALL_TARGETS :=3D pcitest -ALL_PROGRAMS :=3D $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) - -SCRIPTS :=3D pcitest.sh - -all: $(ALL_PROGRAMS) - -export srctree OUTPUT CC LD CFLAGS -include $(srctree)/tools/build/Makefile.include - -# -# We need the following to be outside of kernel tree -# -$(OUTPUT)include/linux/: ../../../../include/uapi/linux/ - mkdir -p $(OUTPUT)include/linux/ 2>&1 || true - ln -sf $(CURDIR)/../../../../include/uapi/linux/pcitest.h $@ - -$(info ${CURDIR}) -prepare: $(OUTPUT)include/linux/ - -PCITEST_IN :=3D $(OUTPUT)pcitest-in.o -$(PCITEST_IN): prepare FORCE - $(Q)$(MAKE) $(build)=3Dpcitest -$(OUTPUT)pcitest: $(PCITEST_IN) - $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ - -clean: - rm -f $(ALL_PROGRAMS) - rm -rf $(OUTPUT)include/ - find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o = -name '\.*.d' -delete - -install: $(ALL_PROGRAMS) - install -d -m 755 $(DESTDIR)$(bindir); \ - for program in $(ALL_PROGRAMS); do \ - install $$program $(DESTDIR)$(bindir); \ - done; \ - for script in $(SCRIPTS); do \ - install $$script $(DESTDIR)$(bindir); \ - done - -FORCE: - -.PHONY: all install clean FORCE prepare +include ../lib.mk diff --git a/tools/testing/selftests/pci_endpoint/config b/tools/testing/se= lftests/pci_endpoint/config new file mode 100644 index 000000000000..7cdcf117db8d --- /dev/null +++ b/tools/testing/selftests/pci_endpoint/config @@ -0,0 +1,4 @@ +CONFIG_PCI_ENDPOINT=3Dy +CONFIG_PCI_ENDPOINT_CONFIGFS=3Dy +CONFIG_PCI_EPF_TEST=3Dm +CONFIG_PCI_ENDPOINT_TEST=3Dm diff --git a/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c b/too= ls/testing/selftests/pci_endpoint/pci_endpoint_test.c new file mode 100644 index 000000000000..964dfb80ff12 --- /dev/null +++ b/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kselftest for PCI Endpoint Subsystem + * + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * https://www.samsung.com + * Author: Aman Gupta + * + * Copyright (c) 2024, Linaro Ltd. + * Author: Manivannan Sadhasivam + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../include/uapi/linux/pcitest.h" + +#include "../kselftest_harness.h" + +#define pci_ep_ioctl(cmd, arg) \ +({ \ + ret =3D ioctl(self->fd, cmd, arg); \ + ret =3D ret < 0 ? -errno : 0; \ +}) + +static const char *test_device =3D "/dev/pci-endpoint-test.0"; +static const unsigned long test_size[5] =3D { 1, 1024, 1025, 1024000, 1024= 001 }; + +FIXTURE(pci_ep_basic) +{ + int fd; +}; + +FIXTURE_SETUP(pci_ep_basic) +{ + self->fd =3D open(test_device, O_RDWR); + + ASSERT_NE(-1, self->fd) TH_LOG("Can't open PCI Endpoint Test device"); +} + +FIXTURE_TEARDOWN(pci_ep_basic) +{ + close(self->fd); +} + +TEST_F(pci_ep_basic, BAR_TEST) +{ + int ret, i; + + for (i =3D 0; i <=3D 5; i++) { + pci_ep_ioctl(PCITEST_BAR, i); + EXPECT_FALSE(ret) TH_LOG("Test failed for BAR%d", i); + } +} + +TEST_F(pci_ep_basic, CONSECUTIVE_BAR_TEST) +{ + int ret; + + pci_ep_ioctl(PCITEST_BARS, 0); + EXPECT_FALSE(ret) TH_LOG("Consecutive BAR test failed"); +} + +TEST_F(pci_ep_basic, LEGACY_IRQ_TEST) +{ + int ret; + + pci_ep_ioctl(PCITEST_SET_IRQTYPE, 0); + ASSERT_EQ(0, ret) TH_LOG("Can't set Legacy IRQ type"); + + pci_ep_ioctl(PCITEST_LEGACY_IRQ, 0); + EXPECT_FALSE(ret) TH_LOG("Test failed for Legacy IRQ"); +} + +TEST_F(pci_ep_basic, MSI_TEST) +{ + int ret, i; + + pci_ep_ioctl(PCITEST_SET_IRQTYPE, 1); + ASSERT_EQ(0, ret) TH_LOG("Can't set MSI IRQ type"); + + for (i =3D 1; i <=3D 32; i++) { + pci_ep_ioctl(PCITEST_MSI, i); + EXPECT_FALSE(ret) TH_LOG("Test failed for MSI%d", i); + } +} + +TEST_F(pci_ep_basic, MSIX_TEST) +{ + int ret, i; + + pci_ep_ioctl(PCITEST_SET_IRQTYPE, 2); + ASSERT_EQ(0, ret) TH_LOG("Can't set MSI-X IRQ type"); + + for (i =3D 1; i <=3D 2048; i++) { + pci_ep_ioctl(PCITEST_MSIX, i); + EXPECT_FALSE(ret) TH_LOG("Test failed for MSI-X%d", i); + } +} + +FIXTURE(pci_ep_data_transfer) +{ + int fd; +}; + +FIXTURE_SETUP(pci_ep_data_transfer) +{ + self->fd =3D open(test_device, O_RDWR); + + ASSERT_NE(-1, self->fd) TH_LOG("Can't open PCI Endpoint Test device"); +} + +FIXTURE_TEARDOWN(pci_ep_data_transfer) +{ + close(self->fd); +} + +FIXTURE_VARIANT(pci_ep_data_transfer) +{ + bool use_dma; +}; + +FIXTURE_VARIANT_ADD(pci_ep_data_transfer, memcpy) +{ + .use_dma =3D false, +}; + +FIXTURE_VARIANT_ADD(pci_ep_data_transfer, dma) +{ + .use_dma =3D true, +}; + +TEST_F(pci_ep_data_transfer, READ_TEST) +{ + struct pci_endpoint_test_xfer_param param =3D {0}; + int ret, i; + + if (variant->use_dma) + param.flags =3D PCITEST_FLAGS_USE_DMA; + + pci_ep_ioctl(PCITEST_SET_IRQTYPE, 1); + ASSERT_EQ(0, ret) TH_LOG("Can't set MSI IRQ type"); + + for (i =3D 0; i < ARRAY_SIZE(test_size); i++) { + param.size =3D test_size[i]; + pci_ep_ioctl(PCITEST_READ, ¶m); + EXPECT_FALSE(ret) TH_LOG("Test failed for size (%ld)", + test_size[i]); + } +} + +TEST_F(pci_ep_data_transfer, WRITE_TEST) +{ + struct pci_endpoint_test_xfer_param param =3D {0}; + int ret, i; + + if (variant->use_dma) + param.flags =3D PCITEST_FLAGS_USE_DMA; + + pci_ep_ioctl(PCITEST_SET_IRQTYPE, 1); + ASSERT_EQ(0, ret) TH_LOG("Can't set MSI IRQ type"); + + for (i =3D 0; i < ARRAY_SIZE(test_size); i++) { + param.size =3D test_size[i]; + pci_ep_ioctl(PCITEST_WRITE, ¶m); + EXPECT_FALSE(ret) TH_LOG("Test failed for size (%ld)", + test_size[i]); + } +} + +TEST_F(pci_ep_data_transfer, COPY_TEST) +{ + struct pci_endpoint_test_xfer_param param =3D {0}; + int ret, i; + + if (variant->use_dma) + param.flags =3D PCITEST_FLAGS_USE_DMA; + + pci_ep_ioctl(PCITEST_SET_IRQTYPE, 1); + ASSERT_EQ(0, ret) TH_LOG("Can't set MSI IRQ type"); + + for (i =3D 0; i < ARRAY_SIZE(test_size); i++) { + param.size =3D test_size[i]; + pci_ep_ioctl(PCITEST_COPY, ¶m); + EXPECT_FALSE(ret) TH_LOG("Test failed for size (%ld)", + test_size[i]); + } +} +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/pci_endpoint/pcitest.c b/tools/testing= /selftests/pci_endpoint/pcitest.c deleted file mode 100644 index b96cc118839b..000000000000 --- a/tools/testing/selftests/pci_endpoint/pcitest.c +++ /dev/null @@ -1,265 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/** - * Userspace PCI Endpoint Test Module - * - * Copyright (C) 2017 Texas Instruments - * Author: Kishon Vijay Abraham I - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -static char *irq[] =3D { "LEGACY", "MSI", "MSI-X" }; - -struct pci_test { - char *device; - char barnum; - bool consecutive_bar_test; - bool legacyirq; - unsigned int msinum; - unsigned int msixnum; - int irqtype; - bool set_irqtype; - bool get_irqtype; - bool clear_irq; - bool read; - bool write; - bool copy; - unsigned long size; - bool use_dma; -}; - -static int run_test(struct pci_test *test) -{ - struct pci_endpoint_test_xfer_param param =3D {}; - int ret =3D -EINVAL; - int fd; - - fd =3D open(test->device, O_RDWR); - if (fd < 0) { - perror("can't open PCI Endpoint Test device"); - return -ENODEV; - } - - if (test->barnum >=3D 0 && test->barnum <=3D 5) { - ret =3D ioctl(fd, PCITEST_BAR, test->barnum); - fprintf(stdout, "BAR%d:\t\t", test->barnum); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->consecutive_bar_test) { - ret =3D ioctl(fd, PCITEST_BARS); - fprintf(stdout, "Consecutive BAR test:\t\t"); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->set_irqtype) { - ret =3D ioctl(fd, PCITEST_SET_IRQTYPE, test->irqtype); - fprintf(stdout, "SET IRQ TYPE TO %s:\t\t", irq[test->irqtype]); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->get_irqtype) { - ret =3D ioctl(fd, PCITEST_GET_IRQTYPE); - fprintf(stdout, "GET IRQ TYPE:\t\t"); - if (ret < 0) { - fprintf(stdout, "NOT OKAY\n"); - } else { - fprintf(stdout, "%s\n", irq[ret]); - ret =3D 0; - } - } - - if (test->clear_irq) { - ret =3D ioctl(fd, PCITEST_CLEAR_IRQ); - fprintf(stdout, "CLEAR IRQ:\t\t"); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->legacyirq) { - ret =3D ioctl(fd, PCITEST_LEGACY_IRQ, 0); - fprintf(stdout, "LEGACY IRQ:\t"); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->msinum > 0 && test->msinum <=3D 32) { - ret =3D ioctl(fd, PCITEST_MSI, test->msinum); - fprintf(stdout, "MSI%u:\t\t", test->msinum); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->msixnum > 0 && test->msixnum <=3D 2048) { - ret =3D ioctl(fd, PCITEST_MSIX, test->msixnum); - fprintf(stdout, "MSI-X%u:\t\t", test->msixnum); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->write) { - param.size =3D test->size; - if (test->use_dma) - param.flags =3D PCITEST_FLAGS_USE_DMA; - ret =3D ioctl(fd, PCITEST_WRITE, ¶m); - fprintf(stdout, "WRITE (%7lu bytes):\t\t", test->size); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->read) { - param.size =3D test->size; - if (test->use_dma) - param.flags =3D PCITEST_FLAGS_USE_DMA; - ret =3D ioctl(fd, PCITEST_READ, ¶m); - fprintf(stdout, "READ (%7lu bytes):\t\t", test->size); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - if (test->copy) { - param.size =3D test->size; - if (test->use_dma) - param.flags =3D PCITEST_FLAGS_USE_DMA; - ret =3D ioctl(fd, PCITEST_COPY, ¶m); - fprintf(stdout, "COPY (%7lu bytes):\t\t", test->size); - if (ret < 0) - fprintf(stdout, "NOT OKAY\n"); - else - fprintf(stdout, "OKAY\n"); - } - - fflush(stdout); - close(fd); - return ret; -} - -int main(int argc, char **argv) -{ - int c; - struct pci_test *test; - - test =3D calloc(1, sizeof(*test)); - if (!test) { - perror("Fail to allocate memory for pci_test\n"); - return -ENOMEM; - } - - /* since '0' is a valid BAR number, initialize it to -1 */ - test->barnum =3D -1; - - /* set default size as 100KB */ - test->size =3D 0x19000; - - /* set default endpoint device */ - test->device =3D "/dev/pci-endpoint-test.0"; - - while ((c =3D getopt(argc, argv, "D:b:Cm:x:i:deIlhrwcs:")) !=3D EOF) - switch (c) { - case 'D': - test->device =3D optarg; - continue; - case 'b': - test->barnum =3D atoi(optarg); - if (test->barnum < 0 || test->barnum > 5) - goto usage; - continue; - case 'C': - test->consecutive_bar_test =3D true; - continue; - case 'l': - test->legacyirq =3D true; - continue; - case 'm': - test->msinum =3D atoi(optarg); - if (test->msinum < 1 || test->msinum > 32) - goto usage; - continue; - case 'x': - test->msixnum =3D atoi(optarg); - if (test->msixnum < 1 || test->msixnum > 2048) - goto usage; - continue; - case 'i': - test->irqtype =3D atoi(optarg); - if (test->irqtype < 0 || test->irqtype > 2) - goto usage; - test->set_irqtype =3D true; - continue; - case 'I': - test->get_irqtype =3D true; - continue; - case 'r': - test->read =3D true; - continue; - case 'w': - test->write =3D true; - continue; - case 'c': - test->copy =3D true; - continue; - case 'e': - test->clear_irq =3D true; - continue; - case 's': - test->size =3D strtoul(optarg, NULL, 0); - continue; - case 'd': - test->use_dma =3D true; - continue; - case 'h': - default: -usage: - fprintf(stderr, - "usage: %s [options]\n" - "Options:\n" - "\t-D PCI endpoint test device {default: /dev/pci-endpoint-test.= 0}\n" - "\t-b BAR test (bar number between 0..5)\n" - "\t-C Consecutive BAR test\n" - "\t-m MSI test (msi number between 1..32)\n" - "\t-x \tMSI-X test (msix number between 1..2048)\n" - "\t-i \tSet IRQ type (0 - Legacy, 1 - MSI, 2 - MSI-X)\n" - "\t-e Clear IRQ\n" - "\t-I Get current IRQ type configured\n" - "\t-d Use DMA\n" - "\t-l Legacy IRQ test\n" - "\t-r Read buffer test\n" - "\t-w Write buffer test\n" - "\t-c Copy buffer test\n" - "\t-s Size of buffer {default: 100KB}\n" - "\t-h Print this help message\n", - argv[0]); - return -EINVAL; - } - - return run_test(test); -} diff --git a/tools/testing/selftests/pci_endpoint/pcitest.sh b/tools/testin= g/selftests/pci_endpoint/pcitest.sh deleted file mode 100644 index 770f4d6df34b..000000000000 --- a/tools/testing/selftests/pci_endpoint/pcitest.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -echo "BAR tests" -echo - -bar=3D0 - -while [ $bar -lt 6 ] -do - pcitest -b $bar - bar=3D`expr $bar + 1` -done -pcitest -C -echo - -echo "Interrupt tests" -echo - -pcitest -i 0 -pcitest -l - -pcitest -i 1 -msi=3D1 - -while [ $msi -lt 33 ] -do - pcitest -m $msi - msi=3D`expr $msi + 1` -done -echo - -pcitest -i 2 -msix=3D1 - -while [ $msix -lt 2049 ] -do - pcitest -x $msix - msix=3D`expr $msix + 1` -done -echo - -echo "Read Tests" -echo - -pcitest -i 1 - -pcitest -r -s 1 -pcitest -r -s 1024 -pcitest -r -s 1025 -pcitest -r -s 1024000 -pcitest -r -s 1024001 -echo - -echo "Write Tests" -echo - -pcitest -w -s 1 -pcitest -w -s 1024 -pcitest -w -s 1025 -pcitest -w -s 1024000 -pcitest -w -s 1024001 -echo - -echo "Copy Tests" -echo - -pcitest -c -s 1 -pcitest -c -s 1024 -pcitest -c -s 1025 -pcitest -c -s 1024000 -pcitest -c -s 1024001 -echo --=20 2.25.1