get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/130858/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 130858,
    "url": "http://patchwork.dpdk.org/api/patches/130858/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20230830021457.2064750-21-chaoyong.he@corigine.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20230830021457.2064750-21-chaoyong.he@corigine.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230830021457.2064750-21-chaoyong.he@corigine.com",
    "date": "2023-08-30T02:14:50",
    "name": "[v2,20/27] net/nfp: refact the mutex module",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "94a37a20dc98878a01f68a772a3e1c12f08ee83c",
    "submitter": {
        "id": 2554,
        "url": "http://patchwork.dpdk.org/api/people/2554/?format=api",
        "name": "Chaoyong He",
        "email": "chaoyong.he@corigine.com"
    },
    "delegate": {
        "id": 319,
        "url": "http://patchwork.dpdk.org/api/users/319/?format=api",
        "username": "fyigit",
        "first_name": "Ferruh",
        "last_name": "Yigit",
        "email": "ferruh.yigit@amd.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20230830021457.2064750-21-chaoyong.he@corigine.com/mbox/",
    "series": [
        {
            "id": 29363,
            "url": "http://patchwork.dpdk.org/api/series/29363/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=29363",
            "date": "2023-08-30T02:14:30",
            "name": "refact the nfpcore module",
            "version": 2,
            "mbox": "http://patchwork.dpdk.org/series/29363/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/130858/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/130858/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 986C641FC8;\n\tWed, 30 Aug 2023 04:18:24 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 5ECD940A76;\n\tWed, 30 Aug 2023 04:16:07 +0200 (CEST)",
            "from NAM10-DM6-obe.outbound.protection.outlook.com\n (mail-dm6nam10on2121.outbound.protection.outlook.com [40.107.93.121])\n by mails.dpdk.org (Postfix) with ESMTP id 5C2DC4064E\n for <dev@dpdk.org>; Wed, 30 Aug 2023 04:16:04 +0200 (CEST)",
            "from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5)\n by DM6PR13MB3786.namprd13.prod.outlook.com (2603:10b6:5:229::11) with\n Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.18; Wed, 30 Aug\n 2023 02:16:02 +0000",
            "from SJ0PR13MB5545.namprd13.prod.outlook.com\n ([fe80::c0f3:c2cc:b5bb:4192]) by SJ0PR13MB5545.namprd13.prod.outlook.com\n ([fe80::c0f3:c2cc:b5bb:4192%4]) with mapi id 15.20.6699.034; Wed, 30 Aug 2023\n 02:16:02 +0000"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;\n b=ChFTAu7BB5rxHHPNYrYTXbmGprLrQPicK2NrcGepz+vD84VYvV5CpZ945JKS02u/B1hzgjV5js+sWXUR/mjqG1AE3JB2Tb5Jil5b5ZqHkXNQvA2nyJi3M1HM2EBTKK7qQ/VctzBo91D2Yv1RA2nXYIRF0JfYri9YEArmrOps6nencndQhS9xisfoYQFgQgCp48rbh4gyj0CH/E//8PYX7CX5Q9k5pF4B4JDvOC63wo5FLMjirdmJCD1rXaaK5xcYI6vFgZQKz6bIutTnwjiF1OlwyiG6jPaQzl8fh+BeTY5wRStpMHUu/t444oLdh4ge23TGVBg2vKpUUryzmLOKVA==",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n s=arcselector9901;\n 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;\n bh=PW2xHWL6QNyk3Ff7FWSfXySy6+lIgvRhxzehARxsxgc=;\n b=nAWdido8QVihu2/xDsFgwXmzWrAnZA7t/YfSKWUh6J0G0uYJq/Zle9oQES7Qpo9TBMHAnJ0NlMhrjXZAe2u/MrB/oSn+OHrGQfmtlg1TtVTZZ1ymv/TXI/QEvQ3+1+OLLEGtkJS1zOgP9ycbYGwH2btyL9qIpMaexNGMB+OQZECqU9S1inl/jpoPbvklSJHCafzK9pSviVPDMaqjKu+u0fk9PDX+eDAA+Ogu7mUKtBI4xqGQIHTN47SyfFbhxX/6NSzed+Jh6mVDOtoYNm7ScVuoI5d/8JC7LrJ4/kysIY/X4rR5f0kh7ACDGz8rrLwuH8Un9eIqr5NyjXP62HNttg==",
        "ARC-Authentication-Results": "i=1; mx.microsoft.com 1; spf=pass\n smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com;\n dkim=pass header.d=corigine.com; arc=none",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n bh=PW2xHWL6QNyk3Ff7FWSfXySy6+lIgvRhxzehARxsxgc=;\n b=C0ITUEPNexH72FuiLF2cgPKG2c0UDocX9uKEo55qLngyDfKv9C32eGvJGlLY0PuK5eHs0dwgvFXgg49KtdG38ry8OmpmlPgFtWmvdt8WTfL/C1MJHWUIoqEL4zWxXQWGYKApLpDNJXI/ffJGBF4l4w4uiyZ0u8dt7zJKJYT6JeE=",
        "Authentication-Results": "dkim=none (message not signed)\n header.d=none;dmarc=none action=none header.from=corigine.com;",
        "From": "Chaoyong He <chaoyong.he@corigine.com>",
        "To": "dev@dpdk.org",
        "Cc": "oss-drivers@corigine.com, niklas.soderlund@corigine.com,\n Chaoyong He <chaoyong.he@corigine.com>",
        "Subject": "[PATCH v2 20/27] net/nfp: refact the mutex module",
        "Date": "Wed, 30 Aug 2023 10:14:50 +0800",
        "Message-Id": "<20230830021457.2064750-21-chaoyong.he@corigine.com>",
        "X-Mailer": "git-send-email 2.39.1",
        "In-Reply-To": "<20230830021457.2064750-1-chaoyong.he@corigine.com>",
        "References": "<20230824110956.1943559-1-chaoyong.he@corigine.com>\n <20230830021457.2064750-1-chaoyong.he@corigine.com>",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "X-ClientProxiedBy": "PH0PR07CA0113.namprd07.prod.outlook.com\n (2603:10b6:510:4::28) To SJ0PR13MB5545.namprd13.prod.outlook.com\n (2603:10b6:a03:424::5)",
        "MIME-Version": "1.0",
        "X-MS-PublicTrafficType": "Email",
        "X-MS-TrafficTypeDiagnostic": "SJ0PR13MB5545:EE_|DM6PR13MB3786:EE_",
        "X-MS-Office365-Filtering-Correlation-Id": "2a82a9ea-d404-42c8-30bb-08dba8ff0ef3",
        "X-MS-Exchange-SenderADCheck": "1",
        "X-MS-Exchange-AntiSpam-Relay": "0",
        "X-Microsoft-Antispam": "BCL:0;",
        "X-Microsoft-Antispam-Message-Info": "\n BTannSoWbzdp4VipzR0ztAFc7nG/TmnsnPsV5WwrFP7izGL28mYVZo7gRex3uG1BC9jUybXlfTcJZT2bB9AuFemPzqw4yoBSprVcw6M9LXZCc3Ot5Aj1xubqV/5ye0VeYK1ffhYzLr3sUb6gzQ6uTYNofrc7k6kfU2iozHZhUcLieN8KeAQDN/X+MYBy2ScsWGtvXaep0RbZ+owS2ssyfaBEbWpsGf16VbAyABMBJOGg4QRfxLk3r2EIDVvX5A+Y/xH7qOkrC4if6hdKvvBiwMCcHttKbhyDio3dDnphVGF1DyxJ2FPiap8AHQgVuaeHfC/ElVu8NhJFuOs9SxwM0vtoXf2Np/1mDQSqAQD3i9D4wi1zg87b9icIuM14GOegPBZRmH+YNldrOyYgPjvWJpCaKxU/zp96WOhOl/8qJZiMIwyqVbbA/DtSIvmShpkUrjOYakL4X+K1omLGUPwOkdfLFBkUuk40u4Hl5X4yJwTO5ramRfrsP9J8sBx/Kv4LASve6C60ZzGvmsjyqwUKdzWPe07fvMFleCeR1j4usVeUZlNyetnL9Pt+7jGJFXn6id2uwTynq1VC0oHQorvuy+6ji7e4Mm/N0nUP4hFKuroOrak/P+mfp9OsY7ONsIosUlJGUXlNJDkxQyAXadSNy0BDJd4OTlbff6U7vTRKNKM=",
        "X-Forefront-Antispam-Report": "CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;\n IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE;\n SFS:(13230031)(136003)(366004)(376002)(346002)(396003)(39830400003)(451199024)(186009)(1800799009)(6512007)(6916009)(316002)(38100700002)(41300700001)(38350700002)(2906002)(4326008)(66574015)(30864003)(83380400001)(2616005)(86362001)(44832011)(26005)(36756003)(1076003)(8676002)(5660300002)(107886003)(8936002)(6666004)(6506007)(6486002)(66556008)(66946007)(66476007)(52116002)(478600001);\n DIR:OUT; SFP:1102;",
        "X-MS-Exchange-AntiSpam-MessageData-ChunkCount": "1",
        "X-MS-Exchange-AntiSpam-MessageData-0": "=?utf-8?q?qOuemsN7KevcbNAOM4JGF2UZ17kb?=\n\t=?utf-8?q?nW9d9j9tLl8ONtwkQZO23fDQIHXTlUi9qx+UWqzkkJtHbx1osggHpCF5JAFJOC+5H?=\n\t=?utf-8?q?aFpbMesGtRfJ9DwHHkAO/p/JSo/XlnQMWWG1Qca0zbsH8NCdm9V9ngLHCWOe9GVDc?=\n\t=?utf-8?q?hnDNVo/b8M8a+FBigIh3T9ikj7gEyXcYh4Qae64xa1YsygHkZEvRAGjcY37fGQC1K?=\n\t=?utf-8?q?BMyfAcemqWjJpT1/FiTfhNkAc1V7bmLYwDb+Rs0Y9hXzQxtUdta2woui7VBQIRq0D?=\n\t=?utf-8?q?x/gYHH0aNFzegTtc55Es12iQ2RaVVQCMVD8nZLXwB1LiD3KE0UFA2Dk99Hz6620hR?=\n\t=?utf-8?q?TXm7RIPrXEm5A+jaupJpCogb2iFsVGIRv9QnbWE3e+rJa/souiNSaZDY5u5nNaav8?=\n\t=?utf-8?q?nzAmCu3uOmsA3u5USczM+rMvxN8QCjIl0SQQxXIQoaUG8IjaTKPvLiqYOLB04vxqv?=\n\t=?utf-8?q?2eRpyDmX1aGU7R5R5ubnzZLqCMZ0O7DvdxKQPxPedayVHDY+WuAP2Km4BSVcNRSJZ?=\n\t=?utf-8?q?h++AvS80oxfWN+3dLTDlYknu8X6BKcPARJbTF3CVV+PfM+HhWL2eahz+9v2d5OwVJ?=\n\t=?utf-8?q?vE9y6CREwK+ygNiouG37vx+9ktILDnih9fBLbZGvbO3cjwG6dBza88pmTFyD3uMgc?=\n\t=?utf-8?q?LqMD15amY32z1khaG0rI+PSJ1BfiNTIyi1DW76jJb0xW3aYLrGshlG8Ebw+8FU4p3?=\n\t=?utf-8?q?7Ei6qOblv1y78/rDmb9EaO+auR373vjYl3cAT6O4TR6hHub0FonYqAxmqz0cNlcqy?=\n\t=?utf-8?q?PXa61PDrZg4BuZwnaRIWf5ORBhp6HnKRtu4XUSMAevHh4y1KdSZ6YoJdQ9S/4II5C?=\n\t=?utf-8?q?5rkKHIDanjPPq+PYppP/b7HC9IKzLD6TEV0mPTkiHbL0HG32kIDRydohh6epCYfL2?=\n\t=?utf-8?q?1jn8pBkl7bFvmhJYO8bOvAFydsr5Zs4Xzwl1EYq3era0rG78gl5y85gN+6d4udOzh?=\n\t=?utf-8?q?GSHxojBfI442B+RFmriTYJxJTJ/a1phl3VhdE6aCI4HB1oLRrrwZ3mZ3nlgJBNa5K?=\n\t=?utf-8?q?ftdu7hSFxNZnpKTic2wyrt1DTgrb1CPpNf3ACBrTSZzCC9pBCffJbRTy19wqFwWmF?=\n\t=?utf-8?q?3+5gN/MzBhIO/sqYs8KBA/FtcmeRhXDOG2xjiqgV9lJH0KXo0VhF1bDUMs+qyMQ9y?=\n\t=?utf-8?q?otMZ7iGWysKsxzZcs8BeoCfxEAuoajFbyIfn66V5hM48gnNGpzP/iwzsLnw7TsSRm?=\n\t=?utf-8?q?Ll1797s7GhcjE2GOJe1mRpHIi1a8NU3cTKuQMxPbtczBySuMrBuFTrrqspaRtKdc2?=\n\t=?utf-8?q?C53VcjILl4guPf36i1vMtP8Sw1Ra24XA9loBhgXAKJ1Bx/GpPVpmF7ounxgtktGPp?=\n\t=?utf-8?q?TdFJHue/0meEUk1YL4Uz9ohJUpHlODg8n/U1lKc6h8kx9ZYXSVqb0tnE9Z3lYVcvb?=\n\t=?utf-8?q?9zbWGwxl0sIULOgsGUX6lFbOfX8P6D8/uGnpHQyU4QEV5gDD7mNNOqQ2H8FJubJ/3?=\n\t=?utf-8?q?oqemcMKptMYhNml75KLWW2MnJ2EjliYEFLbPgDQZrtcjQ1UBp7p6RtH21AxihRqxF?=\n\t=?utf-8?q?aCplltsvb4CPDek1vdc06QmuSd5ReIyKkQ=3D=3D?=",
        "X-OriginatorOrg": "corigine.com",
        "X-MS-Exchange-CrossTenant-Network-Message-Id": "\n 2a82a9ea-d404-42c8-30bb-08dba8ff0ef3",
        "X-MS-Exchange-CrossTenant-AuthSource": "SJ0PR13MB5545.namprd13.prod.outlook.com",
        "X-MS-Exchange-CrossTenant-AuthAs": "Internal",
        "X-MS-Exchange-CrossTenant-OriginalArrivalTime": "30 Aug 2023 02:16:02.7543 (UTC)",
        "X-MS-Exchange-CrossTenant-FromEntityHeader": "Hosted",
        "X-MS-Exchange-CrossTenant-Id": "fe128f2c-073b-4c20-818e-7246a585940c",
        "X-MS-Exchange-CrossTenant-MailboxType": "HOSTED",
        "X-MS-Exchange-CrossTenant-UserPrincipalName": "\n ytvlFI579d7RnD53R2AxwUiXadBFCDl9B/BJ4i8s4E/n5zcOckVKHPXrOsuSUye0j2Jm8RQkTERhc8/fRqQG2+Buu37yxIum7N6/HyAkc1Y=",
        "X-MS-Exchange-Transport-CrossTenantHeadersStamped": "DM6PR13MB3786",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "Add a header file to holds the API declarations of this module.\nAlso sync the logic from kernel driver and remove the unneeded header\nfile include statements.\n\nSigned-off-by: Chaoyong He <chaoyong.he@corigine.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>\n---\n drivers/net/nfp/nfpcore/nfp_cpp.h      |  16 --\n drivers/net/nfp/nfpcore/nfp_mutex.c    | 205 ++++++++++++++-----------\n drivers/net/nfp/nfpcore/nfp_mutex.h    |  25 +++\n drivers/net/nfp/nfpcore/nfp_resource.c |   1 +\n 4 files changed, 138 insertions(+), 109 deletions(-)\n create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h",
    "diff": "diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h\nindex be7ae1d919..42c4df5fdd 100644\n--- a/drivers/net/nfp/nfpcore/nfp_cpp.h\n+++ b/drivers/net/nfp/nfpcore/nfp_cpp.h\n@@ -8,8 +8,6 @@\n \n #include <ethdev_pci.h>\n \n-struct nfp_cpp_mutex;\n-\n /* NFP CPP handle */\n struct nfp_cpp {\n \tuint32_t model;\n@@ -426,20 +424,6 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id,\n int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id,\n \t\tuint64_t address, uint64_t value);\n \n-int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target,\n-\t\tuint64_t address, uint32_t key_id);\n-\n-struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target,\n-\t\tuint64_t address, uint32_t key_id);\n-\n-void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex);\n-\n-int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex);\n-\n-int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex);\n-\n-int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex);\n-\n uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp);\n \n #endif /* __NFP_CPP_H__ */\ndiff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c\nindex 87a9351ff9..9363543422 100644\n--- a/drivers/net/nfp/nfpcore/nfp_mutex.c\n+++ b/drivers/net/nfp/nfpcore/nfp_mutex.c\n@@ -3,21 +3,13 @@\n  * All rights reserved.\n  */\n \n-#include <malloc.h>\n-#include <time.h>\n+#include \"nfp_mutex.h\"\n+\n #include <sched.h>\n \n-#include \"nfp_cpp.h\"\n #include \"nfp_logs.h\"\n #include \"nfp_target.h\"\n \n-#define MUTEX_LOCKED(interface)  ((((uint32_t)(interface)) << 16) | 0x000f)\n-#define MUTEX_UNLOCK(interface)  (0                               | 0x0000)\n-\n-#define MUTEX_IS_LOCKED(value)   (((value) & 0xffff) == 0x000f)\n-#define MUTEX_IS_UNLOCKED(value) (((value) & 0xffff) == 0x0000)\n-#define MUTEX_INTERFACE(value)   (((value) >> 16) & 0xffff)\n-\n /*\n  * If you need more than 65536 recursive locks, please\n  * rethink your code.\n@@ -34,21 +26,51 @@ struct nfp_cpp_mutex {\n \tstruct nfp_cpp_mutex *prev, *next;\n };\n \n+static inline uint32_t\n+nfp_mutex_locked(uint16_t interface)\n+{\n+\treturn (uint32_t)interface << 16 | 0x000f;\n+}\n+\n+static inline uint32_t\n+nfp_mutex_unlocked(uint16_t interface)\n+{\n+\treturn (uint32_t)interface << 16 | 0x0000;\n+}\n+\n+static inline uint16_t\n+nfp_mutex_owner(uint32_t val)\n+{\n+\treturn (val >> 16) & 0xffff;\n+}\n+\n+static inline bool\n+nfp_mutex_is_locked(uint32_t val)\n+{\n+\treturn (val & 0xffff) == 0x000f;\n+}\n+\n+static inline bool\n+nfp_mutex_is_unlocked(uint32_t val)\n+{\n+\treturn (val & 0xffff) == 0;\n+}\n+\n static int\n-nfp_cpp_mutex_validate(uint32_t model,\n+nfp_cpp_mutex_validate(uint16_t interface,\n \t\tint *target,\n \t\tuint64_t address)\n {\n+\t/* Not permitted on invalid interfaces */\n+\tif (NFP_CPP_INTERFACE_TYPE_of(interface) == NFP_CPP_INTERFACE_TYPE_INVALID)\n+\t\treturn -EINVAL;\n+\n \t/* Address must be 64-bit aligned */\n \tif ((address & 7) != 0)\n \t\treturn -EINVAL;\n \n-\tif (NFP_CPP_MODEL_IS_6000(model)) {\n-\t\tif (*target != NFP_CPP_TARGET_MU)\n-\t\t\treturn -EINVAL;\n-\t} else {\n+\tif (*target != NFP_CPP_TARGET_MU)\n \t\treturn -EINVAL;\n-\t}\n \n \treturn 0;\n }\n@@ -84,10 +106,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp,\n \t\tuint32_t key)\n {\n \tint err;\n-\tuint32_t model = nfp_cpp_model(cpp);\n \tuint32_t muw = NFP_CPP_ID(target, 4, 0);    /* atomic_write */\n+\tuint16_t interface = nfp_cpp_interface(cpp);\n \n-\terr = nfp_cpp_mutex_validate(model, &target, address);\n+\terr = nfp_cpp_mutex_validate(interface, &target, address);\n \tif (err < 0)\n \t\treturn err;\n \n@@ -95,8 +117,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp,\n \tif (err < 0)\n \t\treturn err;\n \n-\terr = nfp_cpp_writel(cpp, muw, address + 0,\n-\t\t\tMUTEX_LOCKED(nfp_cpp_interface(cpp)));\n+\terr = nfp_cpp_writel(cpp, muw, address, nfp_mutex_locked(interface));\n \tif (err < 0)\n \t\treturn err;\n \n@@ -133,26 +154,10 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp,\n \tint err;\n \tuint32_t tmp;\n \tstruct nfp_cpp_mutex *mutex;\n-\tuint32_t model = nfp_cpp_model(cpp);\n \tuint32_t mur = NFP_CPP_ID(target, 3, 0);    /* atomic_read */\n+\tuint16_t interface = nfp_cpp_interface(cpp);\n \n-\t/* Look for cached mutex */\n-\tfor (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) {\n-\t\tif (mutex->target == target && mutex->address == address)\n-\t\t\tbreak;\n-\t}\n-\n-\tif (mutex) {\n-\t\tif (mutex->key == key) {\n-\t\t\tmutex->usage++;\n-\t\t\treturn mutex;\n-\t\t}\n-\n-\t\t/* If the key doesn't match... */\n-\t\treturn NULL;\n-\t}\n-\n-\terr = nfp_cpp_mutex_validate(model, &target, address);\n+\terr = nfp_cpp_mutex_validate(interface, &target, address);\n \tif (err < 0)\n \t\treturn NULL;\n \n@@ -172,16 +177,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp,\n \tmutex->address = address;\n \tmutex->key = key;\n \tmutex->depth = 0;\n-\tmutex->usage = 1;\n-\n-\t/* Add mutex to the cache */\n-\tif (cpp->mutex_cache) {\n-\t\tcpp->mutex_cache->prev = mutex;\n-\t\tmutex->next = cpp->mutex_cache;\n-\t\tcpp->mutex_cache = mutex;\n-\t} else {\n-\t\tcpp->mutex_cache = mutex;\n-\t}\n \n \treturn mutex;\n }\n@@ -195,20 +190,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp,\n void\n nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex)\n {\n-\tmutex->usage--;\n-\tif (mutex->usage > 0)\n-\t\treturn;\n-\n-\t/* Remove mutex from the cache */\n-\tif (mutex->next)\n-\t\tmutex->next->prev = mutex->prev;\n-\tif (mutex->prev)\n-\t\tmutex->prev->next = mutex->next;\n-\n-\t/* If mutex->cpp == NULL, something broke */\n-\tif (mutex->cpp && mutex == mutex->cpp->mutex_cache)\n-\t\tmutex->cpp->mutex_cache = mutex->next;\n-\n \trte_free(mutex);\n }\n \n@@ -268,32 +249,28 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex)\n \t\treturn 0;\n \t}\n \n-\terr = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value);\n-\tif (err < 0)\n-\t\tgoto exit;\n-\n \terr = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key);\n \tif (err < 0)\n-\t\tgoto exit;\n+\t\treturn err;\n \n-\tif (key != mutex->key) {\n-\t\terr = -EPERM;\n-\t\tgoto exit;\n-\t}\n+\tif (key != mutex->key)\n+\t\treturn -EPERM;\n \n-\tif (value != MUTEX_LOCKED(interface)) {\n-\t\terr = -EACCES;\n-\t\tgoto exit;\n-\t}\n+\terr = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value);\n+\tif (err < 0)\n+\t\treturn err;\n+\n+\tif (value != nfp_mutex_locked(interface))\n+\t\treturn -EACCES;\n \n-\terr = nfp_cpp_writel(cpp, muw, mutex->address, MUTEX_UNLOCK(interface));\n+\terr = nfp_cpp_writel(cpp, muw, mutex->address,\n+\t\t\tnfp_mutex_unlocked(interface));\n \tif (err < 0)\n-\t\tgoto exit;\n+\t\treturn err;\n \n \tmutex->depth = 0;\n \n-exit:\n-\treturn err;\n+\treturn 0;\n }\n \n /**\n@@ -332,19 +309,17 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex)\n \t/* Verify that the lock marker is not damaged */\n \terr = nfp_cpp_readl(cpp, mur, mutex->address + 4, &key);\n \tif (err < 0)\n-\t\tgoto exit;\n+\t\treturn err;\n \n-\tif (key != mutex->key) {\n-\t\terr = -EPERM;\n-\t\tgoto exit;\n-\t}\n+\tif (key != mutex->key)\n+\t\treturn -EPERM;\n \n \t/*\n \t * Compare against the unlocked state, and if true,\n \t * write the interface id into the top 16 bits, and\n \t * mark as locked.\n \t */\n-\tvalue = MUTEX_LOCKED(nfp_cpp_interface(cpp));\n+\tvalue = nfp_mutex_locked(nfp_cpp_interface(cpp));\n \n \t/*\n \t * We use test_set_imm here, as it implies a read\n@@ -361,10 +336,10 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex)\n \t */\n \terr = nfp_cpp_readl(cpp, mus, mutex->address, &tmp);\n \tif (err < 0)\n-\t\tgoto exit;\n+\t\treturn err;\n \n \t/* Was it unlocked? */\n-\tif (MUTEX_IS_UNLOCKED(tmp)) {\n+\tif (nfp_mutex_is_unlocked(tmp)) {\n \t\t/*\n \t\t * The read value can only be 0x....0000 in the unlocked state.\n \t\t * If there was another contending for this lock, then\n@@ -376,20 +351,64 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex)\n \t\t */\n \t\terr = nfp_cpp_writel(cpp, muw, mutex->address, value);\n \t\tif (err < 0)\n-\t\t\tgoto exit;\n+\t\t\treturn err;\n \n \t\tmutex->depth = 1;\n-\t\tgoto exit;\n+\t\treturn 0;\n \t}\n \n \t/* Already locked by us? Success! */\n \tif (tmp == value) {\n \t\tmutex->depth = 1;\n-\t\tgoto exit;\n+\t\treturn 0;\n \t}\n \n-\terr = MUTEX_IS_LOCKED(tmp) ? -EBUSY : -EINVAL;\n+\treturn nfp_mutex_is_locked(tmp) ? -EBUSY : -EINVAL;\n+}\n+\n+/**\n+ * Release lock if held by local system.\n+ * Extreme care is advised, call only when no local lock users can exist.\n+ *\n+ * @param cpp\n+ *   NFP CPP handle\n+ * @param target\n+ *   NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU)\n+ * @param address\n+ *   Offset into the address space of the NFP CPP target ID\n+ *\n+ * @return\n+ *   - (0) if the lock was OK\n+ *   - (1) if locked by us\n+ *   - (-errno) on invalid mutex\n+ */\n+int\n+nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp,\n+\t\tint target,\n+\t\tuint64_t address)\n+{\n+\tint err;\n+\tuint32_t tmp;\n+\tuint16_t interface = nfp_cpp_interface(cpp);\n+\tconst uint32_t mur = NFP_CPP_ID(target, 3, 0);    /* atomic_read */\n+\tconst uint32_t muw = NFP_CPP_ID(target, 4, 0);    /* atomic_write */\n+\n+\terr = nfp_cpp_mutex_validate(interface, &target, address);\n+\tif (err != 0)\n+\t\treturn err;\n+\n+\t/* Check lock */\n+\terr = nfp_cpp_readl(cpp, mur, address, &tmp);\n+\tif (err < 0)\n+\t\treturn err;\n+\n+\tif (nfp_mutex_is_unlocked(tmp) || nfp_mutex_owner(tmp) != interface)\n+\t\treturn 0;\n+\n+\t/* Bust the lock */\n+\terr = nfp_cpp_writel(cpp, muw, address, nfp_mutex_unlocked(interface));\n+\tif (err < 0)\n+\t\treturn err;\n \n-exit:\n-\treturn err;\n+\treturn 1;\n }\ndiff --git a/drivers/net/nfp/nfpcore/nfp_mutex.h b/drivers/net/nfp/nfpcore/nfp_mutex.h\nnew file mode 100644\nindex 0000000000..a79490b4d6\n--- /dev/null\n+++ b/drivers/net/nfp/nfpcore/nfp_mutex.h\n@@ -0,0 +1,25 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2023 Corigine, Inc.\n+ * All rights reserved.\n+ */\n+\n+#ifndef __NFP_MUTEX_H__\n+#define __NFP_MUTEX_H__\n+\n+#include \"nfp_cpp.h\"\n+\n+struct nfp_cpp_mutex;\n+\n+int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target,\n+\t\tuint64_t address, uint32_t key_id);\n+\n+struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target,\n+\t\tuint64_t address, uint32_t key_id);\n+\n+void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex);\n+int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex);\n+int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex);\n+int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex);\n+int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target, uint64_t address);\n+\n+#endif /* __NFP_MUTEX_H__ */\ndiff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c\nindex ee987c4438..c4cc7f42f6 100644\n--- a/drivers/net/nfp/nfpcore/nfp_resource.c\n+++ b/drivers/net/nfp/nfpcore/nfp_resource.c\n@@ -7,6 +7,7 @@\n \n #include \"nfp_crc.h\"\n #include \"nfp_logs.h\"\n+#include \"nfp_mutex.h\"\n #include \"nfp_target.h\"\n \n #define NFP_RESOURCE_TBL_TARGET         NFP_CPP_TARGET_MU\n",
    "prefixes": [
        "v2",
        "20/27"
    ]
}