From patchwork Thu Apr 14 22:01:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 561396 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0672C433EF for ; Thu, 14 Apr 2022 22:01:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245436AbiDNWEO (ORCPT ); Thu, 14 Apr 2022 18:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244930AbiDNWEG (ORCPT ); Thu, 14 Apr 2022 18:04:06 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32201A1472; Thu, 14 Apr 2022 15:01:39 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id b24so7977812edu.10; Thu, 14 Apr 2022 15:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IGPv67XD0S+UexNg1MndYpUIv/Udyr5RFRP/aJXCovE=; b=bI24UjLJzZzCmYaLHi0up6ApwHcMZAGRaQFWBw9xT+k8lezWFqpX3uBZyFl5yLfx1r j7fyxsvC07UZKJzfsknVLaC2ku2U4nEl+oc0uLCj9bKieaoVSWI7dtju3CUMSHzfX4x+ UQaTf1gskvgo/VCOIn7aa2MLG7QP4RygVcGHsm0sMwXyynLU4mjvdQGHdyzs/RhrvYLM swjsEgGfezFCFgG/cFabKA9MgLIFEngZcJcn1p/DTiQqNglCmCYEunfMzfJ0JY2B733Z TTVf1hqc5GS1GnghJ/DL+UZcBjdx+zSKCRoPe0FE4IMLB64DcEG+s96oDdkSGnOF4vJG kpag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IGPv67XD0S+UexNg1MndYpUIv/Udyr5RFRP/aJXCovE=; b=u6mKZyxzheXQ6cuhvkjAxHgigYwEQtJPETHxC3n1xzJCxWWkvDYK+6XJcC2hjG207V DZDsnuAfClOB+E0cbZRZBC/WmtA6zFdOcr5xZm57e9aKtdOK8ZI6Uwywp84GDQ4HeehB gR8rCJiUJ8xxPpY/I3TU/NCsGxXl2B+SXW5pXXY2z307/HLMbHGoWq+1iaIJEv5b9wJj 88TSw0OH3kbOuyje3m0d1mADtve3ajLLjD0LNBlCESlp146+fW7eqi2R/MnHkpBRZezF VzwgmjC5NQm99QOP6s206lsZfINXJikWnRO+MWe2NPQAuS9HKuk6CNvFdYs0/eextx1H s7Wg== X-Gm-Message-State: AOAM5321Zrn8AhTXg5kmlo/zdhGdAeD7DnwtubV2v+0PgC1wB+Gc16zs KgOmQ3KFp0aud4Bzxeei6L8= X-Google-Smtp-Source: ABdhPJyBo0dLY5PT89TrcCm/E+WmO1KFRDiGtRg1Uo31auDxnDTIel51F6IDjajU0S5kuhrK9mxUHw== X-Received: by 2002:a05:6402:34d4:b0:421:16c7:f474 with SMTP id w20-20020a05640234d400b0042116c7f474mr4680908edc.356.1649973697755; Thu, 14 Apr 2022 15:01:37 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id e15-20020a170906044f00b006e897e110fcsm1060948eja.48.2022.04.14.15.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 15:01:37 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, daejun7.park@samsung.com, powen.kao@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/4] scsi: ufshpb: Merge ufshpb_reset() and ufshpb_reset_host() Date: Fri, 15 Apr 2022 00:01:24 +0200 Message-Id: <20220414220127.587917-2-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414220127.587917-1-huobean@gmail.com> References: <20220414220127.587917-1-huobean@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo There is no functional change in this patch, just merge ufshpb_reset() and ufshpb_reset_host() into one function ufshpb_toggle(). Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshcd.c | 4 ++-- drivers/scsi/ufs/ufshpb.c | 36 +++++++++++++----------------------- drivers/scsi/ufs/ufshpb.h | 6 ++---- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 0899d5b8cdad..de0bc53e3ac6 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7223,7 +7223,7 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba) * Stop the host controller and complete the requests * cleared by h/w */ - ufshpb_reset_host(hba); + ufshpb_toggle(hba, HPB_PRESENT, HPB_RESET); ufshcd_hba_stop(hba); hba->silence_err_logs = true; ufshcd_complete_requests(hba); @@ -8184,7 +8184,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) /* Enable Auto-Hibernate if configured */ ufshcd_auto_hibern8_enable(hba); - ufshpb_reset(hba); + ufshpb_toggle(hba, HPB_RESET, HPB_PRESENT); out: spin_lock_irqsave(hba->host->host_lock, flags); if (ret) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 3ca745ad616c..4463a0fc619f 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -2278,38 +2278,28 @@ static bool ufshpb_check_hpb_reset_query(struct ufs_hba *hba) return flag_res; } -void ufshpb_reset(struct ufs_hba *hba) +/** + * ufshpb_toggle - switch HPB state of all LUs + * @hba: per-adapter instance + * @src: expected current HPB state + * @dest: expected target HPB state + */ +void ufshpb_toggle(struct ufs_hba *hba, enum UFSHPB_STATE src, enum UFSHPB_STATE dest) { struct ufshpb_lu *hpb; struct scsi_device *sdev; shost_for_each_device(sdev, hba->host) { hpb = ufshpb_get_hpb_data(sdev); - if (!hpb) - continue; - - if (ufshpb_get_state(hpb) != HPB_RESET) - continue; - - ufshpb_set_state(hpb, HPB_PRESENT); - } -} - -void ufshpb_reset_host(struct ufs_hba *hba) -{ - struct ufshpb_lu *hpb; - struct scsi_device *sdev; - shost_for_each_device(sdev, hba->host) { - hpb = ufshpb_get_hpb_data(sdev); - if (!hpb) + if (!hpb || ufshpb_get_state(hpb) != src) continue; + ufshpb_set_state(hpb, dest); - if (ufshpb_get_state(hpb) != HPB_PRESENT) - continue; - ufshpb_set_state(hpb, HPB_RESET); - ufshpb_cancel_jobs(hpb); - ufshpb_discard_rsp_lists(hpb); + if (dest == HPB_RESET) { + ufshpb_cancel_jobs(hpb); + ufshpb_discard_rsp_lists(hpb); + } } } diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index b475dbd78988..2825ec69a6a6 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -288,8 +288,7 @@ static int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) { return 0; static void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) {} static void ufshpb_resume(struct ufs_hba *hba) {} static void ufshpb_suspend(struct ufs_hba *hba) {} -static void ufshpb_reset(struct ufs_hba *hba) {} -static void ufshpb_reset_host(struct ufs_hba *hba) {} +static void ufshpb_toggle(struct ufs_hba *hba, enum UFSHPB_STATE src, enum UFSHPB_STATE dest) {} static void ufshpb_init(struct ufs_hba *hba) {} static void ufshpb_init_hpb_lu(struct ufs_hba *hba, struct scsi_device *sdev) {} static void ufshpb_destroy_lu(struct ufs_hba *hba, struct scsi_device *sdev) {} @@ -303,8 +302,7 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp); void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp); void ufshpb_resume(struct ufs_hba *hba); void ufshpb_suspend(struct ufs_hba *hba); -void ufshpb_reset(struct ufs_hba *hba); -void ufshpb_reset_host(struct ufs_hba *hba); +void ufshpb_toggle(struct ufs_hba *hba, enum UFSHPB_STATE src, enum UFSHPB_STATE dest); void ufshpb_init(struct ufs_hba *hba); void ufshpb_init_hpb_lu(struct ufs_hba *hba, struct scsi_device *sdev); void ufshpb_destroy_lu(struct ufs_hba *hba, struct scsi_device *sdev); From patchwork Thu Apr 14 22:01:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 563012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46C72C433FE for ; Thu, 14 Apr 2022 22:01:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245461AbiDNWEQ (ORCPT ); Thu, 14 Apr 2022 18:04:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244949AbiDNWEG (ORCPT ); Thu, 14 Apr 2022 18:04:06 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DC12A27D4; Thu, 14 Apr 2022 15:01:40 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id bg10so12533327ejb.4; Thu, 14 Apr 2022 15:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=97fWddKSGmLrVBKXP8D65MNLbFu69dXpLbEp8OeL0JY=; b=FUvHvo6j7z/nZmhOKzzWjHUmJ4eCUfA52MLjv0C1a1gYlEgCZRDzdW7Z/sAswcJ8Vw pBBixz88dtnyDEuD2J5KG9aVX/FU3TWV3a0nH7GXgyoWqsPulG8AtaU+zkPfQpmsEHg0 rIv6rhd1AHkghutCniAfuUVgdjxrJGKA/ObPj2tW6mqn9whp500GYi3FyO8196AeUbyy 58bzkKq/aZBxqFxEmYjE6BOBvtO5YG5UCmzSUEjnBPWnG3nyoNgFNVb9OnPBVcMW4IFd vsJqqUcS5Kf1JOc66KBlty8zpG8Bx/9eP/rq6zeafRpubY4stVzQWaoQuRlwumzu1cP1 U/0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=97fWddKSGmLrVBKXP8D65MNLbFu69dXpLbEp8OeL0JY=; b=70P0bd5lGzJBqmKn5dBCkApt4/jT1mVYxZ6OUzBsAJEqLsSF6kkK7+SAdxtSijfr13 Y9quSGx0YdLNypxupNwr4VWROfZSWvGwYv0tFHKjM8/Vae+TCmwtlSx7wHf2b9H8mFYL +6RJQaGYfXPy/ZpyeTcE0gEK0iwU1o6j1V5sl29RmnqGdkgfkS04CF9AUCkv4dBRPeQi oNXdLQyrwkJ6bb9SlhTRlq29oXWvsneic4eVtql+wRhBMte19sPppM0KTFHBeB6p1dHu Qw24Vt/kJ97hQ/dZNu5aSVS2t+dh9llKFR6clwMeVk/wo2p7ua6zf0a9lMv3YaZzeYMA qXhg== X-Gm-Message-State: AOAM532OLhHGexaI1KSLlt8DaqFYI+5Ro/wtwjks7qwRNUh6ZCZhsbI3 K1GHMQZiKEDqxm18m6b0ydA= X-Google-Smtp-Source: ABdhPJyRm/v7Vx4UBoSkb0eWxpgcRh2pP8zouhRhRLyiuAmxjdoay1zCFHoFGsfnqU9VaXGCgpTTrg== X-Received: by 2002:a17:907:7f8d:b0:6da:b3d6:a427 with SMTP id qk13-20020a1709077f8d00b006dab3d6a427mr3898689ejc.509.1649973698847; Thu, 14 Apr 2022 15:01:38 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id e15-20020a170906044f00b006e897e110fcsm1060948eja.48.2022.04.14.15.01.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 15:01:38 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, daejun7.park@samsung.com, powen.kao@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/4] scsi: ufshpb: Remove 0 assignment for enum value Date: Fri, 15 Apr 2022 00:01:25 +0200 Message-Id: <20220414220127.587917-3-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414220127.587917-1-huobean@gmail.com> References: <20220414220127.587917-1-huobean@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo If the first enumerator has no initializer, the value of the corresponding constant is zero. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshpb.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index 2825ec69a6a6..b7e2817d4e76 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -59,8 +59,8 @@ enum UFSHPB_MODE { }; enum UFSHPB_STATE { - HPB_INIT = 0, - HPB_PRESENT = 1, + HPB_INIT, + HPB_PRESENT, HPB_SUSPEND, HPB_FAILED, HPB_RESET, From patchwork Thu Apr 14 22:01:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 563011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABF52C433EF for ; Thu, 14 Apr 2022 22:01:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245708AbiDNWEU (ORCPT ); Thu, 14 Apr 2022 18:04:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245017AbiDNWEH (ORCPT ); Thu, 14 Apr 2022 18:04:07 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE21EA5E91; Thu, 14 Apr 2022 15:01:41 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id g18so12478057ejc.10; Thu, 14 Apr 2022 15:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=looIiUbZXlEHUGlU5ZBgu9xV9eMHycErO1AbrDOXdUA=; b=FyV2uV6NBhFd3wt4SJN67bzxmm3Am6xXqYpdq05DNRDI3AGnX7ZXwVtyMCg6wc3fLw qdEdRUjzkKCromLtTM74dHOaZBKjTkaWATPsattxuHAgrIgrYaPwpS0DACeWcLD5EETD 3Z2sAW6OnK4wU/zrJg7JWpf3oDxq1ivY8DnS0v6qDEVjt11zQL6tRGtTlBhN1+fp5QyE WNTWikUB2XCx7icC2O6H+JDy5WDAku1iJAkfD2SIaDTGRbqLvkWGdnOC5MPcxOR2aqKp qVTFKRLfw3AmbHBnxXA6hkbjzPnPkdnDu6wMPsGevjuvmuyrGE35WvghmM2qaUxZ9vYv XMBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=looIiUbZXlEHUGlU5ZBgu9xV9eMHycErO1AbrDOXdUA=; b=trloA9EHdcm+YPloVsjJq8dbF7hZg67RXkhXZAG+u1KinnmTcOEQAD8DngZ4JDXvd0 rI4JnpJXvPpZCjkO1p0fv8KLzHwDEYdH/TSjrpCgDUlvrQm6QZyDAmoJD7QjY/G22aOG Kx4Cjcs/8RjjqzS71WEbhHm4oFO7jGnrlwfTh1toeCM+SG3rtEx/vcToBg4WM6BmyIQa ynyQf/X9pYAwRqWolN3ttqD8YoS54F1BAm29oqLpAiekG717zZ15hSsI/+RBEVIX2BWs D6dWPxaKJLiRJq8pQktiQl4bRq3cc+68nhfSkM8Icz5iQg04GkRAp1J6DnCH1vopXIf7 D+zg== X-Gm-Message-State: AOAM533VAlNv2nHX0cTa60BsNFez290Hdd7Ro06kHOYLcAqIXF1vLQYk XgMy3Str0oxx1VAoTgvwX/Y= X-Google-Smtp-Source: ABdhPJwjM+0SouYfVuEnSBI4qzOhytGd+BsNEp+lc539PycxGXCxQj9sG42ebPORnmP4hKKJXbw0Ug== X-Received: by 2002:a17:906:7955:b0:6e8:a9b:8c7b with SMTP id l21-20020a170906795500b006e80a9b8c7bmr3963680ejo.691.1649973700278; Thu, 14 Apr 2022 15:01:40 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id e15-20020a170906044f00b006e897e110fcsm1060948eja.48.2022.04.14.15.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 15:01:39 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, daejun7.park@samsung.com, powen.kao@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/4] scsi: ufshpb: Cleanup the handler when device reset HPB information Date: Fri, 15 Apr 2022 00:01:26 +0200 Message-Id: <20220414220127.587917-4-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414220127.587917-1-huobean@gmail.com> References: <20220414220127.587917-1-huobean@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo "When the device is powered off by the host, the device may restore L2P map data upon power up or build from the host’s HPB READ command. In case device powered up and lost HPB information, device can signal to the host through HPB Sense data, by setting HPB Operation as ‘2’ which will inform the host that device reset HPB information." This patch is to clean up the handler and make the intent of this handler more readable. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshpb.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 4463a0fc619f..ac442f19d7f7 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -1231,7 +1231,10 @@ 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) +/** + * Set the flags of all active regions to RGN_FLAG_UPDATE, letting the host reload its L2P entries. + */ +static void ufshpb_set_region_update(struct ufshpb_lu *hpb) { struct victim_select_info *lru_info = &hpb->lru_info; struct ufshpb_region *rgn; @@ -1245,6 +1248,24 @@ static void ufshpb_dev_reset_handler(struct ufshpb_lu *hpb) spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); } +static void ufshpb_dev_reset_handler(struct ufs_hba *hba) +{ + struct scsi_device *sdev; + struct ufshpb_lu *hpb; + + __shost_for_each_device(sdev, hba->host) { + hpb = ufshpb_get_hpb_data(sdev); + if (hpb && hpb->is_hcm) + /* + * For the HPB host mode, in case device powered up and lost HPB + * information, we will set the region flag to be RGN_FLAG_UPDATE, + * it will let host reload its L2P entries(re-activate the region + * in the UFS device). + */ + ufshpb_set_region_update(hpb); + } +} + /* * This function will parse recommended active subregion information in sense * data field of response UPIU with SAM_STAT_GOOD state. @@ -1319,17 +1340,7 @@ 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); - } - } + ufshpb_dev_reset_handler(hba); break; default: From patchwork Thu Apr 14 22:01:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 561395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41340C433EF for ; Thu, 14 Apr 2022 22:01:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245615AbiDNWES (ORCPT ); Thu, 14 Apr 2022 18:04:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245126AbiDNWEJ (ORCPT ); Thu, 14 Apr 2022 18:04:09 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3F8BA66DC; Thu, 14 Apr 2022 15:01:42 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id bh17so12503120ejb.8; Thu, 14 Apr 2022 15:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3HuqqJ6TFrv0Wec+QhDogWW1PdyyO3M37oSooOZjklM=; b=aK7jMFu//JAMO93tr5N0H6x+6BVfiC1kWxpUKqIv6bAAVZrbCC35IcXTQdR5ppf4Yk Bxcx5Guumz40rr8pdOiKfdzNBqhF84Z9ZxniQrE/8n9ffKLnVs/ZGspSFOVoLJ7t90VN A4J2fF/MO4Z/aUM0cd9MfPoNBCJWwe1B09z7vcDwPldoPLtYIvlaXnxIcFf5tSvN/S4/ WkSFbCikXjKrU/8U4ZFOYyh/a29s132RJWGSjifhLfia93ADx1C0UOX8Ethno3AWSO68 B1Uq/PhDvL0IPFTOZpoP95wRrjY/TsXuSp99BeZsaree8p7KHlokJnJlMoOytdcoQJ5C SjiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3HuqqJ6TFrv0Wec+QhDogWW1PdyyO3M37oSooOZjklM=; b=bnwv7a4esS/I+YU2JwIoLP22Ffwis4gGmVUMLCKy+y6MwqIZtFoiXLWKPvXUakO4d7 CHKeT2CmIyK0E1s5qo7oFhv+rvO8qy7uvOgnkXvBQWgHK7DI+Kv2dnmoFp9lGiM3pN/A QEB2RsiGAbjtwG19G0/oUj0Uk9AkLizTZyOjQpVzs7DsRuY8s4jRlblXiCdO4BuWFg90 b9k7XH8ILOmAT8jP3hnmrG2YXiwB0ZeIzrOPGQIuX0lD1mdDOwXEh6UEK14gmDgtGdZo uUU+sreuWnBTpQkDCwnEZxII8GnRfylVkw5tSzlEsP7ffulg7ZAgFwhm1ZyggWzSc+Pi Siog== X-Gm-Message-State: AOAM533yG34H2wsq/5pq3B48kxVVFwNVTi2c/0L7jUXLQwjSAUY0SMti /IBciBNzkLlckms0q1BwoXE= X-Google-Smtp-Source: ABdhPJzBWemjPsbUBDy+qiL1YPkFpFFTYIU3ys1ZIXkyNzACh2+aG69PH4I8lD+OsV1Vb/0AZlkIEA== X-Received: by 2002:a17:906:32d0:b0:6ce:e1cf:3f2e with SMTP id k16-20020a17090632d000b006cee1cf3f2emr3876722ejk.214.1649973701365; Thu, 14 Apr 2022 15:01:41 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id e15-20020a170906044f00b006e897e110fcsm1060948eja.48.2022.04.14.15.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 15:01:40 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, daejun7.park@samsung.com, powen.kao@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/4] scsi: ufshpb: Add device reset HPB regions Infor handling for HPB device mode Date: Fri, 15 Apr 2022 00:01:27 +0200 Message-Id: <20220414220127.587917-5-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414220127.587917-1-huobean@gmail.com> References: <20220414220127.587917-1-huobean@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo In UFS HPB Spec JESD220-3A, "5.8. Active and inactive information upon power cycle ... When the device is powered off by the host, the device may restore L2P map data upon power up or build from the host’s HPB READ command. In case device powered up and lost HPB information, device can signal to the host through HPB Sense data, by setting HPB Operation as ‘2’ which will inform the host that device reset HPB information." So, for the HPB device mode, if the UFS device is reset by the RST_N pin, the active regions's information in the device will be reset, and then the device will notify the host side that it is recommended to deactivate all active region in the host HPB memory. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshpb.c | 73 ++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index ac442f19d7f7..82ca0dd5097c 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -1143,6 +1143,39 @@ static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); return ret; } +/** + *ufshpb_update_region_inactive - update a region to be deactivated later + *@hpb: per-LU HPB instance + *@region_index: the region index will be activated later + */ +static void ufshpb_update_region_inactive(struct ufshpb_lu *hpb, int region_index) +{ + int subregion_index; + struct ufshpb_region *rgn; + struct ufshpb_subregion *srgn; + + /* + * Delete this region from acctive list and add it to inactive list + */ + spin_lock(&hpb->rsp_list_lock); + ufshpb_update_inactive_info(hpb, region_index); + spin_unlock(&hpb->rsp_list_lock); + + rgn = hpb->rgn_tbl + region_index; + + /* + * Set subregion state to be HPB_SRGN_INVALID, there will no HPB read on this subregion + */ + spin_lock(&hpb->rgn_state_lock); + if (rgn->rgn_state != HPB_RGN_INACTIVE) { + for (subregion_index = 0; subregion_index < rgn->srgn_cnt; subregion_index++) { + srgn = rgn->srgn_tbl + subregion_index; + if (srgn->srgn_state == HPB_SRGN_VALID) + srgn->srgn_state = HPB_SRGN_INVALID; + } + } + spin_unlock(&hpb->rgn_state_lock); +} static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, struct utp_hpb_rsp *rsp_field) @@ -1202,25 +1235,8 @@ static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, 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, - "inactivate(%d) region %d\n", i, rgn_i); - - spin_lock(&hpb->rsp_list_lock); - ufshpb_update_inactive_info(hpb, rgn_i); - spin_unlock(&hpb->rsp_list_lock); - - rgn = hpb->rgn_tbl + rgn_i; - - spin_lock(&hpb->rgn_state_lock); - if (rgn->rgn_state != HPB_RGN_INACTIVE) { - for (srgn_i = 0; srgn_i < rgn->srgn_cnt; srgn_i++) { - srgn = rgn->srgn_tbl + srgn_i; - if (srgn->srgn_state == HPB_SRGN_VALID) - srgn->srgn_state = HPB_SRGN_INVALID; - } - } - spin_unlock(&hpb->rgn_state_lock); - + dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, "inactivate(%d) region %d\n", i, rgn_i); + ufshpb_update_region_inactive(hpb, rgn_i); } out: @@ -1255,7 +1271,10 @@ static void ufshpb_dev_reset_handler(struct ufs_hba *hba) __shost_for_each_device(sdev, hba->host) { hpb = ufshpb_get_hpb_data(sdev); - if (hpb && hpb->is_hcm) + if (!hpb) + continue; + + if (hpb->is_hcm) { /* * For the HPB host mode, in case device powered up and lost HPB * information, we will set the region flag to be RGN_FLAG_UPDATE, @@ -1263,6 +1282,20 @@ static void ufshpb_dev_reset_handler(struct ufs_hba *hba) * in the UFS device). */ ufshpb_set_region_update(hpb); + } else { + /* + * For the HPB device mode, we add all active regions to inactive list, + * they will be inactivated later in ufshpb_map_work_handler() + */ + struct victim_select_info *lru_info = &hpb->lru_info; + struct ufshpb_region *rgn; + + list_for_each_entry(rgn, &lru_info->lh_lru_rgn, list_lru_rgn) + ufshpb_update_region_inactive(hpb, rgn->rgn_idx); + + if (ufshpb_get_state(hpb) == HPB_PRESENT) + queue_work(ufshpb_wq, &hpb->map_work); + } } }