From patchwork Mon Jul 12 09:50:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 473288 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93781C07E99 for ; Mon, 12 Jul 2021 09:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AEFE6108B for ; Mon, 12 Jul 2021 09:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240956AbhGLJx5 (ORCPT ); Mon, 12 Jul 2021 05:53:57 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:4433 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240930AbhGLJx5 (ORCPT ); Mon, 12 Jul 2021 05:53:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083469; x=1657619469; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=amOe7Gjyt1Hh4vZjAlxnOwqPeqfJ7P/2zsBae3fm2cQ=; b=rqY+lFcT6PZf2Wh4yzz5bEgOogTkgqGmvr/D50B0hYwCVckRIfXjjRj2 8XCIXQVwyThR00Mi15HANmvrTf/1mo2tQ8pK/mBlhjj6kEcoHk87rY6tH /PnG1o5v3EDxzrd1DSmM0d+rRAhvbLbbY54EPZ3CDWcS4fD86V72IWC/7 DQJovjNOvRvEMw9WeF0fWQq+qL76lda15NSUdg7VpLPSPgvx2qFQkITJT jvMrWsqsDeQY8cNRc4KGQfNeV6OOL+u4Qa0CLJe8l4cLLCUD2GPR0YEq/ cgJqQweX5HsposoS0fQSWmw86vo3HqcdBkgvwZQzwYHvSB/uhhNLpM0fc A==; IronPort-SDR: zV3ddZr7x68K0hFd8Sl/U2OTR7WPjeRYRjDw784pjXNKw1fxq2BPAqeKoxqTaPLIMEW2P8pJMM JCAtCfM0kwOWnfKrubv8GKAXzXnwPzI5qki6J70kgf75m0Ekcq+qge7CDFZK+nuLvu170ItGTP kldMLcI8K6H5lq9yFJ/duH2s7kmrRl1p9TJpsWjF5U0G68WeA4LgOuZZLeCGrX6wO62HzuBzLD pDgFM3e2JSDhd4yMSYE5BlC/cQ+HnfTdGp4nILpkSwyvTOyhgKm7KTBrJLv34EJ5Y/A95yixqD FM0= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="173586753" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:51:08 +0800 IronPort-SDR: +CKcCqKCHC1juuCDBouj+Pexe9gfqPNtuOm1WFqcoXo+l/ccRN3Z95uh5TkhjeWEzWbey7mj9W TLIAzdtNLNM6xolOga55JWYrRxmd4dtjYu7aWQVTkVisn26LKn+LkWtpmiUfWDecn1gMtOlMrM EBJ/lbQx2t84tkfBvEA65z0usO9M2OpOhWB88DuvqwizICBMU3sjhYugw9xumt0I/NldS0UfAB fU66rF6TqKcpQkgoYrKsCW4rBXV9jnJcTueQJcItUhvn0hsMsRjqZL98i8OljG4yAmRo4G2xm2 LZ6V0+zmeyiXU5klzdJsGBSJ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:29:16 -0700 IronPort-SDR: Hvt3VZoO4YZpiRP0KwufuGdATWZrcjByULYpOKyf6kwFFwbN7cIdEldmCzOCTjbqR0TOK32Pcw s9qIlvLhTpCs6KeOvhe96QEyeYQqYxy+PNE6rqLVxsY3R+6oRlVgkojTQ2iHSk0TDTsq25EyPU 5yWZLg+ctwe69a6KRV1qcD07C1vw+QUOP79G9r4tz6JOyx2oWVFQ9feEjjBp2MhZ2r4WYMSCRW kOgpa22pBVvWTQw8o/kYjfPGdx8HBY9RymiP+WuZRe06/iMCBNIeByoN2IpgXWXZ/C5bUTD6mK JW8= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:51:04 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 01/12] scsi: ufshpb: Cache HPB Control mode on init Date: Mon, 12 Jul 2021 12:50:28 +0300 Message-Id: <20210712095039.8093-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We will use it later, when we'll need to differentiate between device and host control modes. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshcd.h | 2 ++ drivers/scsi/ufs/ufshpb.c | 8 +++++--- drivers/scsi/ufs/ufshpb.h | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 90aad8393572..0b4496c1af64 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -652,6 +652,7 @@ struct ufs_hba_variant_params { * @hpb_disabled: flag to check if HPB is disabled * @max_hpb_single_cmd: device reported bMAX_DATA_SIZE_FOR_SINGLE_CMD value * @is_legacy: flag to check HPB 1.0 + * @control_mode: either host or device */ struct ufshpb_dev_info { int num_lu; @@ -661,6 +662,7 @@ struct ufshpb_dev_info { bool hpb_disabled; u8 max_hpb_single_cmd; bool is_legacy; + u8 control_mode; }; #endif diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index f417fb89174f..c6fa9cee683a 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -1608,6 +1608,9 @@ static void ufshpb_lu_parameter_init(struct ufs_hba *hba, % (hpb->srgn_mem_size / HPB_ENTRY_SIZE); hpb->pages_per_srgn = DIV_ROUND_UP(hpb->srgn_mem_size, PAGE_SIZE); + + if (hpb_dev_info->control_mode == HPB_HOST_CONTROL) + hpb->is_hcm = true; } static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) @@ -2301,11 +2304,10 @@ void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) { struct ufshpb_dev_info *hpb_dev_info = &hba->ufshpb_dev; int version, ret; - u8 hpb_mode; u32 max_hpb_single_cmd = HPB_MULTI_CHUNK_LOW; - hpb_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CONTROL]; - if (hpb_mode == HPB_HOST_CONTROL) { + hpb_dev_info->control_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CONTROL]; + if (hpb_dev_info->control_mode == HPB_HOST_CONTROL) { dev_err(hba->dev, "%s: host control mode is not supported.\n", __func__); hpb_dev_info->hpb_disabled = true; diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index 1e8d6e1d909e..dc168ba08a09 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -228,6 +228,8 @@ struct ufshpb_lu { u32 entries_per_srgn_shift; u32 pages_per_srgn; + bool is_hcm; + struct ufshpb_stats stats; struct ufshpb_params params; From patchwork Mon Jul 12 09:50:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 474981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05D3DC07E99 for ; Mon, 12 Jul 2021 09:51:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2C6961026 for ; Mon, 12 Jul 2021 09:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238022AbhGLJyO (ORCPT ); Mon, 12 Jul 2021 05:54:14 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:32759 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236948AbhGLJyM (ORCPT ); Mon, 12 Jul 2021 05:54:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083486; x=1657619486; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bB7MvasJZ9DncuscKSgJFhICGBgcOVqFqTXKWZPhUQU=; b=OJRLwhzwuUvMtWtMvoso6XL6/voCkmT3n58gp4un7/wqmodwE5izJ3fq KarvIp0bF7c6xNmm7PMBhwI7LT0KwYCN+so7zlsyxQq0hfTF5r57oHbci RMGu2dW2btoCWEPRxAMJgx731gMnMZq+RaCz/B3Ae9/m/7Cv/8moSQJ3J rs7d6OUN0FKDPl8GDoSdGJebUGhulk50mLr77KnPe74bEuAd58aGrKhpo d5+5PgFhzhBgJUQivYH97jFSlg3oZYOOzCubbLDkbuC5PhBxbN1PjR8MV I9GSklJ1e04VJVrvUb2NLL/2sCn2nM1orzhcqa+0PZvB3RlbgAoFgiNmS A==; IronPort-SDR: 6+bN4A1CiWHehEK7adS7qYnM9bEQLttkYKEPBSrnnR5x60xS6/IcKImX0DwV/RYm6Jn6ytJu68 tspQp45uGV66o2swNiyxa/uIRIaO8SM6bUS7kpY+CAWYB7l9gvVyJLMPTaZz9FoN9tl87OyrIU MCDwibKhLC1EF/FFqkO8YVSwCx55GIW5yOL56ifkx66shbFDSINY6ZKEzTCnCrEjrKQKmkslw0 KJo5g2eVjXNBmZq2JWyt5CNAR+1PEADStOPf5EGUd6YIcjRm4+sKu5CmsMzT2wt6JENfO9HImA U0s= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="174920170" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:51:25 +0800 IronPort-SDR: W4PjXmAUalJoJeH2f4KSsperFqvzHan4BsFwmwnmZw46LrnEITTPFq0Q2rZenFUweLkGbLdFTO rggO+LzRq/XelRIY5qp5QhkJtP4FDPuLzkez5ll92VHT+hTPMFGXQNiGKWT3A9i6pEFbIkb+br yzh9kwjFt2fwQ2hG3Tqs7nfMu6GSRp/V/g6DRIKWKQK8xa3QUvwMxSnXz4+aCk3iVQGVJXcI7Z ocz3hHTdVbWj6d7vK0vY8OTZMEGXzHo1N7LrT83Jp9WTeX6ysi3hxpQNxWUFQfjbEkP0gkU63D nC25OG8Mvs7qjH8dlcmA6fl4 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:29:30 -0700 IronPort-SDR: 1nhFrDFpTgEmecWHRaPtghg0cgmtVG1HnZSyD/+Phx+pmTpO+8ws04ZtlrJUf3zJ77qqDY7BHB bLj3uKjLyrh53Bq7FrNP0YATO1qk1ZcIBFGer+0HSN4eBxrhJrzU9sW0pJX0esXcLVw37HwmqH nFydc8+Ur3wdypooAElFlo1Jcfnx6i4L+4pg2pLRY10oaNJ7z+ONgPt0G1ZYiln67PGMqjHx4+ M/vGiKTRYt8E0rB4IQkPTSyxwjANilc/ZyIUf8EJIcpHQ4FutFvNE0x7c44xbK5sEN94rwBYJv BNw= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:51:19 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 02/12] scsi: ufshpb: Add host control mode support to rsp_upiu Date: Mon, 12 Jul 2021 12:50:29 +0300 Message-Id: <20210712095039.8093-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In device control mode, the device may recommend the host to either activate or inactivate a region, and the host should follow. Meaning those are not actually recommendations, but more of instructions. On the contrary, in host control mode, the recommendation protocol is slightly changed: a) The device may only recommend the host to update a subregion of an already-active region. And, b) The device may *not* recommend to inactivate a region. Furthermore, in host control mode, the host may choose not to follow any of the device's recommendations. However, in case of a recommendation to update an active and clean subregion, it is better to follow those recommendation because otherwise the host has no other way to know that some internal relocation took place. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 34 +++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshpb.h | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index c6fa9cee683a..0ac0a4ec1e1f 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -167,6 +167,8 @@ static void ufshpb_set_ppn_dirty(struct ufshpb_lu *hpb, int rgn_idx, else set_bit_len = cnt; + set_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); + if (rgn->rgn_state != HPB_RGN_INACTIVE && srgn->srgn_state == HPB_SRGN_VALID) bitmap_set(srgn->mctx->ppn_dirty, srgn_offset, set_bit_len); @@ -236,6 +238,11 @@ static bool ufshpb_test_ppn_dirty(struct ufshpb_lu *hpb, int rgn_idx, return false; } +static inline bool is_rgn_dirty(struct ufshpb_region *rgn) +{ + return test_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); +} + static int ufshpb_fill_ppn_from_page(struct ufshpb_lu *hpb, struct ufshpb_map_ctx *mctx, int pos, int len, __be64 *ppn_buf) @@ -713,6 +720,7 @@ static void ufshpb_put_map_req(struct ufshpb_lu *hpb, static int ufshpb_clear_dirty_bitmap(struct ufshpb_lu *hpb, struct ufshpb_subregion *srgn) { + struct ufshpb_region *rgn; u32 num_entries = hpb->entries_per_srgn; if (!srgn->mctx) { @@ -726,6 +734,10 @@ static int ufshpb_clear_dirty_bitmap(struct ufshpb_lu *hpb, num_entries = hpb->last_srgn_entries; bitmap_zero(srgn->mctx->ppn_dirty, num_entries); + + rgn = hpb->rgn_tbl + srgn->rgn_idx; + clear_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); + return 0; } @@ -1238,6 +1250,18 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, srgn_i = be16_to_cpu(rsp_field->hpb_active_field[i].active_srgn); + rgn = hpb->rgn_tbl + rgn_i; + if (hpb->is_hcm && + (rgn->rgn_state != HPB_RGN_ACTIVE || is_rgn_dirty(rgn))) { + /* + * in host control mode, subregion activation + * recommendations are only allowed to active regions. + * Also, ignore recommendations for dirty regions - the + * host will make decisions concerning those by himself + */ + continue; + } + dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, "activate(%d) region %d - %d\n", i, rgn_i, srgn_i); @@ -1245,7 +1269,6 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, ufshpb_update_active_info(hpb, rgn_i, srgn_i); spin_unlock(&hpb->rsp_list_lock); - rgn = hpb->rgn_tbl + rgn_i; srgn = rgn->srgn_tbl + srgn_i; /* blocking HPB_READ */ @@ -1256,6 +1279,14 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, hpb->stats.rb_active_cnt++; } + if (hpb->is_hcm) { + /* + * in host control mode the device is not allowed to inactivate + * regions + */ + goto out; + } + for (i = 0; i < rsp_field->inactive_rgn_cnt; i++) { rgn_i = be16_to_cpu(rsp_field->hpb_inactive_field[i]); dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, @@ -1280,6 +1311,7 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, hpb->stats.rb_inactive_cnt++; } +out: dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, "Noti: #ACT %u #INACT %u\n", rsp_field->active_rgn_cnt, rsp_field->inactive_rgn_cnt); diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index dc168ba08a09..9ab502f82835 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -121,6 +121,8 @@ struct ufshpb_region { /* below information is used by lru */ struct list_head list_lru_rgn; + unsigned long rgn_flags; +#define RGN_FLAG_DIRTY 0 }; #define for_each_sub_region(rgn, i, srgn) \ From patchwork Mon Jul 12 09:50:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 473287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8408CC07E99 for ; Mon, 12 Jul 2021 09:51:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D195610CD for ; Mon, 12 Jul 2021 09:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238127AbhGLJyX (ORCPT ); Mon, 12 Jul 2021 05:54:23 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:11544 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236377AbhGLJyW (ORCPT ); Mon, 12 Jul 2021 05:54:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083494; x=1657619494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QdKOfzlJ2W+4aSAxJPGoEKB3+6FSSH1LQMJ40hFEuwE=; b=PwBgV/lyCbNme7uy/oI05+PwnXfHfqVAKtzi4865AXQ3/r+5B8nxH0uD l/VcolnRXUi8s3TrcBS7qqgBp/84rKGdhBRnkV/AaXiw+V+XGpF1o5Atg IpJYfjdC3hxP+yzHW2/zEqTfPvQcnCZ+x6XnLWomPlvRXuQ+rHkpQ8F1o vAvNkPXe0C6VGX8PkziyBj7r94L8p7Y/tMmb3kqqnwCYCzntFppZdmpJ6 PZ9mKnKVwDIbq4Av6SjY2Y6IstZEUR/Jvwn/ri/OjwKPMyEPN1AN6juFO H5B2P+SPwEKZ5q14mbtljMv28Oep1+Lncku2rd8gll/Aui5qDJABPMYbu Q==; IronPort-SDR: 3dxaf0HVewoNEuq4c9INg9bOjyM1WtFBf0icH9CBP88++2zdewOftAx9TimSv81MTfiNFEEDDk e+YkuqFcGN4Y76ES+rBap6u+726sTCVqt+5TuKZdauQTdaytUaFMc3/9wXR3ZNMhdXmsHF+IwZ MjxhHhKfZ/dOkkG7qF3dTJewGlzRk4Sn7ECLVcjKCbiaFxe1JmCerAYv+Fgmt+//hyFWfc346y jvGbgcOcIyCGCzMQ95ErBOvVJvrmknjR/YOqzxNaorDSjduDybDtVrtARgZi6atbRRfuPtpbw3 j4Q= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="285877067" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:51:32 +0800 IronPort-SDR: EFThIQr+qE5KnFHuXIy8rO8hzgl8U0MMPVyTvl2s34oCuK2wL3HeOy1XJ+muJFy0XqqH5sMxhL hi5Nmp0UnGHNmafB3nWLKaVUX4pk6GD76XQUXqq4urdVUhDm+ZsCuamrWD221racx2hndptw1j KTmRGmDU5RFEH7TCPuY7P4Bf9d1tip+U4h+xbK+V+/fvPY/p1yXntbBmbOSbvlXervv9+hdwT6 FHc56ZzCiiYKVnu2s6j+2bzayam4ueusuqnjfSrBislNyanIuWbxkdQICty+wPxeNIPVN6Pn6f eQQWPacXXzHzRfAtoZP+RTjf Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:29:39 -0700 IronPort-SDR: sgU4EJtUw9ur+afh7mn1YtkqtEPEfDuSrvM80Vv6HiuhliOyyXJJRyRht14Jory3mI5N1vL+Sb Tis7eWp/H1DMs4zNXYsGV1KPTrR8UArc1pFzedLm19B6E4CpUKq3Aigifepi7f97xoatLrgsvz G0BSAtITK8CVExaObFw0i4+g/G868BV7dY2vZaUCIGEEZigoZMiqEz3QX1Vv1rQpj+vVvZ8N+G UB0QIjk5SsVmoENWqBXONQaTNYDOYRTpQzk21NhJEgvrUg3Crk9IfJN0Kr4NyDS3ZnC+IDefU1 CRA= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:51:28 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 03/12] scsi: ufshpb: Transform set_dirty to iterate_rgn Date: Mon, 12 Jul 2021 12:50:30 +0300 Message-Id: <20210712095039.8093-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Given a transfer length, set_dirty meticulously runs over all the entries, across subregions and regions if needed. Currently its only use is to mark dirty blocks, but soon HCM may profit from it as well, when managing its read counters. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 0ac0a4ec1e1f..3663f427dff6 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -145,13 +145,14 @@ static bool ufshpb_is_hpb_rsp_valid(struct ufs_hba *hba, return true; } -static void ufshpb_set_ppn_dirty(struct ufshpb_lu *hpb, int rgn_idx, - int srgn_idx, int srgn_offset, int cnt) +static void ufshpb_iterate_rgn(struct ufshpb_lu *hpb, int rgn_idx, int srgn_idx, + int srgn_offset, int cnt, bool set_dirty) { struct ufshpb_region *rgn; struct ufshpb_subregion *srgn; int set_bit_len; int bitmap_len; + unsigned long flags; next_srgn: rgn = hpb->rgn_tbl + rgn_idx; @@ -167,11 +168,14 @@ static void ufshpb_set_ppn_dirty(struct ufshpb_lu *hpb, int rgn_idx, else set_bit_len = cnt; - set_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); + if (set_dirty) + set_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); - if (rgn->rgn_state != HPB_RGN_INACTIVE && + spin_lock_irqsave(&hpb->rgn_state_lock, flags); + if (set_dirty && rgn->rgn_state != HPB_RGN_INACTIVE && srgn->srgn_state == HPB_SRGN_VALID) bitmap_set(srgn->mctx->ppn_dirty, srgn_offset, set_bit_len); + spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); srgn_offset = 0; if (++srgn_idx == hpb->srgns_per_rgn) { @@ -591,10 +595,8 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) /* If command type is WRITE or DISCARD, set bitmap as drity */ if (ufshpb_is_write_or_discard(cmd)) { - spin_lock_irqsave(&hpb->rgn_state_lock, flags); - ufshpb_set_ppn_dirty(hpb, rgn_idx, srgn_idx, srgn_offset, - transfer_len); - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + ufshpb_iterate_rgn(hpb, rgn_idx, srgn_idx, srgn_offset, + transfer_len, true); return 0; } From patchwork Mon Jul 12 09:50:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 474980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D0F2C07E99 for ; Mon, 12 Jul 2021 09:51:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D2846108B for ; Mon, 12 Jul 2021 09:51:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241203AbhGLJye (ORCPT ); Mon, 12 Jul 2021 05:54:34 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:4475 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241166AbhGLJy2 (ORCPT ); Mon, 12 Jul 2021 05:54:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083500; x=1657619500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2mE6HnixVQ0nNDwBgw5qlos26G/asVJ4KERSAzfQHOY=; b=qY5vqLtwviDxeOeJIufv/LjXyZT6477eVuMfRRLais6Sz1mAg1LOTcKQ OAALsDxNtlD6LDiZpkUmqHG/tB80snaD0YGU0QyI3UooN3V8fKqkpbaHe O0/7UwC3wHQusOrKIn96Mn1dpX0A8AsWnU0w1oNplmTA5YMMuegoTA7uM x9GqcVXBP+QaCnFWefRutPfXAl+8il0JyLWLVrg5tsUbKlPFlLWeLqUcr yAXxYni9oGd+q/HIf45qGrQmxN9lErcqwRs7mF0Z2lQehrpj1TnLMvJVb db2S3+Ci18rbjcl1UEVz3AtvsMTj/oECl1TwG3sxNFKTBL9x+lQ3Ggo1I g==; IronPort-SDR: vMbXU+5KCCex2Yw/ota5N+8TshTRQeUhfueit0JmjbaeN62UZZz6JTMsmLircC8vaCJxCdBqEP /a70cD227xV2jHGpO4vXiIZVwFNVt4uq+R2+Lboq+rccXfgDVm2lfen1KA6S9mxFRMoqxZq71P m+U5puHU1B8QPK8qh1J4Kv0Pdwx3j37ScN9pH880J/D0a04vNAHXBO058ETI/aQddiLm/22Yhb 2mbWp3TBCZXw7i7IyJRHI2Qpaebqy7Ki+b12cqvjNQphOyb5AlajJJ4GDVd0mE4bARQM6Mf6Gy 7sg= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="173586801" 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; 12 Jul 2021 17:51:40 +0800 IronPort-SDR: HcoQhn/MGu6dqQ2au5wPmMYKDFpPzIRyF0DG4t3zOetND2g0XEvYhiidIrLw8ZLb/GwkdXjGIi aR3iofZEenr9Jd2QVxBSV4BglH3jELPQGvWCZugFkjdesif/DrgMC+f2j9wmBdu2O7HTtTZ+Va QjzSh+VqmS465ArCKfAtxirpx6nFRl3Fn22NodQsMmo2ZGAKvCnzLa/j+nqr6qwvbWsNH7MWOZ SGcHZfATcmFjx7zbbTslmh+TFJoANsDDwQ+rLaS3fCOqsYq7uJBKAjx9S8gHc5KgIQBzkSs1RP Gfx+ZDn6eBOK9uQFcfGComUn Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:28:25 -0700 IronPort-SDR: A3KuAPb39dMfnQnL/KpZNdd0sU1ssBM+KoNeolY5F9RgA1YbfJTx5ZuUy3T/uSgUAw+IroHw5m ZqJHKxA5wQtsT711jHR2Xyxim/QHEpKrvuGNQ3mDdT9Hgrlf1O/UhnQBdBPBJeloq7Q2yqiyba gH3jjsNVXW3wCWLLzUQxmVjymL16xApInS0NbtMwAzDP6l9skfarbNHt0KG6cyGtEjEJuNmwd+ L8JuIozuA0StVz7dXginFTdj1vCfotRlGEpmymhHEvVY53YuBHWlAA/ah3d5NsVznt9RJFP2yZ G2M= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:51:36 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 04/12] scsi: ufshpb: Add reads counter Date: Mon, 12 Jul 2021 12:50:31 +0300 Message-Id: <20210712095039.8093-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In host control mode, reads are the major source of activation trials. Keep track of those reads counters, for both active as well inactive regions. We reset the read counter upon write - we are only interested in "clean" reads. Keep those counters normalized, as we are using those reads as a comparative score, to make various decisions. If during consecutive normalizations an active region has exhaust its reads - inactivate it. while at it, protect the {active,inactive}_count stats by adding them into the applicable handler. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 94 ++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufshpb.h | 9 ++++ 2 files changed, 97 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 3663f427dff6..d46235527fba 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -16,6 +16,8 @@ #include "ufshpb.h" #include "../sd.h" +#define ACTIVATION_THRESHOLD 8 /* 8 IOs */ + /* memory management */ static struct kmem_cache *ufshpb_mctx_cache; static mempool_t *ufshpb_mctx_pool; @@ -26,6 +28,9 @@ static int tot_active_srgn_pages; static struct workqueue_struct *ufshpb_wq; +static void ufshpb_update_active_info(struct ufshpb_lu *hpb, int rgn_idx, + int srgn_idx); + bool ufshpb_is_allowed(struct ufs_hba *hba) { return !(hba->ufshpb_dev.hpb_disabled); @@ -149,7 +154,7 @@ static void ufshpb_iterate_rgn(struct ufshpb_lu *hpb, int rgn_idx, int srgn_idx, int srgn_offset, int cnt, bool set_dirty) { struct ufshpb_region *rgn; - struct ufshpb_subregion *srgn; + struct ufshpb_subregion *srgn, *prev_srgn = NULL; int set_bit_len; int bitmap_len; unsigned long flags; @@ -168,15 +173,39 @@ static void ufshpb_iterate_rgn(struct ufshpb_lu *hpb, int rgn_idx, int srgn_idx, else set_bit_len = cnt; - if (set_dirty) - set_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); - spin_lock_irqsave(&hpb->rgn_state_lock, flags); if (set_dirty && rgn->rgn_state != HPB_RGN_INACTIVE && srgn->srgn_state == HPB_SRGN_VALID) bitmap_set(srgn->mctx->ppn_dirty, srgn_offset, set_bit_len); spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + if (hpb->is_hcm && prev_srgn != srgn) { + bool activate = false; + + spin_lock(&rgn->rgn_lock); + if (set_dirty) { + rgn->reads -= srgn->reads; + srgn->reads = 0; + set_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); + } else { + srgn->reads++; + rgn->reads++; + if (srgn->reads == ACTIVATION_THRESHOLD) + activate = true; + } + spin_unlock(&rgn->rgn_lock); + + if (activate) { + spin_lock_irqsave(&hpb->rsp_list_lock, flags); + ufshpb_update_active_info(hpb, rgn_idx, srgn_idx); + spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); + dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, + "activate region %d-%d\n", rgn_idx, srgn_idx); + } + + prev_srgn = srgn; + } + srgn_offset = 0; if (++srgn_idx == hpb->srgns_per_rgn) { srgn_idx = 0; @@ -605,6 +634,19 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) WARN_ON_ONCE(transfer_len > HPB_MULTI_CHUNK_HIGH); + if (hpb->is_hcm) { + /* + * in host control mode, reads are the main source for + * activation trials. + */ + ufshpb_iterate_rgn(hpb, rgn_idx, srgn_idx, srgn_offset, + transfer_len, false); + + /* keep those counters normalized */ + if (rgn->reads > hpb->entries_per_srgn) + schedule_work(&hpb->ufshpb_normalization_work); + } + spin_lock_irqsave(&hpb->rgn_state_lock, flags); if (ufshpb_test_ppn_dirty(hpb, rgn_idx, srgn_idx, srgn_offset, transfer_len)) { @@ -756,6 +798,8 @@ static void ufshpb_update_active_info(struct ufshpb_lu *hpb, int rgn_idx, if (list_empty(&srgn->list_act_srgn)) list_add_tail(&srgn->list_act_srgn, &hpb->lh_act_srgn); + + hpb->stats.rb_active_cnt++; } static void ufshpb_update_inactive_info(struct ufshpb_lu *hpb, int rgn_idx) @@ -771,6 +815,8 @@ static void ufshpb_update_inactive_info(struct ufshpb_lu *hpb, int rgn_idx) if (list_empty(&rgn->list_inact_rgn)) list_add_tail(&rgn->list_inact_rgn, &hpb->lh_inact_rgn); + + hpb->stats.rb_inactive_cnt++; } static void ufshpb_activate_subregion(struct ufshpb_lu *hpb, @@ -1084,6 +1130,7 @@ static int ufshpb_evict_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) rgn->rgn_idx); goto out; } + if (!list_empty(&rgn->list_lru_rgn)) { if (ufshpb_check_srgns_issue_state(hpb, rgn)) { ret = -EBUSY; @@ -1278,7 +1325,6 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, if (srgn->srgn_state == HPB_SRGN_VALID) srgn->srgn_state = HPB_SRGN_INVALID; spin_unlock(&hpb->rgn_state_lock); - hpb->stats.rb_active_cnt++; } if (hpb->is_hcm) { @@ -1310,7 +1356,6 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, } spin_unlock(&hpb->rgn_state_lock); - hpb->stats.rb_inactive_cnt++; } out: @@ -1509,6 +1554,36 @@ static void ufshpb_run_inactive_region_list(struct ufshpb_lu *hpb) spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); } +static void ufshpb_normalization_work_handler(struct work_struct *work) +{ + struct ufshpb_lu *hpb = container_of(work, struct ufshpb_lu, + ufshpb_normalization_work); + int rgn_idx; + + for (rgn_idx = 0; rgn_idx < hpb->rgns_per_lu; rgn_idx++) { + struct ufshpb_region *rgn = hpb->rgn_tbl + rgn_idx; + int srgn_idx; + + spin_lock(&rgn->rgn_lock); + rgn->reads = 0; + for (srgn_idx = 0; srgn_idx < hpb->srgns_per_rgn; srgn_idx++) { + struct ufshpb_subregion *srgn = rgn->srgn_tbl + srgn_idx; + + srgn->reads >>= 1; + rgn->reads += srgn->reads; + } + spin_unlock(&rgn->rgn_lock); + + if (rgn->rgn_state != HPB_RGN_ACTIVE || rgn->reads) + continue; + + /* if region is active but has no reads - inactivate it */ + spin_lock(&hpb->rsp_list_lock); + ufshpb_update_inactive_info(hpb, rgn->rgn_idx); + spin_unlock(&hpb->rsp_list_lock); + } +} + static void ufshpb_map_work_handler(struct work_struct *work) { struct ufshpb_lu *hpb = container_of(work, struct ufshpb_lu, map_work); @@ -1667,6 +1742,8 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) rgn = rgn_table + rgn_idx; rgn->rgn_idx = rgn_idx; + spin_lock_init(&rgn->rgn_lock); + INIT_LIST_HEAD(&rgn->list_inact_rgn); INIT_LIST_HEAD(&rgn->list_lru_rgn); @@ -1908,6 +1985,9 @@ static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) INIT_LIST_HEAD(&hpb->list_hpb_lu); INIT_WORK(&hpb->map_work, ufshpb_map_work_handler); + if (hpb->is_hcm) + INIT_WORK(&hpb->ufshpb_normalization_work, + ufshpb_normalization_work_handler); hpb->map_req_cache = kmem_cache_create("ufshpb_req_cache", sizeof(struct ufshpb_req), 0, 0, NULL); @@ -2007,6 +2087,8 @@ static void ufshpb_discard_rsp_lists(struct ufshpb_lu *hpb) static void ufshpb_cancel_jobs(struct ufshpb_lu *hpb) { + if (hpb->is_hcm) + cancel_work_sync(&hpb->ufshpb_normalization_work); cancel_work_sync(&hpb->map_work); } diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index 9ab502f82835..33d163e76d41 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -106,6 +106,10 @@ struct ufshpb_subregion { int rgn_idx; int srgn_idx; bool is_last; + + /* subregion reads - for host mode */ + unsigned int reads; + /* below information is used by rsp_list */ struct list_head list_act_srgn; }; @@ -123,6 +127,10 @@ struct ufshpb_region { struct list_head list_lru_rgn; unsigned long rgn_flags; #define RGN_FLAG_DIRTY 0 + + /* region reads - for host mode */ + spinlock_t rgn_lock; + unsigned int reads; }; #define for_each_sub_region(rgn, i, srgn) \ @@ -212,6 +220,7 @@ struct ufshpb_lu { /* for selecting victim */ struct victim_select_info lru_info; + struct work_struct ufshpb_normalization_work; /* pinned region information */ u32 lu_pinned_start; From patchwork Mon Jul 12 09:50:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 473286 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEBFAC07E99 for ; Mon, 12 Jul 2021 09:51:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B106D6108B for ; Mon, 12 Jul 2021 09:51:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238281AbhGLJyl (ORCPT ); Mon, 12 Jul 2021 05:54:41 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:11512 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241227AbhGLJyh (ORCPT ); Mon, 12 Jul 2021 05:54:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083509; x=1657619509; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+jnu3rPm16B/c8+fawe4fAuduxrSSeqJoz2Pler85XM=; b=MGw2PwnqSpOJ4+4/d8jtjRHhlORx8enz5sKJb61a9Cfh2HD3L4EgpKGX PMxTN3OYYGu3yAgb+r6qsBzVWWcIOn/d2yx+crBOLFgpn9YG3xNbUZV98 M2ghmqwAiYj4T4ImBLkuTS7eXsH3Xm9TDjRFcD23pZ2zaDd7Kjq4GcraA Le4JD7KViOYST4qE469XjOGJVW2XhLtNBMnnuUailq1tVraOt6Woe5f0Y BwSM0b6me1vO459/z6BoQ5qKNlj3Zf/VcwLIbF/idYzjc7VZwehdWNHdb iEkPMayG6fYM2AReOAdyrvtEDN/pxbZXjVf4Xn3bHOAI+NYVJwFvmrAl5 A==; IronPort-SDR: TqkdiG/y+4lQM+JrKQN2eC60gKsw0KWSEEe1DRGj5Led+SYKIkd+/pa8kP0n45rJYqCdepITgi CyTKD0rMFr757digjlqiEozYt4xOayuVb/McHBH3rqoBcyfkUCNkF8ezS/Zx+6jZSPThs05iqV CFG5RN9zD++XI8TT4TfmuudU6GL2y01vPqwzq+U1o+nylpstHVDxrzEWFpNLSIzSRO16sFyzoC STT9qhdttFty3HFykIjAg3QhmYBrSVQ02a2mMS5OeUAA3gbWPNCLK9MqnU7uBl4/Sg+3cl0SrP MN0= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="174347121" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:51:49 +0800 IronPort-SDR: 3nBGYT7niz3YGn6oyDnaNzz//Pqv85nNa5hOjtsphHkjsJWLbzMBVVVb3LOilpEPQLpB9WRUpd D5Pm5hD0ySfcJWzz4AtEEXqFO52W2d46Y7fUpx8B/dzDt+TjW/fCU7CNd6yiYuLOYsYjxzpGCZ WJ8pzMzLE28ZPbybKg5hGoTdxRQUmSNdRog8Ys4MCgPQ/oV8YzVDRJVnD4ZYamAP5kYODGR+Qk MNUdotiRQDnL/IpI52T8/Yi0ISANZb42iwMaJDiZIAi8WLlD3qgCM/Q992+sYeMnwZps+t304V OijKIbgi9NbTfeAL0SqQuV4R Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:29:56 -0700 IronPort-SDR: tAgKDsFpocX6bue0/yacPL5zed/3JyNfxse9ghYi9Wag7/IFoFyzgB1d5vHDtw4KfZFHbk5J+M jYlfJD40Q3Gq9Fsl44kCL2B4CXKPW6zxMdsznMrZpj1nkAPltU4xgd+UbM8T638L0HbKot+xk5 HTsQQuA35YF6/6btgwav+VyfUNwV7ZpIA2oUCX9SJmqbjz2CF0XDyeYsWkInjkaJhXxOwjVwqJ nylgL3bLQ7D5Er1RvaaEimBoeq8tGK73DjVMj7loHVPGnbZ+olAraETznw+6HOuWyyso8PxtD5 j7I= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:51:45 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 05/12] scsi: ufshpb: Make eviction depends on region's reads Date: Mon, 12 Jul 2021 12:50:32 +0300 Message-Id: <20210712095039.8093-6-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In host mode, eviction is considered an extreme measure. verify that the entering region has enough reads, and the exiting region has much less reads. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index d46235527fba..1eadfc12b6a7 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -17,6 +17,7 @@ #include "../sd.h" #define ACTIVATION_THRESHOLD 8 /* 8 IOs */ +#define EVICTION_THRESHOLD (ACTIVATION_THRESHOLD << 5) /* 256 IOs */ /* memory management */ static struct kmem_cache *ufshpb_mctx_cache; @@ -1056,6 +1057,13 @@ static struct ufshpb_region *ufshpb_victim_lru_info(struct ufshpb_lu *hpb) if (ufshpb_check_srgns_issue_state(hpb, rgn)) continue; + /* + * in host control mode, verify that the exiting region + * has less reads + */ + if (hpb->is_hcm && rgn->reads > (EVICTION_THRESHOLD >> 1)) + continue; + victim_rgn = rgn; break; } @@ -1223,7 +1231,7 @@ static int ufshpb_issue_map_req(struct ufshpb_lu *hpb, static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) { - struct ufshpb_region *victim_rgn; + struct ufshpb_region *victim_rgn = NULL; struct victim_select_info *lru_info = &hpb->lru_info; unsigned long flags; int ret = 0; @@ -1250,7 +1258,15 @@ static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) * It is okay to evict the least recently used region, * because the device could detect this region * by not issuing HPB_READ + * + * in host control mode, verify that the entering + * region has enough reads */ + if (hpb->is_hcm && rgn->reads < EVICTION_THRESHOLD) { + ret = -EACCES; + goto out; + } + victim_rgn = ufshpb_victim_lru_info(hpb); if (!victim_rgn) { dev_warn(&hpb->sdev_ufs_lu->sdev_dev, From patchwork Mon Jul 12 09:50:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 474979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9C2AC07E99 for ; Mon, 12 Jul 2021 09:52:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD68B610CB for ; Mon, 12 Jul 2021 09:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241316AbhGLJyt (ORCPT ); Mon, 12 Jul 2021 05:54:49 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:32809 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241285AbhGLJyp (ORCPT ); Mon, 12 Jul 2021 05:54:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083518; x=1657619518; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OYn10sGIjvUeP/VOinw0S9ZPw0l5lGzPAWp1xmE7ti8=; b=HEfH1AzX0Km0sQ33hjK7/iHF/vUZlWi1e0I1dxBR1ZBdsuDp1cnJjNex bZyJ1YWF45cX8ZrLEWiAGyqUbIGFTRjySxM/uD0l9rs0RqlrOPtCK/wDq B8UMxcsN8yLQ+JyHYBUDdTfHQwopHcLEUPs8bdO3wWPmtvjlFQhM3qiz+ 2ocY90f9xSPVPdS2F6BfR9323JsT/2jT2ofEJcgKbZt61KUJjrdnlnPPn 8iGScA1+unzhlE1GtI/3QnujiHMSIKEuNKYiPbEooc47g0/Un4i5PlzJZ tndeElpArjwVyxVPeecxHR5+mjM6HJTo7elrZYVLIA1Burl7o4adPN4CQ w==; IronPort-SDR: 2ycqrcX/3xRFGHoxv2znYDoV8Tant6ecJCNmripqiEAyBmU5mvVsNZlP2+uME45x4cHW9EBFoQ 7y03CgpzwfwqIAIRMo9wltVL+3mrITVeTcxo9DaDFQRvlk4GdutjLkEi7W+UTrSPvFe0T3rgIS SHroSkDN7uetYj2N2QIjkHroclI1k0GgNKk5vfpzRGZLUx4XxS716mxDMcmcifUeWBs8JxMBaQ keAKeQ7ZwUY8PgCYVnfT93bHWvOTaTKu6WwG5qgZrB+5xTHjUgNg3ErFj5JWqvDgMSq+AHX7nk 11s= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="174920201" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:51:57 +0800 IronPort-SDR: Y/oe6eMbhBEb55P/NpCns6E6b3Sx+7jnGmo4irqmD/2XFrbzAYxSrTqK+xcO054nSDeefHr83j p3TD2V5kWQrgmgWlW9k6zlYDhpQYw8pPTEC7MWZBJLzR9PnPBRd8ZTIXTORjAUVxmnrql5esZ5 KaPzs8Wgbo1KjMelfr9OgoBObMXzuZfNCy93ykGF7nNqxpgU9xtsZ71vIl/fNjE3Lo5G+ze7sx YGgSzuhy05j/ywH0S5vq4EvEdxc8OAgUphZk1hmTsUtne0O4ZlSog6lXeFk/N4tjsrttIIdx22 HhGcObmw1wJOq6dMjSqjfbgh Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:30:04 -0700 IronPort-SDR: pIaf8R13+lBggPE2a4HPzjhM8UYXPkzazqjiNQtktrCm215Es6guBCTiqrNAMOj+alQnhmD9EL dMaNobQARn7STaa+9kUzs3OcDcP2+RK8/ehLO3uZHfIkm4IoirAP7J/yIirg5ImVmKwY2RZq7a lxCpp26tka1v2Blnbu2bW5I6oTsj0MnaYjvp7XS8jyt8hO11TL/uanuoC90D6cOlywU4ErBHn6 dXFUbOoUx8wH0ZhDINrub8fVqSrEOVxmtQEeDCyWlNXnnypnPNas3zpwyb4wv1CDZNJj/lPuDn jYs= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:51:53 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 06/12] scsi: ufshpb: Region inactivation in host mode Date: Mon, 12 Jul 2021 12:50:33 +0300 Message-Id: <20210712095039.8093-7-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In host mode, the host is expected to send HPB-WRITE-BUFFER with buffer-id = 0x1 when it inactivates a region. Use the map-requests pool as there is no point in assigning a designated cache for umap-requests. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 47 +++++++++++++++++++++++++++++++++------ drivers/scsi/ufs/ufshpb.h | 1 + 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 1eadfc12b6a7..7b48a9ab1534 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -692,7 +692,8 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) } static struct ufshpb_req *ufshpb_get_req(struct ufshpb_lu *hpb, - int rgn_idx, enum req_opf dir) + int rgn_idx, enum req_opf dir, + bool atomic) { struct ufshpb_req *rq; struct request *req; @@ -706,7 +707,7 @@ static struct ufshpb_req *ufshpb_get_req(struct ufshpb_lu *hpb, req = blk_get_request(hpb->sdev_ufs_lu->request_queue, dir, BLK_MQ_REQ_NOWAIT); - if ((PTR_ERR(req) == -EWOULDBLOCK) && (--retries > 0)) { + if (!atomic && (PTR_ERR(req) == -EWOULDBLOCK) && (--retries > 0)) { usleep_range(3000, 3100); goto retry; } @@ -737,7 +738,7 @@ static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb, struct ufshpb_req *map_req; struct bio *bio; - map_req = ufshpb_get_req(hpb, srgn->rgn_idx, REQ_OP_SCSI_IN); + map_req = ufshpb_get_req(hpb, srgn->rgn_idx, REQ_OP_SCSI_IN, false); if (!map_req) return NULL; @@ -914,6 +915,8 @@ static void ufshpb_execute_umap_req(struct ufshpb_lu *hpb, rq->cmd_len = HPB_WRITE_BUFFER_CMD_LENGTH; blk_execute_rq_nowait(NULL, req, 1, ufshpb_umap_req_compl_fn); + + hpb->stats.umap_req_cnt++; } static int ufshpb_execute_map_req(struct ufshpb_lu *hpb, @@ -1090,12 +1093,13 @@ static void ufshpb_purge_active_subregion(struct ufshpb_lu *hpb, } static int ufshpb_issue_umap_req(struct ufshpb_lu *hpb, - struct ufshpb_region *rgn) + struct ufshpb_region *rgn, + bool atomic) { struct ufshpb_req *umap_req; int rgn_idx = rgn ? rgn->rgn_idx : 0; - umap_req = ufshpb_get_req(hpb, rgn_idx, REQ_OP_SCSI_OUT); + umap_req = ufshpb_get_req(hpb, rgn_idx, REQ_OP_SCSI_OUT, atomic); if (!umap_req) return -ENOMEM; @@ -1104,13 +1108,19 @@ static int ufshpb_issue_umap_req(struct ufshpb_lu *hpb, return 0; } +static int ufshpb_issue_umap_single_req(struct ufshpb_lu *hpb, + struct ufshpb_region *rgn) +{ + return ufshpb_issue_umap_req(hpb, rgn, true); +} + static int ufshpb_issue_umap_all_req(struct ufshpb_lu *hpb) { - return ufshpb_issue_umap_req(hpb, NULL); + return ufshpb_issue_umap_req(hpb, NULL, false); } static void __ufshpb_evict_region(struct ufshpb_lu *hpb, - struct ufshpb_region *rgn) + struct ufshpb_region *rgn) { struct victim_select_info *lru_info; struct ufshpb_subregion *srgn; @@ -1145,6 +1155,14 @@ static int ufshpb_evict_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) goto out; } + if (hpb->is_hcm) { + spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + ret = ufshpb_issue_umap_single_req(hpb, rgn); + spin_lock_irqsave(&hpb->rgn_state_lock, flags); + if (ret) + goto out; + } + __ufshpb_evict_region(hpb, rgn); } out: @@ -1279,6 +1297,18 @@ static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) "LRU full (%d), choose victim %d\n", atomic_read(&lru_info->active_cnt), victim_rgn->rgn_idx); + + if (hpb->is_hcm) { + spin_unlock_irqrestore(&hpb->rgn_state_lock, + flags); + ret = ufshpb_issue_umap_single_req(hpb, + victim_rgn); + spin_lock_irqsave(&hpb->rgn_state_lock, + flags); + if (ret) + goto out; + } + __ufshpb_evict_region(hpb, victim_rgn); } @@ -1848,6 +1878,7 @@ ufshpb_sysfs_attr_show_func(rb_noti_cnt); ufshpb_sysfs_attr_show_func(rb_active_cnt); ufshpb_sysfs_attr_show_func(rb_inactive_cnt); ufshpb_sysfs_attr_show_func(map_req_cnt); +ufshpb_sysfs_attr_show_func(umap_req_cnt); static struct attribute *hpb_dev_stat_attrs[] = { &dev_attr_hit_cnt.attr, @@ -1856,6 +1887,7 @@ static struct attribute *hpb_dev_stat_attrs[] = { &dev_attr_rb_active_cnt.attr, &dev_attr_rb_inactive_cnt.attr, &dev_attr_map_req_cnt.attr, + &dev_attr_umap_req_cnt.attr, NULL, }; @@ -1981,6 +2013,7 @@ static void ufshpb_stat_init(struct ufshpb_lu *hpb) hpb->stats.rb_active_cnt = 0; hpb->stats.rb_inactive_cnt = 0; hpb->stats.map_req_cnt = 0; + hpb->stats.umap_req_cnt = 0; } static void ufshpb_param_init(struct ufshpb_lu *hpb) diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index 33d163e76d41..0204e4fec6bc 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -191,6 +191,7 @@ struct ufshpb_stats { u64 rb_inactive_cnt; u64 map_req_cnt; u64 pre_req_cnt; + u64 umap_req_cnt; }; struct ufshpb_lu { From patchwork Mon Jul 12 09:50:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 473285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C43D0C07E99 for ; Mon, 12 Jul 2021 09:52:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE0BF610E6 for ; Mon, 12 Jul 2021 09:52:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241395AbhGLJy6 (ORCPT ); Mon, 12 Jul 2021 05:54:58 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:38088 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238441AbhGLJy4 (ORCPT ); Mon, 12 Jul 2021 05:54:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083527; x=1657619527; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ONFhG70nHN8i1/Ll5W+qGDPxvqrDNBO3fKKi64/sBIo=; b=JzpW0Bgmk1bjCJS3vTfMYIoYr5syGCzcg7WcgHhd/4jfyxtg7ktWhqIo dZv91OaZXyypuVxwegmN6BPTppk4UuQ6XmEVHtj+QPCaoERg2/vmm931Q KT15mMDnSjss5LStIkiQkHDsw/2IwywIyjxrddiknF/2D/mSv4HoAe80t 9+aNVL836+AJO8Bxf0vVzx7PeiXZtutXOOW6FSSHGHkCRqrCdPjgjo42C u8RIs2XlJWENLDRSf89v9jk28qvQzDAe9bmNFznols4Slw81PEgRX4+IM gZH6epkGzcnpfrIoHtO1So7LcutMhZgSURwtR7AqKEb1Gl0eRJ5QitFrR A==; IronPort-SDR: tILLnrbJimE5Q6h0KQ1UfpPhmA8bVwE3Sfr1mdIQllGewPEf0v+d9V+hq6rbxTVsHbzxvPIr0q Wv8v7JsFWjd0SMBe3VsZrVYj0TyJ97RAkJ8IrFe/z7Sw1v2KcYCkh5LmNE5zY3x7VGHDBzl4h6 0hrKcUmoSexmrhvEtngYNtb+2S7GYzAhRzTBMsYsi+MzyjJT4id6SOwk4nbejWZ8/WFqf9QR0X zFhTvx3xzWQb3nhWWtgLArMOsqsySFcYEEjEc6Ide3JshxJqUWsi8OkM5y67RuKem7yTQogrJz mpk= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="179153737" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:52:06 +0800 IronPort-SDR: +mYSENp7hen1SPbNIrT/cCVvCglCURfvz2u7r2Uh5znaoCIHhaf1b/1hi9WiGYufyNKnt2l9Y4 SXYtA7ki2tVxjRkhH9g9UzKXIzBkIwxp8gjY0GF7ctczIzzwy0ajeNa+PFJ+KY7hGfL/5SVJJY ESN/pqTs4Scsgjc8kfGg3YJkuVJvyspxUDRLu5msqi0vVDiJxDYVp4Z2mdQuE3nDbCoLMRtOHG hIUH6FNghB+T6ZN/QyDNU47e2XlAfhlw9RENws9jSJS7n73ciggZD7dVxIQE7On78KzTbAZGC2 Jh4/ogV2iIwhEyubtJH+mJ9T Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:30:13 -0700 IronPort-SDR: wkZW2gjRVxDNjrYqJZqyrndvZMO2Dmxgy6kqSYMyHUXtUfTz3dzONCoUfusY1sPXeQ7Qjiwdlm S4hVf+WDXjQZSd5zHTUCPU22rIzfSstcqvO4uSDUbzQF8zrx2HnN3kfuKMVyMnDIST+76mn5Vg QF9/BKmbtWjPEjF/YzGzWvfPpSGeYIIBcwvGibpK2r39zqL7ZnsMugwiofZW9Q3fbkanyyijap WnVixTcxInRu/qnSPj4P3T1E56YyER9gn81XXbyyy7eiBwd51Dydwg0q4pbagUr3F8LTo7YY9I +QE= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:52:02 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 07/12] scsi: ufshpb: Add hpb dev reset response Date: Mon, 12 Jul 2021 12:50:34 +0300 Message-Id: <20210712095039.8093-8-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The spec does not define what is the host's recommended response when the device send hpb dev reset response (oper 0x2). We will update all active hpb regions: mark them and do that on the next read. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 32 +++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshpb.h | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 7b48a9ab1534..5b473f1800ca 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -196,7 +196,8 @@ static void ufshpb_iterate_rgn(struct ufshpb_lu *hpb, int rgn_idx, int srgn_idx, } spin_unlock(&rgn->rgn_lock); - if (activate) { + if (activate || + test_and_clear_bit(RGN_FLAG_UPDATE, &rgn->rgn_flags)) { spin_lock_irqsave(&hpb->rsp_list_lock, flags); ufshpb_update_active_info(hpb, rgn_idx, srgn_idx); spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); @@ -1412,6 +1413,20 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, queue_work(ufshpb_wq, &hpb->map_work); } +static void ufshpb_dev_reset_handler(struct ufshpb_lu *hpb) +{ + struct victim_select_info *lru_info = &hpb->lru_info; + struct ufshpb_region *rgn; + unsigned long flags; + + spin_lock_irqsave(&hpb->rgn_state_lock, flags); + + list_for_each_entry(rgn, &lru_info->lh_lru_rgn, list_lru_rgn) + set_bit(RGN_FLAG_UPDATE, &rgn->rgn_flags); + + spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); +} + /* * This function will parse recommended active subregion information in sense * data field of response UPIU with SAM_STAT_GOOD state. @@ -1486,6 +1501,18 @@ void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) case HPB_RSP_DEV_RESET: dev_warn(&hpb->sdev_ufs_lu->sdev_dev, "UFS device lost HPB information during PM.\n"); + + if (hpb->is_hcm) { + struct scsi_device *sdev; + + __shost_for_each_device(sdev, hba->host) { + struct ufshpb_lu *h = sdev->hostdata; + + if (h) + ufshpb_dev_reset_handler(h); + } + } + break; default: dev_notice(&hpb->sdev_ufs_lu->sdev_dev, @@ -1811,6 +1838,8 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) } else { rgn->rgn_state = HPB_RGN_INACTIVE; } + + rgn->rgn_flags = 0; } return 0; @@ -2138,6 +2167,7 @@ static void ufshpb_cancel_jobs(struct ufshpb_lu *hpb) { if (hpb->is_hcm) cancel_work_sync(&hpb->ufshpb_normalization_work); + cancel_work_sync(&hpb->map_work); } diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index 0204e4fec6bc..43a95c670763 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -127,6 +127,7 @@ struct ufshpb_region { struct list_head list_lru_rgn; unsigned long rgn_flags; #define RGN_FLAG_DIRTY 0 +#define RGN_FLAG_UPDATE 1 /* region reads - for host mode */ spinlock_t rgn_lock; From patchwork Mon Jul 12 09:50:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 474978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED43FC07E99 for ; Mon, 12 Jul 2021 09:52:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D73ED6108B for ; Mon, 12 Jul 2021 09:52:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232112AbhGLJzN (ORCPT ); Mon, 12 Jul 2021 05:55:13 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:11598 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238441AbhGLJzH (ORCPT ); Mon, 12 Jul 2021 05:55:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083540; x=1657619540; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U+bcC9eJ4FUHT74sI1IojB2NK7qiWkn2B+w5FhZE+3U=; b=k3Muw7dLTm9xA+PjnLFUb9fNnuwq1MHvShzR3awtOM037Om9VspVMPSa 743PZO74nhw70BBW6+vGPUcVgMrK9FQa2eA2OCOgv9HssCHzm8mVBuWRJ K0j3yKWgKHv6VlE4kHqdTNHDYVIpwbGrDWjBDbtozgsDjhDif9QhpU0xQ Rv8om2nJgDm2tbNJIrPf8Xw1YbJI8wQNgRPosuzW1fLunv7A6nlZ730MC GLVNVY914kulxrhfUbl8B0qGU65CQzSnG5q8bsDMYrJLkuBh+51mtOx7x hyQAqGMDnfMdsS1APv4hCo0jQIhrNiB7lfsOJMyoh58xs412RQ2XlArWA w==; IronPort-SDR: Dj+h3NesC/L97gSqFBwJ4e/SAvPaflFTJJHxxuqWby8ibS5AARP/swVpyRf4Jwl7uudGz12pwo 3cyLpKCsUdog8C3EH+7aOqxyzVAkPXVe1iFHOhmXBYqzgBG8RtxGH0ci5xsywCW2LVUxdZM4Jt 7zJIEUnYyAvbqvzuH4pn3mgzSCwfND7HDMfHFTqTSigSx9thJuqHO/zK91W1FavZ7gxVzsE18v V/wa5pt4sbm/rU4qlVBqZftbYgVm1M++bTWgH4DEDEQtRxta+nwFyydzhjtx4+AuTNLdMNjV7r wCw= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="285877111" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:52:13 +0800 IronPort-SDR: e0SUiX11wu2Pw3W9laJWl7ki1VwRPQKK/Ah/2U8m/DDLWmcM8XVCtQBvGS7P5oRcnoin4r92Iv opvi0idOtkjyfr46dM0f41fNjmvDH6R00q3vDhYuaWc6u7dkxgk5Z+zYjRqqlnNJlU9omoc03F 7Ilrhq93ZzK6Uw+Aoov/7W404ITj0gXPuffEcBOC0xl/0zxkr0dgw5wknDdU+kKVTuwAXDFYiy Kkk8m4NMOTY2SVGo8Ja74Us0B9nUG/dIXi2dLcxyDC7TtUdyzhzd+6w+Z8+K/oUl//djhXPxi0 U4hWlk5bsFX4eSwo7HkixXxB Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:30:20 -0700 IronPort-SDR: ikGPAzO0XS6zGjpRTav5qBFeI+FqJA/wqqoFN1b2+DW+pQzY5WXCvCBkcrn8ZdYVRgnnSG6I87 8nZ8CxLi69jMogZYwIjUog6b6cqHu1Jl74mC+ihUkU7ZpnxowLhVMsAFA3+S+NuwKzeKpuW0Ia eP74+oUfeGx6m8rGNzw3wuEN9Xs4wyVK4sD+1lVfEm015h+ggZaT3yBhAM6vBU/gRSGIDMQjl5 CGyni9cMAtj80TPuW4EBh5clMm/P5uFHvklK8dbKwzpouerZ4TqbjfZOLtVZUrbd3Qxh/H/zW5 db4= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:52:09 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 08/12] scsi: ufshpb: Add "Cold" regions timer Date: Mon, 12 Jul 2021 12:50:35 +0300 Message-Id: <20210712095039.8093-9-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In order not to hang on to “cold” regions, we shall inactivate a region that has no READ access for a predefined amount of time - READ_TO_MS. For that purpose we shall monitor the active regions list, polling it on every POLLING_INTERVAL_MS. On timeout expiry we shall add the region to the "to-be-inactivated" list, unless it is clean and did not exhaust its READ_TO_EXPIRIES - another parameter. All this does not apply to pinned regions. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 74 +++++++++++++++++++++++++++++++++++++-- drivers/scsi/ufs/ufshpb.h | 8 +++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 5b473f1800ca..4138f081d1dc 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -18,6 +18,9 @@ #define ACTIVATION_THRESHOLD 8 /* 8 IOs */ #define EVICTION_THRESHOLD (ACTIVATION_THRESHOLD << 5) /* 256 IOs */ +#define READ_TO_MS 1000 +#define READ_TO_EXPIRIES 100 +#define POLLING_INTERVAL_MS 200 /* memory management */ static struct kmem_cache *ufshpb_mctx_cache; @@ -1032,12 +1035,63 @@ static int ufshpb_check_srgns_issue_state(struct ufshpb_lu *hpb, return 0; } +static void ufshpb_read_to_handler(struct work_struct *work) +{ + struct ufshpb_lu *hpb = container_of(work, struct ufshpb_lu, + ufshpb_read_to_work.work); + struct victim_select_info *lru_info = &hpb->lru_info; + struct ufshpb_region *rgn, *next_rgn; + unsigned long flags; + LIST_HEAD(expired_list); + + if (test_and_set_bit(TIMEOUT_WORK_RUNNING, &hpb->work_data_bits)) + return; + + spin_lock_irqsave(&hpb->rgn_state_lock, flags); + + list_for_each_entry_safe(rgn, next_rgn, &lru_info->lh_lru_rgn, + list_lru_rgn) { + bool timedout = ktime_after(ktime_get(), rgn->read_timeout); + + if (timedout) { + rgn->read_timeout_expiries--; + if (is_rgn_dirty(rgn) || + rgn->read_timeout_expiries == 0) + list_add(&rgn->list_expired_rgn, &expired_list); + else + rgn->read_timeout = ktime_add_ms(ktime_get(), + READ_TO_MS); + } + } + + spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + + list_for_each_entry_safe(rgn, next_rgn, &expired_list, + list_expired_rgn) { + list_del_init(&rgn->list_expired_rgn); + spin_lock_irqsave(&hpb->rsp_list_lock, flags); + ufshpb_update_inactive_info(hpb, rgn->rgn_idx); + spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); + } + + ufshpb_kick_map_work(hpb); + + clear_bit(TIMEOUT_WORK_RUNNING, &hpb->work_data_bits); + + schedule_delayed_work(&hpb->ufshpb_read_to_work, + msecs_to_jiffies(POLLING_INTERVAL_MS)); +} + static void ufshpb_add_lru_info(struct victim_select_info *lru_info, struct ufshpb_region *rgn) { rgn->rgn_state = HPB_RGN_ACTIVE; list_add_tail(&rgn->list_lru_rgn, &lru_info->lh_lru_rgn); atomic_inc(&lru_info->active_cnt); + if (rgn->hpb->is_hcm) { + rgn->read_timeout = ktime_add_ms(ktime_get(), READ_TO_MS); + rgn->read_timeout_expiries = READ_TO_EXPIRIES; + } } static void ufshpb_hit_lru_info(struct victim_select_info *lru_info, @@ -1819,6 +1873,7 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) INIT_LIST_HEAD(&rgn->list_inact_rgn); INIT_LIST_HEAD(&rgn->list_lru_rgn); + INIT_LIST_HEAD(&rgn->list_expired_rgn); if (rgn_idx == hpb->rgns_per_lu - 1) { srgn_cnt = ((hpb->srgns_per_lu - 1) % @@ -1840,6 +1895,7 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) } rgn->rgn_flags = 0; + rgn->hpb = hpb; } return 0; @@ -2063,9 +2119,12 @@ static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) INIT_LIST_HEAD(&hpb->list_hpb_lu); INIT_WORK(&hpb->map_work, ufshpb_map_work_handler); - if (hpb->is_hcm) + if (hpb->is_hcm) { INIT_WORK(&hpb->ufshpb_normalization_work, ufshpb_normalization_work_handler); + INIT_DELAYED_WORK(&hpb->ufshpb_read_to_work, + ufshpb_read_to_handler); + } hpb->map_req_cache = kmem_cache_create("ufshpb_req_cache", sizeof(struct ufshpb_req), 0, 0, NULL); @@ -2099,6 +2158,10 @@ static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) ufshpb_stat_init(hpb); ufshpb_param_init(hpb); + if (hpb->is_hcm) + schedule_delayed_work(&hpb->ufshpb_read_to_work, + msecs_to_jiffies(POLLING_INTERVAL_MS)); + return 0; release_pre_req_mempool: @@ -2165,9 +2228,10 @@ static void ufshpb_discard_rsp_lists(struct ufshpb_lu *hpb) static void ufshpb_cancel_jobs(struct ufshpb_lu *hpb) { - if (hpb->is_hcm) + if (hpb->is_hcm) { + cancel_delayed_work_sync(&hpb->ufshpb_read_to_work); cancel_work_sync(&hpb->ufshpb_normalization_work); - + } cancel_work_sync(&hpb->map_work); } @@ -2275,6 +2339,10 @@ void ufshpb_resume(struct ufs_hba *hba) continue; ufshpb_set_state(hpb, HPB_PRESENT); ufshpb_kick_map_work(hpb); + if (hpb->is_hcm) + schedule_delayed_work(&hpb->ufshpb_read_to_work, + msecs_to_jiffies(POLLING_INTERVAL_MS)); + } } diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index 43a95c670763..8309b59c7819 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -115,6 +115,7 @@ struct ufshpb_subregion { }; struct ufshpb_region { + struct ufshpb_lu *hpb; struct ufshpb_subregion *srgn_tbl; enum HPB_RGN_STATE rgn_state; int rgn_idx; @@ -132,6 +133,10 @@ struct ufshpb_region { /* region reads - for host mode */ spinlock_t rgn_lock; unsigned int reads; + /* region "cold" timer - for host mode */ + ktime_t read_timeout; + unsigned int read_timeout_expiries; + struct list_head list_expired_rgn; }; #define for_each_sub_region(rgn, i, srgn) \ @@ -223,6 +228,9 @@ struct ufshpb_lu { /* for selecting victim */ struct victim_select_info lru_info; struct work_struct ufshpb_normalization_work; + struct delayed_work ufshpb_read_to_work; + unsigned long work_data_bits; +#define TIMEOUT_WORK_RUNNING 0 /* pinned region information */ u32 lu_pinned_start; From patchwork Mon Jul 12 09:50:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 473284 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF9D2C07E9C for ; Mon, 12 Jul 2021 09:52:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB08F610D2 for ; Mon, 12 Jul 2021 09:52:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237887AbhGLJzO (ORCPT ); Mon, 12 Jul 2021 05:55:14 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:33186 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237071AbhGLJzM (ORCPT ); Mon, 12 Jul 2021 05:55:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083545; x=1657619545; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jObncAsp+JMdQEIeZYaXSS1wRDtUP2PUPeJ34o4VIXc=; b=Og0hydJA+GYbrkIzn84agZ6wjWsemlZydLq7aO19TGy0C87wpNPN6Ivq zC1RLtt/y3QOMg3EPr5TVZGuQ31LQBwCoHRLs493YjlcbGmcZms1ngXS/ H109u98xclD5ToPUIz6QN/r/yuxqzSWkQ8mOGbpBZKbwDC/pM8rk18CNg Qc3ASXT9q5pwN7yRIZp8k9jJ3RuN+j3bKg648gEspMFsD+TTi+OcovKBM apNXIpdBfTfssDoeMgjuuAJUQ4MXsGFX5IOrt4Zrmd+KYargOfANPYR9q 9jkpoXbvnSaBiFAP747CLTkayj3MlvJTmt/qpJes3kVbgOnQBR3RxG6I8 Q==; IronPort-SDR: p7zr5Zd1XTwGvqH0hUKgYKtDidPC/fK2MazwRLDLSKemMGqe/VJIRwnLGemasRgQSiUWVUuT0O KvrNrt7wBvP/6Q29cT2Zw2rW6yTPHIGeJLkC74qjRoNqdM3rAtGgBI4ZMg21PrSLFkemaH6Jer o+cQQYpTr4Cdld1u1XR0FRv0PHvQMa+w7E1/oy9IJ1SnUK+ixlKL+q2dlViZ82eaIunlycRMCe gZcI8NBAz9gpyT9+ksf0hSDcA9GC90mQQnMSmzExnRdHjXo+Ixh1SZRGBXwRcy7bC7RI6Xv5qu 50A= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="278155980" 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; 12 Jul 2021 17:52:23 +0800 IronPort-SDR: PvGWsHkSrNFCzslH2B9CFpxQOFQvjLa2QbKsF5GP8GOu7Yx2nof5MCtUOVCitQDBbIh842k2b5 CM2QADRgJVBvTO6Qwm3oMtNVwt7yoTu97MmNExKhZ55HYUO1AZRCf8MCJIbxGpivjtX1x+/iPH mjCO5CyBgy21N0k6DHqlnXmJJ6EM4112tAhv5qtlTOdtUPb8WJFcMW8vn1VY6pcFNPglvGvrMl yiVd1kc6AZW0gh0o/MPxiYKGEXG0a9LxY3YncmPT8tztttdhmiXKOsrzJUTwDCQ6vzo1buKXjv sZTMLFcgMb4kNW4xZDFqrUJK Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:29:07 -0700 IronPort-SDR: HS/Szc3ouw9r3j2JN40ob0pHNQid2sPOnbLcf35TmP/vOrBMoVmkMy/FMsFelS6q6NbOmA71BP 4E75Xv6W83xfV1yg8dwM2lAceQt6rKDW7xlNRN2zKH/f5SXaM4cvunrsRBDkW7YsZ7LtVy+NYE caygD7LbvmfmHoNt1P9d8EDAsnO/9XFMkphB+z31DNm4UhkuS3kDx+B/sdJujBSYhf2Vw7OS5a KVkzR1o4HiLmm2ksLTm7iz/rAN9JLzNYfE5uA5mrHC/ZJP5ncIrfeYTM4dDgWC1tdKtcZgzWqS cBY= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:52:18 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 09/12] scsi: ufshpb: Limit the number of inflight map requests Date: Mon, 12 Jul 2021 12:50:36 +0300 Message-Id: <20210712095039.8093-10-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In host control mode the host is the originator of map requests. To not flood the device with map requests, use a simple throttling mechanism that limits the number of inflight map requests. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 11 +++++++++++ drivers/scsi/ufs/ufshpb.h | 1 + 2 files changed, 12 insertions(+) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 4138f081d1dc..472633052af1 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -21,6 +21,7 @@ #define READ_TO_MS 1000 #define READ_TO_EXPIRIES 100 #define POLLING_INTERVAL_MS 200 +#define THROTTLE_MAP_REQ_DEFAULT 1 /* memory management */ static struct kmem_cache *ufshpb_mctx_cache; @@ -742,6 +743,14 @@ static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb, struct ufshpb_req *map_req; struct bio *bio; + if (hpb->is_hcm && + hpb->num_inflight_map_req >= THROTTLE_MAP_REQ_DEFAULT) { + dev_info(&hpb->sdev_ufs_lu->sdev_dev, + "map_req throttle. inflight %d throttle %d", + hpb->num_inflight_map_req, THROTTLE_MAP_REQ_DEFAULT); + return NULL; + } + map_req = ufshpb_get_req(hpb, srgn->rgn_idx, REQ_OP_SCSI_IN, false); if (!map_req) return NULL; @@ -756,6 +765,7 @@ static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb, map_req->rb.srgn_idx = srgn->srgn_idx; map_req->rb.mctx = srgn->mctx; + hpb->num_inflight_map_req++; return map_req; } @@ -765,6 +775,7 @@ static void ufshpb_put_map_req(struct ufshpb_lu *hpb, { bio_put(map_req->bio); ufshpb_put_req(hpb, map_req); + hpb->num_inflight_map_req--; } static int ufshpb_clear_dirty_bitmap(struct ufshpb_lu *hpb, diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index 8309b59c7819..edf565e9036f 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -217,6 +217,7 @@ struct ufshpb_lu { struct ufshpb_req *pre_req; int num_inflight_pre_req; int throttle_pre_req; + int num_inflight_map_req; struct list_head lh_pre_req_free; int cur_read_id; int pre_req_min_tr_len; From patchwork Mon Jul 12 09:50:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 474977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C826C07E9E for ; Mon, 12 Jul 2021 09:52:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 788C36102A for ; Mon, 12 Jul 2021 09:52:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237953AbhGLJzX (ORCPT ); Mon, 12 Jul 2021 05:55:23 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:33194 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241681AbhGLJzU (ORCPT ); Mon, 12 Jul 2021 05:55:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083553; x=1657619553; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9DSxUS8WIFDvTZlufvyq8HF9Ro8gnU39eKlN+8oOfI0=; b=MyOZfXCYsQ9hMMdc8yDcazT8Gj4ZTp9AWDWKkAQUPtVZU6jurUhImLb+ Yjn3xP5h8gEMHgOQ2FkcQjZf9PPiKGbXMjoXUH9c79OVNPeT67FCImfAx EQR2ZWhL4CMBWmHyGYZG9oY2gJSBpQlKH1Cm5F3VUu3Wjqb/TMpC8VYle I79G5JVDNLgyEGmZav4H0QXjgEeAeciFE7Nb6Fjf/cIWvnEQe6rvTiExv lX9lkqD1VWXkNXvu0Bh7hPnL4XTBmmewrftrCKdqRL4Nx4ZAWXeR4PXwN NTo5RTDqz7WZmsmjr4zRFUTZSpg0YEcsQYC15Rddsaq1TSOtbloQTEM/I w==; IronPort-SDR: K3N6cfqb87aLaUW0ApAZ9PVSQjaHvO8o1oUEQSGKBa1H3XwllvTqvQc4isBxVLofsN/4dBVf84 tWIiq6PxChQyLIwmrSZluy3tA3OF7mvGP1TTTa75H2PbTlU0UzVlIJnKl4Z/AqbBw5LCcNMjnM pOMj8OSDqJio/fx8WIo0cI4lH9E9qvM+9DDz3Vha+L2+e9Su3tudkK9Il6ECiEjq0QepiVUo2o Nk+dCe3iOnVa+BTGgithqwUv4ufu1f6BHfmOWplJ4BbxGVYEXAeOrO3lZ7vDInJy5Z3qbeDsRL sLY= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="278155986" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:52:32 +0800 IronPort-SDR: lp3Zts7ZyDzg+7Y4wopMcDAWI8qQ/GB6+mY+dC0azRQGw0STb1O4fCSGqrkYK8M387MVmTXbWn L/SvrjCl/WqfQk82PyLE1vwh/kBCx40gHc4y0skC+kfPvvA061u40EP3P3UZbOaMWvLurPoQBw qIoomCcElhl2JtdUYz9qPqPyStdnk0SYRszclmDv2288QltOMqJ1im2V8cVmoUSGKaatCT3Iom 30WFniB3K5D82vK/N3KWYF+irVaQncKEIJAV8FCyw/fFePMhbpwE4f/qxjrciN6Bf9bnj6BNWC 2Vr7jUlPSrwX2pjdB4WM5GwG Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:30:36 -0700 IronPort-SDR: SHWEa9nl+aLpnHUlhZKIBIf/y1v6N36izW9K5tWFs7mN0Q3kijlCHPL9427aIzDYseKo5fmvPg TH2VznQvi3fUwAp0/sngFUGNSBWWTV/2WokqCsCwk9zaHMaGv1FVo/EsVkF3o/U1up9yxdKZ3d A0+BWf7JLilCXMdgbMovJOP9VWDgcNuOiN9zWMnbCl8uQly8aGtFE3fuygNvLgyZxjOU58h/Ws D42r1kOAb3Q5L0fYUltzOzyDYV/ZONMjavoM7IfYkk7EWKQRWrH9ET46RsWsnLj2cSLAoElNKs FIg= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:52:25 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 10/12] scsi: ufshpb: Do not send umap_all in host control mode Date: Mon, 12 Jul 2021 12:50:37 +0300 Message-Id: <20210712095039.8093-11-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org HPB-WRITE-BUFFER with buffer-id = 0x3h is supported in device control mode only. Signed-off-by: Avri Altman --- drivers/scsi/ufs/ufshpb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 472633052af1..17767ebf8bd0 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -2458,7 +2458,8 @@ static void ufshpb_hpb_lu_prepared(struct ufs_hba *hba) ufshpb_set_state(hpb, HPB_PRESENT); if ((hpb->lu_pinned_end - hpb->lu_pinned_start) > 0) queue_work(ufshpb_wq, &hpb->map_work); - ufshpb_issue_umap_all_req(hpb); + if (!hpb->is_hcm) + ufshpb_issue_umap_all_req(hpb); } else { dev_err(hba->dev, "destroy HPB lu %d\n", hpb->lun); ufshpb_destroy_lu(hba, sdev); From patchwork Mon Jul 12 09:50:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 473283 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28D02C07E9C for ; Mon, 12 Jul 2021 09:52:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 166706108B for ; Mon, 12 Jul 2021 09:52:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbhGLJzb (ORCPT ); Mon, 12 Jul 2021 05:55:31 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:11619 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241707AbhGLJzZ (ORCPT ); Mon, 12 Jul 2021 05:55:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083558; x=1657619558; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rOAe0RhkL99Hy07R1vj9oEvsLsHOix4kUohw4rsfT3A=; b=MjQtaTlHOGGPnOq5U2ztRAPtkQQ7cmHq2eDrYIxFqIerHvcERAhvkMDl 75UPyX1N6Nz0zPYJG2klsXQ3peXPNKEqnDpze+Uti68YhYJPhEg6VItr1 Enhyi6Er0Og0a71odesYXCsb1WOQs88fiRH96Yh+++cNobZ76X94/AaLI PZIDrf50V8NoHepiGpfTB7zMku2HojVGHUkl4/EOxQMqRwkN2di7H9bY8 kl1+WpmrMGl52UogdjLaUNcKD0y4prKohvy2nrs3yTPjvyGgkpVQZSb4Y XaONfNNto96DDWSiKqnEbg5+V1yT7axlw8pCgKIatZbXHy3hebaaeJLLY w==; IronPort-SDR: KFGxBPm4dZ723/UHTKGN00lAlsVfj5PJbU8E7R2EfZBqMOm0hMJqzgohtnfNr0idx9EzMel45w v8oT7du834yxN6Beuh8o+Ay1ioA6rgWuIjlh6CbTD1N62OrclSkD1kvr3wuCRPyNyR61M0gZff WM6ZHv4oyp80FLSjfE16w+E28EEvirgg8LzrWajkZcDky0lwWFE3DshYzgDOZcaJpj/AoDGfuy PF4LEVwDyWqlcig3/RVdDk+5Er/GbCrAtg2UcyjtGKOmzi03U2X56h+Ab1By3r0sprxm0zRzhS 1oE= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="285877132" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:52:37 +0800 IronPort-SDR: Qt4j7cyHtg2zhjI8vVweFr+X13Z+UhbJrsEehkHoJBp5hNjFyN+XjBwpxGdcnxnT9E7OCtQabS W3M6SoWFKpAcSV+iQgh2DMRFZoFo2CRxZ+4/twDDKUTq6PaAUSl6A8pq7MdKZVF+oRVv7xLuPE V1/SCF1O5UB90InYRbPpakPgqboOAv99Vmet2pwAR6/y4oMUxL/q412aIJSX1xn5lFYweLxxy+ 3ZdEZmPpfcgnH5tQem/x3Om58TJQMwNeEbS7ViWP3yvhKsmPu9FZTqlIIMIq0W8sjjWWTVux++ db3+f8wa9DZJCNhQIKxFRdpN Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:30:44 -0700 IronPort-SDR: fFzlG+oPOV7zE1GBlC/R94YFHl3SI453Rp1o3PDce+T80NabfPwpoPk0vxMSK1DhSDzMGa+9bI O1A1/YvqVr5Cfo9WXZg8Ii2fEhCp9R1L6PgE1Ya5S3ZxO2UL3MXY5HqBXe0vOiBOpxfmX5skrV nV8bqW7tb3qpLFdWXHtI7fLQD6Yij16jIkuXd+8wt0qDbbFFn0cYHhBG59S0SZpzCRiuqiATe8 rObX9GanDrDsCkIsey1TQS/xPztAaY5ycS2XSdD9OoJDLf6Yp/3mxwcF8wpn7q0U0+lOmBdVJc SwY= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:52:33 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 11/12] scsi: ufshpb: Add support for host control mode Date: Mon, 12 Jul 2021 12:50:38 +0300 Message-Id: <20210712095039.8093-12-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Support devices that report they are using host control mode. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- drivers/scsi/ufs/ufshpb.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 17767ebf8bd0..b638a413bdb2 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -2582,12 +2582,6 @@ void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) u32 max_hpb_single_cmd = HPB_MULTI_CHUNK_LOW; hpb_dev_info->control_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CONTROL]; - if (hpb_dev_info->control_mode == HPB_HOST_CONTROL) { - dev_err(hba->dev, "%s: host control mode is not supported.\n", - __func__); - hpb_dev_info->hpb_disabled = true; - return; - } version = get_unaligned_be16(desc_buf + DEVICE_DESC_PARAM_HPB_VER); if ((version != HPB_SUPPORT_VERSION) && From patchwork Mon Jul 12 09:50:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 474976 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B49AEC07E99 for ; Mon, 12 Jul 2021 09:52:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99C4B6108B for ; Mon, 12 Jul 2021 09:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236843AbhGLJzh (ORCPT ); Mon, 12 Jul 2021 05:55:37 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:11631 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235379AbhGLJze (ORCPT ); Mon, 12 Jul 2021 05:55:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1626083566; x=1657619566; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vwAwp81rljsx2H4LcUfW8BBtCK98ExwmCxEH3093kbc=; b=inwvuUZGA/bvveVkBNs4DldULMvbgZaAAyHlH0Vf6hffTVk/vj0pThoi vk3mQSX4qZagEXnPeQGbT8NaMk8gv3qVAyMxGwr0u2LhYviWcHiY2iKeG QexTFZza90vWjoXnCR8p2mHT60RoZ3DzE8yIc5FH959hOG/ywYOl0aFNw lg4eqdYw//qntbQofMQ2B3K1zCODASVjI+T8ISFHEsusKGs2hePSf0NH5 AlbZO6sOEynKSDgMHSpGhJl6C1TBp1tgjRwJ5t+zsJClmuBA6wBCnvgTz 3SgJw7iZq1M3CX6501/rxrEc9Qc1hpQqM2Dr5Voi3mC+ZamXvOuqmIayh w==; IronPort-SDR: 2Caj6DRIhYmeTRud1uVs50wMVJnZpDdevwTsNujLnyZIsd3kcGF/J65E2rUbPGLzf2ZJBmhph9 GaFrB4Qv5dgEe7ZjLmprtVFMbQpwlbkUmA0Y4ONxlGCRe+x00naOOZep/nxZJnpOYE1dwqyMLW oHbWCgRb+gkDlfaR7gRLSd4M+Onx1spgXsLK7ubjkPqJ+1I+YpcwdUSGwF1YLndVi8Kdi3GSfY 4PW6boa7U6lkYoPmGu9Kn+bXnUxzp+Wk6JLEluTC2cDFmlQNyQfkkmN0kAz1hUj6l2q9i+TUNs lqc= X-IronPort-AV: E=Sophos;i="5.84,232,1620662400"; d="scan'208";a="285877148" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Jul 2021 17:52:45 +0800 IronPort-SDR: 3aawXQK5zL6PSEknlJ8wMjb1/zsZ2CnwvxM4D+b+JGb0fz2skqqzivUmuh1lP5pxpFhJJWcIez Uz9/5+6hj0aHeSJR4tG5DDSJTcQj0cJJi1WVpWNxkyPtNTbPUGdcYrU1uCSB4Q6AN04CqJbUVw SIc7DnjlCCQZ22lBclfLgCFuLQtBlU0XL/dFArrzYEbRDyeRF3UqAtL0P0v35yTsHv1Jbh2rSz idLu7F3ye+erOiWKWCUTGxYIebqMfX5VkaVyEOlIRCoD9Oj2VE8sYcKAx68S6DT7iOMspfEBle qTKeFLKlHrJHYYnV503pGQ4q Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:29:30 -0700 IronPort-SDR: xKIeySFHfS+LtO4zBqV4/JbGWPtTKBsjPJgp+xxKSNDXDujuN7Vzqbe0Tr9KOqvOgVMApr2WRf 6OqDeM6MhoG971UUHHTywCDyV9S1GG1m60nQNrv0SLGxkwhkMyptvhfqL1nGKAv2d78QSCXbbO 6zdIP1jsKGHq2zhrCRAfmvvI/X8GKEXYFqrAvUbtMzxNMdsdGQ2R3rO4iaP7BpyvfRIQpNrdIr 8+SDVyUFoKywDjyDh+x0QNmS4sO7uxz2RJH14N5z+pjs8zvUMwBP4KJKpU3T9w3HTXYiG6PMOb VE0= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Jul 2021 02:52:41 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v12 12/12] scsi: ufshpb: Make host mode parameters configurable Date: Mon, 12 Jul 2021 12:50:39 +0300 Message-Id: <20210712095039.8093-13-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712095039.8093-1-avri.altman@wdc.com> References: <20210712095039.8093-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We can make use of this commit, to elaborate some more of the host control mode logic, explaining what role play each and every variable. While at it, allow those parameters to be configurable. Signed-off-by: Avri Altman Reviewed-by: Daejun Park --- Documentation/ABI/testing/sysfs-driver-ufs | 76 +++++- drivers/scsi/ufs/ufshpb.c | 288 +++++++++++++++++++-- drivers/scsi/ufs/ufshpb.h | 20 ++ 3 files changed, 367 insertions(+), 17 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs index 3971b31975c6..cfd6f8fc2c97 100644 --- a/Documentation/ABI/testing/sysfs-driver-ufs +++ b/Documentation/ABI/testing/sysfs-driver-ufs @@ -1449,7 +1449,7 @@ Description: This entry shows the maximum HPB data size for using single HPB The file is read only. -What: /sys/bus/platform/drivers/ufshcd/*/flags/wb_enable +What: /sys/bus/platform/drivers/ufshcd/*/flags/hpb_enable Date: June 2021 Contact: Daejun Park Description: This entry shows the status of HPB. @@ -1460,3 +1460,77 @@ Description: This entry shows the status of HPB. == ============================ The file is read only. + +What: /sys/class/scsi_device/*/device/hpb_param_sysfs/activation_thld +Date: February 2021 +Contact: Avri Altman +Description: In host control mode, reads are the major source of activation + trials. once this threshold hs met, the region is added to the + "to-be-activated" list. Since we reset the read counter upon + write, this include sending a rb command updating the region + ppn as well. + +What: /sys/class/scsi_device/*/device/hpb_param_sysfs/normalization_factor +Date: February 2021 +Contact: Avri Altman +Description: In host control mode, We think of the regions as "buckets". + Those buckets are being filled with reads, and emptied on write. + We use entries_per_srgn - the amount of blocks in a subregion as + our bucket size. This applies because HPB1.0 only concern a + single-block reads. Once the bucket size is crossed, we trigger + a normalization work - not only to avoid overflow, but mainly + because we want to keep those counters normalized, as we are + using those reads as a comparative score, to make various decisions. + The normalization is dividing (shift right) the read counter by + the normalization_factor. If during consecutive normalizations + an active region has exhaust its reads - inactivate it. + +What: /sys/class/scsi_device/*/device/hpb_param_sysfs/eviction_thld_enter +Date: February 2021 +Contact: Avri Altman +Description: Region deactivation is often due to the fact that eviction took + place: a region become active on the expense of another. This is + happening when the max-active-regions limit has crossed. + In host mode, eviction is considered an extreme measure. We + want to verify that the entering region has enough reads, and + the exiting region has much less reads. eviction_thld_enter is + the min reads that a region must have in order to be considered + as a candidate to evict other region. + +What: /sys/class/scsi_device/*/device/hpb_param_sysfs/eviction_thld_exit +Date: February 2021 +Contact: Avri Altman +Description: same as above for the exiting region. A region is consider to + be a candidate to be evicted, only if it has less reads than + eviction_thld_exit. + +What: /sys/class/scsi_device/*/device/hpb_param_sysfs/read_timeout_ms +Date: February 2021 +Contact: Avri Altman +Description: In order not to hang on to “cold” regions, we shall inactivate + a region that has no READ access for a predefined amount of + time - read_timeout_ms. If read_timeout_ms has expired, and the + region is dirty - it is less likely that we can make any use of + HPB-READing it. So we inactivate it. Still, deactivation has + its overhead, and we may still benefit from HPB-READing this + region if it is clean - see read_timeout_expiries. + +What: /sys/class/scsi_device/*/device/hpb_param_sysfs/read_timeout_expiries +Date: February 2021 +Contact: Avri Altman +Description: if the region read timeout has expired, but the region is clean, + just re-wind its timer for another spin. Do that as long as it + is clean and did not exhaust its read_timeout_expiries threshold. + +What: /sys/class/scsi_device/*/device/hpb_param_sysfs/timeout_polling_interval_ms +Date: February 2021 +Contact: Avri Altman +Description: the frequency in which the delayed worker that checks the + read_timeouts is awaken. + +What: /sys/class/scsi_device/*/device/hpb_param_sysfs/inflight_map_req +Date: February 2021 +Contact: Avri Altman +Description: in host control mode the host is the originator of map requests. + To not flood the device with map requests, use a simple throttling + mechanism that limits the number of inflight map requests. diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index b638a413bdb2..d240817ef02f 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -17,7 +17,6 @@ #include "../sd.h" #define ACTIVATION_THRESHOLD 8 /* 8 IOs */ -#define EVICTION_THRESHOLD (ACTIVATION_THRESHOLD << 5) /* 256 IOs */ #define READ_TO_MS 1000 #define READ_TO_EXPIRIES 100 #define POLLING_INTERVAL_MS 200 @@ -195,7 +194,7 @@ static void ufshpb_iterate_rgn(struct ufshpb_lu *hpb, int rgn_idx, int srgn_idx, } else { srgn->reads++; rgn->reads++; - if (srgn->reads == ACTIVATION_THRESHOLD) + if (srgn->reads == hpb->params.activation_thld) activate = true; } spin_unlock(&rgn->rgn_lock); @@ -744,10 +743,11 @@ static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb, struct bio *bio; if (hpb->is_hcm && - hpb->num_inflight_map_req >= THROTTLE_MAP_REQ_DEFAULT) { + hpb->num_inflight_map_req >= hpb->params.inflight_map_req) { dev_info(&hpb->sdev_ufs_lu->sdev_dev, "map_req throttle. inflight %d throttle %d", - hpb->num_inflight_map_req, THROTTLE_MAP_REQ_DEFAULT); + hpb->num_inflight_map_req, + hpb->params.inflight_map_req); return NULL; } @@ -1053,6 +1053,7 @@ static void ufshpb_read_to_handler(struct work_struct *work) struct victim_select_info *lru_info = &hpb->lru_info; struct ufshpb_region *rgn, *next_rgn; unsigned long flags; + unsigned int poll; LIST_HEAD(expired_list); if (test_and_set_bit(TIMEOUT_WORK_RUNNING, &hpb->work_data_bits)) @@ -1071,7 +1072,7 @@ static void ufshpb_read_to_handler(struct work_struct *work) list_add(&rgn->list_expired_rgn, &expired_list); else rgn->read_timeout = ktime_add_ms(ktime_get(), - READ_TO_MS); + hpb->params.read_timeout_ms); } } @@ -1089,8 +1090,9 @@ static void ufshpb_read_to_handler(struct work_struct *work) clear_bit(TIMEOUT_WORK_RUNNING, &hpb->work_data_bits); + poll = hpb->params.timeout_polling_interval_ms; schedule_delayed_work(&hpb->ufshpb_read_to_work, - msecs_to_jiffies(POLLING_INTERVAL_MS)); + msecs_to_jiffies(poll)); } static void ufshpb_add_lru_info(struct victim_select_info *lru_info, @@ -1100,8 +1102,11 @@ static void ufshpb_add_lru_info(struct victim_select_info *lru_info, list_add_tail(&rgn->list_lru_rgn, &lru_info->lh_lru_rgn); atomic_inc(&lru_info->active_cnt); if (rgn->hpb->is_hcm) { - rgn->read_timeout = ktime_add_ms(ktime_get(), READ_TO_MS); - rgn->read_timeout_expiries = READ_TO_EXPIRIES; + rgn->read_timeout = + ktime_add_ms(ktime_get(), + rgn->hpb->params.read_timeout_ms); + rgn->read_timeout_expiries = + rgn->hpb->params.read_timeout_expiries; } } @@ -1130,7 +1135,8 @@ static struct ufshpb_region *ufshpb_victim_lru_info(struct ufshpb_lu *hpb) * in host control mode, verify that the exiting region * has less reads */ - if (hpb->is_hcm && rgn->reads > (EVICTION_THRESHOLD >> 1)) + if (hpb->is_hcm && + rgn->reads > hpb->params.eviction_thld_exit) continue; victim_rgn = rgn; @@ -1346,7 +1352,8 @@ static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) * in host control mode, verify that the entering * region has enough reads */ - if (hpb->is_hcm && rgn->reads < EVICTION_THRESHOLD) { + if (hpb->is_hcm && + rgn->reads < hpb->params.eviction_thld_enter) { ret = -EACCES; goto out; } @@ -1697,6 +1704,7 @@ static void ufshpb_normalization_work_handler(struct work_struct *work) struct ufshpb_lu *hpb = container_of(work, struct ufshpb_lu, ufshpb_normalization_work); int rgn_idx; + u8 factor = hpb->params.normalization_factor; for (rgn_idx = 0; rgn_idx < hpb->rgns_per_lu; rgn_idx++) { struct ufshpb_region *rgn = hpb->rgn_tbl + rgn_idx; @@ -1707,7 +1715,7 @@ static void ufshpb_normalization_work_handler(struct work_struct *work) for (srgn_idx = 0; srgn_idx < hpb->srgns_per_rgn; srgn_idx++) { struct ufshpb_subregion *srgn = rgn->srgn_tbl + srgn_idx; - srgn->reads >>= 1; + srgn->reads >>= factor; rgn->reads += srgn->reads; } spin_unlock(&rgn->rgn_lock); @@ -2030,8 +2038,247 @@ requeue_timeout_ms_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RW(requeue_timeout_ms); +ufshpb_sysfs_param_show_func(activation_thld); +static ssize_t +activation_thld_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); + int val; + + if (!hpb) + return -ENODEV; + + if (!hpb->is_hcm) + return -EOPNOTSUPP; + + if (kstrtouint(buf, 0, &val)) + return -EINVAL; + + if (val <= 0) + return -EINVAL; + + hpb->params.activation_thld = val; + + return count; +} +static DEVICE_ATTR_RW(activation_thld); + +ufshpb_sysfs_param_show_func(normalization_factor); +static ssize_t +normalization_factor_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); + int val; + + if (!hpb) + return -ENODEV; + + if (!hpb->is_hcm) + return -EOPNOTSUPP; + + if (kstrtouint(buf, 0, &val)) + return -EINVAL; + + if (val <= 0 || val > ilog2(hpb->entries_per_srgn)) + return -EINVAL; + + hpb->params.normalization_factor = val; + + return count; +} +static DEVICE_ATTR_RW(normalization_factor); + +ufshpb_sysfs_param_show_func(eviction_thld_enter); +static ssize_t +eviction_thld_enter_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); + int val; + + if (!hpb) + return -ENODEV; + + if (!hpb->is_hcm) + return -EOPNOTSUPP; + + if (kstrtouint(buf, 0, &val)) + return -EINVAL; + + if (val <= hpb->params.eviction_thld_exit) + return -EINVAL; + + hpb->params.eviction_thld_enter = val; + + return count; +} +static DEVICE_ATTR_RW(eviction_thld_enter); + +ufshpb_sysfs_param_show_func(eviction_thld_exit); +static ssize_t +eviction_thld_exit_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); + int val; + + if (!hpb) + return -ENODEV; + + if (!hpb->is_hcm) + return -EOPNOTSUPP; + + if (kstrtouint(buf, 0, &val)) + return -EINVAL; + + if (val <= hpb->params.activation_thld) + return -EINVAL; + + hpb->params.eviction_thld_exit = val; + + return count; +} +static DEVICE_ATTR_RW(eviction_thld_exit); + +ufshpb_sysfs_param_show_func(read_timeout_ms); +static ssize_t +read_timeout_ms_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); + int val; + + if (!hpb) + return -ENODEV; + + if (!hpb->is_hcm) + return -EOPNOTSUPP; + + if (kstrtouint(buf, 0, &val)) + return -EINVAL; + + /* read_timeout >> timeout_polling_interval */ + if (val < hpb->params.timeout_polling_interval_ms * 2) + return -EINVAL; + + hpb->params.read_timeout_ms = val; + + return count; +} +static DEVICE_ATTR_RW(read_timeout_ms); + +ufshpb_sysfs_param_show_func(read_timeout_expiries); +static ssize_t +read_timeout_expiries_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); + int val; + + if (!hpb) + return -ENODEV; + + if (!hpb->is_hcm) + return -EOPNOTSUPP; + + if (kstrtouint(buf, 0, &val)) + return -EINVAL; + + if (val <= 0) + return -EINVAL; + + hpb->params.read_timeout_expiries = val; + + return count; +} +static DEVICE_ATTR_RW(read_timeout_expiries); + +ufshpb_sysfs_param_show_func(timeout_polling_interval_ms); +static ssize_t +timeout_polling_interval_ms_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); + int val; + + if (!hpb) + return -ENODEV; + + if (!hpb->is_hcm) + return -EOPNOTSUPP; + + if (kstrtouint(buf, 0, &val)) + return -EINVAL; + + /* timeout_polling_interval << read_timeout */ + if (val <= 0 || val > hpb->params.read_timeout_ms / 2) + return -EINVAL; + + hpb->params.timeout_polling_interval_ms = val; + + return count; +} +static DEVICE_ATTR_RW(timeout_polling_interval_ms); + +ufshpb_sysfs_param_show_func(inflight_map_req); +static ssize_t inflight_map_req_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); + int val; + + if (!hpb) + return -ENODEV; + + if (!hpb->is_hcm) + return -EOPNOTSUPP; + + if (kstrtouint(buf, 0, &val)) + return -EINVAL; + + if (val <= 0 || val > hpb->sdev_ufs_lu->queue_depth - 1) + return -EINVAL; + + hpb->params.inflight_map_req = val; + + return count; +} +static DEVICE_ATTR_RW(inflight_map_req); + +static void ufshpb_hcm_param_init(struct ufshpb_lu *hpb) +{ + hpb->params.activation_thld = ACTIVATION_THRESHOLD; + hpb->params.normalization_factor = 1; + hpb->params.eviction_thld_enter = (ACTIVATION_THRESHOLD << 5); + hpb->params.eviction_thld_exit = (ACTIVATION_THRESHOLD << 4); + hpb->params.read_timeout_ms = READ_TO_MS; + hpb->params.read_timeout_expiries = READ_TO_EXPIRIES; + hpb->params.timeout_polling_interval_ms = POLLING_INTERVAL_MS; + hpb->params.inflight_map_req = THROTTLE_MAP_REQ_DEFAULT; +} + static struct attribute *hpb_dev_param_attrs[] = { &dev_attr_requeue_timeout_ms.attr, + &dev_attr_activation_thld.attr, + &dev_attr_normalization_factor.attr, + &dev_attr_eviction_thld_enter.attr, + &dev_attr_eviction_thld_exit.attr, + &dev_attr_read_timeout_ms.attr, + &dev_attr_read_timeout_expiries.attr, + &dev_attr_timeout_polling_interval_ms.attr, + &dev_attr_inflight_map_req.attr, NULL, }; @@ -2115,6 +2362,8 @@ static void ufshpb_stat_init(struct ufshpb_lu *hpb) static void ufshpb_param_init(struct ufshpb_lu *hpb) { hpb->params.requeue_timeout_ms = HPB_REQUEUE_TIME_MS; + if (hpb->is_hcm) + ufshpb_hcm_param_init(hpb); } static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) @@ -2169,9 +2418,13 @@ static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) ufshpb_stat_init(hpb); ufshpb_param_init(hpb); - if (hpb->is_hcm) + if (hpb->is_hcm) { + unsigned int poll; + + poll = hpb->params.timeout_polling_interval_ms; schedule_delayed_work(&hpb->ufshpb_read_to_work, - msecs_to_jiffies(POLLING_INTERVAL_MS)); + msecs_to_jiffies(poll)); + } return 0; @@ -2350,10 +2603,13 @@ void ufshpb_resume(struct ufs_hba *hba) continue; ufshpb_set_state(hpb, HPB_PRESENT); ufshpb_kick_map_work(hpb); - if (hpb->is_hcm) - schedule_delayed_work(&hpb->ufshpb_read_to_work, - msecs_to_jiffies(POLLING_INTERVAL_MS)); + if (hpb->is_hcm) { + unsigned int poll = + hpb->params.timeout_polling_interval_ms; + schedule_delayed_work(&hpb->ufshpb_read_to_work, + msecs_to_jiffies(poll)); + } } } diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index edf565e9036f..c74a6c35a446 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -185,8 +185,28 @@ struct victim_select_info { atomic_t active_cnt; }; +/** + * ufshpb_params - ufs hpb parameters + * @requeue_timeout_ms - requeue threshold of wb command (0x2) + * @activation_thld - min reads [IOs] to activate/update a region + * @normalization_factor - shift right the region's reads + * @eviction_thld_enter - min reads [IOs] for the entering region in eviction + * @eviction_thld_exit - max reads [IOs] for the exiting region in eviction + * @read_timeout_ms - timeout [ms] from the last read IO to the region + * @read_timeout_expiries - amount of allowable timeout expireis + * @timeout_polling_interval_ms - frequency in which timeouts are checked + * @inflight_map_req - number of inflight map requests + */ struct ufshpb_params { unsigned int requeue_timeout_ms; + unsigned int activation_thld; + unsigned int normalization_factor; + unsigned int eviction_thld_enter; + unsigned int eviction_thld_exit; + unsigned int read_timeout_ms; + unsigned int read_timeout_expiries; + unsigned int timeout_polling_interval_ms; + unsigned int inflight_map_req; }; struct ufshpb_stats {