From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934560AbcIPNRs (ORCPT ); Fri, 16 Sep 2016 09:17:48 -0400 Received: from mail-co1nam03on0055.outbound.protection.outlook.com ([104.47.40.55]:35310 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756422AbcIPNRS (ORCPT ); Fri, 16 Sep 2016 09:17:18 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; From: Claudiu Manoil To: , Scott Wood CC: , Roy Pledge Subject: [PATCH 3/5] soc/bman: Add self-test for BMan driver Date: Fri, 16 Sep 2016 16:00:30 +0300 Message-ID: <1474030832-20611-4-git-send-email-claudiu.manoil@nxp.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1474030832-20611-1-git-send-email-claudiu.manoil@nxp.com> References: <1474030832-20611-1-git-send-email-claudiu.manoil@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131185044811738205;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(48376002)(47776003)(2950100001)(81166006)(97736004)(77096005)(305945005)(5660300001)(7846002)(50466002)(5003940100001)(6862003)(33646002)(36756003)(5001770100001)(189998001)(106466001)(105606002)(8666005)(229853001)(19580405001)(19580395003)(356003)(2906002)(575784001)(8676002)(68736007)(104016004)(81156014)(50986999)(86362001)(4326007)(76176999)(92566002)(11100500001)(626004)(586003)(87936001)(50226002)(8936002)(85426001)(7059030)(2004002)(4720700001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0301MB2011;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD042;1:z+Z0M6M1SjoCKAKJMstIVFw1i5gKYSOUvI1WmKAFZJaT0UIt9nsqG61gcfmKDUHkHD3PinXlSvOnRa07oSDvxEOsYMGDBZM15q+/6lrSXf/HGNBZfUpTHKhbUTK0ICbOtd4GF/wBuxwsasWiIrPZU3aqtaZ/V6qpkSWineptQSKaykBLM8P+4BAObwAGPUUGOIy5xCjC9Xe4HWasLMVH5ykUhbiqBMWPIkA5s6bv0HT2pWkvlCAA4vm4IZfpdBqp92AQF7nyAOStuHxlqN+pKdG1MhNiC2CvQnnVeLVGZ+7Wltz1VFTF5sE4BeiEgBWDxjzXwpQE7cGzFyXhYuyF1HSsBMqFqoFqAHZKWD0950xtDUkOJcipnJdvyIsAdUHJYWh7KJniAofosInseJE52DXC+5o/TMvgOfWwdXMccMx5PnSOPl7QIAnZAKuo78HcZErFxZmMLYZrU43jWNUkL1xSWVf3kS6ApItle/Nh9gYmrHtaA/0Em13k9g0PcP4v1PLJyVIPDvE1Ezeb+rK1b6CdjqOq53hN1LzSDR1rGNKmt9rrFXCa+iK1ilPMAC2MOUDJQ+oPYmJY193lDDoeK4p+aNofJeffReezSwvP0KCTYyfLX7PVCaciKbdrNne+UXEU2oqmElhoIUg7ckR+sEfqepv+Ki4niwnAFLEi3tdB9ms5lKiRsUmYse0dvrsBZ5VhlSrj03rqVukDsTS6zT5ysZ7i67ySBemaJpMTe3k= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 5ca23d59-8fe6-49d5-ec5d-08d3de318e4f X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2011;2:yvmW1gQcCYhox+Yl56maoV/kCsUSh8AyhHoReMXW8qL+aCKxkcD4rcsghFn5Z3eDDP5ay7hAcoXXr2OxKI6aZ4bhA8A3wtnEfIUy2rfLkx1yKls+M9yczuFss2zjfs6vQzRB5+fSLcKXtPGLrtQD77jcy6lrZWsuvg6hqqRBBQ4rDuNJfLIUMWfh4yURcy5K;3:3ri0PUDXevnSznM6qvlp9M71j+8HFu6DafmklIEZDTtQo1C4m13kWnJj17Dm3EW0mClcahRaYhk89G68uDh/dudS7WdnvZ8nuq5Ib01+5iIE+ILmep/6QFY0MxQTcSyBLmN9T3Cmq4r009f4mCsLDrlEvXACO5V1vjSqm6yNUiBwPJjLJ4QddclR4J4BtLOxs4I4F47KTUFzDVTxRS23cCcQVX1/2AWSPORwG6EUWeU= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB2011; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2011;25:XUErpQx+S92By0gFaWn+2V0k8R5Oj87bF0g8ffFDcDxSb9gr9vBW3lB48PDEsNZi2mPefpvQbbXPcmN1aheM7zP8RuheqRmnFCp8oqVKveRGo7GAEqmtHdOdMvjYdehEnvJWUr1aBTUTRU2HWVVt28d7l3illAdwlQS0O55LHJ+2ga0CC4ToV3V/lbLFWFMQR85KUxr1fpY8YXXS8UwBDTvi9EMJTSdbrAb/lgSF81H2TC/WpBjLAg1rJJytsQRQdUk3cmexLKIisF8J+yPSNHmouBYOjsqa5iv6jYYbCYelfXA89nYc0inFA98WAUir5StKDdcs+5OGTgiDFJqT9LdB/eZ1N2E6ytkwA++9f0WMFux6p+qVFYGD5CcDNZamuNarN0w8DTEPMaz7P/WqfhzRQ1ai6mGLEiKKD7TRHOD4FEUKWb22ikIG5mxd89nA0M5pIeRsmGjEMOduDKqU7NWw+Mt2CT5qvvr2WFGolfKPtVYiV884eNrEJbkk+VgiiQUAOdl41YxyEA+3h9NBMAJLFe9E04OhKRjJqjjPsdgumAJ8ZiMr0dbMjV0ldt7ZMoxtdI/pSqr8s4lzVns6LmsqXyqM33kxrBLi7mtDX7DKNHe3CgbBvcqGbxYxreEqU6obZTDwIclAXsa5WMfT9zLIUhYKopnx3bEVDTJP7HY2v6uMZBIj/pmdW+m/hvY/WKCotO874B7WuFBxQfJeJ85iKGTrKYx90MECx1Or4spHmlGpb5emJfeojTCfMJ0I X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2011;31:0q9s5tiUfJUGyWD/PPW8XM93h8BnOx2zXKQNiRRXIrwx0gezmbx8eSttsGbQWXFTUm/qgak8VXmtaxr3hCB2KuDdixrjPXhKGKqgJnm5heXz//aoaSkOL+oB62cjVgV/vg5THuLD0qYIavE//QO/iiHdvaSpWcqAy33UxI+M/KzfzdZfDhkHJdMcmlNkwjS9gQceFK5JOJ4N8ByI8+mpzQYNBgcANH2vC2PUmV+UcIM=;4:n4xnOKHtWrSoARPdfHVzlm1QJaUHNLJkssT7bZEjTUC3EnP/L2SNeKWD/AN4uJizvtyX42gPR6fRnI8VVdEZtmhJNsgjbrrgCHjVN35kDgQhAeKWoQVFDIE11jUej/nmtj09dyXMRKv+5tqROHXvmDtrvZNcsN+19dVoYoOP4nDKco+stuWcKuY34Sn8/yQXyHdDL+gGrIRoWxhn6SfNuY4I4zbVTNW8m0Q5asijWLJ4h3oW8Lva/CNfJ89gnKWooFkyjuTrm0cmde3wXKl6/VCS8rmbiSZKy9O7lqRd8qDjEV+IOZafNh6uSWpgBfIdUkpRj6fxcN6gP9zUeT33Snsw47fKLzV6FSBDUF2eRPIOaXSoomcxMXR9PSmRjXZwWj6twnwTksBlsOgJjFifCNAKBzPmIhnJC0qM8zqyy+RCIWLZ/GIKIaaU5T0s+eJMA1ZQA15A0BaS9pA7UBxIqNacQ2YPsse7/L7oZ2lTGUSeXLUKUI121F0N2wL3fdmeHGoD5pUpZipGHWX63E2bWzUnOuLXkBRpE2D3aucomAbYwZSJwco+1onRerjGN2hkhemA0qSooRS2665gFXLex4G4ffyy3RqU5VjcyZLoxUg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(227817650892897)(275809806118684); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(13017025)(5005006)(8121501046)(13015025)(13024025)(13023025)(13018025)(10201501046)(3002001)(6055026);SRVR:CY1PR0301MB2011;BCL:0;PCL:0;RULEID:(400006);SRVR:CY1PR0301MB2011; X-Forefront-PRVS: 0067A8BA2A X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB2011;23:Slm7NYxCtdswwXFO9MccZfALvUAESIrQgZVAYJC?= =?us-ascii?Q?KX71sZ3SXisOjc1BaoeXr33XTx+Q/CHvuOBzBMANU9O0V3dxQM37Uq4iNnQx?= =?us-ascii?Q?5Hwa+6Yti8ZqinrICgYZQAQynEO2BWVyLOQ6aghFniArGqtQzBfFN8OZ79pv?= =?us-ascii?Q?vleEvI6+CDtRLfIetKF5Kiv0PJMuwZwq2XfhCR1mtVpKuOemSHJsZ0BqvHdZ?= =?us-ascii?Q?oWf/ZEE48n6YW/Pyd6dbCMCOOOYbR6TFpfECwPP058VkUa6Md0tS+nJt9NLA?= =?us-ascii?Q?EKxO8qe0Nz1ESKjKVgOUK+uuYiV1h2MmfCrE4Ij0hdaOJGOFdt2OBsxaAhtZ?= =?us-ascii?Q?UrUJl/k1GUGgbgp+3X8CyRvtt5vn5JTIoidzbAaTSHWSWnJSbjU0SL23QnlE?= =?us-ascii?Q?gQjyd6Jg4Gey5j/KLrnjhTgX738sKHZ7btanqo3nkmwLevhGid8/pb7JVoiO?= =?us-ascii?Q?0+e8aSD87kedblyx9Lgiin/H+mcOk1X2pJl8nSkND8Ys7gk/+jqugrxqkh4s?= =?us-ascii?Q?19HOKro3vND792UKS+uo1518nTXMqWtnsdtBCTKeRPzbwbL2O7inCTWh7HbV?= =?us-ascii?Q?G29LX4VfVtPquUjS512BHRTM66SEF/nBx9BknDefTMPB68clJqX0QfOqaY6P?= =?us-ascii?Q?It8Ewqv4jzgchAuKPP/l6g9bOoua/JoIPc6WPjq/6hIdaxicr3xqomjlMXpL?= =?us-ascii?Q?dGdyPa7/50yWvny09dCV6+6Qtuv998rEPzdj9gDQQriLkwfLxrzZ41NVYpPc?= =?us-ascii?Q?mkNQWNy+R+9qfBPBys72XZO0RV0DJ72Ylnr/IDjTxO9NEfwazJRklJBeN0V+?= =?us-ascii?Q?pAaRcWVy+W7afisaVXEdCho6++BAWpun6Jy1/8KdHmW6aanhyRswOviRKXzW?= =?us-ascii?Q?YHbfT1HjujwyowuJ8yMacueJ5MgNJjVbbfmaEsifnihRkLFf7o4gVB9ZgZwi?= =?us-ascii?Q?JAd1b5HL2qemDTogT4mOSWiEIfbLvtxU0Vs8W/g028u3G7tcqrPXtm9OsoWh?= =?us-ascii?Q?f6d+rS7ZMfXWAZwn7mF2jZjpPMp4V0bsMJ+mAdJXetxI1aDx0/VKfD58iIFF?= =?us-ascii?Q?Ug0l57/qxlLYNpvj/iIbxwgjKc2Xj8C4kZnh+YoE9I1TP29BKc+NGZIJgxYq?= =?us-ascii?Q?vCiIyML5oKmDHqjWrfFfD8CFjxE+lNN98t9vIYizV8OvgJZAP6+9h13VQNL8?= =?us-ascii?Q?L0ykBR/BTWR95oIlvl6agE5Rg8Emcqu/+BuZJ2HfiVrhIbAIbV+SZXDlqn+X?= =?us-ascii?Q?+jS2p0AOCl755pG6XJis=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2011;6:CLyPcMqpZ1Pg7wsgNtJheZW8AZC9qwSV4ug63pLP0+dgppA2XreD8RfZV346+CBfth6e3DieVR2ENm6JXpTHH2+CdNlNHr9A/CyKv98bdaAKUMn6mYM53nenfSVY472LfHQxT155n/URe1ME65Hv08K4BPgTWpjF1QzjUle04iaHCs/9KlcWqsd/74HPwBKsmhdqF+Q9cGYO/65U4UT58OoS6aFPttCKs/vSNev4oGp1NmHELx1GByKO8kdzOCIUq7tygf2jq5z9h55Ibrlwf6SITqSz0DyGA2z/97rHdSo=;5:aeBQzYDseAoQ8khz4JBZiif5O9QixIoQIfAx0JfZKm/rkUMXyquMnz42XArhJs2aNi/9hhLteh7Kwik+SbgMdIK8oftuyKgwyTWJbaJyaSMkLfx39Idp34n32uAci6+k7eWPNVNFK9po29u6PrCXhcBAr+5CdcoYGZYnil+5wqs=;24:vekLfu0IgWH4EnSxIxqqdgqufRcQND4jsbYimUUxQM9qqaSN5a5o7hcCGzGsA+yM9LiGI1kTVhLDTft1QiXnlhWGgGOF1qLj24tLxykib1g=;7:M2gZLtRW1+w6kB0HDlh7RVkvNGLsa3kj7VdY+GrQRhQPcRV945rLIGQABBMAoJb67/TAe1AbXhtOJb7LJdZ45K3sdD4Fa6/HD6VUi12DBa4EKBMw5MInq0rv3IlSYDoue7UePwsm2j78fDf6nb5NFTOYN+Gi/WWnyG1ile9eg+5nelJLAg2LW8RLR4RoTdrmPW77mzdTdbOdkS8ofxYruAkDiyIuOKcQgaFYNxxpOIXbB1lz4xLgH0dybcytlh/V SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2016 13:01:21.0022 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB2011 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a self test for the DPAA 1.x Buffer Manager driver. This test ensures that the driver can properly acquire and release buffers using the BMan portal infrastructure. Signed-off-by: Roy Pledge Signed-off-by: Claudiu Manoil --- drivers/soc/fsl/qbman/Kconfig | 16 ++++ drivers/soc/fsl/qbman/Makefile | 4 + drivers/soc/fsl/qbman/bman_test.c | 53 ++++++++++++ drivers/soc/fsl/qbman/bman_test.h | 35 ++++++++ drivers/soc/fsl/qbman/bman_test_api.c | 151 ++++++++++++++++++++++++++++++++++ 5 files changed, 259 insertions(+) create mode 100644 drivers/soc/fsl/qbman/bman_test.c create mode 100644 drivers/soc/fsl/qbman/bman_test.h create mode 100644 drivers/soc/fsl/qbman/bman_test_api.c diff --git a/drivers/soc/fsl/qbman/Kconfig b/drivers/soc/fsl/qbman/Kconfig index 0abb9c8..5e4b288 100644 --- a/drivers/soc/fsl/qbman/Kconfig +++ b/drivers/soc/fsl/qbman/Kconfig @@ -25,4 +25,20 @@ config FSL_DPAA_CHECKING Compiles in additional checks, to sanity-check the drivers and any use of the exported API. Not recommended for performance. +config FSL_BMAN_TEST + tristate "BMan self-tests" + help + Compile the BMan self-test code. These tests will + exercise the BMan APIs to confirm functionality + of both the software drivers and hardware device. + +config FSL_BMAN_TEST_API + bool "High-level API self-test" + depends on FSL_BMAN_TEST + default y + help + This requires the presence of cpu-affine portals, and performs + high-level API testing with them (whichever portal(s) are affine + to the cpu(s) the test executes on). + endif # FSL_DPAA diff --git a/drivers/soc/fsl/qbman/Makefile b/drivers/soc/fsl/qbman/Makefile index 6e0ee30..714dd97 100644 --- a/drivers/soc/fsl/qbman/Makefile +++ b/drivers/soc/fsl/qbman/Makefile @@ -1,3 +1,7 @@ obj-$(CONFIG_FSL_DPAA) += bman_ccsr.o qman_ccsr.o \ bman_portal.o qman_portal.o \ bman.o qman.o + +obj-$(CONFIG_FSL_BMAN_TEST) += bman-test.o +bman-test-y = bman_test.o +bman-test-$(CONFIG_FSL_BMAN_TEST_API) += bman_test_api.o diff --git a/drivers/soc/fsl/qbman/bman_test.c b/drivers/soc/fsl/qbman/bman_test.c new file mode 100644 index 0000000..09b1c96 --- /dev/null +++ b/drivers/soc/fsl/qbman/bman_test.c @@ -0,0 +1,53 @@ +/* Copyright 2008 - 2016 Freescale Semiconductor, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "bman_test.h" + +MODULE_AUTHOR("Geoff Thorpe"); +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_DESCRIPTION("BMan testing"); + +static int test_init(void) +{ +#ifdef CONFIG_FSL_BMAN_TEST_API + int loop = 1; + + while (loop--) + bman_test_api(); +#endif + return 0; +} + +static void test_exit(void) +{ +} + +module_init(test_init); +module_exit(test_exit); diff --git a/drivers/soc/fsl/qbman/bman_test.h b/drivers/soc/fsl/qbman/bman_test.h new file mode 100644 index 0000000..037ed34 --- /dev/null +++ b/drivers/soc/fsl/qbman/bman_test.h @@ -0,0 +1,35 @@ +/* Copyright 2008 - 2016 Freescale Semiconductor, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "bman_priv.h" + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +void bman_test_api(void); diff --git a/drivers/soc/fsl/qbman/bman_test_api.c b/drivers/soc/fsl/qbman/bman_test_api.c new file mode 100644 index 0000000..6f6bdd1 --- /dev/null +++ b/drivers/soc/fsl/qbman/bman_test_api.c @@ -0,0 +1,151 @@ +/* Copyright 2008 - 2016 Freescale Semiconductor, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "bman_test.h" + +#define NUM_BUFS 93 +#define LOOPS 3 +#define BMAN_TOKEN_MASK 0x00FFFFFFFFFFLLU + +static struct bman_pool *pool; +static struct bm_buffer bufs_in[NUM_BUFS] ____cacheline_aligned; +static struct bm_buffer bufs_out[NUM_BUFS] ____cacheline_aligned; +static int bufs_received; + +static void bufs_init(void) +{ + int i; + + for (i = 0; i < NUM_BUFS; i++) + bm_buffer_set64(&bufs_in[i], 0xfedc01234567LLU * i); + bufs_received = 0; +} + +static inline int bufs_cmp(const struct bm_buffer *a, const struct bm_buffer *b) +{ + if (bman_ip_rev == BMAN_REV20 || bman_ip_rev == BMAN_REV21) { + + /* + * On SoCs with BMan revison 2.0, BMan only respects the 40 + * LS-bits of buffer addresses, masking off the upper 8-bits on + * release commands. The API provides for 48-bit addresses + * because some SoCs support all 48-bits. When generating + * garbage addresses for testing, we either need to zero the + * upper 8-bits when releasing to BMan (otherwise we'll be + * disappointed when the buffers we acquire back from BMan + * don't match), or we need to mask the upper 8-bits off when + * comparing. We do the latter. + */ + if ((bm_buffer_get64(a) & BMAN_TOKEN_MASK) < + (bm_buffer_get64(b) & BMAN_TOKEN_MASK)) + return -1; + if ((bm_buffer_get64(a) & BMAN_TOKEN_MASK) > + (bm_buffer_get64(b) & BMAN_TOKEN_MASK)) + return 1; + } else { + if (bm_buffer_get64(a) < bm_buffer_get64(b)) + return -1; + if (bm_buffer_get64(a) > bm_buffer_get64(b)) + return 1; + } + + return 0; +} + +static void bufs_confirm(void) +{ + int i, j; + + for (i = 0; i < NUM_BUFS; i++) { + int matches = 0; + + for (j = 0; j < NUM_BUFS; j++) + if (!bufs_cmp(&bufs_in[i], &bufs_out[j])) + matches++; + WARN_ON(matches != 1); + } +} + +/* test */ +void bman_test_api(void) +{ + int i, loops = LOOPS; + + bufs_init(); + + pr_info("%s(): Starting\n", __func__); + + pool = bman_new_pool(); + if (!pool) { + pr_crit("bman_new_pool() failed\n"); + goto failed; + } + + /* Release buffers */ +do_loop: + i = 0; + while (i < NUM_BUFS) { + int num = 8; + + if (i + num > NUM_BUFS) + num = NUM_BUFS - i; + if (bman_release(pool, bufs_in + i, num)) { + pr_crit("bman_release() failed\n"); + goto failed; + } + i += num; + } + + /* Acquire buffers */ + while (i > 0) { + int tmp, num = 8; + + if (num > i) + num = i; + tmp = bman_acquire(pool, bufs_out + i - num, num); + WARN_ON(tmp != num); + i -= num; + } + i = bman_acquire(pool, NULL, 1); + WARN_ON(i > 0); + + bufs_confirm(); + + if (--loops) + goto do_loop; + + /* Clean up */ + bman_free_pool(pool); + pr_info("%s(): Finished\n", __func__); + return; + +failed: + WARN_ON(1); +} -- 1.7.11.7