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.52.28 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796145668; b=z9wxxbAnJxAM8Paif5huqb8/dbSinP7zxyf8h26Bx4moOOKIxKrzbH2k5qhD7XY9Q4K1 K/rrOqeJVXsA0tabQJywBBsTNgd+r7Aqcv/liU3lw/8MNmjSc4P1BMLejHplr/ug0XLLL Y03FwHr2TsNArtwIaqnefrtA0aZQMiozcyUa+8kqWadmu5TPMOXC6pCYPLGr9YmqHFxsl qxz3OP2NBrSk70H9E7O3uetbpqwnhH44jGN41r12QfMNnvP8mxGYoKrKf/n+K3sVOhG3A OpXP/x6eRDTUkT8LV3O2UkHfqiFl8rgP++AsFS+Ecyd1vVn4vKm0fIH4j4T4/00KVuw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796145668; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Message-ID:Date:MIME-Version:User-Agent:Subject: Content-Language:To:CC:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding: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=FBJHK4wWCVMTqS60/cAlGOZc2CgNrV2iq78x2LlR5q8=; b=S/L+bapOtufb0dwCMB2pkPXXrpz5UiXoSvkvDVOpS00wttbwZBSSb5WuM/iLxEp8qiZM zHZSGGPKKXbvg06FwbMF3H1KDXVa0SBpx6MvIzXYYicyZlyeziP51qLng04bsm3sY/IT8 TwSt9BqPTP8ptzKdssD+CBI9dftVGvyEWWxyp/ZJCEhQTJiurMK4O9wRzekSO+eGVkXfi UsgvbCicZRlcqE894ECSBHjvG6u13nG6SHTWEAYMDbXNl9XEEkhU31+9S03wpSEBvIbBt buEsngdzjgN29UGSKT/A3fgwfcwVCsZf0828VlYpFXw/ep9I/OR1oLiQwKDsEhvRXkA== 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=VFOTGVVE; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.28 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011028.outbound.protection.outlook.com [52.101.52.28]) (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 38CA2606A320 for ; Tue, 1 Dec 2026 17:21:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 38CA2606A320 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=VFOTGVVE ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LjYZQxTeep5WwnBfMgH/6tv9xEPJkhPhft6JnFdhaOl5Qr+ch/fa66QG/hG8TwuCu7YGv7yLIaHv9daQBzsPfHMvtnJWo8KP8voUTdUVIoRsqJO1nn4TzYZDXtdag6tvXpUOjihat8oUQ7kbvqGV1TezqUJBmzckiV2WmyMgYHg28EkwGk1FIIfeF1RFVZqbm/Vh1bZiHJ+ZVqVeBzNffFUfjBzgfURq0zXa8sajZuRW0brdQ2Jg5JozOf4G6jYNx6Ic0s2/7BQnUOYGn56p5HRb02GxoeD35c+1YNwVpqezojnK6xNxhVy6JPFp/eG4RugfvqMvt8cr0EI0qTdOrw== 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=FBJHK4wWCVMTqS60/cAlGOZc2CgNrV2iq78x2LlR5q8=; b=Ra9n4mMh2CHrU+RNoujRpHoZXUVFpuzG2vGySJMF3RKpeJQE8WIt2oS90Bl3wR2RjrHV/984/CXvRsfbr0YXFHkEZFd/uIqGda9njtt9crEarcdhDzNSp9BL8JUhtVbXP1hH9NYiB8Lqni70Tj7tpEJKh66bFS+BoAFaFUe4H+guA86kaodlAdPWudv/+sVR2QyCjl8YozSvvLI1Av/sVfXyfXDSC6rLFMTRa1pl/YGyb10CExo7fQ1iCv3CN753+XunK+3llhe9GDrebaSYr/i7PtaicLVhBWil2t28F6FIsgBMheVF0CSlKsKBdIaNZK+7mTJWyunQVRLmYV3nlA== 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=FBJHK4wWCVMTqS60/cAlGOZc2CgNrV2iq78x2LlR5q8=; b=VFOTGVVE+uJkkvZVcW/nKh/RRFbPXtb4ar49Zx59FfTLRNK5Ws8ETX73kWNeufrm5CCmXOH17ZUz5NUrtgP/rFihz0kikLKUEQxYk8L/t4M6tDdJaOmHuYXu8E9w72byqmFPBuVLBiT/jSnIA4fB3TnI3LHqe6KGgOfxeDqqPmo= Received: from CY5P220CA0001.NAMP220.PROD.OUTLOOK.COM (2603:10b6:930:ed::12) by SN7PR12MB6861.namprd12.prod.outlook.com (2603:10b6:806:266::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.7; Tue, 1 Dec 2026 17:21:02 +0000 Received: from MWH0EPF000D894C.namprd05.prod.outlook.com (2603:10b6:930:ed:cafe::87) by CY5P220CA0001.outlook.office365.com (2603:10b6:930:ed::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 17:21:01 +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 MWH0EPF000D894C.mail.protection.outlook.com (10.167.249.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 17:21:01 +0000 Received: from satlexmb08.amd.com (10.181.42.217) 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; Tue, 1 Dec 2026 11:20:58 -0600 Received: from [172.19.71.207] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Tue, 1 Dec 2026 11:20:57 -0600 Message-ID: <23dbf227-0b1e-5a77-4086-baea491968a1@amd.com> Date: Tue, 1 Dec 2026 09:20:56 -0800 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 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH V2 4/5] accel/amdxdna: Handle AIE4 firmware notifications Content-Language: en-US To: David Zhang , , , , , , CC: Nishad Saraf , , References: <20261130225904.1103363-1-yidong.zhang@amd.com> <20261130225904.1103363-5-yidong.zhang@amd.com> From: Lizhi Hou In-Reply-To: <20261130225904.1103363-5-yidong.zhang@amd.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000D894C:EE_|SN7PR12MB6861:EE_ X-MS-Office365-Filtering-Correlation-Id: 31927d70-b7cc-45c4-fd9f-08df4fcf790d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|36860700016|376014|1800799024|4143699003|261009223027099003|18002099003|22082099003|261028144727099003|11063799006|10067099003|5023799004|261026121527099003|261021121427099003|261026140227099003|261022105027099003|56012099006|261102123227099003; X-Microsoft-Antispam-Message-Info: uV/4y/SRBoJzSG1Gn1GNP6hb1vdqSIYLiveVGaGtwpEdU+YReKk5q0KvfFKTtf4cn31MnSHO4tQmS1fdc4AQdLxoZYAYEUmKtQBRfsQfSJY6LgdGf/gt25nAPrFG75PLHXlQBjN6IlrjMHIM7Yszv5RfgJ87Omg3YfuBoxbg5UttrkSqo3ql2i2GBQCfO487b24+L1ennTJo/yz9ywQTP2Ql7b1culzYfJPVbuiKnQ6A1qalTXxF4UIbs7EX51cnoyuOZkVMK4X2wvFzIYDBAbm4PKS0CdZSOxQwuApAxevAKlfJwO5gvtB3vTqCQ5pSWHEfyhJhC1n9g+wwboWam3S4X0HbdEPLJD84lR8BMcopEhNhxbm0O1Q8ORvensdTDOv3LKlsgwp1NHnsw8JZvKmPjEgaCPAZjWwbtxubD5e0/KwL1LyXRnxy77l0eBW6JNz2HWO68ilUg2FvIHYHyTmv+qF6Gj6C2f2CBkZo2LVtxNS42KYe/BgRrJjHw1ZOdfKXLYNYGvM92ySk2VtpopgKvcG8PIOuuX91CVqAbnm0NnM3oWZtDx86vzIqdhEowGeFNksYnuenecpOoUVWgMDTq2VrrpXslToL8zNc1oU2gGdUUlSc0PeJFnjJsV2yOWZamgD4C19krl4yNgdlt6NUSuI/G/7ViRR25kuVqVHclSd1ypDGCVylva9PDWyHMr8CCFdCBj8eJCfHWUQpzQ== 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)(23010399003)(82310400026)(36860700016)(376014)(1800799024)(4143699003)(261009223027099003)(18002099003)(22082099003)(261028144727099003)(11063799006)(10067099003)(5023799004)(261026121527099003)(261021121427099003)(261026140227099003)(261022105027099003)(56012099006)(261102123227099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3Ue8a32dEEmxRqgKhJdyVn7dyFPJmZl9u09GILeGQzhuBYGGA0ywZl26kq7jpk8ndLuDG8qDRXlk5tSusQ/ucJieNR9f+UvLwpZfn3/m/dUppiFS8vi31l3S4qoqpazJVo8mepvgste7SgZX0Wm4wEolZGOG0QAPHNCprE/Tw+B5kPfvDyxLy5S8qmZjMXEd+oRHP/wE60PjZj1O2FDV2FQF3rBcYJ4NzAOcpKoHY1gM7ev59Wx3NBhbG/s2sFjqEZMbVRCUweGjFkpfxUyJfdZbbXQMeGK14T1rDK2gu3EOILSOa9GqW2cM4/BdCXbjUhPZqLTz+SXSm86wCmNVydtqXzo8vMBuJrBquBBzvq3rFw6EEqCr90h4CmICwLFU0RzognHpqG0pBt2zomdMOCzVGYfkoanJ5RUEp41zO28X6aw2Isu8wvN8WCmVxK8L X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 17:21:01.5151 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31927d70-b7cc-45c4-fd9f-08df4fcf790d 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: MWH0EPF000D894C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6861 On 11/30/26 14:59, David Zhang wrote: > From: Nishad Saraf > > Firmware sends notifications, such as context errors, as messages with > ID 0. Add an optional mailbox handler for ID 0 messages, and use it on > the AIE4 management channel to reset the context on a context error. > > Signed-off-by: Nishad Saraf > Signed-off-by: David Zhang > --- > drivers/accel/amdxdna/aie4_error.c | 104 ++++++++++++++++++++++++ > drivers/accel/amdxdna/aie4_msg_priv.h | 31 +++++++ > drivers/accel/amdxdna/aie4_pci.c | 2 + > drivers/accel/amdxdna/aie4_pci.h | 1 + > drivers/accel/amdxdna/amdxdna_mailbox.c | 18 ++++ > drivers/accel/amdxdna/amdxdna_mailbox.h | 17 ++++ > 6 files changed, 173 insertions(+) > > diff --git a/drivers/accel/amdxdna/aie4_error.c b/drivers/accel/amdxdna/aie4_error.c > index a56bf5891bf1..9ca99af3e2c1 100644 > --- a/drivers/accel/amdxdna/aie4_error.c > +++ b/drivers/accel/amdxdna/aie4_error.c > @@ -407,3 +407,107 @@ void aie4_async_events_stop(struct amdxdna_dev_hdl *ndev) > if (events) > WRITE_ONCE(events->gen, events->gen + 1); > } > + > +/* > + * struct aie4_async_note - context error notification from firmware > + * @work: worker that resets the context > + * @ndev: device handle > + * @events: pool owning the workqueue > + * @gen: @events gen when the notification arrived > + * @ctx_gen: device context generation when the notification arrived > + * @ctx_id: firmware context ID > + */ > +struct aie4_async_note { > + struct work_struct work; > + struct amdxdna_dev_hdl *ndev; > + struct aie4_async_events *events; > + u32 gen; > + u64 ctx_gen; > + u32 ctx_id; > +}; > + > +static void aie4_async_note_worker(struct work_struct *work) > +{ > + struct aie4_async_note *note = container_of(work, struct aie4_async_note, work); > + struct amdxdna_dev_hdl *ndev = note->ndev; > + struct amdxdna_dev *xdna = ndev->aie.xdna; > + > + mutex_lock(&xdna->dev_lock); > + /* Skip a notification left over from a previous channel. */ > + if (note->gen != note->events->gen) > + goto unlock; > + > + /* There is no report, so record it like a job timeout. */ > + aie4_record_async_error(ndev, AMDXDNA_ERROR_NUM_KDS_EXEC, 0, note->ctx_id); > + aie4_reset_hwctx_by_id(ndev, note->ctx_id, note->ctx_gen, NULL); > + > +unlock: > + mutex_unlock(&xdna->dev_lock); > + kfree(note); > +} > + > +/* > + * Called from the mailbox receive worker for each message firmware sends on > + * its own, so defer the context reset to the async event workqueue. > + */ > +int aie4_async_note_cb(void *handle, u32 opcode, void __iomem *data, size_t size) > +{ > + struct amdxdna_dev_hdl *ndev = handle; > + struct aie4_async_events *events = ndev->async_events; > + struct amdxdna_dev *xdna = ndev->aie.xdna; > + struct aie4_async_note *note; > + u32 event_id, type, ctx_id; > + > + if (opcode != AIE4_MSG_OP_ASYNC_EVENT_NOTE || > + size < sizeof(struct aie4_msg_async_note)) > + return -EINVAL; > + > + event_id = readl(data + offsetof(struct aie4_msg_async_note, event_id)); > + switch (event_id) { > + case AIE4_ASYNC_NOTE_CONTEXT_ERROR: > + ctx_id = readl(data + offsetof(struct aie4_msg_async_note, > + context_error.ctx_id)); > + XDNA_ERR(xdna, "Firmware reported context %u error", ctx_id); > + break; > + case AIE4_ASYNC_NOTE_REPORT_DROPPED: > + type = readl(data + offsetof(struct aie4_msg_async_note, > + report_dropped.async_event_type)); > + ctx_id = readl(data + offsetof(struct aie4_msg_async_note, > + report_dropped.ctx_id)); > + /* An AIE error also sends CONTEXT_ERROR; reset only for this one. */ > + if (type != AIE4_ASYNC_EVENT_TYPE_CTX_ERROR) { > + XDNA_ERR(xdna, "Firmware had no async event buffer, type %u context %u", > + type, ctx_id); > + return 0; > + } > + XDNA_ERR(xdna, > + "TDR or uC error on context %u without a report", > + ctx_id); > + break; > + case AIE4_ASYNC_NOTE_POWER_ERROR: > + XDNA_ERR(xdna, "Firmware reported a power sequencing error"); > + return 0; > + default: > + XDNA_DBG(xdna, "Firmware notification %u ignored", event_id); > + return 0; > + } > + > + /* The PF runs no contexts. */ > + if (!events) > + return 0; > + > + /* Called from the mailbox receive worker, which must not block. */ > + note = kzalloc_obj(*note, GFP_NOWAIT); > + if (!note) > + return -ENOMEM; > + > + note->ndev = ndev; > + note->events = events; > + note->gen = READ_ONCE(events->gen); > + /* Contexts created after this notification are not the one it reports. */ > + note->ctx_gen = READ_ONCE(ndev->ctx_gen); > + note->ctx_id = ctx_id; > + INIT_WORK(¬e->work, aie4_async_note_worker); > + queue_work(events->wq, ¬e->work); > + return 0; > +} > diff --git a/drivers/accel/amdxdna/aie4_msg_priv.h b/drivers/accel/amdxdna/aie4_msg_priv.h > index f8c94cf316fd..7a0f89150bff 100644 > --- a/drivers/accel/amdxdna/aie4_msg_priv.h > +++ b/drivers/accel/amdxdna/aie4_msg_priv.h > @@ -16,6 +16,8 @@ enum aie4_msg_opcode { > AIE4_MSG_OP_ASYNC_EVENT_REPORT = 0x10004, > AIE4_MSG_OP_SET_RUNTIME_CONFIG = 0x10007, > AIE4_MSG_OP_QUERY_CERT_FIRMWARE_VERSION = 0x1000F, > + /* Sent by firmware with message ID 0; no response is expected. */ > + AIE4_MSG_OP_ASYNC_EVENT_NOTE = 0x10012, > > AIE4_MSG_OP_CREATE_VFS = 0x20001, > AIE4_MSG_OP_DESTROY_VFS = 0x20002, > @@ -402,4 +404,33 @@ struct aie4_async_ctx_error { > struct aie4_msg_app_health_report app_health_report; > }; > > +/* Events reported with AIE4_MSG_OP_ASYNC_EVENT_NOTE. */ > +enum aie4_msg_async_note_id { > + AIE4_ASYNC_NOTE_FW_LOG_WATERMARK, > + AIE4_ASYNC_NOTE_FW_TRACE_WATERMARK, > + AIE4_ASYNC_NOTE_DEBUG_MODE_ACTIVATED, > + AIE4_ASYNC_NOTE_CONTEXT_ERROR, > + AIE4_ASYNC_NOTE_REPORT_DROPPED, > + AIE4_ASYNC_NOTE_POWER_ERROR, > +}; > + > +/* > + * AIE4_MSG_OP_ASYNC_EVENT_NOTE: an event small enough to fit in the message. > + * @event_id selects the union member. > + */ > +struct aie4_msg_async_note { > + __u32 event_id; > + union { > + __u32 reserved[4]; > + struct { > + __u32 ctx_id; > + } context_error; > + /* A report that firmware had no async event buffer for. */ > + struct { > + __u32 async_event_type; > + __u32 ctx_id; > + } report_dropped; > + }; > +} __packed; > + > #endif /* _AIE4_MSG_PRIV_H_ */ > diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c > index a45c6bb21aaf..78a739573ad3 100644 > --- a/drivers/accel/amdxdna/aie4_pci.c > +++ b/drivers/accel/amdxdna/aie4_pci.c > @@ -250,6 +250,7 @@ static int aie4_mailbox_start(struct amdxdna_dev *xdna, > XDNA_ERR(xdna, "failed to alloc mailbox channel"); > return -ENODEV; > } > + xdna_mailbox_set_async_cb(ndev->aie.mgmt_chann, ndev, aie4_async_note_cb); > > mgmt_mb_irq = pci_irq_vector(pdev, ndev->aie.mgmt_chan_idx); > if (mgmt_mb_irq < 0) { > @@ -491,6 +492,7 @@ static int aie4_vf_hw_start(struct amdxdna_dev_hdl *ndev) > /* > * A VF registers no async event buffers, so firmware keeps none of > * its memory across a VF reset or driver reload. > + * Firmware reports VF context errors with notifications instead. > */ > > ret = aie4_restore_power_mode(ndev); > diff --git a/drivers/accel/amdxdna/aie4_pci.h b/drivers/accel/amdxdna/aie4_pci.h > index b24865c9ebc8..6da2810c3fb4 100644 > --- a/drivers/accel/amdxdna/aie4_pci.h > +++ b/drivers/accel/amdxdna/aie4_pci.h > @@ -161,6 +161,7 @@ int aie4_async_events_alloc(struct amdxdna_dev_hdl *ndev, u32 num_events); > void aie4_async_events_free(struct amdxdna_dev_hdl *ndev); > int aie4_async_events_register(struct amdxdna_dev_hdl *ndev, u32 num_events); > void aie4_async_events_stop(struct amdxdna_dev_hdl *ndev); > +int aie4_async_note_cb(void *handle, u32 opcode, void __iomem *data, size_t size); > > /* aie4_message.c */ > int aie4_query_aie_metadata(struct amdxdna_dev_hdl *ndev, > diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.c b/drivers/accel/amdxdna/amdxdna_mailbox.c > index 967f6f1eb764..2d6cce06ecf6 100644 > --- a/drivers/accel/amdxdna/amdxdna_mailbox.c > +++ b/drivers/accel/amdxdna/amdxdna_mailbox.c > @@ -66,6 +66,8 @@ struct mailbox_channel { > struct work_struct rx_work; > u32 i2x_head; > bool bad_state; > + void *async_handle; > + xdna_mailbox_async_cb_t async_cb; > > /* Pre-allocated message buffer pool */ > void *msg_buf; > @@ -302,6 +304,15 @@ mailbox_get_resp(struct mailbox_channel *mb_chann, struct xdna_msg_header *heade > u32 slot; > > msg_id = header->id; > + if (!msg_id && mb_chann->async_cb) { > + ret = mb_chann->async_cb(mb_chann->async_handle, header->opcode, > + data, header->total_size); > + if (ret) > + MB_ERR(mb_chann, "Async handler for opcode 0x%x ret %d", > + header->opcode, ret); > + return 0; > + } > + > if (!mailbox_validate_msgid(msg_id)) { > MB_ERR(mb_chann, "Bad message ID 0x%x", msg_id); > return -EINVAL; > @@ -549,6 +560,13 @@ struct mailbox_channel *xdna_mailbox_alloc_channel(struct mailbox *mb) > return NULL; > } > > +void xdna_mailbox_set_async_cb(struct mailbox_channel *mb_chann, void *async_handle, > + xdna_mailbox_async_cb_t async_cb) > +{ > + mb_chann->async_handle = async_handle; > + mb_chann->async_cb = async_cb; > +} > + > void xdna_mailbox_free_channel(struct mailbox_channel *mb_chann) > { > if (!mb_chann) > diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.h b/drivers/accel/amdxdna/amdxdna_mailbox.h > index 7f4a40b4230b..cf06bc8c6c09 100644 > --- a/drivers/accel/amdxdna/amdxdna_mailbox.h > +++ b/drivers/accel/amdxdna/amdxdna_mailbox.h > @@ -9,6 +9,10 @@ > struct mailbox; > struct mailbox_channel; > > +/* Handler for a message firmware sends on its own, with message ID 0. */ > +typedef int (*xdna_mailbox_async_cb_t)(void *handle, u32 opcode, > + void __iomem *data, size_t size); > + > /* > * xdna_mailbox_msg - message struct > * > @@ -102,6 +106,19 @@ xdna_mailbox_start_channel(struct mailbox_channel *mb_chann, > u32 xdna_mailbox_intr_reg, > int mb_irq, u32 n_msg); > > +/* > + * xdna_mailbox_set_async_cb() -- set the handler for firmware notifications > + * > + * @mb_chann: the handle return from xdna_mailbox_alloc_channel() > + * @async_handle: handle passed to @async_cb > + * @async_cb: called from the receive worker for each message with ID 0; > + * must not block. Its return value is only logged. > + * > + * Call before xdna_mailbox_start_channel(). > + */ > +void xdna_mailbox_set_async_cb(struct mailbox_channel *mb_chann, void *async_handle, > + xdna_mailbox_async_cb_t async_cb); > + Reviewed-by: Lizhi Hou > /* > * xdna_mailbox_free_channel() -- free mailbox channel > *