From patchwork Wed Jun 16 11:27:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 462622 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 0D3E4C48BE8 for ; Wed, 16 Jun 2021 11:28:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4FD56128B for ; Wed, 16 Jun 2021 11:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232308AbhFPLac (ORCPT ); Wed, 16 Jun 2021 07:30:32 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:4725 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbhFPLac (ORCPT ); Wed, 16 Jun 2021 07:30:32 -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=1623842907; x=1655378907; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vDksMCPROdbgzbzogxqTNaIIhU8JtS4xpZaUcJ4bey0=; b=oQl2pwixA4lHYViow8hSLnIhErYW/z5D+KIvGRaBGpBniiP1Arm5vSvp /QS9Fv8amdLJYp8iTkDydBJ5IPH/tM9qTtphAaPGdbrGtq0Of9/6GjNhi 35/OSkAaVKhfz0XAHzp9LbIrEu1AMw3V2qSwvlgguvnPwRdO77BSpQ//1 p9s+D2KovF1NpZqc7mRRJvDotkJSjtR+Fa/vrvmZfdNk+ydpV/C3Y3kJS IFBg5Jngllqt/lXErrHXWBsmFcZHld14khMxBJ+/TcpFJUCjrzPMfPoPP jUKJdAd1oig1+eZnmn9LgyLpTOTlVpHkSzf5ThzcFEYiT+kmuVl2W3+NQ A==; IronPort-SDR: yCmXQd5wjhaEVJWdruSvhbJBvEXhC+Btb4+F4aXh6k5zZYB6HX6xC9LeXtbTzCoVKe+knOguhs DRuZVBJyg6BhFcQza6Jgck08nVj4PigtQriJdvZGuKImBjx96zogBWB8k1IlWuIkfSPfzqcqVA Zg9AKgFI2h8jJKSo5HQnedW9F2hARn8mw86K/8VMvssqB/DMLj5Jd+OsdZKQR7QZKuFccloo0M tAbby7fC59vNSVeGCyhHywgkOfNXJISyybFI4hLeOOsylCERAtcDLxz3h7p6AXrm3RzM9bk05T Izw= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="172653640" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:28:26 +0800 IronPort-SDR: d2/9KKYyTCaAbSEShE3vMf9nI0wNArUFXIrqmIbIk0zuZhDhH335MbGTxmgmcDLq/6LYaEpCQH V2Mb4V1wXpkpx91fCi29BesLL84SS/QEjqSzEMon+QZ4EYZVLd0OJLaWi1dqQ3S1TfJeh+envQ 9jlhxQS1qyr784rITAl4Q6YCOtYNA/T1JGkSOVYlmtD033j2TfW5cGnNw5uzHNagPWXn3Mazu8 JDDpot8mhLEAJaQYQWJN0RFk/7oBg0qKbkYi9/1DSt+erXICnAL5FThNV+dIhJTe4zwlad51Zp FGMf/tctJeaV2zXkaI+Rz3WK Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:07:16 -0700 IronPort-SDR: A2vqhEIDRK/0wFXZ118GlQpZQgZZs/qOlE4ofgSyvVowxTZ6QvEEg92v7E6CElBmuZnkuLB6AY tktGWgA7CehWbs4p5omXKjeknfgQ09sm6T8az6slQsyet4undwJrOBbX0gSQxBm6dTCB7hDAZr wG4Gwnr3VbKsJ/tQAWbPzRZ1Mm1eS8KHWz+dc5oadctnhHEGH1OZLqrtd5XnUmQL3cezt6LrJS /ifSNQY3FP590509Eg2F++diIStI4Dg2U9ZvZv3iAL+CGufaiiSNupO/PWCrXA1n0bNG8i8Q0u 1/c= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:28:22 -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 v11 01/12] scsi: ufshpb: Cache HPB Control mode on init Date: Wed, 16 Jun 2021 14:27:49 +0300 Message-Id: <20210616112800.52963-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 69c2450ef650..61f4fcf6bc07 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 Wed Jun 16 11:27:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 461798 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 026C1C48BE6 for ; Wed, 16 Jun 2021 11:28:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D81D06128C for ; Wed, 16 Jun 2021 11:28:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232386AbhFPLam (ORCPT ); Wed, 16 Jun 2021 07:30:42 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:65350 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232382AbhFPLal (ORCPT ); Wed, 16 Jun 2021 07:30:41 -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=1623842914; x=1655378914; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VsFl0BSSzEpcepwJIpxcxa26x244/RmPQno1tOqHH1M=; b=N1jITnUffw4qJHAUH04svQd2W08kst0NjUGq84x5cGZ55jI1eLs5h4Q5 9JesU4OobAPhTO2s20Cs48vwbdDLgvCk83DoALAsdL2P37hjzvjfpZOol n7xJyfkD9zCPEPuWTVTky7q8e/O/bk3IREe9upKHqOsHt1Pu4F/uDPPyV iUqwvbGaYXQAK2sUFNBrxc7VxxyEIYzqGZLJPe03iTcFd2gj5151+uoiI Ccf730j28d+bmU38tjX+UsCHbWj7a5gCRCMiSIldHlGPvv3n2/28IznFF vvlnKQzQRMcoZSKuXcvaoToGlR1OBwKMuLrncINW27EDc5t7I6+44hMUe g==; IronPort-SDR: 9j/u5uDQx/IUerpD0KGbRXzVDUvWt7RBD2yWuWIE6M6E4M9hhsu7YPpPz2yd1Lw+w8Lx+rIDs9 gTYUnP6daVfBncgOuDRTbV88u4C2x/XhZYnjpBTXi37WXCqxrdY2bmCG8tK6FNARZGGGvzAU6w jF8uw7FuF5EoFcn7rbuOR9BoI1mj5WWfkGmzfbgFzlnIjN+zGUIwhz4Xy6AygnKutxe/+63Fhu UKtS1eP2ifiaNZxGtGkxd10ca3U9K4ErcjZ/NkjuELGoOLVGCjEUcEyCkYmcdOX7VWdvkLhmWk 3cs= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="176876289" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:28:32 +0800 IronPort-SDR: zFtki8XHoOUev0uWIQ1E1OZFp3jOxOZ53elaa1GArHnN6eRcZeNLBdA2QkQu2Tb06omQQP3nyN oHflVhzVTe/2tshkHTKUrMswtjXcdfm/MhqyvfqZBpVWafN/xd/iXHvsO12KP1DApYgko+Iuie 8nh8KD98lHE8RFHxVv+UZtZVfiVZ2fYYMHK5ppATeo9t2kH9SJDLu9LcY6fQtVk9FlBiLqfBiv qV7lUvYpx7WBkzxYzDrbTmwKIAtHb7i5ECJJQyR46TBFag/4tCdEFMZtDY7sNblG5NwMrhf/9I xOLZtc+TxlYnVf0gfLgI8lhL Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:06:02 -0700 IronPort-SDR: 9N4pv0Ly2mnfra+xSt7geJxlxA/fDgq7bzN9zNKzAiMT4JUnpIeopCRAY4Y8y9yluakAPCiGpu eRnfPOC2ynaw6BUThAB2X98C02hXTM6WoGwOa7MwacNRvmIbyk+trAOjAZ4C3KbfG8DFVQIX7q oRhjnB7ZzB1ZFoOW2Lly33kDWgdmb/dM/Pv6880p48dNMnX9dkvO5lyrkc4dFkffAZBLIkMcth IqTV/OQJc2vANEe36sXgdFS1LAwpS9KBqmRgQDcwTsZ/PLo7kz1OIMScIsTVTST2ZmEgdycNY2 42I= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:28:30 -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 v11 02/12] scsi: ufshpb: Add host control mode support to rsp_upiu Date: Wed, 16 Jun 2021 14:27:50 +0300 Message-Id: <20210616112800.52963-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 61f4fcf6bc07..3fd9fd5cb43e 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 Wed Jun 16 11:27:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 462621 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 4B617C48BE5 for ; Wed, 16 Jun 2021 11:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F70C61351 for ; Wed, 16 Jun 2021 11:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232432AbhFPLat (ORCPT ); Wed, 16 Jun 2021 07:30:49 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:17148 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232453AbhFPLar (ORCPT ); Wed, 16 Jun 2021 07:30:47 -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=1623842921; x=1655378921; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N+UorW/M+tQ9BKtSt2SvsYx6FPcT/Bjw5KUFrbTxwXI=; b=TSwNXEzNfBmU/5lmYcWBB3y0gXbL0y359z8cZQMZPPymDgsynS0eetUd q5y2WdJ9+jnux9XeD2D4B6fblfZMYXucR0sxqJGjAjTYikqRPmGgZqaBL Z4SU91Um45anq62IllHBJMX7a8Bh+PeBuQqCtamhOV2gSSaVwQDefDi02 SnuhmfKTnOX9AfesZdazhr2XuomT7ebgMBTROS33dphpo0uFcn36IwPDy Irdbf31Ok7bVFk88xlyQ3wVu8HCgoC+f4xcwQQ2MHY6GkXTF/KtBlF6aD Vev7ku2ea/1sLxo/QiLBSsvmER7RENd5WEhPMkrjeeH1GOt36BqHRSSFg g==; IronPort-SDR: bB/4xpovxTZtcriVjBLOB3tenFBqQdLNmWeLzH9L+7dKpKLBXXz1H2lA+5pg5MQoo9ejLrw5T6 S1stMr1/0Km4FMmdvV3z4uKHCuDJts1MduaT7nKof7v2gBczyR7iBDdWWWqhW4x0Yg5dd0zaQF olKDPXWXJ7Sg70bvyu0y2buVg6S5MZ1O8RMnQIEkjA/Tgto7RN4htVoYjnVzdk0vAiynel5EIW ybNi4/u84CJyJVOUKT8zm3t3Ic92z2R3JgIhwDgmwRrczXxNkjzyeU6jwVAZx0dNB13Ymiwp19 49s= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="283553826" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:28:41 +0800 IronPort-SDR: gCtU1Xv82jyhqld4htIyMfHMuOGyYkmvp8Yl9lUdXj/nF+6/NIgPxwN6Kq2U1jPbHnBfWn1RmM DZpK6QbyFkgflKeLH3ZviR1qo6+4kRhKboW/hCr35MUeLdCUCo1BwZRphaxmxYC8DLTBhDJUmA Tzuq5IQiM+iVIssZpmqzlP2DJEY7RdbkGkYyWMJIaVRTrziY9R/fd2U4F7FTTAt9dxT4PcXXv8 BiWkBPg9pJT9ew9/BmFe/ePJCmPSX2GuMk3+KFQdBLCwEBbun0PIX7w/1/zpOiOz0SpF7HZ+E7 Ghp/jj/Z90fmE2CScQHyiS0r Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:06:09 -0700 IronPort-SDR: aRUZk5rD3fNbDYiSuvFlErv8VaNlAzujCEMzNrb/I8RfYRckLLEfLSlG++CCgYMrHKxIwCIGjH 4bnutSSV/SNa50G5+TiwAcmwxXRXOELdgaESIjj7sWeYvGd8yOta1kfCAoye2vXqR33mnoK22c D3QpNI0pIAYl+27TkveT9+AgXI/8ApxISAod3Rgr/p0EQWjNXMwez8W/syA6r88Pm0XdencZg8 Z43I4nbMTHfOGDIg7RMhuWB3io6f3KO+t0iiYTRAAaC2MLYEp3IjQemjOeKYIe9mfH4W+eP1pT OE4= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:28:37 -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 v11 03/12] scsi: ufshpb: Transform set_dirty to iterate_rgn Date: Wed, 16 Jun 2021 14:27:51 +0300 Message-Id: <20210616112800.52963-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 3fd9fd5cb43e..7db553769717 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 Wed Jun 16 11:27:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 461797 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 5CD30C48BE5 for ; Wed, 16 Jun 2021 11:28:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4479B6128B for ; Wed, 16 Jun 2021 11:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232469AbhFPLa5 (ORCPT ); Wed, 16 Jun 2021 07:30:57 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:17157 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232476AbhFPLay (ORCPT ); Wed, 16 Jun 2021 07:30:54 -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=1623842928; x=1655378928; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MH8AyvkrMMYDA/b/Jmo9KImTIqSvsagyK53VFCQe/uI=; b=CmqH+eacMqxA8SNA6nIR02Z5vBQJNTUTSH0CCqz8SwqTe+rwtFWXnGlo EmNMijMtSE0Z6JPSAgPupuFbjhvXpGtDzg4Wbe4mMOPkNeFleHoBrhMRc 9dXg4LXQ9N0oho+E1TPi+tGr9fDoFdrLU0H8/l2BXOyW3CLOfc5Vo4pzq xiT60ikDpyKTD+5E021Sxtb2ss1nJH9FooOzl0l+qLuJx/hTzrYXVTwVH LGoLdDwuBoLdok1uGrLeb9q7PypcD7BtX/Ij4ksjhrDnb3Y/BPPBgmZzt jAPPobwNXHSpLRfHePa6YrTJdhjJGQ/ZVSICYDsvNGCPxTKkvTpsoPNo5 Q==; IronPort-SDR: +wzz6ZVvDou8thN3weo5ur/eZ1wGk/naaZ1gBiLOMapY4T5XDM+EO+gBiJuvDqOBBLH/nVq/vd NwfLcsY0VNZ1Pwso2SWhbiNDYRoPUsmG0m1PnvOAx0qXSUZNnGZ/3rEwSXVJwM6QdF/6chGR0V XvKBt1BoPg/4Uw+fCiWWjnLk0PDcvwScJcIR70s7Cgx+qZ/iD4pIgfx3Vlq4oOAmtZXATB+Evu ID4GOyMMdE5rIHW3QdAyNwbkSX+QWvKjXNpWnkqu6un4QIouRieZ5rCfPRcSnWoNLlOmEDSSkw dd8= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="283553844" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:28:48 +0800 IronPort-SDR: 46ZIyqb8133FHtEab3cE+4WyR/OELYjnErJnhqowlUN9MkPXlC4Z1FOq0zwKh4xC+VDwcshqFp DV6G1IlydFD1pFg1GTMugEiLgK1GoGu701YqDxsnju0Zv7qiSbgRet0YRroSbOuYHIDA3Gd/kz YccAYnmpot6uQxl7xg0ErwFWe0Jr71NIj6aRyeRX5ppSSR6GDcWWNeQKa2H4W82dUmmyN/SNmS NVCmGil4GHgXPf70qfNmD+Pq9nnZKAMG2y5dixTpTeLozLmPBKCcpu8nmBGr78kGAMDqOk5B++ WY/6ZHR30EbXj4+PJ9e3ELLp Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:07:38 -0700 IronPort-SDR: Xnb9Po5cWAdjHIYASxUfjTkirtDwSQuaSmAcpY/cVbSBm8UeX4tVnnMrHZWgKMWYqm6lYTaKgS GCDfchruXUQu5a5NYSfPSQxq1X1LPXYXKINQdORcg0U+85gJXTiQR1Q4vd2o+0/C6ZPnd/Zrh9 5WNmxDLnK/PK/0z+i6oKQsXafJF0aVD7/E5qer4GzNtfMTQSTquk4KoeDzQqA19lvbsvKpOQpk 6Of0tUYfd6SldsX/als1f2OutF/8nv4sVjHAECM4KDd4IwXXkhmNCXzpBpmJ7NNuuZ0LJ8trSw 1yo= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:28:44 -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 v11 04/12] scsi: ufshpb: Add reads counter Date: Wed, 16 Jun 2021 14:27:52 +0300 Message-Id: <20210616112800.52963-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 7db553769717..9e5e585e1a43 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 Wed Jun 16 11:27:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 462620 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 89ACBC48BE8 for ; Wed, 16 Jun 2021 11:28:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6362661246 for ; Wed, 16 Jun 2021 11:28:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232486AbhFPLbE (ORCPT ); Wed, 16 Jun 2021 07:31:04 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:65265 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232480AbhFPLbB (ORCPT ); Wed, 16 Jun 2021 07:31:01 -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=1623842937; x=1655378937; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KOE+iOlrS9XEWOKhdbmkFiw56P3ix4vKgtUj2RN0skk=; b=kD5AFggroqcOl7ZCTf4NrRaJfpI6IqQePhW2rk0QEaxIl9E8p6ev8am9 aeuyyUo8+cZmZ48PTw62Te+dez1lu5BN7sCj2yaz176r1bVnyYoR4SKlz gTN4tL/gounzTXveDAM/Y5DKgeVxeFO0QyPEzIM6lmsdfmC14dZPypsgH OjiqS6VDFEf7ZdEGhn6DShQa+Gd8sbE5dt3bBAmMrQniyQowM8TOlKECL 7NMQf0f+mrAMHv5miNI2byFnn6bKiw1lRQsHpQQGH/7L16gE5v6ZgTogv VkeYqHV+htB4y5y92l2uIFV8l2V6ZWNZvCyX8ib+OLpbBYgsbLciQ5N8S Q==; IronPort-SDR: 1TL6MbaIeKuLWpz2wfJTKFm3et/euhDuLCE4MXdtUepVaT+muB/GOzcIDLq4Nf2JOM3YFuRDsB G6HzueSr06x0D3uo8xki4X0YpGxvxdkryi+WPAqMCDc6aHPwDz5KDEBFikduBIQd0f0AM9xbka nIJ4cqAAMaWb4TVodpDAjd/npXwnrQjOJhUWK1g0gdBN65QSDbAkK67k0Tbzrf9Ab+fvUXd/lN uc6vJoeGBYpEhTftTFr1HIlO0wzbfKWFmmmHmLMdjLhqVRk+O5srymvexjVEpdwpLxrGsVqi+6 zMw= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="275871304" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:28:58 +0800 IronPort-SDR: XVF9Z+kEvbWwgzX6zZG9BLQv257RzhNkx5qkEOZUOZ9zjiNsrQszMMfApL+d1YTRFETS2hD8kN 3W9L55wEtWNlJsOV++s1KeyFtOOz9hkJs/o6uIqgPuKsbpr6UWc6/Q0nV8yoHe/H0OAzf99EsN D37Cmlj13KsKYkoFU45JSpCkF7t6ahApjXtxLVaXpLnDapxbBVLu5f5Z8l6+2oVv1zXhf9SuKn DurtKEYgGPHgrgE6vlcT8fLegPtUjnpGvAXCF5taqy/nwyWClasF8L5URF+D1uzh9A+CcPsYem r5lkyT9mA2PTH8PFnKA9nMhx Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:06:22 -0700 IronPort-SDR: JG0vsmxmw+4ICbxk14ZD5ixEGdx3PxeKImRAu+ZJXBjwXRrxxdFhVVHadY1L3NyEAq2r8TVoTB PBa4mdxE7B9OFSnU/LG4tMrZY74i0/0ckd/0u2Jsd7GbNBBaBkszy9T5ORCXJG5GTS4lOXFWaj fDPsYGExPx3UqCtOdEM0RuG/HxGw4Q5mV2GodGzOyg+8K9pJMnUi1BR2wUa6l87C614VwbpZaG xZQwI4fZ5sNo+L6OerzRVW2jK4e/EJEq7FFiiR0hz01d/i4yoG+SedRrCfwkCiF1irwIFWmFCK zzU= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:28:50 -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 v11 05/12] scsi: ufshpb: Make eviction depends on region's reads Date: Wed, 16 Jun 2021 14:27:53 +0300 Message-Id: <20210616112800.52963-6-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 9e5e585e1a43..b61558196290 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 Wed Jun 16 11:27:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 461796 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 E1F8EC48BE8 for ; Wed, 16 Jun 2021 11:29:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C487E61246 for ; Wed, 16 Jun 2021 11:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbhFPLbL (ORCPT ); Wed, 16 Jun 2021 07:31:11 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:4785 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232519AbhFPLbI (ORCPT ); Wed, 16 Jun 2021 07:31:08 -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=1623842943; x=1655378943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5ZxgchlyaAoOW0pfw6dDegeGqzfsqGa2k1NmSNnm0Sk=; b=QknK9mSWWXhRWGwl2zOKetiEdE87y70RYowWk2fiz6BA1YbXGLef0qH8 qeZTXRJDa4O9fkw7n2/AoO1RI7DMuZLhhjEXTH4JwBW9sO31PyUkIUYpF vEcJJ8dXBkHi4P40AQ8t1vyrsozhIbF8C96XjxN+sMjIx0ID+L1/F9Qpl sJpvpJOx1qnQ5re3MyB8v6Nve479uz0TQdL8IO2zm+oUgpBxI3GzgbiV7 fRrZZZyJFx4p2eBhT04pfEPcbXF2o6WPXokje9FvHH1mSVUOirSu0BSgJ C92pzETCnJRiMyV+0UVnoaYHfhxlaYS0JLHy7YoyMOOea2QgZKfVbyuTz g==; IronPort-SDR: C/lc5FANPULPgFMRBByW2abHYhMHlwI8fCJ8iB0wT6LEu8qC9/2xVNUbju7lYs6VyDnUvm3lde aIE+lDP+lDXpQSzEUyPoT8GOcS38mGpUybMQWiDJB5wc0aDD0e9o/HTWI5AHwtjYpcXKciQ+z1 8+SWj4jUx/LVU8tmEO3mvrnp/CxTeGxlrrKNGylApqFMtJ8rW7QXboo+kngWEOvxHhHLWQhT0S BQG81VuwXcCoA1AQlOmORXHyXQw0+w+hE0dOhT5FT+6OXS/cmPfNFES6FyeITklZeUJyM21+5/ Lpo= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="172653698" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:29:02 +0800 IronPort-SDR: XounaXtUFI1LtuUvh8JWHMjuKLDMaW7/uIpUzi68uKWNxIywZ2dlT4W3I/TC67TiB92QOvV3Lr RWXLLoaGTZbQPe17Tiv17xJrijv4ijSK/XKOsix2wm5IU/QWAL/EX3MHRynaPWomZhjmz0PKm1 9uKM2P+H1xf/TnezJ2nifTMqBIXHPKQMKiBPKy4cAW6U4TbFGgICtmVehxGGKBKLZ1yDFa+BQN e2aU6W3b4tFWLH9HvPWvjhMTtqPRUnu11BeP+xn1opCk9YMG0I/3QWZJEQQuF8DHQxZ0y1nugh vibVoTQuyP8PBjC0fNfAgoxV Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:06:30 -0700 IronPort-SDR: /Xcpq+KZvZuCu1PdByFDwDYEVdk0r6jafqjuLb/cehUV1Kh3slH8JoMV2StvfNDM6zB0yzscGj Ww45fR0O2pZo8N+J2Z1AG0N8Y276vMw4dgCiunKhV6yItwei622hd/mbgxv9WgUC2gGxDrADb/ mopi4+Pjcxh//S1Vci908/M/5T5eqLB9PKm62WWCmL2/7p8IoY/jZrPJ9WKBp1siNc6S+HekpM Aa5SfGhDOEVeWhHFCnI/hrcdS34HCg7MtCOPYOXSMPpKa6k/1BLIdN80w+le68jXCTr5nT5umF ICw= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:28:58 -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 v11 06/12] scsi: ufshpb: Region inactivation in host mode Date: Wed, 16 Jun 2021 14:27:54 +0300 Message-Id: <20210616112800.52963-7-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 b61558196290..d6a4b816814c 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 Wed Jun 16 11:27:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 462619 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 D7313C49361 for ; Wed, 16 Jun 2021 11:29:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF9A061356 for ; Wed, 16 Jun 2021 11:29:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232535AbhFPLb0 (ORCPT ); Wed, 16 Jun 2021 07:31:26 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:4793 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232533AbhFPLbR (ORCPT ); Wed, 16 Jun 2021 07:31:17 -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=1623842952; x=1655378952; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8W1qEu1Mr+hQwfZ6EHqBvEoeGG8HcxcW7lQTa5SQp5A=; b=lRKO2RlVP+YDvLUT3xe78XSvbThnnit9b3GBLxecjB8G/IrjuandlAn8 dCnB35dZCLOkFJdnhXCxuV7M/P1lwj1x1/7ZZNFtttenqEVpepq1ymzDZ t+QRUXh0Xk9r1qa4YAiR2Ut6vXv/rCkVdgx0tlmtG7njqeH40caojKhRA E6/BXcGY/TsWy9n4QZYnMUaBWZPvt6QzdeuGlJ8n+S0CZNeBiXXNUOtbA oKldq1Dl2kp0+dNNISPv8MpHMcoxd9F4wYIriRrdGweacQ+ZcF+9KcUvL oV13ckWfZ8uRafrEAYtJvgeRmAmAXyHt/WrXlGfvaoXl/UUikxAERIoEf g==; IronPort-SDR: bNI4iztcfvIza+6kONRFLmyRFH+jkjlD5oHKxFLRFse12arRwcX/sq+X5XXcjENaI7bRGLfUbB jGDaKPiC1CE8J+Y1f2CBkhLSx3PFRME+3w4orrgmYlYj8TuhZdZk3INj+LTDd8bk5NiqXjmzUc 265PM+QZBCAwlZBiqvJ5ob1ObKj7SwsioiRrQRZu3cbJfh8n6xG9bdEGPSNEoqHwSSS2ZtvqvZ 0tY3H9OMJNW5F3P5TzxEP/Il8wmeAg3GrmrmVLtva+Bk5MLH5qXjBby8XSV/Ts5vMVZJjhUo9l cew= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="172653706" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:29:11 +0800 IronPort-SDR: N/mAOqTnPY222VlaEsdNVtNxZlIyZIFoayV5vUKRUGShaDQ+CimDMkUzhvrz87gKQZQFEPHgrC 5MnljuSAFihWlmMbIJzTEqdVb99kAROkW58xY5i0zVIqMQ5BREWuNk7jdgCPv79OethRiKkrkj 6AgGijDcHSkEmXnRjVZ45Vxknf6Ai8UKpHqqse9fIl2dr+uFX0Ov5ZP29Ngqb77ERKGkDYyZER LnGlsPYdtt/E8O75IbNJZCNd6FHDRf1FY8QxxURPo8FMPGthz/4Kp3g1YNhgV3bWS2jZHmWyBD JCSadPcY9oT3jEhR2uEdQUws Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:06:39 -0700 IronPort-SDR: uvRqXFpJDJ9yWuxhYthjIzVCPxgY4ioVNykLkuvD1qi7gHlbAFHb6yVFdzvXafsTQPR3mR607H WE1ZdK4V5s+BBwRI4rQEPBR6jpZewC2JwzPzt5SgrmZil7Jot/baNGXzfTjg1s+jxZx+DML31U aaB/HacbLkegvVcBpLW4577gq0SCqfLnG7PY1JY7nPvHyHTws0bEUIgGgRjMfpZWBznoOlZfBv +MZKtp1ILj5qogguonse9VZmre6nGWnWJRuf5X6s1EAMuQ7bI5UzBk9J6WiOTaWbrbJcBL0DGi aAc= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:29:07 -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 v11 07/12] scsi: ufshpb: Add hpb dev reset response Date: Wed, 16 Jun 2021 14:27:55 +0300 Message-Id: <20210616112800.52963-8-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 d6a4b816814c..39b86e8b2eee 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 Wed Jun 16 11:27:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 461795 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 4EB54C49EA2 for ; Wed, 16 Jun 2021 11:29:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 306B16128B for ; Wed, 16 Jun 2021 11:29:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232524AbhFPLb1 (ORCPT ); Wed, 16 Jun 2021 07:31:27 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:30224 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbhFPLbZ (ORCPT ); Wed, 16 Jun 2021 07:31: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=1623842957; x=1655378957; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QmslEhEyWR2A2blac4IjPnOEJ4QqpiLz4G81vkdi4Cw=; b=ir+tL1sUB9lxyKFEvX7PuoqdeTkF0FxXNWCiZ1p0jzEjUgxn8RfvMtes gAc6fqxDP0/meqAHy8Hj9WWtk7hXyyq8dib6BcHWx9pn2KcnUaU5VF1eq CHqHXocTPwdVpIAqaMLBsGoAmWIlQtcNzL8vlcgPFwbH9iUSoJ6CfyqeG LNFOoRmJQPRbgmKKWGeVcG5IcOs089VUJWFI3Lidh//qSD3gCPU857Gr+ rWmdhIjl3/YUE4Z2dqYH2FZSyWPchrfqKzOYOwny5XS9mKNxJxDLUSAlT YZmNt2sC32XGtYAHtOx7y5/0DyVJVVx6BNZrsw/5RrjtumZM3N/5C97ry g==; IronPort-SDR: DZISGay1XOMLlbXb0wWmcdPtb2bg1MLqF18hlW7A0skV/dL1PbkpiaLwRi36rAjNRo+j3wbnte nmfXuBI5W+YT44Xr06hHeR1SZ/uAr1P4yP4cCeelRvuu3CBpG3jDkdhWbD2jdzBnCmML9hbFox fFyvNpJDUrUbP+ccmO9hD8R0uYWKB/2/K0o0NW7oBPHjGU9iC4+fzYq9MEYryGolvsxz4+ynKF sUMtV6f9c53uioCLcvf4bHbbw1UqcWEK4rgpw3ETiAUl52YZplwzGwq3srW502i/q/A7eokEOS mrQ= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="172091850" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:29:17 +0800 IronPort-SDR: nQm5RNgJveTV9r3KzDf+Qj+lHeIw7Tq7EAvthErX5xJECdqPvbpe2YT/TUCNCYQ5b7ZMAhb5pj AjqyVvKjakDlOicz6au0vujyMyK/NghFZCy50p5vwI+oUBQlMl8qNOPTFAyY1gQw/uwTs4i0qs vl4qopJ+DUOqYMrqFzsa+CpmF6XhmCgfUrAn5TBdotUZPY5vnENdUPPwrChSvnP0hiyRSnk1lQ DUQAde401HND7Nsi0J/GTGapF7otB923sDeBKEhv4cH6HzuuDJWjdGlSvlFn8+5kDM4qhZbLhb VKoVftTkTVAI9kvq5pSpEYDe Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:06:46 -0700 IronPort-SDR: Edc71OKVf3Ijq14Nixfq1vrlemrrAdSY9RTm50x00pH2OM/dDWdQ38ulkhGKcSdKaDs2Fa013o QNIPKbHe+oLCC08wsOq1o2VHnfgvAuJprkPwln7KAhjnq4Vfg9a1mzT/i1W1PXLQKZEAq7DGfO T6c55sp6qUif6fUIMk8YcUBx/QScewfYfyeihFzOI2XaKlTyy+0ZR8V/Z+w17XHt1DHkh6KPNt OReeNuHKQIIpYT/NhUBa5OOUi9cWi2wpYNLjQOANZbxmFWWoPClVJNychIUrX6fgo0pnYJQLOv i+g= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:29:15 -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 v11 08/12] scsi: ufshpb: Add "Cold" regions timer Date: Wed, 16 Jun 2021 14:27:56 +0300 Message-Id: <20210616112800.52963-9-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 39b86e8b2eee..cf719831adb3 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 Wed Jun 16 11:27:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 462618 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 51749C48BE5 for ; Wed, 16 Jun 2021 11:29:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F13161351 for ; Wed, 16 Jun 2021 11:29:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232582AbhFPLbn (ORCPT ); Wed, 16 Jun 2021 07:31:43 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:25358 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232565AbhFPLbe (ORCPT ); Wed, 16 Jun 2021 07:31: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=1623842968; x=1655378968; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FGBSV7gU77EqLJ6pQZAhOqU+1xzQhklp97zFvxCr8IQ=; b=fE8Jw2hv1YfH1gVQwzOcv7NHf1jNXFYbnVWBhDu/xWywK09hrcns9SHL h6vDCLRixdqgmAzP6movwyvf2PExzJ6WbcMRz+OLQqcczhgd5Uf/fCl8L k5PXoEimoy/cgV2R46cCC4n7Sa8d+T+12Pd5pRtGFiYS50UOL/vUUmtgL xMZJyTJYvqreOdpD81dYDSLxbnA5XOFwASUy0WGSfohDnyyubEWYVKp3z 17b6bRthbaqSwMH0daiqtQdL1bpcnMBhwi2iL2K9gdfTjfr+qHok0jvIr rUeB8rVGQ7MFrB2R+eZKHmI4TQ7qTECiH0+iPDvKJu+nwi/tgIsL3Ztk2 w==; IronPort-SDR: e9s0PyH4B2TK6lpOFrtB+Bt2j6tQTkg4UhtYvlqj/70Vtdfaf5FZ22uCZ0x44422104EbJS/fn rdx3ZzSPHSlkipdb+FWM2e9OyzrGqYu00dlZ8hC+EhYc6F6Ig8rPxOGq3LKRE04Rvcf5F9YhMA CL6Jt42J/tMio6jHuim0vsOEERzB6oHFgIdsJLmtGmtRZ7rewGjRX1WY9g3mF9F/P+pq2jFMFn +P2O13j2YDIZMTSVOyw/XLavcJyKW2FricNQvnp6It9FLcl8IOo6Q1eJvl2FglxVEEGdU9gm9g 4Ms= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="171352792" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:29:27 +0800 IronPort-SDR: K3soBkqP7ON/1xB8AvgaxKpUkrpOzAwA2EH1mEwvJQkr8A5d8IVcYY+k+ZtAw9RT0Yb2hzAzXQ oB+83apzxsOlITmuugN35vDRhBbXaUn+nuaETzmRsLY4F7hYNZfKF8d4vzgN6lt4oQenNae1AW YnGaHNEebJgBgMqAhorcc5Dkp08hafPvJx7zXsM8VNt4S8N6q8Mz0KcMYnhAzHf/YQFBE9u9Rd p7m+bmpJK/ohgrcqiQXlNSH3TprjQM/gMj1mpnbHEjACagQRMfLe/xqs1TW2BPMVXUAUOx22M4 b8+RjRDQLhR2PnFR+R1eGoC6 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:06:55 -0700 IronPort-SDR: mQ1zRgyaK28LfKzfqMCFPq1zETWSAMshVjhgsyIm5vOUF0wrEopEt3lXoL2dWkU5Wtr1oNHmul CAOFsWWAgFpaPZAQC03woRYqxwJhTCOwunhKpfVYT3Vj34Wmz7kDIL+k9D69rJjc+CGLwyOdGA qY/dLLIZhMl+t4SAHFpgGNywrh6z4UJ7YNGYGoKvW/vNVUBvoCYe/Gq3KKz5Dqyb6u8Di2B4sH 9hJK4Id9/9n1aiIbyNch5wWK60OjmtjbSSo8dS8kHxdr+yQtv3uYpEX6jwIrmHzGyTNpLpttbi aJM= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:29:23 -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 v11 09/12] scsi: ufshpb: Limit the number of inflight map requests Date: Wed, 16 Jun 2021 14:27:57 +0300 Message-Id: <20210616112800.52963-10-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 cf719831adb3..c9c1c39cb269 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 Wed Jun 16 11:27:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 461794 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 6118BC48BE8 for ; Wed, 16 Jun 2021 11:29:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A91461351 for ; Wed, 16 Jun 2021 11:29:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232591AbhFPLbt (ORCPT ); Wed, 16 Jun 2021 07:31:49 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:65418 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232555AbhFPLbo (ORCPT ); Wed, 16 Jun 2021 07:31:44 -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=1623842977; x=1655378977; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QEVwtoq6tjmcRLMLSE2RCHvwORFqC9XJA7WfJrOBcd8=; b=aoyTtc6K+neQeCZzemqcmCl0tjsfO9q5JdKaSQDpsAE+z2/Wnt19+uCo fYXYuF4bGMrmwzbwhYwnUusrUvk24n/bdAVoX59+TlQs1hJ9guIe4JhYI 3AU2cVRuSPATbC855CdYM72ESC5AQm9ngjbzM8TlYwPI8fuZJlcZgb2ya OhQldwRek/BWHBlPdJD4Im0bomF9P5nPxQiscUnYYjWttcBe4RUlKtvN/ 76QQkz3i1jQ2HV+ddq9RGs32cZj+UTAQ57zMAY6Rfg04CgjuVtwr1DfKX Zovv13x8kjyTFi3S/CgpsVVE9YkoIZBc/AmjwxhEYIkppTzVJjNbPuDLq w==; IronPort-SDR: 14tP8T/YzwyUJ5/xZ0nTTCB8H9D7d2O2RAU0DPW1Ksf+KSSF98+i8m7OhnXP203QdqblGtSbOU T7zUeo+eHOjjf2OCfdjGXvmpF1F10iPrGmPSfD4vDVNuM6H/1KZzSWiKRzXcTvFjvq5wEZdNOz HFw8KLHM8ZFI1GNLGUCKozfpvTIrI5t5iJlQrgN5YXdPuSDpzncudzpBp4Q/YVkdy/8IUokvz/ mrU6OOj2s4Z2JN7XAzwFmUo66pwNG7ql0Eq4PGnRyOYITaZSJyvfP1keu7UKvGJFvsSfW7v4Ii 5lQ= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="176876353" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:29:37 +0800 IronPort-SDR: K4yqGnX52Kb654057e+nNVfAg92l6rD7jx62gWZrDN9HJ3hmfCoq0GUQMDjexY0PS0Q0pCSWRt +3Bd9HDUPeXxPu02JMrUiklBQvmMwOFDSpVgjU1IYkFygMrEp5G0tBNF2SQtT/sMukWJG3GBGV 6zBa4uUb08m86U5llPtU92TvBlUuLkaH4iIJfHKzMGL/Jjk7Il5Fpj9qciNbhe/ziepQj4xIv2 gBTPKEaIwg/Ges55lHvVA5oF1LpN2iqgIkDCvP2RjD2mmEaq+4OUce7vwp+26Z8KyuhpWS6qzA gBkkK1hBwkMNuMtF5OGZUHbS Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:08:28 -0700 IronPort-SDR: L+93vWasVXbJT+Ub8qCFROmGMY75g3t0i6fBd+093mStB2g55Cjr8C52G7Crm7Aev2c/I6eq8h oNW9WP8oRHOENRNIcCiT1oW8aWMaYa/EApKc2rHQ51BftEknVTxKJ+xo5M2a/+vw7DX+zIe6rl wGfJ19qFyyDlXSdrv+7diV3B+wYOgiXkg/OHX9ZEMiuZPNM1X4+fxpPvSQG554650WrIINBjWc V6IppBAZ4GZ+/A85PB4Yohn0BMsQlw2juQc/ZYAuUxeHr5v2KtUDmIeACFo/yjsWSHx7WP8zIb +Rg= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:29:34 -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 v11 10/12] scsi: ufshpb: Do not send umap_all in host control mode Date: Wed, 16 Jun 2021 14:27:58 +0300 Message-Id: <20210616112800.52963-11-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 c9c1c39cb269..126de2987919 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 Wed Jun 16 11:27:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 462617 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 EC5BBC48BE5 for ; Wed, 16 Jun 2021 11:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D10586128B for ; Wed, 16 Jun 2021 11:29:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232559AbhFPLb6 (ORCPT ); Wed, 16 Jun 2021 07:31:58 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:25378 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232604AbhFPLbx (ORCPT ); Wed, 16 Jun 2021 07:31:53 -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=1623842988; x=1655378988; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rqBDSxgR5oeIA+/zf1rkyGQe7vLReilKmsbBFYMY4Wk=; b=qXVY6tXTHPzAgsSKaBoCFmzHh3HC/QkjbHWzxf1u/yqdKKR2Du4KjCAf 56ReK1EZ/PA12hclSZST0T5c/C24/tHpezHeFj4p+EOYF7FV1qTL7GrTt BVbJvbItkryfAbn/fSe56FT82W5YJM97gIXuIs0XfWvUnMRSOVJYHf/22 T9bQcRp7WfqvXnfa/TJnmmUpw9WDZd7Ql1ZyMunMilZXeOfSbQmvghCAI odmOMVzXjkY800DF2q3lJ+W6FShXeZzYRIWCBlIrM+926ba+1at7CoN3b iJHi7nDRcPR+q0qyGEIZu5U20EhnB6CmHZNHY/UqCj5OgLIE8P4wFFef/ Q==; IronPort-SDR: 8dYoY5fBIIZsiavjyIP72UkElbBSLZkMtxotMBg8ZaHk5WkmBJH1veLEMMdvT7Yaa4JjYVUcdZ oJM/geEH8guPfD0fJrKZoQTo6WyBJ1GIvxcvu72nC/73R/aCLTshFNHS4jtVTnqIMXGS+iJJHH WHh4ZSbuYJzqe99vYvEcukcZqmvMWEz831xzhnXMcc2oIjWXoKCyFlcUvDpKGjTYsUQ2IkYtJN bYNY+ezW8tILEoz0NGfzQpMY3J6sHpwl6lOF+fpOLI3TMmxJgDYPMp3VDmevHGahE9/gx8+T2j zjU= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="171352811" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Jun 2021 19:29:47 +0800 IronPort-SDR: 8/MRDCkHWb9JMjTOM5oGAJFrzCGFcfd67IxM99NSDulLMYxpoGpCVW76zKCiaA2bXRi/r7rpbg Qe+ISjJwvWYvzxAktZsdbg6iLu2G/C1LUsALveiQ0XFZ9gOoxTUOA9iUPqDhFZdJmzDSqKqJRK G5A2/ObP6zwi60ROb01cDGSJyxEWZCQ/u5mQbgzPkBBhvsLKPlt6Yp8o+vwD2wQR3hmCGcchNe nCqBLtI9ZNjRkZN2l90VYnZjctoGY81YcdVK/YRTYo5A0ax1DVSjWzA09eMZs0lPHE28jdj0nJ j7srntrX4oEOWcBIcT7FojKl Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:07:15 -0700 IronPort-SDR: js1LC9qOrI7vsXmWnbFXFggYxYv/W7Cm0tuYK4LB5WmNFgBuXdYHq6gPEqXRVFBPc2JAmOJgYo daX+wmsBLIWlLggRnV9ieu+m3bchUtgJ248Id4IJYYe84oIzHrnbOMf9QMfkB86UqqCbNKITvV ohn6sxOA8DcUv2uwYBxBOcpEd5RcH4Bbj72IX67aif9GmJ1/HycQNo50nS0c3yFeq9u7Easw1x N8fr7/HNty2bH/9US9ybRLyU+w9USQA2J+N0N5rPLsvcM8+qS11Liw8KwOzus2oyj49I7NopIK TSY= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:29:44 -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 v11 11/12] scsi: ufshpb: Add support for host control mode Date: Wed, 16 Jun 2021 14:27:59 +0300 Message-Id: <20210616112800.52963-12-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 126de2987919..ab66919f4065 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 Wed Jun 16 11:28:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 461793 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 17788C48BE6 for ; Wed, 16 Jun 2021 11:30:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F043861246 for ; Wed, 16 Jun 2021 11:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232607AbhFPLcE (ORCPT ); Wed, 16 Jun 2021 07:32:04 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:30278 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232602AbhFPLcB (ORCPT ); Wed, 16 Jun 2021 07:32:01 -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=1623842994; x=1655378994; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bA4z4tBNnxVUE8VEs6eI9PaGePrvlQ1yeXwqVRHvPoQ=; b=gApRdcD9hxwE7DDzj5P84obIhpGva4+6VmMstW/zocQ30MB6uBlPABAZ 2J3rEqTDPE5uKtMybpMkKLl9kw8KCmSf39u4wNiDh0gHRMTZCKCX5bxu/ VePPc6PubhC9NjdwTrbiAglVcZq/3oPBiy7YViB0ZD1BevDc/w5JFJG+c INdFvxjftDNa7TyzrBbu9l8g8wxskgi3Kd2N8Ev4Y9+zEN+r1EgcxqStf fpSHyj/rcD4hViYKeeQ98wBx8wxw33x6z11jqkoAWtu/yppoPdlBwluMm oZ7XDNVnj752YYsyyGwPA5cO3UOxTJPEz6ahMaNJGDO31X2U18L0i5okT g==; IronPort-SDR: olcv8VD8swCRTmFvqDvI6pV3QUALceEAr7KKSYpJphw5wE4bvl3qxaWmHmEAgjb4usW7fm8YPo zNmmMQFWHpNYU7MJba6gZ5YXteuie9kOkd4Q5KtvWGYFrtyP+/L5YkIUEPim4IiHAoxz5QJ0VN ngQL6iqIxnKo8nbiFa9yrr/4Kz8wLFRmGWezfphbYlU94VLFAxgOYfUfYJmAiDl1lhHp/p686S aX453E5yOsjmtOKzXi3dTLTXtjOOQAtnsmt/kbHhNGqAWv/nX9f+RcBBtYAXY1+FTEtQxjrk1T KX8= X-IronPort-AV: E=Sophos;i="5.83,277,1616428800"; d="scan'208";a="172091909" 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; 16 Jun 2021 19:29:54 +0800 IronPort-SDR: obkJulFVU1FTa7Rui9xwgsoUX9PvxNTCzUpdZN8Dysw7TMl/XmCSBC1a2TwFYdsqoF53gddKVZ TC9a6eSTJP4VIbicISn8dU2vxzLCgVWSf80DyTdxwMXrSV3DUYOPpPx6XXtXNF+D0eXRYrmy38 rNzNJS4h++QQXvtdgkw5dj5JQHrIIHTggBIVwolgIwVV0kuRJfj+aJl/HsDRIeZykw3Sa54/Ls pzwy8xdfH/NionBbal8d/vFRY5NLbFphcdqxY+H/9WWnzaX8TEwMLrUeLU0cM//ga55Ru+JKJQ 6x+uGPeGZRF6Eu3OsNFAtelJ Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2021 04:08:45 -0700 IronPort-SDR: /rEKIf2b4/AW17IvCinhCPYwjWoga1XNFxvEnye2Tyww9wmkeEh4yGCc/0O/baqqcyrLt7WwRZ EPoySZRHnlNSMnG1yeR9yqXXNEW2xbZa7S8jafGT69r66rueS6uGWFsbGwDWE1+vxKUtnIQFlY vq6gE5wzplyDlSQPgqJoDin90otier0NaP8z3zCWCOkIBiY0SG7LdsbnLfrimmAHmzebw8DtC4 3UqzYJPAX4eB9/92UW5D2UoLxbpEzlVQPYEwZd69kIA6eEAG6xzPK32ISlBn8WfP/5u29uFwpT /0A= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Jun 2021 04:29:52 -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 v11 12/12] scsi: ufshpb: Make host mode parameters configurable Date: Wed, 16 Jun 2021 14:28:00 +0300 Message-Id: <20210616112800.52963-13-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616112800.52963-1-avri.altman@wdc.com> References: <20210616112800.52963-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 d001f008312b..b10cecb286df 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 ab66919f4065..6f2ded8c63b0 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 {