From patchwork Tue Sep 10 21:50:49 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: 827287 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 82ED61A08CB for ; Tue, 10 Sep 2024 21:52:18 +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=1726005141; cv=none; b=Q7k8wEyd/47oLX/6zWpFNkod9mCrlIbxP/YUhsTNmi2y+sdkoLAtuaD1xD4BIBeE5jraQEAU4G71aoNMsj+90FJBuRHM5U52IvcuqWqobKfFgOdfu3SDOJ4DabwnLAnusNrJMLJQAr294/4ESM8OM2Z4g69bgHMlizrJXcZFdEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005141; c=relaxed/simple; bh=yocigBvgwUu3P0zecHtqv0kfecFnMXDWk64JbFoWS3M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=unoLSLUP0wBiKc5nkVzBq2LGqeAuqDAS7hR7oW26q8e7/0NRUrReUalyMe0DpN44/WkbKJhyUpCtzcwiVLdbPn0n3Jh6JKCzoJQ89ceb+SDVP6FHccgk2dnXqNEe+3wrYgSJABD72rw0vXnCnRcxMu33epnLSo9bHkxtP3Zjzb0= 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=Pihovyif; 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="Pihovyif" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HVT6rxgz6ClY9K; Tue, 10 Sep 2024 21:52:17 +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=1726005131; x=1728597132; bh=3V5Cu 9qDL8YOhVGr78U8Zr03SbPYsHSx1T1VdK5/T7Q=; b=PihovyifKy6Y8Qx0GNR0m Gjw+isxqnMZrTwQhRAjFoM/ocC2yfilvuGWhFT5Hb7avjVK90FEKZogT95dI9hCg QwiAIwvXRNYAM2Z0WpqTJD8dxhQpL/mR5ZubhBfCIhSNf1o2JhtaY6Qal9fz5i6T Zy6SjCL6hUv0QLrjerz/1tsAX5HQPn8FmaEITYqvCOjc7nZfMlT/rSaytpm7uDwE fXxtrFogPIT5ij2ZSdEwrV2l3VunidfJ+Mo+PFXBQSg2+ZgsG1N7CPn7SQPKry2I 1bHre5sLsQN4y0L7TQNr3tiNZvnbsAob479HQO99ajtCH9IGCab90XOTmk1vcyef 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 COjkeRq2gV8c; Tue, 10 Sep 2024 21:52:11 +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 4X3HVJ73kfz6ClY9H; Tue, 10 Sep 2024 21:52:08 +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 Subject: [PATCH v5 01/10] scsi: ufs: core: Introduce ufshcd_add_scsi_host() Date: Tue, 10 Sep 2024 14:50:49 -0700 Message-ID: <20240910215139.3352387-2-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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 | 84 ++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 8ea5a82503a9..ecf6da2efed1 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10357,6 +10357,56 @@ 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)) { + 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 @@ -10488,35 +10538,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)) { - 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); @@ -10574,9 +10598,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 Tue Sep 10 21:50:50 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: 827676 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 5AF2A1A08CB for ; Tue, 10 Sep 2024 21:52:24 +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=1726005145; cv=none; b=BX0THeKoptPgz5nvhB1qQdSn3W0txVK7+mTr2EcL+NSQpZL/pFTSKykgkTXElvywYUGcVM/kxgkK7s8SxIepzIsiuzH7JMp93D0ktJ9Z882aH1C9pTytSTAVZC0YD3js4A3QTf5hOij6gKJF7XIqxTh1pduy4SSeV85vNV6VELU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005145; c=relaxed/simple; bh=01GpisYQQyfFxOYH3nSPjJZnCG5wvkM75ADlW42Ar7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uTc1HLYq4L2prZPheKLmzSstBOZdK0ZlQeQdfeBt1H+tIFzXOdV2Oxxdr99ZxlB1cu8Z3LD4c33fFk/XAWSb3/7vRHD0ocxfyRc4UDNNEqUTd1RXrjkmtYZTbz4x3joo6O8pUEMIbAl1CsnohTRS8F46z01ftzMd/q80Aq1glx8= 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=D/dpSfxD; 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="D/dpSfxD" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HVc05jJz6ClY9K; Tue, 10 Sep 2024 21:52:24 +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=1726005138; x=1728597139; bh=5sjXm ZRA9guOoc2FHLvHcUpvKIetH6Ut3NOdHuwzsAY=; b=D/dpSfxDZiETx4weeRa2T U9B1/eY7yYR1/DVsFaHeZkamj6KWyXl2IWB6rq2sMcOffKAFQq3KGxBHHYwE7CAn CaK1Qh2YKRn3RVzRDSGe6xNy4Xwk0Xits6IGmW8hYIh3OjKC3/Z92TU81jQ0+0GJ V0ZpXdLHba8bw2IVs/rhrIQXxygc2Okg6ed+3Ny1tJ4YaJ1s+MpEypAVoMkCRhVZ VIHiBK5Z7uEXzJkMOhXtapEmmt/CvpAT9i5Hkip+bNJTfyQCbuvxpgOgdIfbID+f ZPWq4dEUWGCu1M+i+azp6ZPXSFn7FXY/uk8IzJGXBuOuSpXYYPgx9RoWq1grkDGN 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 ApAFcYGjixW6; Tue, 10 Sep 2024 21:52:18 +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 4X3HVR5Lwbz6ClY9J; Tue, 10 Sep 2024 21:52:15 +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 Subject: [PATCH v5 02/10] scsi: ufs: core: Introduce ufshcd_post_device_init() Date: Tue, 10 Sep 2024 14:50:50 -0700 Message-ID: <20240910215139.3352387-3-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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 ecf6da2efed1..0ca20f069cbd 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8709,6 +8709,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; @@ -8778,33 +8812,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 Tue Sep 10 21:50:51 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: 827286 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 09B831ABEC9 for ; Tue, 10 Sep 2024 21:52:29 +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=1726005151; cv=none; b=gEd+DYsABKl8ZVEHaiOMJiMxV6wGcdTRy7WO0JL7Kpd/tqZov1tNC4CBSYCzt4OI36b9S0lZsGTsPDceMzhuSIXxphChMhOeFRBjGNU0o9omZkN+18OeOD0i+uNPVcDfJowLtPfIIgpYAbupVkm9DaT8vPvRoYKG4xMMJ3yFpVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005151; c=relaxed/simple; bh=2+HawifvlU7XBJ7sgcZaVrH1ZB48wCIRIHuaLViGXbw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qINupNTbqyMbsYk+qJhML5WiwtFhQvxDLaTgOeg7IOyB6cdYCySMuw/OOTefQ0W7Xegr0oWw/dCmDKNFwKByyH0UncfAVxugrYDDcryU1Oo8vXRaoOo+75LxKx0fqG4rJb42XSzE8GydJ2UXqAFzsRnUEqsmHddI/XZHS5N7lB0= 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=vKdRE8k3; 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="vKdRE8k3" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HVj3YYjz6ClY9K; Tue, 10 Sep 2024 21:52:29 +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=1726005144; x=1728597145; bh=Jc6/G r2+hoHWK0YP5X1QMpHQtO+syZEWlLFMWzMyDI8=; b=vKdRE8k3bfihwX1M9X1nC /9iQ9tveECW+34mkaIP7DerbShB28Aw+hWaU6K0YWkUm3OtBlwswvjpl7qC0oUBX k6qV3AFniGxycauV5vJjSeK4N7+jQUDjTXke1BvtXQE/Y25Q+nPF8UpnJDTtJisy XVdeU6YAeBW4NJpcCb8eFebk1yF0DU6070xfTRzDpX4hik+wf24AmuFhKgMEQBv2 HPStOAjZRXY/Hlr8dGml54zu2yCivmkpH3NNGRrSvy/rbDiuKgSqu4eYg+JpH/2T chXdcnZ51QX2d6nb4FoPt5sOWnfqH60pbTIrBMfYYifQpx1OAhFdfVVv38xD+TK9 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 5hu-mxjFFTbq; Tue, 10 Sep 2024 21:52:24 +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 4X3HVZ1VyWz6ClY9H; Tue, 10 Sep 2024 21:52:21 +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 Subject: [PATCH v5 03/10] scsi: ufs: core: Call ufshcd_add_scsi_host() later Date: Tue, 10 Sep 2024 14:50:51 -0700 Message-ID: <20240910215139.3352387-4-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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 0ca20f069cbd..6ebafd08ad6e 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10546,10 +10546,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); @@ -10561,7 +10557,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; } /* @@ -10596,6 +10592,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); @@ -10603,12 +10603,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 Tue Sep 10 21:50:52 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: 827675 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 4399D16C854 for ; Tue, 10 Sep 2024 21:52:36 +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=1726005157; cv=none; b=AXXsjJZEkxVpOS7kxWJVjGR2xczcxtGcGzxQ7KkE08wptRLtFe/8eyhqakQ6JNXsjMjENWmx5sg3HJ1hKBXyYRK16Ug1Uj+a3kLrYcaFKgdKlUoKm1jl1M1Bk/cdQKlU96vbgVl8CJTtFLrkkkFmDecEqz1rExRKGs9jJFAtnms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005157; c=relaxed/simple; bh=U7lMu8m0dw0ArsEn5+e2wEp9zKzRCt/+KD0bd5BW5FM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oZtVyBcXDm6bJ+aYkoIIbeKq9p+zzcolaOWcrQHcU1bSg0LIHVJV8AbiQJo5HDFkEw/AMub8uo+ngmllb5A86ZAfjIiIHKY7DeUWw97EFQSEYFGNtvEXWxrh7M7V/DRZAC/QJ3HoRbmj/v4HvgatF9TKOYtHLnT8sqtn7/fCtCg= 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=QwbJLSog; 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="QwbJLSog" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HVq5h89z6ClY9K; Tue, 10 Sep 2024 21:52:35 +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=1726005150; x=1728597151; bh=NyjaE SiX1YAiX6d+ldZl6Ad4kITviHe/WoI+/kNDj2I=; b=QwbJLSogm8Tob77jKA0HG 9iz1HL16rI6vrab8oLqw3Mgzm10B1EN9A7xOnNEU4nD9AsY2biIfi50/sCIhJ5SG LF3QWI8Nx/kxZ2vvbb72Y32HJArSkmJ3qnsXg0xhWoWmWOfT4K59WgdOSZDSNco9 rvAvvSRPk0Apa4I+c4NHQba8G5MDegvW+LIEB6GSwv/GuVLprDJGl0aBf56omh/P TCIVYpYEqn+DDb4cx24LW9NqStgvYlJTSTzzqJIHUFFl/wuv+dvEswttDAP5lYZA XkQzt6SVOPLCfrj3pv/FI3Xv5+/2U5V1av/jqMdGrN5c+AnLbbxdkL3m91PKWwu3 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 gLjoGcKcpjGe; Tue, 10 Sep 2024 21:52:30 +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 4X3HVh5g7Kz6ClY9J; Tue, 10 Sep 2024 21:52:28 +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 Subject: [PATCH v5 04/10] scsi: ufs: core: Introduce ufshcd_process_device_init_result() Date: Tue, 10 Sep 2024 14:50:52 -0700 Message-ID: <20240910215139.3352387-5-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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_device_init_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 6ebafd08ad6e..1094c1ba2212 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -7664,6 +7664,29 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) return err; } +/** + * ufshcd_process_device_init_result - Process the ufshcd_device_init() result. + * @hba: UFS host controller instance. + * @start: time when the ufshcd_device_init() call started. + * @ret: ufshcd_device_init() return value. + */ +static void ufshcd_process_device_init_result(struct ufs_hba *hba, + ktime_t device_init_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(), device_init_start)), + hba->curr_dev_pwr_mode, hba->uic_link_state); +} + /** * ufshcd_host_reset_and_restore - reset and restore host controller * @hba: per-adapter instance @@ -8827,7 +8850,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); @@ -8873,16 +8895,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_device_init_result(hba, start, ret); return ret; } From patchwork Tue Sep 10 21:50:53 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: 827285 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 C26231AB50A for ; Tue, 10 Sep 2024 21:52: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=1726005165; cv=none; b=c9VI/Zrad2vsgxw1qE3A1+fHmGAjIeX9+2vjI0syQI31FGt3cgsOp4osanFy9c3Aiw2RAvijswa/W7mpu/r4HXi+TSnCko/cW7M/6Cns3i5NPnI4bt9rwrgz+UzeiUb4GjpYK7SH1jMCcbDJ80yvWILMLu9vDc31Dp6I/2SgPys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005165; c=relaxed/simple; bh=eGViY3dYjO44fa9t6+teZD4Z5CreYMBn2BTH4wv8HxQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YYuK/b0CAzq0HV8GsixLlDyaIMdfWj86MnQk9d9aQc2iNc5XqqDnYha9rarExtW0g0RSsbpD60dvZz18RzEg9e7wWAwH2PVTp65Of74SYfOevWvHIX17SdzjrkkkAEzVUcT4e7/Wq6Q8q4l7Yf0m2q5koIFY9mmnp1bFjG8GKOA= 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=4BhhwosC; 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="4BhhwosC" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HVz3zcjz6ClY9J; Tue, 10 Sep 2024 21:52: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=1726005157; x=1728597158; bh=ypulb DRngynoqRqHIs0BdjJ63VAn26a6AKKaNCb/99M=; b=4BhhwosCuE4deDiaVsXh6 I25BEDEZpZiJxJx1jKdYZsNGUL9B1iGFvSmtlEsLZNH4B7PV3mve8wFOOsX2xI0Q SS7mnJAhruyNAsBC7uLBKMStPDf9hXDnOAPUrez+aXz4ZO2mKIBNCDlhu9enMRPM 2rXKZFfWMxEx31Dccnxh37Xe5g3sbqq/vK7cd/ER2XwlVXGtGULUAhP2AAk/to6R ViURiiHivU23ZuyZAMZ7Ln0u9AtjtAtozEj3jo6tCOA+2oj5EdbPdoZBQGMP5PDA 1uuJTIsGzGwuit+qT2L+wv6bjfgJrdLVoOeYSRlxUZWMzMW51ARCZvNDYfkzxTTV 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 5URS0F-BSpQF; Tue, 10 Sep 2024 21:52:37 +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 4X3HVq14ymz6ClY9H; Tue, 10 Sep 2024 21:52:34 +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 Subject: [PATCH v5 05/10] scsi: ufs: core: Move the ufshcd_device_init() call Date: Tue, 10 Sep 2024 14:50:53 -0700 Message-ID: <20240910215139.3352387-6-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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_device_init_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 1094c1ba2212..f62d257a92da 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); @@ -7716,8 +7717,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 device_init_start = ktime_get(); + + err = ufshcd_device_init(hba, /*init_dev_params=*/false); + if (!err) + err = ufshcd_probe_hba(hba, false); + ufshcd_process_device_init_result(hba, device_init_start, err); + } if (err) dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err); @@ -8849,13 +8856,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 */ @@ -8868,13 +8870,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); @@ -8894,9 +8896,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_device_init_result(hba, start, ret); - return ret; + return 0; } /** @@ -8907,11 +8907,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 device_init_start; int ret; down(&hba->host_sem); /* Initialize hba, detect and initialize UFS device */ - ret = ufshcd_probe_hba(hba, true); + device_init_start = ktime_get(); + ret = ufshcd_device_init(hba, /*init_dev_params=*/true); + if (ret == 0) + ret = ufshcd_probe_hba(hba, true); + ufshcd_process_device_init_result(hba, device_init_start, ret); up(&hba->host_sem); if (ret) goto out; From patchwork Tue Sep 10 21:50:54 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: 827674 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 B418D16C854 for ; Tue, 10 Sep 2024 21:52:56 +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=1726005179; cv=none; b=VpUMN8DAYp3v1OWpgswmt/0auVS+0sVEoKNYs6qwc+qEFTtoWrAl0IYNHcwouoMMSKYSRn78RMXgTHbRWX3aovyfi+/zyeYZEIG5lNqrpBfYWCzumVS1/HUFRuIf3mSsB8V4XzrnnPQuAXmFsET/q4527dQqsTrYpioUXH8fdlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005179; c=relaxed/simple; bh=zNlCB08jDbibw0nhGvbGzTuYdrXLqSKTf4TVKOOWbik=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qnXcGV15B1BSWDa2o6aYSzV7wi+kkLOV17zHItbObbS6nkRPl46pa491x62GiQ/es7Mgf6vuFFLF+ejb0YpHD3BjJ0X4jGp+gnzJwIW9AxSuE5L54wwzQoXpUYdqm+eSL+sbmLYpwrZFYe1FTAUyiwAYtE3Su1oT955ZIGZ8jJU= 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=1/fHbeNj; 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="1/fHbeNj" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HWD1LPSz6ClY9K; Tue, 10 Sep 2024 21:52:56 +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=1726005167; x=1728597168; bh=be49l IEYpP6EJ8/UJiShDjP+G2nBMdGBWpxxS+kJn94=; b=1/fHbeNjbif1uv5kp/qXy RZY385dY4C6gtM8RDsWEJUdP7r3yZDsX2fhxTjs6KfQmayRlz97qts9Z7B25gzhp jYSultiE2LzJ9EAToCSH8cE0WJIWeN9pATbyv+qaKlvaTR9AfKCG92mS/kFoYR90 Ls7Rb4QXn6r8qUIGlzw7EcMZHnLcvYjllpud/HNMev6E2E1jstFi3k+v6/0+C2Br 2k3P+B4bimS7T5RA+81id5g+rU6qo46xN68oDh/yfDG3QI9E8Me67yn7OE1hTHW4 rPbcAE9UTzn2e54q/2VwEVIU7QLc+usQ6cOB5tWbLAY1hDKwxAI+Ts5vF9O2CZIF 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 dS-R03DnjCMB; Tue, 10 Sep 2024 21:52:47 +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 4X3HW04Gd1z6ClY9H; Tue, 10 Sep 2024 21:52:44 +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 , Alim Akhtar , Eric Biggers , Minwoo Im , Maramaina Naresh Subject: [PATCH v5 06/10] scsi: ufs: core: Move the ufshcd_device_init(hba, true) call Date: Tue, 10 Sep 2024 14:50:54 -0700 Message-ID: <20240910215139.3352387-7-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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_add_scsi_host() checks whether or not the MCQ mode is enabled and since ufshcd_device_init() may modify hba->mcq_enabled, only call scsi_add_host() from ufshcd_device_init() if the SCSI host has not yet been added by ufshcd_device_init(). Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 16 +++++++++------- include/ufs/ufshcd.h | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index f62d257a92da..a3c5493ccc8f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8907,16 +8907,12 @@ 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 device_init_start; int ret; down(&hba->host_sem); /* Initialize hba, detect and initialize UFS device */ - device_init_start = ktime_get(); - ret = ufshcd_device_init(hba, /*init_dev_params=*/true); - if (ret == 0) - ret = ufshcd_probe_hba(hba, true); - ufshcd_process_device_init_result(hba, device_init_start, ret); + ret = ufshcd_probe_hba(hba, true); + ufshcd_process_device_init_result(hba, hba->device_init_start, ret); up(&hba->host_sem); if (ret) goto out; @@ -10387,7 +10383,7 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba) { int err; - if (!is_mcq_supported(hba)) { + if (!hba->scsi_host_added) { err = scsi_add_host(hba->host, hba->dev); if (err) { dev_err(hba->dev, "scsi_add_host failed\n"); @@ -10610,6 +10606,12 @@ 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 */ + hba->device_init_start = ktime_get(); + 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; diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index a43b14276bc3..55ec89fa16af 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -839,6 +839,7 @@ enum ufshcd_mcq_opr { * @dev: device handle * @ufs_device_wlun: WLUN that controls the entire UFS device. * @hwmon_device: device instance registered with the hwmon core. + * @device_init_start: start time of first ufshcd_device_init() call. * @curr_dev_pwr_mode: active UFS device power mode. * @uic_link_state: active state of the link to the UFS device. * @rpm_lvl: desired UFS power management level during runtime PM. @@ -972,6 +973,8 @@ struct ufs_hba { struct device *hwmon_device; #endif + ktime_t device_init_start; + enum ufs_dev_pwr_mode curr_dev_pwr_mode; enum uic_link_state uic_link_state; /* Desired UFS power management level during runtime PM */ From patchwork Tue Sep 10 21:50:55 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: 827284 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 F36111A08CB for ; Tue, 10 Sep 2024 21:52: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=1726005180; cv=none; b=ll1mHnrqosk1J0j838t+TlcYzbscfQsp59k5FFJYhg6iT0l7z9mRVTZzsMabd9JlKxi2wPYVK2AJJ6vzWhHCYvcf0vKTMZMMaSshiBYLYkXhbDBwPa4ulCgQ6stROIHYdsV4ThhmLnSO2Aw8QNRvkq6pIlYeUIi/u4tw1AHEmeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005180; c=relaxed/simple; bh=U/LhdQpxx1mptXdBPrKsngT2ltMETUJSab0NbNuN45E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O268KC8WRUotZUu6L8JITWDlpt8bUcBf/XTfz1QMmmpHXWBV0Ifxohz27AHYKWO8SJGZ8BOFYELBOsyLVVaWJs11A8bow3x4vg7aIGayuJ8P2B6goHoUR3sYoyqS3/zfrBaJ8yAIy/cs8757HiuJJkLsPgVXZwd9hingk2lw6Ns= 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=h7lqTVF3; 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="h7lqTVF3" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HWG5Fj3z6ClY9L; Tue, 10 Sep 2024 21:52: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=1726005174; x=1728597175; bh=jvN9a 7cN3llulZP15wCbi++ckwNhSMDxvsqgeNC6wM8=; b=h7lqTVF3LJcjeDoxdo0HJ ANi3HqAoh8fAoTao4YHnDM3qecmjCXEe1AH+9TFqWUORWAgtDUVvXH+Km45gB360 kPItomPwy6eUOqYxiJfsP/8WFnDc6CZpZxLFAykmHT26WBYr6FzFL1+JqTf33i80 N0e73g+tRS9sivekfFj5D3wrleZT6/CoWlDgGUBVgu1CjJCHrwOJCCxeAiEjf1Vu SuyTLHUwnr6SNwfwPFE6gvARhtU+AyMClNvwd8vJnja37Nj2X8qZSOBDqH+WhzTn Kezln6qx7lYFEDkWy8hZuL01Yqp/bf3eRRHtIdq1EeXYwcIAIM8oD342czvZ/mVv 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 F8uCWi7qktvU; Tue, 10 Sep 2024 21:52:54 +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 4X3HW76GQ7z6ClY9J; Tue, 10 Sep 2024 21:52:51 +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 Subject: [PATCH v5 07/10] scsi: ufs: core: Expand the ufshcd_device_init(hba, true) call Date: Tue, 10 Sep 2024 14:50:55 -0700 Message-ID: <20240910215139.3352387-8-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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 | 55 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index a3c5493ccc8f..efa9c177a80f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10608,7 +10608,60 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) /* Initialize hba, detect and initialize UFS device */ hba->device_init_start = ktime_get(); - err = ufshcd_device_init(hba, /*init_dev_params=*/true); + + 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_device_init_result(hba, hba->device_init_start, err); if (err) goto out_disable; From patchwork Tue Sep 10 21:50:56 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: 827673 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 283851A08CB for ; Tue, 10 Sep 2024 21:53:04 +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=1726005186; cv=none; b=mZySnSE3+hc58iur4Pq4r6XIi5e/EL5BlUv5kcut9QDYUtlEsQbewS8hYvlGY2zkW6DhcKX9CYaDaloKNsKq+H8/gf4gY2v9HxmxmTuLIkByOwv3Saqj4tt7HoOxMq1LizQH3uCT02yGxUWcgT7WQPmw0dVO+zZrrSHppPA3GPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005186; c=relaxed/simple; bh=lByadXpuat5mMYq9fBixfko2QYJ97gaXHuXlj4yqNUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dV67oBylhzZfnYUyXgrsfajdWGcZeIJOzX79+4wlyFEaeGcQ56HOnawGQaBLv+x8vvUQDz12BVdnKE97NaALA6YAyapya4Iw6/GdgrfX9mB8XhcOhBMhuX8j8iwXBssfLu6Z9xnThiyWMLWmRBRlNlCwbfZjxrz9ZEBIbbR+qjY= 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=uEQCDQ+L; 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="uEQCDQ+L" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HWN4Ng6z6ClY9K; Tue, 10 Sep 2024 21:53:04 +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=1726005180; x=1728597181; bh=bfktr atM+bUs3/t5PQVrWmxMwz98Z8IztApqHJVPOr4=; b=uEQCDQ+L6OJpfdUSwJ98b QyqtskJkg86PWEZNZ7s2vBHWtuarv5tzVMcokWF5I3KlHkYpuKD7b2GnciPgoGEi yixcOx0+2nqQlg22tUZJyPPj+0H8Lf5f+ynXx5ZZWrW+APmAKCeMLAkpsgiXlAmI FSIvzpogfMV834k4ysGOOhaW5DSYM1TXCf2Dsgu6Yd9Gzvf1uc3vcwbbeemrlZCk DOdWGhLLKfxq8BXjH3o+W5ipqlxbtcmRaGyAPJGrPtPb70moWA2E8y6UExwVLQtk tTlGTNR5O64LYp2iRI6V/IAQg1UUnpFwoaG8I79E7wArxLuVFCmjt9ioRI4V6Q9v 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 Fcb1h-rB5SnG; Tue, 10 Sep 2024 21:53:00 +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 4X3HWG1wPfz6ClY9H; Tue, 10 Sep 2024 21:52:58 +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 Subject: [PATCH v5 08/10] scsi: ufs: core: Remove code that is no longer needed Date: Tue, 10 Sep 2024 14:50:56 -0700 Message-ID: <20240910215139.3352387-9-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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 | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index efa9c177a80f..ce4f9c8554c3 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8776,7 +8776,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; @@ -8817,25 +8818,7 @@ 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)) { + if (is_mcq_supported(hba)) { /* UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH is set */ ufshcd_config_mcq(hba); ufshcd_mcq_enable(hba); From patchwork Tue Sep 10 21:50: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: 827283 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 45BB316C854 for ; Tue, 10 Sep 2024 21:53:12 +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=1726005193; cv=none; b=swpHtNQYY4+BkbLzKBAVH2+o5YxFw7iDUDagH/JKZhoJgrdvylZVIPQyPxE6i8MD/hMRpWWsjunViVFeht0L5GLkaMcDDMN6LnVrfa51RnIuxyvJhEgMI0Qfj1uaXH6+J7CJwnBuBqSwcH6NXMStNrpjeRN5lGqc88Weg141mOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005193; c=relaxed/simple; bh=0SdYyNklTWMjUNeGd2bfwc8KjT1wUihB7YLNEUN3zjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kPimQyMqgPhx9+rPvDHIDoB7Zpm1Ay3NWMqc/PzDnj9E8WvamxBwEe4qUY9RgvySYyuEHskLPoU+px62A+dYUl7WID6IHC2n+lKIDKVy5h9AjYMRDKvzlD5PXyHC4mfw5KxisPfHKQOtX2GT9oH0uE4PzjMHkSwimkRPun39Au8= 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=XKtOS82q; 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="XKtOS82q" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HWW56GFz6ClY9H; Tue, 10 Sep 2024 21:53:11 +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=1726005186; x=1728597187; bh=j4boG iLUFUuN9zSPBCgUzs66zsHPCZMQitRzINFsoUk=; b=XKtOS82qiMf5JLR0Qyjzm YieUrWSAYHczXbwSI6t0Uue0Rck0lMHD4Vb4umGRbN0yqaay45pKAkt0jsU8IVi8 0q/HMhgoRIZzc9y/CKf2sbrxrw3ckuKuy9iZEN0Jl7FoM3lTarxw1zyFJ1Zg/JgJ +YzAVopach5Lcoc+sn+7HvK2RqG2yk1qg53pFqSSro39NgYa0gY/jm1LFGgaAdeI /SSnOtwl1eQxbGDvoOZ6lVSORUA7OiNoFX6scrVRns9P9Stv1MRw6nKKuR6EonoZ Xbvj8KmaGtjsxTvxixLglBVSnBRMT3KmiFl/XP3PgQIy6jPcKdEvfVcvqGCOE9D9 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 5keeQAZiK88q; Tue, 10 Sep 2024 21:53:06 +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 4X3HWN42rgz6ClY9J; Tue, 10 Sep 2024 21:53:04 +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 Subject: [PATCH v5 09/10] scsi: ufs: core: Move the MCQ scsi_add_host() call Date: Tue, 10 Sep 2024 14:50:57 -0700 Message-ID: <20240910215139.3352387-10-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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 ufshcd_post_device_init() calls. This patch prepares for combining the two scsi_add_host() calls. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 40 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index ce4f9c8554c3..8e4e25da9a6f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10366,7 +10366,25 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba) { int err; - if (!hba->scsi_host_added) { + 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 { err = scsi_add_host(hba->host, hba->dev); if (err) { dev_err(hba->dev, "scsi_add_host failed\n"); @@ -10621,26 +10639,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 Tue Sep 10 21:50: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: 827672 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 9046816C854 for ; Tue, 10 Sep 2024 21:53:17 +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=1726005198; cv=none; b=OKsVxCaZLYyXAeR5BUWF5Tjh59AjZeQZqgwyyCB35YPDDMBmTwrNHC+lsNh9TdekQ7RMbD281+JaGHBmxAdJ2z71pKZ8/R5S5zImAMJYYqmlT+DKzTN1h5wVuMPpYbPu56MDgnqsm2HIfrHNU0LA/GaXdIHRw5wtQvwXPhuaN2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726005198; c=relaxed/simple; bh=FcNXwFm2t4NtiMtmENM4EKPIqfeQvdo4dBsv89dVGKE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GnO9B6FhdBaRBjqai6hoiBW9TqGXoGDBsglrNu3X9fYHfGtWJF0zVG1YPIO2A4WrjSe+dHsSk4zCoHnOcRtor6lX7IvAEEbCw5RMz7ZK1gjs4g/wxNjmEUnWztm6YWPYGQaBtcq4BSLhdnwV+tZrXyJFixv5ou/YLjmPBcipn9Q= 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=o89m8q9Z; 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="o89m8q9Z" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X3HWd2JyNz6ClY9J; Tue, 10 Sep 2024 21:53:17 +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=1726005193; x=1728597194; bh=ajzJN SmOryFRZyCx5aom1bD2v29IejOfo6L50+TG8OY=; b=o89m8q9Z/z9FX8HfGmU76 xwpcVlYZ7lkIUVaCDOnbmqjdZKOtRED7kRRL2M8GHoE2FE674vlRk6kZUvhY4FcV rCMKrpsKdtcFm98lQtDqO0Mv1GA3zY6YXMR8dA85CyZ2PCvmpNyaiqVjSsZpEv6z L1DCU46011tmS3iaZNy2eGRZWPu8+krX0UcG6HydVstdC8J6aDCwdhBoCnLRpkOb f978U/5XZ0P26siWddF7VTOJSGD056vRSh5Kjh6N3SY3C69i8mhp2EKkvL6TKBRa eHp+AQTxrpVhnx506Oegv/ohuuLmX8lzRbwOfzq1Ll13spM3bgXKIa0Ghrgo16F7 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 QGZv5V_Sx2KY; Tue, 10 Sep 2024 21:53:13 +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 4X3HWV6N3Mz6ClY8n; Tue, 10 Sep 2024 21:53:10 +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 Subject: [PATCH v5 10/10] scsi: ufs: core: Move code out of an if-statement Date: Tue, 10 Sep 2024 14:50:58 -0700 Message-ID: <20240910215139.3352387-11-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910215139.3352387-1-bvanassche@acm.org> References: <20240910215139.3352387-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 --- drivers/ufs/core/ufshcd.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 8e4e25da9a6f..2ad2c3e968c4 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10378,21 +10378,15 @@ 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 { - 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; } + 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,