mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Huan Tang <tanghuan@vivo.com>,
	alim.akhtar@samsung.com, avri.altman@wdc.com,
	James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com, beanhuo@micron.com,
	keosung.park@samsung.com, quic_ziqichen@quicinc.com,
	viro@zeniv.linux.org.uk, gwendal@chromium.org,
	peter.wang@mediatek.com, manivannan.sadhasivam@linaro.org,
	quic_cang@quicinc.com, quic_nguyenb@quicinc.com,
	ebiggers@google.com, minwoo.im@samsung.com,
	linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Cc: opensource.kernel@vivo.com, luhongfei@vivo.com,
	Wenxing Cheng <wenxing.cheng@vivo.com>
Subject: Re: [PATCH] ufs: core: Add HID support
Date: Thu, 17 Apr 2025 15:05:01 -0700	[thread overview]
Message-ID: <4eef6172-3ba2-43a9-b6af-3750c39bb344@acm.org> (raw)
In-Reply-To: <20250417125008.123-1-tanghuan@vivo.com>

On 4/17/25 5:50 AM, Huan Tang wrote:
> +What:		/sys/bus/platform/drivers/ufshcd/*/hid_trigger
> +What:		/sys/bus/platform/devices/*.ufs/hid_trigger
> +Date:		April 2025
> +Contact:	Huan Tang <tanghuan@vivo.com>
> +Description:
> +		The host can enable or disable complete HID.
> +
> +		========  ============
> +		enable    Let kworker(ufs_hid_enable_work) execute the complete HID
> +		disable   Cancel kworker(ufs_hid_enable_work) and disable HID
> +		========  ============
> +		The file is write only.
> +
> +What:		/sys/bus/platform/drivers/ufshcd/*/attributes/defrag_operation
> +What:		/sys/bus/platform/devices/*.ufs/attributes/defrag_operation
> +Date:		April 2025
> +Contact:	Huan Tang <tanghuan@vivo.com>
> +Description:
> +		The host can enable or disable HID analysis and HID defrag operations.
> +
> +		===============  ==================================================
> +		all_disable      HID analysis and HID defrag operation are disabled
> +		analysis_enable  HID analysis is enabled
> +		all_enable       HID analysis and HID defrag operation are enabled
> +		===============  ==================================================
> +
> +		The attribute is read/write.

Combining HID analysis and HID defragmentation controls into a single
sysfs attribute seems weird to me. Please replace the above two
attributes with two different attributes: one for controlling HID
analysis and another one for controlling HID defragmentation.

> +
> +What:		/sys/bus/platform/drivers/ufshcd/*/attributes/hid_available_size
> +What:		/sys/bus/platform/devices/*.ufs/attributes/hid_available_size
> +Date:		April 2025
> +Contact:	Huan Tang <tanghuan@vivo.com>
> +Description:
> +		The total fragmented size in the device is reported through this
> +		attribute.
> +
> +		The attribute is read only.

Please change the name of this attribute into "hid_fragmented_size". I
think that this alternative name is much more clear.

> +
> +What:		/sys/bus/platform/drivers/ufshcd/*/attributes/hid_size
> +What:		/sys/bus/platform/devices/*.ufs/attributes/hid_size
> +Date:		April 2025
> +Contact:	Huan Tang <tanghuan@vivo.com>
> +Description:
> +		The host sets the size to be defragmented by an HID defrag operation.
> +
> +		The attribute is read/write.

Please make the name of this attribute more clear, e.g. by renaming it
into "hid_defrag_size". Additionally, please change "defrag" into
"defragmentation".

> +What:		/sys/bus/platform/drivers/ufshcd/*/attributes/hid_progress_ratio
> +What:		/sys/bus/platform/devices/*.ufs/attributes/hid_progress_ratio
> +Date:		April 2025
> +Contact:	Huan Tang <tanghuan@vivo.com>
> +Description:
> +		Defrag progress is reported by this attribute,indicates the ratio of
> +		the completed defrag size over the requested defrag size.
> +
> +		====  ======================================
> +		01h   1%
> +		...
> +		64h   100%
> +		====  ======================================
> +
> +		The attribute is read only.

Please change the format of this attribute from hexadecimal into
decimal (64h -> 100).

> +
> +What:		/sys/bus/platform/drivers/ufshcd/*/attributes/hid_state
> +What:		/sys/bus/platform/devices/*.ufs/attributes/hid_state
> +Date:		April 2025
> +Contact:	Huan Tang <tanghuan@vivo.com>
> +Description:
> +		The HID state is reported by this attribute.
> +
> +		====   ======================================
> +		00h    Idle(analysis required)
> +		01h    Analysis in progress
> +		02h    Defrag required
> +		03h    Defrag in progress
> +		04h    Defrag completed
> +		05h    Defrag is not required
> +		====  ======================================
> +
> +		The attribute is read only.

Please change the format of this attribute from hexadecimal into
decimal. Please add an additional sysfs attribute that provides the
textual meaning of the HID state such that users don't have to look up
the documentation of these codes.

> +config SCSI_UFS_HID
> +	bool "Support UFS Host Initiated Defrag"
> +	help
> +	  The UFS HID feature allows the host to check the status of whether
> +	  defragmentation is needed or not and enable the device's internal
> +	  defrag operation explicitly.
> +
> +	  If unsure, say N.

Here and everywhere else in documentation that is intended for humans,
please change "defrag" into "defragmentation". Please also make the
Kconfig description more clear, e.g. by changing it into the following:

	help
	  In NAND-based storage devices garbage collection is
	  inevitable. Garbage collection may cause latency spikes.
	  The UFS Host-Initiated Defragmentation (HID) functionality
	  gives the host control over when defragmentation (garbage
	  collection) happens and hence can be used to avoid latency
	  spikes.

> +#define HID_SCHED_COUNT_LIMIT	300
> +static int hid_sched_cnt;
> +static void ufs_hid_enable_work_fn(struct work_struct *work)

A blank line is required after the macro definition and also between the
declaration of the static variable and the function definition.

> +{
> +	struct ufs_hba *hba;
> +	int ret = 0;
> +	enum ufs_hid_defrag_operation defrag_op;
> +	u32 hid_ahit = 0;
> +	bool hid_flag = false;

In new code, please order declarations such that the longest declaration
occurs first ("reverse Christmas tree").

> +	hba = container_of(work, struct ufs_hba, ufs_hid_enable_work.work);
> +
> +	if (!hba->dev_info.hid_sup)
> +		return;
> +
> +	down(&hba->host_sem);
> +
> +	if (!ufshcd_is_user_access_allowed(hba)) {
> +		up(&hba->host_sem);
> +		return;
> +	}
> +
> +	ufshcd_rpm_get_sync(hba);
> +	hid_ahit = hba->ahit;
> +	ufshcd_auto_hibern8_update(hba, 0);

Why is auto-hibernation disabled here? Please add a comment.

> +int ufs_hid_disable(struct ufs_hba *hba)
> +{
> +	enum ufs_hid_defrag_operation defrag_op = HID_ANALYSIS_AND_DEFRAG_DISABLE;
> +	u32 hid_ahit;
> +	int ret;
> +
> +	down(&hba->host_sem);
> +
> +	if (!ufshcd_is_user_access_allowed(hba)) {
> +		up(&hba->host_sem);
> +		return -EBUSY;
> +	}
> +
> +	ufshcd_rpm_get_sync(hba);
> +	hid_ahit = hba->ahit;
> +	ufshcd_auto_hibern8_update(hba, 0);
> +
> +	ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
> +				QUERY_ATTR_IDN_HID_DEFRAG_OPERATION, 0, 0, &defrag_op);
> +
> +	ufshcd_auto_hibern8_update(hba, hid_ahit);
> +	ufshcd_rpm_put_sync(hba);
> +	up(&hba->host_sem);
> +
> +	return ret;
> +}

Please add a comment that explains why the ufshcd_auto_hibern8_update()
call is present.

> +static ssize_t hid_size_show(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +	u32 value;
> +	int ret;
> +
> +	ret = hid_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
> +				QUERY_ATTR_IDN_HID_SIZE, &value);
> +	if (ret)
> +		return ret;
> +
> +	return sysfs_emit(buf, "0x%08X\n", value);
> +}

Why the hexadecimal format? All other sysfs size attributes I know of
use the decimal format.

Thanks,

Bart.


  reply	other threads:[~2025-04-17 22:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-17 12:50 Huan Tang
2025-04-17 22:05 ` Bart Van Assche [this message]
2025-05-12 13:35   ` Huan Tang
2025-04-18  8:05 ` Avri Altman
2025-05-12 13:36   ` Huan Tang
2025-04-22  7:37 ` Peter Wang (王信友)
2025-05-12 13:37   ` Huan Tang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4eef6172-3ba2-43a9-b6af-3750c39bb344@acm.org \
    --to=bvanassche@acm.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=alim.akhtar@samsung.com \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=ebiggers@google.com \
    --cc=gwendal@chromium.org \
    --cc=keosung.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=luhongfei@vivo.com \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=martin.petersen@oracle.com \
    --cc=minwoo.im@samsung.com \
    --cc=opensource.kernel@vivo.com \
    --cc=peter.wang@mediatek.com \
    --cc=quic_cang@quicinc.com \
    --cc=quic_nguyenb@quicinc.com \
    --cc=quic_ziqichen@quicinc.com \
    --cc=tanghuan@vivo.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wenxing.cheng@vivo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®