From patchwork Tue Mar 5 21:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13583000 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (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 1ADE8168DD; Tue, 5 Mar 2024 21:01:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709672478; cv=none; b=gBnFvGWFjo3UO497q3sDYQp3axBSEiuA4lZdYre880QW68bPLYbhm/P3pju3ebQ0qbkMg2+mTQgORWwBN37x5WcrSrEHowxSfsZqb0nXpdKPFv0DQfgmIRVgzhFVoUGONPcVYw2EfjyM61UR+aZc9xb44XHUKHr6LBUcDa6pYOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709672478; c=relaxed/simple; bh=IuBwA/fW3rQm/qse2UqUNp2c3FdtJr9WHEPD47rdum8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dlRRW485gNw+qu5ffPRhnyV+OdPyjJMlzmPnLsR1Kf4qjOb9tvQq60GoJH7dPvjZvcxhe7KkHU/2dWjEEV3YzZdb8kQkXUJ9I+BB6ru9JHmU5TJwayQEeAyJjqTkvXcC/JvgsrdfRlHx3oQLWnLEWTASMgc+ocx3e9hAMrTB7SQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=k9M2HSmd; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="k9M2HSmd" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1709672476; x=1741208476; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IuBwA/fW3rQm/qse2UqUNp2c3FdtJr9WHEPD47rdum8=; b=k9M2HSmdcg14GnZaZ/hDo144kAxNGWWzbtScR8ENvc6Mr4L0mLBkPB+D 32lysLxyrEYETasMS3w1H/0BtQj9lVTxX0OAY0X1Uzg52FnQ1sYB3CNZY QNRS8krjk9RR7mUt+Ah0B/LNskOYZIQX2Hzh2sgY7X7ei9NvhqFn4A8gP P64+6bAIUr+xdZ7fVzTZmHrDVsJGwU5p71NmnxA3bxtZKW8AsRw7Og1Xc nraKsYB3kfP54rPbtyzQ7O9wPsIn/vowWpAa3zvGj0JSHmgcz80E/VKCB 8jI8Srt6FeDidfEAotgf0w/iergMJ6nIO5jYALcn1SqZfQ8JkgiXjo936 g==; X-CSE-ConnectionGUID: fU0R9NE2R9ObftjyCOHkUA== X-CSE-MsgGUID: IY/e7B1NQSu5sCw2joS1Ig== X-IronPort-AV: E=Sophos;i="6.06,206,1705334400"; d="scan'208";a="10855990" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Mar 2024 05:01:14 +0800 IronPort-SDR: NkOvuFfzqDDuB7azPg6xeA+PNk6waA423TXu/bu55I98uRkS1dRell/djWIsOERIlXG3tXKe8I jfrBmSMeimyw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Mar 2024 12:10:25 -0800 IronPort-SDR: pxgEwPUjejmb1LiGvKlc/yTd4SVeOsu91Lpid28Gl0GbhOkIL26+TNa3aQDEHeQIPXJyMYFhLy dlNexT41TiFg== WDCIronportException: Internal Received: from 87h6l33.ad.shared (HELO BXYGM33.ad.shared) ([10.225.32.8]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Mar 2024 13:01:13 -0800 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: Bart Van Assche , Bean Huo , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v2 1/4] scsi: ufs: Re-use device management locking code Date: Tue, 5 Mar 2024 23:00:46 +0200 Message-ID: <20240305210051.10847-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240305210051.10847-1-avri.altman@wdc.com> References: <20240305210051.10847-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Group those 3 calls that repeat for every device management command into a lock and unlock handlers. Reviewed-by: Bart Van Assche Signed-off-by: Avri Altman Reviewed-by: Bean Huo --- drivers/ufs/core/ufshcd.c | 69 ++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 21429eec1b82..983b7b8e3c7c 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3272,6 +3272,20 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, return err; } +static void ufshcd_dev_man_lock(struct ufs_hba *hba) +{ + ufshcd_hold(hba); + mutex_lock(&hba->dev_cmd.lock); + down_read(&hba->clk_scaling_lock); +} + +static void ufshcd_dev_man_unlock(struct ufs_hba *hba) +{ + up_read(&hba->clk_scaling_lock); + mutex_unlock(&hba->dev_cmd.lock); + ufshcd_release(hba); +} + /** * ufshcd_exec_dev_cmd - API for sending device management requests * @hba: UFS hba @@ -3294,8 +3308,6 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, /* Protects use of hba->reserved_slot. */ lockdep_assert_held(&hba->dev_cmd.lock); - down_read(&hba->clk_scaling_lock); - lrbp = &hba->lrb[tag]; lrbp->cmd = NULL; err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag); @@ -3312,7 +3324,6 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); out: - up_read(&hba->clk_scaling_lock); return err; } @@ -3383,8 +3394,8 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, BUG_ON(!hba); - ufshcd_hold(hba); - mutex_lock(&hba->dev_cmd.lock); + ufshcd_dev_man_lock(hba); + ufshcd_init_query(hba, &request, &response, opcode, idn, index, selector); @@ -3426,8 +3437,7 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, MASK_QUERY_UPIU_FLAG_LOC) & 0x1; out_unlock: - mutex_unlock(&hba->dev_cmd.lock); - ufshcd_release(hba); + ufshcd_dev_man_unlock(hba); return err; } @@ -3457,9 +3467,8 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, return -EINVAL; } - ufshcd_hold(hba); + ufshcd_dev_man_lock(hba); - mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index, selector); @@ -3489,8 +3498,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, *attr_val = be32_to_cpu(response->upiu_res.value); out_unlock: - mutex_unlock(&hba->dev_cmd.lock); - ufshcd_release(hba); + ufshcd_dev_man_unlock(hba); return err; } @@ -3553,9 +3561,8 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba, return -EINVAL; } - ufshcd_hold(hba); + ufshcd_dev_man_lock(hba); - mutex_lock(&hba->dev_cmd.lock); ufshcd_init_query(hba, &request, &response, opcode, idn, index, selector); hba->dev_cmd.query.descriptor = desc_buf; @@ -3588,8 +3595,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba, out_unlock: hba->dev_cmd.query.descriptor = NULL; - mutex_unlock(&hba->dev_cmd.lock); - ufshcd_release(hba); + ufshcd_dev_man_unlock(hba); return err; } @@ -5070,8 +5076,8 @@ static int ufshcd_verify_dev_init(struct ufs_hba *hba) int err = 0; int retries; - ufshcd_hold(hba); - mutex_lock(&hba->dev_cmd.lock); + ufshcd_dev_man_lock(hba); + for (retries = NOP_OUT_RETRIES; retries > 0; retries--) { err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_NOP, hba->nop_out_timeout); @@ -5081,8 +5087,8 @@ static int ufshcd_verify_dev_init(struct ufs_hba *hba) dev_dbg(hba->dev, "%s: error %d retrying\n", __func__, err); } - mutex_unlock(&hba->dev_cmd.lock); - ufshcd_release(hba); + + ufshcd_dev_man_unlock(hba); if (err) dev_err(hba->dev, "%s: NOP OUT failed %d\n", __func__, err); @@ -7209,8 +7215,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, /* Protects use of hba->reserved_slot. */ lockdep_assert_held(&hba->dev_cmd.lock); - down_read(&hba->clk_scaling_lock); - lrbp = &hba->lrb[tag]; lrbp->cmd = NULL; lrbp->task_tag = tag; @@ -7275,7 +7279,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP, (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); - up_read(&hba->clk_scaling_lock); return err; } @@ -7314,13 +7317,11 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, cmd_type = DEV_CMD_TYPE_NOP; fallthrough; case UPIU_TRANSACTION_QUERY_REQ: - ufshcd_hold(hba); - mutex_lock(&hba->dev_cmd.lock); + ufshcd_dev_man_lock(hba); err = ufshcd_issue_devman_upiu_cmd(hba, req_upiu, rsp_upiu, desc_buff, buff_len, cmd_type, desc_op); - mutex_unlock(&hba->dev_cmd.lock); - ufshcd_release(hba); + ufshcd_dev_man_unlock(hba); break; case UPIU_TRANSACTION_TASK_REQ: @@ -7380,9 +7381,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r u16 ehs_len; /* Protects use of hba->reserved_slot. */ - ufshcd_hold(hba); - mutex_lock(&hba->dev_cmd.lock); - down_read(&hba->clk_scaling_lock); + ufshcd_dev_man_lock(hba); lrbp = &hba->lrb[tag]; lrbp->cmd = NULL; @@ -7448,9 +7447,8 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r } } - up_read(&hba->clk_scaling_lock); - mutex_unlock(&hba->dev_cmd.lock); - ufshcd_release(hba); + ufshcd_dev_man_unlock(hba); + return err ? : result; } @@ -8713,9 +8711,7 @@ static void ufshcd_set_timestamp_attr(struct ufs_hba *hba) if (dev_info->wspecversion < 0x400) return; - ufshcd_hold(hba); - - mutex_lock(&hba->dev_cmd.lock); + ufshcd_dev_man_lock(hba); ufshcd_init_query(hba, &request, &response, UPIU_QUERY_OPCODE_WRITE_ATTR, @@ -8733,8 +8729,7 @@ static void ufshcd_set_timestamp_attr(struct ufs_hba *hba) dev_err(hba->dev, "%s: failed to set timestamp %d\n", __func__, err); - mutex_unlock(&hba->dev_cmd.lock); - ufshcd_release(hba); + ufshcd_dev_man_unlock(hba); } /** From patchwork Tue Mar 5 21:00:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13583001 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) (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 17FC8168DD; Tue, 5 Mar 2024 21:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709672484; cv=none; b=TaJ85egLW7hF+ivO7Y7J9nBxi8WyviEFROA5ygpcyCsv8Zksz2CrnmeFILqcX9ykepK0fs3fV9+xVxm9+8Sy6tcsfiIFTJKls3GmInEDAbWxLMebGlg/LA9F6FwKZGUzupaAk66PlaNIVdb7LwCYz9P0iiOPo9dlPQ8c5BtN6Hg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709672484; c=relaxed/simple; bh=ZnfZ7ET4S4wv/2O0OfB43T3O8cyA0isR3aRfNcoDRmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZW7+kMvKDXMOOT4gmYyYIbZDLyb7tNPmFPIv5evefpKP034PBugIER/dM1QmphAUj8vBL0BBAnc7xbpa7V99tWa88LP97A9bZnq3ToAnhO4qkQs25jAwIzBXgOjrG/X0Cvx/SIMzKFI7uMezy/EvFAGJ7xN1prJ57InffSOHNZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=oGJoRhCe; arc=none smtp.client-ip=216.71.153.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="oGJoRhCe" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1709672481; x=1741208481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZnfZ7ET4S4wv/2O0OfB43T3O8cyA0isR3aRfNcoDRmE=; b=oGJoRhCeD7m/EtFe1upJOQC+uAsEx7qFV7AYPA6P+lu7mkiWdXY6IcRU /+QdmnBfQpWkX/Tg0mcvbYm1XuW0tCo8tp4DEj+FnMYWo/jbE2xoLmqGO A42e9lc3b0zzCyFF0+BicTy4zAOcOwjaKYGW7TKBRYOc2dW8f4ENtdc4M nueJ3PWy5XmOrPWqJpFX1iMOm/uvPA3VAgne6E9GbIAk3kTEZLRiAxcWu GDE5dqcX54cWwMGMhgHagdrzqhkfE5zh8mDdiZPLVW8oeo1ymvbTdRINq BRae4gPGsdGq0DA1uqdUAuB8b9jtjH1z23hY7TxPUfs50D6n4I99ZAmfc Q==; X-CSE-ConnectionGUID: 6Zi/sagxS3iEqeokvHFWYg== X-CSE-MsgGUID: ESprFExJQI6/QYU1pJVnjw== X-IronPort-AV: E=Sophos;i="6.06,206,1705334400"; d="scan'208";a="11475152" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Mar 2024 05:01:20 +0800 IronPort-SDR: YmXt7AuP4dn8bMSM65zDKgDFdz0g/KBjwRDsk5sC/1UAmICCm6LLbYHZ0yFNNsPJZkQQCjkhWS lh7BLkyQEsRg== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Mar 2024 12:10:31 -0800 IronPort-SDR: EqkbNSMQh2+6eQtB1ZejmsXhgDYwgoSuizsi4k/Qx2r5PVKHkaPduGQm6vQWwsiVA7OvhqR2ji 6Oi9KMDfp/Yg== WDCIronportException: Internal Received: from 87h6l33.ad.shared (HELO BXYGM33.ad.shared) ([10.225.32.8]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Mar 2024 13:01:18 -0800 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: Bart Van Assche , Bean Huo , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v2 2/4] scsi: ufs: Re-use exec_dev_cmd Date: Tue, 5 Mar 2024 23:00:47 +0200 Message-ID: <20240305210051.10847-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240305210051.10847-1-avri.altman@wdc.com> References: <20240305210051.10847-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move out the actual command issue from exec_dev_cmd so it can be used elsewhere. While at it, remove a redundant "lrbp->cmd = NULL" assignment. Also, as a free bonus, call the upiu trace if it doesn't. Signed-off-by: Avri Altman --- drivers/ufs/core/ufshcd.c | 53 ++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 983b7b8e3c7c..3f62ad7b4062 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3286,6 +3286,25 @@ static void ufshcd_dev_man_unlock(struct ufs_hba *hba) ufshcd_release(hba); } +static int ufshcd_issue_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, + const u32 tag, int timeout) +{ + DECLARE_COMPLETION_ONSTACK(wait); + int err; + + hba->dev_cmd.complete = &wait; + + ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr); + + ufshcd_send_command(hba, tag, hba->dev_cmd_queue); + err = ufshcd_wait_for_dev_cmd(hba, lrbp, timeout); + + ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP, + (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); + + return err; +} + /** * ufshcd_exec_dev_cmd - API for sending device management requests * @hba: UFS hba @@ -3300,31 +3319,18 @@ static void ufshcd_dev_man_unlock(struct ufs_hba *hba) static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, enum dev_cmd_type cmd_type, int timeout) { - DECLARE_COMPLETION_ONSTACK(wait); const u32 tag = hba->reserved_slot; - struct ufshcd_lrb *lrbp; + struct ufshcd_lrb *lrbp = &hba->lrb[tag]; int err; /* Protects use of hba->reserved_slot. */ lockdep_assert_held(&hba->dev_cmd.lock); - lrbp = &hba->lrb[tag]; - lrbp->cmd = NULL; err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag); if (unlikely(err)) - goto out; - - hba->dev_cmd.complete = &wait; - - ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr); - - ufshcd_send_command(hba, tag, hba->dev_cmd_queue); - err = ufshcd_wait_for_dev_cmd(hba, lrbp, timeout); - ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP, - (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); + return err; -out: - return err; + return ufshcd_issue_dev_cmd(hba, lrbp, tag, timeout); } /** @@ -7206,7 +7212,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, enum dev_cmd_type cmd_type, enum query_opcode desc_op) { - DECLARE_COMPLETION_ONSTACK(wait); const u32 tag = hba->reserved_slot; struct ufshcd_lrb *lrbp; int err = 0; @@ -7246,17 +7251,12 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); - hba->dev_cmd.complete = &wait; - - ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr); - - ufshcd_send_command(hba, tag, hba->dev_cmd_queue); /* * ignore the returning value here - ufshcd_check_query_response is * bound to fail since dev_cmd.query and dev_cmd.type were left empty. * read the response directly ignoring all errors. */ - ufshcd_wait_for_dev_cmd(hba, lrbp, QUERY_REQ_TIMEOUT); + ufshcd_issue_dev_cmd(hba, lrbp, tag, QUERY_REQ_TIMEOUT); /* just copy the upiu response as it is */ memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu)); @@ -7371,7 +7371,6 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r struct ufs_ehs *rsp_ehs, int sg_cnt, struct scatterlist *sg_list, enum dma_data_direction dir) { - DECLARE_COMPLETION_ONSTACK(wait); const u32 tag = hba->reserved_slot; struct ufshcd_lrb *lrbp; int err = 0; @@ -7418,11 +7417,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); - hba->dev_cmd.complete = &wait; - - ufshcd_send_command(hba, tag, hba->dev_cmd_queue); - - err = ufshcd_wait_for_dev_cmd(hba, lrbp, ADVANCED_RPMB_REQ_TIMEOUT); + err = ufshcd_issue_dev_cmd(hba, lrbp, tag, ADVANCED_RPMB_REQ_TIMEOUT); if (!err) { /* Just copy the upiu response as it is */ From patchwork Tue Mar 5 21:00:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13583002 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 2B13F128817; Tue, 5 Mar 2024 21:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709672494; cv=none; b=P/Yp33yl2q4VT4zo7tDSYJeciurrMmkvprtWuzRFM2sg2hd6eqJRiukthL3ad6/cIx+HyIMzaAY1Kdz39K6gVYcyP+WEsoR4Hg6nTXVS+uLA9sLmwBuv48xzoxzM/FQABrytOmLxq+TuS2hJixoTwx82N3XTVS+GjSS99BLVsc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709672494; c=relaxed/simple; bh=/P84ODUHYbGsYYgXUeXdf6QOlpEWyHv+gD90llRzItY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l0v1IJ7Plli/3cIXA5U7MjZYKpccIwCwpp5Ha7hiqBLdenhKrL9a8Ylf3erdMuU8uMVYjCw8euTVTJiI5PAthXzhSk9fO+k3Eyvksbd8Z42hEVpNKxclThH4Ljkh24uCWvXbhKbxQVq0yCnqRwC0YzcOSWAN467zqWcp2kDFJ9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=nBRothHD; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nBRothHD" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1709672492; x=1741208492; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/P84ODUHYbGsYYgXUeXdf6QOlpEWyHv+gD90llRzItY=; b=nBRothHD3ZrnaBDZgSapBdSvlU3N45bpjIlK4nT+CMTGqWO2DDd6Nelh gnKmtwzLEwMIoQfEhbghJMhp9xEmXsaITYK+i3Urq1lpAyCiHc2N5wYfw 82oqEe0lZxN9dab5Vmh1aLcqX/GFSypslOF03KmnIfL4hyRSICj9yiknv 6CPtF/LKuQnki82+tWgPsY8LSBvOt/KTvxD8hlxkJz0HinT+ubvfrtlti pO/nE0GrO92wxwEBFJ+YmrojinXsrN1VjV5HMHkf0f1ZytbMevWT4hLYB h20ukYmokqHUKhP4O8VWuRPc6ZsW2tFzlbDD4Hd/jAW6vjd352FnzEJOQ A==; X-CSE-ConnectionGUID: OTGbBJByQX6LfY7+1NEmkQ== X-CSE-MsgGUID: NdPADZwQQ1SOro07xyav2Q== X-IronPort-AV: E=Sophos;i="6.06,206,1705334400"; d="scan'208";a="10423325" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Mar 2024 05:01:30 +0800 IronPort-SDR: dGlA6gGgWuCI7l69K8d1mtYIufSHy8dIbSPK5DOv8P7RntsEd2vvP4EfjiFX5OZllWlWS/bBFb Xiru63z7GcHQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Mar 2024 12:10:40 -0800 IronPort-SDR: gNX+rEGkrn/kOQ89Qga37f+D+SkgseS5wSxKjBs90yqq8MhiyrIhFoEq3OaFOM5h9WwmGiXaDP qGjEOVzqaK3Q== WDCIronportException: Internal Received: from 87h6l33.ad.shared (HELO BXYGM33.ad.shared) ([10.225.32.8]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Mar 2024 13:01:28 -0800 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: Bart Van Assche , Bean Huo , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v2 3/4] scsi: ufs: Re-use compose_dev_cmd Date: Tue, 5 Mar 2024 23:00:48 +0200 Message-ID: <20240305210051.10847-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240305210051.10847-1-avri.altman@wdc.com> References: <20240305210051.10847-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move out some of the dev_cmd initializations so it can be used elsewhere. Signed-off-by: Avri Altman Reviewed-by: Bean Huo Reviewed-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 3f62ad7b4062..c9c2b7f99758 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3061,15 +3061,21 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) return err; } -static int ufshcd_compose_dev_cmd(struct ufs_hba *hba, - struct ufshcd_lrb *lrbp, enum dev_cmd_type cmd_type, int tag) +static void ufshcd_setup_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, + enum dev_cmd_type cmd_type, u8 lun, int tag) { lrbp->cmd = NULL; lrbp->task_tag = tag; - lrbp->lun = 0; /* device management cmd is not specific to any LUN */ + lrbp->lun = lun; lrbp->intr_cmd = true; /* No interrupt aggregation */ ufshcd_prepare_lrbp_crypto(NULL, lrbp); hba->dev_cmd.type = cmd_type; +} + +static int ufshcd_compose_dev_cmd(struct ufs_hba *hba, + struct ufshcd_lrb *lrbp, enum dev_cmd_type cmd_type, int tag) +{ + ufshcd_setup_dev_cmd(hba, lrbp, cmd_type, 0, tag); return ufshcd_compose_devman_upiu(hba, lrbp); } @@ -7213,20 +7219,14 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, enum query_opcode desc_op) { const u32 tag = hba->reserved_slot; - struct ufshcd_lrb *lrbp; + struct ufshcd_lrb *lrbp = &hba->lrb[tag]; int err = 0; u8 upiu_flags; /* Protects use of hba->reserved_slot. */ lockdep_assert_held(&hba->dev_cmd.lock); - lrbp = &hba->lrb[tag]; - lrbp->cmd = NULL; - lrbp->task_tag = tag; - lrbp->lun = 0; - lrbp->intr_cmd = true; - ufshcd_prepare_lrbp_crypto(NULL, lrbp); - hba->dev_cmd.type = cmd_type; + ufshcd_setup_dev_cmd(hba, lrbp, cmd_type, 0, tag); if (hba->ufs_version <= ufshci_version(1, 1)) lrbp->command_type = UTP_CMD_TYPE_DEV_MANAGE; @@ -7372,7 +7372,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r enum dma_data_direction dir) { const u32 tag = hba->reserved_slot; - struct ufshcd_lrb *lrbp; + struct ufshcd_lrb *lrbp = &hba->lrb[tag]; int err = 0; int result; u8 upiu_flags; @@ -7382,14 +7382,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r /* Protects use of hba->reserved_slot. */ ufshcd_dev_man_lock(hba); - lrbp = &hba->lrb[tag]; - lrbp->cmd = NULL; - lrbp->task_tag = tag; - lrbp->lun = UFS_UPIU_RPMB_WLUN; - - lrbp->intr_cmd = true; - ufshcd_prepare_lrbp_crypto(NULL, lrbp); - hba->dev_cmd.type = DEV_CMD_TYPE_RPMB; + ufshcd_setup_dev_cmd(hba, lrbp, DEV_CMD_TYPE_RPMB, UFS_UPIU_RPMB_WLUN, tag); /* Advanced RPMB starts from UFS 4.0, so its command type is UTP_CMD_TYPE_UFS_STORAGE */ lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; From patchwork Tue Mar 5 21:00:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13583003 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 03E9F12C80B; Tue, 5 Mar 2024 21:01:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709672501; cv=none; b=ZaygO/I2I/iLDJdAk9PeQQgLXRPmmKG6qm4wZYCZd1o6J2FE2PhG87g/BkW+QsRXaTcN63E8uNBeJowty2Ug5ZU1arsFy00c9SAx8hcbq5SzYMHKyIdX+iSNFIV/ISlFSBDZQH+LOoiN6e4x4/fXJO0y7MRKUMUHLdcE6p5BSZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709672501; c=relaxed/simple; bh=29ejzVaI8kO5HhUl/tLZDpgSk6p3AVFcVgn82c34VcY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DAL/I4PWYCndMmzijGjDgMRCtQDEZDQNDeUijQgeAZvpbAKDc7GeMo1G3g6qA35TpQ7QN0GlHy2iDv22v9c5ckSXz0lgy9w4NnfGETgda50HNqScuPXQEglL6rv40Q58GYoJPSnLrQydSmZZTb6IjnoYL5VT06RounDDcJbY0RI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=dxFeOtPi; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="dxFeOtPi" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1709672500; x=1741208500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=29ejzVaI8kO5HhUl/tLZDpgSk6p3AVFcVgn82c34VcY=; b=dxFeOtPi7DXKf94ZAnyqO4bM6ccwqB2w4e6iZxMF8HVWwezhb9Oo98EZ wC+2nB0k1YO9D+dQRAgZHgewxR4oXOwk0uHWsh4RDoIwtm07b26088N6K vIGrzC9VsJhvkZd6Dek9tdIpUTpUSMozfRtL6GYV1Mb5OyJjHOPdrgaWP 5XTyLL3nriu8GAA39x4y1KuuL4rYLZGbqxVZ9culFvLitJ5xZYy0zMvon rZQQUvmSpJmzMFCak/HWBF6dK3crKEtYt3C7sWRIIp1FOcA0HreOd6ppl RpVKfJno8NEUMpZXSYeSydybAULVWmAP7UTYjgWrFgQJ38VESW6MGYQT9 Q==; X-CSE-ConnectionGUID: eaFc0iNzRRmZW7Lc5gc4Jg== X-CSE-MsgGUID: 19Uu2znaQsWkG42YPrKImA== X-IronPort-AV: E=Sophos;i="6.06,206,1705334400"; d="scan'208";a="10728671" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 06 Mar 2024 05:01:38 +0800 IronPort-SDR: sHqXVOknCW2wtQy/7Lq6IElgd9J50U1RFsrfxBqO+U+8NJJ/y0WzsE83bWOgAHuz95zTHnfZES elSsjh9CVOvw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Mar 2024 12:05:07 -0800 IronPort-SDR: USV0O+qG8QEIyQNqETbVoFM6BwvoRpVli1KcCHpk7tHiRsAtvGtIxrV1WeEzf7VvhyNKxUuSQP fs2N8+bSNd3g== WDCIronportException: Internal Received: from 87h6l33.ad.shared (HELO BXYGM33.ad.shared) ([10.225.32.8]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Mar 2024 13:01:35 -0800 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: Bart Van Assche , Bean Huo , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v2 4/4] scsi: ufs: Re-use compose_devman_upiu Date: Tue, 5 Mar 2024 23:00:49 +0200 Message-ID: <20240305210051.10847-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240305210051.10847-1-avri.altman@wdc.com> References: <20240305210051.10847-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move some code fragments into ufshcd_prepare_req_desc_hdr so it can be used throughout. Signed-off-by: Avri Altman --- drivers/ufs/core/ufshcd.c | 49 ++++++++++++++------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index c9c2b7f99758..a39a2b34ee2b 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -2710,18 +2710,27 @@ static void ufshcd_disable_intr(struct ufs_hba *hba, u32 intrs) /** * ufshcd_prepare_req_desc_hdr - Fill UTP Transfer request descriptor header according to request * descriptor according to request + * @hba: per adapter instance * @lrbp: pointer to local reference block * @upiu_flags: flags required in the header * @cmd_dir: requests data direction * @ehs_length: Total EHS Length (in 32‐bytes units of all Extra Header Segments) + * @scsi: scsi or device management` */ -static void ufshcd_prepare_req_desc_hdr(struct ufshcd_lrb *lrbp, u8 *upiu_flags, - enum dma_data_direction cmd_dir, int ehs_length) +static void +ufshcd_prepare_req_desc_hdr(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, + u8 *upiu_flags, enum dma_data_direction cmd_dir, + int ehs_length, bool scsi) { struct utp_transfer_req_desc *req_desc = lrbp->utr_descriptor_ptr; struct request_desc_header *h = &req_desc->header; enum utp_data_direction data_direction; + if (hba->ufs_version <= ufshci_version(1, 1)) + lrbp->command_type = scsi ? UTP_CMD_TYPE_SCSI : UTP_CMD_TYPE_DEV_MANAGE; + else + lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; + *h = (typeof(*h)){ }; if (cmd_dir == DMA_FROM_DEVICE) { @@ -2854,12 +2863,8 @@ static int ufshcd_compose_devman_upiu(struct ufs_hba *hba, u8 upiu_flags; int ret = 0; - if (hba->ufs_version <= ufshci_version(1, 1)) - lrbp->command_type = UTP_CMD_TYPE_DEV_MANAGE; - else - lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; + ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, DMA_NONE, 0, false); - ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, DMA_NONE, 0); if (hba->dev_cmd.type == DEV_CMD_TYPE_QUERY) ufshcd_prepare_utp_query_req_upiu(hba, lrbp, upiu_flags); else if (hba->dev_cmd.type == DEV_CMD_TYPE_NOP) @@ -2882,13 +2887,8 @@ static void ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) unsigned int ioprio_class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); u8 upiu_flags; - if (hba->ufs_version <= ufshci_version(1, 1)) - lrbp->command_type = UTP_CMD_TYPE_SCSI; - else - lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; - - ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, - lrbp->cmd->sc_data_direction, 0); + ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, + lrbp->cmd->sc_data_direction, 0, true); if (ioprio_class == IOPRIO_CLASS_RT) upiu_flags |= UPIU_CMD_FLAGS_CP; ufshcd_prepare_utp_scsi_cmd_upiu(lrbp, upiu_flags); @@ -7228,16 +7228,11 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, ufshcd_setup_dev_cmd(hba, lrbp, cmd_type, 0, tag); - if (hba->ufs_version <= ufshci_version(1, 1)) - lrbp->command_type = UTP_CMD_TYPE_DEV_MANAGE; - else - lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; + ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, DMA_NONE, 0, false); /* update the task tag in the request upiu */ req_upiu->header.task_tag = tag; - ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, DMA_NONE, 0); - /* just copy the upiu request as it is */ memcpy(lrbp->ucd_req_ptr, req_upiu, sizeof(*lrbp->ucd_req_ptr)); if (desc_buff && desc_op == UPIU_QUERY_OPCODE_WRITE_DESC) { @@ -7378,24 +7373,14 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r u8 upiu_flags; u8 *ehs_data; u16 ehs_len; + int ehs = (hba->capabilities & MASK_EHSLUTRD_SUPPORTED) ? 2 : 0; /* Protects use of hba->reserved_slot. */ ufshcd_dev_man_lock(hba); ufshcd_setup_dev_cmd(hba, lrbp, DEV_CMD_TYPE_RPMB, UFS_UPIU_RPMB_WLUN, tag); - /* Advanced RPMB starts from UFS 4.0, so its command type is UTP_CMD_TYPE_UFS_STORAGE */ - lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; - - /* - * According to UFSHCI 4.0 specification page 24, if EHSLUTRDS is 0, host controller takes - * EHS length from CMD UPIU, and SW driver use EHS Length field in CMD UPIU. if it is 1, - * HW controller takes EHS length from UTRD. - */ - if (hba->capabilities & MASK_EHSLUTRD_SUPPORTED) - ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, dir, 2); - else - ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, dir, 0); + ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, DMA_NONE, ehs, false); /* update the task tag */ req_upiu->header.task_tag = tag;