From patchwork Tue Apr 19 18:30:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 563859 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 A014AC4332F for ; Tue, 19 Apr 2022 18:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357344AbiDSSii (ORCPT ); Tue, 19 Apr 2022 14:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357617AbiDSShu (ORCPT ); Tue, 19 Apr 2022 14:37:50 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 657A23FD82; Tue, 19 Apr 2022 11:30:56 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 11so17378066edw.0; Tue, 19 Apr 2022 11:30:56 -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=/nMLlDhPnop9g4KyrUFEvrHcvhanglhDeFL7ZQagGwQ=; b=bmW71mT1hdUwk4bLQJmEY7XNptT1RccKTZ1fmJs/u4VvfIiIwZ5jlOqvRCziZQ1NJX YaxJ3KRiTrZRMAeXzN7A3Az5oaiIDbkKYIiQJsVXes4crAU3WDShGG6KiKsZAvANX0F8 uz5J7bATTpS6M8Xuivb6ZLHDfjUFwjWTsDGJmvrpQ5obPTAJclpHxYr8b4is+Fujg848 lu4u8aotfVVJ6h5FQ6j0xpJxjc/y7uST9gOihiboBSTYoO0Tmzex0Ue/KcMm4JnSA9Bw rZnmz/y2yXYbFrwJFziFzEMW6FvkqnyeCfT5k+OoliJdhKg9z6A6xSwqWe3C3pTeVwbR yiaQ== 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=/nMLlDhPnop9g4KyrUFEvrHcvhanglhDeFL7ZQagGwQ=; b=NQmADpJNAgbPM2nSZw0ree9yfTP+Q/L1vPzD6cRTq9V/LSUuhgDxUsKnXCc/5tzxIB mEPeCiFlnfjOhQ7ePPBV2nM3rrCJxgDkWOBkuRUPZOPicbToGQP49gN/d4FmMnEpfg2n O5JZsxJAEuzeRmIbDbcU9amCCg9o7AzGEND9AjOEzo7DA+MbOmbFxJMlM9oYcVvW+2lT UPQEei+dGfP9/b1m49coqfu/BZQG6O5PqKoIVVjsqABC6H/tA59pgfaMtXwL47VN1DC2 KvkXGRvAvxOiDs1fFTrVW682WxJgvWg69XOQEYFHK6FxUYU2LzN5FaKKwbHeW2eddgf2 49fw== X-Gm-Message-State: AOAM530ToB8iklEgVOf59lTPKFErzL27RsRZeB6rMlG/37UTopsf4R5p 6wj6P3EbPDTYWlGVJ1ouay0= X-Google-Smtp-Source: ABdhPJyD7CINQv+BWj19/jswAEpH8TDbfJGztG6Bm1Zhnqje/oKF4xZP7cV+0xE259Km7F7M9XVrMQ== X-Received: by 2002:a05:6402:ea8:b0:41d:78ca:b929 with SMTP id h40-20020a0564020ea800b0041d78cab929mr18899620eda.289.1650393054897; Tue, 19 Apr 2022 11:30:54 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id bq23-20020a056402215700b0041d8fcac53asm8799915edb.23.2022.04.19.11.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 11:30:54 -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, cang@codeaurora.org, daejun7.park@samsung.com, powen.kao@mediatek.com, peter.wang@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/5] scsi: ufshpb: Merge ufshpb_reset() and ufshpb_reset_host() Date: Tue, 19 Apr 2022 20:30:40 +0200 Message-Id: <20220419183044.789065-2-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220419183044.789065-1-huobean@gmail.com> References: <20220419183044.789065-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..9df032e82ec3 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: target HPB state to switch to + */ +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 Tue Apr 19 18:30:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 564269 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 6C6CBC3527A for ; Tue, 19 Apr 2022 18:35:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355038AbiDSSi1 (ORCPT ); Tue, 19 Apr 2022 14:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357619AbiDSShv (ORCPT ); Tue, 19 Apr 2022 14:37:51 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DA3F3FDA1; Tue, 19 Apr 2022 11:30:57 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id k23so34681475ejd.3; Tue, 19 Apr 2022 11:30:57 -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=l4gaGxR7QY976pTLr51DV5OFFvZ4SvJxGNErfabGm/GnDcsHJDY/Gdk/2Z0EkzaQLq s7p0x+toR+dVXKzTOT/KpgKoBkUKU27RVLblkE0A9OXiqrtVu8G31A8/n9v6B8Sfk25u 3EsqcW67ipUUI1wd6PXhpolMX3CkD8cPku7CLVV38euJBrhPIwjvYyAI9OejewDE4cpd tWMS6Me9ASCDuQsGmBcUOXqQbHO8qHPX4lQcfZXWX0HPMrGjnsZTbNGb2V3XvSW0OUiU F9IKzakhpNdtaDKBg775xKB9RG9zVpPWnPIbruH8DyRNCQi4n2u1CEC9w7V9BciV+QFj e3KQ== 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=RKEh80dVSxUvueiQ/YKrqRbLs1iDoVCS4VTGjv+h0wN31ExfEVlYHSkPVVeUz2yqzn 7ky82ua94FNQY8ybiP8Q+Yfyqr7OsWUlwwJUFWioyINvX3uTYDI7TmBklEmuNjTa5m3I ElN44T0biBYj3IiW//53fHjnPkdVhYIb5DcSoqpGyXtum9MbIHuPldT2tx5e3BA+0vQs UlJJFtYFryrvjhZARP3raphyS9A3WXa5ISchTjRqnU7wPx2ax9TlpVf6cikDqc82ZmU6 P25J14wMBH1v7onCLzNMdYyp1yPApZrSJKIdniCiygbVnr30jtM8WHKCkJ5SHR4Hj2Hp H3TA== X-Gm-Message-State: AOAM530QraoSAQaHqXAi7ZzdUuB6chxwRGYTIwGLl8+thEICt0J69d8p 9QjfKs/bqlkH3lfFbJHU6Uc= X-Google-Smtp-Source: ABdhPJy40m5Mj+RdiYvb/wXuHzxxId5OkZmRF/y55+fiCI2YZOOZ0XAkb8ztMvmaAqyjR4wELyXmFA== X-Received: by 2002:a17:907:3da5:b0:6e8:c2c8:1f18 with SMTP id he37-20020a1709073da500b006e8c2c81f18mr14463438ejc.728.1650393055646; Tue, 19 Apr 2022 11:30:55 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id bq23-20020a056402215700b0041d8fcac53asm8799915edb.23.2022.04.19.11.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 11:30:55 -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, cang@codeaurora.org, daejun7.park@samsung.com, powen.kao@mediatek.com, peter.wang@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] scsi: ufshpb: Remove 0 assignment for enum value Date: Tue, 19 Apr 2022 20:30:41 +0200 Message-Id: <20220419183044.789065-3-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220419183044.789065-1-huobean@gmail.com> References: <20220419183044.789065-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 Tue Apr 19 18:30:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 564268 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 7190BC433F5 for ; Tue, 19 Apr 2022 18:35:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357283AbiDSSib (ORCPT ); Tue, 19 Apr 2022 14:38:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357620AbiDSShv (ORCPT ); Tue, 19 Apr 2022 14:37:51 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08D0F3FDA3; Tue, 19 Apr 2022 11:30:58 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id k23so34681546ejd.3; Tue, 19 Apr 2022 11:30:57 -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=K58kqXUDzWjZzDY1bjT5aDipXJoJyyUTkMqZrlco4wA=; b=dKelcTJDsnum7ZKzW2/NDFb+blrxkiDUow4HfKE1eA7gJVJ+wKGOQtcoMduAtdaxzT gu8SlYfKb2+SmEWL5JzSHbyrmWX6hNpjqftqeoaTNj+nV1q3yZG/r9NfveimfV156zd4 D/JTuN2WjW1pli8B998nbv2BAN3AXrc/4x76EcpOJ+gUc8g7z3qHuwaz2O0tf89KZgsP 8DP444APaS7k+XuYBakOqfvmkBo4af9RUClHlXE2A/InMMLHSJM3Ac2EZW/8EpojIf73 k/dIDPq+AXdvuMoba+rYqPf216cTiCeAhP/tsMNpAiY+krRRMYvgiI+w50o5T1Gwrvlk RZ/Q== 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=K58kqXUDzWjZzDY1bjT5aDipXJoJyyUTkMqZrlco4wA=; b=3yAan5eUKPBBH3hHFgYw2VZ4Ucnr9XZpGFJQY0HAJQEIajYtnmApwjf4aaBraYQ0FQ O4VkXJVLyTwtGA/xfOrAxCf434nb+nsECW1rsdVS3e1fETiGWv8lqHEoeqPUBXZZEm6o nvINtGgjmK9tN8iTtwCk/c/ZnXyjyqQcWpbDztnqJP6hjjEOX3UWyXEaRQ5yDouJBZfp 6e/jMPElr6Y8xyMoLmIG7pIfbEKvmhwoUuA/QSLpS2HGCjaNn8WrAjG4GOEzN1bnRbJU M/JweQa9mcuzAm0yZV4K419s2iVoy1Vj04LM7sjOKs/vJkZOuA1oc+954t3OPua5ItQJ dF7A== X-Gm-Message-State: AOAM531FceVcNfb06nntV2dbca0FuASl4b1P5Sj0N3e/i2Qc6ILHCVgb zCDLGn0sinGnl1jazS/PVWo= X-Google-Smtp-Source: ABdhPJxr5BSggcSmFl0rnn4nGLNOLvnNRvNGQXlTW6BCftocTCGsRt6GC3znJtiRxML6UhVrS8/vMA== X-Received: by 2002:a17:907:7f9f:b0:6ef:a120:4ea6 with SMTP id qk31-20020a1709077f9f00b006efa1204ea6mr10818840ejc.607.1650393056549; Tue, 19 Apr 2022 11:30:56 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id bq23-20020a056402215700b0041d8fcac53asm8799915edb.23.2022.04.19.11.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 11:30:56 -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, cang@codeaurora.org, daejun7.park@samsung.com, powen.kao@mediatek.com, peter.wang@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] scsi: ufshpb: Cleanup the handler when device reset HPB information Date: Tue, 19 Apr 2022 20:30:42 +0200 Message-Id: <20220419183044.789065-4-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220419183044.789065-1-huobean@gmail.com> References: <20220419183044.789065-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, no functional change. 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 9df032e82ec3..4538164fc493 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 to let host side reload L2P entries later + */ +static void ufshpb_set_regions_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_regions_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 Tue Apr 19 18:30:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 563861 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 377E1C433F5 for ; Tue, 19 Apr 2022 18:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357216AbiDSSi3 (ORCPT ); Tue, 19 Apr 2022 14:38:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357621AbiDSShv (ORCPT ); Tue, 19 Apr 2022 14:37:51 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC3693FDAC; Tue, 19 Apr 2022 11:30:58 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 21so22452586edv.1; Tue, 19 Apr 2022 11:30:58 -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=quF0kGFJZARtpZdxF32uHKlym+kdTs0MbLMlThQPGOk=; b=ALdJe0/n8CLQQkXATOw+mP6ETLroIdVvEXBh4bny8gcUHVzwFdgyQOYGaG3LLVBsOy R6CNsgFGBmNN0HLHdZMhmGFrFpLmvoml3mrYl4orTrSP8FjiKKl6motRIinRA8JbZhq1 fGJXKqnvmz9ZXIFsUPwOF9JlnAsk3TqPA4xZnqoGhk7Qey9Mv6m6BcLJCco+tUO7JzaK q5Hv0k5D77eU+ohxtQ0XPZDZ3b+/Iq3NSEjYjrKlQu+F+l6VSss+WxH9oL0foBO9Wn93 DVjDKVQlTsaIgvIkypzh3UINVqr9zaMxcTbEpxyUxb5FPjBx1G5GKtNc7ifzJdPiCNf+ Od+A== 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=quF0kGFJZARtpZdxF32uHKlym+kdTs0MbLMlThQPGOk=; b=1+y4zeP1mCmOrOdzzV6VLZsIzV0mSVX0i59C88ODx9XRr1geHarYTpnHNjmOmNwuLh /PsS6xp9DaM+VkELoNB5FL08jzgdaL9d5Gx0/U7XxgkyQl8Qid88wNXitmhXfYKtbO3a SfblcOzcpKYSFQrio+cHcKMpcifXN+6YErLVB8fS2KPQTYJaaBKCPcAs0ugvhsAUMAST RR0kvcRQ9A+M+50M3xE0UyKTuVB8yxE5AAdzeBfW2qmTPeqHN9VoqbBD4604C8xiuURy 5VyTISNGzAX+6JIuc6xqUgtglnJHIulBoK/7A0QcrYDap2UjhnGFAtnxdhQiaC5v0reX wzGw== X-Gm-Message-State: AOAM532thZIQC+nvoeGBcXzclQagS3ra2cEa8CNFLX9QeIMcwl5Nx1B8 rGc0c4WKzbn5uEzifbmuF1U= X-Google-Smtp-Source: ABdhPJyWEhY+u7KTDVJXiiqlYrBD+6qdbWkkxBlC3rcgahcZC2o0tXsZyNRMLfckCmul0NN+FKI0RQ== X-Received: by 2002:aa7:db0f:0:b0:41d:7b44:2613 with SMTP id t15-20020aa7db0f000000b0041d7b442613mr18735469eds.126.1650393057426; Tue, 19 Apr 2022 11:30:57 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id bq23-20020a056402215700b0041d8fcac53asm8799915edb.23.2022.04.19.11.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 11:30:57 -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, cang@codeaurora.org, daejun7.park@samsung.com, powen.kao@mediatek.com, peter.wang@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] scsi: ufshpb: Add handing of device reset HPB regions Infos in HPB device mode Date: Tue, 19 Apr 2022 20:30:43 +0200 Message-Id: <20220419183044.789065-5-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220419183044.789065-1-huobean@gmail.com> References: <20220419183044.789065-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." Therefore, for HPB device control mode, if the UFS device is reset via the RST_N pin, the active region information in the device will be reset. If the host side receives this notification from the device side, it is recommended to inactivate all active regions in the host's HPB cache. 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 4538164fc493..4b15fa862beb 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_submit_region_inactive() - submit a region to be inactivated later + *@hpb: per-LU HPB instance + *@region_index: the index associated with the region that will be inactivated later + */ +static void ufshpb_submit_region_inactive(struct ufshpb_lu *hpb, int region_index) +{ + int subregion_index; + struct ufshpb_region *rgn; + struct ufshpb_subregion *srgn; + + /* + * Remove this region from active region 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_submit_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_regions_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_submit_region_inactive(hpb, rgn->rgn_idx); + + if (ufshpb_get_state(hpb) == HPB_PRESENT) + queue_work(ufshpb_wq, &hpb->map_work); + } } } From patchwork Tue Apr 19 18:30:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 563860 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 378F8C433EF for ; Tue, 19 Apr 2022 18:35:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357325AbiDSSie (ORCPT ); Tue, 19 Apr 2022 14:38:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357622AbiDSShv (ORCPT ); Tue, 19 Apr 2022 14:37:51 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A33C73FDB5; Tue, 19 Apr 2022 11:30:59 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id c6so22390621edn.8; Tue, 19 Apr 2022 11:30:59 -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=asQR7zN/XNqbk75IdkIIvMcykcD0n/R0IhNlXpw8b/8=; b=U8PVwNJbHKakFbCBfMIZNubo80awJYXhDlBQ0Lxsr52TsItMW0m1wMDFITolgED++c 0MmcSveoAJ6MurJHyTJWf1XdI2qKth36l8s7fORa86DN+uu4JI2mzNAQ0kjb+n7mSrvT kyWvqR0Sw7zC/JB395xwttpT/WUrp/yttQzGp5NQzoKg/jjXdlG3d+qJDBv+jdH2mXJH WbZ0BNMeN4nd39DCM2c5KN7v7HTfrmSZts71k6eDBgeLMgW4QNlW5S9F5e4SilZKENo8 p6FYgKApejZLmFJSaD7Sl3c20n/cfvWsLjeRAwgRz5wUMhvoAcMR05WQJcY/xaoB4wcq XPXg== 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=asQR7zN/XNqbk75IdkIIvMcykcD0n/R0IhNlXpw8b/8=; b=gZaZV3XLcZ6w1eWA/1xV4SgJkEDHhf+un4I2gt++z4aIqg5aZT/5lOrz5ybZDo5+ma n83VevgXGJ7l1dOi19JFMlcRUgUpHTZq06U4zrsHJTPBKeHgbkXZL/eGEt8Ds8cTFTRH ml5yJJxhEVk8U1QcEU7MMxkks3oBo/F0gPpsm0B7ShExPrVbcdXaMpPWAlZy1u9esz1Q wnqs62uTGzK3KRdX429BeN0z1rYC9HkERsx4vmi6n0T8I6xGrgcNhDjTL87Wz7PIFhVZ iqprAyxtdnJmyyCKw87O2AV//Qx3GLkjlWhdG7oFGY1jtsvdjckyW5DkdZAjS3HPHTme xFxg== X-Gm-Message-State: AOAM530YtEJ3+XNTPQeeSNJJ54SLakx2olnoom0USCF6VtoyzShR/my1 EuXBWRl1JhH8Y9k958+WTyM= X-Google-Smtp-Source: ABdhPJykrYzUE5FPB44JUthiGF5Brjn/CSN4UgNGAv+EBxSn1Mae7UVPSGCEdYO2ivDR/3cpE4x0jg== X-Received: by 2002:a05:6402:26c9:b0:423:d545:9d49 with SMTP id x9-20020a05640226c900b00423d5459d49mr16670208edd.242.1650393058264; Tue, 19 Apr 2022 11:30:58 -0700 (PDT) Received: from linux.. (p5dd1ed70.dip0.t-ipconnect.de. [93.209.237.112]) by smtp.gmail.com with ESMTPSA id bq23-20020a056402215700b0041d8fcac53asm8799915edb.23.2022.04.19.11.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 11:30:57 -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, cang@codeaurora.org, daejun7.park@samsung.com, powen.kao@mediatek.com, peter.wang@mediatek.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] scsi: ufshpb: Cleanup ufshpb_suspend/resume Date: Tue, 19 Apr 2022 20:30:44 +0200 Message-Id: <20220419183044.789065-6-huobean@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220419183044.789065-1-huobean@gmail.com> References: <20220419183044.789065-1-huobean@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo ufshpb_resume() is only called when the HPB state is HPB_SUSPEND, so the check statement for "ufshpb_get_state(hpb) != HPB_PRESENT" is useless. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshpb.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 4b15fa862beb..0e3bfd241f87 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -2354,11 +2354,9 @@ void ufshpb_suspend(struct ufs_hba *hba) shost_for_each_device(sdev, hba->host) { hpb = ufshpb_get_hpb_data(sdev); - if (!hpb) + if (!hpb || ufshpb_get_state(hpb) != HPB_PRESENT) continue; - if (ufshpb_get_state(hpb) != HPB_PRESENT) - continue; ufshpb_set_state(hpb, HPB_SUSPEND); ufshpb_cancel_jobs(hpb); } @@ -2371,20 +2369,15 @@ void ufshpb_resume(struct ufs_hba *hba) shost_for_each_device(sdev, hba->host) { hpb = ufshpb_get_hpb_data(sdev); - if (!hpb) + if (!hpb || ufshpb_get_state(hpb) != HPB_SUSPEND) continue; - if ((ufshpb_get_state(hpb) != HPB_PRESENT) && - (ufshpb_get_state(hpb) != HPB_SUSPEND)) - continue; ufshpb_set_state(hpb, HPB_PRESENT); ufshpb_kick_map_work(hpb); if (hpb->is_hcm) { - unsigned int poll = - hpb->params.timeout_polling_interval_ms; + unsigned int poll = hpb->params.timeout_polling_interval_ms; - schedule_delayed_work(&hpb->ufshpb_read_to_work, - msecs_to_jiffies(poll)); + schedule_delayed_work(&hpb->ufshpb_read_to_work, msecs_to_jiffies(poll)); } } }