From patchwork Wed Oct 16 20:11:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836578 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 541DA12E4A for ; Wed, 16 Oct 2024 20:13:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109594; cv=none; b=IXvS6ZjUuyPMHVlqalS+LLk9yw7wFBJ/JiWh5+pEB56KmeTpXAcHcGY2RLvPK22LVa+/82c5Golrx54mIaFXC/yF3zuiQWTnIhmh7iyBEtrcsLf2qbJsi0iL/dnWlHmj/7UqHwfNBqgiYFFifRqR9hNbGwf2rHa9jKVrnhfWDbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109594; c=relaxed/simple; bh=bpMReAwJswMYvGeC7UoXFo4kmL9Jddce1tjz4YVsCEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bxc9OyCvyky0Ma+Bb2dvzS9gTiyoI9cZWviaJ5H2yng7t5wX3S9R037s2YeW7lZEp9eMSd1gEjO/5ZljRcSddJgEGkid40caF8EVkejA6+8L4YCk0nhNCj/SpJM8VOuZMaYmkmWO39Y60n9WJIthKeBypjmrMF1RdcWFA2cb9Fg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=u3HiBNEM; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="u3HiBNEM" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMbX4qBJz6ClY9l; Wed, 16 Oct 2024 20:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109583; x=1731701584; bh=8B4U8 k/O/uJHBPZe7ncHwFShjwIJYlJwBtC/aQZKr6Y=; b=u3HiBNEMRchziUDSeokZk 3NL+fiPzcfVOKlHLto0jyrmaGVih8bAWZl2eZ8p/qbEr6zhUdVmSJFpAzSO9D9ko Xx0qJGdNelQHBEvtPXlH0HBReR9znOWlCRIfQR/OmLm7eZPd3htzT9MCUfnaytNt VC0Wu4nYHxuCIDWU8/jDmvHpQY4S4lRQOOCrCc+bdRyctSKONG724nfZOk9P1iTH 7Sjcd6G8UjmWPlOQl/0/Uw/6kxsbQvduVIG5z7RthyglfbnQ1iw1YDl+osnnlVAG c1shf6MXD9oRoIf/wuh8uuc3UczAsRfRl30vqRbCRIPvpl+2L23EN/fUo8XqUYhw Q== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 7aLnhjcA6_i2; Wed, 16 Oct 2024 20:13:03 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMbK4D33z6Cnk9T; Wed, 16 Oct 2024 20:13:01 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Avri Altman , Bean Huo , "Bao D. Nguyen" , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Andrew Halaney , Maramaina Naresh Subject: [PATCH v6 01/11] scsi: ufs: core: Introduce ufshcd_add_scsi_host() Date: Wed, 16 Oct 2024 13:11:57 -0700 Message-ID: <20241016201249.2256266-2-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the code for adding a SCSI host and also the code for managing TMF tags from ufshcd_init() into a new function called ufshcd_add_scsi_host(). This patch prepares for combining the two scsi_add_host() calls into a single call. No functionality has been changed. Reviewed-by: Avri Altman Reviewed-by: Bean Huo Reviewed-by: Bao D. Nguyen Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 96 ++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 9e6d008f4ea4..959509d9445e 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10377,6 +10377,62 @@ static const struct blk_mq_ops ufshcd_tmf_ops = { .queue_rq = ufshcd_queue_tmf, }; +static int ufshcd_add_scsi_host(struct ufs_hba *hba) +{ + int err; + + if (!is_mcq_supported(hba)) { + if (!hba->lsdb_sup) { + dev_err(hba->dev, + "%s: failed to initialize (legacy doorbell mode not supported)\n", + __func__); + return -EINVAL; + } + err = scsi_add_host(hba->host, hba->dev); + if (err) { + dev_err(hba->dev, "scsi_add_host failed\n"); + return err; + } + hba->scsi_host_added = true; + } + + hba->tmf_tag_set = (struct blk_mq_tag_set) { + .nr_hw_queues = 1, + .queue_depth = hba->nutmrs, + .ops = &ufshcd_tmf_ops, + .flags = BLK_MQ_F_NO_SCHED, + }; + err = blk_mq_alloc_tag_set(&hba->tmf_tag_set); + if (err < 0) + goto remove_scsi_host; + hba->tmf_queue = blk_mq_alloc_queue(&hba->tmf_tag_set, NULL, NULL); + if (IS_ERR(hba->tmf_queue)) { + err = PTR_ERR(hba->tmf_queue); + goto free_tmf_tag_set; + } + hba->tmf_rqs = devm_kcalloc(hba->dev, hba->nutmrs, + sizeof(*hba->tmf_rqs), GFP_KERNEL); + if (!hba->tmf_rqs) { + err = -ENOMEM; + goto free_tmf_queue; + } + + return 0; + +free_tmf_queue: + blk_mq_destroy_queue(hba->tmf_queue); + blk_put_queue(hba->tmf_queue); + +free_tmf_tag_set: + blk_mq_free_tag_set(&hba->tmf_tag_set); + +remove_scsi_host: + if (hba->scsi_host_added) + scsi_remove_host(hba->host); + + return err; +} + /** * ufshcd_init - Driver initialization routine * @hba: per-adapter instance @@ -10508,41 +10564,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->is_irq_enabled = true; } - if (!is_mcq_supported(hba)) { - if (!hba->lsdb_sup) { - dev_err(hba->dev, "%s: failed to initialize (legacy doorbell mode not supported)\n", - __func__); - err = -EINVAL; - goto out_disable; - } - err = scsi_add_host(host, hba->dev); - if (err) { - dev_err(hba->dev, "scsi_add_host failed\n"); - goto out_disable; - } - hba->scsi_host_added = true; - } - - hba->tmf_tag_set = (struct blk_mq_tag_set) { - .nr_hw_queues = 1, - .queue_depth = hba->nutmrs, - .ops = &ufshcd_tmf_ops, - .flags = BLK_MQ_F_NO_SCHED, - }; - err = blk_mq_alloc_tag_set(&hba->tmf_tag_set); - if (err < 0) - goto out_remove_scsi_host; - hba->tmf_queue = blk_mq_alloc_queue(&hba->tmf_tag_set, NULL, NULL); - if (IS_ERR(hba->tmf_queue)) { - err = PTR_ERR(hba->tmf_queue); - goto free_tmf_tag_set; - } - hba->tmf_rqs = devm_kcalloc(hba->dev, hba->nutmrs, - sizeof(*hba->tmf_rqs), GFP_KERNEL); - if (!hba->tmf_rqs) { - err = -ENOMEM; - goto free_tmf_queue; - } + err = ufshcd_add_scsi_host(hba); + if (err) + goto out_disable; /* Reset the attached device */ ufshcd_device_reset(hba); @@ -10600,9 +10624,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) free_tmf_queue: blk_mq_destroy_queue(hba->tmf_queue); blk_put_queue(hba->tmf_queue); -free_tmf_tag_set: blk_mq_free_tag_set(&hba->tmf_tag_set); -out_remove_scsi_host: if (hba->scsi_host_added) scsi_remove_host(hba->host); out_disable: From patchwork Wed Oct 16 20:11:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836086 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EF2912E4A for ; Wed, 16 Oct 2024 20:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109597; cv=none; b=hXUxEX+lJKugR33SB2NPpWQzKO6zzXWJovOItursjQrUnZW/wHhycb+i/feWvnbVzcO3lU4Lvf04CWTJLbxB8dFx/+DretW4a9wKiQOXG16a3q2NzWE4ht1qGehOHkQBNbZT84Rmhd5IIh2jOJHQ16AC/Jt+Q2DpARhdVwloWko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109597; c=relaxed/simple; bh=wXRP63UqwTiWOhTtBpP2JaKHGS6kVr2G7L9rhqX80Xs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hUU1bHIp3xrDr1aDcO5tq+KIqTFfxXLC8PI10wUurQXnEyvympoSbGftUK0xi5mX7czZgQ3N8OYtemUMIUj+fr9sLWphGzm855eMeMDwaAMshxuFfA3N7KdEo1N8ldTOi7IOvYwr1yxv5Fco9loSEZXejmnWLSwHsal5S2pgY/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=fffyvqjk; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="fffyvqjk" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMbb5dM8z6ClY9l; Wed, 16 Oct 2024 20:13:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109589; x=1731701590; bh=pquFk 9TI0O7CiEdHrqHuxbcIDkqw6Lygfnrgo1oOLCs=; b=fffyvqjkz1Rz59G7/e/al 2kPe8w65GLHtYTMtG3Iu2JGwCBG0HMJGLk8s1Xjco9kuaweaXcjN31nJxqPvGg/x Ti0g73/gcXZ1NqIWIgovXaOEfQIOuxUHIuVHibZQ+pB+PQEqPqjqz0Cef6jRCocn V0UfQWTNhDxWcVw6scwCtFyvUgsxkbbpQUFMd7VUqK+0eC2IVHNNnx7CVJfN1o3F 4io8gEpAH4r5TcWZr3suAOBa7VefgDVxNxO/4iHN6AazYtln/03jljaxRqUT3ctT Bn5NuHUBBuLAUDEMLsz/CnqcHJPUgFPVpNzPzCam7G/Cn1MvvPcmAL2Yst3f3wJp Q== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id vHk8GNzeukTe; Wed, 16 Oct 2024 20:13:09 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMbR5Xhgz6ClY9d; Wed, 16 Oct 2024 20:13:07 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Avri Altman , Manivannan Sadhasivam , "Bao D. Nguyen" , "James E.J. Bottomley" , Peter Wang , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 02/11] scsi: ufs: core: Introduce ufshcd_post_device_init() Date: Wed, 16 Oct 2024 13:11:58 -0700 Message-ID: <20241016201249.2256266-3-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Prepare for inlining one ufshcd_device_init() call by introducing the new function ufshcd_post_device_init(). No functionality has been changed. Reviewed-by: Avri Altman Reviewed-by: Manivannan Sadhasivam Reviewed-by: Bao D. Nguyen Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 62 ++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 959509d9445e..17c22e880cef 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8732,6 +8732,40 @@ static void ufshcd_config_mcq(struct ufs_hba *hba) hba->nutrs); } +static int ufshcd_post_device_init(struct ufs_hba *hba) +{ + int ret; + + ufshcd_tune_unipro_params(hba); + + /* UFS device is also active now */ + ufshcd_set_ufs_dev_active(hba); + ufshcd_force_reset_auto_bkops(hba); + + ufshcd_set_timestamp_attr(hba); + schedule_delayed_work(&hba->ufs_rtc_update_work, + msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); + + if (!hba->max_pwr_info.is_valid) + return 0; + + /* + * Set the right value to bRefClkFreq before attempting to + * switch to HS gears. + */ + if (hba->dev_ref_clk_freq != REF_CLK_FREQ_INVAL) + ufshcd_set_dev_ref_clk(hba); + /* Gear up to HS gear. */ + ret = ufshcd_config_pwr_mode(hba, &hba->max_pwr_info.info); + if (ret) { + dev_err(hba->dev, "%s: Failed setting power mode, err = %d\n", + __func__, ret); + return ret; + } + + return 0; +} + static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) { int ret; @@ -8801,33 +8835,7 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) } } - ufshcd_tune_unipro_params(hba); - - /* UFS device is also active now */ - ufshcd_set_ufs_dev_active(hba); - ufshcd_force_reset_auto_bkops(hba); - - ufshcd_set_timestamp_attr(hba); - schedule_delayed_work(&hba->ufs_rtc_update_work, - msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); - - /* Gear up to HS gear if supported */ - if (hba->max_pwr_info.is_valid) { - /* - * Set the right value to bRefClkFreq before attempting to - * switch to HS gears. - */ - if (hba->dev_ref_clk_freq != REF_CLK_FREQ_INVAL) - ufshcd_set_dev_ref_clk(hba); - ret = ufshcd_config_pwr_mode(hba, &hba->max_pwr_info.info); - if (ret) { - dev_err(hba->dev, "%s: Failed setting power mode, err = %d\n", - __func__, ret); - return ret; - } - } - - return 0; + return ufshcd_post_device_init(hba); } /** From patchwork Wed Oct 16 20:11:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836577 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0540D12E4A for ; Wed, 16 Oct 2024 20:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109603; cv=none; b=AAuDMlxKtJuGZVh806mOj2kWKjuU4Ido04McqJR3XxZKv8W5jYy/9+ufffJU44TJhhAqSJUZBlqYPvSnXPY86MB/N6P1zm9l0ZwGflqIpc0f2ZgrIMI+BVqpRBjOfmKZ3MdYplqeyRpRnFqqZtbaLK/TUDWI/+O15nl+SM+vzCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109603; c=relaxed/simple; bh=1u9W0UVV1kxoSTpzz5IgFEAL5FTGNwluT8g/j2VjMyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SBN2gYWzGGO9fKGknjHz05nXRDU37ALG8sY2qviX/YF27wFoQ3qH05uy8LQGpUaOnD5Q/q3lGcoNT8ZXN1KDeEPZIDWQC9UHEwgqj9NCyv8MO3taZO2kew8xD8SAW2dxDm8h9uBRN0EtzM1SjT1qXL8cUJ/ntB/711Ro3uHTug4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=dMaRx0cx; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="dMaRx0cx" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMbj3hr8z6ClY9l; Wed, 16 Oct 2024 20:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109595; x=1731701596; bh=Qff3Z vJGx1Rk01P3Futdi2VhVug8QU9Lh1vOk6C4gg8=; b=dMaRx0cxbY9qkAzUqmSN2 XNbiQrskKEjlcpUheeNgJF5JKnswQFNrsLxhWsBfk1TEX7vSYFWdZ1wG2z2QVMgl 5mIpEzhdcqLBIYJ+OLhArupCbH1VnbdMCYRO2Uqpj7mMzemxqvNTT5C3ctaOnOP8 6ctTxUXM3K8+JZNf7Va1pkhe2ob+qwr0J32D/QlTnW/cfGMjShxOUQoHYkHK7wfZ lObURgioZ9+UlWKVu4P7bmt21kKgQWZCGuGnmjxRzQ+n9pC97LMF7n5khOpkvCsJ 3owt7uOUKdxN/7DTcSu8vNj1z4MLJ5n2ijZ3SkvT1p03kXt4+qJRgINLAeouoKQU Q== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id XedZKqiv-CUZ; Wed, 16 Oct 2024 20:13:15 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMbY21N2z6Cnk9T; Wed, 16 Oct 2024 20:13:13 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Manivannan Sadhasivam , Bean Huo , "Bao D. Nguyen" , "James E.J. Bottomley" , Peter Wang , Avri Altman , Andrew Halaney , Maramaina Naresh Subject: [PATCH v6 03/11] scsi: ufs: core: Call ufshcd_add_scsi_host() later Date: Wed, 16 Oct 2024 13:11:59 -0700 Message-ID: <20241016201249.2256266-4-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Call ufshcd_add_scsi_host() after host controller initialization has completed. This is safe because no code between the old and new ufshcd_add_scsi_host() call site depends on the scsi_add_host() call. Reviewed-by: Manivannan Sadhasivam Reviewed-by: Bean Huo Reviewed-by: Bao D. Nguyen Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 17c22e880cef..17604397aaba 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10572,10 +10572,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->is_irq_enabled = true; } - err = ufshcd_add_scsi_host(hba); - if (err) - goto out_disable; - /* Reset the attached device */ ufshcd_device_reset(hba); @@ -10587,7 +10583,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) dev_err(hba->dev, "Host controller enable failed\n"); ufshcd_print_evt_hist(hba); ufshcd_print_host_state(hba); - goto free_tmf_queue; + goto out_disable; } /* @@ -10622,6 +10618,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) */ ufshcd_set_ufs_dev_active(hba); + err = ufshcd_add_scsi_host(hba); + if (err) + goto out_disable; + async_schedule(ufshcd_async_scan, hba); ufs_sysfs_add_nodes(hba->dev); @@ -10629,12 +10629,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) ufshcd_pm_qos_init(hba); return 0; -free_tmf_queue: - blk_mq_destroy_queue(hba->tmf_queue); - blk_put_queue(hba->tmf_queue); - blk_mq_free_tag_set(&hba->tmf_tag_set); - if (hba->scsi_host_added) - scsi_remove_host(hba->host); out_disable: hba->is_irq_enabled = false; ufshcd_hba_exit(hba); From patchwork Wed Oct 16 20:12:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836085 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20EEC12E4A for ; Wed, 16 Oct 2024 20:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109608; cv=none; b=V5CjmicGAjLGrWjkkR5sPpqapwKnherrJZJENlUeE6mY9iJbpG7BrmeYDYrTXf/uRZOZtInqRKvsi0/6RRZssta7bEN6sySP9xPCHY6mXlEIC/LUO9zlD+5s93N+lAfEXhwS7htUt3hJKH5f8mV6Ws5CrrrC19V8Wn4jHIdWGWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109608; c=relaxed/simple; bh=Yu3RdaVQZFLF2pRAqaPh8Rgx84nbMv7fas4TICo94rE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tp6XvRkT5bB16ZW1QqEP19HdWuITZc+XSqG9AX44xgr+WT2OzWCj8W9Ws7feRP1nxONUP86pvPQAXBssmgFgxqCHCaY5Qh0TC7GkRHB/hbvOxz7cdSeKWYUfmvESR1qhSXBeX3CVaEV0ClEOo/AirI3nbZQwITxkozsiXV0yj98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=JD9qo6R9; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="JD9qo6R9" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMbp4sMLz6ClY9l; Wed, 16 Oct 2024 20:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109600; x=1731701601; bh=5BNhY V9M5GPzg2W8iLsE4XjZLDUUotPqrr4TPlEIU80=; b=JD9qo6R9f2VE4pXqLEhbg jii8sSVwYBz0nVKWLh2iixRVZ7rGnXnYKxwmw8vVoKBubxN1ORXQ9T8ggNY2mGgd fLz0qy2F9shtamC5rZvYHciuSBCneWPZ4M0IAqTCo63VnqVmBllzXiprIOlg0cmE o/R4zs1ZUDlG8WOAd2p6jsLf2ZQEzbAlFNMBooGj1u8GySRODaNce+MqWy7JByrJ 7+Z8MQkR0LBbhnVKjTYWEkgv3KA1OgdmiXl5mM3oKhPYYvi2zm553thJZy+9nnbT kn/tCshK/85IlzNYvPSg07c0o8iUyG5tt61Fbn+IanOnLnH0t1W/0zx4H4lJKtTC A== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id v7PUdmpNNAmC; Wed, 16 Oct 2024 20:13:20 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMbg3fdJz6ClY9d; Wed, 16 Oct 2024 20:13:19 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 04/11] scsi: ufs: core: Introduce ufshcd_process_probe_result() Date: Wed, 16 Oct 2024 13:12:00 -0700 Message-ID: <20241016201249.2256266-5-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Prepare for moving a ufshcd_device_init() call from inside ufshcd_probe_hba() into the ufshcd_probe_hba() callers by introducing the function ufshcd_process_probe_result(). No functionality has been changed. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 17604397aaba..724060a9eae7 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -7684,6 +7684,29 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) return err; } +/** + * ufshcd_process_probe_result - Process the ufshcd_probe_hba() result. + * @hba: UFS host controller instance. + * @probe_start: time when the ufshcd_probe_hba() call started. + * @ret: ufshcd_probe_hba() return value. + */ +static void ufshcd_process_probe_result(struct ufs_hba *hba, + ktime_t probe_start, int ret) +{ + unsigned long flags; + + spin_lock_irqsave(hba->host->host_lock, flags); + if (ret) + hba->ufshcd_state = UFSHCD_STATE_ERROR; + else if (hba->ufshcd_state == UFSHCD_STATE_RESET) + hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL; + spin_unlock_irqrestore(hba->host->host_lock, flags); + + trace_ufshcd_init(dev_name(hba->dev), ret, + ktime_to_us(ktime_sub(ktime_get(), probe_start)), + hba->curr_dev_pwr_mode, hba->uic_link_state); +} + /** * ufshcd_host_reset_and_restore - reset and restore host controller * @hba: per-adapter instance @@ -8850,7 +8873,6 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) { ktime_t start = ktime_get(); - unsigned long flags; int ret; ret = ufshcd_device_init(hba, init_dev_params); @@ -8896,16 +8918,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) ufshcd_configure_auto_hibern8(hba); out: - spin_lock_irqsave(hba->host->host_lock, flags); - if (ret) - hba->ufshcd_state = UFSHCD_STATE_ERROR; - else if (hba->ufshcd_state == UFSHCD_STATE_RESET) - hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL; - spin_unlock_irqrestore(hba->host->host_lock, flags); - - trace_ufshcd_init(dev_name(hba->dev), ret, - ktime_to_us(ktime_sub(ktime_get(), start)), - hba->curr_dev_pwr_mode, hba->uic_link_state); + ufshcd_process_probe_result(hba, start, ret); return ret; } From patchwork Wed Oct 16 20:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836576 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 123DA1C1741 for ; Wed, 16 Oct 2024 20:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109612; cv=none; b=sOQPqXnJ+vCaN+lSm/mMb2INt6q10uvz5i/skAutCeKV9UjWQ2Z9TGbtjrSdQbVxqcFuEFdjaHTfRWnMjbML7VUgrD473FlNEoapvITLYodKBHvWiiYORyOtC2mdEnTQD9EHvcu08QDkjTAwSus6m0cKYyrTC+Z0c/KE9RRjqzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109612; c=relaxed/simple; bh=kMdZiM4rNKzZLh35oqNldFK2ReI7tZDOiPeuL4NV5Uk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sj81igcNBZH8LyrRk/U/bspJLtAWSro7yRZQRMLkNCrZD0BQYXpdmWLFcuVC24PD7bDZSBxOgbfUz9WMupdd3rW4d9VZJ9qkdLvMrX5G+vYYvvFVRoaiNOsM2qSp3FxPRoiVIh2kEvpr5O4hqw4zlGrwTcc2qPGu42JZVdpU5o0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=TlLESZFJ; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="TlLESZFJ" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMbt5Y8Fz6ClY9d; Wed, 16 Oct 2024 20:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109607; x=1731701608; bh=idj3h Ceuzq0P4D6iXWWRsKs+5391c9u6HDdZDSDOgD8=; b=TlLESZFJ+FHNYDp9zmjGJ KikAzV2gNrGfWBTKg7n0RN7J240SqyqcReoq3mgRT3+71qaHQF2Ifut7cTAnr0pI QtL3QBzFt4LSbKtKto8Zp9N25C/Gz1n2Cu6qzYuQNrYQcY6UsZa9MN8hHrZOo23b p+zt9pe2desAH2nxIa8TWwbB/EPYrVxmDqkxOEn4+R9fgJgfUG/cx10AA3+3hyAv ODSceL26vnW68pVRTAD7JSYgBuMFFqrAngd0dqMWcrb3/4VpgPM+GFyvk3xU1Q04 79GlA/3efny5GnDEXyYv4qvShakv8lcFUGF06KrrqqHhNBeuUhru05QCJJLfdjl7 g== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id IVg2-CNdbzJJ; Wed, 16 Oct 2024 20:13:27 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMbm6qYvz6Cnk9T; Wed, 16 Oct 2024 20:13:24 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 05/11] scsi: ufs: core: Convert a comment into an explicit check Date: Wed, 16 Oct 2024 13:12:01 -0700 Message-ID: <20241016201249.2256266-6-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The comment /* UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH is set */ is only correct if ufshcd_device_init() is only called by ufshcd_probe_hba(). Convert the comment into an explicit check. This patch prepares for moving the ufshcd_device_init() calls. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 724060a9eae7..7b8eaf2b9ce2 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8851,8 +8851,9 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) return ret; } hba->scsi_host_added = true; - } else if (is_mcq_supported(hba)) { - /* UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH is set */ + } else if (is_mcq_supported(hba) && + hba->quirks & + UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH) { ufshcd_config_mcq(hba); ufshcd_mcq_enable(hba); } From patchwork Wed Oct 16 20:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836084 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2969F1C2324 for ; Wed, 16 Oct 2024 20:13:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109620; cv=none; b=XphDXbP+2qwdz/yqe/Z+M4+pXCzJKsjND0qHUHelxjwnqdzGiwSrwdTJice0mL+jV7RiQXfRFH5DyHvNGqTf8EVMWcMczzwQXz39hMuk56h/CDZyDTvSV/Gbey+8H2gXs27nNVyQPrCtEIjrppzc8FMw0/RoEArvfU+35U++jHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109620; c=relaxed/simple; bh=EV1mThDHg3lhvc0UfT4b8qrlwqYJEfT2XkdhZoOSfl4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ntxqSbS42lpQcM8y4j7sWhncoR1/dzqag0PooZQwtC1ZkmbeImzKZ/n7Yn99XAyNna1Vd6JtZAvTaD9R6o0/GEnI0YWG+fh0qt6evrUkag5B4gRwRRHnVpDd2u7ygjmHMl6aq/xv6ONsI/pFPc+NpmJOz+1UOGtX+mAB/W1VJaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=jQwfQx5p; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="jQwfQx5p" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMc26cSZz6ClY9l; Wed, 16 Oct 2024 20:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109612; x=1731701613; bh=zKOcL UillfXPGor6+AekdXVkp0FA9d5rnrgS1sSO1vI=; b=jQwfQx5pa6LcKq1uY/bbF VQjEwFP7cRfuQcydNOeEsPARpKSZKP59m9YJ03exXrP+++Y/yNhet++7ptEg+oql AFEPuRYvwB6uWfhA8PYqoyLQWpH3gDEIIGGLJqDMVoVhF22M+7E3uez2YVaiPtbQ 0bB+XP8uG991VadM9MMqKd2PKAJghsA1Pre9il64vEjV22xJNX6jWyDGKpBCp5rn sl+u2iINeKl9gGEAqmBnrNz1uGQdT0n+wmTYHBSh2GGTWBa+9tw1nvBElOEWTQ/c 3vynV2fSFF+xDFGwo3W+ae5LBhCVyQnQjJWog+HUjAhVHZsjagMCE5lY6U9u36dh g== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id Oof8NVUeSQyw; Wed, 16 Oct 2024 20:13:32 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMbv2fhyz6Cnk9T; Wed, 16 Oct 2024 20:13:31 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 06/11] scsi: ufs: core: Move the ufshcd_device_init() calls Date: Wed, 16 Oct 2024 13:12:02 -0700 Message-ID: <20241016201249.2256266-7-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the ufshcd_device_init() and ufshcd_process_hba_result() calls to the ufshcd_probe_hba() callers. This change refactors the code without modifying the behavior of the UFSHCI driver. This change prepares for moving one ufshcd_device_init() call into ufshcd_init(). Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 7b8eaf2b9ce2..8803031f1694 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -298,6 +298,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba); static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd); static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag); static void ufshcd_hba_exit(struct ufs_hba *hba); +static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params); static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params); static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on); static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba); @@ -7736,8 +7737,14 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba) err = ufshcd_hba_enable(hba); /* Establish the link again and restore the device */ - if (!err) - err = ufshcd_probe_hba(hba, false); + if (!err) { + ktime_t probe_start = ktime_get(); + + err = ufshcd_device_init(hba, /*init_dev_params=*/false); + if (!err) + err = ufshcd_probe_hba(hba, false); + ufshcd_process_probe_result(hba, probe_start, err); + } if (err) dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err); @@ -8873,13 +8880,8 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) */ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) { - ktime_t start = ktime_get(); int ret; - ret = ufshcd_device_init(hba, init_dev_params); - if (ret) - goto out; - if (!hba->pm_op_in_progress && (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) { /* Reset the device and controller before doing reinit */ @@ -8892,13 +8894,13 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) dev_err(hba->dev, "Host controller enable failed\n"); ufshcd_print_evt_hist(hba); ufshcd_print_host_state(hba); - goto out; + return ret; } /* Reinit the device */ ret = ufshcd_device_init(hba, init_dev_params); if (ret) - goto out; + return ret; } ufshcd_print_pwr_info(hba); @@ -8918,9 +8920,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) ufshcd_write_ee_control(hba); ufshcd_configure_auto_hibern8(hba); -out: - ufshcd_process_probe_result(hba, start, ret); - return ret; + return 0; } /** @@ -8931,11 +8931,16 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) static void ufshcd_async_scan(void *data, async_cookie_t cookie) { struct ufs_hba *hba = (struct ufs_hba *)data; + ktime_t probe_start; int ret; down(&hba->host_sem); /* Initialize hba, detect and initialize UFS device */ - ret = ufshcd_probe_hba(hba, true); + probe_start = ktime_get(); + ret = ufshcd_device_init(hba, /*init_dev_params=*/true); + if (ret == 0) + ret = ufshcd_probe_hba(hba, true); + ufshcd_process_probe_result(hba, probe_start, ret); up(&hba->host_sem); if (ret) goto out; From patchwork Wed Oct 16 20:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836575 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C52B1216A2F for ; Wed, 16 Oct 2024 20:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109625; cv=none; b=dgMkRkHFa3xF45SNf2mH0xm6/Pxvr1CF7HyvOkNGarTO4aRm/eGcq+PkU21EvQqqV9QKPwMfWN1tqA4hCdj7FIX0n0CQolFAbbjMlNIJMNpf7msyAvSZN9UQ2qaIL9Fj1rvxcfrBZnX/nTRpZG5kit7zHqVTWzGRMZVrAcS81RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109625; c=relaxed/simple; bh=l7zpIObIHmeefx+6Bd8CVeiVAZXklNAquvVu/uguf5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mU3iwtYVbziNxuoIIYZ9JArLhMuIEVrTu6VZ7vG0hv/N/bODWP3d7L9Zz1tIvgsxkqruWuxVDSDUd0maUh63m9j99yt+l4JAWAO7JE52Tg69shuYCtc+JMhJbTDvtjwJGnTowhQ7Awf1hR2pPfivXy0Ix26Z4l1pofB9XHZLqho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=DIQSYOp4; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="DIQSYOp4" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMc72fHNz6ClY9l; Wed, 16 Oct 2024 20:13:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109618; x=1731701619; bh=/NNbG 6RIcSaUAnxTooaivkM1JeTa92umfn6us3KLGhA=; b=DIQSYOp4t2iP9ZBA7ga5I 7QjxWPW3sJ1SVJ2ytB4RQyCctdQn/ow27n+7lAH9i9MrEAifEbzrBbJEAFQDj5tw Uvic/MY9h22+QdkNASkdB1mGlL3oqCsgvXDCYd2sJW+wc689eQaducBx0opfeZHK mrgmaQxY25u2bcQC0bdEwOdMZcSJ7N/jCvwja2QDBL9/EmGd0ThLFNd2hSe8xiuD 7EmgctfZrOQFjn0JBa2VQHlRjXMzTS91xjO0rYTHQJ2K8yNKFL9B9x1kWH/YyqLf 86GnNbCB4y/YVrAOrzzU9S0YRDs6AiSLnRe3Np4bd5/HojicLCwokoYXk2nsumb/ w== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id dmO7j30x7F_b; Wed, 16 Oct 2024 20:13:38 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMc04Lyyz6ClY9d; Wed, 16 Oct 2024 20:13:36 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 07/11] scsi: ufs: core: Move the ufshcd_device_init(hba, true) call Date: Wed, 16 Oct 2024 13:12:03 -0700 Message-ID: <20241016201249.2256266-8-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ufshcd_async_scan() is called (asynchronously) only by ufshcd_init(). Move the ufshcd_device_init(hba, true) call from ufshcd_async_scan() into ufshcd_init(). This patch prepares for moving both scsi_add_host() calls into ufshcd_add_scsi_host(). Calling ufshcd_device_init() from ufshcd_init() without holding hba->host_sem is safe. This is safe because hba->host_sem serializes core code and sysfs callbacks. The ufshcd_device_init() call is moved before the scsi_add_host() call and hence happens before any SCSI sysfs attributes are created. Since ufshcd_device_init() may call scsi_add_host(), only call scsi_add_host() from ufshcd_add_scsi_host() if the SCSI host has not yet been added by ufshcd_device_init(). Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 8803031f1694..063b87be23e9 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8937,9 +8937,7 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) down(&hba->host_sem); /* Initialize hba, detect and initialize UFS device */ probe_start = ktime_get(); - ret = ufshcd_device_init(hba, /*init_dev_params=*/true); - if (ret == 0) - ret = ufshcd_probe_hba(hba, true); + ret = ufshcd_probe_hba(hba, true); ufshcd_process_probe_result(hba, probe_start, ret); up(&hba->host_sem); if (ret) @@ -10408,7 +10406,8 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba) { int err; - if (!is_mcq_supported(hba)) { + if (!hba->scsi_host_added) { + WARN_ON_ONCE(is_mcq_supported(hba)); if (!hba->lsdb_sup) { dev_err(hba->dev, "%s: failed to initialize (legacy doorbell mode not supported)\n", @@ -10637,6 +10636,11 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) */ ufshcd_set_ufs_dev_active(hba); + /* Initialize hba, detect and initialize UFS device */ + err = ufshcd_device_init(hba, /*init_dev_params=*/true); + if (err) + goto out_disable; + err = ufshcd_add_scsi_host(hba); if (err) goto out_disable; From patchwork Wed Oct 16 20:12:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836083 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEDAC12E4A for ; Wed, 16 Oct 2024 20:13:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109630; cv=none; b=JjBVHyMiMguOYUXIHSwXMhcgOF7dH0t1Z+Ww2g5nMWDDeFKqMhO3JzgzZAhM4rKFYoZiXUsc4KcAc4bWVLbGy3b7sDJ8VvO70GSXGenCm52blIH1RQrXBAwH9L711fudXBrjH+bi0P9yiglUUoxAtRhmfu7/HAowyCyj8fWesRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109630; c=relaxed/simple; bh=fGM2q4jbIeIYvTnf9cN/S7IQXUZFQM+jGIJGHI6SoXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nHs6hN8bKBmUDifowoNBRzF9mlphmJ9TUteDbSB7ZFP2swpFOTGANckYTaEOhyDJWHRTBQMsAnvHLr27uRIoQidq8YwT8CVrg3u70/jYIt+aX5J51jOB8Vd7DOj16stHREB5PRUfrcfxMAz9cfPoRSDn4bFTFA2rQwnXgODV0gw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=oJiKwPh5; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="oJiKwPh5" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMcD4YPwz6ClY9l; Wed, 16 Oct 2024 20:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109623; x=1731701624; bh=ri7JD 4f1O0MmRZ9rEvuXjVcJHtBUCL03CLsP40e53b0=; b=oJiKwPh5RG7v5q5hmHUMu yzGnQ8RmYrkp0EoZiDkLvFDTTf6+vw2LLICVd4fESltoG5KIWUhZ+bqfU8W+2tyc y5Bsb7adsu8VckD2mRQ8o9MddK/oScaFSVS+iI62/MkI3TW23amj7SOdPpX8lhba 6rpZJ3h+RxXR9K48GOME+cvhFgqCIUXci/DAlwA4FXOQR3WJytZuNbRyt7x1JlSH 8VwEsiI1TaSSafbrudtADms+iPl0W8cgY/3McMP5avgVz5AbNtiavttspmmwrh1q TvLo8bZBQ0PQypekA4lAGXakxSnXyucM47KMWg+H4ZjdzeH2iNVhLiFyjnzSiYYi w== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id cxzDoEE8FHt8; Wed, 16 Oct 2024 20:13:43 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMc60dGvz6Cnk9T; Wed, 16 Oct 2024 20:13:41 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 08/11] scsi: ufs: core: Expand the ufshcd_device_init(hba, true) call Date: Wed, 16 Oct 2024 13:12:04 -0700 Message-ID: <20241016201249.2256266-9-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Expand the ufshcd_device_init(hba, true) call and remove all code that depends on init_dev_params == false. This change prepares for combining the two scsi_add_host() calls. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 56 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 063b87be23e9..d09aa3763f88 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10637,7 +10637,61 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) ufshcd_set_ufs_dev_active(hba); /* Initialize hba, detect and initialize UFS device */ - err = ufshcd_device_init(hba, /*init_dev_params=*/true); + ktime_t probe_start = ktime_get(); + + hba->ufshcd_state = UFSHCD_STATE_RESET; + + err = ufshcd_link_startup(hba); + if (err) + goto out_disable; + + if (hba->quirks & UFSHCD_QUIRK_SKIP_PH_CONFIGURATION) + goto initialized; + + /* Debug counters initialization */ + ufshcd_clear_dbg_ufs_stats(hba); + + /* UniPro link is active now */ + ufshcd_set_link_active(hba); + + /* Verify device initialization by sending NOP OUT UPIU */ + err = ufshcd_verify_dev_init(hba); + if (err) + goto out_disable; + + /* Initiate UFS initialization, and waiting until completion */ + err = ufshcd_complete_dev_init(hba); + if (err) + goto out_disable; + + err = ufshcd_device_params_init(hba); + if (err) + goto out_disable; + + if (is_mcq_supported(hba)) { + ufshcd_mcq_enable(hba); + err = ufshcd_alloc_mcq(hba); + if (!err) { + ufshcd_config_mcq(hba); + } else { + /* Continue with SDB mode */ + ufshcd_mcq_disable(hba); + use_mcq_mode = false; + dev_err(hba->dev, "MCQ mode is disabled, err=%d\n", + err); + } + err = scsi_add_host(host, hba->dev); + if (err) { + dev_err(hba->dev, "scsi_add_host failed\n"); + goto out_disable; + } + hba->scsi_host_added = true; + } + + err = ufshcd_post_device_init(hba); + +initialized: + ufshcd_process_probe_result(hba, probe_start, err); if (err) goto out_disable; From patchwork Wed Oct 16 20:12:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836574 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50F6812E4A for ; Wed, 16 Oct 2024 20:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109634; cv=none; b=FS2yZD+Ts1v2QM8bF7lvIDcO1TSZkHeFurXLHVQ/4lIiMNI51iMRakbJDtsKDtT9RoTQCv5zCYPK+1RP+t8K4BzdpaTginZIXuMTm0n0jIQWJx0isSjT58PMbz18ewjqZfRqi5xn4Ky784KPTScaJlW72etE15/iVM4AkmnL0+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109634; c=relaxed/simple; bh=FBnVD8X/iO345TcQMbf7TNnc+0luhatqupU9YeQbNbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CRx3n3PDnJLlJr+5vcwQSwftnlmY/zmuuowo7nEyOAcDwiuCi889HI3HHckZIFYVsDp2aB9d4KTPLvWpfm36AT1VG3fh4t/ZK+kolZ1sqSXrBGbsMP2o7B9+XxhCRsQ6qa+Yuo29sSF50YYRPfKwxbfFGVl7a1fCkenM1g6qmM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=opgZlC1n; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="opgZlC1n" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMcK0cr3z6ClY9l; Wed, 16 Oct 2024 20:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109628; x=1731701629; bh=U5O40 t7Sr2iwa3pt+jCk7rQ0o4vd7wBfyNgizOXfjOE=; b=opgZlC1nXU/gHPmOBh1np nFYPTxyYOfQnWB/eAPZSUw4xMiWlMGgn/Vls1HloQmrfu/jMVMRJtI8ixo8IydU9 8336Dk2D3PGheihNVwo0j47NQXiu8NHKb+W3g+LckcSLiL0rp0HfT+i8/VA2AL2v YvCFGjrq8lca1jOJC/Amt7hls9HIYNwIrdWljYGPvJkrHWklrjPIFZrNMGzRAXn4 v4O5FgoOmpPesQPPtKBV7D5U0buvlTpYAdDfdQDcenAaA2P4dZhKI5CsqD86qRBe K4qFHR1XaF92PPplBvig/1xMIOLQOPsa4985bNUfQTOlXwHZsiBhsxMOSDpXBfAL g== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id e5gN-722lNTp; Wed, 16 Oct 2024 20:13:48 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMcC2D6qz6ClY9d; Wed, 16 Oct 2024 20:13:47 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 09/11] scsi: ufs: core: Remove code that is no longer needed Date: Wed, 16 Oct 2024 13:12:05 -0700 Message-ID: <20241016201249.2256266-10-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Previous changes guarantee that hba->scsi_host_added is true before ufshcd_device_init() is called. Hence, remove the code from ufshcd_device_init() that depends on hba->scsi_host_added being false. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index d09aa3763f88..e3f433f221fc 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8799,7 +8799,8 @@ static int ufshcd_post_device_init(struct ufs_hba *hba) static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) { int ret; - struct Scsi_Host *host = hba->host; + + WARN_ON_ONCE(!hba->scsi_host_added); hba->ufshcd_state = UFSHCD_STATE_RESET; @@ -8840,27 +8841,8 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) ret = ufshcd_device_params_init(hba); if (ret) return ret; - if (is_mcq_supported(hba) && !hba->scsi_host_added) { - ufshcd_mcq_enable(hba); - ret = ufshcd_alloc_mcq(hba); - if (!ret) { - ufshcd_config_mcq(hba); - } else { - /* Continue with SDB mode */ - ufshcd_mcq_disable(hba); - use_mcq_mode = false; - dev_err(hba->dev, "MCQ mode is disabled, err=%d\n", - ret); - } - ret = scsi_add_host(host, hba->dev); - if (ret) { - dev_err(hba->dev, "scsi_add_host failed\n"); - return ret; - } - hba->scsi_host_added = true; - } else if (is_mcq_supported(hba) && - hba->quirks & - UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH) { + if (is_mcq_supported(hba) && + hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH) { ufshcd_config_mcq(hba); ufshcd_mcq_enable(hba); } From patchwork Wed Oct 16 20:12:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836082 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDCA5216A16 for ; Wed, 16 Oct 2024 20:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109640; cv=none; b=BKX6zzBWnZhbp9zVDpRDE7dSYiPhU2Lw2Z/HjTyixSJODEiCx+OqnHZv3d0KI25GjxpX+9LjxSo7U0enGQAFgVrHuz0W96z8hTVLzZHMpZiyR7PAm/DjKePH30XzgjNhx4eeNMg4PDTnEcOP2Iu3PDgMqd1NTF9JMjIPvcc7m+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109640; c=relaxed/simple; bh=GnHtxMXpO5LNE9COz51W51s0CivO9ro1jXLWLdslKLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lEmN5e3UujwGRzOGcD8A3T3iXoVWjpLjgfJDIXutpf8dLomIr9yySu60DfAymXla+NE0cQttfH6QtnShAlSCEJTkFNJMjqtG9PdD6ysa/VPDsFzxWCSUCgov6LbcMsP+jfB/RcakcF2B//dWAsRhvmZCMDg1dFS0p5e/3uEZr2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=iFJ/XUZV; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="iFJ/XUZV" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMcQ3JTbz6ClY9l; Wed, 16 Oct 2024 20:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109633; x=1731701634; bh=rWt6p 6AOTQVgGEYA0Ic2e9BVjQxleGStm+oOW+nXOM8=; b=iFJ/XUZVPA3+VusscNK94 7QI2KpU3ZQkjptsSMtS+Cmn9jcw3PmxucaLa4FtBN3oyH17lwEBCtWyNU1pQHsUn T2CaDtZoDx7Z9uBvw+J0GcpH3L7Ws969sFsLX+31eh5awIMniG62f4ir1Gubjq4K 2iAHzp9DLJeB48xt9H6exuLqOSjQPV5I8iqcMKuAYoV8ByZGnE4ALlWsO3ms4gIk /cEMe3dDHWrX9Sz6bLFzp8NWn+SE7x+QrvtLi3Qg/cxdxFUfJ9tMe1ddmkQAZaRY YhhQPrMzxNceRU1RymrXYBH+R84Z89JEmIEYa01IRpbW/CJXfXODna7SgpavvAuw A== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id QW8aZx47m7lC; Wed, 16 Oct 2024 20:13:53 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMcJ3dskz6Cnk9T; Wed, 16 Oct 2024 20:13:52 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 10/11] scsi: ufs: core: Move the MCQ scsi_add_host() call Date: Wed, 16 Oct 2024 13:12:06 -0700 Message-ID: <20241016201249.2256266-11-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Whether or not MCQ is used, call scsi_add_host from ufshcd_add_scsi_host(). For MCQ this patch swaps the order of the scsi_add_host() and UFS device initialization. This patch prepares for combining the two scsi_add_host() calls. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 41 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index e3f433f221fc..f34563e3a51d 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10388,8 +10388,25 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba) { int err; - if (!hba->scsi_host_added) { - WARN_ON_ONCE(is_mcq_supported(hba)); + if (is_mcq_supported(hba)) { + ufshcd_mcq_enable(hba); + err = ufshcd_alloc_mcq(hba); + if (!err) { + ufshcd_config_mcq(hba); + } else { + /* Continue with SDB mode */ + ufshcd_mcq_disable(hba); + use_mcq_mode = false; + dev_err(hba->dev, "MCQ mode is disabled, err=%d\n", + err); + } + err = scsi_add_host(hba->host, hba->dev); + if (err) { + dev_err(hba->dev, "scsi_add_host failed\n"); + return err; + } + hba->scsi_host_added = true; + } else { if (!hba->lsdb_sup) { dev_err(hba->dev, "%s: failed to initialize (legacy doorbell mode not supported)\n", @@ -10650,26 +10667,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) if (err) goto out_disable; - if (is_mcq_supported(hba)) { - ufshcd_mcq_enable(hba); - err = ufshcd_alloc_mcq(hba); - if (!err) { - ufshcd_config_mcq(hba); - } else { - /* Continue with SDB mode */ - ufshcd_mcq_disable(hba); - use_mcq_mode = false; - dev_err(hba->dev, "MCQ mode is disabled, err=%d\n", - err); - } - err = scsi_add_host(host, hba->dev); - if (err) { - dev_err(hba->dev, "scsi_add_host failed\n"); - goto out_disable; - } - hba->scsi_host_added = true; - } - err = ufshcd_post_device_init(hba); initialized: From patchwork Wed Oct 16 20:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 836573 Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2A6A216A2C for ; Wed, 16 Oct 2024 20:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109645; cv=none; b=bPE3B4A2ymUN9ZmvqD0J+kCVRW3mK42shPb3SWQ4UAd4lGMLYvU8ufWafFIegODcxrJQR8nZRs6X7QnDjdAd6KSBWVW3IATdIs2IcVoGFgtmR74Uj5emwAKQ0zopOX9pqKdGyC4l5OOGWBTupSPBO+3Vt/PoI7MvheQIeWFJQUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729109645; c=relaxed/simple; bh=cYV42VxVhY5kL8e2T5dqcRDubzKO90rYMF9KTubK/pQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DMXpPXJg5Wbt97hT4uNhPeBhzv11mWJpZF8lCMQqqhUsMRQ2qoEm9rw6LVKG8r8+Hnvj02dHGIYb4mAO90y/FBOric9zBD6mQyXoddUL9r5mSOHasoVMaYOIkmGfr7MgaXQfgI/h/6RC90Qa1GV1azZJUpFtRA1o9de+qmE7yG4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=JEvW8UlW; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="JEvW8UlW" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4XTMcW33Pnz6Cnk9T; Wed, 16 Oct 2024 20:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1729109638; x=1731701639; bh=me3Sb bjeBlWKgZJa41qIV0pALnmHH9ZVDS9G/r1+FTU=; b=JEvW8UlWbKXuWG2bfCmi/ n5S14cN8j9SX+h6qCrtSH4m/tAaphLBHg6p5p2mGgLCfC9CmwOFusbp0vnLOWlh6 Y2wSDeCGVfPV1wrd4O0UOuUhLhar8EObVoy6u5qTdInbK4w2pzaLRzFtQkNXlmKR 70E3YF4uHNwVsnjb2C1A/CVt1LQiVt6wL0QN/Mu5qFT+ioZW1lJqGM2WexsIwsG9 mVg4Th223QYAUTW+0XmwfZjtgEgA78xmXxxfx52ItpLfaX1hN91kII3eaNIQw9it NHzVZmst3r/ys23NH47bS54NyXFTEhYGAlaCwbmH4CYcWzi/Siwtntq36rltsA6q g== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id L6hiy44is_jp; Wed, 16 Oct 2024 20:13:58 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4XTMcP2sGqz6ClY9d; Wed, 16 Oct 2024 20:13:57 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "Bao D. Nguyen" , "James E.J. Bottomley" , Manivannan Sadhasivam , Peter Wang , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh Subject: [PATCH v6 11/11] scsi: ufs: core: Move code out of an if-statement Date: Wed, 16 Oct 2024 13:12:07 -0700 Message-ID: <20241016201249.2256266-12-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org> References: <20241016201249.2256266-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The previous patch in this series introduced identical code in both branches of an if-statement. Move that code outside the if-statement. Reviewed-by: Bao D. Nguyen Signed-off-by: Bart Van Assche Tested-by: Neil Armstrong # SM8650-QRD Tested-by: Neil Armstrong # on SM8650-HDK Tested-by: Neil Armstrong # on SM8650-QRD --- drivers/ufs/core/ufshcd.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index f34563e3a51d..70d89e154c4f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10400,26 +10400,20 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba) dev_err(hba->dev, "MCQ mode is disabled, err=%d\n", err); } - err = scsi_add_host(hba->host, hba->dev); - if (err) { - dev_err(hba->dev, "scsi_add_host failed\n"); - return err; - } - hba->scsi_host_added = true; - } else { - if (!hba->lsdb_sup) { - dev_err(hba->dev, - "%s: failed to initialize (legacy doorbell mode not supported)\n", - __func__); - return -EINVAL; - } - err = scsi_add_host(hba->host, hba->dev); - if (err) { - dev_err(hba->dev, "scsi_add_host failed\n"); - return err; - } - hba->scsi_host_added = true; } + if (!is_mcq_supported(hba) && !hba->lsdb_sup) { + dev_err(hba->dev, + "%s: failed to initialize (legacy doorbell mode not supported)\n", + __func__); + return -EINVAL; + } + + err = scsi_add_host(hba->host, hba->dev); + if (err) { + dev_err(hba->dev, "scsi_add_host failed\n"); + return err; + } + hba->scsi_host_added = true; hba->tmf_tag_set = (struct blk_mq_tag_set) { .nr_hw_queues = 1,