From nobody Tue Nov 24 11:45:52 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795483808; b=R3SfHIF7PYXqz5fkTb24XNk4udizkgO2K79lEwfSZiWQmnqUK5VQx6mHqqfeq7EEQxkv TwbpFMVWo5IuoslEaoP8+Bqjt1W+HhPjYS6e1cQhjfRDWdJxu0eyGsg6jMjrm5QZDJ5pJ Al5NwKtiLBBKW9UwUshC71/JagM2Rdhih/4tzzTxG3zjJObrAA5FHJyt6JF7rl2Aqz4oT cSE5GQF4vM8Uy7Hkk8Ob7sGvonMo3a8wRrboDMPC4h0Sv+ImX0eVluUwsCV1zplBLTcRN NpO7/rUvs+bEwLIzfQ0P3kZwsQ7uDgP71v5gbP9HpLS5QQn1LqoIAJV5ILCgbMzsXGQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795483808; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=aZ+kdjMwzLW6D1d8Noa04UT5HiQC8LgMJZGM4R3Q9WU=; b=fwuHk9ncT4Cy1c8Pn7Lgnnf/HDURbTdKdEbydA0ETpFEMiN7AuCHwQaFG0F+ef1gHkav c2GA5FOyj8iGO80PLt1xAiu838GgzLng4g2X8Ob0nN/a/1fYt9JtkJwfuxtUHsGmIrvai p8rCWkzCaRM0+87qvpS5ePgI2yc0pdNFMmeXy50+rZh/dNza1Ob0xUxXKejftUB6hTG9j bFqEt26U4YpaXATvlK1JKIeXOYSYPf+CtemSLhjEFca79XuIe8akteICS/l9r57RE8iwZ BAmW0jkcmxBq0As1xlCNO45W2pzPqrvuFrlGD3WjG3VXd0wwyeq3FbO86nqR4aLVRSw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--powenkao.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=UBmAvtsh; arc=none smtp.remote-ip=209.85.215.200 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D81A606A32C for ; Tue, 24 Nov 2026 01:30:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1D81A606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--powenkao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=UBmAvtsh Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cdd48746a49so2322923a12.0 for ; Mon, 23 Nov 2026 17:30:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795483807; x=1796088607; darn=vger.kernel.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=aZ+kdjMwzLW6D1d8Noa04UT5HiQC8LgMJZGM4R3Q9WU=; b=UBmAvtshi1MR+jB7Et3WRppr+mRq801u72XXTzXTUR2woLynEgQLZkpA/XuR2+2KhJ lDJZEl0GfJgXuvl3USjrgcRiW8n46q2YNOz8D0HcUJY3FzHyHezef0jYdIJttM84zLUS gByv7Xt7HCbTgsSF0+YFm3metxFqAgIO10DPSOdZJ6zrsU0T87zZlpX7XR1VUpO0f/oC Y6NvOz60DPnHP40QJk724++/H8XK0uJTeOa2Jly4M7QSXFgy5gL0PGZXCy6iaKV/EZkP IoxBy8Gl/r5ekwD9cajmVnGudHMStVAEH0wjeeM9MUjmsMJmNLEviaf+H9wT7+VYYplL vm3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795483807; x=1796088607; 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=aZ+kdjMwzLW6D1d8Noa04UT5HiQC8LgMJZGM4R3Q9WU=; b=RKpTD9RfL2gA6t9kcWYoeJTmQ2VUoI5gyKFPNLYHPz9An8gInnqhU5EDrrzPC1J+IY S0+u+OskObNAFOgdJTcu+aCbQlCICTwroRoEqt2uWH56/DPxBKPZrC4zCY3DqJeOy14S gBvesg9/+RZB6YX5lQ8UivdVBSYjf9bafKsomf5VEAehyabyq4f92wscANRwjoc4VfRs J1sYsDBGyuGjCa+gItGDO2SJyU0jDMyTrvKAMizG6aFNXKtC1TtdHaMYvF8MkUOOyYie GMJMO0gSKvoRYgLQTp0DC1tEhv6/ov34Zfk+sqxnPXGXoYD09CpK/ZwuUyhvKfOfYw4E goHQ== X-Forwarded-Encrypted: i=1; AL+hErF2EPu8iNOLMUiaLzE/+0RJRmDzBHoRSIfEU+U0NvYhSm2G/sYTF4WJsqiLYrDq0vvL7TSVdnjwnyRGcdE=@vger.kernel.org X-Gm-Message-State: APuU4Z+Qr/Iny5ECicjB9+CtalQHNYh0oM6QcVRRf6QvrMseaZt3j/uJ HE8ljZN7fMDvUmggy53eiNXC0bD9FrMz99xQsxgZy1hrKyy8w7TX0ipOVUVRJRNTVPjebFUsYA1 ZEYAUd9wyAnVvrQ== X-Received: from pjyp3.prod.google.com ([2002:a17:90a:e703:b0:3b3:ec38:c78e]) (user=powenkao job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1d03:b0:3ab:31e6:12fc with SMTP id 98e67ed59e1d1-3b41c5574f0mr12394867a91.0.1795483807147; Mon, 23 Nov 2026 17:30:07 -0800 (PST) Date: Tue, 24 Nov 2026 09:29:32 +0800 In-Reply-To: <20261124012951.3143833-1-powenkao@google.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 References: <20261124012951.3143833-1-powenkao@google.com> X-Mailer: git-send-email 2.56.1.809.ga0b61035b5-goog Message-ID: <20261124012951.3143833-2-powenkao@google.com> Subject: [PATCH v2 1/2] scsi: ufs: core: Defer debugfs init until after device init From: Po-Wen Kao To: linux-scsi@vger.kernel.org Cc: Konstantin Vyshetsky , Alim Akhtar , Bart Van Assche , Bean Huo , Stanley Jhu , "James E . J . Bottomley" , "Martin K . Petersen" , Peter Wang , Can Guo , linux-kernel@vger.kernel.org, Brian Kao , Li Qiang , John Garry , HOYOUNG SEO , Hyeoncheol Jeong Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Brian Kao ufshcd_hba_init() currently creates the debugfs hierarchy and fault injection attributes before the controller version (hba->ufs_version), controller locks, and device descriptor (hba->dev_info.wspecversion) are initialized. Move ufs_debugfs_hba_init() and ufs_fault_inject_hba_init() into ufshcd_init() alongside ufs_sysfs_add_nodes(), and move the matching ufs_debugfs_hba_exit() from ufshcd_hba_exit() into ufshcd_remove() alongside ufs_sysfs_remove_nodes(). Use disable_delayed_work_sync() in ufs_debugfs_hba_exit() so an in-flight exception event cannot re-queue debugfs_ee_work while scsi_remove_host() is still tearing down devices. Moving the exit call symmetrically keeps probe error paths from tearing down uncreated debugfs state, drains debugfs readers before scsi_remove_host() removes the WLUN during unbind, and lets debugfs initialization inspect both hba->ufs_version and hba->dev_info.wspecversion directly. Suggested-by: Peter Wang Signed-off-by: Brian Kao Reviewed-by: Peter Wang --- drivers/ufs/core/ufs-debugfs.c | 2 +- drivers/ufs/core/ufshcd.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/ufs/core/ufs-debugfs.c b/drivers/ufs/core/ufs-debugfs.c index 9f83628f3e2c..e62b942b37dc 100644 --- a/drivers/ufs/core/ufs-debugfs.c +++ b/drivers/ufs/core/ufs-debugfs.c @@ -529,5 +529,5 @@ void ufs_debugfs_hba_init(struct ufs_hba *hba) void ufs_debugfs_hba_exit(struct ufs_hba *hba) { debugfs_remove_recursive(hba->debugfs_root); - cancel_delayed_work_sync(&hba->debugfs_ee_work); + disable_delayed_work_sync(&hba->debugfs_ee_work); } diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 56a77f4a2a6e..f1df1d6734d9 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10115,9 +10115,6 @@ static int ufshcd_hba_init(struct ufs_hba *hba) if (err) goto out_disable_vreg; =20 - ufs_debugfs_hba_init(hba); - ufs_fault_inject_hba_init(hba); - hba->is_powered =3D true; goto out; =20 @@ -10139,7 +10136,6 @@ static void ufshcd_hba_exit(struct ufs_hba *hba) ufshcd_exit_clk_gating(hba); if (hba->eh_wq) destroy_workqueue(hba->eh_wq); - ufs_debugfs_hba_exit(hba); ufshcd_vops_exit(hba); ufshcd_setup_vreg(hba, false); ufshcd_setup_clocks(hba, false); @@ -11027,6 +11023,7 @@ void ufshcd_remove(struct ufs_hba *hba) ufs_bsg_remove(hba); ufs_rpmb_remove(hba); ufs_sysfs_remove_nodes(hba->dev); + ufs_debugfs_hba_exit(hba); cancel_delayed_work_sync(&hba->ufs_rtc_update_work); blk_mq_destroy_queue(hba->tmf_queue); blk_put_queue(hba->tmf_queue); @@ -11505,6 +11502,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *= mmio_base, unsigned int irq) ufs_sysfs_add_nodes(hba->dev); hba->dme_qos_sysfs_handle =3D sysfs_get_dirent(hba->dev->kobj.sd, "dme_qos_notification"); + ufs_debugfs_hba_init(hba); + ufs_fault_inject_hba_init(hba); async_schedule(ufshcd_async_scan, hba); =20 device_enable_async_suspend(dev); --=20 2.56.1.809.ga0b61035b5-goog From nobody Tue Nov 24 11:45:52 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795483817; b=bsqZYH2dxK+zWNRITBJyiEPb+pSEgG2EsoS0j0/rS9UAOdZBmbiZ5peMHd5qCsxkX3JG Uoqi4kMuZVtd2YEgiq+L/CocYAasoOUX3Xdsr1Wv17+kw7ObjXkOlEalxiskCLbKKQyrg S4wuWCf5bggTnsG29JmnnLh8HFMEWmx7sJXuUmv2T/S7mO7v5yCeOF2jKLJq00NiNzj4y YAoAZbDy0IgDVMs7OGXx2IoasMoMqXSJg+eunqlD0nMs3qpq4qjWBytJbEX24UJFavA/P GCxy5Wulop1J4gx3nXyBPwRKTwLp/4UiPZs6XHQUKXKLF0LaPjyefYGZ46auGiyGQlg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795483817; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=2FIA87CiZS2yZ6BVy7ZaQJLxqkasxBGdfUSu6p0khMY=; b=ABXyoYXZMhhbQWC9UDyqZvR72C/YXJ1OLS8pSV39M1h3vjviu1Y60RPhF03iXr78qDUi NZ0uTBGX3AV1e7bCE+nwJwKK5FslHBL4Jjr5nGO+J3VkCACXeg11AS60DdpZ9NOrWaeYH kEjRdp3kRGAqjaQCYlAXUDwaAIMjcUYLVPyCF7d2do/vD0hTEHwLCpA4sJhkgMUSDpBgt jLDK6v0D4KiEY3bz9oS0D/u1B64axeqFciYOzVkOnMqPuVc+CpAtTgRj1RZu8KvFmxrY+ 6QJizwdZ71U6qzWJGR5494IGI/+zt4M0vbaMCBtd8n4WGfx+D/etFAZzDxVeEBl8Uwg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--powenkao.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=m7mZs3FU; arc=none smtp.remote-ip=209.85.210.200 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90366606A326 for ; Tue, 24 Nov 2026 01:30:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 90366606A326 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--powenkao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=m7mZs3FU Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-8b930598cf0so6413922b3a.1 for ; Mon, 23 Nov 2026 17:30:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795483816; x=1796088616; darn=vger.kernel.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=2FIA87CiZS2yZ6BVy7ZaQJLxqkasxBGdfUSu6p0khMY=; b=m7mZs3FUdyzTv4wdTDHTQXiA8tCJO3nHXniLtY0qg4HzN+yFVa2lGvsjBCCQ5Db2+e ktyKeMrtGeuG0emMOaQUx0g6Pg5s8x2SbcfsKVvpYw2MlJU9pAzdBoR9VNmCzKzfzHny dWv3+tySO8RnYJMvy8ykbCn4QrqI9WK91oott2sh6QDgHSpfaDTsbGAHcNa3ofGt20uL WGmCAq5qRi52fUZTjUdy/ZcJdCthwANggQkDKI0rCNlgBEzUKgINp5LLgz4nAEUQ0bPL zD3GCRh+jKW9p9oj3BMmxEUvRIYCzB8sK1n/uWi5tXBvDk1vPKXIjIwbPhku+LV0TS4P z0mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795483816; x=1796088616; 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=2FIA87CiZS2yZ6BVy7ZaQJLxqkasxBGdfUSu6p0khMY=; b=oWphocFby+2Dt1PAR1wQnsvZD030IXErFQ+hUvCd0eXvO6dWXyySbLW2C0Z/B5AVI3 C+aDVXBpCjjoDdHfPAspMaov3bp1Qz1FmVyYUgpuHwwkWnZ1cAaiVLE6KRTHXCyZk62O eeyJMwItNHfm6HtW7pxMUgGY0Hs/SqyP5mMFevhJN+KQcX2n6v4c0Ei5pJY2+En9YTRu QxnwKeySsKy2jigtn600+NuMml+mBp5K653C5PjQqZZLOuCon9Pk1/2XmWYSCyisRM8D QNfecUr339TXHh8qAzhmrz5WA0Coyb6NKUbvWC+tUWFeXrhVUjdrr0AR7fPUQUVhkzh+ pgAQ== X-Forwarded-Encrypted: i=1; AL+hErE5/f+Y4DF7dhtd82Kc20E4aKC0EC6J6yBF/NGhkCU99Vhzaht3nm6SkMLbIBonxHlZeADq9+VGIKRNbI0=@vger.kernel.org X-Gm-Message-State: APuU4Z/J/QpEfWlO4WTzNQP2pauZkQ2WsXnCaih4G3jWRwj3dQx3B6YD MGA/HfLp2JeVSAiIC/FUmvosTsizcNGUe8O7vXehlbTstjWKY1V0wVTA0+HEiHbcL4YQtmZRdYB iO3dm6gTRjp+ebA== X-Received: from pfblo18.prod.google.com ([2002:a05:6a00:3d12:b0:891:63bf:32]) (user=powenkao job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:10c7:b0:8a5:7006:1ecf with SMTP id d2e1a72fcca58-8c87c671b53mr12496620b3a.39.1795483815488; Mon, 23 Nov 2026 17:30:15 -0800 (PST) Date: Tue, 24 Nov 2026 09:29:33 +0800 In-Reply-To: <20261124012951.3143833-1-powenkao@google.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 References: <20261124012951.3143833-1-powenkao@google.com> X-Mailer: git-send-email 2.56.1.809.ga0b61035b5-goog Message-ID: <20261124012951.3143833-3-powenkao@google.com> Subject: [PATCH v2 2/2] scsi: ufs: core: Add debugfs for PA TFS/FEC error counters From: Po-Wen Kao To: linux-scsi@vger.kernel.org Cc: Konstantin Vyshetsky , Alim Akhtar , Bart Van Assche , Bean Huo , Stanley Jhu , "James E . J . Bottomley" , "Martin K . Petersen" , Peter Wang , Can Guo , linux-kernel@vger.kernel.org, Brian Kao , John Garry , Li Qiang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Brian Kao MIPI UniPro v3.0 introduces the Transport Framing Structure (TFS) with Reed-Solomon Forward Error Correction (FEC) in the Physical Adapter (PA) layer, along with five PA MIB attributes (0x15C3-0x15C7) that count TFS frames with uncorrectable FEC errors, TFS CRC errors, TFS format errors, and 64-bit corrected FEC symbols. Exposing these counters allows observing pre-FEC symbol correction and framing errors for HS-G6 (1b1b) link-margin diagnostics without dropping the link. Define the PA_TFS_* attributes in include/ufs/unipro.h and expose them under debugfs: /sys/kernel/debug/ufshcd//pa_err_stats/{host,device}/ - fec_err_cnt - crc_err_cnt - format_err_cnt - recovered_fec_symbols Skip creation entirely on hosts setting UFSHCD_QUIRK_BROKEN_UIC_CMD. Otherwise gate each subdirectory independently: host/ is created when UFSHCI >=3D 5.0, and device/ is created when wSpecVersion >=3D 0x0500 (the pa_err_stats parent directory is omitted if neither is supported). Each file reads the local (host) or peer (device) PA attribute and resets it to 0 when '0' is written. Writing PA_TFS_RecErrorCountL clears the full 64-bit PA_TFS_RecErrorCount counter per MIPI UniPro v3.0 Section 5.6.7, and reads sample the high/low words with a bounded hi-lo-hi retry loop to avoid 32-bit rollover tearing. Positive UIC command result codes are translated to standard negative errno values. Signed-off-by: Brian Kao Reviewed-by: Peter Wang --- drivers/ufs/core/ufs-debugfs.c | 211 +++++++++++++++++++++++++++++++++ include/ufs/unipro.h | 5 + 2 files changed, 216 insertions(+) diff --git a/drivers/ufs/core/ufs-debugfs.c b/drivers/ufs/core/ufs-debugfs.c index e62b942b37dc..7913c824d49b 100644 --- a/drivers/ufs/core/ufs-debugfs.c +++ b/drivers/ufs/core/ufs-debugfs.c @@ -206,6 +206,215 @@ static const struct file_operations ufs_saved_err_fop= s =3D { .release =3D single_release, }; =20 +#define UFS_PA_ERR_REC_READ_RETRIES 3 + +struct ufs_pa_err_attr { + const char *name; + u32 mib_attr; + u8 peer; +}; + +static int ufs_dme_err_to_errno(int err) +{ + if (err <=3D 0) + return err; + + switch (err) { + case UIC_CMD_RESULT_INVALID_ATTR: + return -EOPNOTSUPP; + case UIC_CMD_RESULT_INVALID_ATTR_VALUE: + return -EINVAL; + case UIC_CMD_RESULT_READ_ONLY_ATTR: + return -EPERM; + case UIC_CMD_RESULT_BUSY: + return -EBUSY; + default: + return -EIO; + } +} + +static int ufs_pa_err_read_rec_cnt(struct ufs_hba *hba, u8 peer, u64 *val) +{ + u32 hi_before, lo, hi_after; + int err, retry; + + for (retry =3D 0; retry < UFS_PA_ERR_REC_READ_RETRIES; retry++) { + err =3D ufshcd_dme_get_attr(hba, + UIC_ARG_MIB(PA_TFS_RECERRORCOUNTH), + &hi_before, peer); + if (err) + return ufs_dme_err_to_errno(err); + + err =3D ufshcd_dme_get_attr(hba, + UIC_ARG_MIB(PA_TFS_RECERRORCOUNTL), + &lo, peer); + if (err) + return ufs_dme_err_to_errno(err); + + err =3D ufshcd_dme_get_attr(hba, + UIC_ARG_MIB(PA_TFS_RECERRORCOUNTH), + &hi_after, peer); + if (err) + return ufs_dme_err_to_errno(err); + + if (hi_before =3D=3D hi_after) { + *val =3D ((u64)hi_after << 32) | lo; + return 0; + } + } + + return -EAGAIN; +} + +static int ufs_pa_err_cnt_show(struct seq_file *s, void *data) +{ + const struct ufs_pa_err_attr *attr =3D s->private; + struct ufs_hba *hba =3D hba_from_file(s->file); + int err; + + if (!hba->ufs_device_wlun) + return -ENODEV; + + err =3D ufs_debugfs_get_user_access(hba); + if (err) + return err; + + if (hba->ufshcd_state !=3D UFSHCD_STATE_OPERATIONAL) { + err =3D -EBUSY; + goto out; + } + + if (attr->mib_attr =3D=3D PA_TFS_RECERRORCOUNTL) { + u64 val; + + err =3D ufs_pa_err_read_rec_cnt(hba, attr->peer, &val); + if (!err) + seq_printf(s, "%llu\n", val); + } else { + u32 val; + + err =3D ufshcd_dme_get_attr(hba, UIC_ARG_MIB(attr->mib_attr), + &val, attr->peer); + err =3D ufs_dme_err_to_errno(err); + if (!err) + seq_printf(s, "%u\n", val); + } + +out: + ufs_debugfs_put_user_access(hba); + return err; +} + +static ssize_t ufs_pa_err_cnt_write(struct file *file, const char __user *= buf, + size_t count, loff_t *ppos) +{ + const struct ufs_pa_err_attr *attr =3D file->f_inode->i_private; + struct ufs_hba *hba =3D hba_from_file(file); + unsigned int val; + int err; + + if (!hba->ufs_device_wlun) + return -ENODEV; + + err =3D kstrtouint_from_user(buf, count, 0, &val); + if (err) + return err; + + if (val !=3D 0) + return -EINVAL; + + err =3D ufs_debugfs_get_user_access(hba); + if (err) + return err; + + if (hba->ufshcd_state !=3D UFSHCD_STATE_OPERATIONAL) { + err =3D -EBUSY; + goto out; + } + + /* + * Per MIPI UniPro v3.0 Section 5.6.7, setting PA_TFS_RecErrorCountL + * clears the entire 64-bit PA_TFS_RecErrorCount counter to 0. + */ + err =3D ufshcd_dme_set_attr(hba, UIC_ARG_MIB(attr->mib_attr), + ATTR_SET_NOR, 0, attr->peer); + err =3D ufs_dme_err_to_errno(err); + +out: + ufs_debugfs_put_user_access(hba); + return err ? err : count; +} + +static int ufs_pa_err_cnt_open(struct inode *inode, struct file *file) +{ + return single_open(file, ufs_pa_err_cnt_show, inode->i_private); +} + +static const struct file_operations ufs_pa_err_cnt_fops =3D { + .owner =3D THIS_MODULE, + .open =3D ufs_pa_err_cnt_open, + .read =3D seq_read, + .write =3D ufs_pa_err_cnt_write, + .llseek =3D seq_lseek, + .release =3D single_release, +}; + +static const struct ufs_pa_err_attr ufs_host_pa_err_attrs[] =3D { + { "fec_err_cnt", PA_TFS_FECERRORCOUNT, DME_LOCAL }, + { "crc_err_cnt", PA_TFS_CRCERRORCOUNT, DME_LOCAL }, + { "format_err_cnt", PA_TFS_FORMATERRORCOUNT, DME_LOCAL }, + { "recovered_fec_symbols", PA_TFS_RECERRORCOUNTL, DME_LOCAL }, + { } +}; + +static const struct ufs_pa_err_attr ufs_dev_pa_err_attrs[] =3D { + { "fec_err_cnt", PA_TFS_FECERRORCOUNT, DME_PEER }, + { "crc_err_cnt", PA_TFS_CRCERRORCOUNT, DME_PEER }, + { "format_err_cnt", PA_TFS_FORMATERRORCOUNT, DME_PEER }, + { "recovered_fec_symbols", PA_TFS_RECERRORCOUNTL, DME_PEER }, + { } +}; + +static void ufs_debugfs_pa_err_create_dir(struct ufs_hba *hba, + struct dentry *parent, + const char *name, + const struct ufs_pa_err_attr *attrs) +{ + const struct ufs_pa_err_attr *pa_attr; + struct dentry *sub_dir; + + sub_dir =3D debugfs_create_dir(name, parent); + if (IS_ERR_OR_NULL(sub_dir)) + return; + + d_inode(sub_dir)->i_private =3D hba; + for (pa_attr =3D attrs; pa_attr->name; pa_attr++) + debugfs_create_file(pa_attr->name, 0600, sub_dir, + (void *)pa_attr, &ufs_pa_err_cnt_fops); +} + +static void ufs_debugfs_pa_err_init(struct ufs_hba *hba) +{ + bool host_sup =3D hba->ufs_version >=3D ufshci_version(5, 0); + bool dev_sup =3D hba->dev_info.wspecversion >=3D 0x500; + struct dentry *pa_dir; + + if ((hba->quirks & UFSHCD_QUIRK_BROKEN_UIC_CMD) || + (!host_sup && !dev_sup)) + return; + + pa_dir =3D debugfs_create_dir("pa_err_stats", hba->debugfs_root); + if (IS_ERR_OR_NULL(pa_dir)) + return; + + if (host_sup) + ufs_debugfs_pa_err_create_dir(hba, pa_dir, "host", + ufs_host_pa_err_attrs); + if (dev_sup) + ufs_debugfs_pa_err_create_dir(hba, pa_dir, "device", + ufs_dev_pa_err_attrs); +} + static const struct ufs_debugfs_attr ufs_attrs[] =3D { { "stats", 0400, &ufs_debugfs_stats_fops }, { "saved_err", 0600, &ufs_saved_err_fops }, @@ -494,6 +703,8 @@ void ufs_debugfs_hba_init(struct ufs_hba *hba) debugfs_create_u32("exception_event_rate_limit_ms", 0600, hba->debugfs_ro= ot, &hba->debugfs_ee_rate_limit_ms); =20 + ufs_debugfs_pa_err_init(hba); + if (!(hba->caps & UFSHCD_CAP_TX_EQUALIZATION)) return; =20 diff --git a/include/ufs/unipro.h b/include/ufs/unipro.h index 9c168703b104..b82f9a9e838f 100644 --- a/include/ufs/unipro.h +++ b/include/ufs/unipro.h @@ -200,6 +200,11 @@ #define PA_PACPFRAMECOUNT 0x15C0 #define PA_PACPERRORCOUNT 0x15C1 #define PA_PHYTESTCONTROL 0x15C2 +#define PA_TFS_FECERRORCOUNT 0x15C3 +#define PA_TFS_CRCERRORCOUNT 0x15C4 +#define PA_TFS_FORMATERRORCOUNT 0x15C5 +#define PA_TFS_RECERRORCOUNTL 0x15C6 +#define PA_TFS_RECERRORCOUNTH 0x15C7 #define PA_TXHSG4SYNCLENGTH 0x15D0 #define PA_PEERRXHSG4ADAPTINITIAL 0x15D3 #define PA_TXHSADAPTTYPE 0x15D4 --=20 2.56.1.809.ga0b61035b5-goog