mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-07 09:55:19 +02:00
BACKPORT: scsi: ufs: core: Allow RTT negotiation
The rtt-upiu packets precede any data-out upiu packets, thus synchronizing
the data input to the device: this mostly applies to write operations, but
there are other operations that requires rtt as well.
There are several rules binding this rtt - data-out dialog, specifically
There can be at most outstanding bMaxNumOfRTT such packets. This might
have an effect on write performance (sequential write in particular), as
each data-out upiu must wait for its rtt sibling.
UFSHCI expects bMaxNumOfRTT to be min(bDeviceRTTCap, NORTT). However, as of
today, there does not appears to be no-one who sets it: not the host
controller nor the driver. It wasn't an issue up to now: bMaxNumOfRTT is
set to 2 after manufacturing, and wasn't limiting the write performance.
UFS4.0, and specifically gear 5 changes this, and requires the device to be
more attentive. This doesn't come free - the device has to allocate more
resources to that end, but the sequential write performance improvement is
significant. Early measurements shows 25% gain when moving from rtt 2 to
9. Therefore, set bMaxNumOfRTT to be min(bDeviceRTTCap, NORTT) as UFSHCI
expects.
Change-Id: I26a6d008a8007e9abfad913ba367706d698a6c5e
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20240530142510.734-2-avri.altman@wdc.com
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 362473899
(cherry picked from commit 9ec54934ce
)
[ bvanassche: introduced struct ufs_hba_priv ]
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
parent
bf58cbe86d
commit
4bf609a0ed
|
@ -6,6 +6,21 @@
|
|||
#include <linux/pm_runtime.h>
|
||||
#include <ufs/ufshcd.h>
|
||||
|
||||
/*
|
||||
* @rtt_cap - bDeviceRTTCap
|
||||
* @nortt - Max outstanding RTTs supported by controller
|
||||
*/
|
||||
struct ufs_hba_priv {
|
||||
struct ufs_hba hba;
|
||||
u8 rtt_cap;
|
||||
int nortt;
|
||||
};
|
||||
|
||||
static inline struct ufs_hba_priv *to_hba_priv(struct ufs_hba *hba)
|
||||
{
|
||||
return container_of(hba, struct ufs_hba_priv, hba);
|
||||
}
|
||||
|
||||
static inline bool ufshcd_is_user_access_allowed(struct ufs_hba *hba)
|
||||
{
|
||||
return !hba->shutting_down;
|
||||
|
|
|
@ -103,6 +103,9 @@ enum {
|
|||
/* Polling time to wait for fDeviceInit */
|
||||
#define FDEVICEINIT_COMPL_TIMEOUT 1500 /* millisecs */
|
||||
|
||||
/* bMaxNumOfRTT is equal to two after device manufacturing */
|
||||
#define DEFAULT_MAX_NUM_RTT 2
|
||||
|
||||
/* UFSHC 4.0 compliant HC support this mode. */
|
||||
static bool use_mcq_mode = true;
|
||||
|
||||
|
@ -2302,6 +2305,8 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba)
|
|||
((hba->capabilities & MASK_TASK_MANAGEMENT_REQUEST_SLOTS) >> 16) + 1;
|
||||
hba->reserved_slot = hba->nutrs - 1;
|
||||
|
||||
to_hba_priv(hba)->nortt = FIELD_GET(MASK_NUMBER_OUTSTANDING_RTT, hba->capabilities) + 1;
|
||||
|
||||
/* Read crypto capabilities */
|
||||
err = ufshcd_hba_init_crypto_capabilities(hba);
|
||||
if (err) {
|
||||
|
@ -8150,6 +8155,35 @@ out:
|
|||
dev_info->b_ext_iid_en = ext_iid_en;
|
||||
}
|
||||
|
||||
static void ufshcd_set_rtt(struct ufs_hba *hba)
|
||||
{
|
||||
struct ufs_dev_info *dev_info = &hba->dev_info;
|
||||
u32 rtt = 0;
|
||||
u32 dev_rtt = 0;
|
||||
|
||||
/* RTT override makes sense only for UFS-4.0 and above */
|
||||
if (dev_info->wspecversion < 0x400)
|
||||
return;
|
||||
|
||||
if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
|
||||
QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &dev_rtt)) {
|
||||
dev_err(hba->dev, "failed reading bMaxNumOfRTT\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* do not override if it was already written */
|
||||
if (dev_rtt != DEFAULT_MAX_NUM_RTT)
|
||||
return;
|
||||
|
||||
rtt = min_t(int, to_hba_priv(hba)->rtt_cap, to_hba_priv(hba)->nortt);
|
||||
if (rtt == dev_rtt)
|
||||
return;
|
||||
|
||||
if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
|
||||
QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt))
|
||||
dev_err(hba->dev, "failed writing bMaxNumOfRTT\n");
|
||||
}
|
||||
|
||||
void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
|
||||
const struct ufs_dev_quirk *fixups)
|
||||
{
|
||||
|
@ -8212,6 +8246,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
|
|||
desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1];
|
||||
dev_info->bqueuedepth = desc_buf[DEVICE_DESC_PARAM_Q_DPTH];
|
||||
|
||||
to_hba_priv(hba)->rtt_cap = desc_buf[DEVICE_DESC_PARAM_RTT_CAP];
|
||||
|
||||
model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
|
||||
|
||||
err = ufshcd_read_string_desc(hba, model_index,
|
||||
|
@ -8544,6 +8580,8 @@ static int ufshcd_device_params_init(struct ufs_hba *hba)
|
|||
goto out;
|
||||
}
|
||||
|
||||
ufshcd_set_rtt(hba);
|
||||
|
||||
ufshcd_get_ref_clk_gating_wait(hba);
|
||||
|
||||
if (!ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG,
|
||||
|
@ -10297,7 +10335,7 @@ int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle)
|
|||
}
|
||||
|
||||
host = scsi_host_alloc(&ufshcd_driver_template,
|
||||
sizeof(struct ufs_hba));
|
||||
sizeof(struct ufs_hba_priv));
|
||||
if (!host) {
|
||||
dev_err(dev, "scsi_host_alloc failed\n");
|
||||
err = -ENOMEM;
|
||||
|
|
|
@ -68,6 +68,7 @@ enum {
|
|||
/* Controller capability masks */
|
||||
enum {
|
||||
MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F,
|
||||
MASK_NUMBER_OUTSTANDING_RTT = 0x0000FF00,
|
||||
MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000,
|
||||
MASK_EHSLUTRD_SUPPORTED = 0x00400000,
|
||||
MASK_AUTO_HIBERN8_SUPPORT = 0x00800000,
|
||||
|
|
Loading…
Reference in New Issue
Block a user