From nobody Mon Nov 23 05:00:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1791198238; cv=none; d=zohomail.com; s=zohoarc; b=m049GdU9Cr73UytqSZ4u7XIKr81wck73BIV3RSVihQsMKPyHhylX+RDYKUx34NGVXAZk8BHNuKJ1zse7wYrByyUYxwaFhFXyWSXvV5fr8JBEWbs7EFOwvPuKoXHx6qFbU9b9wVQ1uLnmpJBNUPhUu8GockomLMgoB4qF4t6QK5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791198238; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=M5v8qUl4HO0U7DRUSDf/YGwEmMmliYBjW9aq2FXssZY=; b=amyh7jifTx4x9lD5FQIxTpkDK4K4qsI/fXik1j5DJtNhofdBOGofoga7L3c//Mx1kNTgmivDdu3wHt/IQaib1NrH4xMT/TIzEZyCdcC+ym+cJbA8Gcf+thOZTDuC7m0a8R8AY4mXqPRPP6GkMawcBF18tQj4NggWhp9T1Rb/RoQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791198238364783.2368293210181; Mon, 5 Oct 2026 04:03:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xDgTe-0002Zs-1a; Mon, 05 Oct 2026 07:03:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <394PDagoKCmoabIVTMgRPcOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--stanleyjhu.bounces.google.com>) id 1xDgTb-0002YK-DO for qemu-devel@nongnu.org; Mon, 05 Oct 2026 07:03:23 -0400 Received: from mail-pf1-x448.google.com ([2607:f8b0:4864:20::448]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <394PDagoKCmoabIVTMgRPcOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--stanleyjhu.bounces.google.com>) id 1xDgTZ-0005QF-G7 for qemu-devel@nongnu.org; Mon, 05 Oct 2026 07:03:22 -0400 Received: by mail-pf1-x448.google.com with SMTP id d2e1a72fcca58-86fa6b15ed3so1956372b3a.1 for ; Mon, 05 Oct 2026 04:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1791198199; x=1791802999; darn=nongnu.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=M5v8qUl4HO0U7DRUSDf/YGwEmMmliYBjW9aq2FXssZY=; b=mla61yVEQSehEE0+4uEY9rm1rMy+DN6bYlii1+0QqfoLzlmUP7bDLMKPA/3z/+rmTR aYZP9hAJ2wnFUGPHWkmqDevpI4dgpStSFAxVa5gSJfwDtGNczF8WrRKjGtcFGjZm4ekl WiO7aIAz3spB4jbKQc97IPwebfmzZoTESTIncS8wyeVpY2Z/hyhN8LzRCxkQWGjiVWhn QX9xXYor2UVYN5SteXDN5k5BqxdyHbOlcyCsv2TT0YHcqx0Dh51pO3iBN4jwFxi3oTVN gXkjitnNW9lm6qVCL+8loiQi5h/zg8n2Le/70T+FyHyAd+bVtPo2DL3/cpHIGuOYHE7L Lb1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791198199; x=1791802999; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=M5v8qUl4HO0U7DRUSDf/YGwEmMmliYBjW9aq2FXssZY=; b=saHuzGoVbtyjAZPgRwM/Q+SPw8p+TzexqAs+MtMPUv9L+w433sg/mZbZrU+YstpglR dGHbGxBAFP6rVO3Q+QUxmFF0nyXriRKOvBdq3ZGQSfzgUFxXlevPUHhksI6zkqKPPRIm HrOj7AX2wfx9HPXSF7u8U6GWeMO7fKS89L0kSYPLY9DH+exSiSmb0wfJ6jEoPd6N3PJ1 h1+uYpJMkmp8/mC5hfZhu1ZEU1qLXtVOJh2P2htcNNUINEHa/HA9+DTnu5cRr8kl1hVY iPxZuhZEO60UX631cl7V49fJCeySC13li1Kz8pN/zeHcQL8EUPAC/6Lx5D/d/43wHrnW 8caA== X-Forwarded-Encrypted: i=1; AKwUvBwdo0F/jSVJFwowXUPK86s+glrzmlEBNi9tgSh9LplHk10XBUE9ioEcQpOlNk1CquGJ1mlIQL5Jlt0I@nongnu.org X-Gm-Message-State: AFq9FYLAmjhDpj8od2t/GkaAkg4RckLvlQYWidnv/P5rA2h5b3bjYQLY Y2nGBVXn9YoHUenLPPzmH89sDUpCnbPh15NUC2cZxoSdLNdN34UH8PLlTi5QjwJeZ3Xrc3ZZEeS l9bYSMn6RUkqcF/B6ErXJPw== X-Received: from pfbmt10.prod.google.com ([2002:a05:6a00:6e6a:b0:88f:a93e:7dfa]) (user=stanleyjhu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1bc7:b0:880:ee58:2768 with SMTP id d2e1a72fcca58-88af8b3f3c3mr8408909b3a.56.1791198199093; Mon, 05 Oct 2026 04:03:19 -0700 (PDT) Date: Mon, 5 Oct 2026 19:03:12 +0800 In-Reply-To: <20261005110315.3327418-1-stanleyjhu@google.com> Mime-Version: 1.0 References: <20261005110315.3327418-1-stanleyjhu@google.com> X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20261005110315.3327418-2-stanleyjhu@google.com> Subject: [PATCH v4 1/4] hw/ufs: Track SCSIRequest and cancel pending requests in ufs_clear_req From: Stanley Jhu To: Jeuk Kim , Jeuk Kim Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Stefan Hajnoczi , Richard Henderson , Paolo Bonzini , Fam Zheng , Kevin Wolf , Hanna Reitz , Jinyoung Choi Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::448; envelope-from=394PDagoKCmoabIVTMgRPcOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--stanleyjhu.bounces.google.com; helo=mail-pf1-x448.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1791198239465158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Existing callers of ufs_clear_req() only invoke it after requests are no longer in flight. In preparation for Task Management Request (TMR) task abort and MCQ queue cleanup support, where individual in-flight requests are aborted without purging the entire SCSI device, track the active SCSIRequest in UfsRequest and cancel any pending request via scsi_req_cancel() in ufs_clear_req(). Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim --- hw/ufs/lu.c | 8 ++++++++ hw/ufs/ufs.c | 6 ++++++ hw/ufs/ufs.h | 1 + 3 files changed, 15 insertions(+) diff --git a/hw/ufs/lu.c b/hw/ufs/lu.c index bdb165085..5905c49fa 100644 --- a/hw/ufs/lu.c +++ b/hw/ufs/lu.c @@ -173,6 +173,9 @@ static void ufs_scsi_command_complete(SCSIRequest *scsi= _req, size_t resid) int16_t status =3D scsi_req->status; uint32_t transfered_len =3D scsi_req->cmd.xfer - resid; =20 + assert(req !=3D NULL); + req->sreq =3D NULL; + /* WB / HID accounting should only happen for successful commands */ if (status =3D=3D GOOD) { ufs_wb_process_write_req(req, transfered_len); @@ -190,6 +193,10 @@ static void ufs_scsi_command_complete(SCSIRequest *scs= i_req, size_t resid) =20 static void ufs_scsi_command_cancelled(SCSIRequest *scsi_req) { + UfsRequest *req =3D scsi_req->hba_private; + + assert(req !=3D NULL); + req->sreq =3D NULL; scsi_req->hba_private =3D NULL; scsi_req_unref(scsi_req); } @@ -389,6 +396,7 @@ static UfsReqResult ufs_process_scsi_cmd(UfsLu *lu, Ufs= Request *req) SCSIRequest *scsi_req =3D scsi_req_new(lu->scsi_dev, task_tag, lu->lun, req->req_upiu.sc.cdb, UFS_CDB_SIZE, req); + req->sreq =3D scsi_req; =20 uint32_t len =3D scsi_req_enqueue(scsi_req); if (len) { diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index 3c4d7424d..adae6639e 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -2221,6 +2221,12 @@ void ufs_complete_req(UfsRequest *req, UfsReqResult = req_result) =20 static void ufs_clear_req(UfsRequest *req) { + if (req->sreq !=3D NULL) { + SCSIRequest *sreq =3D req->sreq; + req->sreq =3D NULL; + scsi_req_cancel(sreq); + } + if (req->sg !=3D NULL) { qemu_sglist_destroy(req->sg); g_free(req->sg); diff --git a/hw/ufs/ufs.h b/hw/ufs/ufs.h index 6f2693b7c..265a43faa 100644 --- a/hw/ufs/ufs.h +++ b/hw/ufs/ufs.h @@ -60,6 +60,7 @@ typedef struct UfsRequest { UtpUpiuRsp rsp_upiu; =20 /* for scsi command */ + SCSIRequest *sreq; QEMUSGList *sg; uint32_t data_len; =20 --=20 2.56.0.rc1.315.gc6ed9934b7-goog From nobody Mon Nov 23 05:00:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1791198239; cv=none; d=zohomail.com; s=zohoarc; b=e2HJHMYzIIWfLIOy5dUbWFKmx0P+Xxb3y0aWwNTYORareFIUUw4J7NbJywd5hvIYyGbMmWa0CC7IURglQWl622MWIN4nYg+uVCZrzrsFRGZsKDrsEEkzLLqzcUQeCqf/Ov3glxrBT6t1eKX9Py/IoqCZriCXsJNfC7X8XUE04Ls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791198239; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DquBNqapPFvSrSvuzaqbhHyPBctiNwwc9aHt5UXK6eA=; b=gmNrKJ+H/1WdwAyDwvrRDSNWKh+dM1690CQ+WvcfeD9WBZTSA1TA2A2ZvJSVvOpDowXGrAshDt3J1wWb4yvqEOS3Rv1W3hbx++8zaED38V78bU8o6BheHe8WhFagnkfIhBifpzhgNQqD9Hu7/RFp/bY9EBlcFPrKZOH/EOHv52I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791198239390521.465445485643; Mon, 5 Oct 2026 04:03:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xDgTj-0002bR-B9; Mon, 05 Oct 2026 07:03:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3-IPDagoKCmsbcJWUNhSQdPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--stanleyjhu.bounces.google.com>) id 1xDgTd-0002Zb-G3 for qemu-devel@nongnu.org; Mon, 05 Oct 2026 07:03:25 -0400 Received: from mail-pg1-x547.google.com ([2607:f8b0:4864:20::547]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3-IPDagoKCmsbcJWUNhSQdPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--stanleyjhu.bounces.google.com>) id 1xDgTb-0005Qe-G4 for qemu-devel@nongnu.org; Mon, 05 Oct 2026 07:03:25 -0400 Received: by mail-pg1-x547.google.com with SMTP id 41be03b00d2f7-cc72777faa2so1186365a12.1 for ; Mon, 05 Oct 2026 04:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1791198201; x=1791803001; darn=nongnu.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DquBNqapPFvSrSvuzaqbhHyPBctiNwwc9aHt5UXK6eA=; b=kHJy4rZy4bb34wuwjjJSikJtQbKd5uSwcPTgKrNUW2AcEM4V460NulgSbjCDgO5mXN 0oDiKWUZWNIET0Xa0z2Q+1NuZcXrPWEv/7FbJmPNZRHFq4Nq+ytzwUGIm3nJhtf94MZV lvK8uVUVK0nxEOszIumJDPBAgFHktOUlUPD7vuzT59FSU9FGQlZYEf32Z9aj8UvZg4qz cTwpBTtDrwY1Uy7SlMHEYH0jqDsG0ETyV0DTtysyaTdfsQx5p+1dgTmhzTMxCN/QFjBE QpMIqKwl1JmZ00bvrHAkJ9C2221Wg+uoaOmD4Knewkzbyj1E/m0W7rWbqSUWtAPgJaSi wtqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791198201; x=1791803001; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DquBNqapPFvSrSvuzaqbhHyPBctiNwwc9aHt5UXK6eA=; b=RAfFUo4CXLoB/ywgJwdn8AqMztppy0uRKqrkZXr1uAEl7enGyk+HcqdCoqXF91h6wx 1K3VIPDWGqMz8OQBQvXQsBrxfYxCd6GG9u2EPH5X9QN/YLfKMrt2yDdamzSmKbVnwUU5 QALSH6l31JNfN8kRIlnT+Hlo3qFadPIvw9anI+5NPcog4dF4T7TrijF4U95iQlJNMIHW +4AjXILoGQOxlnVMpBaEwpTACe997ZlA9c4D/g6A6Wbt0R42sz8JG+Np2TQmfeOOaKFM kXnVKXTx7ClhzeV84aHPO9fOHUyA2bG2fl0H/s7HdqR+WYfeq9cR5c7EXTAwmBOIGbTU mhAQ== X-Forwarded-Encrypted: i=1; AKwUvByaXr4+OHPRwAV8EzF5dfYQS6VJfbA+YfzP4DcWqmbruz/s6fKb65Bk7k3Awb3lGOd1MSpzrhMhPOrk@nongnu.org X-Gm-Message-State: AFuF++nbXBBJ/JVneRKkF2sTj9Uwl+3oAaS/QyMOzNHShGBfsX1YWGXZ k/p8VYGiYtetdwPjSayzmWf9O3s1SkRxQ2d0fk13ESzTiAeS4UhXVyZMPgYvXX5BDfWHWSHUR6A VCRfAH6QPzRpZard87pJz+Q== X-Received: from pgba18-n1.prod.google.com ([2002:a05:6a02:6452:10b0:cc1:bda2:d0a3]) (user=stanleyjhu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3944:b0:3de:188c:27b7 with SMTP id adf61e73a8af0-3e0d6ba9712mr6282429637.38.1791198200883; Mon, 05 Oct 2026 04:03:20 -0700 (PDT) Date: Mon, 5 Oct 2026 19:03:13 +0800 In-Reply-To: <20261005110315.3327418-1-stanleyjhu@google.com> Mime-Version: 1.0 References: <20261005110315.3327418-1-stanleyjhu@google.com> X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20261005110315.3327418-3-stanleyjhu@google.com> Subject: [PATCH v4 2/4] hw/ufs: Support MCQ runtime interrupt and queue status registers From: Stanley Jhu To: Jeuk Kim , Jeuk Kim Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Stefan Hajnoczi , Richard Henderson , Paolo Bonzini , Fam Zheng , Kevin Wolf , Hanna Reitz , Jinyoung Choi Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::547; envelope-from=3-IPDagoKCmsbcJWUNhSQdPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--stanleyjhu.bounces.google.com; helo=mail-pg1-x547.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1791198241112158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement Multi-Circular Queue (MCQ) runtime operational registers (SQnRTC, SQnRTS, SQnCTI, SQnIS/IE, CQnIS/IE, CQnIACR) per JEDEC UFSHCI: - Handle SQRTC.STOP transitions (0 -> 1 stop and 1 -> 0 resume) and SQRTC.ICU cleanup using Submission Queue Cleanup Task Information (SQCTI). Immediately clear SQRTS.CUS and SQRTS.RTC on ICU =3D 1, post a CQE with OCS =3D UFS_OCS_ABORTED on an active matching task, and set SQRTS.CUS =3D 1 with SQRTS.RTC =3D 0 (success), 1 (task not found), 2 (SQ not stopped), or 3 (SQ disabled). - Implement write-1-to-clear per-queue interrupt status (SQnIS, CQnIS) and synchronize the global IS.CQES bit. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim --- hw/ufs/trace-events | 1 + hw/ufs/ufs.c | 112 +++++++++++++++++++++++++++++++++++++++++++- include/block/ufs.h | 15 ++++++ 3 files changed, 126 insertions(+), 2 deletions(-) diff --git a/hw/ufs/trace-events b/hw/ufs/trace-events index 922293355..d8173b12b 100644 --- a/hw/ufs/trace-events +++ b/hw/ufs/trace-events @@ -14,6 +14,7 @@ ufs_process_uiccmd(uint32_t uiccmd, uint32_t ucmdarg1, ui= nt32_t ucmdarg2, uint32 ufs_mcq_complete_req(uint8_t qid) "sqid %"PRIu8"" ufs_mcq_create_sq(uint8_t sqid, uint8_t cqid, uint64_t addr, uint16_t size= ) "mcq create sq sqid %"PRIu8", cqid %"PRIu8", addr 0x%"PRIx64", size %"PRI= u16"" ufs_mcq_create_cq(uint8_t cqid, uint64_t addr, uint16_t size) "mcq create = cq cqid %"PRIu8", addr 0x%"PRIx64", size %"PRIu16"" +ufs_write_mcq_op_reg(uint8_t qid, uint32_t offset, uint32_t data) "qid %"P= RIu8", offset 0x%"PRIx32", data 0x%"PRIx32"" ufs_hce_reset(void) "HCE 1 -> 0 reset: cancelling BHs, resetting MCQ and r= equest lists" =20 # error condition diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index adae6639e..956ef9c87 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -446,13 +446,14 @@ static void ufs_mcq_process_sq(void *opaque) { UfsSq *sq =3D opaque; UfsHc *u =3D sq->u; + UfsMcqOpReg *opr =3D &u->mcq_op_reg[sq->sqid]; UfsSqEntry sqe; UfsRequest *req; hwaddr addr; uint16_t head =3D ufs_mcq_sq_head(u, sq->sqid); int err; =20 - if (u->resetting) { + if (u->resetting || FIELD_EX32(opr->sq.rts, SQRTS, STS)) { return; } =20 @@ -536,6 +537,7 @@ static void ufs_mcq_process_cq(void *opaque) } =20 ufs_clear_req(req); + req->state =3D UFS_REQUEST_IDLE; QTAILQ_INSERT_TAIL(&req->sq->req_list, req, entry); } =20 @@ -970,6 +972,56 @@ static void ufs_mcq_process_db(UfsHc *u, uint8_t qid, = uint32_t db) qemu_bh_schedule(sq->bh); } =20 +static void ufs_mcq_sq_cleanup(UfsHc *u, uint8_t qid) +{ + UfsMcqOpReg *opr =3D &u->mcq_op_reg[qid]; + UfsSq *sq =3D u->sq[qid]; + uint8_t task_tag =3D FIELD_EX32(opr->sq.cti, SQCTI, TASK_TAG); + uint8_t lun =3D FIELD_EX32(opr->sq.cti, SQCTI, LUN); + UfsRequest *req =3D NULL; + uint8_t rtc; + + opr->sq.rts =3D FIELD_DP32(opr->sq.rts, SQRTS, CUS, 0); + opr->sq.rts =3D FIELD_DP32(opr->sq.rts, SQRTS, RTC, 0); + + if (!sq) { + rtc =3D 3; + } else if (!FIELD_EX32(opr->sq.rts, SQRTS, STS)) { + rtc =3D 2; + } else { + for (int i =3D 0; i < sq->size; i++) { + UfsRequest *candidate =3D &sq->req[i]; + if ((candidate->state =3D=3D UFS_REQUEST_RUNNING || + candidate->state =3D=3D UFS_REQUEST_ERROR) && + candidate->req_upiu.header.task_tag =3D=3D task_tag && + candidate->req_upiu.header.lun =3D=3D lun) { + req =3D candidate; + break; + } + } + + if (req) { + if (req->sreq !=3D NULL) { + SCSIRequest *sreq =3D req->sreq; + req->sreq =3D NULL; + scsi_req_cancel(sreq); + } + req->utrd.header.dword_2 =3D cpu_to_le32( + (le32_to_cpu(req->utrd.header.dword_2) & ~UFS_MASK_OCS) | + UFS_OCS_ABORTED); + req->state =3D UFS_REQUEST_COMPLETE; + QTAILQ_INSERT_TAIL(&sq->cq->req_list, req, entry); + ufs_mcq_process_cq(sq->cq); + rtc =3D 0; + } else { + rtc =3D 1; + } + } + + opr->sq.rts =3D FIELD_DP32(opr->sq.rts, SQRTS, CUS, 1); + opr->sq.rts =3D FIELD_DP32(opr->sq.rts, SQRTS, RTC, rtc); +} + static void ufs_write_mcq_op_reg(UfsHc *u, hwaddr offset, uint32_t data, unsigned size) { @@ -983,6 +1035,9 @@ static void ufs_write_mcq_op_reg(UfsHc *u, hwaddr offs= et, uint32_t data, =20 opr =3D &u->mcq_op_reg[qid]; =20 + trace_ufs_write_mcq_op_reg(qid, (uint32_t)(offset % sizeof(UfsMcqOpReg= )), + data); + switch (offset % sizeof(UfsMcqOpReg)) { case offsetof(UfsMcqOpReg, sq.tp): if (opr->sq.tp !=3D data) { @@ -990,6 +1045,40 @@ static void ufs_write_mcq_op_reg(UfsHc *u, hwaddr off= set, uint32_t data, } opr->sq.tp =3D data; break; + case offsetof(UfsMcqOpReg, sq.rtc): { + bool prev_stop =3D FIELD_EX32(opr->sq.rtc, SQRTC, STOP); + bool new_stop =3D FIELD_EX32(data, SQRTC, STOP); + + if (!prev_stop && new_stop) { + /* SQ_STOP (0 -> 1): Stop queue */ + opr->sq.rts =3D FIELD_DP32(opr->sq.rts, SQRTS, STS, 1); + if (u->sq[qid] && u->sq[qid]->bh) { + qemu_bh_cancel(u->sq[qid]->bh); + } + } else if (prev_stop && !new_stop) { + /* SQ_START (1 -> 0): Resume queue */ + opr->sq.rts =3D FIELD_DP32(opr->sq.rts, SQRTS, STS, 0); + if (u->sq[qid] && u->sq[qid]->bh) { + qemu_bh_schedule(u->sq[qid]->bh); + } + } + if (FIELD_EX32(data, SQRTC, ICU)) { + ufs_mcq_sq_cleanup(u, qid); + data =3D FIELD_DP32(data, SQRTC, ICU, 0); + } + opr->sq.rtc =3D data; + break; + } + case offsetof(UfsMcqOpReg, sq.cti): + opr->sq.cti =3D data; + break; + case offsetof(UfsMcqOpReg, sq_int.is): + opr->sq_int.is &=3D ~data; + ufs_irq_check(u); + break; + case offsetof(UfsMcqOpReg, sq_int.ie): + opr->sq_int.ie =3D data; + break; case offsetof(UfsMcqOpReg, cq.hp): { UfsCq *cq =3D u->cq[qid]; =20 @@ -1006,8 +1095,27 @@ static void ufs_write_mcq_op_reg(UfsHc *u, hwaddr of= fset, uint32_t data, ufs_mcq_update_cq_head(u, qid, data); break; } - case offsetof(UfsMcqOpReg, cq_int.is): + case offsetof(UfsMcqOpReg, cq_int.is): { + bool pending =3D false; + opr->cq_int.is &=3D ~data; + for (int i =3D 0; i < ARRAY_SIZE(u->mcq_op_reg); i++) { + if (u->mcq_op_reg[i].cq_int.is) { + pending =3D true; + break; + } + } + if (!pending) { + u->reg.is =3D FIELD_DP32(u->reg.is, IS, CQES, 0); + } + ufs_irq_check(u); + break; + } + case offsetof(UfsMcqOpReg, cq_int.ie): + opr->cq_int.ie =3D data; + break; + case offsetof(UfsMcqOpReg, cq_int.iacr): + opr->cq_int.iacr =3D data; break; default: trace_ufs_err_invalid_register_offset(offset); diff --git a/include/block/ufs.h b/include/block/ufs.h index d19b3c65e..b72403c47 100644 --- a/include/block/ufs.h +++ b/include/block/ufs.h @@ -224,6 +224,21 @@ typedef struct QEMU_PACKED UfsMcqSqReg { uint32_t rts; } UfsMcqSqReg; =20 +REG32(SQRTC, offsetof(UfsMcqSqReg, rtc)) + FIELD(SQRTC, STOP, 0, 1) + FIELD(SQRTC, ICU, 1, 1) + +REG32(SQCTI, offsetof(UfsMcqSqReg, cti)) + FIELD(SQCTI, TASK_TAG, 0, 8) + FIELD(SQCTI, LUN, 8, 8) + FIELD(SQCTI, IID, 16, 4) + FIELD(SQCTI, EXT_IID, 20, 4) + +REG32(SQRTS, offsetof(UfsMcqSqReg, rts)) + FIELD(SQRTS, STS, 0, 1) + FIELD(SQRTS, CUS, 1, 1) + FIELD(SQRTS, RTC, 4, 4) + typedef struct QEMU_PACKED UfsMcqCqReg { uint32_t hp; uint32_t tp; --=20 2.56.0.rc1.315.gc6ed9934b7-goog From nobody Mon Nov 23 05:00:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1791198285; cv=none; d=zohomail.com; s=zohoarc; b=TqzXhWonv96di7WUaOkeKP9HL1oSLMQaBoNv+8b7T8tFD6Q2fVRq9FdveeQAPRDfxj0/ruuHDi0cgMdxPD7w2Rz86YW8Ox9QkWmJK/X2FwEMOb3d79KUYIF3CODa+l02qfP8fZL43vY3raS+zpx8o5SfgZTJIPaZPO6w01TEQ5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791198285; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K5eUzRQW+5Aqjf4eZC1yePv4IOuOBDABX0sGLyhsqfU=; b=Cr6Q7s/vMgbv28Rbph6eaIuFzEyDtpao3lEbYzRC+LTrdqpGf4ztrSDs8en7xyiZb8Y/xe531cabzAAn11MgcaR3x3jmMpXcT44fCR4RD7szCoS/IpK/Y8pxluVR/aAiIm7GCDxqvnMFkQgQeTet6xs0Wl67NoXi0EWcRGhtxck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791198285481138.72031820813504; Mon, 5 Oct 2026 04:04:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xDgTm-0002db-6M; Mon, 05 Oct 2026 07:03:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3-4PDagoKCm4efMZXQkVTgSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--stanleyjhu.bounces.google.com>) id 1xDgTh-0002ak-Fn for qemu-devel@nongnu.org; Mon, 05 Oct 2026 07:03:30 -0400 Received: from mail-pg1-x545.google.com ([2607:f8b0:4864:20::545]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3-4PDagoKCm4efMZXQkVTgSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--stanleyjhu.bounces.google.com>) id 1xDgTd-0005RA-Lb for qemu-devel@nongnu.org; Mon, 05 Oct 2026 07:03:27 -0400 Received: by mail-pg1-x545.google.com with SMTP id 41be03b00d2f7-cc44d708055so2386039a12.0 for ; Mon, 05 Oct 2026 04:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1791198203; x=1791803003; darn=nongnu.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=K5eUzRQW+5Aqjf4eZC1yePv4IOuOBDABX0sGLyhsqfU=; b=p2bloZz8YhCDUbkjBlaJ7B/+TwfXoqeNYrZewzXY7PZLK5LtU8/sp03K4L7c0EastA E685fQfplxeAIdaksSqasluXhl76tU9o7SFTeERIGeHPZNK/AdpP8E9k1/mxmUcTXQ0z HOQcrjtayXpx9qh9+WplHrdj9hVvooMb8fpDE9Au2jBsmUOocaAT227qwweyGnH5CxO+ +ATwXplyoh+xAtidwWliO97WRpOy3jCmFI+G+A73rJf0kT8Xzl1o9gssg1RwPNeousz3 /Zvr7IzMHrphpnCwgdGyi0doXRAqFPg1Eprbx+Zih/sWBWbMu5JX3W8d32ub4CAlR2My +pAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791198203; x=1791803003; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=K5eUzRQW+5Aqjf4eZC1yePv4IOuOBDABX0sGLyhsqfU=; b=JMoNhD1Zmh7bGYSAWsYW/huwFr7EskHNsUjDPH6Mxfmu3vvukbTx78ZGFZnNdKnes4 GD7YJh8/uyyURUgQsDq3MpmngKfG91R1Kk7iUlz+4zsBNDnbIw7WaiA4jOx5Tg6b55fR pZl8YQR99UarvA5iu1wrG3HgaP8ruj7EZWx/azo7zezwsRoFDu1J0eOVddQPbzhPxBec sFw8YKVVxebkSPh/9Ov3oW3kpCkWAsoNFHYfuviFyomeITYGOk05329D6hfT6ROHzymN om+K5zsXskpAkYxzGFtJG2CAaTOgorrprHivo9VkQkE3wrozTtgq95ryjES17sAgBATa bezg== X-Forwarded-Encrypted: i=1; AKwUvBxJ3csUjSAmjBDbM/s513gZBckvlQCEY15Go4FwxI1A1D1xAeoWh/cqhjCL+aaXvZ6Fb3T+ZASF49R0@nongnu.org X-Gm-Message-State: AFuF++lBb09LA/UOMhmriPG9ZpRuT0FNqwV5726flrSRald0BH3Q9IFu 7qa7dg12OXFh+apzMHds5Hfq3v8c0Sy0fIXK650TY8keeXMqXmtncCpNXrEIwOLEn48ZDP2ddUx dNE59NqZqUHM9vT6WBEsBCA== X-Received: from pfcy26.prod.google.com ([2002:a05:6a00:93da:b0:88e:cc4a:845]) (user=stanleyjhu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:1392:b0:3e0:c258:2f15 with SMTP id adf61e73a8af0-3e0d6b70267mr5927881637.57.1791198203004; Mon, 05 Oct 2026 04:03:23 -0700 (PDT) Date: Mon, 5 Oct 2026 19:03:14 +0800 In-Reply-To: <20261005110315.3327418-1-stanleyjhu@google.com> Mime-Version: 1.0 References: <20261005110315.3327418-1-stanleyjhu@google.com> X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20261005110315.3327418-4-stanleyjhu@google.com> Subject: [PATCH v4 3/4] hw/ufs: Implement Task Management Request (TMR) handling From: Stanley Jhu To: Jeuk Kim , Jeuk Kim Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Stefan Hajnoczi , Richard Henderson , Paolo Bonzini , Fam Zheng , Kevin Wolf , Hanna Reitz , Jinyoung Choi Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::545; envelope-from=3-4PDagoKCm4efMZXQkVTgSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--stanleyjhu.bounces.google.com; helo=mail-pg1-x545.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1791198287716158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement UTP Task Management Request List (UTMRL) doorbell and TMR processing per JEDEC UFSHCI: - Support UTMRLDBR, UTMRLCLR (clear-on-zero), and UTMRLRSR registers, and gate IS.UTMRCS interrupt assertion on the UTMRD Interrupt (I) bit. - Handle UFS_QUERY_TASK and UFS_ABORT_TASK across legacy UTRL and MCQ queues, reporting overall Target Success/Failure in rsp_header.response and the TM Service Response in output_param1. For MCQ, UFS_ABORT_TASK cancels the active SCSIRequest and defers CQE posting (OCS =3D UFS_OCS_ABORTED) and slot recycling to subsequent SQRTC.ICU cleanup. - Reset UTMRLRSR on HCE reset. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim --- hw/ufs/trace-events | 1 + hw/ufs/ufs.c | 133 +++++++++++++++++++++++++++++++++++++++++++- include/block/ufs.h | 1 + 3 files changed, 134 insertions(+), 1 deletion(-) diff --git a/hw/ufs/trace-events b/hw/ufs/trace-events index d8173b12b..5e5a54a3f 100644 --- a/hw/ufs/trace-events +++ b/hw/ufs/trace-events @@ -15,6 +15,7 @@ ufs_mcq_complete_req(uint8_t qid) "sqid %"PRIu8"" ufs_mcq_create_sq(uint8_t sqid, uint8_t cqid, uint64_t addr, uint16_t size= ) "mcq create sq sqid %"PRIu8", cqid %"PRIu8", addr 0x%"PRIx64", size %"PRI= u16"" ufs_mcq_create_cq(uint8_t cqid, uint64_t addr, uint16_t size) "mcq create = cq cqid %"PRIu8", addr 0x%"PRIx64", size %"PRIu16"" ufs_write_mcq_op_reg(uint8_t qid, uint32_t offset, uint32_t data) "qid %"P= RIu8", offset 0x%"PRIx32", data 0x%"PRIx32"" +ufs_process_tmr(uint8_t func, uint32_t tag, uint8_t resp) "query_func 0x%"= PRIx8", task_tag %"PRIu32", tm_resp 0x%"PRIx8"" ufs_hce_reset(void) "HCE 1 -> 0 reset: cancelling BHs, resetting MCQ and r= equest lists" =20 # error condition diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index 956ef9c87..4c505e0bf 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -772,6 +772,7 @@ static void ufs_hce_reset(UfsHc *u) u->reg.utmrldbr =3D 0; u->reg.utrlcnr =3D 0; u->reg.utrlrsr =3D 0; + u->reg.utmrlrsr =3D 0; u->reg.is =3D 0; =20 /* 4. Free MCQ Queues and reset MCQ dynamic registers */ @@ -809,6 +810,126 @@ static void ufs_hce_reset(UfsHc *u) ufs_irq_check(u); } =20 +static UfsRequest *ufs_find_req_by_tag(UfsHc *u, uint8_t lun, uint32_t tas= k_tag) +{ + if (task_tag < u->params.nutrs) { + UfsRequest *req =3D &u->req_list[task_tag]; + if ((req->state =3D=3D UFS_REQUEST_RUNNING || + req->state =3D=3D UFS_REQUEST_READY) && + req->req_upiu.header.lun =3D=3D lun && + req->req_upiu.header.task_tag =3D=3D task_tag) { + return req; + } + } + + if (u->params.mcq) { + for (int q =3D 0; q < ARRAY_SIZE(u->sq); q++) { + UfsSq *sq =3D u->sq[q]; + if (!sq) { + continue; + } + for (int i =3D 0; i < sq->size; i++) { + UfsRequest *req =3D &sq->req[i]; + if (req->state =3D=3D UFS_REQUEST_RUNNING && + req->req_upiu.header.lun =3D=3D lun && + req->req_upiu.header.task_tag =3D=3D task_tag) { + return req; + } + } + } + } + + return NULL; +} + +static void ufs_process_tmr(UfsHc *u, uint32_t val) +{ + hwaddr base_addr =3D (((hwaddr)u->reg.utmrlbau) << 32) + u->reg.utmrlb= a; + uint32_t completed_int_mask =3D 0; + + u->reg.utmrldbr |=3D val; + + for (int i =3D 0; i < u->params.nutmrs; i++) { + if (val & (1 << i)) { + uint64_t desc_addr =3D base_addr + i * sizeof(UtpTaskReqDesc); + UtpTaskReqDesc desc; + uint8_t tm_func, tm_resp, lun; + uint32_t task_tag; + + if (ufs_addr_read(u, desc_addr, &desc, sizeof(desc))) { + continue; + } + + tm_func =3D desc.upiu_req.req_header.query_func; + lun =3D desc.upiu_req.req_header.lun; + task_tag =3D be32_to_cpu(desc.upiu_req.input_param2); + + if (tm_func =3D=3D UFS_QUERY_TASK) { + UfsRequest *req =3D ufs_find_req_by_tag(u, lun, task_tag); + + if (req) { + tm_resp =3D UFS_UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED; + } else { + tm_resp =3D UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL; + } + } else if (tm_func =3D=3D UFS_ABORT_TASK) { + UfsRequest *req =3D ufs_find_req_by_tag(u, lun, task_tag); + + if (req) { + if (ufs_mcq_req(req)) { + if (req->sreq !=3D NULL) { + SCSIRequest *sreq =3D req->sreq; + req->sreq =3D NULL; + scsi_req_cancel(sreq); + } + req->state =3D UFS_REQUEST_ERROR; + } else { + ufs_clear_req(req); + req->state =3D UFS_REQUEST_IDLE; + u->reg.utrldbr &=3D ~(1 << req->slot); + } + } + tm_resp =3D UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL; + } else { + tm_resp =3D UFS_UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED; + } + + memset(&desc.upiu_rsp, 0, sizeof(desc.upiu_rsp)); + desc.header.dword_2 =3D cpu_to_le32( + (le32_to_cpu(desc.header.dword_2) & ~UFS_MASK_OCS) | + UFS_OCS_SUCCESS); + desc.upiu_rsp.rsp_header.trans_type =3D + UFS_UPIU_TRANSACTION_TASK_RSP; + desc.upiu_rsp.rsp_header.flags =3D 0; + desc.upiu_rsp.rsp_header.lun =3D desc.upiu_req.req_header.lun; + desc.upiu_rsp.rsp_header.task_tag =3D + desc.upiu_req.req_header.task_tag; + if (tm_resp =3D=3D UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL || + tm_resp =3D=3D UFS_UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED) { + desc.upiu_rsp.rsp_header.response =3D UFS_COMMAND_RESULT_S= UCCESS; + } else { + desc.upiu_rsp.rsp_header.response =3D UFS_COMMAND_RESULT_F= AIL; + } + desc.upiu_rsp.output_param1 =3D cpu_to_be32(tm_resp); + + if (ufs_addr_write(u, desc_addr, &desc, sizeof(desc))) { + continue; + } + + trace_ufs_process_tmr(tm_func, task_tag, tm_resp); + u->reg.utmrldbr &=3D ~(1 << i); + if (le32_to_cpu(desc.header.dword_0) & UFS_UTP_REQ_DESC_INT_CM= D) { + completed_int_mask |=3D (1 << i); + } + } + } + + if (completed_int_mask) { + u->reg.is =3D FIELD_DP32(u->reg.is, IS, UTMRCS, 1); + ufs_irq_check(u); + } +} + static void ufs_write_reg(UfsHc *u, hwaddr offset, uint32_t data, unsigned= size) { switch (offset) { @@ -871,10 +992,20 @@ static void ufs_write_reg(UfsHc *u, hwaddr offset, ui= nt32_t data, unsigned size) case A_MCQCONFIG: u->reg.mcqconfig =3D data; break; - case A_UTRLCLR: case A_UTMRLDBR: + if (!FIELD_EX32(u->reg.hce, HCE, HCE) || + !FIELD_EX32(u->reg.utmrlrsr, UTMRLRSR, UTMRLRSR)) { + break; + } + ufs_process_tmr(u, data); + break; case A_UTMRLCLR: + u->reg.utmrldbr &=3D data; + break; case A_UTMRLRSR: + u->reg.utmrlrsr =3D data; + break; + case A_UTRLCLR: trace_ufs_err_unsupport_register_offset(offset); break; default: diff --git a/include/block/ufs.h b/include/block/ufs.h index b72403c47..b0515325f 100644 --- a/include/block/ufs.h +++ b/include/block/ufs.h @@ -141,6 +141,7 @@ REG32(UTMRLBAU, offsetof(UfsReg, utmrlbau)) REG32(UTMRLDBR, offsetof(UfsReg, utmrldbr)) REG32(UTMRLCLR, offsetof(UfsReg, utmrlclr)) REG32(UTMRLRSR, offsetof(UfsReg, utmrlrsr)) + FIELD(UTMRLRSR, UTMRLRSR, 0, 1) REG32(UICCMD, offsetof(UfsReg, uiccmd)) REG32(UCMDARG1, offsetof(UfsReg, ucmdarg1)) REG32(UCMDARG2, offsetof(UfsReg, ucmdarg2)) --=20 2.56.0.rc1.315.gc6ed9934b7-goog From nobody Mon Nov 23 05:00:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1791198280; cv=none; d=zohomail.com; s=zohoarc; b=AL9dkEdP1J6NVa99LUQi/y6GlQXDDsjl06vLQKxC7On1euHBtO2jN7wY8bnv8yRCgyX9YIzFpu3qNBKxFVALdOBPYayTmbssmSsQ9JvcFoZa9LVVVPKdrXdkWx0439Y9M6cwDwOTes82+unLp30j++Ee8F7U0X2vUtW2NuYfO3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791198280; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KmtpQWUw98ulbJ4Apgs/zzyDTH2jGHwieHZEIkyAWR8=; b=VWDH9P0035/GmiSdEbf82RkojUgUipRNg+S4Fq2loheenfHlKj4eHbV2XjtAhiISMPzbKzuOorDYwRIFjo/MAqxtsUzm/BvQWzA1jWvAVbIVvQmhBPKI5PECznA5cJmSxU/CFDA1/On5XJpBAY52SX9SqmvCuiSyQDZ/TQSmjTU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791198279978578.8525257548315; Mon, 5 Oct 2026 04:04:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xDgTm-0002dZ-5q; Mon, 05 Oct 2026 07:03:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3_IPDagoKCm8fgNaYRlWUhTbbTYR.PbZdRZh-QRiRYabaTah.beT@flex--stanleyjhu.bounces.google.com>) id 1xDgTh-0002al-Fm for qemu-devel@nongnu.org; Mon, 05 Oct 2026 07:03:30 -0400 Received: from mail-pg1-x545.google.com ([2607:f8b0:4864:20::545]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3_IPDagoKCm8fgNaYRlWUhTbbTYR.PbZdRZh-QRiRYabaTah.beT@flex--stanleyjhu.bounces.google.com>) id 1xDgTf-0005Re-2k for qemu-devel@nongnu.org; Mon, 05 Oct 2026 07:03:28 -0400 Received: by mail-pg1-x545.google.com with SMTP id 41be03b00d2f7-cc7695f6a30so2146553a12.0 for ; Mon, 05 Oct 2026 04:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1791198205; x=1791803005; darn=nongnu.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=KmtpQWUw98ulbJ4Apgs/zzyDTH2jGHwieHZEIkyAWR8=; b=tm6FcR2cBNygNe/taJPiLQf+0v8Its+umcwZnbSkN+KmHIf34TkW3wEobfajkK+jWA /TQsN+RQlti5wvcnRjIpYlfn+DvSURNzf45o363pObLJMC0gm/Ga6SEgsCZWQq2H80yc uPhOu+5eo87rFGBU2gE1y5n905jFx4a9bFLlXfj1eqi7IN8lEwetfAYM0aJXSH0s+DAR bvqfbpmaHAJ1KpgjzWCpbAnR14D4If1eTG9RYDvQ1mGiEJnMU5H/BTmf4TMKe0sS0ZLs tDxDvbg8Mp6dPg3hTRu/dKD5tuCXmTmrN/4N1MRbfCBpe9ZUcSVZ9DlbO7O5DCeKf3ij XpDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791198205; x=1791803005; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KmtpQWUw98ulbJ4Apgs/zzyDTH2jGHwieHZEIkyAWR8=; b=bsS2MBgMoJPIhWgaYddu9wJvdFzbCfkpe+y/BFNEhewj30AdP/45aqLeBUla9ZFSFi YDXWIf8L0vyES3udWrW3EojdoECBh13TwJ69iYkFco0m1Nfz/Wv1VNcZLnxvOWU3dEqG faFGj3E4ZzGjjzq9+hnfeAyOaI0j9hpsAt2WpsjFDoOPLaAfNyfGKiyHjTaPlCG5HTW2 xw0D//o1PExbte0Q0H7TJCvZGXgcuDb4/L8VtDTi5KOsqFaUx/9t8TQ6PgSJhJwS/q3j aiE8I8PllWtq78K0GJH+QP6OJklEGHwVNF9l6TUdbF48sylcpyHWwP2i3QTywfNTEPdl 7HLw== X-Forwarded-Encrypted: i=1; AKwUvByhgoCz3Cl02fTIR5GcOTY+zvfmRO+Wv8SyM0gar8/QvCpCoy544u6jj7ZUS0GptopPUAlN9K8YXcrX@nongnu.org X-Gm-Message-State: AFuF++nnugzcF40547CvUeVrYDCiy3bgB7p5SF5myZht8Ari6JHAaygu wOC1+Y1zmtWkmyGoz7XbicNzC28dk9TTVHIWVlNrrtC9wEkwWXJTbaHsdTq0mviVncBew+pboSU EfW+qE60zzQLMmeviuJ7i2w== X-Received: from pgcv27.prod.google.com ([2002:a05:6a02:531b:b0:cc7:a1dc:d7e4]) (user=stanleyjhu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:734c:b0:3d3:aec2:4dcd with SMTP id adf61e73a8af0-3e0bced1f06mr9322012637.25.1791198204911; Mon, 05 Oct 2026 04:03:24 -0700 (PDT) Date: Mon, 5 Oct 2026 19:03:15 +0800 In-Reply-To: <20261005110315.3327418-1-stanleyjhu@google.com> Mime-Version: 1.0 References: <20261005110315.3327418-1-stanleyjhu@google.com> X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20261005110315.3327418-5-stanleyjhu@google.com> Subject: [PATCH v4 4/4] hw/ufs: Skip nullified MCQ submission queue entries with OCS_ABORTED From: Stanley Jhu To: Jeuk Kim , Jeuk Kim Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Stefan Hajnoczi , Richard Henderson , Paolo Bonzini , Fam Zheng , Kevin Wolf , Hanna Reitz , Jinyoung Choi Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::545; envelope-from=3_IPDagoKCm8fgNaYRlWUhTbbTYR.PbZdRZh-QRiRYabaTah.beT@flex--stanleyjhu.bounces.google.com; helo=mail-pg1-x545.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1791198281389158501 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Per JEDEC UFSHCI (JESD223G Section 6.1.1 and Section 4.4.6 Step 2B), host software in MCQ mode may stop a Submission Queue and nullify an unfetched SQE by setting its UTRD Command Type (DW0 bits 31:28) to 0xF. When the Submission Queue is resumed, the host controller shall skip execution of the nullified transfer request and post a Completion Queue Entry (CQE) to the Completion Queue with OCS =3D ABORTED (0x06). In ufs_mcq_process_sq(), check for UFS_UTP_CMD_TYPE_NULL (0xF), read the Request UPIU header on a best-effort basis via ufs_dma_read_req_upiu() to populate cqe.task_tag and cqe.lun for UFSHCI 4.1+ completion decoding, and unconditionally post a CQE with UFS_OCS_ABORTED without executing the command or writing a Response UPIU for the nullified entry. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim --- hw/ufs/ufs.c | 17 ++++++++++++++++- include/block/ufs.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index 4c505e0bf..f008af746 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -36,6 +36,7 @@ =20 static void ufs_exec_req(UfsRequest *req); static void ufs_clear_req(UfsRequest *req); +static void ufs_mcq_process_cq(void *opaque); =20 static inline uint64_t ufs_mcq_reg_addr(UfsHc *u, int qid) { @@ -474,6 +475,17 @@ static void ufs_mcq_process_sq(void *opaque) ufs_mcq_init_req(sq->u, req, sq); memcpy(&req->utrd, &sqe, sizeof(req->utrd)); =20 + if ((le32_to_cpu(sqe.header.dword_0) >> 28) =3D=3D UFS_UTP_CMD_TYP= E_NULL) { + ufs_dma_read_req_upiu(req); + req->utrd.header.dword_2 =3D cpu_to_le32( + (le32_to_cpu(req->utrd.header.dword_2) & ~UFS_MASK_OCS) | + UFS_OCS_ABORTED); + req->state =3D UFS_REQUEST_COMPLETE; + QTAILQ_INSERT_TAIL(&sq->cq->req_list, req, entry); + ufs_mcq_process_cq(sq->cq); + continue; + } + req->state =3D UFS_REQUEST_RUNNING; ufs_exec_req(req); } @@ -493,7 +505,10 @@ static void ufs_mcq_process_cq(void *opaque) break; } =20 - ufs_dma_write_rsp_upiu(req); + if ((le32_to_cpu(req->utrd.header.dword_0) >> 28) !=3D + UFS_UTP_CMD_TYPE_NULL) { + ufs_dma_write_rsp_upiu(req); + } =20 /* UTRD/CQE are LE; round-trip through host to keep BE correct. */ uint64_t ucdba =3D diff --git a/include/block/ufs.h b/include/block/ufs.h index b0515325f..4a614fbe5 100644 --- a/include/block/ufs.h +++ b/include/block/ufs.h @@ -665,6 +665,7 @@ enum { UFS_UTP_CMD_TYPE_SCSI =3D 0x0, UFS_UTP_CMD_TYPE_UFS =3D 0x1, UFS_UTP_CMD_TYPE_DEV_MANAGE =3D 0x2, + UFS_UTP_CMD_TYPE_NULL =3D 0xf, }; =20 /* To accommodate UFS2.0 required Command type */ --=20 2.56.0.rc1.315.gc6ed9934b7-goog