[PATCH 08/17] ufs: Expose 'ufshcd_ops_dbg_register_dump' vops to allow dumping debug registers

Marek Vasut marek.vasut at mailbox.org
Tue Aug 15 00:34:14 CEST 2023


On 8/14/23 23:54, Bhupesh Sharma wrote:
> Add more verbose debug capabilities and vops to allow dumping
> UFS debug registers / regions, similar to how the UFS Linux driver
> does it.
> 
> Signed-off-by: Bhupesh Sharma <bhupesh.sharma at linaro.org>
> ---
>   drivers/ufs/ufs.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
>   drivers/ufs/ufs.h |  9 ++++++
>   2 files changed, 80 insertions(+)
> 
> diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
> index b2c3af429e..15fa3832b9 100644
> --- a/drivers/ufs/ufs.c
> +++ b/drivers/ufs/ufs.c
> @@ -59,10 +59,81 @@
>   /* maximum bytes per request */
>   #define UFS_MAX_BYTES	(128 * 256 * 1024)
>   
> +#define ufshcd_hex_dump(prefix_str, buf, len) do {                      \
> +	size_t __len = (len);                                           \
> +	print_hex_dump(prefix_str,                             		\
> +		       DUMP_PREFIX_OFFSET,				\
> +		       16, 4, buf, __len, false);                       \
> +} while (0)
> +
>   static inline bool ufshcd_is_hba_active(struct ufs_hba *hba);
>   static inline void ufshcd_hba_stop(struct ufs_hba *hba);
>   static int ufshcd_hba_enable(struct ufs_hba *hba);
>   
> +int ufshcd_dump_regs(struct ufs_hba *hba, size_t offset, size_t len,
> +		     const char *prefix)
> +{
> +	u32 *regs;
> +	size_t pos;
> +
> +	if (offset % 4 != 0 || len % 4 != 0) /* keep readl happy */
> +		return -EINVAL;
> +
> +	regs = kzalloc(len, GFP_KERNEL);
> +	if (!regs)
> +		return -ENOMEM;
> +
> +	for (pos = 0; pos < len; pos += 4) {
> +		if (offset == 0 &&
> +		    pos >= REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER &&
> +		    pos <= REG_UIC_ERROR_CODE_DME)
> +			continue;
> +		regs[pos / 4] = ufshcd_readl(hba, offset + pos);
> +	}
> +
> +	ufshcd_hex_dump(prefix, regs, len);
> +	kfree(regs);

Why not use variable on stack instead of this malloc-free cycle ?


More information about the U-Boot mailing list