From patchwork Thu Jan 20 08:03:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Chen X-Patchwork-Id: 12718418 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com 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 802E1C433EF for ; Thu, 20 Jan 2022 08:03:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbiATIDw (ORCPT ); Thu, 20 Jan 2022 03:03:52 -0500 Received: from mx0a-00622301.pphosted.com ([205.220.163.205]:46210 "EHLO mx0a-00622301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230116AbiATIDw (ORCPT ); Thu, 20 Jan 2022 03:03:52 -0500 Received: from pps.filterd (m0241924.ppops.net [127.0.0.1]) by mx0a-00622301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20K7uNKY010800; Thu, 20 Jan 2022 00:03:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ambarella.com; h=from : to : subject : date : message-id : content-transfer-encoding : mime-version : content-type; s=com20210415pp; bh=YsGnLNUA3rb0Yo+TOXesGgaq2ULszx6UXRYdoF9pqis=; b=xI1DLS51MTKtwfv2q5df/CnRKeoszCF37LB4KRrXB+SdIKRPGflrcW30ea04LR07GkXx PClcbxxJQ18oBUKri4sA1Xc7oJI8xtIj8HDM5sX185G6APnG0fEdNTtIlWhjayzedKP7 puO0Ok9+46kBb7MosJ5fTKkzOxHsl0hFj8+LelYIzYfeZTQucRO2FDkRMQLyIJQBZP1m GVeuUN/Zu2bKGOIPgcDOrAUXe0p4lXtnhV8WETbORpDBs2p1DKyatXL4kmaaPF9kP/wW CIM+FjA1me+YB0UTVv6RvYl5VT+whtIwPGkROAvk3amizv0R0z4zjz5N+EqMDm5JAuZv QQ== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by mx0a-00622301.pphosted.com (PPS) with ESMTPS id 3dpp0gr991-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Jan 2022 00:03:20 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l95cxxckNTDx0zImZn1K0P1SbyDNjZd254LeZlcQeF3sx2Nx1kufrKoV5YIaJdnnO43OXPKhvVoKL2+GQvtt+gS2lwypX6wSyQ6JO2Har/XB0sKaEOM1+PgpzzsgXLwl1Q/z8my5R2RBxCy1EvI4WwbJxcDbCM6rZiuD7kf2j828dCtJLq3sv4ylxOdKJynnl8whKsnduAxPVR4IGrM7wMLD/6sRWcJ6crQLTbYf+p3k8sHZXwYKAbsYLhfG0wprk3Cy/otjDzctUc6gsimCRqKDbOaLUUQJGmaSjdnCN8RgnKz0jQsxC0H5lp4aWoAWg4wJJfFTk9A8BDM06b55JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vWJa+zEk8Shcm7QpNQdHbgho4seW+4nRQmx+yMKXOhQ=; b=HKO0ZYfxy2TY0akgnYR4I4QchhrB+FgTlSRjOr/UXD6984R5loqZhYjqBzEMZyPl03K9f/YOM+LU/VyK6jRCwB2Eoc7H2EsXAyEY04g8QbUrxAz1xgBx2U0V+wMz8gDETJDb19OY7dFgDVe56zK7If7eLCcA4wRgDGN0QT/qJIu+WXN+osWrETVJJ8CjkL+OgKm9JFW8sGdvN+ixZN2qFBn3OsE0BRKFOu0R8TPepelfGoxrYOPSxR2FWhMyBhivCSdgGLNLs6m3eA1YdUrUrqQGrk3SZlpeT7Esb9W/oSbkRNtrKDtdsLO239ec5WVyVBstv3oqarRdRyTohIhLvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ambarella.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vWJa+zEk8Shcm7QpNQdHbgho4seW+4nRQmx+yMKXOhQ=; b=JGw6zrGrHyXxUk/M9kpB5sImvPjg0W/S1lfm4pp6Z38XwAFw+Y/7waJDT8jgxPzXrZJkSaZ0MBgKAN18tveUnMaSYipY6qpsg0c20l3Yz5u1cDEjeQnYoijXhflxut1G8AdulmPRnKPaS3oT3uUs8nc7aiLy+k4kIC4tzuYTuNAmkhmHbRiR8hQW69mkzVUNoqUzV7C0W1P6nP3MwEgfdexIgWXa+s6FMCubQqBXT/HcuFnxIvoy+yPH8zCXzu9VIpiTiRU+Qp2ngPJS2BoRdJtZFt9jGxLNCo3ZklxOCDOrh8SN4ja4SaR/ZIsXGSnlpUolFJ/Nt3jv/L9cPnuHXg== Received: from SA1PR19MB5572.namprd19.prod.outlook.com (2603:10b6:806:229::8) by MN2PR19MB2944.namprd19.prod.outlook.com (2603:10b6:208:f2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.8; Thu, 20 Jan 2022 08:03:18 +0000 Received: from SA1PR19MB5572.namprd19.prod.outlook.com ([fe80::2df6:255a:c65f:69db]) by SA1PR19MB5572.namprd19.prod.outlook.com ([fe80::2df6:255a:c65f:69db%7]) with mapi id 15.20.4909.008; Thu, 20 Jan 2022 08:03:18 +0000 From: Li Chen To: Kishon Vijay Abraham I , Lorenzo Pieralisi , =?iso-8859-2?q?Krzysztof_Wil?= =?iso-8859-2?q?czy=F1ski?= , Arnd Bergmann , Greg Kroah-Hartman , Bjorn Helgaas , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH] misc: pci_endpoint_test: simplify endpoint test read and write operations Thread-Topic: [PATCH] misc: pci_endpoint_test: simplify endpoint test read and write operations Thread-Index: AdgN08pRFuc4KG9kQuiq2cd/4nCPdQ== Date: Thu, 20 Jan 2022 08:03:17 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2e615fac-db10-4e64-2724-08d9dbeb518c x-ms-traffictypediagnostic: MN2PR19MB2944:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: e4J9OUXggmqkjbx/OIhX8WqEIe/df00Ti5v3St2qsWvBL2fD4eKgpMJs8Kf0AwZYRwEby/s/OTHNHOL5AxDoGXesibFJ96Fgxv3NbEUPEzE6EjQRm1Wq8P8IgC/3f7/wbaAe+3sfoPLLuQMisxZelF4Ulku/UrIIO2LcN8Ph0h2oAZdOg1BNVPXsEt66R4aq0G6Oct+ltJ36tzlnA82YqxPbvpXtPKoY6OGODH8FL2lSP7pab/Uf98jEDUUZGKZISqSs4Hwk2nmLdWQz2Ofz+t9FJR1uaZ8Ub1rw5xMG6BHqQ0hF6ZGucJYiKuwxoSBtQqM54xcodsjA48Es/28oGu7/MdDoDLECEWWhSKYod4FNVMX6D5aOGhuPbfVkZm5cGnNTo4DkkURX9ZV+kZz1r6ZkQGOMmcm6M8hbb4B4VGshRIiGrjk1Mdtm3mcp1UOT0sltNRMVh11xwma281XfwoaZ8JWSf4VS2B0u25xvb517COOCFBvm6aoxEjjPi5E0fHENONmqjkG6GmUHQk5uDqwbpBm3ABPyIJ+NAHL22KtaeY6ZwgptidqHWzkPdTvOAdc6AaOLSW8Gg++TYnj6lymSMfcLb/jeQ+cnyS2EpFERUUw8WPrc50s6WZdVDYpdiWYRxlErTYcN+i01ASiWXg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA1PR19MB5572.namprd19.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(186003)(66946007)(316002)(55016003)(9686003)(64756008)(66556008)(66446008)(8936002)(6506007)(52536014)(26005)(33656002)(86362001)(122000001)(83380400001)(88996005)(2906002)(71200400001)(7696005)(8676002)(5660300002)(66476007)(508600001)(38100700002)(110136005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-2?q?jo46YXpJhKxsKWR9nwCHU66?= =?iso-8859-2?q?TF6QxrlZDDcc3bguKNcHmqfczXnd/pjd1r8qqbu4LjIvi6v00CeLPXMoL26o?= =?iso-8859-2?q?ACzEc8Obs57kyIbaJN4wpqoFuaKKy56raovK5uAlV2O+lwJcjSTiX/qUTqMW?= =?iso-8859-2?q?+42jM0w23Tma/t4UzihxOCbG/QvlFRGXr7x6XjOztyYdqEp+y2N2uw57tjnB?= =?iso-8859-2?q?ufq3mUF9nyNJlxuy8W+e8ejsJeStQmonafgls/8XExemfHEqPCuI7LqBsLg9?= =?iso-8859-2?q?w96U7cqYujfUmjjzGmRpCOT4BlJMyWJazl+7z/u9yG3CZl1Q4dMwGFpuGUhX?= =?iso-8859-2?q?ktEskM8kloFuux3tZAcoJRhML/Q6uHjj8TsXOlzBaW16gIB5w9/Uk8TRPAMH?= =?iso-8859-2?q?7YFiJGT3EkZrq/K90tVkKcs/A0UTCzSGD+UUxEhbTphadjiRExxJ0bmLtJRy?= =?iso-8859-2?q?++MZY/gyYZf/F4DubMGZ9cT2enaVud4Id3Xp0p06CBtdXTihLbGdnQV9jXj/?= =?iso-8859-2?q?YJTK9810EeVf5uR20eXfMXh6KZLcAi77pvokr1LNZqu4kRVP4yMGjDt3CJfN?= =?iso-8859-2?q?AT7XuOnL/G1k7Ge26yzohjvGPV9u1F1vxEoozF5lmYGZS41AwNykLQXOM6nu?= =?iso-8859-2?q?8lWXq0s2Qhp9WoBhkBlb0MeR/Y1N53/Quh2woy6cYCQJO9N7Embjkbk+qWdm?= =?iso-8859-2?q?8shrh5fCWa62ISUhUCtmyaPQzUHDB1zAs0aF3/8HEj8fKFO8Pfus1EZBslum?= =?iso-8859-2?q?37sdNDYdxcRXhtOXFmzidYshVEFMZVuy3dw5spmJ5bEVPeRZlzxtz8U4Ak2T?= =?iso-8859-2?q?VG3EXSNwBuwsbZp8a+WwrgDieAeJ0KUsmc6KYpW9LACb8UBDsX7J2nW8fmLr?= =?iso-8859-2?q?ouDqeVwq4BAExy8oj6qkyQY5h5WmYTIZXp5Ih2FYeYWgec4zEYVsJCC+X/Ll?= =?iso-8859-2?q?hm2XW88s5glWg+9jjnN3uPEjVIINcO0ub1VCjHQbg/otFIVlnC31sEmBpvhc?= =?iso-8859-2?q?9xXQlKnpGDsUGhU6y0nnG3kJ2sxGsbjB23NvvbZa9x9/31IGnStFS2n1AIL3?= =?iso-8859-2?q?G4YYn3N9XXoOEgBEZdhvOURSp2kNgaKvrGmc4Jz3ObBadE97eg3GPeibGXKk?= =?iso-8859-2?q?dH2e0AUP5ZN8qDuDr2GW7jdkKvCaF5WiKG1tLWp0hKu1cxy8a7g64mXZht9Y?= =?iso-8859-2?q?UukFqm4nbqazp/HISw+9E/zPdCXPLdophS10QDI2wv3SO6pFP26eLx/xvLYF?= =?iso-8859-2?q?NL667QtpsNYA6fKvYPQAPauQoGg0HTe6Qjqf65YlDrZu1g3uql7u3vPMwpB5?= =?iso-8859-2?q?/d0vO+O/+UJAYvj/69ilGieQKm9UHogRtABNEhOumy95yx5/k2rlDIq1nfDf?= =?iso-8859-2?q?zKuBXTJOqkQg6qVj39SFy6POHlAyAATYrpBEepOM4++FQUSMdrNlyP9uG9ig?= =?iso-8859-2?q?ADtv/nb65Sb2OJptGPURXvhQytfBRxOvqH91OWeRAQzoaZEZ+l0oYgVgyJrZ?= =?iso-8859-2?q?HSPe8FogzKX/JXRyH/3/Xr9o6CfUXo8/7XwOS9CKUpgV5eCvkIq8XobiSwu7?= =?iso-8859-2?q?dH738Tr0GLIEQ/wyamzRPdptsJMmbNZIwG3Cbn+lq/bJpBw6olM2OjFEOy+G?= =?iso-8859-2?q?9cIGVjZq4jXye6P6Zai4pY3SkLrwLnhkeRHwBkC9AxCid7Uu5VfxT8gwAUcs?= =?iso-8859-2?q?=3D?= MIME-Version: 1.0 X-OriginatorOrg: ambarella.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SA1PR19MB5572.namprd19.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e615fac-db10-4e64-2724-08d9dbeb518c X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2022 08:03:17.9854 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3ccd3c8d-5f7c-4eb4-ae6f-32d8c106402c X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: EjxBQI+g3WEDIZ4XXl8KWdT4tRWwz4pNQ2lmymPyQQENJ6zKD7gDEAfgHME9OCm3uZdoa7l+fmnq5qBL6VXAOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR19MB2944 X-Proofpoint-GUID: 3L86d8oka5f7st-R-u95PHEGwzwAN2VV X-Proofpoint-ORIG-GUID: 3L86d8oka5f7st-R-u95PHEGwzwAN2VV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-20_03,2022-01-19_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 clxscore=1015 bulkscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201200042 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Introduce pci_endpoint_epf_transfer_data to simplify read and write operations. Signed-off-by: Li Chen --- drivers/misc/pci_endpoint_test.c | 288 ++++++++++++------------------- 1 file changed, 108 insertions(+), 180 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 2ed7e3aaff3a8..55ae2f1851a13 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -103,6 +103,11 @@ enum pci_barno { BAR_5, }; +enum operation { + EPF_READ, + EPF_WRITE, +}; + struct pci_endpoint_test { struct pci_dev *pdev; void __iomem *base; @@ -142,6 +147,107 @@ static inline u32 pci_endpoint_test_bar_readl(struct pci_endpoint_test *test, { return readl(test->bar[bar] + offset); } +static bool pci_endpoint_test_transfer_data(struct pci_endpoint_test *test, + unsigned long arg, const enum operation operation) +{ + struct pci_endpoint_test_xfer_param param; + bool ret = false; + u32 flags = 0; + bool use_dma; + void *addr; + dma_addr_t phys_addr; + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + void *orig_addr; + dma_addr_t orig_phys_addr; + size_t offset; + size_t alignment = test->alignment; + int irq_type = test->irq_type; + size_t size; + int err; + + err = copy_from_user(¶m, (void __user *)arg, sizeof(param)); + if (err != 0) { + dev_err(dev, "Failed to get transfer param\n"); + return false; + } + + size = param.size; + if (size > SIZE_MAX - alignment) + goto err; + + use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA); + if (use_dma) + flags |= FLAG_USE_DMA; + + if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { + dev_err(dev, "Invalid IRQ type option\n"); + goto err; + } + + orig_addr = kzalloc(size + alignment, GFP_KERNEL); + if (!orig_addr) + goto err; + + get_random_bytes(orig_addr, size + alignment); + + orig_phys_addr = dma_map_single(dev, orig_addr, size + alignment, + operation == EPF_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE); + if (dma_mapping_error(dev, orig_phys_addr)) { + dev_err(dev, "failed to map source buffer address\n"); + goto err_phys_addr; + } + + if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) { + phys_addr = PTR_ALIGN(orig_phys_addr, alignment); + offset = phys_addr - orig_phys_addr; + addr = orig_addr + offset; + } else { + phys_addr = orig_phys_addr; + addr = orig_addr; + } + + if (operation == EPF_WRITE) { + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_CHECKSUM, + crc32_le(~0, addr, size)); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR, + lower_32_bits(phys_addr)); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_SRC_ADDR, + upper_32_bits(phys_addr)); + } else { + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR, + lower_32_bits(phys_addr)); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR, + upper_32_bits(phys_addr)); + } + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + + // if we ask rc to write to ep, then ep should do read operation, and vice versa. + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + operation == EPF_WRITE ? COMMAND_READ : COMMAND_WRITE); + + wait_for_completion(&test->irq_raised); + + dma_unmap_single(dev, orig_phys_addr, size + alignment, + operation == EPF_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE); + + if (operation == WRITE) + ret = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS) & STATUS_READ_SUCCESS; + else + ret = crc32_le(~0, addr, size) == pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM); + +err_phys_addr: + kfree(orig_addr); + +err: + return ret; +} static inline void pci_endpoint_test_bar_writel(struct pci_endpoint_test *test, int bar, u32 offset, u32 value) @@ -473,191 +579,13 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, static bool pci_endpoint_test_write(struct pci_endpoint_test *test, unsigned long arg) { - struct pci_endpoint_test_xfer_param param; - bool ret = false; - u32 flags = 0; - bool use_dma; - u32 reg; - void *addr; - dma_addr_t phys_addr; - struct pci_dev *pdev = test->pdev; - struct device *dev = &pdev->dev; - void *orig_addr; - dma_addr_t orig_phys_addr; - size_t offset; - size_t alignment = test->alignment; - int irq_type = test->irq_type; - size_t size; - u32 crc32; - int err; - - err = copy_from_user(¶m, (void __user *)arg, sizeof(param)); - if (err != 0) { - dev_err(dev, "Failed to get transfer param\n"); - return false; - } - - size = param.size; - if (size > SIZE_MAX - alignment) - goto err; - - use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA); - if (use_dma) - flags |= FLAG_USE_DMA; - - if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { - dev_err(dev, "Invalid IRQ type option\n"); - goto err; - } - - orig_addr = kzalloc(size + alignment, GFP_KERNEL); - if (!orig_addr) { - dev_err(dev, "Failed to allocate address\n"); - ret = false; - goto err; - } - - get_random_bytes(orig_addr, size + alignment); - - orig_phys_addr = dma_map_single(dev, orig_addr, size + alignment, - DMA_TO_DEVICE); - if (dma_mapping_error(dev, orig_phys_addr)) { - dev_err(dev, "failed to map source buffer address\n"); - ret = false; - goto err_phys_addr; - } - - if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) { - phys_addr = PTR_ALIGN(orig_phys_addr, alignment); - offset = phys_addr - orig_phys_addr; - addr = orig_addr + offset; - } else { - phys_addr = orig_phys_addr; - addr = orig_addr; - } - - crc32 = crc32_le(~0, addr, size); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_CHECKSUM, - crc32); - - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR, - lower_32_bits(phys_addr)); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_SRC_ADDR, - upper_32_bits(phys_addr)); - - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size); - - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, - COMMAND_READ); - - wait_for_completion(&test->irq_raised); - - reg = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); - if (reg & STATUS_READ_SUCCESS) - ret = true; - - dma_unmap_single(dev, orig_phys_addr, size + alignment, - DMA_TO_DEVICE); - -err_phys_addr: - kfree(orig_addr); - -err: - return ret; + return pci_endpoint_test_transfer_data(test, arg, EPF_WRITE); } static bool pci_endpoint_test_read(struct pci_endpoint_test *test, unsigned long arg) { - struct pci_endpoint_test_xfer_param param; - bool ret = false; - u32 flags = 0; - bool use_dma; - size_t size; - void *addr; - dma_addr_t phys_addr; - struct pci_dev *pdev = test->pdev; - struct device *dev = &pdev->dev; - void *orig_addr; - dma_addr_t orig_phys_addr; - size_t offset; - size_t alignment = test->alignment; - int irq_type = test->irq_type; - u32 crc32; - int err; - - err = copy_from_user(¶m, (void __user *)arg, sizeof(param)); - if (err) { - dev_err(dev, "Failed to get transfer param\n"); - return false; - } - - size = param.size; - if (size > SIZE_MAX - alignment) - goto err; - - use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA); - if (use_dma) - flags |= FLAG_USE_DMA; - - if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { - dev_err(dev, "Invalid IRQ type option\n"); - goto err; - } - - orig_addr = kzalloc(size + alignment, GFP_KERNEL); - if (!orig_addr) { - dev_err(dev, "Failed to allocate destination address\n"); - ret = false; - goto err; - } - - orig_phys_addr = dma_map_single(dev, orig_addr, size + alignment, - DMA_FROM_DEVICE); - if (dma_mapping_error(dev, orig_phys_addr)) { - dev_err(dev, "failed to map source buffer address\n"); - ret = false; - goto err_phys_addr; - } - - if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) { - phys_addr = PTR_ALIGN(orig_phys_addr, alignment); - offset = phys_addr - orig_phys_addr; - addr = orig_addr + offset; - } else { - phys_addr = orig_phys_addr; - addr = orig_addr; - } - - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR, - lower_32_bits(phys_addr)); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR, - upper_32_bits(phys_addr)); - - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size); - - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, - COMMAND_WRITE); - - wait_for_completion(&test->irq_raised); - - dma_unmap_single(dev, orig_phys_addr, size + alignment, - DMA_FROM_DEVICE); - - crc32 = crc32_le(~0, addr, size); - if (crc32 == pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM)) - ret = true; - -err_phys_addr: - kfree(orig_addr); -err: - return ret; + return pci_endpoint_test_transfer_data(test, arg, EPF_READ); } static bool pci_endpoint_test_clear_irq(struct pci_endpoint_test *test)