Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1721265lqg; Mon, 4 Mar 2024 01:25:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXhT/SVQctAt5UMxWbCTIXlQ1GALbKLjPg4a90qMWsrQukJ6+97dea/e6XYiyiPk2VS5U3Y4s3yC4q+ht7mABbmohWbVpwRvhiaFC4dPQ== X-Google-Smtp-Source: AGHT+IFlbeiuvN+SDELWBHVr2Xp6JJcev/jMpSAli+w8o2rJlutJYtKcuuH8oOLyWpG5BUx12pzN X-Received: by 2002:a17:906:fb13:b0:a42:f801:d664 with SMTP id lz19-20020a170906fb1300b00a42f801d664mr6472698ejb.17.1709544359405; Mon, 04 Mar 2024 01:25:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709544359; cv=pass; d=google.com; s=arc-20160816; b=C3mX9HeAVf5WEbwKgeP+0/iZxHqsjQOdmtUZZKYbVA7AMvtBX00pcG8RIpmXX3vixr 7u6/Yn6temJa2c2O+WUW3oZ/yKJWGjS6RTcGWmPwRF1Vb33O3l3lp6FF2BnsalB18EZK V/XcORtaLqgE9CnqzJrFoJVL0eBiGSJ8DpGQ1LjRhnnNIqCN+674jpBGi7fTGZeVqJ00 UYiljdTqh/lsf0N6nTN4srJGpDu+MPNYj7c7nF+RDZKoA72XNPPQFqUJPdNYUWFell37 LAuLFH5QDB0PneeAx91CCUJ/exxxdiuu2flSwZKY+l6WdwnZg/5s0mcBypXQZjfCKSjT fn4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:wdcironportexception:ironport-sdr :ironport-sdr:dkim-signature; bh=W1pTrXil1Ol7ONiXolZEdelaH4V0zlP4UI8a0dBzLz8=; fh=lbnuh9Va1UwcnWxZPbjQjN30xhVZh+Gs5sSzMLG81NY=; b=tqdP3sguaHw3lSp9iNhW/IcJuykQwevihwhygqjarMg0R6a5sJOe/ddf0brSbo6IJO CkJpl7sptFARGqWkdhfFbYg8sJZNUx/fanS156sKCqz/TAnp1cTb01hbLVfbCIwrfMoH KxK/5VVzV0WEQyjxQE7P4Il5Ucq8OdzlRywzwOMLmkYn3jZVlriHufLZW6AE+0LoHJmr wmT+DlQbqQbESNIGtJaZnlWv0jy819TpcgQhLJvqrt0RdCfB+TS9I1pqoD/jXUT1hEck XtodYHWfIhzDvpnYUYzBjWfcDSHCpm2rUgAiEh0oKNZrHS7ryTzp+IFjo6K/XQzscd1E snEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=Lk8ZZ7vO; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-90312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a9-20020a1709064a4900b00a4504198645si1381924ejv.556.2024.03.04.01.25.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 01:25:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=Lk8ZZ7vO; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-90312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F24E61F261BD for ; Mon, 4 Mar 2024 09:25:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 346E9381A0; Mon, 4 Mar 2024 09:24:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Lk8ZZ7vO" 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 266B5224E6; Mon, 4 Mar 2024 09:24:03 +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=1709544245; cv=none; b=GNsTnnI5OXRHW768EF7rD1aleO3JDRzamEQl51DJBMM9CY5BvIrMJDc1StpprT4M7+CRLM142djkKBZozhVWppIZhOhsj/pkKa4/Zz8wlco2D6ZI03gj0SuqcwrK5QN0dsk16n0Xlo2ptgufjfPSi3XSNhzfxGwroXSAaJbhfm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709544245; c=relaxed/simple; bh=KxSA6CY4fAe1QPEUfy59B02FcUbgtm0MWJDpXFmXmQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AHpwO0VZQO2U6BLE1P5B5zPqovyg5EACz8rDcersh9ZHCEMpj7Njav9lG1gb7vTTxaK/Ju0hCgD8oZfWQG7+b0JOgHky/O/B6WScC4M1MKLD1o/z27Nz759kfjcBHZHIFMxdedOTNDnqhNNz+zoWYgE+AI+7+XHv2o6u6MF4VfQ= 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=Lk8ZZ7vO; 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 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1709544243; x=1741080243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KxSA6CY4fAe1QPEUfy59B02FcUbgtm0MWJDpXFmXmQ4=; b=Lk8ZZ7vOeJAKeJjos5D+v2eLas5ZMLFi5gZBulOvxcYdIgjKiLOLs+tt GnAyKdCFoNAv2T3eXXoBkS4TfKeMUK/A14G8ZKFNCfFf9TbAw+/veQX0u H4QQ+yZUykPFG7Xgx4mvyLt9/ycJ4eWHp8a87eqltFtfNCtf9DadvzfzL KdU2Ra41HhoMhR+gscdVXtsSnrTKBWUVPalUaey9yVwh22how8vj+qD2E nZRW3i/mBwnwWyziTqzZKSs9joA5iiWq3DWuaIZSc7dpZsDwBC6K/RLwZ QnMuEfKJpZyNjohBxdo2a/UqdFkqbGtn2flLuLctM4Zo5omVGJw1j4TB7 w==; X-CSE-ConnectionGUID: nf9Aw35fTSy1Ik8jqPmviA== X-CSE-MsgGUID: miUSt343RA2tuOovQYifCQ== X-IronPort-AV: E=Sophos;i="6.06,203,1705334400"; d="scan'208";a="11326496" 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; 04 Mar 2024 17:24:02 +0800 IronPort-SDR: fXBrP+xcueaKucUNwlfE86aKYf1g2CiZQh1THpK0YZ8DqFXFXDNP1j8j8m4ewI5eRxjjrdaa8f 8eLOha0fLhwA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Mar 2024 00:33:15 -0800 IronPort-SDR: yYw8TOOEC6u6sDlKfOZjDUPiJuPoFRtXjMdfM2Z5x9+FOxxIfwdfH7gXP4yA7iM2pk1Y5FIzzv PWJDdnGVvbzg== WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Mar 2024 01:24:00 -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 1/4] scsi: ufs: Re-use device management locking code Date: Mon, 4 Mar 2024 11:23:43 +0200 Message-ID: <20240304092346.654-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240304092346.654-1-avri.altman@wdc.com> References: <20240304092346.654-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Group those 3 calls that repeat for every device management command into a lock and unlock handlers. Signed-off-by: Avri Altman --- drivers/ufs/core/ufshcd.c | 75 +++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 21429eec1b82..7456f046e7de 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 @@ -3291,11 +3305,6 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp; int err; - /* 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 +3321,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 +3391,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 +3434,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 +3464,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 +3495,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 +3558,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 +3592,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 +5073,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 +5084,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); @@ -7206,11 +7209,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, int err = 0; u8 upiu_flags; - /* 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 +7273,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 +7311,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 +7375,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 +7441,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 +8705,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 +8723,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); } /** -- 2.42.0