From patchwork Wed Jan 27 15:12: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: 372061 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F826C433E0 for ; Wed, 27 Jan 2021 15:25:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1056C207BC for ; Wed, 27 Jan 2021 15:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235801AbhA0PYd (ORCPT ); Wed, 27 Jan 2021 10:24:33 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:51782 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235284AbhA0POV (ORCPT ); Wed, 27 Jan 2021 10:14:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760460; x=1643296460; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pYqNFpWu5gdPAJjbMMciUgh9gaj1oKk/cLrxHPOh+G8=; b=QpuCXwWra1axa5mmSilLb3WVeC9awCyru0dLvVjjTMkphhw9n0rW/aCp 6zEw/rqj74XauWFc56QoRlKCuBJYzMymidnQMyvAoHOzlV3Ft6pu+qDCn HTMZIqauxKGvxozfCz4dg69YeVNBTziTQsblhiyHj1mrNkToyatD951pq EfvVr+LyCs41aKZISdlH49E4j+024BtlT212OuWvamj6LzeFUCNQS9+yZ ggXBhMFVZILVtzBPPiBLO+NM7mhPwZsP7CLcWMA1NNSXefZQSupSec0lc Hn+yxksNfpICrzhrtLNHANwatZhv+HgGb+WM+vu8aG7+hVv7Z4puqz5sq w==; IronPort-SDR: DM3vvhmWQPZ22e0speaI34nn/kafJkycYudWC5F0GCDsr3nkj2SySXuEfTFXMNhnDVRR+2cY4y FdWTbYXH5O1JT1zj47tIF3X9FGVkjxBgq4YXcjvS256/RfK3Sm61vj58SriQrXhw+kJHGvFBot 2XrWcqy2aLmwF2G9Orj0dib3HAymusvHAU5vs0UD0TuLWR7kkWiXWCKq72QtxyYxElph0ZJenj d8Uqrg9+LC82fnr1SY7QZHe6JTTGeIySsIBRGiErnyqDC32Trh6FRuH1oR1beBrJasXFDY5T6B Q9M= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="158454188" 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; 27 Jan 2021 23:12:50 +0800 IronPort-SDR: j9uaeg9ovkYwmvKrEmEgQK442LzxJQ6vVZugPyksY8DbenSeuhqTvkkPE0VEBGFNWVwBGtFKaH EKCPGk1hUqoQtR0pfl9HC8gJs7ozpTfoRd0IthWRJpsFZbg7K5nLF6gTSB5869nvB5m63bjrRz Vj6Iq5HEFq34QBkh32UpDhkz01cYJ0hmR80IKHX8q1zgTrOapdkutddYkg3XjipVg3kuZL1cUl rihoztpYY7Fdss/o5SAon52hexqQrRZTrwWvRjG5qrDdXAZjRa7IaotwTNziuwewGnJLiVeMrO QDgwlgvqzCjLFTnhmo/Kh7hG 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; 27 Jan 2021 06:57:10 -0800 IronPort-SDR: OoREcpqAz05j/2BjvIBTgK++qemH9rDka295k2VVoMO+Qei8qKNmtT3C30E+Y4pGEjjB8NYgNi AckljoYNl9XRWGFtMXZFB8aR2DjhenFG1070ZobvUhcVm5DaRVF0E+nRXlvCGLFs6LQQE9czZu fl/ufdYjO441BWlnLsQmvsXnvP3GlQ9ayiSjQ2bzgV4hX+0F8bs/eEwkIm21dq7tHnvMG4c34e 1BDcTsAyDfz3AvA4Hvt8PV3JpLNwIJP9D4L7nRImmz4d6DYUdxfGcct5ZLBLC8kpxGE2VwwOMi E44= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:12:46 -0800 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 1/8] scsi: ufshpb: Cache HPB Control mode on init Date: Wed, 27 Jan 2021 17:12:10 +0200 Message-Id: <20210127151217.24760-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-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 --- drivers/scsi/ufs/ufshpb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index d3e6c5b32328..183bdf35f2d0 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -26,6 +26,8 @@ static int tot_active_srgn_pages; static struct workqueue_struct *ufshpb_wq; +static enum UFSHPB_MODE ufshpb_mode; + bool ufshpb_is_allowed(struct ufs_hba *hba) { return !(hba->ufshpb_dev.hpb_disabled); @@ -1690,10 +1692,9 @@ void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) { struct ufshpb_dev_info *hpb_dev_info = &hba->ufshpb_dev; int version; - u8 hpb_mode; - hpb_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CONTROL]; - if (hpb_mode == HPB_HOST_CONTROL) { + ufshpb_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CONTROL]; + if (ufshpb_mode == HPB_HOST_CONTROL) { dev_err(hba->dev, "%s: host control mode is not supported.\n", __func__); hpb_dev_info->hpb_disabled = true; From patchwork Wed Jan 27 15:12: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: 373024 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47756C433DB for ; Wed, 27 Jan 2021 15:15:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E094B20771 for ; Wed, 27 Jan 2021 15:15:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235334AbhA0POc (ORCPT ); Wed, 27 Jan 2021 10:14:32 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:50687 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235184AbhA0POF (ORCPT ); Wed, 27 Jan 2021 10:14:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760444; x=1643296444; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a+gWe1zrtM/8RLwHT911hun5GdaHlKNsD1TIXe6zByI=; b=buwOj/236dNnjVyNfZd2+PkIcnI/OWh8EnplpA+czUPhiHt1lVFbKclI mwEHHfnnjnqXmb4k5qZYKWgSFcwtFHV+Ry53iuijEWRd0mj8FcuQtTc+9 Zx9NODqTO2GgEvYG9e98fkLw/0kwZqlD5zMaVCo7/82AEtBy7UeiIQiO+ niontr9qni/GY7vI/7MbnmNBJSl8UAhy4wGDc+0K0V9sXoZfW7vxF50Wv 9ztl7FBGowAYLA6iy8NRLBIEmrUWG1/0gZnA/+RjAjqM8e7S3vf68Ox53 s9fyUftJFJ+GwjmjPoVw1TBxxPW+9+a151YPqQgXMUPz62Wqbu1GSrDyB w==; IronPort-SDR: qDfAqTVYjZTmh8CrmAHISAenGC47nLLXsxjTZotaOmLfqUdSTEZ8zFTh+BZOGqXL1OCHszfDJ1 saal5r2xWEg/4WBn/msOjIW+ZUeVBHALWeWZBx/s5DQMOpDeY7uTPDtuIT48Hd7NnXeqhSQmuL nsXsd9QRp44WDdfiCyOUybHgV+4f2ybLPIk9TE6hTsMEAKorTTDOLs+pObxOzgd9SzSDj2MPvI CZ9HMHs1z37QO8VegNP8ODjNFaBgMQJhNMMfdUK2Lu8htlwTn6hWalBP4c/mwM1wnBipMONzNV Eao= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="158455365" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 27 Jan 2021 23:12:57 +0800 IronPort-SDR: ISRKgmjQpZsI2bGuDLVpQmJKAE49ZVr5m8139S81nAZW71RtzPtF+SLem6KMThTWEPMU+DZg4W qtzYJ3uTo4oxx9r42XkyrqCpZ/Z6rajKsVfKKGuVbB9sDouz5Q8xYlqKJeFoei2KaFba39Ahs2 y14uwTLU8VjtpJDFZf3qazEEIiobBoCQlvSABDwpDMLI6i7emIqKbbNbGr1EFREzQji3AKatSM DuUkF+Aawe2rUdx/sHG27aUbyWOBmBwCbpcf9/eOrj3ssi6BVYtkZxoeTsGVzUwknoTyGyqr6E 64SNskYmKl+WKMrnFe0kGsQ9 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; 27 Jan 2021 06:55:16 -0800 IronPort-SDR: pdTIneKST+RSvixuV5IMDyjTAi3rhAkexGajfSaUmIh1iN1yXX6RTQiilhzkAgp1V8vOrhCvf2 lbWOXMX3C5XScqt697SLgwjz7FOMAuasp5KuAQxXxo8stPveTXimKJPHPUQS8W4Vb6nOrabjOp eYNHElX4TGRdSgDKg0+KNMpC4Edm2TURtkpf93Wiplw0X9Q9JjUBmebHKWVtsrXzQ/PjO0HY46 YkwWHVu/4vYGb2c0FHMowTiEQx+CswIxzg/1jTKyvOOOxs2bKilrj4dwcLj1YH/dkKcxNCB2+C tXs= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:12:54 -0800 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 2/8] scsi: ufshpb: Add host control mode support to rsp_upiu Date: Wed, 27 Jan 2021 17:12:11 +0200 Message-Id: <20210127151217.24760-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There are some limitations to activations / inactivations in host control mode - Add those. Signed-off-by: Avri Altman --- drivers/scsi/ufs/ufshpb.c | 35 +++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshpb.h | 6 ++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 183bdf35f2d0..5fa1f5bc08e6 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -140,6 +140,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); @@ -201,6 +203,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 u64 ufshpb_get_ppn(struct ufshpb_lu *hpb, struct ufshpb_map_ctx *mctx, int pos, int *error) { @@ -380,8 +387,12 @@ 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; + WARN_ON(!srgn->mctx); bitmap_zero(srgn->mctx->ppn_dirty, hpb->entries_per_srgn); + rgn = hpb->rgn_tbl + srgn->rgn_idx; + clear_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); return 0; } @@ -814,17 +825,39 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, */ spin_lock(&hpb->rsp_list_lock); for (i = 0; i < rsp_field->active_rgn_cnt; i++) { + struct ufshpb_region *rgn; + rgn_idx = be16_to_cpu(rsp_field->hpb_active_field[i].active_rgn); srgn_idx = be16_to_cpu(rsp_field->hpb_active_field[i].active_srgn); + rgn = hpb->rgn_tbl + rgn_idx; + if (ufshpb_mode == HPB_HOST_CONTROL && + (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_idx, srgn_idx); ufshpb_update_active_info(hpb, rgn_idx, srgn_idx); hpb->stats.rb_active_cnt++; } + if (ufshpb_mode == HPB_HOST_CONTROL) { + /* + * in host control mode the device is not allowed to inactivate + * regions + */ + goto out_unlock; + } + for (i = 0; i < rsp_field->inactive_rgn_cnt; i++) { rgn_idx = be16_to_cpu(rsp_field->hpb_inactive_field[i]); dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, @@ -832,6 +865,8 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, ufshpb_update_inactive_info(hpb, rgn_idx); hpb->stats.rb_inactive_cnt++; } + +out_unlock: spin_unlock(&hpb->rsp_list_lock); dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, "Noti: #ACT %u #INACT %u\n", diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index 2c43a03b66b6..8a34b0f42754 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -48,6 +48,11 @@ enum UFSHPB_MODE { HPB_DEVICE_CONTROL, }; +enum HPB_RGN_FLAGS { + RGN_FLAG_UPDATE = 0, + RGN_FLAG_DIRTY, +}; + enum UFSHPB_STATE { HPB_PRESENT = 1, HPB_SUSPEND, @@ -109,6 +114,7 @@ struct ufshpb_region { /* below information is used by lru */ struct list_head list_lru_rgn; + unsigned long rgn_flags; }; #define for_each_sub_region(rgn, i, srgn) \ From patchwork Wed Jan 27 15:12:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 372060 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C689BC433E0 for ; Wed, 27 Jan 2021 15:32:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F8DE2076B for ; Wed, 27 Jan 2021 15:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343757AbhA0Pc0 (ORCPT ); Wed, 27 Jan 2021 10:32:26 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:45981 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235268AbhA0POP (ORCPT ); Wed, 27 Jan 2021 10:14:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760455; x=1643296455; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7VFDSJqxHUSXRoc2A3ruFxeTNHKGX04nUEcpHMmE0PY=; b=miCvkYJk09bWrNt+OHE5tKfMVQ2w3OrbVybHkWcDUPqg1UeV2mzgBKV5 eTGS3ED7oUJE4aWaANprBKgE7vxVGbrwt4cuWI/8hVDar+5EemKBL5jn4 AI3mSZk1nTc/g+U8lWl0u2JQpYsB1Kt4u1WYHyPMZc6U5ZOqFDNugPBGp a9ZRwvVFcFPXFsiHvgJlygwzJscwNtXkK9WMe8kCdZN3X5ndWJZ/cyayu VTlSDY6j9QMkEZFcUFmpJRZzX1d5jUMAOh3mUAQFT6VDB+bQTsofE+EIS KPit2zK7JthMHiLNbu0ynzrYL5TbKclRuIbVotEO0JrTK7VjUvAXlFItq Q==; IronPort-SDR: Mm3Ne0XmkAWLFA5Ka9AKewzNxmjBnw6vmFEIBmNglBjpU8vSfgl/KTNUvEuED+H7ZXBjGUTKPs fy+8J0pKZOnc7hKPoIaartn9CBW5DbcHpTN2QfwDd2QxHRE8QHTcPfriHiabuqdTEwtwdFHzB2 4GB4JSO/j2OzEf2H+u/pxgdHMNq6ALSS9yOqIDAg8wzHKK4b6Qzvj/o2alg6BlQQ6AScQVaJQG 3zuYk1kZTX+WD6QabBy4G7bTLBDlHuZmZMd4O6qr5i/rUJ9EwiJeM7oThIVMbNnfoAU/tLYYec c78= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="162900946" 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; 27 Jan 2021 23:13:06 +0800 IronPort-SDR: fCb5pqjkWniYX7ucz0douTOVaapvB37x/ylliD2gvm3ePIhZuv10PVu/tVm4XZObBa57r24yoE 9xbuuBdd53SzcAVV0ZKuokAUFwFH52cQckHfGrvjfjPUyXuZHHbrwpSOSPmPj+ruSI1UgO0Yj5 9oSvMQIJt6sLKrINN59sCb1NfTC+z7fKO8AcPmD72AL1CakYtCi42s4Lz00JRBuE9fC7ihpYT+ ACvm9FTUygFYiNx7xzU2Og9MqwJjFOa+1r/gU82qsUYCHxJ91zrDEQJC+udp9h7Ruqq5BHEP7d ZrSltkDBr4Awj9ETzYzyPR4I 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; 27 Jan 2021 06:55:25 -0800 IronPort-SDR: 16N/ihp9MyZPJSJZKsrL/vxP5zkj1nT5PGiUxR820l0ofyoqKRITGGN/4PfQt0OryMNUbw/96K HOdx6Ei1iyeNTaqH+VJrBwuqAvXMBOTiIZrXe4TbUub9FAd7X3YEdO5GCcPQ3Ndi8KUcsV65Mw cX5egc0WSWir9jEujXGJPfTCEslnWcX9L+zQhVYh6o5GpUCa18D0obVGwSaKeApYxS4Y9tvO65 DTpA6dXoZKjfCm5i57uCettK9ze7dicpBLqNcSo7HXeJ1VF3T7CmFk06MlKKPNG56lbfL6HFVz VT4= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:13:02 -0800 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 3/8] scsi: ufshpb: Add region's reads counter Date: Wed, 27 Jan 2021 17:12:12 +0200 Message-Id: <20210127151217.24760-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-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. less intuitive however, is that we also reset it upon region's deactivation. 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. If we don’t reset the counter, we will trigger a lot of trashing of the HPB database, since few reads (or even one) to the region that was deactivated, will trigger a re-activation trial. 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. Signed-off-by: Avri Altman --- drivers/scsi/ufs/ufshpb.c | 96 +++++++++++++++++++++++++++++++++------ drivers/scsi/ufs/ufshpb.h | 5 ++ 2 files changed, 86 insertions(+), 15 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 5fa1f5bc08e6..51c3607166bc 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -16,6 +16,9 @@ #include "ufshpb.h" #include "../sd.h" +#define WORK_PENDING 0 +#define ACTIVATION_THRSHLD 4 /* 4 IOs */ + /* memory management */ static struct kmem_cache *ufshpb_mctx_cache; static mempool_t *ufshpb_mctx_pool; @@ -261,6 +264,21 @@ ufshpb_set_hpb_read_to_upiu(struct ufshpb_lu *hpb, struct ufshcd_lrb *lrbp, cdb[14] = transfer_len; } +static void ufshpb_update_active_info(struct ufshpb_lu *hpb, int rgn_idx, + int srgn_idx) +{ + struct ufshpb_region *rgn; + struct ufshpb_subregion *srgn; + + rgn = hpb->rgn_tbl + rgn_idx; + srgn = rgn->srgn_tbl + srgn_idx; + + list_del_init(&rgn->list_inact_rgn); + + if (list_empty(&srgn->list_act_srgn)) + list_add_tail(&srgn->list_act_srgn, &hpb->lh_act_srgn); +} + /* * This function will set up HPB read command using host-side L2P map data. * In HPB v1.0, maximum size of HPB read command is 4KB. @@ -276,6 +294,7 @@ void ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) unsigned long flags; int transfer_len, rgn_idx, srgn_idx, srgn_offset; int err = 0; + u64 reads; hpb = ufshpb_get_hpb_data(cmd->device); if (!hpb) @@ -306,12 +325,39 @@ void ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) ufshpb_set_ppn_dirty(hpb, rgn_idx, srgn_idx, srgn_offset, transfer_len); spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + + if (ufshpb_mode == HPB_HOST_CONTROL) + atomic64_set(&rgn->reads, 0); + return; } + if (ufshpb_mode == HPB_HOST_CONTROL) + reads = atomic64_inc_return(&rgn->reads); + if (!ufshpb_is_support_chunk(transfer_len)) return; + if (ufshpb_mode == HPB_HOST_CONTROL) { + /* + * in host control mode, reads are the main source for + * activation trials. + */ + if (reads == ACTIVATION_THRSHLD) { + spin_lock_irqsave(&hpb->rsp_list_lock, flags); + ufshpb_update_active_info(hpb, rgn_idx, srgn_idx); + hpb->stats.rb_active_cnt++; + 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); + } + + /* keep those counters normalized */ + if (reads > hpb->entries_per_srgn && + !test_and_set_bit(WORK_PENDING, &hpb->work_data_bits)) + 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)) { @@ -396,21 +442,6 @@ static int ufshpb_clear_dirty_bitmap(struct ufshpb_lu *hpb, return 0; } -static void ufshpb_update_active_info(struct ufshpb_lu *hpb, int rgn_idx, - int srgn_idx) -{ - struct ufshpb_region *rgn; - struct ufshpb_subregion *srgn; - - rgn = hpb->rgn_tbl + rgn_idx; - srgn = rgn->srgn_tbl + srgn_idx; - - list_del_init(&rgn->list_inact_rgn); - - if (list_empty(&srgn->list_act_srgn)) - list_add_tail(&srgn->list_act_srgn, &hpb->lh_act_srgn); -} - static void ufshpb_update_inactive_info(struct ufshpb_lu *hpb, int rgn_idx) { struct ufshpb_region *rgn; @@ -646,6 +677,9 @@ static void __ufshpb_evict_region(struct ufshpb_lu *hpb, ufshpb_cleanup_lru_info(lru_info, rgn); + if (ufshpb_mode == HPB_HOST_CONTROL) + atomic64_set(&rgn->reads, 0); + for_each_sub_region(rgn, srgn_idx, srgn) ufshpb_purge_active_subregion(hpb, srgn); } @@ -1044,6 +1078,33 @@ 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; + int rgn_idx; + + hpb = container_of(work, struct ufshpb_lu, ufshpb_normalization_work); + + for (rgn_idx = 0; rgn_idx < hpb->rgns_per_lu; rgn_idx++) { + struct ufshpb_region *rgn = hpb->rgn_tbl + rgn_idx; + u64 reads = atomic64_read(&rgn->reads); + + if (reads) + atomic64_set(&rgn->reads, reads >> 1); + + if (rgn->rgn_state != HPB_RGN_ACTIVE || + atomic64_read(&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); + } + + clear_bit(WORK_PENDING, &hpb->work_data_bits); +} + static void ufshpb_map_work_handler(struct work_struct *work) { struct ufshpb_lu *hpb = container_of(work, struct ufshpb_lu, map_work); @@ -1308,6 +1369,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 (ufshpb_mode == HPB_HOST_CONTROL) + 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); @@ -1394,6 +1458,8 @@ static void ufshpb_discard_rsp_lists(struct ufshpb_lu *hpb) static void ufshpb_cancel_jobs(struct ufshpb_lu *hpb) { + if (ufshpb_mode == HPB_HOST_CONTROL) + 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 8a34b0f42754..b0e78728af38 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -115,6 +115,9 @@ struct ufshpb_region { /* below information is used by lru */ struct list_head list_lru_rgn; unsigned long rgn_flags; + + /* region reads - for host mode */ + atomic64_t reads; }; #define for_each_sub_region(rgn, i, srgn) \ @@ -175,6 +178,8 @@ struct ufshpb_lu { /* for selecting victim */ struct victim_select_info lru_info; + struct work_struct ufshpb_normalization_work; + unsigned long work_data_bits; /* pinned region information */ u32 lu_pinned_start; From patchwork Wed Jan 27 15:12:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 372063 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E74E6C433E6 for ; Wed, 27 Jan 2021 15:15:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8EEC207B0 for ; Wed, 27 Jan 2021 15:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235638AbhA0PPS (ORCPT ); Wed, 27 Jan 2021 10:15:18 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:30681 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235428AbhA0POe (ORCPT ); Wed, 27 Jan 2021 10:14:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760474; x=1643296474; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vas6vzHGrww2zViujLO89n+jvEzx6usSOUxeeboPCy0=; b=KsYpOtT+j2da7IBvHQfgQA57aBpTPmhWYnQfGSlR9/nXREN6lmNNf0Hs w72QBWC/vuKzSGlrR/kJg/MQcBHdtptmSy7EiZJvbDH70jQB8HbVQFzD2 Nkmxwg7QRfCkGTGwTak3BgCMApZJ/ZPwmw/LXwAQTkMswK2TjuLGdbPHg k3DkjQSKLMgCB2eA7F3cPYh/weFZZXea3wd5yZGV8vHQsCO4BDlasJ2/y 5PVKrkukHLj/al3jqq9sJRJMHuJU3vRI33o1gH3GoIo7ItiROkB33Yddf UUJejS/aPVkbEqJW8Th/1xTzghzL8kSKIy7VHv2c8tEe4pRicESUghZLG A==; IronPort-SDR: CKpC2PQqpieDUCpgSwtHAqea8m9MiqatktAj2uVZGRScfrGH/SIOzuW2QxgDtg3/GujuD1s9Ln c5KuJCsOduUuJ26mns6OMbpKYsWJ271b8uENmnmL5OobKfCgTZTDkE6gSt4KchHRUhIqgqXKJz RLQxXkkI1wrGtKyBn4rruq7h0DUy76iDqAEqVT8Vut3esOuQ8hu7Qhp4SBfd6AsplHFfdINdZ/ tcRKfXWcQNJkcgZrdTmUVH0KBANLCPjAL43cQN9rf3TWGGTRycMQJaj88h5IvDZ15PKCbhQH/2 h0E= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="158454216" 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; 27 Jan 2021 23:13:15 +0800 IronPort-SDR: Q1QhEK+BDVTxgKcbnvbh9gMlWPcj1ZQISaVximfggfQe0EjQ2N81UhcyxLiHuORwku/OlzT4sj 58lC85miidCo5K+x12qJp7bZcW6g+LILUni2QEZnun4uWT/TPJQMEhGLmnS8+FSgkzXJPV6g8p S0BPto12LN0UedXbYtQIn0mKWxJ0tZ7sYHs3H8HtOLzfStenvMFkY9wt53OnAXYZoG0PiA6EG5 0oV0VtadNRE5TnjLt9jfzYbHh36pPR+vrX78bwW5rg6+Vbm3kEvhR9zlHd29lxtxmAN/qeq92d al+kWeAyDGl0J7hffmjImxxp 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; 27 Jan 2021 06:57:36 -0800 IronPort-SDR: w64i1XuSCkd1qWhfzqgpJYu/6un6gWY5MG5cMco/LTb0oWD2ot+QiV2kbuxzecbkMtSV4YRWPm lPGZvhbtkE52hm2QrE1N60R4E44rdvU5Xz3NHlY28Vbhz/ttPXF9PdDiTFCLsJD7pVOVB+E57t bsrqGbSG08jANbj7G4moWJIv6Yow31nlL8gOEw94LoQYGeKMgVlFvjuh6Qo++a4UVk/Dhf3mvT AHrYZdQ3uoElBZ0SvI8tNxqhey2ROcl3Ip8DtJQZRJW8Pl6yzu9qu5ZCpI7WavnuixWkmxzvvk 5LU= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:13:11 -0800 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 4/8] scsi: ufshpb: Make eviction depends on region's reads Date: Wed, 27 Jan 2021 17:12:13 +0200 Message-Id: <20210127151217.24760-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-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 --- drivers/scsi/ufs/ufshpb.c | 44 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 51c3607166bc..a16c0f2d5fac 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -18,6 +18,7 @@ #define WORK_PENDING 0 #define ACTIVATION_THRSHLD 4 /* 4 IOs */ +#define EVICTION_THRSHLD (ACTIVATION_THRSHLD << 6) /* 256 IOs */ /* memory management */ static struct kmem_cache *ufshpb_mctx_cache; @@ -639,6 +640,14 @@ 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 (ufshpb_mode == HPB_HOST_CONTROL && + atomic64_read(&rgn->reads) > (EVICTION_THRSHLD >> 1)) + continue; + victim_rgn = rgn; break; } @@ -789,7 +798,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; @@ -817,6 +826,17 @@ static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) * 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 (ufshpb_mode == HPB_HOST_CONTROL && + atomic64_read(&rgn->reads) < EVICTION_THRSHLD) { + ret = -EACCES; + goto out; + } + victim_rgn = ufshpb_victim_lru_info(hpb); if (!victim_rgn) { dev_warn(&hpb->sdev_ufs_lu->sdev_dev, @@ -1024,8 +1044,13 @@ static void ufshpb_run_active_subregion_list(struct ufshpb_lu *hpb) rgn = hpb->rgn_tbl + srgn->rgn_idx; ret = ufshpb_add_region(hpb, rgn); - if (ret) - goto active_failed; + if (ret) { + if (ret == -EACCES) { + spin_lock_irqsave(&hpb->rsp_list_lock, flags); + continue; + } + goto add_region_failed; + } ret = ufshpb_issue_map_req(hpb, rgn, srgn); if (ret) { @@ -1039,9 +1064,22 @@ static void ufshpb_run_active_subregion_list(struct ufshpb_lu *hpb) spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); return; +add_region_failed: + if (ufshpb_mode == HPB_HOST_CONTROL) { + /* + * In host control mode, it is common that eviction trials + * fail, either because the entering region didn't have enough + * reads, or a poor-performing exiting region wasn't found. + * No need to re-insert those regions to the "to-be-activated" + * list. + */ + return; + } + active_failed: dev_err(&hpb->sdev_ufs_lu->sdev_dev, "failed to activate region %d - %d, will retry\n", rgn->rgn_idx, srgn->srgn_idx); + spin_lock_irqsave(&hpb->rsp_list_lock, flags); ufshpb_add_active_list(hpb, rgn, srgn); spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); From patchwork Wed Jan 27 15:12:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 373022 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87D4EC433E6 for ; Wed, 27 Jan 2021 15:20:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F61E207E8 for ; Wed, 27 Jan 2021 15:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235778AbhA0PT0 (ORCPT ); Wed, 27 Jan 2021 10:19:26 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:46031 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235483AbhA0POo (ORCPT ); Wed, 27 Jan 2021 10:14:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760483; x=1643296483; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Pdp00ko/BXv1nquiuxIwLaZHqLcdvOgRkvfcz0tbUgY=; b=Oz2ZaqBf39evtQt0en59730/oYAMFCDBL0zRDQYVAhPhPA3LxDVvNdTA 3OSq6XvM3Gbm74gwzuwrFm2+/Tm6PQOcb7RFRaGKRQZ8VgGqLiAqNWcXQ Qragj7jekBwmNTO5DGmWgcrbxOmQC4IV9jompsYKPAjcG+vM8Ckv0BzEq zXs7jG1EgHzcb+pKtuOaGngx5oJlSgmsIOIjNsFiEVrzEsvaDhMltoDFO Qn2QnPb2a341FKNVg2WBwTXAAGXlt9q6owIMpulbPNNmGXYP4tnSetu8E JfCXP+qPFDutEV3pvOwNMk8iVCZb1rCB+Yl9baYpiDLMGFlTXUyMnbKOa w==; IronPort-SDR: fWk0L/jqTVvGlQCP4Q+NI6KdFzpkTHsgwP7nhQUIaSpRmWtVevD4mLb6pSOJPWGqlaY4Pp1kdI 36+3lRA2rLDPVRkyvCM7wI29e60iS8hZaAmyIQ/qcv8Zz4uVIF7pWoLUpeH6c2ntnwM6NehKhf 6VyZBp1vIPmsLnVQkPxeD/YlqcFEt4+2m8hv4hWi4ldqvJp4Njr+DLkLMHskfycM5pvUhRM0UQ hVGFwsaxx9fenU/mhQIWd3FRVs7ROKPjB+PeRiwna9w5aBcTVh6Mzs9gv+tfZv2N6Hw8o7Ftis LFY= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="162900980" 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; 27 Jan 2021 23:13:24 +0800 IronPort-SDR: 6elZPfMKOwleYU3U8IMoN7Y499P3YfgodhKrtm2FpuMGwRc719XDFuyw08RJWinUwRwGFTbQWD db7DK7vdOIfV3PJPCXSm+rfrVXLIVMPnXcU0Kj3kpKFB4mSkz9nYOYqGhPmXu+l3k+/22L6hN8 r3n7ewd9Ut1ciQaMV4NvaMOVjj6T1X9TYLmaN3xnKaykVUMT2vJtnaxrL7KhBWGQznmSBQvG99 g4+1chtk+A7yIglzYGKEzEvk/Jn/IB5NgKGZI+80L8rpLBTgE1i94Y6tokSWHiaZY9UJj+NzzN cK/Hw0vFf4HOY/Gwf0aitEel 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; 27 Jan 2021 06:55:43 -0800 IronPort-SDR: v5NbBKQE6kS+PQEC262KkZesCe0NZ2CTQetXbSsZIB9pQMmYfZYl0tL3bBhSJrPjzeY3GmA1EK X+fgBmQVCfqySuZmI5W1UlfjFLQzOLwYGJwZQasBCqPDn9XFwT95py8KmE9eHDq381rXdzYeco GhcfS5jDZW5Zj7pyvUd+Vsa8hj9VCoJThYNFH/EIspUmtP5lRleAh5B2ZNhc9GXusd2jtQulDI gu6RhtTb8LT6LU+51nLXXUFJTNJRqJ47mg9Y4Z1dT4ntjhPYMH5hzzrA0biMzOFzg2arSg90QN XYI= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:13:21 -0800 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 5/8] scsi: ufshpb: Region inactivation in host mode Date: Wed, 27 Jan 2021 17:12:14 +0200 Message-Id: <20210127151217.24760-6-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org I 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 --- drivers/scsi/ufs/ufshpb.c | 120 +++++++++++++++++++++++++++++++------- drivers/scsi/ufs/ufshpb.h | 4 ++ 2 files changed, 104 insertions(+), 20 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index a16c0f2d5fac..c09c8dce0745 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -386,49 +386,66 @@ void ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) hpb->stats.hit_cnt++; } +static struct ufshpb_req *ufshpb_get_req(struct ufshpb_lu *hpb, + int rgn_idx, enum req_opf dir) +{ + struct ufshpb_req *rq; + struct request *req; + + rq = kmem_cache_alloc(hpb->map_req_cache, GFP_KERNEL); + if (!rq) + return NULL; + + req = blk_get_request(hpb->sdev_ufs_lu->request_queue, + dir, 0); + if (IS_ERR(req)) + goto free_rq; + + rq->hpb = hpb; + rq->req = req; + rq->rgn_idx = rgn_idx; + + return rq; + +free_rq: + kmem_cache_free(hpb->map_req_cache, rq); + return NULL; +} + +static void ufshpb_put_req(struct ufshpb_lu *hpb, struct ufshpb_req *rq) +{ + blk_put_request(rq->req); + kmem_cache_free(hpb->map_req_cache, rq); +} + static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb, struct ufshpb_subregion *srgn) { struct ufshpb_req *map_req; - struct request *req; struct bio *bio; - map_req = kmem_cache_alloc(hpb->map_req_cache, GFP_KERNEL); + map_req = ufshpb_get_req(hpb, srgn->rgn_idx, REQ_OP_SCSI_IN); if (!map_req) return NULL; - req = blk_get_request(hpb->sdev_ufs_lu->request_queue, - REQ_OP_SCSI_IN, 0); - if (IS_ERR(req)) - goto free_map_req; - bio = bio_alloc(GFP_KERNEL, hpb->pages_per_srgn); if (!bio) { - blk_put_request(req); - goto free_map_req; + ufshpb_put_req(hpb, map_req); + return NULL; } - map_req->hpb = hpb; - map_req->req = req; map_req->bio = bio; - - map_req->rgn_idx = srgn->rgn_idx; map_req->srgn_idx = srgn->srgn_idx; map_req->mctx = srgn->mctx; return map_req; - -free_map_req: - kmem_cache_free(hpb->map_req_cache, map_req); - return NULL; } static void ufshpb_put_map_req(struct ufshpb_lu *hpb, - struct ufshpb_req *map_req) + struct ufshpb_req *map_req) { bio_put(map_req->bio); - blk_put_request(map_req->req); - kmem_cache_free(hpb->map_req_cache, map_req); + ufshpb_put_req(hpb, map_req); } static int ufshpb_clear_dirty_bitmap(struct ufshpb_lu *hpb, @@ -483,6 +500,13 @@ static void ufshpb_activate_subregion(struct ufshpb_lu *hpb, srgn->srgn_state = HPB_SRGN_VALID; } +static void ufshpb_umap_req_compl_fn(struct request *req, blk_status_t error) +{ + struct ufshpb_req *umap_req = (struct ufshpb_req *)req->end_io_data; + + ufshpb_put_req(umap_req->hpb, umap_req); +} + static void ufshpb_map_req_compl_fn(struct request *req, blk_status_t error) { struct ufshpb_req *map_req = (struct ufshpb_req *) req->end_io_data; @@ -501,6 +525,14 @@ static void ufshpb_map_req_compl_fn(struct request *req, blk_status_t error) ufshpb_put_map_req(map_req->hpb, map_req); } +static void ufshpb_set_write_buf_cmd(unsigned char *cdb, int rgn_idx) +{ + cdb[0] = UFSHPB_WRITE_BUFFER; + cdb[1] = UFSHPB_WRITE_BUFFER_ID; + put_unaligned_be16(rgn_idx, &cdb[2]); + cdb[9] = 0x00; +} + static void ufshpb_set_read_buf_cmd(unsigned char *cdb, int rgn_idx, int srgn_idx, int srgn_mem_size) { @@ -514,6 +546,27 @@ static void ufshpb_set_read_buf_cmd(unsigned char *cdb, int rgn_idx, cdb[9] = 0x00; } +static int ufshpb_execute_umap_req(struct ufshpb_lu *hpb, + struct ufshpb_req *umap_req) +{ + struct request_queue *q; + struct request *req; + struct scsi_request *rq; + + q = hpb->sdev_ufs_lu->request_queue; + req = umap_req->req; + req->timeout = 0; + req->end_io_data = (void *)umap_req; + rq = scsi_req(req); + ufshpb_set_write_buf_cmd(rq->cmd, umap_req->rgn_idx); + rq->cmd_len = HPB_WRITE_BUFFER_CMD_LENGTH; + + blk_execute_rq_nowait(q, NULL, req, 1, ufshpb_umap_req_compl_fn); + + hpb->stats.umap_req_cnt++; + return 0; +} + static int ufshpb_execute_map_req(struct ufshpb_lu *hpb, struct ufshpb_req *map_req) { @@ -673,6 +726,25 @@ 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_req *umap_req; + + umap_req = ufshpb_get_req(hpb, rgn->rgn_idx, REQ_OP_SCSI_OUT); + if (!umap_req) + return -ENOMEM; + + if (ufshpb_execute_umap_req(hpb, umap_req)) + goto free_umap_req; + + return 0; + +free_umap_req: + ufshpb_put_req(hpb, umap_req); + return -EAGAIN; +} + static void __ufshpb_evict_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) { @@ -680,6 +752,11 @@ static void __ufshpb_evict_region(struct ufshpb_lu *hpb, struct ufshpb_subregion *srgn; int srgn_idx; + + if (ufshpb_mode == HPB_HOST_CONTROL && + ufshpb_issue_umap_req(hpb, rgn)) + return; + lru_info = &hpb->lru_info; dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, "evict region %d\n", rgn->rgn_idx); @@ -1368,6 +1445,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_attrs[] = { &dev_attr_hit_cnt.attr, @@ -1376,6 +1454,7 @@ static struct attribute *hpb_dev_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, }; @@ -1392,6 +1471,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 int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index b0e78728af38..47a8877f9cdb 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -35,8 +35,11 @@ /* hpb vender defined opcode */ #define UFSHPB_READ 0xF8 #define UFSHPB_READ_BUFFER 0xF9 +#define UFSHPB_WRITE_BUFFER 0xFA #define UFSHPB_READ_BUFFER_ID 0x01 +#define UFSHPB_WRITE_BUFFER_ID 0x01 #define HPB_READ_BUFFER_CMD_LENGTH 10 +#define HPB_WRITE_BUFFER_CMD_LENGTH 10 #define LU_ENABLED_HPB_FUNC 0x02 #define HPB_RESET_REQ_RETRIES 10 @@ -158,6 +161,7 @@ struct ufshpb_stats { u64 rb_active_cnt; u64 rb_inactive_cnt; u64 map_req_cnt; + u64 umap_req_cnt; }; struct ufshpb_lu { From patchwork Wed Jan 27 15:12:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 372064 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 A9876C433E0 for ; Wed, 27 Jan 2021 15:15:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F4B5207BC for ; Wed, 27 Jan 2021 15:15:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235585AbhA0PO4 (ORCPT ); Wed, 27 Jan 2021 10:14:56 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25658 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235437AbhA0POm (ORCPT ); Wed, 27 Jan 2021 10:14:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760482; x=1643296482; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FjmDrGo/SvhF+h3fNWWxJ6aaSFusGpBlATpzroPSKmo=; b=DRM5r0zABkBd8ClhyevDx3PIDVlIhlA2+xnMqj/yphmsn7XFB7FEqI8s M9XFeOpe7pnA0Xa39TikZCbqIextJqU0tXI/GQesp6kMTtcmDA9G85eKS kE2jKVWw6fBz0Vn/KgGHe8FkSDLE3RTRZCX2xT/a2jIBFiSXyf/UPqtA0 MsQBKTkCl1VV5MyE2SZUTOh94RybmFX+NSoix2MHV7UsQdGi3lmSJJxY0 356fojHpj9QzCnjZSbVz17hew/OnxNkTme17vt0c5lf9DqhgWA8o00iJG z7f8+13ooVfY/Vik4C3Pvt6RcO/bUxveuquf0yvZsldWWqM+6H+JAEirj w==; IronPort-SDR: 3b2P9lR0BtvkgvOt+sjuadIg4djg/mdv+yn7B8NK/r1xRvjPPO5gGYtWptdFFdi6McOaNIB8fi Yfg30FlHpiRT8HnfDw5frC/aNHwhstet4LpjqkXbcddzt56YHML2EtUtoej7RW4n9k9x4oWfq4 9bjDdETMp6NMUq0DYnLYvRcIJduDsCAU/tGN2HVtDOaBEpPXk46f6iV2LxLghFLcsDUraBs6Do vKuoV+zCmVpJwujXXbO1YkZ5HgPX23Cx5Y/jzjJjOjpILyWy/+vyMi6flxxGl4ugXXXvYsgiwJ oXE= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="159631226" 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; 27 Jan 2021 23:13:31 +0800 IronPort-SDR: HoRmLC8W69ki6Y0cJnVu5SbJBv0q1aDgXtfejaAwYJys8YhCraYP76CJ/mfbmGz/PztZRzETtB TUR8mI2a2YzG17X5qTtq9hrVCHngStcM7QGKWoKpZwBftMmSp/jIXWhzKLUwD+i5OFBm/1gLSv UrGnsuqgAJliFWUSbre4tD3Q1iKJeOgz/dhJwygWSskMNmQRnQTvNzIfKvfwWOwG1fLkePT5sL U3mwiOPqbttVZi1iUxn9FyPZ0hCm/Ad5c8QAH+qrJSQZresTdq6WYR/F9/l+ipSQvZ0cKUuhD6 laTfWgr5AdIXPoAtrAyL78R/ 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; 27 Jan 2021 06:55:50 -0800 IronPort-SDR: c30zxQEYMLgwpBwamwYeHZowFmVWOvSWWE9eASk7rPG3iaMTAolktzVZBN6YumzmFtTHW9jKcm JW+AW9Yg6SclhiRov4LREPL11BDuCWQYJHDT+OpIPnhHNkUfyizwyzbkKYmYw7Zt9hW/SPYUzV KJS+2yQRzaJOw60FyUUeHarEjNkOSD3Q00JB0aLZ4irQ/I+d0DkeMRrjHa9UXKYF4jyb5JI8yI boI7x/6CgvFbghDdmIlbcyT0Z076wWEUyRRMQSFdVxSBCmrwDaFRPQ1tlhSsk1Z/e4nqJZm6xF eYg= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:13:28 -0800 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 6/8] scsi: ufshpb: Add hpb dev reset response Date: Wed, 27 Jan 2021 17:12:15 +0200 Message-Id: <20210127151217.24760-7-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-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 --- drivers/scsi/ufs/ufshpb.c | 55 ++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufshpb.h | 1 + 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index c09c8dce0745..cb99b57b4319 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -17,6 +17,7 @@ #include "../sd.h" #define WORK_PENDING 0 +#define RESET_PENDING 1 #define ACTIVATION_THRSHLD 4 /* 4 IOs */ #define EVICTION_THRSHLD (ACTIVATION_THRSHLD << 6) /* 256 IOs */ @@ -344,7 +345,8 @@ void ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) * in host control mode, reads are the main source for * activation trials. */ - if (reads == ACTIVATION_THRSHLD) { + if (reads == ACTIVATION_THRSHLD || + 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); hpb->stats.rb_active_cnt++; @@ -1061,6 +1063,24 @@ 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 (ufshpb_mode == HPB_HOST_CONTROL) { + struct ufshpb_lu *h; + struct scsi_device *sdev; + + shost_for_each_device(sdev, hba->host) { + h = sdev->hostdata; + if (!h) + continue; + + if (test_and_set_bit(RESET_PENDING, + &h->work_data_bits)) + continue; + + schedule_work(&h->ufshpb_lun_reset_work); + } + } + break; default: dev_notice(&hpb->sdev_ufs_lu->sdev_dev, @@ -1193,6 +1213,28 @@ static void ufshpb_run_inactive_region_list(struct ufshpb_lu *hpb) spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); } +static void ufshpb_reset_work_handler(struct work_struct *work) +{ + struct ufshpb_lu *hpb; + struct victim_select_info *lru_info; + struct ufshpb_region *rgn, *next_rgn; + unsigned long flags; + + hpb = container_of(work, struct ufshpb_lu, ufshpb_lun_reset_work); + + lru_info = &hpb->lru_info; + + spin_lock_irqsave(&hpb->rgn_state_lock, flags); + + list_for_each_entry_safe(rgn, next_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); + + clear_bit(RESET_PENDING, &hpb->work_data_bits); +} + static void ufshpb_normalization_work_handler(struct work_struct *work) { struct ufshpb_lu *hpb; @@ -1379,6 +1421,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; @@ -1487,9 +1531,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 (ufshpb_mode == HPB_HOST_CONTROL) + if (ufshpb_mode == HPB_HOST_CONTROL) { INIT_WORK(&hpb->ufshpb_normalization_work, ufshpb_normalization_work_handler); + INIT_WORK(&hpb->ufshpb_lun_reset_work, + ufshpb_reset_work_handler); + } hpb->map_req_cache = kmem_cache_create("ufshpb_req_cache", sizeof(struct ufshpb_req), 0, 0, NULL); @@ -1576,8 +1623,10 @@ static void ufshpb_discard_rsp_lists(struct ufshpb_lu *hpb) static void ufshpb_cancel_jobs(struct ufshpb_lu *hpb) { - if (ufshpb_mode == HPB_HOST_CONTROL) + if (ufshpb_mode == HPB_HOST_CONTROL) { + cancel_work_sync(&hpb->ufshpb_lun_reset_work); 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 47a8877f9cdb..4bf77169af00 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -183,6 +183,7 @@ struct ufshpb_lu { /* for selecting victim */ struct victim_select_info lru_info; struct work_struct ufshpb_normalization_work; + struct work_struct ufshpb_lun_reset_work; unsigned long work_data_bits; /* pinned region information */ From patchwork Wed Jan 27 15:12:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 373023 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4BC1C43381 for ; Wed, 27 Jan 2021 15:16:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BE6A207D2 for ; Wed, 27 Jan 2021 15:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343710AbhA0PQJ (ORCPT ); Wed, 27 Jan 2021 10:16:09 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:45981 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235619AbhA0PPN (ORCPT ); Wed, 27 Jan 2021 10:15:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760513; x=1643296513; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8LCpJhOcp6mb2OjMnRI5NHCjmwJ1AWYbDF0CdKK+aq8=; b=qXLLcHdJkr1sznvYHXMY8MBChp6laimt1HyhY/LO3pihNy6sPsdccNoN KsDBrxOX7YrywsOmJknfYEtH9kluhbDVZxjv4qxU0SRSM9yYo6RphYdMv gZiuL1kdNYkPjhiM4GsoAaK1V/Tn7EpXcgPCm0UQ9zdKZK3sHxfErfQdW ZJyjN7yaDEa8tjz5CjmRubaONifDaHV2kKnXxmMs4rf54Rry4ETqVxcMR 4lKn74zT+2yactvp4WFsZwTzoqW63EnOM/+iGcE+LFnEO9xhXx0495F9o 2LZ6WTNRLHd7h57JhM1mUScjQLyG+GnUl7zZLaS4uehyeDw4hlz/Mwpqz A==; IronPort-SDR: D9JrpSxhohPzAEGLCe51v3qoz29zcZQQhXcioiZUlvH2XCZgKyS5FHYdrhBP0CJqGlHGGEu5Z9 TzYvKMK1EGnBM54VTdU7tFkexM3pjtRgh8wfVj7KwfbunM22WAgQRpeOAALNZhvUBoXagPzs5d zYfgQSA0EV6GK6HhHOorORB3P/hLY0U4qkhOKmwowoJc8PMJNwNKeFUSgic8M5Izrh+v00KeB5 Ep4dvXtqF5QL8F+3VLfvq17D1h7cVO5iiRCCyDTKu1b8hiRGmK6OJu+kE9TF37reLF4Ux6aAkJ 7+Q= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="162900991" 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; 27 Jan 2021 23:13:38 +0800 IronPort-SDR: gnGTMDbW/3ZOzsn62wT2ZEMJFem3283GDkjey82ey82nQAW0uGhtiWweT+sUGJ4n/KT2vatJjY DzRBufzq/DMgyeOckLvJNO4XokZG44WueeFY1sI/f0Qg6nCxGyNfIbGMDzBkBMJ37gcUbFQUAN Vfvt1QAijeoHHrAs+Cl6mdIaKR3VG7auxWsrHQnGt2VM0pnvE+cBdEByDPbyTptu7BRnfGERlq twVyV+PO3EfLq1k7lBfKLZ+w7YW0Fdu+ar2+s775j0FkBjcUVYIN/KJ4aEJchYRcni/YJIg5KI JOKxt4sHF4MrAWwD0wYh17LB 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; 27 Jan 2021 06:55:57 -0800 IronPort-SDR: wgInEWAFnI5lo4O6WB2WBc5aGele/BMuVCCir7VxgbKoIv2ojG5kJzAgz3GezpOHb929oHGJ5l dbcfoCzCkheOp0PCFAkit9wo3tCMFIyQEb1liYG7X26uuVyO0QTWjaamJrAuNyBiOOsVIAcEIe s0rJWZ7bJ+YoQNTkbDmFsL/1HZOCwQR64Bo+L3ehV+67GT0nI7008+k88DYFthpokbcGUWHMte Yb7wSw7bUM/FbB2PeO0aHNzjZ47xQx9v4eWX/0BF5Ifbvqxb1SZ73lZnxB1WAcPUhpmolej/O3 CgA= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:13:34 -0800 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 7/8] scsi: ufshpb: Add "Cold" regions timer Date: Wed, 27 Jan 2021 17:12:16 +0200 Message-Id: <20210127151217.24760-8-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-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 exahust its READ_TO_EXPIRIES - another parameter. All this does not apply to pinned regions. Signed-off-by: Avri Altman --- drivers/scsi/ufs/ufshpb.c | 75 ++++++++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshpb.h | 7 ++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index cb99b57b4319..482f01c3b3ee 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -18,8 +18,12 @@ #define WORK_PENDING 0 #define RESET_PENDING 1 +#define TIMEOUT_WORK_PENDING 2 #define ACTIVATION_THRSHLD 4 /* 4 IOs */ #define EVICTION_THRSHLD (ACTIVATION_THRSHLD << 6) /* 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; @@ -671,12 +675,69 @@ static int ufshpb_check_srgns_issue_state(struct ufshpb_lu *hpb, return 0; } +static void ufshpb_read_to_handler(struct work_struct *work) +{ + struct delayed_work *dwork = to_delayed_work(work); + struct ufshpb_lu *hpb; + struct victim_select_info *lru_info; + struct ufshpb_region *rgn, *next_rgn; + unsigned long flags; + LIST_HEAD(expired_list); + + hpb = container_of(dwork, struct ufshpb_lu, ufshpb_read_to_work); + + if (test_and_set_bit(TIMEOUT_WORK_PENDING, &hpb->work_data_bits)) + return; + + spin_lock_irqsave(&hpb->rgn_state_lock, flags); + + lru_info = &hpb->lru_info; + + 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); + bool dirty, expired; + + if (!timedout) + continue; + + dirty = is_rgn_dirty(rgn); + expired = atomic_dec_and_test(&rgn->read_timeout_expiries); + + if (dirty || expired) + 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); + hpb->stats.rb_inactive_cnt++; + spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); + } + + clear_bit(TIMEOUT_WORK_PENDING, &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) + 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 (ufshpb_mode == HPB_HOST_CONTROL) { + rgn->read_timeout = ktime_add_ms(ktime_get(), READ_TO_MS); + atomic_set(&rgn->read_timeout_expiries, READ_TO_EXPIRIES); + } } static void ufshpb_hit_lru_info(struct victim_select_info *lru_info, @@ -1404,6 +1465,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) % @@ -1536,6 +1598,8 @@ static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) ufshpb_normalization_work_handler); INIT_WORK(&hpb->ufshpb_lun_reset_work, ufshpb_reset_work_handler); + INIT_DELAYED_WORK(&hpb->ufshpb_read_to_work, + ufshpb_read_to_handler); } hpb->map_req_cache = kmem_cache_create("ufshpb_req_cache", @@ -1562,6 +1626,10 @@ static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) ufshpb_stat_init(hpb); + if (ufshpb_mode == HPB_HOST_CONTROL) + schedule_delayed_work(&hpb->ufshpb_read_to_work, + msecs_to_jiffies(POLLING_INTERVAL_MS)); + return 0; release_m_page_cache: @@ -1624,6 +1692,7 @@ static void ufshpb_discard_rsp_lists(struct ufshpb_lu *hpb) static void ufshpb_cancel_jobs(struct ufshpb_lu *hpb) { if (ufshpb_mode == HPB_HOST_CONTROL) { + cancel_delayed_work_sync(&hpb->ufshpb_read_to_work); cancel_work_sync(&hpb->ufshpb_lun_reset_work); cancel_work_sync(&hpb->ufshpb_normalization_work); } @@ -1734,6 +1803,10 @@ void ufshpb_resume(struct ufs_hba *hba) continue; ufshpb_set_state(hpb, HPB_PRESENT); ufshpb_kick_map_work(hpb); + if (ufshpb_mode == HPB_HOST_CONTROL) + 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 4bf77169af00..86c16a4127bd 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -121,6 +121,12 @@ struct ufshpb_region { /* region reads - for host mode */ atomic64_t reads; + + /* region "cold" timer - for host mode */ + ktime_t read_timeout; + atomic_t read_timeout_expiries; + struct list_head list_expired_rgn; + }; #define for_each_sub_region(rgn, i, srgn) \ @@ -184,6 +190,7 @@ struct ufshpb_lu { struct victim_select_info lru_info; struct work_struct ufshpb_normalization_work; struct work_struct ufshpb_lun_reset_work; + struct delayed_work ufshpb_read_to_work; unsigned long work_data_bits; /* pinned region information */ From patchwork Wed Jan 27 15:12:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 372062 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C84EC433E6 for ; Wed, 27 Jan 2021 15:16:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B437A20780 for ; Wed, 27 Jan 2021 15:16:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235599AbhA0PQW (ORCPT ); Wed, 27 Jan 2021 10:16:22 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25658 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235727AbhA0PP3 (ORCPT ); Wed, 27 Jan 2021 10:15:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760528; x=1643296528; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C2n2qbZr6K8K8MlNh1JdDi0Gp2waOLViiNEO8MOhZ0s=; b=Uonukni7nqGl1uJYZqoYwV6v9MoOr07sS90UPToepsxOxi38oN2Y87nK TPKAvlM4iihAUVVwx/2OQsqs4wzLkpBGVxqLwzojoFVdZCh+t535TN+M2 LGk/erislm+CdOD7FfAVp6aG68z8HaIBmuD2dFl//LTj5qm9CCwTkfT6K Yhy0f7b7AnSYkSPQmUEQzjvkD2rQ5EuA8OVckHL8m3JPMuba7Q2MWSfE7 8lHNbNmdL3vp9TtA55GAyZTmi57BmhjU0fNJVAWMbswjEeb+jvF4IzJ+6 +AF/0yUWkztzWsHCqHD9TiL2Gb7dUmHfnk1ald1AlTWX5efs6Qn1dLGBH g==; IronPort-SDR: hwLWqOL9bWDVA/StNymDDFvmFEw64d47dpOrn1os+1A+p1SZeFX4NT7KBFTvbiOsSS9E690yE0 J22QsvhYueHZVB4+NRZuC6POFFKgaQrZuJhaPIBz9HABhObDmrlQbfds+PvxGKzMkbG4iNjwcD wLYYG85nARvAz78bp2URatH+v/OsVO7j2JzM0atrbTRqOiMzB/dMaeWQ/nEC0G9/8jCqNcvNcC G4OJRY/7iLNsW2kbAPErqqWR0GLGf5kegno7loI+elgZ2dGi5GMbzRgOeEGRORBEUmbemTc6OR Mzk= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="159631247" 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; 27 Jan 2021 23:13:45 +0800 IronPort-SDR: OGeUd8Ln1ZDER3s9Lv/aGn+y+1jPuceKcrY2Pi5U43bWaMSnYGO9XwoiVP9Vcp51VeaZ4NvU/J 9iWkUafBYpJDCAKMAbX7nN6IfTQAkUGtsm0G87rEbxSiUS1CjYlNden3NPUEq2UGdCG7DK9y1z 5c48ET/IP8pJiot/ricZ743l61l3rZlXv50eydYUbFkjRfPZdQrpW/B7Un78aMigckByUTHTpM ljfiRsDrM7hFSbuQOlOWbgQW+tFnMeaaq1qvhbV6lFtW7EgcUIuVBNyLsVqglpN7vyYaE7QkuN prl29T63d1W9PBt9+Do+rxvO 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; 27 Jan 2021 06:56:04 -0800 IronPort-SDR: o489SMbUEnyxQWr0H2UZf+VKLk5mCIyRERRszbtbajz3gCxfZiZ4cH/cCjfwtFRNsbcP6Mcbiu Kpk42Onft1VInu73GYHn42xhGdusAF0n5+6cCXDjHsZJCuoezJsoVmTvM/1GuIvTSumtCLMDTa a9YUvyKXXmmRn4v7OtqHn2OVbaJnYtpM4ppARefBzXv66x8AtME/IiaxQm7TEp6i1DsOxBBXlC eVjsDH5uBnOAu2EwxQ/SQvzR1ry4G1jBe8G04W2FbrGl2OMLBDb5WWxuSIsAdOeytLoWcQkn3p Tf4= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:13:41 -0800 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 8/8] scsi: ufshpb: Add support for host control mode Date: Wed, 27 Jan 2021 17:12:17 +0200 Message-Id: <20210127151217.24760-9-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-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 --- 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 482f01c3b3ee..3ea9f7079189 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -2035,12 +2035,6 @@ void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) int version; ufshpb_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CONTROL]; - if (ufshpb_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) {