Received: from 004.mia.mailroute.net (004.mia.mailroute.net [199.89.3.7]) (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 4097D2F7446 for ; Fri, 31 Oct 2025 20:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761943393; cv=none; b=fHUxTXwBcQGXrV5NaE497ioh/J/J6nw9YQW+QTN6QNErtDuhkUGTavBW9xpdvXi8mhuHnKmUMFEoTuaAaDtJfUDr6tgXzN/CQb7NNpQ1kb7cXHTBwRhOE++LKnn7ss3FJKc7EtXytbkgWQlZusQXbN9gvEg8PFwJsSl+8ORyqK8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761943393; c=relaxed/simple; bh=QDqfRTaG2HYnnJcRqVZHUAzSrR9gVW/CdgV+OUl8Thk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OSCBpLHY/L2BBLNvQYf4ViaHjqffic5t/nvrO8Aekj/MwhvAQcFrEc5Ey5Ygh+hJr+FHBzRCXGLRk2i9P2FjGulI21A1AwrDN2qXXTm+I4PXhkJfqLCwcpB3ZItEWrjoJIp1s/j7mtwIPLlPJpMbWwLJNf4axW+FX1VvIpJsbTc= 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=AQ9GC0OQ; arc=none smtp.client-ip=199.89.3.7 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="AQ9GC0OQ" Received: from localhost (localhost [127.0.0.1]) by 004.mia.mailroute.net (Postfix) with ESMTP id 4cytGl3nk8zm0pKT; Fri, 31 Oct 2025 20:43: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=1761943389; x=1764535390; bh=/ajQp inFf13MLYxpNUe48xRy5UR+URiLycrE/AV0hl4=; b=AQ9GC0OQfBZgW+x69f2+6 jiAv9kfqwS2pwAyNh2xObDBmSDPEeTY4Fslyijk/sgLXFFI/d3OFvmK8chV0/hBo rSFXpplmqygJytR80Yn69eX2ZxuawXxnXKhuT97F4B9pifOgNS4yKezN8JLYhBYn CIwHuO8+Ash5pBpSXBOYV9oaxwJcHp3mCdv5alQIIZgCehnWAaCg8o5pTMjiI0gI E1JF+Mpd8pffRJnVMCzVMeA4gtGaBrRUH/adMD3CkR3xYpVq+xYWX4mJbSHhBUg6 gcLNIScs+dkG9/BFAy0sR2906rNE9a8L7PB9Sf9Tvu4J5ODphwZZomn0PCEfDVYl A== X-Virus-Scanned: by MailRoute Received: from 004.mia.mailroute.net ([127.0.0.1]) by localhost (004.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 9tJWvy8RSQwX; Fri, 31 Oct 2025 20:43:09 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.180.219]) (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 004.mia.mailroute.net (Postfix) with ESMTPSA id 4cytGb5nrfzm0ySQ; Fri, 31 Oct 2025 20:43:02 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Peter Wang , Avri Altman , Bean Huo , "Bao D. Nguyen" , Adrian Hunter Subject: [PATCH v8 18/28] ufs: core: Allocate the SCSI host earlier Date: Fri, 31 Oct 2025 13:39:26 -0700 Message-ID: <20251031204029.2883185-19-bvanassche@acm.org> X-Mailer: git-send-email 2.51.1.930.gacf6e81ea2-goog In-Reply-To: <20251031204029.2883185-1-bvanassche@acm.org> References: <20251031204029.2883185-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Call ufshcd_add_scsi_host() before any UPIU commands are sent to the UFS device. This patch prepares for letting ufshcd_add_scsi_host() allocate memory for both SCSI and UPIU commands. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 93f2853ff5df..7935aad4ca13 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -10605,6 +10605,9 @@ static int ufshcd_add_scsi_host(struct ufs_hba *h= ba) { int err; =20 + WARN_ON_ONCE(!hba->host->can_queue); + WARN_ON_ONCE(!hba->host->cmd_per_lun); + if (is_mcq_supported(hba)) { ufshcd_mcq_enable(hba); err =3D ufshcd_alloc_mcq(hba); @@ -10765,7 +10768,11 @@ int ufshcd_init(struct ufs_hba *hba, void __iome= m *mmio_base, unsigned int irq) ufshcd_host_memory_configure(hba); =20 host->can_queue =3D hba->nutrs - UFSHCD_NUM_RESERVED; - host->cmd_per_lun =3D hba->nutrs - UFSHCD_NUM_RESERVED; + /* + * Set the queue depth for WLUNs. ufs_get_device_desc() will increase + * host->cmd_per_lun to a larger value. + */ + host->cmd_per_lun =3D 1; host->max_id =3D UFSHCD_MAX_ID; host->max_lun =3D UFS_MAX_LUNS; host->max_channel =3D UFSHCD_MAX_CHANNEL; @@ -10857,6 +10864,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iome= m *mmio_base, unsigned int irq) FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3); } =20 + err =3D ufshcd_add_scsi_host(hba); + if (err) + goto out_disable; + /* Hold auto suspend until async scan completes */ pm_runtime_get_sync(dev); =20 @@ -10907,10 +10918,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iome= m *mmio_base, unsigned int irq) if (err) goto out_disable; =20 - err =3D ufshcd_add_scsi_host(hba); - if (err) - goto out_disable; - async_schedule(ufshcd_async_scan, hba); ufs_sysfs_add_nodes(hba->dev); =20