Re: [PATCH v2 2/2] scsi: ufs: core: Add debugfs for PA TFS/FEC error counters

From: Bart Van Assche

Date: Tue Nov 24 2026 - 13:47:43 EST


On 11/23/26 5:29 PM, Po-Wen Kao wrote:
> +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 = 0; retry < UFS_PA_ERR_REC_READ_RETRIES; retry++) {

Does the UniPro v3.0 specification define whether or not reading
PA_TFS_RecErrorCountL latches PA_TFS_RecErrorCountH? If it does, this
retry loop is not necessary. If it doesn't, please mention this in a
source code comment.

> + /*
> + * 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 = ufshcd_dme_set_attr(hba, UIC_ARG_MIB(attr->mib_attr),
> + ATTR_SET_NOR, 0, attr->peer);

This comment only applies to one of the four attributes while the code
below it applies to all attributes. Please make that clear in the
comment.

> +static const struct ufs_pa_err_attr ufs_host_pa_err_attrs[] = {
> + { "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[] = {
> + { "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 },
> + { }
> +};

These two arrays only differ in the value of the .peer member. Has it
been considered to use a single array?

> +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 = debugfs_create_dir(name, parent);
> + if (IS_ERR_OR_NULL(sub_dir))
> + return;
> +
> + d_inode(sub_dir)->i_private = hba;

The comment above hba_from_file() says that @file corresponds to a
debugfs attribute in directory hba->debugfs_root. That comment is no
longer accurate. Please update it.

> +static void ufs_debugfs_pa_err_init(struct ufs_hba *hba)
> +{
> + bool host_sup = hba->ufs_version >= ufshci_version(5, 0);
> + bool dev_sup = hba->dev_info.wspecversion >= 0x500;

The PA_TFS_* attributes are UniPro attributes. Has it been considered
to check the UniPro version (PA_LOCALVERINFO and PA_REMOTEVERINFO)
instead of the UFSHCI version and wSpecVersion? That would require
adding a UFS_UNIPRO_VER_3_0 constant in include/ufs/unipro.h.

Thanks,

Bart.