From patchwork Mon May 24 11:19:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 446692 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, 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 7C9DBC04FF3 for ; Mon, 24 May 2021 11:22:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51B0261132 for ; Mon, 24 May 2021 11:22:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232614AbhEXLXu (ORCPT ); Mon, 24 May 2021 07:23:50 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:43182 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232517AbhEXLXt (ORCPT ); Mon, 24 May 2021 07:23:49 -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=1621855347; x=1653391347; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g8YJqqHhsUD1hXtF423Hwl8dEqD1b09rkmtdLn0wQjY=; b=KVSfCJrZ5IshgOUNunGDI8TZeOQ2ORGqE4BkWPcAvf8CfmtDU8I7Mjvv 0ZBFuqf9DQ90dznFYNElCUJUTWgXliubD7brVJOxKuqN5WyOtEXXuI6xM jpn/RbOiKHyaQrHpLt7CR3MGpjT1deELa6XJmVrXN1AS7wHV69ci3IBJb XOo6mfak/F3/jYigZ97+YYpbVpAVw8e7XCf97vy8Srgwo/ORw2Db8XzWR 8Az+MuziiXOOg+RBa8qZrw/rGv9araUNKsI2SEzsn/brTeyDc2c6w7FnE JtvUiWRuRUq+QkVyNZgHAbj3g9YDz2NfZ+mS5CnqZySMApnFyXynOFx+e A==; IronPort-SDR: YqwU85lWoQVcq1METLHpyMlsJv8Ov8DHDkGyHovuEYiToyg03f1ERYM1NR8ywiNyCu06/jCWmM Tqo727sV3Wmk+EAwlrqy/iYX832E/P8WZunBq6Nb26Hv398AQHr0btzaKuTtJiagfNu9qHMl+K X5PGBsDOMolp1487hj3aOlKNlYPNxfLdScj1zFBuCVjTeLFWWRZmFSp2m0H1vd/kTyPBoz+CrO B1Pp4ZgVqFtpfP243l95gMk1DCpdkD272eMqa5tr5cFtRVc+9BFHqBv6ZwQmACrHy1Np7M5Pw5 Xr4= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="273140489" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 May 2021 19:22:26 +0800 IronPort-SDR: 7dh3y282h0/WQU8AUc0b4+T7B9qpZUuLHlvm1Tuh23U5yaSokWTQdhqoRkh55PJ8UR8JjdSI2V JYXcYK8NO+8j3wZnubtW6eTCNau0p1GetMNbOyTQGuAKGOq2k10B1jdBQ9lRcXJ02qct4vwtDU ItF5fHjN4YzTBinHNvJTT7szB6ZmsddWkr9UCotAREym47OZd3hXSTmotyYcc2NDQZRjTWiKLB PY9Z2BcqK0e5jP53tS3agcIl6I5P/9aQMPvl13Gx34OmyHE92Yz3k03FyKGHXrczP3whcXa1Lo 1cEYXaVqNIAWJl8wnUFuew6g 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; 24 May 2021 04:00:35 -0700 IronPort-SDR: bbmMT2uGy3ldJbSRANP4fr8OpDH0ormeYVw1XTE3YFQfJaYap4/PiGDUvOf4HHKTihawp9GtwK zMsgbXwR3kMl7MqjBxvh1joFvBhCuU1Tz8xKqy86OFUL3YpTKxTwwYhx7oqojSTNF0CKAqTanC pUq45k3QpB7Jsv8ZNC7EkZ9J3Ala3KbFluWFQC5BzbnkW/Y6pj2op3/UUtDsdj0WPn64HlBUWd Qm8v7LIz9iV2HzTKrivNyqV0eosYdDKL6odN/kLP0P7bLveN/Gglnhf0BADTOIUfcP5VJk+I/4 Jik= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:22:16 -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 v9 01/12] scsi: ufshpb: Cache HPB Control mode on init Date: Mon, 24 May 2021 14:19:02 +0300 Message-Id: <20210524111913.61303-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 b6b294297a59..dfce84b17561 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -673,6 +673,7 @@ struct ufs_hba_monitor { * @hpb_disabled: flag to check if HPB is disabled * @max_hpb_single_cmd: maximum size of single HPB command * @is_legacy: flag to check HPB 1.0 + * @control_mode: either host or device */ struct ufshpb_dev_info { int num_lu; @@ -682,6 +683,7 @@ struct ufshpb_dev_info { bool hpb_disabled; int 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 85801e35a53b..08290ab34f58 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -1612,6 +1612,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) @@ -2303,11 +2306,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 b1128b0ce486..7df30340386a 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -228,6 +228,8 @@ struct ufshpb_lu { u32 entries_per_srgn_shift; u32 pages_per_srgn; + bool is_hcm; + struct ufshpb_stats stats; struct ufshpb_params params; From patchwork Mon May 24 11:19:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 447717 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, 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 A2624C04FF3 for ; Mon, 24 May 2021 11:22:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 806F6610FA for ; Mon, 24 May 2021 11:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232513AbhEXLYS (ORCPT ); Mon, 24 May 2021 07:24:18 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:43226 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232517AbhEXLYR (ORCPT ); Mon, 24 May 2021 07:24: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=1621855390; x=1653391390; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8oJiGZWvCOYhNCjPFkvi+zKs+g6YfPSJL7ChfduYeOo=; b=GQF5jnyw3v0MW3o2M4/Jo0Qru3Gh7yNh7OF9qhi6JfRteuHwWDp1F0uo B+78/mqDVPm1zM7O9uOeQ51oS6o/v/KQTvWb2spRP25iLtQhEaVuEAIEo 7KvPJCUfgXzQrd4OeBB04oEjZVUtRY3/dIjBHjBho5YFNxKwFPjmQsmGx EcQcweu+m+ISYvRYUhZsIwwk0cKkkg1NTOeq3IyP2kLjSTRdNtrisrUk2 mRkYhs49f68fa8CtoO26y2fhXA8NB2ENwuEVQLkCYjA7CKZUbMedh17ij rNcVIPHJ2tmLFgImASmw9JiJGyF2zkpIpMx3+T16oZBE35QsW3J/rAVxb w==; IronPort-SDR: CaetfJEPR7QLof4f2h/VTHDLzR7joemhp3fC+evSWVynNQOS8OjCY3zMww6OC4QmagSSuuBhlA VxMB/Fid4Y7rLpoFM8uNNowylEwyOiqRAoCJMeRjzc9G38kYqyEPWQiyDY7UqENeroW9B+Nn89 Fugi1D28ES7vk5jq3y+VNtjpckhP5zn8wf1B5NTqOyT1yxiJn/7IOk/bOiEdvygTVCK72y7g0E pdwG2yCz+1Cwr/FJ+OfL1faVWLtCGW9B78uG2p/U6rrRRMRWRaE+nNet0Pmn/di1dC/JFfz4oS kUE= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="273140516" 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; 24 May 2021 19:23:09 +0800 IronPort-SDR: jkSb/5AuwkTx2qB3TEPCPa1qQivwXW/znoaiYCNoa75KZiwGpn5IFSpPS4pNyAoNSidCZ34nMI OKpD5b2vL2A4W8BYynYvIqvZRiXybDguCBlt8eN6CZBr/eIre6RWnjQzWIRn6O/jvS4Po2lwX7 BcgJq3TRDiREiC6ivxphI2uZuZQAZ/d5VGJlm6W55yH4IviGB/5Ho3Wqvr8Lp1daZty7/96F9F eWxJtmfs+ocVAf2IVbn+Ho6KesanXpTOZhwEKbTgUOlGaMMFBAxd/af6cmdM65KXgquwOsbtYt Ggvienth2C1EImEreEVjxQWe 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; 24 May 2021 04:02:18 -0700 IronPort-SDR: nKpxCPl8dHM7ZQGhwKMbHgehgpmAb2Pw8Qmt1sJK+siWrQ8J0qPgm+FSvdhZ+d5rSMQs4uZPEj reV0HieKJjYYkbDn1T8ijAObdlEqZgy8U2nQflp2qe3bf0Q9781gUF3R6ZpNQZHjtw1ND5X8pO ciC85xnNeCllu8v2AplemAbmPyiJovVPdB0IdttJjieFWUvMncbA/zHjtNKGgLZddCFDWBIwgp OnRO4HtZIZDZHYcW6TxswkAEIJAGqjcdclcvziCbAO3joGc+oU+qejHPeiWsh8/gDWLIzKVvW/ DcM= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:22:45 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v9 02/12] scsi: ufshpb: Add host control mode support to rsp_upiu Date: Mon, 24 May 2021 14:19:03 +0300 Message-Id: <20210524111913.61303-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 08290ab34f58..a19732b5f8d3 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -166,6 +166,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); @@ -235,6 +237,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, u64 *ppn_buf) @@ -710,6 +717,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) { @@ -723,6 +731,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; } @@ -1242,6 +1254,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); @@ -1249,7 +1273,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 */ @@ -1260,6 +1283,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, @@ -1284,6 +1315,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 7df30340386a..032672114881 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -121,6 +121,8 @@ struct ufshpb_region { /* below information is used by lru */ struct list_head list_lru_rgn; + unsigned long rgn_flags; +#define RGN_FLAG_DIRTY 0 }; #define for_each_sub_region(rgn, i, srgn) \ From patchwork Mon May 24 11:19:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 446691 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, 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 910D0C04FF3 for ; Mon, 24 May 2021 11:23:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F8DD61132 for ; Mon, 24 May 2021 11:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232693AbhEXLY3 (ORCPT ); Mon, 24 May 2021 07:24:29 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:55116 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbhEXLY1 (ORCPT ); Mon, 24 May 2021 07:24:27 -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=1621855380; x=1653391380; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/iSUc3xRkBe0Jmn+hxK86Y4EAfWDCXgC+AP6lA0Bkxo=; b=gQVv1W3wT5Osj92X4kPPzSfUrTn6ZrTkSXYQLM4a4D5l/yhtxcZy4fPe tfGqV7d0D73j4QsCwnJo9+WAMGQbels9fy6Ki64e9eTGpWI86QqxQ/8pv 3sFj5z8VE4/aWbM+d567mQwqJCVc/Uj51QM2295VcoF+qk9X14xKE3Cvj vy0GjkUSq+DwllgLighQrhAAUysr9+HnxoPcyecOJHnnQ8fPDpcHXJ1Qm HJpOSZyEQ3wAYj7qgJyrHlj8aINKgiMXTXu/A5VnWdXTmTGjnp7BrGtkP Ecp7bkm1aTLOoxiCWK4sI/xUt7gJuG0qIXUHhkk1N9CX2HQsukkIOI4ZT g==; IronPort-SDR: vpCMy7W0wOvV7p8Njjp507hIBo8U97XgV+g1ihWD5TW7WZz1gSyi7BxUyP3b4urhrQ9/Hbt67t AEIrugF7RYMFEqjFAogrwpod5QAeO6vX4+z6dySpOsDqJ1rWIQjck1eA5Vf+jJj9iBqu8K5ji/ tpO7+OsNU+K9TGAX9gU5vT3uIXYbyubDqaW2JjYg6AZWNBrs87XcqUyPaSGHV2kKmtkkwAGJmY fJXhI9bUNxFBv4ZBHhP5LLfNykv314JppVrRTrrlxoGBDuLRdlhuCmV9zVrs2AF8sJrO0CGSVT tbk= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="169770928" 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; 24 May 2021 19:22:59 +0800 IronPort-SDR: 17k0bIXx5WmDYuScAISqOloeS5gTycy6UGeXHjxE19QPhH7MyaE3uEIDrakwvbMMNuyUoLfpvv tllMWHB8JCH2Ms7tnazctbzeiD9IxO5Bo4GB4I8CDx7ydXvZEfCzHPleW6X/qGzQGQMbcCnhjc r6ZKb27k16YaczUGkHVTXwmV5ox1y3qk2ZBroVQOMdbwKB+ucP6I2rvlda7OgiMTSRISjoXJv5 3a+NP0VBwXy9LcqGGtZZJ529D9SO9OLG89BkCWM4Cb9a4J0gXCpa5T5gFPE6iUplEUq9utywCm i+W4yTL3BLlXjYl4UuvSrQvA 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; 24 May 2021 04:02:28 -0700 IronPort-SDR: IgT9egXin3bQgG4i4CItxSbVv+/LHxVe/XhF64LJ9J3b/DnBtofe+f/XbpsfHaHgeoS9J5sx0z 2fZ1CPYcjiTPo3n/Gmnn62qRR35uB6aqr11aY9fC/voIocJ5G+pWjYhtLaQVxmltZx10qXnFsc I+5a0J07vTvH9qb+18Kgsbf7KkWaP6xX5ZHaDlTCLAZg5e+lmr0GVyXukIYlLboEaj1yjaGtP2 ClMv++REEbg0cbwAQ5pDC1f2rTRN9EjNCk6A5BnfYr2cl/fHYFS2Ds8QHnK5q7Uu31Utw5FEHI Ajk= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:22:55 -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 v9 03/12] scsi: ufshpb: Transform set_dirty to iterate_rgn Date: Mon, 24 May 2021 14:19:04 +0300 Message-Id: <20210524111913.61303-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 a19732b5f8d3..0a50eae35549 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -144,13 +144,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; @@ -166,11 +167,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) { @@ -590,10 +594,8 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) /* If command type is WRITE or DISCARD, set bitmap as drity */ if (ufshpb_is_write_or_discard(cmd)) { - spin_lock_irqsave(&hpb->rgn_state_lock, flags); - ufshpb_set_ppn_dirty(hpb, rgn_idx, srgn_idx, srgn_offset, - transfer_len); - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + ufshpb_iterate_rgn(hpb, rgn_idx, srgn_idx, srgn_offset, + transfer_len, true); return 0; } From patchwork Mon May 24 11:19:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 447716 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, 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 4211DC04FF3 for ; Mon, 24 May 2021 11:23:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2807E61132 for ; Mon, 24 May 2021 11:23:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232760AbhEXLYh (ORCPT ); Mon, 24 May 2021 07:24:37 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:55129 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232719AbhEXLYf (ORCPT ); Mon, 24 May 2021 07:24:35 -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=1621855388; x=1653391388; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U1w4yULBML4WMznCh3dedqv2ofmy+4c6nMYBArhfDw0=; b=d9XOE4pvHwsj9DGwTFerDU6kkrvhkpK+Cmk6/Dvkwz+Mdgj4SQz2iAv4 S8kgIfEqsDdyPYW6+crZLqotzJ4SNtsfvrahxQCVBZi7g+p99CDoZW/cb N5DcUdTf96AFT5HsEBQzgtSUJkoJ2EqarcnQF6irFENKR6unhHBykRIYs h/jIidu4zckae4nz05vN8cKeZMpf4k4hiFxSxsihFpSAGSxpjuaY5Q4f5 o2dpdQdzn5iTf6P4EM0X4ndCK1pRZ9eaXXEEdjjkBHy6m9sj8NXS/Jwz1 eq9TdqpeXNyfXBXntd+6p/kE4xyUOha2GBXBEKeOb8a4UWZXp94rkuxQ1 g==; IronPort-SDR: p+/zCWAKhEA0jH/8S+ln9aNFK3Hdn9YOQNsfT5O0fvDyUqu069wkT/GTdD9pwkbSmlS63ZgOgq TXjTQ+E9gzH79ZIjHZUi1OIl3joiDbMu+xyMmdpiGGkdWMIMNOkvjZp4PD96xgrJ9qDgJQCjyg Vq9EXD7xEIYTW/hZCCcEuCdcQ0Eo1JHT20B+b3miInm8TlsXeGLYYc3mckMzsx3wp9C4vtrrma OvQRJEUj0R8JiHhHxUvvU830ncpTIJ/JntmTR5ALkdCkBQMOohZos5iwFU3Awfc+rvxajBrHI+ PU4= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="169770933" 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; 24 May 2021 19:23:08 +0800 IronPort-SDR: 55ojW9obuMOz5g0YVBbDO+A8e4SX887gtvoc0fhEi5NlDs8B1vSwT5MQ/82g4IF+EnuT/Ia8qw Vw+wn6pRIGhEw+jjoig37wiMYAcgJRqe8bx0oBJlH0eNSLSIv2FvTIxt7g4LtoSaSM0v5mIimE /5a1Uhp7R9moKGH7ImR3xC5sDgLdMbR7FVvWXIULHKW+Dh6H2qpJtbk9ScFPjYbrCi8ItNiVVI j6JzcLUw+KPLpkeEIYcGIKaaEXUtlsJo5xyvvPddaYzdLlyHSrHRw8V5o0sa6FeHQFCRHGnPy4 ypocPiLL+QOjOA5bdCzMJRXQ 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; 24 May 2021 04:02:37 -0700 IronPort-SDR: zcLcHLBgDRBfF9Q5H6NeWQVc+rhjA0d1yp5Fw8duYYjLmvCtMJNkBaLAkd7NzjeoPOFXkvRaXD ac4UOpHMTrN6e2Q5Qp2tosMFq6mlsobLEQUQCNZp6HsDxAlfr91xY0Dmol/gUMf3mI9Q4wCvLM Tu4neT8aSsgBsclsd1dV5iJ0YlW/7eYYBjTpGkHLV0qwhdKJQzwVxnn7mFxOidmthE6D6nstLc znn7SKpPMR3J76XRl+WqpXGDxTjUpX9X0MOuH4eqjWew5gprdcEt6DeDTjKGA2hMqHUODl+bnU u1c= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:23:03 -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 v9 04/12] scsi: ufshpb: Add reads counter Date: Mon, 24 May 2021 14:19:05 +0300 Message-Id: <20210524111913.61303-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 0a50eae35549..e3b1eb857ce3 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); @@ -148,7 +153,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; @@ -167,15 +172,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; @@ -602,6 +631,19 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) if (!ufshpb_is_supported_chunk(hpb, transfer_len)) return 0; + 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)) { @@ -753,6 +795,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) @@ -768,6 +812,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, @@ -1088,6 +1134,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; @@ -1282,7 +1329,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) { @@ -1314,7 +1360,6 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, } spin_unlock(&hpb->rgn_state_lock); - hpb->stats.rb_inactive_cnt++; } out: @@ -1513,6 +1558,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); @@ -1671,6 +1746,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); @@ -1910,6 +1987,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); @@ -2009,6 +2089,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 032672114881..87495e59fcf1 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -106,6 +106,10 @@ struct ufshpb_subregion { int rgn_idx; int srgn_idx; bool is_last; + + /* subregion reads - for host mode */ + unsigned int reads; + /* below information is used by rsp_list */ struct list_head list_act_srgn; }; @@ -123,6 +127,10 @@ struct ufshpb_region { struct list_head list_lru_rgn; unsigned long rgn_flags; #define RGN_FLAG_DIRTY 0 + + /* region reads - for host mode */ + spinlock_t rgn_lock; + unsigned int reads; }; #define for_each_sub_region(rgn, i, srgn) \ @@ -212,6 +220,7 @@ struct ufshpb_lu { /* for selecting victim */ struct victim_select_info lru_info; + struct work_struct ufshpb_normalization_work; /* pinned region information */ u32 lu_pinned_start; From patchwork Mon May 24 11:19:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 446690 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, 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 2CAEDC04FF3 for ; Mon, 24 May 2021 11:23:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D8F761132 for ; Mon, 24 May 2021 11:23:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232762AbhEXLYn (ORCPT ); Mon, 24 May 2021 07:24:43 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:17436 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232651AbhEXLYn (ORCPT ); Mon, 24 May 2021 07:24:43 -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=1621855395; x=1653391395; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OnMBRzrruyNOJYDo4+Xotl7uoG9aAm+mR3kOeI0xjqI=; b=AUlC/HLTQ6bbWJsOuJZYJArqh2PZzjGGDZCBUYjpnuKJAcJoZKM52mgU HiotYQOXOJnWdLX94ai1L7MQTD9ijYP4sMg6+Wt108CUJXVxHade6tqET UetenRbiVoQ0FNAMQuZ+bJCuT+O/9fGNjtDsLry71IKrWduqdenEZCLGG EIdS2OcNJeM6WxuJAHeYMekX57RPpgEwr6JgXhQ0AliQjY30nXRFZEh+f sfRiAwoZ6Tb3uwvOXL3TqnfjQ0lEG5daac+pGDjNDMC9GopCnlsqn2fq5 taKqEK3HxrvwiDeNVDvcAuMkxFXKi99oNnkKvnyEBQc7c3L6KDkX/cl7C w==; IronPort-SDR: wiebSsQ4F6LwOh4Md1nqRxNMLWPa1tHOnaBZsNqSFw0AI2nppCvj5SRBv66dW4WtU0Nk2YSby8 8JOfdbu20pJpQJEXMYjG1bFWaUzzC2A5bGbkdLWrdokW8xo13zYZmfWz0FK0QKozQLUEawg3xv rv+aR9JZcfkjF2lPEOe2Jo+zejpcJzPhiJY3NA+MrNKMxZlLZZk/LmS2aLNjCfAOecxrb+lCM4 oMIGDCASDCymo5FJYJh9n/xLM1cMY0Z/w+zgpa+00NjfXH+bAYdFM2+NZ5KUW8hOZ1z4H5Xv+v NLc= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="168540286" 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; 24 May 2021 19:23:15 +0800 IronPort-SDR: XJ2l4Vc3S6Fnfy3u1qaBc5LnK+DDTdsxVtSIbHFcVBFvpvevEqQos18eWkaghLhcUwB8OpK0oj ddG+gsP7zGxRTrGd5eYjAQ/2ZowmigGt5EnJVEAyac2FpaqERYW6+0ngt0usT3K242L8rAg3yb 7cX+b5Qg7WBVMVxMvIZ+z6WbSJK8ZF6XhXWGaecD0tJm4ZTxkDWrxTkdlUCsWvSbjXK9BUf6qc 31mkZBHZgUi0/wRvSC2GwrbLveIPtFX/pcpK2dtW8SZQegPIvseY6J5fvzGOrEf3oPdTA+fz4n Lf97WKvnCsmhwwIKIGLpvGCr 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; 24 May 2021 04:02:45 -0700 IronPort-SDR: 5osQcLZdIrzGaQrzHARDRVNZ59ns++CVTgxSwBqrNHPh8tzi3IsXzPxoO6mHf5aZ/4+P311Mjb LPNYmV+oh8KspY2wtf4Vdczmfnei/K+3QrT8kjf+JsiDuZWCqcPp7YYbrF6eLvg5BLtOPdtXPw nP8mQ1jowpiIIn8+4xb5IR62ZazhnDc9zwsu3T53LpQ1f+SxgylJZsiHPTxoWnXVO9HLoCuuoR HezkvbfVSTqij0s2Ya4QPFU0qpopEX05/zeAwiOY4iP45CjGXw3QymuGpktvbW5Mm6suvWlyyo tfs= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:23:11 -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 v9 05/12] scsi: ufshpb: Make eviction depends on region's reads Date: Mon, 24 May 2021 14:19:06 +0300 Message-Id: <20210524111913.61303-6-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 e3b1eb857ce3..180e74675912 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; @@ -1055,6 +1056,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; } @@ -1227,7 +1235,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; @@ -1254,7 +1262,15 @@ static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) * It is okay to evict the least recently used region, * because the device could detect this region * by not issuing HPB_READ + * + * in host control mode, verify that the entering + * region has enough reads */ + if (hpb->is_hcm && rgn->reads < EVICTION_THRESHOLD) { + ret = -EACCES; + goto out; + } + victim_rgn = ufshpb_victim_lru_info(hpb); if (!victim_rgn) { dev_warn(&hpb->sdev_ufs_lu->sdev_dev, From patchwork Mon May 24 11:19:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 447715 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, 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 43677C04FF3 for ; Mon, 24 May 2021 11:23:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24FF761132 for ; Mon, 24 May 2021 11:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232806AbhEXLYx (ORCPT ); Mon, 24 May 2021 07:24:53 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25872 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232651AbhEXLYv (ORCPT ); Mon, 24 May 2021 07:24:51 -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=1621855403; x=1653391403; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HZ1/03jdESdDt4jNUFCkSdJlnvse+EqIr/O1w7o8zds=; b=e2FbQlsDnVIKeV8Qxdglo2/3jHdpuXTgC95lqF2EizYJ9g4f+ew9CXA+ IfuuoAOl3RXYo5XuXmf9D5SaXqGHWrjqaVACItrM77imJXU8mlaWYnk/F q7i3F0MgqDaSa5cz81U8zqtWgr9LdUcABdibP6GRxWIE+tXw6182J/kvp 2TIOSdySgLLfi60A4+HvfcI400NP0MN2LMInzsCR6fPUZZjZyuipH3WQx wHU1BQ7g1AK4eCHaiTggl8v+DREswTsOxeGqCElGtZtyBYmEI2vFo4uQF 9DCDBYahJYLWaVT53F7yqzWdZhDj5ZWybLqdfbvXx8ZtDDwluRU9BdUi3 A==; IronPort-SDR: rb4I2MvO8/e+HTIF6gBSW8/cwpH1cIEy5npmFJEzLdmY/0cAAu6eKN7MXCKY0fBIJh2HHptdUY +Yac1xyAAruzPR8JVjaue7mJg+EA36e7mbTz2bNDNpkYnpccHPGpW6g5N130GHVcbfzN5lypr6 FiGTtfGAtmmNqrHhZXxGwH9n6rKF7HqicULTtILc9tgyPnFEv/ivKoe7zKnG95d+jqJbtIByxs zuLSzlP2EZ3pJVN5AqFQgIr7L9IjPTK4SYbuJANNTaPwI9L1eqQAR0oZZTc+7oPRLdLcdOKMhE ebU= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="280526031" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 May 2021 19:23:23 +0800 IronPort-SDR: Yg1yOoaUQgJI2X+FRo7v0D5TXbB+Uz9zisnZpfD9Nx9XT75i8GvNJrkfAvh7HbEQqmkaXzJnJ7 6XWL4GnqOMbJqXCIm4rcNUCRpqhN6r2X2oGWjLC8jYnCUBH2mWrYVTcVBA+QCu6r70vGzpSojX CbJ5CpQaeTxKlWMQJzA/kyGFoEU9cKWmFIfbb6YU2ZC7aESZnjdxI994bFfMqwzjIoiNVRMrz6 sqe4Zs0AKQQjceu9DWRs5guAdDNCei2ije8FOdEJMVprmEdCD7kzw5fUtdut6mJX8tepyF+BUW VH4MWnNAZizc6fAZ5JB0CzYw 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; 24 May 2021 04:01:38 -0700 IronPort-SDR: hW/Hc25l3yHV9IV8VglwdC/coKgDR+AOVwBI49iebNzTaMzUz2yHXCIT6gJljjRnCiFZhpr8oJ 4Cy9tnvX+cRcOpzSl9vYxRk3kyawEYIpEVyx6OnrIASIRLvIB1gWin5purKQlJgfY2gGk/U/Mf TOVenIkvYgNoIYTzNyl5TEM+aXS2BUtP1icL7T4rD+YBL4ABZa2KSgJaUiCo/m8x8FUPzIatxD +gSDlRECiU2oiJMk28OHYf3flynEhJT185fBQtIowAF7rNz1HIG3KTaCP83jqdsfZJYf/xYVAu FQU= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:23:19 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v9 06/12] scsi: ufshpb: Region inactivation in host mode Date: Mon, 24 May 2021 14:19:07 +0300 Message-Id: <20210524111913.61303-7-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 | 46 +++++++++++++++++++++++++++++++++------ drivers/scsi/ufs/ufshpb.h | 1 + 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 180e74675912..0d010a343f34 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -689,7 +689,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; @@ -703,7 +704,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; } @@ -734,7 +735,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; @@ -912,6 +913,7 @@ static int ufshpb_execute_umap_req(struct ufshpb_lu *hpb, blk_execute_rq_nowait(NULL, req, 1, ufshpb_umap_req_compl_fn); + hpb->stats.umap_req_cnt++; return 0; } @@ -1089,12 +1091,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; @@ -1108,13 +1111,19 @@ static int ufshpb_issue_umap_req(struct ufshpb_lu *hpb, return -EAGAIN; } +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; @@ -1149,6 +1158,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: @@ -1283,6 +1300,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); } @@ -1851,6 +1880,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, @@ -1859,6 +1889,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, }; @@ -1983,6 +2014,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 87495e59fcf1..1ea58c17a4de 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -191,6 +191,7 @@ struct ufshpb_stats { u64 rb_inactive_cnt; u64 map_req_cnt; u64 pre_req_cnt; + u64 umap_req_cnt; }; struct ufshpb_lu { From patchwork Mon May 24 11:19:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 446689 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, 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 318C0C04FF3 for ; Mon, 24 May 2021 11:23:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16D99610FC for ; Mon, 24 May 2021 11:23:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232829AbhEXLZG (ORCPT ); Mon, 24 May 2021 07:25:06 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:43308 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232706AbhEXLZA (ORCPT ); Mon, 24 May 2021 07:25:00 -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=1621855431; x=1653391431; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=90KIGp0u2Y2Y3vVUouBxy6qJk4x1dGxUCOvkrKN2kss=; b=FOP19gndmDlayomVuiJBvSayufpHsQRb+X0fctBpK4zuySgfbXzu5wOe rlHO0NZtQp0jq8wSKeShWz7q6MnT6uLUHqW08PnLlX9F9RSA+ggt3uRoS hu5nLeHHI+97lebtp3unijhNCi9JqOMDpu9tlVPrmVQ80FFj7AUhwuijz tcw4Tg3DajqKJuAaepWcHzakZ8gnqvXTM2SdmUim69cD2BEEPfHY0t53v Gu1Mb1W2YCPd3KdY/iFNVWDb6IpAai9T7oB4CWyOzfIrBMQ0ThBLapNEn Ark7MhFr+lUO13w0e2mms3ZyPtIOCOsW2H7eNpwb6gPvupuypUFbXs0+x A==; IronPort-SDR: s5ADGYxlVAPey0uxSahbjO0+eS793lnX7iHVWtpLbmKsSnfedvLZiJEOXJdcikYe9F6s8pCjRK X+Ziqw/G/KQuZZbev/OXxa8Gw6DGYJthR/yISlLFZOrFYSV/pQKKYu1D1l91X4Ejw+REzk+cJM yOhLAUee8FUdjJFSXMEX6KWZMN65vR0/5hZbu24HUsFrSfBmqYrZ9u8tG8YK5bh8c6LMQEjn+i r6CnUZL/r6iiSqcoH7peGmvhyo1r0ca0m0M+GTdJGfxscTO1n7LIAUfrKwz0zFcgNXcv5TShjZ dx0= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="273140565" 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; 24 May 2021 19:23:50 +0800 IronPort-SDR: deIP+qd8pl9i6+8E/9dmSFG11MUCvQrGfZid+nNhzC+R/ZniZMKYRyGZ+vfMefQQ0YAgCSNKEu cd6AGKZ6fug76dbxgDYrMYQStc3/KtnDzgrg+E9FoyfMs9PZM8mTXN6myfQ9SxQ8KvCk/zy1ac mOMtXBEWMm0miLnunHu6oEButgmKUgghstAKIkl6SQt9K3p28ZY+TzojvZwmW0EB1gskl3h2U1 nwP7mcAAjL+78lhmMLflyAgn/0Lqr0PE8y17NNm4biGtIpRa5Og+FH8sFoGV6oXdHQ2848MMIi p4RRjY6xy8I+lV6tIekiHq0H 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; 24 May 2021 04:03:01 -0700 IronPort-SDR: iLT3drKCL2pvSMIqikBWnEScoLKsFVLcGU8mpsBq0xipQJqG6arxzsGY8ZMxpkRXi888fzZRn8 X9LdK/zT4AYlBQ9IsDdKtNp8AEnemQD63B3ltQgT/tGZ+Q1EP3QU/WOc9pRw7AymG63OnzwOr0 7aHPbbqNz1M4/978xZxKScCbiUf5iUcFRU3dKMXHcAYgWaUDwks6LeY96DDG9LITrR5Up1/5RZ /xce6IBK+oQ3VeWKP4Wx3NCuD0TdbbmrY/0jzT5xD7u8vkABf+6SDLoqI+k4paUL1BW9Rq/Az6 CjE= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:23:28 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v9 07/12] scsi: ufshpb: Add hpb dev reset response Date: Mon, 24 May 2021 14:19:08 +0300 Message-Id: <20210524111913.61303-8-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 0d010a343f34..73e3fe89b5cc 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -195,7 +195,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); @@ -1415,6 +1416,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. @@ -1489,6 +1504,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, @@ -1814,6 +1841,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; @@ -2139,6 +2168,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 1ea58c17a4de..b863540e28d6 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -127,6 +127,7 @@ struct ufshpb_region { struct list_head list_lru_rgn; unsigned long rgn_flags; #define RGN_FLAG_DIRTY 0 +#define RGN_FLAG_UPDATE 1 /* region reads - for host mode */ spinlock_t rgn_lock; From patchwork Mon May 24 11:19:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 447714 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, 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 B202DC04FF3 for ; Mon, 24 May 2021 11:23:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9806361132 for ; Mon, 24 May 2021 11:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232820AbhEXLZS (ORCPT ); Mon, 24 May 2021 07:25:18 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25908 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbhEXLZG (ORCPT ); Mon, 24 May 2021 07:25:06 -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=1621855418; x=1653391418; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/s6BCmdFe94BsPWAzxEQXm732yJLke9N0JHym2keXOw=; b=d6Gi+NWLGmzm/r/9ouOdlIOjnflt0oafkm6kmjIHdqJni0u5kmxGFefi 9iV/OvpyswpmfKryVOpCKn1r+mWUcvu0eYnX7N2nd1OTPpuN0GF0RVccD bSpTkNoY0Em0jm4CwWPnZCj3RwBayKSugjSIci/fWTDR+4GcC0/XoMbzJ 4NtPWC/eHiK7o/Xg6XpwYHWyEUdxsWPR3+O6vr1iWZozskdn80o+eXgMs ec9hOPTIJ1iFQfHtvRg/CZKD0bcU4LOoBx3PMJY7SfgcbARkPFSHqO0st GwZ+aa+OK7ZWCehdhaGVfVbrxevgakt+Q3I4ZU1gt7O66f7elKUbIpCRd w==; IronPort-SDR: mWqcQ/nUVJ25VYUEe0jJ+toNzEUei6U0YNi+bDyqwMxc2ULuGYH/mftZjvxDDhLWoRH/oBcyKF J6fGjG7dPLt3kNnMjJLcIrUxwqxNUfvdYmEt+uUeAzJxER//nu51fmmbyPaYddbAEhByXfnvfH wENLpvuVa9H+6ppLjmTTVMMMBgM5WS6QleiPZbwWHuV0E8ZGxOq9TW56rUA4T1OF3ry3xUfOJK w1siOOlb2tWMOZ1Guqwb5MSZW5sscBZ+td+A4uvjo2RbThhy2LlKnaKYhf6RDOOBXIAVtjRv88 YA8= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="280526048" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 24 May 2021 19:23:38 +0800 IronPort-SDR: 9gPs1dhjAkta5owBif/Iv2nw39JkuiNXghieGUHdIf2pE8elOLjgI2A5iTjFUO4I4bsGdwbtId rFoLDAWoxQPiewGvmHNbNSQK0AYfb21KZ5Vu092U4LBC2vezPdDMys9mvxjjjbsf+5hpEa8VDh Jxru/PhtVqPaHatGa1FY5nArsrKQtA20HRectWzDoCEOWKdAqqqy54PDM9Pybbpd5MDlnAHRYE PveGxZFbFn4sX/F4zAYUJIP8Ij1/mPiHL/ZxzgEXWmi9q8WZQohzSEfbOZk2RQENH+40kHe5LF NP9zQ7nvPcwMcGe9KmA7Zusy 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; 24 May 2021 04:03:08 -0700 IronPort-SDR: igcV53kgduJ/oZu6zKjspEsepCr/mE2xWR5nZjyQc9UDEIzqwsoxHvS/C8uL9rD5NahukFuPVw rc4Po+8GvRh+XxaNjqnrXaPgdUppseZKEZfiCx6ccpZGXuHuTp6J1qcOR1gSAcYRp5SHlz/5me JOh/TLa3GbmMyHcNFCUdPs3mttm6vfHfOYwZPVLD8pcbgWro7acpeHG/E+4KVjYZZG5C7V1OSV htp4XAF3Lvackkwpo/N5myU0mg2Dyru5XCIKKZ/oNWh1EA1bHdWE0iZ/iHTxX4NpjPgN8cRTOl i1Y= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:23: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 v9 08/12] scsi: ufshpb: Add "Cold" regions timer Date: Mon, 24 May 2021 14:19:09 +0300 Message-Id: <20210524111913.61303-9-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 73e3fe89b5cc..e1b77c9e6284 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; @@ -1030,12 +1033,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, @@ -1822,6 +1876,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) % @@ -1843,6 +1898,7 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) } rgn->rgn_flags = 0; + rgn->hpb = hpb; } return 0; @@ -2064,9 +2120,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); @@ -2100,6 +2159,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: @@ -2166,9 +2229,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); } @@ -2276,6 +2340,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 b863540e28d6..448062a94760 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -115,6 +115,7 @@ struct ufshpb_subregion { }; struct ufshpb_region { + struct ufshpb_lu *hpb; struct ufshpb_subregion *srgn_tbl; enum HPB_RGN_STATE rgn_state; int rgn_idx; @@ -132,6 +133,10 @@ struct ufshpb_region { /* region reads - for host mode */ spinlock_t rgn_lock; unsigned int reads; + /* region "cold" timer - for host mode */ + ktime_t read_timeout; + unsigned int read_timeout_expiries; + struct list_head list_expired_rgn; }; #define for_each_sub_region(rgn, i, srgn) \ @@ -223,6 +228,9 @@ struct ufshpb_lu { /* for selecting victim */ struct victim_select_info lru_info; struct work_struct ufshpb_normalization_work; + struct delayed_work ufshpb_read_to_work; + unsigned long work_data_bits; +#define TIMEOUT_WORK_RUNNING 0 /* pinned region information */ u32 lu_pinned_start; From patchwork Mon May 24 11:19:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 446688 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, 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 93EB4C04FF3 for ; Mon, 24 May 2021 11:24:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 652D761132 for ; Mon, 24 May 2021 11:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232865AbhEXLZf (ORCPT ); Mon, 24 May 2021 07:25:35 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:21975 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232706AbhEXLZP (ORCPT ); Mon, 24 May 2021 07:25:15 -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=1621855426; x=1653391426; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X+S+UWcVVZpcDsyp4d30JhOYB8agagAYzQEHi7XbKnA=; b=jv7m3Tt3BOCCuKF0DZv1xLFkQP9dpLLOGIZ3Ex+Hh3WlJWKcd22LlKte RttMBeG1f1DLBwa7xnVXcQ4Ucxx2CEcWZHZbH8ZHJnxa7vARH5URIf3hR fB6YuxJLKNXalY0iGHStDyYynHxNule5ouajuUMQvckrcq3TPQ/1NLz8k 0veGNopYDSlZ+jPB4J9f1g4qMapL5A/wo/1ISGR5jxo13Lon8UA135AYr eAxIaJY+sJWWazPd3PXKLaBP4cVRTg6WK3K38ZSTfBVF+v1mAGBTL7s/D cIttE9AsE3WTlPCBOgiWkIEsPV0jxdwXOzHW13YFaZ0o8czv4qEpH4uwQ w==; IronPort-SDR: UvWNP8rIyX+lOKUzsT4IIaM4FbiUweZZf7oUW0Ac4chveuBPG5lJckbCXJycV72TiR8Fj2wI2g 9n/TAop2QH753rKGEpIsRJvrTANremkQ3jxo2wojqC0T32zhNdvSBjA+RiTuG7c70/LIsEl61l NV1vJm+AMt/CGfUAcaw+p6VV+7TtJBpwthaAfWqpjwUzPoZ0Jq3jJ8ULQ8DryuXdb2deTCIB3J vaK2uloRdzpkmCAC0ExifoViHBKXGL17HdpIwaaj1IzepGzLPCvkQEvkLaGAaJnmMQdpf9TeyB vrA= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="169230684" 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; 24 May 2021 19:23:45 +0800 IronPort-SDR: MCfFA/JmiFv9MMkt7iSD1t3Os3qyAngDhmjePRJEImQhMCbX+eOptZhtm4fWMa32WLllFPpAa7 vXPc6pJ8urRDjefPwHc5uJpjgLDNYTkI2kgjI3zAlB5NcV7O+evQIfZ1xp4pBBPW+WrkvpRbmI AY0TY9c2qU8M8Yp5yYgFEhcGcghuzbTKR5rc15MC8urcx2kg630RMkqgZCNaTlspU7RXZZni67 Vxa5uITjxphwc9/CH7Vy0nmbFxG5rshpgtq2S83M4Tl7ns0Y/uFlOovDiAKKZJ1UODEMKcH7id I0/gbC9bKUNowZgeK777f1Qt 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; 24 May 2021 04:03:16 -0700 IronPort-SDR: BsdI67gYlbF8HUK+leXgK33vYvUajDHytICL0RIwPNuSGh8VHtFvFqOxJNcr5aSt6KbdcPner6 523lDqSdL+kIPAh1SrhspX/R/2h+b0CLixn1CkwALfgpkYrsLQXVoTV0U5VJxukdTFNlymindk 69xSIHPHt2v1BXZLtZfT0Ia6j9dhEn+jzO9yHO8z9Ge6a/MWKA0DmPHmrSyQFfezqe69wz6OMJ SieQPMqtKCYfS7edSlcpsdQn6uLSgAcvfjppZjcDgZmrDJrAZzQctwRnJnBs1OhERTebppD9Q3 7mM= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:23:41 -0700 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH v9 09/12] scsi: ufshpb: Limit the number of inflight map requests Date: Mon, 24 May 2021 14:19:10 +0300 Message-Id: <20210524111913.61303-10-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 e1b77c9e6284..47f9021caa29 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; @@ -739,6 +740,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; @@ -753,6 +762,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; } @@ -762,6 +772,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 448062a94760..cfa0abac21db 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -217,6 +217,7 @@ struct ufshpb_lu { struct ufshpb_req *pre_req; int num_inflight_pre_req; int throttle_pre_req; + int num_inflight_map_req; struct list_head lh_pre_req_free; int cur_read_id; int pre_req_min_tr_len; From patchwork Mon May 24 11:19:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 447713 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, 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 630F9C2B9F8 for ; Mon, 24 May 2021 11:24:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4206361151 for ; Mon, 24 May 2021 11:24:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232822AbhEXLZk (ORCPT ); Mon, 24 May 2021 07:25:40 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:21990 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232848AbhEXLZV (ORCPT ); Mon, 24 May 2021 07:25:21 -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=1621855433; x=1653391433; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2slTZFlzYas3SOwwmRMcQOgCDAott0ELfJUt8Y1jKJ0=; b=Xc45/dqkB+vDNLeX0Kg1kqZjJ39zNH/r0uLpgnQ2cdMx4XmFXXxsNZqi F7a7m8cli8dZb7dlk+y4wSepbMsj0tDrRqrVxjtVO0n489FBI+SBglcU+ +YiA1I3vkPEIX+rlPHxtezudk5+u/o3URYcrg6oBCh5EGtnokpH2zjq3+ jwGT39m1BtDfMPPzyreL8L1bIgqfFE46Z4J6EyUNEYicATYhQmSvgm5ir alIZ/msD04xmSEhYGP6s5WRkRM3D267DB2RNi8avscF8MuEaiWweVvpBw qx8sAiOqkd6F1wqhcu9ju5xJJDl2ZjY87G1sx2wYxcJ6xGmwiwLCnE6gY w==; IronPort-SDR: ufdYh5Z7vSIzh+jDdEEjma1gpADTpc1NR6Q4K2VfFc4FMnpjKyck7jvPJsY6FTvdcVWMgnlMCv 6wY5JkhD+dr6hM4UpgfnQvKF/kcrH/t1xuhWBnZn95CbfRMD2b+WrGfLOyXK8TpT3HxF9EYUo3 dTkoJP0o1GFRsV43H8eUjMuGv4DPEOsUnSk/iwV6p3FaPCdG8CEIiRY43/1bzkePh1kYhVeEhd jqcY/CtFcVvADsA0Zae3nJIEHuGdkIbTkg6FFitqjbNHWHl5JNgEOf3OHTuW3f2hKDTh5JcbxZ 1pc= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="169230689" 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; 24 May 2021 19:23:53 +0800 IronPort-SDR: 54s55FL/CN7ss4W5Y/rJpbKfaUcdnkCzomxxbbjnmy093ur2OYdmzzMXfNws/iPqCvuCAk8whh +IPErjutYxGrQnxzP3akvOU1QMj2XhqYsVQZL0xfKNiYwpzg8gTi9brvwOqy++Nxqvz9lCU8YG gDl5BgQ74+4MKgykhalI9q/G0GAk55KZfr/t1XlKokZJlGWE7TAv7nbf7ScGuyD+cO0JyKAsW8 1DYdljVSEVhFp+Zp0f/YpKNToguMPf2RTaTKN8ChhLbOnHNTG84PGQ9s6SCat4T5rwk9o9QoCY Ne6zRKkfGWskeld9ePE8kym7 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; 24 May 2021 04:02:08 -0700 IronPort-SDR: 6uLKFkry0a/w/L1q1ijz/FUQaadZyo8OsBYqPiQg2r3muBehyFlCr/lkvSAqWUPtzBCYWUbBiE V4PO5NB65tNLVw2qx+szesq5577Y7CpagcrGCwxp4ITO7t2P14VOf99/1D2WfD9cGth7pa0+IB HzQ+N6MvJvE2l9lT9LxAM40SPM65G6dmoFCJnOLuAskTPdzD2GXCDEYRvPDNF+yWY7FKDvD7Ji 21Qqc5FsGnm3Y9oCqRbhbTyQmtX9y66z5kmjJeVWxMvOOoGJttcCywAGqVI6P40EzNAxGyyMhs GiA= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:23:49 -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 v9 10/12] scsi: ufshpb: Do not send umap_all in host control mode Date: Mon, 24 May 2021 14:19:11 +0300 Message-Id: <20210524111913.61303-11-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 47f9021caa29..585515c560a4 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -2459,7 +2459,8 @@ static void ufshpb_hpb_lu_prepared(struct ufs_hba *hba) ufshpb_set_state(hpb, HPB_PRESENT); if ((hpb->lu_pinned_end - hpb->lu_pinned_start) > 0) queue_work(ufshpb_wq, &hpb->map_work); - ufshpb_issue_umap_all_req(hpb); + if (!hpb->is_hcm) + ufshpb_issue_umap_all_req(hpb); } else { dev_err(hba->dev, "destroy HPB lu %d\n", hpb->lun); ufshpb_destroy_lu(hba, sdev); From patchwork Mon May 24 11:19:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 446687 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, 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 2815BC04FF3 for ; Mon, 24 May 2021 11:24:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 073E461132 for ; Mon, 24 May 2021 11:24:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232860AbhEXLZ5 (ORCPT ); Mon, 24 May 2021 07:25:57 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25937 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232861AbhEXLZ3 (ORCPT ); Mon, 24 May 2021 07:25:29 -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=1621855441; x=1653391441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qWReMlBu2pEz10hW6XZxbX0QXg7/bMn3wao9J0zFBXg=; b=q76xaTlpJuj8CFagYJYkSLzuqrk39QPiAPrXwq9Lffk13Eq9x6aJj6gw tdtjyxyw1u4kso2hr276pwvJSYSVNf9D3c6okJ8hloVuunKjaz2QLnCZk 1W10RJe2hAo679yRZEs7Iq8sb4tkiHZt4p9dUVWV54uOaam1cglm3wqzH 4gGZjPuDOJeJqu9R3RL5GGNAJvfBsiQster+7XtZsv6HTzrOwagGxxavF IYz0olI7/OBlX0kYouBC1x8hfaBWZz1G45YatoddgXyntbRsnDT8De9pO 71q7Om0hCU7Ctb8FEUcOKrELBfFV3M1M2k1i2t6sRfiggdSE4YX8YtD1A g==; IronPort-SDR: ZzLmolHE0y5zV8eMYZ25UTlJESVkLZuWi+SEW186avRKd0nq1nSWSUeHnPBRzXaot+GvPUrf9N Ogv1ipR6u6ZGe6j2NjmM+qEkvyqUDC2WvIVRgTHMXREwSTzK9v7Q0U2FFcbHd+YtoESKI6eHyb QsgI1z44UfPWsoI+8u8od6ZNn33qSVzH+h1yKrDV5Ci1V0EzIbuqjuy2DKKlNljB16UVjmwCEd M3meAY+k/Lf+Nxd2U8yfOVxnwHnpk2m5zNtLRpzo0H4/CZnc+jeH4DF82VNST/1PfNkSs868Ui GzM= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="280526068" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 24 May 2021 19:24:01 +0800 IronPort-SDR: YdjGZdPdgSf7cFguNJvbFo80HILysLB+ATbaM3M9iOOwD19DG3LKpZu7DcbfgjQt61Lpl5YKkd IVldb1CKYM0UJ5RLN2YNiYg0HH1Y3lceFYKtUCh6zjrQA5Pru1Uc52WbJ7JUgTz5Gzw8jXZJoA +3wa8E0eU3ukLqesrX4PYe7gqGbb9IgXqeN+2l+6G5Jk9Zwenb4ty15Fp1a+gsoq0PasPx38V4 Gtyaz5u+Ljf9XJsxe/7/ghxUCOWs++NTlwYaOI3k6oqcJchvq8mHY1p8rSZMVuIiElOlGqJZml pfhWev87no4XMzkwmP5viqbx 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; 24 May 2021 04:03:31 -0700 IronPort-SDR: 5EoQycSBlssjux3NqiqqvxE4o6WRLgYUCzH3z5m+/oUpfYXoZzW2IfIU269MxytWUX1vwlsttc 9Sko7/og+oMP4Wgzg1ECw/phQstiMMGQIdq/eN3LilizG1wpXXr5LqwmLBivEeR4zfoDFhOatX kobqI0Adi8SenFc+93+It08zsWntc6weX/CBJfxN5sSvNPgTNCGsmWNFoFr9ku++ZC1q8G/ulq PmOK0kFAWFNlLkfiSw/SIjd1AvOrUT6WilWX8WkHHpcbTjIZ8olyMByTtH+WixN5QDbHNFJ2q1 hsU= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:23:57 -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 v9 11/12] scsi: ufshpb: Add support for host control mode Date: Mon, 24 May 2021 14:19:12 +0300 Message-Id: <20210524111913.61303-12-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 585515c560a4..f52942cbf3b3 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -2583,12 +2583,6 @@ void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) u32 max_hpb_single_cmd = HPB_MULTI_CHUNK_LOW; hpb_dev_info->control_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CONTROL]; - if (hpb_dev_info->control_mode == HPB_HOST_CONTROL) { - dev_err(hba->dev, "%s: host control mode is not supported.\n", - __func__); - hpb_dev_info->hpb_disabled = true; - return; - } version = get_unaligned_be16(desc_buf + DEVICE_DESC_PARAM_HPB_VER); if ((version != HPB_SUPPORT_VERSION) && From patchwork Mon May 24 11:19:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 447712 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, 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 3F966C04FF3 for ; Mon, 24 May 2021 11:24:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 17CE2610FC for ; Mon, 24 May 2021 11:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232721AbhEXLZ7 (ORCPT ); Mon, 24 May 2021 07:25:59 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:8802 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232867AbhEXLZh (ORCPT ); Mon, 24 May 2021 07:25:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621855450; x=1653391450; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JOBOZPHb/vpTAzqOIzSTkF8cq3Gr08ahbmbqA0rWwDk=; b=KGqcu+MsmjcIzah7zq7LRbzteHJkB9kACrcFtRpQ49W9t0LNr5nqlmNT hOAxwpKpiREhhlQ9bkCE/LExKqwAbBb8uN4kLt26t+Oaoipnrk3lPwR98 jZ4G2y8Kj1ASe9pPbNC3ZIQ8BPYDLyPaGYcgZTmojREXC3tJY1mlPBle9 1LWWpz4RNMmTHR7gaB/zvG6+nq25BVFk2t7/Ry3lep4fnJq6nCyvvTweq GKnMRtF4BRi8UsrAp3LuiT/aD9eA6pnoOKV1IOFi44CluKhW4P15BAOZq aMEuCFqGJOc8AqEnNuCqNBCEN7QIy1lFhLAjcsst3u2blOTJ8S+/oz9h9 Q==; IronPort-SDR: QEIVEn68t1ZowGGXpyYqpv0tHyBnmfYmGHjQ5FiulgbkN7yGQDWnE80BINHYGuxau70mhYdLYi 8uqWwYUgKWrYRq4XQcGa+GqmLPca42hLBR/mZttt3SE59lQW0c496g90yVAj5ca6LBMRUFh/H3 YXcCg/1A91hZXgdF7HaVqxZlHtETXvzgvFFUvTLMu+ZDCpEcVGqlDyPJOtrL4SC/CSkvx8cGq6 SWH2r2heq0HgljIqvQzwRBTTCV6V9cpGl0qLlzoGUiOmBb9yxYXvJf3Xutkc1Hjv6FP3tEg7Ux iV4= X-IronPort-AV: E=Sophos;i="5.82,319,1613404800"; d="scan'208";a="169770981" 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; 24 May 2021 19:24:09 +0800 IronPort-SDR: sDmRuFR5mVIdPVrPK5jiX3oKsIogXCwgoOEoXo/xQb/xM1ueA0bDc0tNVVLxINGs/UTWVFIImR Es0AbsM9IxGD4Ek7pjXu/20Hv+0o7Z8DGRrL1Le0JgQmeA/HlA6jbHaE5AQO528fD9WN7uXpxO AdBeb2LDH7C+3DcOdftOlHkcg0sPYnncmiwXGoECLlOlp60caTzo66TclIsDTbGn9GK5y/dvxT 3UST3xOceDgngGUqbOL8HPtFU1TiZTcNZyQB2KWsanezkkN/nVspo5oIyNV9ANhPXqRtehoRR6 i9qIa9r0V3ft/rUe58lGXpQc 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; 24 May 2021 04:03:38 -0700 IronPort-SDR: pUx3NBYhjrV3uAXDneqeDSCU5SqNuczyqw13u6hPf7kfLatAK744ZMvQ79SDwHRCLNkXOEhv++ hBFmkZKPtNOEa7+MJJplB/ElXOFz8C+BaCTVi6xFSVPmRsdZz+WqDfUZyh3c4046INCDxiYO+v kLz5Yv1n4TrcxH6hb4RhmT0SgdoDQKgX5rDbhYAgxwmvDPZopubqgIpS9SmGVKP9sXp6PAZFFq rYQqLI+VsPYHUJg7x9+bruy171AeRwkCs70Jko3NM/NFOUcmP+dGh6Y/T+Li9kTTcxBD4+oTaX z3c= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 24 May 2021 04:24:05 -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 v9 12/12] scsi: ufshpb: Make host mode parameters configurable Date: Mon, 24 May 2021 14:19:13 +0300 Message-Id: <20210524111913.61303-13-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524111913.61303-1-avri.altman@wdc.com> References: <20210524111913.61303-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 | 84 +++++- drivers/scsi/ufs/ufshpb.c | 288 +++++++++++++++++++-- drivers/scsi/ufs/ufshpb.h | 20 ++ 3 files changed, 365 insertions(+), 27 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs index 8bafacfea827..1bbe7adcc40c 100644 --- a/Documentation/ABI/testing/sysfs-driver-ufs +++ b/Documentation/ABI/testing/sysfs-driver-ufs @@ -1449,14 +1449,76 @@ 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 -Date: March 2021 -Contact: Daejun Park -Description: This entry shows the status of HPB. - - == ============================ - 0 HPB is not enabled. - 1 HPB is enabled - == ============================ - - 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 f52942cbf3b3..af098954927e 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 @@ -194,7 +193,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); @@ -741,10 +740,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; } @@ -1051,6 +1051,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)) @@ -1069,7 +1070,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); } } @@ -1087,8 +1088,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, @@ -1098,8 +1100,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; } } @@ -1128,7 +1133,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; @@ -1349,7 +1355,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; } @@ -1700,6 +1707,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; @@ -1710,7 +1718,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); @@ -2031,8 +2039,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, }; @@ -2116,6 +2363,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) @@ -2170,9 +2419,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; @@ -2351,10 +2604,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 cfa0abac21db..68a5af0ff682 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 {