From patchwork Mon Jun 17 21:07:40 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: 13701434 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 B82A018C356 for ; Mon, 17 Jun 2024 21:09: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=1718658555; cv=none; b=YKTgK7Y+wFNUztzqnjfCJ/ss7SK79kC6EC7IKlacj10IeM/rTZ1tHLWP5L71Wb10K2NtVHBDIGOAnKOhiW5aNKFOYBJ3rORjHxKhEQbgm3H5yXFafzfBTjK9N3D6MWfEp7mzgqFxkwze+IC2JWWeCMEvUiKp202d7VyzGsiZd/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718658555; c=relaxed/simple; bh=Pk3GJOJuxOgURl4t/SO0NgSE96MeDjhPEiDrcL+vO10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H9c+lwwQnJEApyAjfD9ksZPluZdDnUEFS0popTf5FEYQ+So+9jTTMtB5x2YO5VcMcfSTTgJmbrIEczyvM65Y2AKYh9llQunQpCmG1I2aAIXgoEPPLv009G6syzS+uAmTubr/lZYY1JVqVJURl+ZaRXDpg6D6Gmf7Bg4LATw3Tgw= 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=uB47GrGw; 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="uB47GrGw" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4W32Z10Vk8z6Cnk97; Mon, 17 Jun 2024 21:09:13 +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=1718658543; x=1721250544; bh=OX6TY b0TjAZL0FNYAuGZMbCIBiopSlAzEZPpkNHBnMs=; b=uB47GrGwzoLbn0X39Gk10 wF9XjN0aWYF2JclFB/7CXyHXn/ahZT8io1mOWgjytHqgn70xskuKqM4dtEk27s1/ 2qZMZq7/1iZAJz8TJP/6tN+9CNWPMdIz70seLyVzEPwLybG2Y4hBapPgN5owXw1J 6vcsLvMlX7vV+5LPxsCLbsqzYhdWgzLxBqIp3MclLwnGh/+G57gBxwGLtXCW7o5A vCL6aDaSgKgHrrwp3P574wViIx2U8m+F2qadtLG9EBs5x/8t7i9SI4hi/6ETO4eG 1IkezhXIJYApzsoZPQEmXJyTywke6k4EIvf6Q/1wiiUkmypjRBNInMm+Lu+dJndn 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 wRCJ87rr4-aN; Mon, 17 Jun 2024 21:09:03 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4W32Yp5qdKz6Cnk95; Mon, 17 Jun 2024 21:09:02 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Avri Altman , Peter Wang , Manivannan Sadhasivam , Bean Huo , Minwoo Im , Maramaina Naresh , Akinobu Mita Subject: [PATCH 1/8] scsi: ufs: Initialize struct uic_command once Date: Mon, 17 Jun 2024 14:07:40 -0700 Message-ID: <20240617210844.337476-2-bvanassche@acm.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog In-Reply-To: <20240617210844.337476-1-bvanassche@acm.org> References: <20240617210844.337476-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of first zero-initializing struct uic_command and next initializing it memberwise, initialize all members at once. Signed-off-by: Bart Van Assche Reviewed-by: Daejun Park Reviewed-by: Avri Altman Reviewed-by: Manivannan Sadhasivam --- drivers/ufs/core/ufshcd.c | 62 ++++++++++++++++++++------------------- include/ufs/ufshcd.h | 4 +-- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 41bf2e249c83..5d784876513e 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3993,11 +3993,11 @@ static void ufshcd_host_memory_configure(struct ufs_hba *hba) */ static int ufshcd_dme_link_startup(struct ufs_hba *hba) { - struct uic_command uic_cmd = {0}; + struct uic_command uic_cmd = { + .command = UIC_CMD_DME_LINK_STARTUP, + }; int ret; - uic_cmd.command = UIC_CMD_DME_LINK_STARTUP; - ret = ufshcd_send_uic_cmd(hba, &uic_cmd); if (ret) dev_dbg(hba->dev, @@ -4015,11 +4015,11 @@ static int ufshcd_dme_link_startup(struct ufs_hba *hba) */ static int ufshcd_dme_reset(struct ufs_hba *hba) { - struct uic_command uic_cmd = {0}; + struct uic_command uic_cmd = { + .command = UIC_CMD_DME_RESET, + }; int ret; - uic_cmd.command = UIC_CMD_DME_RESET; - ret = ufshcd_send_uic_cmd(hba, &uic_cmd); if (ret) dev_err(hba->dev, @@ -4054,11 +4054,11 @@ EXPORT_SYMBOL_GPL(ufshcd_dme_configure_adapt); */ static int ufshcd_dme_enable(struct ufs_hba *hba) { - struct uic_command uic_cmd = {0}; + struct uic_command uic_cmd = { + .command = UIC_CMD_DME_ENABLE, + }; int ret; - uic_cmd.command = UIC_CMD_DME_ENABLE; - ret = ufshcd_send_uic_cmd(hba, &uic_cmd); if (ret) dev_err(hba->dev, @@ -4111,7 +4111,12 @@ static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba) int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel, u8 attr_set, u32 mib_val, u8 peer) { - struct uic_command uic_cmd = {0}; + struct uic_command uic_cmd = { + .command = peer ? UIC_CMD_DME_PEER_SET : UIC_CMD_DME_SET, + .argument1 = attr_sel, + .argument2 = UIC_ARG_ATTR_TYPE(attr_set), + .argument3 = mib_val, + }; static const char *const action[] = { "dme-set", "dme-peer-set" @@ -4120,12 +4125,6 @@ int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel, int ret; int retries = UFS_UIC_COMMAND_RETRIES; - uic_cmd.command = peer ? - UIC_CMD_DME_PEER_SET : UIC_CMD_DME_SET; - uic_cmd.argument1 = attr_sel; - uic_cmd.argument2 = UIC_ARG_ATTR_TYPE(attr_set); - uic_cmd.argument3 = mib_val; - do { /* for peer attributes we retry upon failure */ ret = ufshcd_send_uic_cmd(hba, &uic_cmd); @@ -4155,7 +4154,11 @@ EXPORT_SYMBOL_GPL(ufshcd_dme_set_attr); int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel, u32 *mib_val, u8 peer) { - struct uic_command uic_cmd = {0}; + struct uic_command uic_cmd = { + .command = peer ? UIC_CMD_DME_PEER_GET : UIC_CMD_DME_GET, + .argument1 = attr_sel, + + }; static const char *const action[] = { "dme-get", "dme-peer-get" @@ -4189,10 +4192,6 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel, } } - uic_cmd.command = peer ? - UIC_CMD_DME_PEER_GET : UIC_CMD_DME_GET; - uic_cmd.argument1 = attr_sel; - do { /* for peer attributes we retry upon failure */ ret = ufshcd_send_uic_cmd(hba, &uic_cmd); @@ -4325,7 +4324,11 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd) */ int ufshcd_uic_change_pwr_mode(struct ufs_hba *hba, u8 mode) { - struct uic_command uic_cmd = {0}; + struct uic_command uic_cmd = { + .command = UIC_CMD_DME_SET, + .argument1 = UIC_ARG_MIB(PA_PWRMODE), + .argument3 = mode, + }; int ret; if (hba->quirks & UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP) { @@ -4338,9 +4341,6 @@ int ufshcd_uic_change_pwr_mode(struct ufs_hba *hba, u8 mode) } } - uic_cmd.command = UIC_CMD_DME_SET; - uic_cmd.argument1 = UIC_ARG_MIB(PA_PWRMODE); - uic_cmd.argument3 = mode; ufshcd_hold(hba); ret = ufshcd_uic_pwr_ctrl(hba, &uic_cmd); ufshcd_release(hba); @@ -4381,13 +4381,14 @@ EXPORT_SYMBOL_GPL(ufshcd_link_recovery); int ufshcd_uic_hibern8_enter(struct ufs_hba *hba) { - int ret; - struct uic_command uic_cmd = {0}; + struct uic_command uic_cmd = { + .command = UIC_CMD_DME_HIBER_ENTER, + }; ktime_t start = ktime_get(); + int ret; ufshcd_vops_hibern8_notify(hba, UIC_CMD_DME_HIBER_ENTER, PRE_CHANGE); - uic_cmd.command = UIC_CMD_DME_HIBER_ENTER; ret = ufshcd_uic_pwr_ctrl(hba, &uic_cmd); trace_ufshcd_profile_hibern8(dev_name(hba->dev), "enter", ktime_to_us(ktime_sub(ktime_get(), start)), ret); @@ -4405,13 +4406,14 @@ EXPORT_SYMBOL_GPL(ufshcd_uic_hibern8_enter); int ufshcd_uic_hibern8_exit(struct ufs_hba *hba) { - struct uic_command uic_cmd = {0}; + struct uic_command uic_cmd = { + .command = UIC_CMD_DME_HIBER_EXIT, + }; int ret; ktime_t start = ktime_get(); ufshcd_vops_hibern8_notify(hba, UIC_CMD_DME_HIBER_EXIT, PRE_CHANGE); - uic_cmd.command = UIC_CMD_DME_HIBER_EXIT; ret = ufshcd_uic_pwr_ctrl(hba, &uic_cmd); trace_ufshcd_profile_hibern8(dev_name(hba->dev), "exit", ktime_to_us(ktime_sub(ktime_get(), start)), ret); diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 9e0581115b34..d4d63507d090 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -73,8 +73,8 @@ enum ufs_event_type { * @done: UIC command completion */ struct uic_command { - u32 command; - u32 argument1; + const u32 command; + const u32 argument1; u32 argument2; u32 argument3; int cmd_active; From patchwork Mon Jun 17 21:07:41 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: 13701433 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 778F318F2D9 for ; Mon, 17 Jun 2024 21:09: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=1718658553; cv=none; b=hHAWusiV+VYNKRafP5LrP+CMnzjjxU1W5rq80J71j6XHz/8EDoZGrBvF6Pza3ULHOXrjG9qhLB1ybPH1DqyJM06Y0rS3hkaEnh2WOMhvfSvxgMrbD9QWvlAcEBTmHqtGNOad4CMsRBRq+KErtgeNQAocryLKN5+2TsBVhZMMgoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718658553; c=relaxed/simple; bh=O/JB9XQAY0uS7Cq3b1wiklbTpa90dbpWm4YJGEgP5a4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ecaZUmTnSgakiTMNkwlkFBIIOCDq0twyQMOTvzwnm6wdqoQXCIzcceF1NaHulabeOwYiqmqRxMbrzIGXhPI23VWyYHh4A+cTaMurdRWkYn0Tkys/7VGlVuJ3xD59A73b6sMDNChieDc9jDtT/h3dmC8Pqr91Y3m8IwXMARgRQ9Y= 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=YPY34Zhe; 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="YPY34Zhe" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4W32Yz6w3Gz6Cnk98; Mon, 17 Jun 2024 21:09: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=1718658548; x=1721250549; bh=UVoNf os25vc8suv/8xQHLa0e80xjHR4VymJwDgxT5TA=; b=YPY34ZheDxijAwNhTEThi +fzXn53NHl3VeitaCchrXQv0FQqe/zFqRy8IGJiiiO1t/uboWt+CDf3336JpZf1e mlEpb9GaviJGMfhZvjt6WLMH+2aC0W/KCUjKK5YrxZm7rFMGpTgYJpNmKmohHU2G pKev3kj/YQdmM2htbnujTuSCg6t6UMXMSJI3Tf57NBmnfq/uHnYFAjosJdBMomnZ v49HIw6Ab/hzX7YVt2pEMzgWwTqLS5hRqKSXoFa4XgJW7YV1dWsJtjwfh0S1/OCw rHvBlciPUukOPvdHZMyGabQxy0VlcA9vl3Lz0cmwfdMHe/HBpcvuYBo0cfqw0Y1v 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 U-MEyR0aGE76; Mon, 17 Jun 2024 21:09:08 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4W32Yw0sqXz6Cnk97; Mon, 17 Jun 2024 21:09:08 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Avri Altman , Peter Wang , Manivannan Sadhasivam , Bean Huo Subject: [PATCH 2/8] scsi: ufs: Remove two constants Date: Mon, 17 Jun 2024 14:07:41 -0700 Message-ID: <20240617210844.337476-3-bvanassche@acm.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog In-Reply-To: <20240617210844.337476-1-bvanassche@acm.org> References: <20240617210844.337476-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 SCSI host template members .cmd_per_lun and .can_queue are copied into the SCSI host data structure. Before these are used, these are overwritten by ufshcd_init(). Hence, this patch does not change any functionality. Signed-off-by: Bart Van Assche Reviewed-by: Manivannan Sadhasivam --- drivers/ufs/core/ufshcd.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 5d784876513e..7761ccca2115 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -164,8 +164,6 @@ EXPORT_SYMBOL_GPL(ufshcd_dump_regs); enum { UFSHCD_MAX_CHANNEL = 0, UFSHCD_MAX_ID = 1, - UFSHCD_CMD_PER_LUN = 32 - UFSHCD_NUM_RESERVED, - UFSHCD_CAN_QUEUE = 32 - UFSHCD_NUM_RESERVED, }; static const char *const ufshcd_state_name[] = { @@ -8959,8 +8957,6 @@ static const struct scsi_host_template ufshcd_driver_template = { .eh_timed_out = ufshcd_eh_timed_out, .this_id = -1, .sg_tablesize = SG_ALL, - .cmd_per_lun = UFSHCD_CMD_PER_LUN, - .can_queue = UFSHCD_CAN_QUEUE, .max_segment_size = PRDT_DATA_BYTE_COUNT_MAX, .max_sectors = SZ_1M / SECTOR_SIZE, .max_host_blocked = 1, From patchwork Mon Jun 17 21:07:42 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: 13701435 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 52C6918C356 for ; Mon, 17 Jun 2024 21:09:23 +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=1718658564; cv=none; b=nXwfoVneUM5zb4ZlJVF0LQc60GWwN1k36TMFb3oYxgoJdCG8eUvcN6WgBrr3AEPbiFONeTTBXgs9Sx6SXyUtae4wWIBtt+y6FE2NFjLuqDiLom5C18uTnkRhGXhazpc1uNNli6u5M0kf19bbAQFUzhWEV321GFn0QiCCf5yJFjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718658564; c=relaxed/simple; bh=OoJLwAFNGsANX8AMDEEGDq9DOjbfM7yxO52DiqBftqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fr6h7mUOISD+N0eyeUq0/wtVsa5YhZBZnAfP87pDC39R3O75AlyebgulPkISaXXfVz0f+r1bkdISxxJsoG23a8mQhHZKHe7GmJ28zNOaaHf0M2ER+9QwMZi3zjOrKFhPh7PdIi/KtPOnqrbQ6chcUZJjSh0Q6xu5LI1tRMpeAV8= 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=VrEntE1r; 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="VrEntE1r" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4W32ZB6f0Tz6Cnk98; Mon, 17 Jun 2024 21:09:22 +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=1718658557; x=1721250558; bh=aQcdM 7osT1j4+4virxde9dcGmwT94mxRb7fWbCygNfg=; b=VrEntE1r9Ae/SmnMmAXli of7t7UXApBdACP5essTi2CRSZZ1GkDKs/OFr0HjWG5wmb1Q8kP7cSfJHZl+sRDIS NyWPnw+12S/czXNkyMgseXlCG9eW139R+1lakbV+afyfwi67IJWBRXwhmYPCzOIn Vn9u1JNHrl62PzcNPWeYdOKCKz5NSTceJ/qXusn+teiwrF7Y6GiUbZPI5N699VUU xjG9OvXCyLO6FP9Hvkr0D9KsdUomDQoBnInBvIWgVz5ZdlGVWYLHifsMbAA+6y4h de7XqUDNeR+tqGOF5jKnvzghZXuwW7h7NRxyX7YJEieOLDv9SspEtNaM/o1jaOXf 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 07SkSgVHPb5R; Mon, 17 Jun 2024 21:09:17 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4W32Z44s16z6Cnk95; Mon, 17 Jun 2024 21:09:16 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Minwoo Im , Peter Wang , ChanWoo Lee , "Bao D. Nguyen" , Po-Wen Kao , Yang Li , Keoseong Park Subject: [PATCH 3/8] scsi: ufs: Inline ufshcd_mcq_vops_get_hba_mac() Date: Mon, 17 Jun 2024 14:07:42 -0700 Message-ID: <20240617210844.337476-4-bvanassche@acm.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog In-Reply-To: <20240617210844.337476-1-bvanassche@acm.org> References: <20240617210844.337476-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make ufshcd_mcq_decide_queue_depth() easier to read by inlining ufshcd_mcq_vops_get_hba_mac(). Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufs-mcq.c | 18 +++++++++++------- drivers/ufs/core/ufshcd-priv.h | 8 -------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c index 4bcae410c268..0482c7a1e419 100644 --- a/drivers/ufs/core/ufs-mcq.c +++ b/drivers/ufs/core/ufs-mcq.c @@ -144,14 +144,14 @@ EXPORT_SYMBOL_GPL(ufshcd_mcq_queue_cfg_addr); */ int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba) { - int mac; + int mac = -EOPNOTSUPP; - /* Mandatory to implement get_hba_mac() */ - mac = ufshcd_mcq_vops_get_hba_mac(hba); - if (mac < 0) { - dev_err(hba->dev, "Failed to get mac, err=%d\n", mac); - return mac; - } + if (!hba->vops || !hba->vops->get_hba_mac) + goto err; + + mac = hba->vops->get_hba_mac(hba); + if (mac < 0) + goto err; WARN_ON_ONCE(!hba->dev_info.bqueuedepth); /* @@ -160,6 +160,10 @@ int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba) * shared queuing architecture is enabled. */ return min_t(int, mac, hba->dev_info.bqueuedepth); + +err: + dev_err(hba->dev, "Failed to get mac, err=%d\n", mac); + return mac; } static int ufshcd_mcq_config_nr_queues(struct ufs_hba *hba) diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index f42d99ce5bf1..a1add22205db 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -255,14 +255,6 @@ static inline int ufshcd_vops_mcq_config_resource(struct ufs_hba *hba) return -EOPNOTSUPP; } -static inline int ufshcd_mcq_vops_get_hba_mac(struct ufs_hba *hba) -{ - if (hba->vops && hba->vops->get_hba_mac) - return hba->vops->get_hba_mac(hba); - - return -EOPNOTSUPP; -} - static inline int ufshcd_mcq_vops_op_runtime_config(struct ufs_hba *hba) { if (hba->vops && hba->vops->op_runtime_config) From patchwork Mon Jun 17 21:07:43 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: 13701437 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 917181990AA for ; Mon, 17 Jun 2024 21:09:38 +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=1718658580; cv=none; b=IkMYlADobhCJvo2fm/0xeaBwKsQHZ/6J0jk7BmsmAq7fAtf/9ZGnScIZfEWSDBPTS8Ssqxj+xcLMYxcHkyB2GhezCZknQ2J4EChibO5Z7IkKlzNnZCeg5DpiqJGlmzuJAAKSZ6ULzmV1gHm7Fexajml9Yjaqp7nkj0DCYJmLJE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718658580; c=relaxed/simple; bh=2zKDr8TmKteVUKVH/MAwKAaBSZyj490W7Dnu5Frhw20=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IXH4PYx7AYv0W2BJNDoZXHa8Inl9noNAUySL5hGaF+6IMlVtlbkORwpoIws7o92yetEKSlhdMXXQVmeyOInIX0qYoWfj7we9rugZf9mCPJfURFpVeCHNVJTdf0HM5LNGxeGxqcuSgfpfy6QaHcI+lh47/du9WON0uT4fG+IQU+U= 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=sJlgJhgV; 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="sJlgJhgV" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4W32ZT6wWSz6Cnk8y; Mon, 17 Jun 2024 21:09:37 +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=1718658570; x=1721250571; bh=oY0f7 FaDNCyBr1Oi4AJhOqe+7IsMJ9NaLgyilxl9+SE=; b=sJlgJhgVqfJJl33Z6BoJS 2GHCug4LHBO8mjyxczLrtFdRyphimFMqXTOuMdlJzl24sKopWk0H0ecCy/YajdGU bwguvazj6zuHen1PgrLI8wSoyKf1nD4+KsRgnSupJjq/+8bqiD9XgVqCksqGEX6h FJ3fcqb/5gqpMLhEZ2QDV1ZSsBkLY9f1CiRIkkOtH64Pu9WRyWni47LdkgeHIxGU LtHCwFSeOA/3fYPThf7PdIhWpe3+dFMEKAKG2MT0KOZmRm0uKLwEPKZfTKJDmUpZ yZlZ2iURTBSuAi5cAipvd3+657j7paSfTlRTwD1WUw6Anl0uaNnJZCxVqscapjsU 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 PTi_Naww_Y4z; Mon, 17 Jun 2024 21:09:30 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4W32ZJ594cz6Cnk95; Mon, 17 Jun 2024 21:09:28 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Minwoo Im , Peter Wang , ChanWoo Lee , Yang Li , Po-Wen Kao , Avri Altman , Manivannan Sadhasivam , Maramaina Naresh , Akinobu Mita , Bean Huo Subject: [PATCH 4/8] scsi: ufs: Make .get_hba_mac() optional Date: Mon, 17 Jun 2024 14:07:43 -0700 Message-ID: <20240617210844.337476-5-bvanassche@acm.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog In-Reply-To: <20240617210844.337476-1-bvanassche@acm.org> References: <20240617210844.337476-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 UFSHCI controllers that are compliant with the UFSHCI 4.0 standard report the maximum number of supported commands in the controller capabilities register. Use that value if .get_hba_mac == NULL. Signed-off-by: Bart Van Assche Reviewed-by: Daejun Park --- drivers/ufs/core/ufs-mcq.c | 12 +++++++----- include/ufs/ufshcd.h | 4 +++- include/ufs/ufshci.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c index 0482c7a1e419..d6f966f4abef 100644 --- a/drivers/ufs/core/ufs-mcq.c +++ b/drivers/ufs/core/ufs-mcq.c @@ -138,7 +138,6 @@ EXPORT_SYMBOL_GPL(ufshcd_mcq_queue_cfg_addr); * * MAC - Max. Active Command of the Host Controller (HC) * HC wouldn't send more than this commands to the device. - * It is mandatory to implement get_hba_mac() to enable MCQ mode. * Calculates and adjusts the queue depth based on the depth * supported by the HC and ufs device. */ @@ -146,10 +145,13 @@ int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba) { int mac = -EOPNOTSUPP; - if (!hba->vops || !hba->vops->get_hba_mac) - goto err; - - mac = hba->vops->get_hba_mac(hba); + if (!hba->vops || !hba->vops->get_hba_mac) { + hba->capabilities = + ufshcd_readl(hba, REG_CONTROLLER_CAPABILITIES); + mac = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS) + 1; + } else { + mac = hba->vops->get_hba_mac(hba); + } if (mac < 0) goto err; diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index d4d63507d090..d32637d267f3 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -325,7 +325,9 @@ struct ufs_pwr_mode_info { * @event_notify: called to notify important events * @reinit_notify: called to notify reinit of UFSHCD during max gear switch * @mcq_config_resource: called to configure MCQ platform resources - * @get_hba_mac: called to get vendor specific mac value, mandatory for mcq mode + * @get_hba_mac: reports maximum number of outstanding commands supported by + * the controller. Should be implemented for UFSHCI 4.0 or later + * controllers that are not compliant with the UFSHCI 4.0 specification. * @op_runtime_config: called to config Operation and runtime regs Pointers * @get_outstanding_cqs: called to get outstanding completion queues * @config_esi: called to config Event Specific Interrupt diff --git a/include/ufs/ufshci.h b/include/ufs/ufshci.h index c50f92bf2e1d..899077bba2d2 100644 --- a/include/ufs/ufshci.h +++ b/include/ufs/ufshci.h @@ -67,7 +67,7 @@ enum { /* Controller capability masks */ enum { - MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F, + MASK_TRANSFER_REQUESTS_SLOTS = 0x000000FF, MASK_NUMBER_OUTSTANDING_RTT = 0x0000FF00, MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000, MASK_EHSLUTRD_SUPPORTED = 0x00400000, From patchwork Mon Jun 17 21:07:44 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: 13701436 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 9455118C356 for ; Mon, 17 Jun 2024 21:09: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=1718658578; cv=none; b=Vz46co1dlpChz6NcIh5tN8+TmL5C3OQGQqHKOCKK7AT8pdf3rb9V4T9qBjhW09kehtlqyjqcXAs/Ecmibj2q9R8XldRm0nO/YtR/GTA0sFMrVwwEKIP6qTzq40Wagd6ihzHefxD3VJvRoyIXZ3rVpeDgqksYo0NoNL1PmNO4Wao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718658578; c=relaxed/simple; bh=T9WrfpuBDHAe4xeZm3YN8pMCpcrsE0CX5iaqAirKMB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bcVhOXfTZjtdlIMQvqjCpnh5OeRW4TXMczQOyMA0mI+T01TMEr2TL9Qgsbr5MS+8/GWkRoYYMS64i3qjmlLssq86RHPsDLVJiatH53IM9gn8btB9PyOyNqVbv5hcyQHrSSp7TuQAOpTeW8BKNY7Th9vslS0kzdvobQkKYSRy1OU= 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=EbzvC5iM; 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="EbzvC5iM" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4W32ZS2bVXz6Cnk9B; Mon, 17 Jun 2024 21:09:36 +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=1718658574; x=1721250575; bh=0gyQs VhGa672wbZSWf6EJ1bspdIdFZwvR0VKtj2LVjM=; b=EbzvC5iM+imUYi2HJeVu0 31BoZPeHClpCjA2LTJeVAcua94Je2fDPTWkbwSGiy6VtYIkGodLCXr0q9yE+9zRm gqEoZu6WSsuI8ZyBGenVWMdYwSscrih6422iU5tj70+XZ2QCrghlX9/5lJIjY6g7 ylp6iP6JdFVv2BK/rMfLa8rLZya5zqrLMuSNr8IdsGQJNztSkOUB4Q163TNcRiux VkrLTmppUWlLgOOnDtR8gFSDI0eSPh2CY8tn1Uzz4s5hzT2ksFEEGf2n6oKzI+gT yM7T9B3Zu0RjbmSlRswc/nJg58qdmv9yXU4UA+OpvKHYb1Nu8EErhMTxgn4FqhY+ 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 W8H4rV7233iW; Mon, 17 Jun 2024 21:09:34 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4W32ZP6h9Mz6Cnk98; Mon, 17 Jun 2024 21:09:33 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Keoseong Park Subject: [PATCH 5/8] scsi: ufs: Declare ufshcd_mcq_poll_cqe_lock() once Date: Mon, 17 Jun 2024 14:07:44 -0700 Message-ID: <20240617210844.337476-6-bvanassche@acm.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog In-Reply-To: <20240617210844.337476-1-bvanassche@acm.org> References: <20240617210844.337476-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_mcq_poll_cqe_lock() is declared in include/ufs/ufshcd.h and also in drivers/ufs/core/ufshcd-priv.h. Remove the declaration from the latter file. Signed-off-by: Bart Van Assche Reviewed-by: Avri Altman --- drivers/ufs/core/ufshcd-priv.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index a1add22205db..fb4457a84d11 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -72,8 +72,6 @@ u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i); void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i); struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba, struct request *req); -unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, - struct ufs_hw_queue *hwq); void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, struct ufs_hw_queue *hwq); bool ufshcd_cmd_inflight(struct scsi_cmnd *cmd); From patchwork Mon Jun 17 21:07:45 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: 13701438 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 0F28B1990AA for ; Mon, 17 Jun 2024 21:09:42 +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=1718658584; cv=none; b=X73uAN8f+hggFp9xsGjSYB/wgEASt5QNdkhwUIkWN57t7zUDFr0mPI0OLx1KY+R6sY3uwiOJv7Xplcr6EjZrg7D9+xzoka5ruLtG2DQd6e8f5MFtERD4hy6dd+a4cfQOO5PT6SMVKr3PWXvDWMbV86Ao5JV3cD/YO2waCsM54vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718658584; c=relaxed/simple; bh=xgJj6t3fBWpmlB3hDcPD1m1ugdyL8Tpx1obBtHTQ+i4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L3CC46r+5zKcuCt3krAfhAlor3BT1BviAAR65UGDVvHdItB8oQocX3A6cDlmCPfLVYv155CiTQcFkvv+cpCY9cwykPAYRxL8TW+UejZKl0PJWWFwaLAcngOoP+uAXojZU8OO/zQyBYtJTfupXMe97aN6L2cGi6+7ov7PPCs7700= 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=gmOf8J40; 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="gmOf8J40" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4W32ZZ4Dm4z6Cnk8y; Mon, 17 Jun 2024 21:09:42 +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=1718658579; x=1721250580; bh=huP5g gTZKKqUkyhGa5Wjm6aKhUkPbI0naNf9IfumIbg=; b=gmOf8J40433ZjAT/fesDB yt4HhMQv5ux+kxvbEllWBoAdTdXFd9Beem8GWRUit4z1ZrIZSqywFyn/RiKYDyfG lqx3/nq3/KkJUc0vTE/B11FU0vwWmG3uA22RZ9szsC2FqXxwpQ93P93/3dHtMPFp y1rJxtzRVXkM4+keKECKMaLu2o5d4Ki1udJRP8WO5DBt1c/7ylQc9RT8RpsY/khm wClKTtVkM0QQfepl1306yyBaKPreDiExrPg4EOL4sdRXy3Ofay91CbM/C5f4NSvX PlBm6u0K0JvvZwFs8w2eVNdKA+dHYPIAkFaLw2U8viF/0qtOud6ecmdJ21DhSVH8 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 UWbARFDW8CAr; Mon, 17 Jun 2024 21:09:39 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4W32ZV4ncYz6Cnk95; Mon, 17 Jun 2024 21:09:38 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Avri Altman , Peter Wang , Manivannan Sadhasivam , Bean Huo , Andrew Halaney Subject: [PATCH 6/8] scsi: ufs: Make ufshcd_poll() complain about unsupported arguments Date: Mon, 17 Jun 2024 14:07:45 -0700 Message-ID: <20240617210844.337476-7-bvanassche@acm.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog In-Reply-To: <20240617210844.337476-1-bvanassche@acm.org> References: <20240617210844.337476-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 ufshcd_poll() implementation does not support queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT in MCQ mode. Hence complain if queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT in MCQ mode. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 7761ccca2115..db374a788140 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5562,6 +5562,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) struct ufs_hw_queue *hwq; if (is_mcq_enabled(hba)) { + WARN_ON_ONCE(queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT); hwq = &hba->uhq[queue_num]; return ufshcd_mcq_poll_cqe_lock(hba, hwq); From patchwork Mon Jun 17 21:07:46 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: 13701440 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 E3AE418C356 for ; Mon, 17 Jun 2024 21:10: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=1718658623; cv=none; b=UFeWFfPqxm8furkD3K5z20nL/NTQJscR8VradnchQSKA8SYbQoMY926mF5aGE0api8sgzbpUTMw4UQ32FWKWLwjKhV03zAYi9HZQVYScWn/kp96H2ljve3JM9USUWWbfloicb94av08TwsHgWCn7jFQMz+0sv7vPNaNV2E/Jglg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718658623; c=relaxed/simple; bh=hPHjiDx82O4XZfWXcB77/9420Z7wOTk88urjKEgSZBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ILsU/QxRWV7TB34e3yiBkLlY6Yd4PXG+ZpTW9Gmo1x+HdYRyhxAPOss5jE9Ng6d//pgnJl3BfgqSaxQawtF7BzFYpadc3wDLQ1p/kfnwSin7DgNF2XyXhjbA3jJr3wVQ0YFhcasJLh2XUz7YUPbQN6WjNZPKChWtWWHarsgM1Io= 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=Zcl/MpDH; 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="Zcl/MpDH" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4W32bK4qGqz6Cnk98; Mon, 17 Jun 2024 21:10: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=1718658596; x=1721250597; bh=bCRLs SD2qdYp34UMbcSPqJbZlGJqTdMGxVq3wDaKD5k=; b=Zcl/MpDHwjF4S3M/eytrr vwILM8qDtEm5OeFIJlPqPYI9fcxSFaUUQsiciVy9UwklKswpFEQxuf65ynwI00so 72GTg37dnzv6d4TVQa1fSO5Vunlr88Je3Nb1NKIa3MFrPxxKDJeo4xOdNYGoEsgq Aeh6xneNr9xv+7XXhONJ1WoIkP7IRVY2IyCLlRtDEthCwVAd9XO3OHUA1iMoRCiB YxOrM2uOdytUWBo95Ff9dVPwing+6m+lKPRB+4tV3AYvr49pZC/eLV/lnQqdncy8 H9j6NBN4vfJhdO3M86J/Rw9GH7ORNiLZhxmzKilSw6ThMxFbAwMP2XbeahNxhwwy 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 PyYqoJ_fYUvH; Mon, 17 Jun 2024 21:09:56 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4W32Zp5tvQz6Cnk95; Mon, 17 Jun 2024 21:09:54 +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 , Manivannan Sadhasivam , Matthias Brugger , AngeloGioacchino Del Regno , Minwoo Im , ChanWoo Lee , "Bao D. Nguyen" , Po-Wen Kao , Yang Li , Keoseong Park , Avri Altman , Andrew Halaney , Bean Huo , Maramaina Naresh , Akinobu Mita Subject: [PATCH 7/8] scsi: ufs: Make the polling code report which command has been completed Date: Mon, 17 Jun 2024 14:07:46 -0700 Message-ID: <20240617210844.337476-8-bvanassche@acm.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog In-Reply-To: <20240617210844.337476-1-bvanassche@acm.org> References: <20240617210844.337476-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 introducing a new __ufshcd_poll() caller that will need to know whether or not a specific command has been completed. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufs-mcq.c | 25 +++++++++++++------- drivers/ufs/core/ufshcd-priv.h | 4 ++-- drivers/ufs/core/ufshcd.c | 41 +++++++++++++++++++++++---------- drivers/ufs/host/ufs-mediatek.c | 2 +- drivers/ufs/host/ufs-qcom.c | 2 +- include/ufs/ufshcd.h | 3 ++- 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c index d6f966f4abef..c9155759934c 100644 --- a/drivers/ufs/core/ufs-mcq.c +++ b/drivers/ufs/core/ufs-mcq.c @@ -294,17 +294,22 @@ static int ufshcd_mcq_get_tag(struct ufs_hba *hba, struct cq_entry *cqe) return div_u64(addr, ufshcd_get_ucd_size(hba)); } -static void ufshcd_mcq_process_cqe(struct ufs_hba *hba, - struct ufs_hw_queue *hwq) +/* Returns true if and only if @compl_cmd has been completed. */ +static bool ufshcd_mcq_process_cqe(struct ufs_hba *hba, + struct ufs_hw_queue *hwq, + struct scsi_cmnd *compl_cmd) { struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq); - int tag = ufshcd_mcq_get_tag(hba, cqe); if (cqe->command_desc_base_addr) { - ufshcd_compl_one_cqe(hba, tag, cqe); - /* After processed the cqe, mark it empty (invalid) entry */ + const int tag = ufshcd_mcq_get_tag(hba, cqe); + + /* Mark the CQE as invalid. */ cqe->command_desc_base_addr = 0; + + return ufshcd_compl_one_cqe(hba, tag, cqe, compl_cmd); } + return false; } void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, @@ -315,7 +320,7 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, spin_lock_irqsave(&hwq->cq_lock, flags); while (entries > 0) { - ufshcd_mcq_process_cqe(hba, hwq); + ufshcd_mcq_process_cqe(hba, hwq, NULL); ufshcd_mcq_inc_cq_head_slot(hwq); entries--; } @@ -325,8 +330,10 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, spin_unlock_irqrestore(&hwq->cq_lock, flags); } +/* Clears *@compl_cmd if and only if *@compl_cmd has been completed. */ unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, - struct ufs_hw_queue *hwq) + struct ufs_hw_queue *hwq, + struct scsi_cmnd **compl_cmd) { unsigned long completed_reqs = 0; unsigned long flags; @@ -334,7 +341,9 @@ unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, spin_lock_irqsave(&hwq->cq_lock, flags); ufshcd_mcq_update_cq_tail_slot(hwq); while (!ufshcd_mcq_is_cq_empty(hwq)) { - ufshcd_mcq_process_cqe(hba, hwq); + if (ufshcd_mcq_process_cqe(hba, hwq, + compl_cmd ? *compl_cmd : NULL)) + *compl_cmd = NULL; ufshcd_mcq_inc_cq_head_slot(hwq); completed_reqs++; } diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index fb4457a84d11..42802fd689fb 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -61,8 +61,8 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, enum flag_idn idn, u8 index, bool *flag_res); void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit); -void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, - struct cq_entry *cqe); +bool ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, + struct cq_entry *cqe, struct scsi_cmnd *compl_cmd); int ufshcd_mcq_init(struct ufs_hba *hba); int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba); int ufshcd_mcq_memory_alloc(struct ufs_hba *hba); diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index db374a788140..e3835e61e4b1 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5488,9 +5488,12 @@ void ufshcd_release_scsi_cmd(struct ufs_hba *hba, * @hba: per adapter instance * @task_tag: the task tag of the request to be completed * @cqe: pointer to the completion queue entry + * @compl_cmd: if not NULL, check whether this command has been completed + * + * Returns: true if and only if @compl_cmd has been completed. */ -void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, - struct cq_entry *cqe) +bool ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, + struct cq_entry *cqe, struct scsi_cmnd *compl_cmd) { struct ufshcd_lrb *lrbp; struct scsi_cmnd *cmd; @@ -5507,6 +5510,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, ufshcd_release_scsi_cmd(hba, lrbp); /* Do not touch lrbp after scsi done */ scsi_done(cmd); + return cmd == compl_cmd; } else if (hba->dev_cmd.complete) { if (cqe) { ocs = le32_to_cpu(cqe->status) & MASK_OCS; @@ -5514,20 +5518,26 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, } complete(hba->dev_cmd.complete); } + return false; } /** * __ufshcd_transfer_req_compl - handle SCSI and query command completion * @hba: per adapter instance * @completed_reqs: bitmask that indicates which requests to complete + * @compl_cmd: if not NULL, check whether *@compl_cmd has been completed. + * Clear *@compl_cmd if it has been completed. */ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, - unsigned long completed_reqs) + unsigned long completed_reqs, + struct scsi_cmnd **compl_cmd) { int tag; for_each_set_bit(tag, &completed_reqs, hba->nutrs) - ufshcd_compl_one_cqe(hba, tag, NULL); + if (ufshcd_compl_one_cqe(hba, tag, NULL, + compl_cmd ? *compl_cmd : NULL)) + *compl_cmd = NULL; } /* Any value that is not an existing queue number is fine for this constant. */ @@ -5554,7 +5564,8 @@ static void ufshcd_clear_polled(struct ufs_hba *hba, * Return: > 0 if one or more commands have been completed or 0 if no * requests have been completed. */ -static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) +static int __ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num, + struct scsi_cmnd **compl_cmd) { struct ufs_hba *hba = shost_priv(shost); unsigned long completed_reqs, flags; @@ -5565,7 +5576,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) WARN_ON_ONCE(queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT); hwq = &hba->uhq[queue_num]; - return ufshcd_mcq_poll_cqe_lock(hba, hwq); + return ufshcd_mcq_poll_cqe_lock(hba, hwq, compl_cmd); } spin_lock_irqsave(&hba->outstanding_lock, flags); @@ -5582,11 +5593,16 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) spin_unlock_irqrestore(&hba->outstanding_lock, flags); if (completed_reqs) - __ufshcd_transfer_req_compl(hba, completed_reqs); + __ufshcd_transfer_req_compl(hba, completed_reqs, compl_cmd); return completed_reqs != 0; } +static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) +{ + return __ufshcd_poll(shost, queue_num, NULL); +} + /** * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is * invoked from the error handler context or ufshcd_host_reset_and_restore() @@ -5630,7 +5646,7 @@ static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, } spin_unlock_irqrestore(&hwq->cq_lock, flags); } else { - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); } } } @@ -6905,7 +6921,7 @@ static irqreturn_t ufshcd_handle_mcq_cq_events(struct ufs_hba *hba) ufshcd_mcq_write_cqis(hba, events, i); if (events & UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS) - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); } return IRQ_HANDLED; @@ -7398,7 +7414,7 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) lrbp->lun == lun) { ufshcd_clear_cmd(hba, pos); hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(lrbp->cmd)); - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); } } err = 0; @@ -7426,7 +7442,8 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) __func__, pos); } } - __ufshcd_transfer_req_compl(hba, pending_reqs & ~not_cleared_mask); + __ufshcd_transfer_req_compl(hba, pending_reqs & ~not_cleared_mask, + NULL); out: hba->req_abort_count = 0; @@ -7603,7 +7620,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) dev_err(hba->dev, "%s: cmd was completed, but without a notifying intr, tag = %d", __func__, tag); - __ufshcd_transfer_req_compl(hba, 1UL << tag); + __ufshcd_transfer_req_compl(hba, 1UL << tag, NULL); goto release; } diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index c7a0ab9b1f59..4dbe334b36bb 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -1715,7 +1715,7 @@ static irqreturn_t ufs_mtk_mcq_intr(int irq, void *__intr_info) ufshcd_mcq_write_cqis(hba, events, qid); if (events & UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS) - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); return IRQ_HANDLED; } diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index cca190d1c577..cc1d9614fcd6 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -1715,7 +1715,7 @@ static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data) struct ufs_hw_queue *hwq = &hba->uhq[id]; ufshcd_mcq_write_cqis(hba, 0x1, id); - ufshcd_mcq_poll_cqe_lock(hba, hwq); + ufshcd_mcq_poll_cqe_lock(hba, hwq, NULL); return IRQ_HANDLED; } diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index d32637d267f3..443afb97a637 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1284,7 +1284,8 @@ unsigned int ufshcd_mcq_queue_cfg_addr(struct ufs_hba *hba); u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i); void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i); unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, - struct ufs_hw_queue *hwq); + struct ufs_hw_queue *hwq, + struct scsi_cmnd **compl_cmd); void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba); void ufshcd_mcq_enable_esi(struct ufs_hba *hba); void ufshcd_mcq_enable(struct ufs_hba *hba); From patchwork Mon Jun 17 21:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13701439 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 32A3A18C356 for ; Mon, 17 Jun 2024 21:10:06 +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=1718658608; cv=none; b=O+tC3L+1zOlQ9Qq1/3Q7qCfpht+M9XfD8WpG3jGum72cerdYv6vInLh3qFQ0Dn0dmOIv/243lgfAQ0QrfhlDsKq4ipVZA5y/fvZnwTRtNrnjezcu3UDfPkgQ5m53/jfaHe7smGHdO88leWeWdrY/d6k7st0IMLm47m4CkYpjWg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718658608; c=relaxed/simple; bh=yb0McD41g0o0HCK3QhnzrK3mBzf73/2CNyLyHjfHosA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M8e45e71s3ritgaakWg+M+FqDkEe7e7LUtC37WlqOW2fttqRAv2W7L0tBwfUroYzlRQJvjlXyKWXAs2ZSMcgIHEjG+NnnqGqiWrCJxXum0Ewu3GXSjNQ8PC7IFlJ9bQJFGQCvTZjdmT7UnIXYiHXCiOr7vcCqEA4PG/FgtzxzQQ= 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=rNI14ai3; 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="rNI14ai3" Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4W32b24Z7fz6Cnk9B; Mon, 17 Jun 2024 21:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received; s=mr01; t=1718658601; x= 1721250602; bh=tQEsiqrH6OPSOAxgYaULeIt/dsptPbFpcFz+UiujRzw=; b=r NI14ai3PTVSHVFiCuGeOmtKiB9mHT3n3axPHgXmzt8oAmzzvn2Ab7UcWqLniKRg6 2L9qUVE8MHAOTV8NZmE3iS6asBNTg38mvu0ONOl0aAc2K7d3fDUNsSNjslXkUulq DHyFdvwJHkIi+TLHDt2fGiD0cFu1QgStMnCP7OyimVwZiQca01O5zFsCr/Q2mCCa CKjdyjvBlLQA/TEdO3oULJajeFiYB9SpHmjhb7vSDEHRaxNMwcsItPN29UNxY0Tb q18LfbTv0BSV0SbPoHB50DrRNtksXzguzCWoo9CQAGp1+0YqH7ga+FGKN32McDof gw5MB0vM4zxM7sMALRu7g== 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 x5-e__vOByqT; Mon, 17 Jun 2024 21:10:01 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.132.0.90]) (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 4W32Zw63Ykz6Cnk98; Mon, 17 Jun 2024 21:10:00 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Avri Altman , Peter Wang , Manivannan Sadhasivam , Bean Huo , Andrew Halaney Subject: [PATCH 8/8] scsi: ufs: Check for completion from the timeout handler Date: Mon, 17 Jun 2024 14:07:47 -0700 Message-ID: <20240617210844.337476-9-bvanassche@acm.org> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog In-Reply-To: <20240617210844.337476-1-bvanassche@acm.org> References: <20240617210844.337476-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If ufshcd_abort() returns SUCCESS for an already completed command then that command is completed twice. This results in a crash. Prevent this by checking whether a command has completed without completion interrupt from the timeout handler. This CL fixes the following kernel crash: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 Call trace:  dma_direct_map_sg+0x70/0x274  scsi_dma_map+0x84/0x124  ufshcd_queuecommand+0x3fc/0x880  scsi_queue_rq+0x7d0/0x111c  blk_mq_dispatch_rq_list+0x440/0xebc  blk_mq_do_dispatch_sched+0x5a4/0x6b8  __blk_mq_sched_dispatch_requests+0x150/0x220  __blk_mq_run_hw_queue+0xf0/0x218  __blk_mq_delay_run_hw_queue+0x8c/0x18c  blk_mq_run_hw_queue+0x1a4/0x360  blk_mq_sched_insert_requests+0x130/0x334  blk_mq_flush_plug_list+0x138/0x234  blk_flush_plug_list+0x118/0x164  blk_finish_plug()  read_pages+0x38c/0x408  page_cache_ra_unbounded+0x230/0x2f8  do_sync_mmap_readahead+0x1a4/0x208  filemap_fault+0x27c/0x8f4  f2fs_filemap_fault+0x28/0xfc  __do_fault+0xc4/0x208  handle_pte_fault+0x290/0xe04  do_handle_mm_fault+0x52c/0x858  do_page_fault+0x5dc/0x798  do_translation_fault+0x40/0x54  do_mem_abort+0x60/0x134  el0_da+0x40/0xb8  el0t_64_sync_handler+0xc4/0xe4  el0t_64_sync+0x1b4/0x1b8 Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index e3835e61e4b1..47cc0802c4f4 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8922,7 +8922,28 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd) { - struct ufs_hba *hba = shost_priv(scmd->device->host); + struct scsi_device *sdev = scmd->device; + struct ufs_hba *hba = shost_priv(sdev->host); + struct scsi_cmnd *cmd2 = scmd; + const u32 unique_tag = blk_mq_unique_tag(scsi_cmd_to_rq(scmd)); + + WARN_ON_ONCE(!scmd); + + if (is_mcq_enabled(hba)) { + struct request *rq = scsi_cmd_to_rq(scmd); + struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, rq); + + ufshcd_mcq_poll_cqe_lock(hba, hwq, &cmd2); + } else { + __ufshcd_poll(hba->host, UFSHCD_POLL_FROM_INTERRUPT_CONTEXT, + &cmd2); + } + if (cmd2 == NULL) { + sdev_printk(KERN_INFO, sdev, + "%s: cmd with tag %#x has already been completed\n", + __func__, unique_tag); + return SCSI_EH_DONE; + } if (!hba->system_suspending) { /* Activate the error handler in the SCSI core. */