From nobody Fri Dec 19 19:04:59 2025 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DEBA30B518 for ; Tue, 14 Oct 2025 06:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760421883; cv=none; b=uIIaHQUvj2dCZAZRjhbi+I4GxrdOMpe+TIRQEVgImC00LxSg/AvUCGlLmTx/C7o+edvXeFQzoiWNp9vzR6t89FjTdeK66sioqT+ArzvXeyqIcTKj/uojdyAa29gFCQZWVzWTwdRrgbwz0Ec0FZ1ZbGZa0AfvsjR2HOVhfSB7TyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760421883; c=relaxed/simple; bh=+ic5AihcIegAradhwux+QLsSKjrjS2y32uAShcvRa2Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RVFhWO5m/5S8Lvt90fa/+PaxZhM9tDMdwnESTOj+Vw87jf1bfenTytvghwu+KAbWk49dico1jPrGNzGUibEkK2MxN9c4TnOyZa/B08AJ6dKuPGd3BgbfR+K9cteRKXWlila0VR5sWbGucIgrLmCvKJ6JZzOdzopd/HysFeq94fE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=aHQhrPiB; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="aHQhrPiB" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 59DHD9t4005642 for ; Tue, 14 Oct 2025 06:04:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=tDnjiEFQvmj 6QEflrGl3a0N01kBNbGPHWb9PIOiOQ2s=; b=aHQhrPiBSlcPJpMDCb4S8oq9H/z 6vWvsWxknKCM8gFKElfXxKcq/bfHGw59tTu7aIEkwSEogNk5CirdKkLsX5PjFF/8 HAuKQznIwur65GcbOoTuYIds5EoGvQ1ruinDQcR2RXQXdgJaB1iIWGof1Ucxkcg1 VpgR2z+XvGKGXxnlfpT4pRCKR9upQA4IFHvcsWL1gLMASm6foLb81i9UHOMjEEs/ kU1iJauzGDcKnw6BH/v3goWxEje4ZKEFq384jrHXsTBSr54y50G9AoUoozO8oLyN MxZnlYScquc67hvDonlkRCGlhj6xfc6x0FFXeDj3TUp+YEBMwS05MjV1tKA== Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 49qfa87bdr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 14 Oct 2025 06:04:40 +0000 (GMT) Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-b62cdd71290so8473278a12.1 for ; Mon, 13 Oct 2025 23:04:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760421879; x=1761026679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :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17jfDuZrjIykFHcNZ6gY1+0YXLR/4lxHZjltArRG3wnM/Yq4ruN X-Received: by 2002:a05:6a20:a128:b0:32d:95f2:1fe with SMTP id adf61e73a8af0-32da8df32d3mr30176136637.2.1760421878963; Mon, 13 Oct 2025 23:04:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYbnXuM+iOSZX3hz/0dhkllzDFS6YwugLjRnZ5256l5aV2JKlrgvuY1ArMl3v0AvxE39tuXQ== X-Received: by 2002:a05:6a20:a128:b0:32d:95f2:1fe with SMTP id adf61e73a8af0-32da8df32d3mr30176096637.2.1760421878470; Mon, 13 Oct 2025 23:04:38 -0700 (PDT) Received: from hu-pkambar-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7992b0604cfsm13946024b3a.9.2025.10.13.23.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 23:04:38 -0700 (PDT) From: palash.kambar@oss.qualcomm.com To: mani@kernel.org, alim.akhtar@samsung.com, avri.altman@wdc.com, bvanassche@acm.org, peter.griffin@linaro.org, krzk@kernel.org, peter.wang@mediatek.com, beanhuo@micron.com, quic_nguyenb@quicinc.com, adrian.hunter@intel.com, ebiggers@kernel.org, neil.armstrong@linaro.org, James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com Cc: linux-arm-msm@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, quic_cang@quicinc.com, quic_nitirawa@quicinc.com, Palash Kambar Subject: [PATCH V1 2/2] ufs: ufs-qcom: Disable AHIT before SQ tail update to prevent race in MCQ mode Date: Tue, 14 Oct 2025 11:34:06 +0530 Message-Id: <20251014060406.1420475-3-palash.kambar@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251014060406.1420475-1-palash.kambar@oss.qualcomm.com> References: <20251014060406.1420475-1-palash.kambar@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: oJkmI452E_YA3QKDMbq8MFO7XvY1QM8B X-Proofpoint-ORIG-GUID: oJkmI452E_YA3QKDMbq8MFO7XvY1QM8B X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMDExMDAxNyBTYWx0ZWRfX3xZ3n+6dzOZT fb9tdjDm746r1x5ZLXvV82ILAmFaA9nCCyqik1Zhp/ztWkVH8efMX7fpfZM7QSjgZ/EaBObBnEk syY4EX+zm07+fC4xzetWH6qzEi7UZLYDk0r6TIkI/k7y++Jwm6+xm5XRjE4tGdSdidi+xrcJsrr dYp9TYbS8RG1dgavdrB3G9eH/iy7TnBchtCnw+qAXDFx03MKfJAogsds+k69Jcn8T7WelPlW8ea sV2WXSSu2gRIA52syeOFj3lV/xbQmNcRwnIIEuT4zkWW2BI8t4KBq6YdyZupdK6ZqZJa+E1yOQ0 mydrHjZ6rCh+fJB9hmb4oDAse23Jp5gb3xOmMzzFDD0FE7TF29WFE9n3+q3S/ZjWfW3F5PiLROS Rwlwo4I3t5QraBuJpv6RpCjIzuP/EQ== X-Authority-Analysis: v=2.4 cv=JLw2csKb c=1 sm=1 tr=0 ts=68ede7f8 cx=c_pps a=Oh5Dbbf/trHjhBongsHeRQ==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=x6icFKpwvdMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=COk6AnOGAAAA:8 a=EUspDBNiAAAA:8 a=qjqbbBDWswgaW-2ywKgA:9 a=_Vgx9l1VpLgwpw_dHYaR:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-14_02,2025-10-13_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 malwarescore=0 spamscore=0 clxscore=1011 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2510020000 definitions=main-2510110017 Content-Type: text/plain; charset="utf-8" From: Can Guo In MCQ mode, a race condition can occur on QCOM UFSHC V6 when the Auto-Hibernate Idle Timer (AHIT) is close to expiring. If a data command and a hibernate command are issued simultaneously to the UniPro layer, the data command may be dropped. To prevent this, AHIT is disabled by reprogramming it to 0 before updating the SQ tail pointer. Once there are no active commands in the UFS host controller, the timer is re-enabled. This change ensures reliable command delivery in MCQ mode by avoiding timing conflicts between data and hibernate operations. Signed-off-by: Can Guo Co-developed-by: Palash Kambar Signed-off-by: Palash Kambar --- drivers/ufs/host/ufs-qcom.c | 35 +++++++++++++++++++++++++++++++++++ drivers/ufs/host/ufs-qcom.h | 1 + 2 files changed, 36 insertions(+) diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index 89a3328a7a75..f31239f4fc50 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -1286,6 +1286,39 @@ static int ufs_qcom_icc_init(struct ufs_qcom_host *h= ost) return 0; } =20 +static void ufs_qcom_send_command(struct ufs_hba *hba, + struct ufshcd_lrb *lrbp) +{ + struct ufs_qcom_host *host =3D ufshcd_get_variant(hba); + unsigned long flags; + + if ((host->hw_ver.major =3D=3D 6 && host->hw_ver.minor =3D=3D 0 && + host->hw_ver.step =3D=3D 0) && hba->mcq_enabled) { + spin_lock_irqsave(hba->host->host_lock, flags); + if ((++host->active_cmds) =3D=3D 1) + /* Stop the auto-hiberate idle timer */ + ufshcd_writel(hba, 0, REG_AUTO_HIBERNATE_IDLE_TIMER); + spin_unlock_irqrestore(hba->host->host_lock, flags); + } +} + +static void ufs_qcom_compl_command(struct ufs_hba *hba, + struct ufshcd_lrb *lrbp) +{ + struct ufs_qcom_host *host =3D ufshcd_get_variant(hba); + unsigned long flags; + + if ((host->hw_ver.major =3D=3D 6 && host->hw_ver.minor =3D=3D 0 && + host->hw_ver.step =3D=3D 0) && hba->mcq_enabled) { + spin_lock_irqsave(hba->host->host_lock, flags); + if ((--host->active_cmds) =3D=3D 0) + /* Activate the auto-hiberate idle timer */ + ufshcd_writel(hba, hba->ahit, + REG_AUTO_HIBERNATE_IDLE_TIMER); + spin_unlock_irqrestore(hba->host->host_lock, flags); + } +} + /** * ufs_qcom_init - bind phy with controller * @hba: host controller instance @@ -2194,6 +2227,8 @@ static const struct ufs_hba_variant_ops ufs_hba_qcom_= vops =3D { .get_ufs_hci_version =3D ufs_qcom_get_ufs_hci_version, .clk_scale_notify =3D ufs_qcom_clk_scale_notify, .setup_clocks =3D ufs_qcom_setup_clocks, + .setup_xfer_req =3D ufs_qcom_send_command, + .compl_command =3D ufs_qcom_compl_command, .hce_enable_notify =3D ufs_qcom_hce_enable_notify, .link_startup_notify =3D ufs_qcom_link_startup_notify, .pwr_change_notify =3D ufs_qcom_pwr_change_notify, diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h index 380d02333d38..a97da99361a8 100644 --- a/drivers/ufs/host/ufs-qcom.h +++ b/drivers/ufs/host/ufs-qcom.h @@ -308,6 +308,7 @@ struct ufs_qcom_host { u32 phy_gear; =20 bool esi_enabled; + unsigned long active_cmds; }; =20 struct ufs_qcom_drvdata { --=20 2.34.1