From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.56.21 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796002857; b=m0KZUMmT51RYJ02RMO4JJd+t/tkcje94Bonp//SqMpgtK8siBOQo464a9jYfRKRveueR Wr8TClFMQSayzIKjoQxCVZenESUSnVZUQbvhNSkrO4pXvg1h+TLfEK+3MguZBJcEDFaM4 s8j3vMYz7ln26hxWmKu5LJDxY7A/QCGrG3RRiOr+ArIlH4U6HIZloMrpUp+9vz0LL0/u0 sTWB+zhi/Gt0X8pvLEYO0UPCRvssZ+hSUCctlC92etphSMQfSDfrJgo4Ney8xBVCQTSJF kZkl3goWk1CCeq7C5tSIO9T9kwrYMN/y2GmR/EV7Y5MRx87QdJXuXGfntdp6JT5tskw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796002857; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Received:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: Content-Type:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=WSSjSX4Qp4iif6+rsf5kjmD39ZEpUcMi6aOWrNWIYTA=; b=2HZV7xoNyJ9xyaOpvm7dft2MUF8AznFhQf05vN14+Zcx3CBXRI9E73nWuct5/1GNzksk bTcRKN6RlgoZ0aBL9ZFv+E/b2j2BX/MVVYUjv1tIw/K1rzIB37vvoGima/+5hsu/1sG1R UIPcwZ2lD4+WP2pybnUwTjus4ASxez4PwS87k0MgSiuItUnEiYcMf5qPrjDkrhwHv349k qcmHugaMGIiJY/3rUyIpZeOc+YjMFZ7R/qPySg1An1Q3sNyNdSdbeJ7eFAJ6jirfHGZgu b5lBUzzj1lku4SmhD5XrVE0LpiYGtDlFLU7Ay0IWtho8SVpmUfFmLUDj+oDXUcB/OUg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=ozPg5S8y; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.56.21 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010021.outbound.protection.outlook.com [52.101.56.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9EBA606A333 for ; Mon, 30 Nov 2026 01:40:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C9EBA606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=ozPg5S8y ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GJ47c8aN9IzpRDwA8F8zc6Lh/75h/gZquoSTuRWZIbClcgQNOjkdgALBsSgPHTmaOIFrXZGelhkLBnKaL1Ip428dp2ejdGkRGf/CngzzHyUmdPCEn2wxxZaOLHKKsLRCRaCk1zwehknGPmzbDNKBqrK2RPUEVN88RAlu7Js/LHYbZ+PWNr4Mx6jUPiyagRPDIvtG2PcvITjyY1a05rybDGCq2p/nP9Gso+aTcUNjqrl5JW3nvKtFtRFysbZduyHrp9O13nFgLOD186KHFqdcz2eYB2SNkiBUN28oaaRInrMAOm4a2/8ShZvv5Ru0FUAcYeXsLiJqatL+ozblYNXsNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=WSSjSX4Qp4iif6+rsf5kjmD39ZEpUcMi6aOWrNWIYTA=; b=GLiek7RkkpY9CNHnYiCHEIgqStcCntIWUWhvIY+c48YAgPcqW73b90u/mM7OCw0/+V7LOxtOsYjq8ES/WARawfHYx7SObE1pThEFRz4tqhOwkgTMyv4B+opmPefjo/v2xUsm1LUGCzvzQ8byeEjJ6JIqoIk4KJyHSdjEL3ltJwIc1IB+hFqCWC9Kc6eRCgE0QEFaYdp78/r9NVebosuuNNDKcTitLQGVx43psLLD+XUeA/H1cs//0rCDTgmGw9NqVXFMliMh/gPBmOYtactlDiIZlLBC3X1Ek0nUqpTgwGMrX7uY9L76wQkABs6miUS0XpgCbtgF3FCes90mfMM3Tw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=quicinc.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WSSjSX4Qp4iif6+rsf5kjmD39ZEpUcMi6aOWrNWIYTA=; b=ozPg5S8yZABpVtW4FM7NsLmejQ0BqTGrfNqjP46yP82hf5c+bw6Yb6tdk+xcQ8yxUqw3df/Eo1MNATanR3u//AhqOaqLF5RMwb9r/JqMM0O7QdveAMQVcCJ0EF2QhlNaiL3wMFugK4t7h67XVJrg7925Jr+iLbgGvdLZr7i3AHE= Received: from MW4PR04CA0357.namprd04.prod.outlook.com (2603:10b6:303:8a::32) by DS0PR12MB7748.namprd12.prod.outlook.com (2603:10b6:8:130::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Mon, 30 Nov 2026 01:40:50 +0000 Received: from MWH0EPF000DD30C.namprd05.prod.outlook.com (2603:10b6:303:8a:cafe::96) by MW4PR04CA0357.outlook.office365.com (2603:10b6:303:8a::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.12 via Frontend Transport; Mon, 30 Nov 2026 01:40:50 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MWH0EPF000DD30C.mail.protection.outlook.com (10.167.249.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Mon, 30 Nov 2026 01:40:50 +0000 Received: from satlexmb10.amd.com (10.181.42.219) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Sun, 29 Nov 2026 19:40:49 -0600 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb10.amd.com (10.181.42.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Sun, 29 Nov 2026 19:40:49 -0600 Received: from xsjdavidzha51.xilinx.com (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Sun, 29 Nov 2026 19:40:48 -0600 From: David Zhang To: , , , , , , CC: David Zhang , , Subject: [PATCH V1 2/4] accel/amdxdna: Add AIE4 context recovery Date: Sun, 29 Nov 2026 17:40:36 -0800 Message-ID: <20261130014038.712239-3-yidong.zhang@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261130014038.712239-1-yidong.zhang@amd.com> References: <20261130014038.712239-1-yidong.zhang@amd.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000DD30C:EE_|DS0PR12MB7748:EE_ X-MS-Office365-Filtering-Correlation-Id: 38792652-d102-4ac6-e838-08df4e82f6ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700016|1800799024|23010399003|5023799004|4143699003|11063799006|6133799003|261009223027099003|18002099003|22082099003|7136999003|10067099003|56012099006|261028144727099003|261026135527099003|261026121527099003|261026130827099003|261026140227099003|261022113327099003|261022075727099003|261102123227099003|261022105027099003|261021121427099003|261022115727099003|261021135927099003|261021133027099003|261021130227099003|261021123027099003; X-Microsoft-Antispam-Message-Info: kmbXY4b7IeeXPXqEKBUlaf5jPN+9E/kZQt/1w0927pH8oT58W5Qfi21gp1B+IGdPBtFx6x07okfvK6Y5nMi8os/+PwAbDxViOYuLh5ny1pUoXRP5P0UbpbdI8RImaYrXTBqcyKt23wwQBRzhPslT3pOiEAn+K96r+dEkHDqoleej7zSI01VUw3d7JVJITDfYfuf3DBuoKhlBCzjOUPRGDwrV5U/o68PwmARaVErIpthLUGktMmZrR4NizdjM04ZySr3IRhNq0uvYJSLZRcIH/6j9nDyvWS9tGY759iwv0MR5m9nG/FEofEKKPJhhcLxOiJh00MM/2Vz9iwEirpSzGWrcD5/i8odbxXDzDB4AOA8DF6twlJ6816FtwBSkVj+PquPGHV6o47Tz53As5X79ctpWBnRs2MNZPTBLPPmLs++hOSc6V0AN2s0Cg3jQtAwTUfc7xwnfide3aSBH+dApWx/F6fbx7+amEUD6jZm/2FLzVcDiuH68uoJTRpsNkcukiYmUa4PUHRJRJB8NCH01g5JKcqhx2N+nQ7Dc/vL0YE6vOdSuG8yTx7U2KhaKtxlKwHZLDCZG8y5rElDIGJ+UdppSmYV1MaWw+tj3cQYL0aQ6WL6M4RdG//06uU+cKUJ/uN1F+e6pieCfuGKWR4M7XW6DbH8WUzhC7MHLCCM0FBj2j22m+PrYMFnKa4f1SIK6NigWCqkJp1cisbBRdr2FdA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(82310400026)(36860700016)(1800799024)(23010399003)(5023799004)(4143699003)(11063799006)(6133799003)(261009223027099003)(18002099003)(22082099003)(7136999003)(10067099003)(56012099006)(261028144727099003)(261026135527099003)(261026121527099003)(261026130827099003)(261026140227099003)(261022113327099003)(261022075727099003)(261102123227099003)(261022105027099003)(261021121427099003)(261022115727099003)(261021135927099003)(261021133027099003)(261021130227099003)(261021123027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ajLzX9IKW2T+v9+Sl7qc5yLekERThzUJGsZgrIXP4z3RA5Sq4gt9Xn99keGwAV8cgbKPOWFIpZbZbf6Wme8UFAQHtdIIrjD1iGpCpzdjj7rKI1nzMIZrNdYlROZI3WgsNMg8GpHiy3DkyCcnbkU/aqJ9Y6Q24eqk8t95KySOTZrT8owPh7gYAWr1PtE8W2dA64O2QtcFp36lz8fs3z3qgHtlGybilOrRyBO4Q2gehZno2n1/FJIC5a2PXh+OOXKv6HVhTnE/16lvMELIEhXCDeeJlBl+7AiIOKE0t1fVlGAfP7nMQ+NBqfmyV9aniaDFWTRrpHVEN7laBnB68xjDojubX2iOv3JW1bRFIn/i9E7faYlFvOdmjbNqV0YdD1/aLSaRMFc7zx/5I7tX0z+IjATytX1UQWn21ZiDk2EE2n1hccH/7PYnhmHYEL2x0eFE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 01:40:50.2035 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38792652-d102-4ac6-e838-08df4e82f6ce X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000DD30C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7748 Recover an AIE4 context when firmware reports a context error in an async event: destroy and create the firmware context again, and complete the jobs that were running on it. Signed-off-by: David Zhang --- drivers/accel/amdxdna/aie4_ctx.c | 292 +++++++++++++++++++++----- drivers/accel/amdxdna/aie4_error.c | 76 +++++++ drivers/accel/amdxdna/aie4_pci.c | 25 +++ drivers/accel/amdxdna/aie4_pci.h | 27 ++- drivers/accel/amdxdna/amdxdna_ctx.h | 1 + drivers/accel/amdxdna/amdxdna_error.h | 10 + 6 files changed, 375 insertions(+), 56 deletions(-) diff --git a/drivers/accel/amdxdna/aie4_ctx.c b/drivers/accel/amdxdna/aie4_ctx.c index 7904e05ca826..9f61fcd6e518 100644 --- a/drivers/accel/amdxdna/aie4_ctx.c +++ b/drivers/accel/amdxdna/aie4_ctx.c @@ -258,6 +258,9 @@ int aie4_hwctx_create(struct amdxdna_hwctx *hwctx) } priv->hw_ctx_id = resp.hw_context_id; + /* Firmware reuses context IDs; let error handlers skip newer contexts. */ + WRITE_ONCE(ndev->ctx_gen, ndev->ctx_gen + 1); + priv->gen = ndev->ctx_gen; hwctx->fw_ctx_id = resp.hw_context_id; hwctx->start_col = 0; @@ -277,7 +280,7 @@ int aie4_hwctx_create(struct amdxdna_hwctx *hwctx) hwctx->fw_ctx_id = -1; return ret; } - WRITE_ONCE(priv->has_error, false); + WRITE_ONCE(priv->has_reset, false); WRITE_ONCE(priv->cert_comp, cert_comp); mutex_unlock(&priv->io_lock); hwctx->doorbell_offset = CTX_INVALID_DOORBELL; @@ -286,17 +289,6 @@ int aie4_hwctx_create(struct amdxdna_hwctx *hwctx) return 0; } -/* Linked cert_comp acts as connected sentinel for submit waiters. */ -static bool aie4_hwctx_connected(struct amdxdna_hwctx *hwctx) -{ - return !!READ_ONCE(hwctx->priv->cert_comp); -} - -static bool aie4_hwctx_has_error(struct amdxdna_hwctx *hwctx) -{ - return READ_ONCE(hwctx->priv->has_error); -} - void aie4_hwctx_destroy(struct amdxdna_hwctx *hwctx, enum aie4_hwctx_flags flags) { struct amdxdna_client *client = hwctx->client; @@ -304,26 +296,21 @@ void aie4_hwctx_destroy(struct amdxdna_hwctx *hwctx, enum aie4_hwctx_flags flags struct amdxdna_dev *xdna = client->xdna; struct amdxdna_dev_hdl *ndev = xdna->dev_handle; struct cert_comp *cert_comp; - bool has_error = false; + bool has_reset = false; drm_WARN_ON(&xdna->ddev, !mutex_is_locked(&xdna->dev_lock)); if (flags == AIE4_HWCTX_DISCONNECT || flags == AIE4_HWCTX_ERROR) - has_error = true; + has_reset = true; mutex_lock(&priv->io_lock); - if (has_error) - WRITE_ONCE(priv->has_error, true); - cert_comp = priv->cert_comp; - WRITE_ONCE(priv->cert_comp, NULL); - mutex_unlock(&priv->io_lock); - - if (cert_comp) - wake_up_all(&cert_comp->waitq); - - if (has_error) - wake_up_all(&priv->job_list_wq); + if (has_reset) + WRITE_ONCE(priv->has_reset, true); + /* + * Destroy the firmware context first; woken waiters complete its jobs. + * Hold io_lock so no submitter publishes to the context meanwhile. + */ if (flags != AIE4_HWCTX_DISCONNECT && priv->hw_ctx_id != CTX_INVALID_ID) { /* * Pairs with aie4_hwctx_create(): detach debug buffers. @@ -334,6 +321,16 @@ void aie4_hwctx_destroy(struct amdxdna_hwctx *hwctx, enum aie4_hwctx_flags flags aie4_msg_destroy_context(ndev, priv->hw_ctx_id); } + cert_comp = priv->cert_comp; + WRITE_ONCE(priv->cert_comp, NULL); + mutex_unlock(&priv->io_lock); + + if (cert_comp) + wake_up_all(&cert_comp->waitq); + + if (has_reset) + wake_up_all(&priv->job_list_wq); + if (cert_comp) aie4_put_cert_comp(cert_comp); @@ -341,8 +338,8 @@ void aie4_hwctx_destroy(struct amdxdna_hwctx *hwctx, enum aie4_hwctx_flags flags hwctx->fw_ctx_id = -1; hwctx->doorbell_offset = CTX_INVALID_DOORBELL; - /* Skip cancel_work_sync on error so worker can abort in-flight jobs. */ - if (!has_error) + /* On reset, the worker still retires running jobs: completed or faulted. */ + if (!has_reset) cancel_work_sync(&priv->job_work); } @@ -545,13 +542,6 @@ static u64 get_read_index(struct amdxdna_hwctx *hwctx) return ri; } -/* Verify cert_comp remains linked to detect disconnect or reset. */ -static bool check_cert_comp_linked(struct amdxdna_hwctx *hwctx, struct cert_comp *comp) -{ - /* READ_ONCE pairs with the link/unlink WRITE_ONCE. */ - return comp == READ_ONCE(hwctx->priv->cert_comp); -} - /* * Lockless wait condition: wake on completion or disconnect. Record * completion, so callers do not re-read state that can change after the @@ -561,30 +551,55 @@ static inline bool cmd_done_or_unlinked(struct amdxdna_hwctx *hwctx, u64 seq, struct cert_comp *comp, bool *done) { *done = get_read_index(hwctx) > seq; - return *done || !check_cert_comp_linked(hwctx, comp); + /* An unlinked cert_comp means a disconnect or reset; pairs with WRITE_ONCE. */ + return *done || (comp != READ_ONCE(hwctx->priv->cert_comp)); } /* - * Return 0 once seq completed, -ENODEV if the context is lost, or -EAGAIN - * if it is suspended by power management before seq completed. + * Return 0 once seq completed, -ETIME when the user timeout expires, -ENODEV + * if the context is lost, or -EAGAIN to wait again: the context was suspended + * or reset, or an unlimited wait reached the job timeout. */ int aie4_cmd_wait(struct amdxdna_hwctx *hwctx, u64 seq, u32 timeout) { unsigned long wait_jifs = MAX_SCHEDULE_TIMEOUT; - struct cert_comp *cert_comp = aie4_get_cert_comp(hwctx); + struct amdxdna_hwctx_priv *priv = hwctx->priv; + struct cert_comp *cert_comp; bool done = false; long ret; + if (timeout) + wait_jifs = msecs_to_jiffies(timeout); + + /* A reset disconnects the context for a while; wait for it to end. */ + ret = wait_event_interruptible_timeout(priv->job_list_wq, + !READ_ONCE(priv->resetting), wait_jifs); + if (ret < 0) + return ret; + if (!ret) + return -ETIME; + wait_jifs = ret; + /* + * A completion can arrive without its interrupt. Bound an unlimited + * wait by the job timeout, which re-checks it; user space waits again + * on -EAGAIN. + */ + if (!timeout) + wait_jifs = msecs_to_jiffies(AIE4_JOB_TIMEOUT_MS); + + cert_comp = aie4_get_cert_comp(hwctx); if (!cert_comp) { /* Not connected: read_index in host memory is still valid. */ if (get_read_index(hwctx) > seq) return 0; - return aie4_hwctx_has_error(hwctx) ? -ENODEV : -EAGAIN; + /* + * A reset in progress is retried; a context still reset after it + * is dead. Read both flags under io_lock, where the reset sets them. + */ + guard(mutex)(&priv->io_lock); + return priv->has_reset && !priv->resetting ? -ENODEV : -EAGAIN; } - if (timeout) - wait_jifs = msecs_to_jiffies(timeout); - ret = wait_event_interruptible_timeout(cert_comp->waitq, cmd_done_or_unlinked(hwctx, seq, cert_comp, &done), @@ -595,11 +610,11 @@ int aie4_cmd_wait(struct amdxdna_hwctx *hwctx, u64 seq, u32 timeout) return ret; if (done) return 0; - if (!ret) + if (!ret && timeout) return -ETIME; - /* Woken by disconnect before seq completed. */ - return aie4_hwctx_has_error(hwctx) ? -ENODEV : -EAGAIN; + /* User space retries -EAGAIN. */ + return -EAGAIN; } /* ---- kernel-mode submission (driver fills the queue and rings doorbell) ---- */ @@ -648,6 +663,22 @@ static int wait_till_seq_completed(struct amdxdna_hwctx *hwctx, u64 seq, return ret ? -EAGAIN : -ETIME; } +/* + * During a reset, a submitter with no published command waits for the new + * firmware context; one that published part of a chain returns so the reset + * can complete it. + */ +static bool aie4_submit_wait_done(struct amdxdna_hwctx *hwctx) +{ + struct amdxdna_sched_job *job = READ_ONCE(hwctx->priv->pending_head); + + if (!AIE4_HWCTX_HAS_RESET(hwctx)) + return AIE4_HWCTX_CONNECTED(hwctx); + + return !(READ_ONCE(hwctx->priv->resetting) && job && + job->aie4_job_state == AIE4_JOB_STATE_PENDING); +} + static int wait_till_connected_hsa_not_full(struct amdxdna_hwctx *hwctx) { struct amdxdna_dev *xdna = hwctx->client->xdna; @@ -669,17 +700,20 @@ static int wait_till_connected_hsa_not_full(struct amdxdna_hwctx *hwctx) hsa_not_full = true; } ret = wait_event_freezable(priv->job_list_wq, - aie4_hwctx_connected(hwctx) || - aie4_hwctx_has_error(hwctx)); + aie4_submit_wait_done(hwctx)); mutex_lock(&priv->io_lock); if (ret) return ret; - if (aie4_hwctx_has_error(hwctx)) { - XDNA_DBG(xdna, "ctx %s in error; unwinding -ENODEV", + if (AIE4_HWCTX_HAS_RESET(hwctx)) { + /* A reset started after the wait; wait for the new context. */ + if (!aie4_submit_wait_done(hwctx)) + continue; + XDNA_DBG(xdna, "ctx %s is reset; unwinding -ENODEV", hwctx->name); return -ENODEV; } - } while (!hsa_not_full || !aie4_hwctx_connected(hwctx)); + } while (!hsa_not_full || !AIE4_HWCTX_CONNECTED(hwctx) || + AIE4_HWCTX_HAS_RESET(hwctx)); return 0; } @@ -955,6 +989,107 @@ static void job_abort(struct amdxdna_sched_job *job) job_done(job); } +/* + * Mark the job that faulted, or that the job timeout found hung, as timed + * out. Use only the command BOs looked up at submit, as the command BO is + * writable by user space and its handles may be gone. + */ +/* Context health data of a timed-out command, read by user space. */ +struct aie4_ctx_health { + struct amdxdna_ctx_health header; + u32 ctx_state; + u32 num_uc; + u32 ctx_error_type; + struct aie4_uc_health_info uc_info[AIE4_MPNPUFW_MAX_UC_COUNT]; +}; + +/* Write the health data, with no more uC entries than fit in @size. */ +static void aie4_fill_ctx_health(const struct aie4_async_ctx_error *report, + void *data, size_t size) +{ + const struct aie4_msg_app_health_report *app = &report->app_health_report; + struct aie4_ctx_health health = { + .header.version = AMDXDNA_CMD_CTX_HEALTH_V1, + .header.npu_gen = AMDXDNA_CMD_CTX_HEALTH_AIE4, + }; + size_t len = offsetof(struct aie4_ctx_health, uc_info); + u32 num_uc = 0; + + if (size < len) + return; + + /* The error type is valid without an app health report. */ + health.ctx_error_type = report->error_type; + if (app->version) { + num_uc = min_t(u32, FIELD_GET(AIE4_APP_HEALTH_NUM_UC, app->ctx_num_uc), + AIE4_MPNPUFW_MAX_UC_COUNT); + num_uc = min_t(u32, num_uc, (size - len) / sizeof(health.uc_info[0])); + health.ctx_state = FIELD_GET(AIE4_APP_HEALTH_CTX_STATUS, app->ctx_num_uc); + memcpy(health.uc_info, app->uc_info, num_uc * sizeof(health.uc_info[0])); + } + health.num_uc = num_uc; + + memcpy(data, &health, len + num_uc * sizeof(health.uc_info[0])); +} + +/* + * Mark the job that faulted as timed out, with the health data from + * @report. Use only the command BOs looked up at submit, as the command BO + * is writable by user space and its handles may be gone. + */ +static void job_fault(struct amdxdna_sched_job *job, + const struct aie4_async_ctx_error *report) +{ + const struct aie4_msg_app_health_report *app = &report->app_health_report; + struct amdxdna_hwctx *hwctx = job->hwctx; + struct amdxdna_gem_obj *abo = job->cmd_bo; + struct amdxdna_cmd_chain *cc; + struct amdxdna_cmd *cmd; + u32 cmd_idx, len; + + XDNA_ERR(hwctx->client->xdna, "%s job %lld timed out", hwctx->name, job->seq); + amdxdna_cmd_set_state(job->cmd_bo, ERT_CMD_STATE_TIMEOUT); + + if (job->aie4_cmd_bo_cnt) { + /* The run list index is valid only with a health report. */ + cmd_idx = app->version ? app->runlist_read_idx : 0; + if (cmd_idx >= job->aie4_cmd_bo_cnt) + cmd_idx = 0; + /* Bounds-checked against the BO size. */ + cc = amdxdna_cmd_get_payload(job->cmd_bo, &len); + if (cc && len >= offsetofend(struct amdxdna_cmd_chain, error_index)) + cc->error_index = cmd_idx; + abo = job->aie4_cmd_bos[cmd_idx]; + } + + cmd = amdxdna_gem_vmap(abo); + if (cmd) { + memset(cmd->data, 0xff, abo->mem.size - sizeof(*cmd)); + aie4_fill_ctx_health(report, cmd->data, abo->mem.size - sizeof(*cmd)); + } + + dma_fence_set_error(job->fence, -ETIME); + if (get_read_index(hwctx) <= job->seq) + update_read_index(hwctx, job->seq + 1); + job_done(job); +} + +/* Return true once per reset for a fault, so only the oldest job times out. */ +static bool aie4_hwctx_take_fault(struct amdxdna_hwctx *hwctx, + struct aie4_async_ctx_error *report) +{ + struct amdxdna_hwctx_priv *priv = hwctx->priv; + bool fault; + + mutex_lock(&priv->io_lock); + fault = priv->reset_fault; + priv->reset_fault = false; + *report = priv->reset_report; + mutex_unlock(&priv->io_lock); + + return fault; +} + /* * Stop a context whose running job timed out, so the NPU no longer * accesses the job BOs before the worker aborts the jobs and signals @@ -969,7 +1104,7 @@ static void job_timeout(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *j return; /* The job may have completed or the context disconnected meanwhile. */ - if (aie4_hwctx_connected(hwctx) && get_read_index(hwctx) <= job->seq) { + if (AIE4_HWCTX_CONNECTED(hwctx) && get_read_index(hwctx) <= job->seq) { XDNA_ERR(xdna, "hwctx %s job %llu timed out", hwctx->name, job->seq); aie4_hwctx_stop(hwctx); } @@ -982,6 +1117,7 @@ static void job_worker(struct work_struct *work) container_of(work, struct amdxdna_hwctx_priv, job_work); struct amdxdna_hwctx *hwctx = priv->hwctx; struct amdxdna_sched_job *job; + struct aie4_async_ctx_error report; int ret; while ((job = peek_running_job(hwctx))) { @@ -998,9 +1134,12 @@ static void job_worker(struct work_struct *work) job_abort(job); else job_complete(job); - } else if (aie4_hwctx_has_error(hwctx)) { + } else if (AIE4_HWCTX_HAS_RESET(hwctx)) { dequeue_running_job(hwctx, job); - job_abort(job); + if (aie4_hwctx_take_fault(hwctx, &report)) + job_fault(job, &report); + else + job_abort(job); } else { /* Disconnected by suspend; resume requeues the worker. */ break; @@ -1037,6 +1176,53 @@ int aie4_hwctx_wait_for_running(struct amdxdna_hwctx *hwctx) return ret; } +/* + * Reset a context: destroy the firmware context, complete the running jobs, + * then create the firmware context again. Called with dev_lock held. + */ +void aie4_hwctx_reset(struct amdxdna_hwctx *hwctx, + const struct aie4_async_ctx_error *ctx_err) +{ + struct amdxdna_hwctx_priv *priv = hwctx->priv; + struct amdxdna_dev *xdna = hwctx->client->xdna; + int ret; + + drm_WARN_ON(&xdna->ddev, !mutex_is_locked(&xdna->dev_lock)); + + XDNA_ERR(xdna, "Resetting hwctx %s", hwctx->name); + + mutex_lock(&priv->io_lock); + WRITE_ONCE(priv->resetting, true); + /* Under io_lock, so a submitter does not publish to the old context. */ + WRITE_ONCE(priv->has_reset, true); + priv->reset_fault = true; + if (ctx_err) + priv->reset_report = *ctx_err; + else + memset(&priv->reset_report, 0, sizeof(priv->reset_report)); + mutex_unlock(&priv->io_lock); + + aie4_hwctx_destroy(hwctx, AIE4_HWCTX_ERROR); + /* + * A chain submitter that did not stop could publish the rest of its + * chain to a new context, so leave the context reset instead. + */ + ret = aie4_hwctx_wait_for_running(hwctx); + if (!ret) + ret = aie4_hwctx_create(hwctx); + if (ret) + XDNA_ERR(xdna, "Failed to create hwctx %s after reset, ret %d", + hwctx->name, ret); + + mutex_lock(&priv->io_lock); + priv->reset_fault = false; + WRITE_ONCE(priv->resetting, false); + mutex_unlock(&priv->io_lock); + + /* Waiters and submitters re-check now that the reset finished. */ + wake_up_all(&priv->job_list_wq); +} + void aie4_hwctx_resume_jobs(struct amdxdna_hwctx *hwctx) { struct amdxdna_hwctx_priv *priv = hwctx->priv; diff --git a/drivers/accel/amdxdna/aie4_error.c b/drivers/accel/amdxdna/aie4_error.c index c1f4819d0107..a56bf5891bf1 100644 --- a/drivers/accel/amdxdna/aie4_error.c +++ b/drivers/accel/amdxdna/aie4_error.c @@ -14,6 +14,8 @@ #include "aie.h" #include "aie4_msg_priv.h" #include "aie4_pci.h" +#include "amdxdna_ctx.h" +#include "amdxdna_error.h" #include "amdxdna_mailbox.h" #include "amdxdna_pci_drv.h" @@ -26,6 +28,7 @@ * @addr: DMA address of the slice * @resp: last response; status is MAX_AIE4_MSG_STATUS_CODE when none * @resp_gen: @gen when the last response arrived + * @resp_ctx_gen: device context generation when the last response arrived */ struct aie4_async_event { struct amdxdna_dev_hdl *ndev; @@ -35,6 +38,7 @@ struct aie4_async_event { dma_addr_t addr; struct aie4_msg_async_event_config_resp resp; u32 resp_gen; + u64 resp_ctx_gen; }; /* @@ -63,6 +67,8 @@ static int aie4_async_event_cb(void *handle, void __iomem *data, size_t size) /* Tag the response with the channel it arrived on. */ e->resp_gen = READ_ONCE(e->events->gen); + /* Contexts created after this event are not the one it reports. */ + e->resp_ctx_gen = READ_ONCE(e->ndev->ctx_gen); e->resp.type = readl(data + offsetof(struct aie4_msg_async_event_config_resp, type)); wmb(); /* Update status last; the worker reads it first */ @@ -110,6 +116,68 @@ static bool aie4_tdr_detected(u32 error_type) error_type == AIE4_ASYNC_EVENT_CTX_ERR_PREEMPTION_TIMEOUT; } +static enum amdxdna_error_num aie4_ctx_error_num(u32 error_type) +{ + switch (error_type) { + case AIE4_ASYNC_EVENT_CTX_ERR_HWSCH_FAILURE: + case AIE4_ASYNC_EVENT_CTX_ERR_STOP_FAILURE: + return AMDXDNA_ERROR_NUM_KDS_CU; + case AIE4_ASYNC_EVENT_CTX_ERR_AIE_FAILURE: + case AIE4_ASYNC_EVENT_CTX_ERR_PREEMPTION_TIMEOUT: + case AIE4_ASYNC_EVENT_CTX_ERR_NEW_PROCESS_FAILURE: + case AIE4_ASYNC_EVENT_CTX_ERR_UC_CRITICAL_ERROR: + case AIE4_ASYNC_EVENT_CTX_ERR_UC_COMPLETION_TIMEOUT: + return AMDXDNA_ERROR_NUM_KDS_EXEC; + default: + return AMDXDNA_ERROR_NUM_UNKNOWN; + } +} + +/* Keep the error for the DRM_AMDXDNA_HW_LAST_ASYNC_ERR query. */ +static void aie4_record_async_error(struct amdxdna_dev_hdl *ndev, + enum amdxdna_error_num err_num, + u32 ctx_status, u32 ctx_id) +{ + struct amdxdna_async_error *rec = &ndev->last_async_err; + + drm_WARN_ON(&ndev->aie.xdna->ddev, !mutex_is_locked(&ndev->aie.xdna->dev_lock)); + rec->err_code = AMDXDNA_ERROR_ENCODE(err_num, AMDXDNA_ERROR_MODULE_AIE_CORE); + rec->ts_us = ktime_to_us(ktime_get_real()); + rec->ex_err_code = AMDXDNA_EXTRA_ERR_CTX_ENCODE(ctx_status, ctx_id); +} + +/* Reset the context with firmware ID ctx_id that existed at generation gen. */ +static void aie4_reset_hwctx_by_id(struct amdxdna_dev_hdl *ndev, u32 ctx_id, + u64 gen, const struct aie4_async_ctx_error *ctx_err) +{ + struct amdxdna_dev *xdna = ndev->aie.xdna; + bool found = false; + struct amdxdna_client *client; + struct amdxdna_hwctx *hwctx; + unsigned long hwctx_id; + int idx; + + drm_WARN_ON(&xdna->ddev, !mutex_is_locked(&xdna->dev_lock)); + + amdxdna_for_each_client(xdna, client) { + idx = srcu_read_lock(&client->hwctx_srcu); + amdxdna_for_each_hwctx(client, hwctx_id, hwctx) { + if (!hwctx->priv || hwctx->priv->hw_ctx_id != ctx_id || + hwctx->priv->gen > gen) + continue; + found = true; + aie4_hwctx_reset(hwctx, ctx_err); + break; + } + srcu_read_unlock(&client->hwctx_srcu, idx); + if (found) + break; + } + + if (!found) + XDNA_DBG(xdna, "Context %u was already reset or destroyed", ctx_id); +} + static void aie4_log_health_report(struct amdxdna_dev *xdna, struct aie4_msg_app_health_report *health) { @@ -147,6 +215,7 @@ static void aie4_async_ctx_error(struct aie4_async_event *e) struct amdxdna_dev_hdl *ndev = e->ndev; struct amdxdna_dev *xdna = ndev->aie.xdna; u32 ctx_id = ctx_err->ctx_id; + u32 ctx_status = 0; if (aie4_tdr_detected(ctx_err->error_type)) XDNA_ERR(xdna, "TDR on context %u: %s", ctx_id, @@ -155,6 +224,13 @@ static void aie4_async_ctx_error(struct aie4_async_event *e) XDNA_ERR(xdna, "Firmware reported context %u event: %s", ctx_id, aie4_ctx_error_str(ctx_err->error_type)); aie4_log_health_report(xdna, health); + + if (health->version) + ctx_status = FIELD_GET(AIE4_APP_HEALTH_CTX_STATUS, health->ctx_num_uc); + aie4_record_async_error(ndev, aie4_ctx_error_num(ctx_err->error_type), + ctx_status, ctx_id); + + aie4_reset_hwctx_by_id(ndev, ctx_id, e->resp_ctx_gen, ctx_err); } static void aie4_async_event_report(struct aie4_async_event *e) diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c index 5910563b6c1d..a45c6bb21aaf 100644 --- a/drivers/accel/amdxdna/aie4_pci.c +++ b/drivers/accel/amdxdna/aie4_pci.c @@ -1039,6 +1039,25 @@ static int aie4_set_state(struct amdxdna_client *client, return ret; } +/* Only the last context error is kept, so return one element. */ +static int aie4_get_array(struct amdxdna_client *client, + struct amdxdna_drm_get_array *args) +{ + struct amdxdna_dev_hdl *ndev = client->xdna->dev_handle; + + if (args->param != DRM_AMDXDNA_HW_LAST_ASYNC_ERR) + return -EOPNOTSUPP; + + args->num_element = 1; + args->element_size = min_t(u32, args->element_size, + sizeof(ndev->last_async_err)); + if (copy_to_user(u64_to_user_ptr(args->buffer), &ndev->last_async_err, + args->element_size)) + return -EFAULT; + + return 0; +} + static int aie4_alloc_work_buffer(struct amdxdna_dev_hdl *ndev) { struct amdxdna_dev *xdna = ndev->aie.xdna; @@ -1281,6 +1300,10 @@ int aie4_hwctx_resume_all(struct amdxdna_dev_hdl *ndev) amdxdna_for_each_client(xdna, client) { idx = srcu_read_lock(&client->hwctx_srcu); amdxdna_for_each_hwctx(client, hwctx_id, hwctx) { + /* Skip recreating a context marked dead by a failed reset. */ + if (AIE4_HWCTX_HAS_RESET(hwctx) && + !READ_ONCE(hwctx->priv->resetting)) + continue; ret = aie4_hwctx_create(hwctx); if (ret) goto error; @@ -1503,6 +1526,7 @@ const struct amdxdna_dev_ops aie4_vf_ops = { .cmd_wait = aie4_cmd_wait, .get_aie_info = aie4_get_info, .set_aie_state = aie4_set_state, + .get_array = aie4_get_array, .resume = pm_ptr(aie4_vf_resume), .suspend = pm_ptr(aie4_vf_suspend), }; @@ -1520,6 +1544,7 @@ const struct amdxdna_dev_ops aie4_classic_ops = { .cmd_wait = aie4_cmd_wait, .get_aie_info = aie4_get_info, .set_aie_state = aie4_set_state, + .get_array = aie4_get_array, .resume = pm_ptr(aie4_classic_resume), .suspend = pm_ptr(aie4_classic_suspend), .runtime_resume = pm_ptr(aie4_classic_resume), diff --git a/drivers/accel/amdxdna/aie4_pci.h b/drivers/accel/amdxdna/aie4_pci.h index 9c37c78169bf..b24865c9ebc8 100644 --- a/drivers/accel/amdxdna/aie4_pci.h +++ b/drivers/accel/amdxdna/aie4_pci.h @@ -50,7 +50,16 @@ struct amdxdna_hwctx_priv { struct cert_comp *cert_comp; u32 hw_ctx_id; - bool has_error; + /* Number of this firmware context; see amdxdna_dev_hdl.ctx_gen. */ + u64 gen; + /* The firmware context was destroyed; the worker completes running jobs. */ + bool has_reset; + /* A reset is in progress and creates the firmware context again. */ + bool resetting; + /* The oldest drained job faulted; mark it timed out with reset_report. */ + bool reset_fault; + /* Firmware report of the fault; zeroed without a firmware report. */ + struct aie4_async_ctx_error reset_report; /* Attached debug buffers, held until removal or fini. */ struct amdxdna_gem_obj *fw_buf_bo[AMDXDNA_FW_BUF_NUM]; /* Their configuration, sent again when the context is created. */ @@ -74,6 +83,11 @@ struct amdxdna_hwctx_priv { struct workqueue_struct *job_work_q; }; +/* A linked cert_comp means the context has a firmware context. */ +#define AIE4_HWCTX_CONNECTED(hwctx) (!!READ_ONCE((hwctx)->priv->cert_comp)) +/* Set while a reset runs, and kept if the reset left the context dead. */ +#define AIE4_HWCTX_HAS_RESET(hwctx) READ_ONCE((hwctx)->priv->has_reset) + struct amdxdna_dev_priv { const char *npufw_path; const char *certfw_path; @@ -129,6 +143,11 @@ struct amdxdna_dev_hdl { /* Context switch hysteresis timeout in microseconds. */ u32 ctx_switch_hysteresis_us; + /* Bumped on each firmware context creation, under dev_lock. */ + u64 ctx_gen; + /* Last context error reported by firmware, under dev_lock. */ + struct amdxdna_async_error last_async_err; + struct amdxdna_drm_query_firmware_version cert_version; }; @@ -176,8 +195,8 @@ void aie4_free_msg_buffer(struct amdxdna_dev *xdna, struct aie4_msg_buf *buf); enum aie4_hwctx_flags { AIE4_HWCTX_NORMAL = 0, AIE4_HWCTX_GRACEFUL, - AIE4_HWCTX_DISCONNECT, /* sets has_error, do not destroy context */ - AIE4_HWCTX_ERROR, /* sets has_error, destroy context */ + AIE4_HWCTX_DISCONNECT, /* sets has_reset, do not destroy context */ + AIE4_HWCTX_ERROR, /* sets has_reset, destroy context */ }; int aie4_hwctx_init(struct amdxdna_hwctx *hwctx); @@ -192,6 +211,8 @@ void aie4_hwctx_resume_jobs(struct amdxdna_hwctx *hwctx); int aie4_hwctx_config(struct amdxdna_hwctx *hwctx, u32 type, u64 value, void *buf, u32 size); int aie4_hwctx_sync_debug_bo(struct amdxdna_hwctx *hwctx, u32 debug_bo_hdl); +void aie4_hwctx_reset(struct amdxdna_hwctx *hwctx, + const struct aie4_async_ctx_error *ctx_err); /* aie4_pci.c */ void aie4_hwctx_suspend_all(struct amdxdna_dev_hdl *ndev, int clean_jobs); diff --git a/drivers/accel/amdxdna/amdxdna_ctx.h b/drivers/accel/amdxdna/amdxdna_ctx.h index bf248d3f16ed..7a7406c6f706 100644 --- a/drivers/accel/amdxdna/amdxdna_ctx.h +++ b/drivers/accel/amdxdna/amdxdna_ctx.h @@ -89,6 +89,7 @@ struct amdxdna_cmd_preempt_data { #define AMDXDNA_CMD_CTX_HEALTH_V1 1 #define AMDXDNA_CMD_CTX_HEALTH_AIE2 0 +#define AMDXDNA_CMD_CTX_HEALTH_AIE4 1 struct amdxdna_ctx_health { u32 version; u32 npu_gen; diff --git a/drivers/accel/amdxdna/amdxdna_error.h b/drivers/accel/amdxdna/amdxdna_error.h index 326d7153b17d..c384eec3377e 100644 --- a/drivers/accel/amdxdna/amdxdna_error.h +++ b/drivers/accel/amdxdna/amdxdna_error.h @@ -30,6 +30,8 @@ enum amdxdna_error_num { AMDXDNA_ERROR_NUM_AIE_LOCK, AMDXDNA_ERROR_NUM_AIE_DMA, AMDXDNA_ERROR_NUM_AIE_MEM_PARITY, + AMDXDNA_ERROR_NUM_KDS_CU = 13, + AMDXDNA_ERROR_NUM_KDS_EXEC, AMDXDNA_ERROR_NUM_UNKNOWN = 15, }; @@ -56,6 +58,14 @@ enum amdxdna_error_module { (FIELD_PREP(AMDXDNA_EXTRA_ERR_COL_MASK, col) | \ FIELD_PREP(AMDXDNA_EXTRA_ERR_ROW_MASK, row)) +/* Extra error code of a context error: firmware context status and ID. */ +#define AMDXDNA_EXTRA_ERR_CTX_ID_MASK GENMASK_U64(31, 0) +#define AMDXDNA_EXTRA_ERR_CTX_STATUS_MASK GENMASK_U64(63, 32) + +#define AMDXDNA_EXTRA_ERR_CTX_ENCODE(status, ctx_id) \ + (FIELD_PREP(AMDXDNA_EXTRA_ERR_CTX_ID_MASK, ctx_id) | \ + FIELD_PREP(AMDXDNA_EXTRA_ERR_CTX_STATUS_MASK, status)) + /* * Maximum number of async event buffers. This value is used in two places: * (1) to size the management mailbox channel, which must happen before -- 2.34.1