From patchwork Thu May 16 05:51:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 797441 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 427C912B83; Thu, 16 May 2024 05:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715838702; cv=none; b=n7bULyCC+5o5Z7/MR7Aobl/LjDPvqOBePc74SNtAB5EkmgeKjAnPuMcvQzk4QkiBsJ1xP05wa1IaC7yBsBQ1SwiZqrpye7czGm/9g/29qLeM2PaKt9CeZ9FXqYkp3gH7j1NDbTNaPwkgy2ai++UIOfuJa/7tsjbT6cl4OiMhfG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715838702; c=relaxed/simple; bh=yTEfkjiq6HIcCZcRbrgbXTOg/XqjS0pAkcG5SfFtZGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EkoQzOfCke4ftOKZVhtkm1Y44tIiKQ7TUtMgi7g3/VON/NlB+fsCM6/asjvDRGFVKkwj5pjDNGz/xLjjoqR5rb8oFjjhpYC3kyhqTJk9i+5vCgIoUw6Kan1T/rP32yXfLGFadi2lzimtrrc5yc3fcOBb3U0+2iV1bUVkj1Oze9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=aPfD69WI; arc=none smtp.client-ip=216.71.153.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="aPfD69WI" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1715838700; x=1747374700; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yTEfkjiq6HIcCZcRbrgbXTOg/XqjS0pAkcG5SfFtZGI=; b=aPfD69WIH37UZr/YarVzA5PdJDgpesGNeBaflXeDi8ZE6RwlDSIPYt3V ihMA8bo74XWm7HWmjwGznd5Df6tE6aSj+1M0YLwvBv4OBVRUuioT1Vv6h XWlf0ZlJYGoKDfLcyQ+Ogll+f5XJwW9V74Pov4fvhIDZZQdLZ1vYTxATr MvvP1dECq/SmpiB5nelCHAJtXH7GnrWU+XZ32eQoOIeV/U64lMUjWo7Xa VBhLWkpLnw+uVYpxv17dGuUQFFEiHm8QuayBe0lF/oakPXSf9PYiGo4CC +At1UH6vhvZ8G1RfskP4sKvW7RuWpdZAD8Z9Or8DFf2FBmqB6vqMMZXsF g==; X-CSE-ConnectionGUID: cs26tttiQxm0e904GH8+/g== X-CSE-MsgGUID: bptpykfMR2a8BPb4Nj5QnA== X-IronPort-AV: E=Sophos;i="6.08,163,1712592000"; d="scan'208";a="17296238" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2024 13:51:39 +0800 IronPort-SDR: 66459157_q9iazH+mDcRK3NR82ZTOlb0K7FRW+hm7URsjiS8t1nyIKgn rZB6pcOf7rwJ0DstwLL0ocp66ckr+ILE6YtHpNQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 May 2024 21:53:43 -0700 WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip02.wdc.com with ESMTP; 15 May 2024 22:51:37 -0700 From: Avri Altman To: "Martin K . Petersen" Cc: Bart Van Assche , Bean Huo , Peter Wang , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v4 1/3] scsi: ufs: Allow RTT negotiation Date: Thu, 16 May 2024 08:51:22 +0300 Message-ID: <20240516055124.24490-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240516055124.24490-1-avri.altman@wdc.com> References: <20240516055124.24490-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Bean Huo --- drivers/ufs/core/ufshcd.c | 36 ++++++++++++++++++++++++++++++++++++ include/ufs/ufshcd.h | 2 ++ include/ufs/ufshci.h | 1 + 3 files changed, 39 insertions(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 0819ddafe7a6..c472bfdf071e 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -102,6 +102,9 @@ /* Default RTC update every 10 seconds */ #define UFS_RTC_UPDATE_INTERVAL_MS (10 * MSEC_PER_SEC) +/* 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; @@ -2405,6 +2408,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; + hba->nortt = FIELD_GET(MASK_NUMBER_OUTSTANDING_RTT, hba->capabilities) + 1; + /* Read crypto capabilities */ err = ufshcd_hba_init_crypto_capabilities(hba); if (err) { @@ -8119,6 +8124,35 @@ static void ufshcd_ext_iid_probe(struct ufs_hba *hba, u8 *desc_buf) dev_info->b_ext_iid_en = ext_iid_en; } +static void ufshcd_rtt_set(struct ufs_hba *hba, u8 *desc_buf) +{ + 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, desc_buf[DEVICE_DESC_PARAM_RTT_CAP], 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) { @@ -8278,6 +8312,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba) if (hba->ext_iid_sup) ufshcd_ext_iid_probe(hba, desc_buf); + ufshcd_rtt_set(hba, desc_buf); + /* * ufshcd_read_string_desc returns size of the string * reset the error value diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index bad88bd91995..d74bd2d67b06 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -819,6 +819,7 @@ enum ufshcd_mcq_opr { * @capabilities: UFS Controller Capabilities * @mcq_capabilities: UFS Multi Circular Queue capabilities * @nutrs: Transfer Request Queue depth supported by controller + * @nortt - Max outstanding RTTs supported by controller * @nutmrs: Task Management Queue depth supported by controller * @reserved_slot: Used to submit device commands. Protected by @dev_cmd.lock. * @ufs_version: UFS Version to which controller complies @@ -957,6 +958,7 @@ struct ufs_hba { u32 capabilities; int nutrs; + int nortt; u32 mcq_capabilities; int nutmrs; u32 reserved_slot; diff --git a/include/ufs/ufshci.h b/include/ufs/ufshci.h index 385e1c6b8d60..c50f92bf2e1d 100644 --- a/include/ufs/ufshci.h +++ b/include/ufs/ufshci.h @@ -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, From patchwork Thu May 16 05:51:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 797636 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6470929424; Thu, 16 May 2024 05:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715838710; cv=none; b=r9qDTjeGY3tZjiBeet5lA3flcpB+L/tVYctUDSdqMs3wyE3MO33dX7Auqdxj4ThLjvl1AFuChfZZOtWIS8XLkq//W17+/OrUBj6SgYpzAAtwb1fY5BjGvzYR0Bc3gpTZoPNewYIgCJvfuuFuYUyAijmWHPW7/B1T6pxZCWoZ2V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715838710; c=relaxed/simple; bh=q71DnC9S45cHGSP7aHjDfuajgF1C8NzvZXMKmM3pLNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SK7P9E6Km2tyQW53RGs3suu9+/rIgOXYwvC5fClZFphhqm1ib1pxvgo7KmSGqkA18i6KQF5Xh279itV7cjrrjeofGYqH8v6Xp1ZkGmZpMdTeCn5LxUUUcAOsLPC40We/70AwZJNcOxG6UqadjeFuyCnFrUsMI+Yo8cZ+w07uQQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=ei8vkge8; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ei8vkge8" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1715838708; x=1747374708; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q71DnC9S45cHGSP7aHjDfuajgF1C8NzvZXMKmM3pLNg=; b=ei8vkge88I0KR8jMXoZDPChNXMO+LXO0kcPfBvVTehY/rbu9k6TuTsyf iz7q9l/nISrUg6CmTtQwJ8FT7DeAy7Y6YuYkLhyGRByH9mtHrIJDb09h8 FkHQGy1uNx+7OtWwoIpbzFRmZD9YNLxKyilyBoTlflnTAkttUKgR2SRTA qxvGlu96TWgNfFZX64RVNbfQiOYAy0Cdjm8gbfcFCemZaDmj5dJCFjYmw jqLX/yXbb/eEI10kT6tzKNEfJK4DesipWLAnRGVywH50yIYXrVEDHMdMJ fGazgVFF7JQKG5e5COxGmd/tikt8rpWHNcu1LxUyboK9lCpP4AxhlNnvP w==; X-CSE-ConnectionGUID: oX3FVi/FTxqfMS2btVSf9w== X-CSE-MsgGUID: H6oDOhGLSG6k9rOikp+Avw== X-IronPort-AV: E=Sophos;i="6.08,163,1712592000"; d="scan'208";a="16457576" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2024 13:51:46 +0800 IronPort-SDR: 664592b3_dI9ZHyBQ7K9/ptOZjIlTIbpM7BHPe08YCxd8kvRghQ2viud HoMp/vdoNfkoiWUG0XdYQZIUKXfwF5KlJaH67Jw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 May 2024 21:59:31 -0700 WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip02.wdc.com with ESMTP; 15 May 2024 22:51:45 -0700 From: Avri Altman To: "Martin K . Petersen" Cc: Bart Van Assche , Bean Huo , Peter Wang , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v4 2/3] scsi: ufs: Allow platform vendors to set rtt Date: Thu, 16 May 2024 08:51:23 +0300 Message-ID: <20240516055124.24490-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240516055124.24490-1-avri.altman@wdc.com> References: <20240516055124.24490-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Allow platform vendors to take precedence having their own rtt negotiation mechanism. This makes sense because the host controller's nortt characteristic may defer among vendors. Signed-off-by: Avri Altman --- drivers/ufs/core/ufshcd.c | 5 ++++- include/ufs/ufshcd.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index c472bfdf071e..0407d1064e74 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8312,7 +8312,10 @@ static int ufs_get_device_desc(struct ufs_hba *hba) if (hba->ext_iid_sup) ufshcd_ext_iid_probe(hba, desc_buf); - ufshcd_rtt_set(hba, desc_buf); + if (hba->vops && hba->vops->rtt_set) + hba->vops->rtt_set(hba, desc_buf); + else + ufshcd_rtt_set(hba, desc_buf); /* * ufshcd_read_string_desc returns size of the string diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index d74bd2d67b06..9237ea65bd26 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -329,6 +329,7 @@ struct ufs_pwr_mode_info { * @get_outstanding_cqs: called to get outstanding completion queues * @config_esi: called to config Event Specific Interrupt * @config_scsi_dev: called to configure SCSI device parameters + * @rtt_set: negotiate rtt */ struct ufs_hba_variant_ops { const char *name; @@ -374,6 +375,7 @@ struct ufs_hba_variant_ops { int (*get_outstanding_cqs)(struct ufs_hba *hba, unsigned long *ocqs); int (*config_esi)(struct ufs_hba *hba); + void (*rtt_set)(struct ufs_hba *hba, u8 *desc_buf); }; /* clock gating state */ From patchwork Thu May 16 05:51:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 797440 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49B892CCC2; Thu, 16 May 2024 05:51:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715838716; cv=none; b=Rd0vWLXlmjAL8e5LqeCzj5Ndtvr24Zym/jNE8fibgd+liIbb6GIOWodR6yra1RAaUL1A9V1VgMyfpimNtt1TjU8g3I5ZEHgaqYDKTiq2qo0vr3JE9McV2JXgS8KSORo+5H03LWxKjt8wYgzOtVsyIcbrbsnPfkJiUjb20MWGa5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715838716; c=relaxed/simple; bh=mlTAF9IzZ5MszVVLrlFoPVpBmLnU5DPQaAULf7aCYbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ir8onV9D0/qwp+QhMf5DDpkcDuN7J9g5M5S9x1uNXzgBv13pdShmNTwrjpF58uMpMBMqxDIUrvkomkpjxvIj6UpZ+67YHxqCdj1h6ibmwvfVwv0FLGbpEnSI0c1C8x6xM7T2JzSpeOLwRUsHr2B5urcUryVkDJQ++QCIPz/IIz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=jYpS8t5W; arc=none smtp.client-ip=216.71.153.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="jYpS8t5W" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1715838715; x=1747374715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mlTAF9IzZ5MszVVLrlFoPVpBmLnU5DPQaAULf7aCYbs=; b=jYpS8t5W9nRZzd6S5rQaBQAiTzT4KglJ8d0MItgi2P7/EZKxmSGwBEMM zHMxAax8eCL7A2yChym6Ak3PmuuDOVYSqjIb1OUMMhzvzorfVtOeIbZgh HmFrwMgIIV8jg+GZoBfhcRgZb8EkWpQD69/f987DB2xslSBmvpfgfQpJM DvVVvKAzFqelfRFD5kTG8IU4YEOFrWpG/kXmHGdgT29TSi4BHz70E+hk3 HTnSsqygCMljeXfdsqitA+Jx4tVw1viBMsxctv06T91EZ5oKh+9v9lNKd 81zYOg5exfkHVQw5YqoZLEH//9Y/3AzmtVW1YNRMepWnz/eDoVpyEs6IK A==; X-CSE-ConnectionGUID: uS2NQsooQUyfYY8zn3e4PA== X-CSE-MsgGUID: Dd9XOfrYQq23V6RqKM+4lw== X-IronPort-AV: E=Sophos;i="6.08,163,1712592000"; d="scan'208";a="17296259" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2024 13:51:54 +0800 IronPort-SDR: 664592ba_pa912tIsMhlzTVLeTqH8evgXhe7dysXnMntJiZo7BHQYtf0 7iN/iz5rZzF2lW7E6Ux/AsewEMHVj2CXNf46M1A== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 May 2024 21:59:39 -0700 WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip02.wdc.com with ESMTP; 15 May 2024 22:51:53 -0700 From: Avri Altman To: "Martin K . Petersen" Cc: Bart Van Assche , Bean Huo , Peter Wang , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v4 3/3] scsi: ufs: sysfs: Make max_number_of_rtt read-write Date: Thu, 16 May 2024 08:51:24 +0300 Message-ID: <20240516055124.24490-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240516055124.24490-1-avri.altman@wdc.com> References: <20240516055124.24490-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Given the importance of the RTT parameter, we want to be able to configure it via sysfs. This is because UFS users should be discouraged from change UFS device parameters without the UFSHCI driver being aware of these changes. Signed-off-by: Avri Altman --- Documentation/ABI/testing/sysfs-driver-ufs | 14 +++--- drivers/ufs/core/ufs-sysfs.c | 58 +++++++++++++++++++++- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs index 5bf7073b4f75..fe943ce76c60 100644 --- a/Documentation/ABI/testing/sysfs-driver-ufs +++ b/Documentation/ABI/testing/sysfs-driver-ufs @@ -920,14 +920,16 @@ Description: This file shows whether the configuration descriptor is locked. What: /sys/bus/platform/drivers/ufshcd/*/attributes/max_number_of_rtt What: /sys/bus/platform/devices/*.ufs/attributes/max_number_of_rtt -Date: February 2018 -Contact: Stanislav Nijnikov +Date: May 2024 +Contact: Avri Altman Description: This file provides the maximum current number of - outstanding RTTs in device that is allowed. The full - information about the attribute could be found at - UFS specifications 2.1. + outstanding RTTs in device that is allowed. bMaxNumOfRTT is a + read-write persistent attribute and is equal to two after device + manufacturing. It shall not be set to a value greater than + bDeviceRTTCap value, and it may be set only when the hw queues are + empty. - The file is read only. + The file is read write. What: /sys/bus/platform/drivers/ufshcd/*/attributes/exception_event_control What: /sys/bus/platform/devices/*.ufs/attributes/exception_event_control diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c index 3d049967f6bc..8c6aeb836407 100644 --- a/drivers/ufs/core/ufs-sysfs.c +++ b/drivers/ufs/core/ufs-sysfs.c @@ -1340,6 +1340,63 @@ static const struct attribute_group ufs_sysfs_flags_group = { .attrs = ufs_sysfs_device_flags, }; +static ssize_t max_number_of_rtt_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + u32 rtt; + int ret; + + down(&hba->host_sem); + if (!ufshcd_is_user_access_allowed(hba)) { + up(&hba->host_sem); + return -EBUSY; + } + + ufshcd_rpm_get_sync(hba); + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt); + ufshcd_rpm_put_sync(hba); + + if (ret) + goto out; + + ret = sysfs_emit(buf, "0x%08X\n", rtt); + +out: + up(&hba->host_sem); + return ret; +} + +static ssize_t max_number_of_rtt_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + unsigned int rtt; + int ret; + + if (kstrtouint(buf, 0, &rtt)) + return -EINVAL; + + down(&hba->host_sem); + if (!ufshcd_is_user_access_allowed(hba)) { + ret = -EBUSY; + goto out; + } + + ufshcd_rpm_get_sync(hba); + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, + QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt); + ufshcd_rpm_put_sync(hba); + +out: + up(&hba->host_sem); + return ret < 0 ? ret : count; +} + +static DEVICE_ATTR_RW(max_number_of_rtt); + static inline bool ufshcd_is_wb_attrs(enum attr_idn idn) { return idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS && @@ -1387,7 +1444,6 @@ UFS_ATTRIBUTE(max_data_in_size, _MAX_DATA_IN); UFS_ATTRIBUTE(max_data_out_size, _MAX_DATA_OUT); UFS_ATTRIBUTE(reference_clock_frequency, _REF_CLK_FREQ); UFS_ATTRIBUTE(configuration_descriptor_lock, _CONF_DESC_LOCK); -UFS_ATTRIBUTE(max_number_of_rtt, _MAX_NUM_OF_RTT); UFS_ATTRIBUTE(exception_event_control, _EE_CONTROL); UFS_ATTRIBUTE(exception_event_status, _EE_STATUS); UFS_ATTRIBUTE(ffu_status, _FFU_STATUS);