Skip to content

Commit 9ec5493

Browse files
avri-altman-sndkmartinkpetersen
authored andcommitted
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. Signed-off-by: Avri Altman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bean Huo <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1613e60 commit 9ec5493

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
/* Default RTC update every 10 seconds */
103103
#define UFS_RTC_UPDATE_INTERVAL_MS (10 * MSEC_PER_SEC)
104104

105+
/* bMaxNumOfRTT is equal to two after device manufacturing */
106+
#define DEFAULT_MAX_NUM_RTT 2
107+
105108
/* UFSHC 4.0 compliant HC support this mode. */
106109
static bool use_mcq_mode = true;
107110

@@ -2405,6 +2408,8 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba)
24052408
((hba->capabilities & MASK_TASK_MANAGEMENT_REQUEST_SLOTS) >> 16) + 1;
24062409
hba->reserved_slot = hba->nutrs - 1;
24072410

2411+
hba->nortt = FIELD_GET(MASK_NUMBER_OUTSTANDING_RTT, hba->capabilities) + 1;
2412+
24082413
/* Read crypto capabilities */
24092414
err = ufshcd_hba_init_crypto_capabilities(hba);
24102415
if (err) {
@@ -8121,6 +8126,35 @@ static void ufshcd_ext_iid_probe(struct ufs_hba *hba, u8 *desc_buf)
81218126
dev_info->b_ext_iid_en = ext_iid_en;
81228127
}
81238128

8129+
static void ufshcd_set_rtt(struct ufs_hba *hba)
8130+
{
8131+
struct ufs_dev_info *dev_info = &hba->dev_info;
8132+
u32 rtt = 0;
8133+
u32 dev_rtt = 0;
8134+
8135+
/* RTT override makes sense only for UFS-4.0 and above */
8136+
if (dev_info->wspecversion < 0x400)
8137+
return;
8138+
8139+
if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
8140+
QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &dev_rtt)) {
8141+
dev_err(hba->dev, "failed reading bMaxNumOfRTT\n");
8142+
return;
8143+
}
8144+
8145+
/* do not override if it was already written */
8146+
if (dev_rtt != DEFAULT_MAX_NUM_RTT)
8147+
return;
8148+
8149+
rtt = min_t(int, dev_info->rtt_cap, hba->nortt);
8150+
if (rtt == dev_rtt)
8151+
return;
8152+
8153+
if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
8154+
QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt))
8155+
dev_err(hba->dev, "failed writing bMaxNumOfRTT\n");
8156+
}
8157+
81248158
void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
81258159
const struct ufs_dev_quirk *fixups)
81268160
{
@@ -8256,6 +8290,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
82568290
desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1];
82578291
dev_info->bqueuedepth = desc_buf[DEVICE_DESC_PARAM_Q_DPTH];
82588292

8293+
dev_info->rtt_cap = desc_buf[DEVICE_DESC_PARAM_RTT_CAP];
8294+
82598295
model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
82608296

82618297
err = ufshcd_read_string_desc(hba, model_index,
@@ -8508,6 +8544,8 @@ static int ufshcd_device_params_init(struct ufs_hba *hba)
85088544
goto out;
85098545
}
85108546

8547+
ufshcd_set_rtt(hba);
8548+
85118549
ufshcd_get_ref_clk_gating_wait(hba);
85128550

85138551
if (!ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG,

include/ufs/ufs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ struct ufs_dev_info {
592592
enum ufs_rtc_time rtc_type;
593593
time64_t rtc_time_baseline;
594594
u32 rtc_update_period;
595+
596+
u8 rtt_cap; /* bDeviceRTTCap */
595597
};
596598

597599
/*

include/ufs/ufshcd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ enum ufshcd_mcq_opr {
819819
* @capabilities: UFS Controller Capabilities
820820
* @mcq_capabilities: UFS Multi Circular Queue capabilities
821821
* @nutrs: Transfer Request Queue depth supported by controller
822+
* @nortt - Max outstanding RTTs supported by controller
822823
* @nutmrs: Task Management Queue depth supported by controller
823824
* @reserved_slot: Used to submit device commands. Protected by @dev_cmd.lock.
824825
* @ufs_version: UFS Version to which controller complies
@@ -957,6 +958,7 @@ struct ufs_hba {
957958

958959
u32 capabilities;
959960
int nutrs;
961+
int nortt;
960962
u32 mcq_capabilities;
961963
int nutmrs;
962964
u32 reserved_slot;

include/ufs/ufshci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum {
6868
/* Controller capability masks */
6969
enum {
7070
MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F,
71+
MASK_NUMBER_OUTSTANDING_RTT = 0x0000FF00,
7172
MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000,
7273
MASK_EHSLUTRD_SUPPORTED = 0x00400000,
7374
MASK_AUTO_HIBERN8_SUPPORT = 0x00800000,

0 commit comments

Comments
 (0)