Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp976784lqp; Thu, 23 May 2024 06:00:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXg+gzvm+3sg79S8aEjHydfm0MktnvsCmQ7dhlx8hXx5lYD330+qvz53rj+bUEsPHCp+DYksraueWlDUj7bGbaSPnvmamhBO5LpZRK3Cg== X-Google-Smtp-Source: AGHT+IGKkuf9Gn9b3Kwn8sVkpxE2FQosdXL9Xe//LU+Hs5pQl1acudPcTfLif7KFOl01YRamVC9/ X-Received: by 2002:a17:906:31d3:b0:a5c:dd2c:d95b with SMTP id a640c23a62f3a-a623e9d5530mr167472766b.25.1716469216310; Thu, 23 May 2024 06:00:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716469216; cv=pass; d=google.com; s=arc-20160816; b=J/lgKb8tiEpLo4+p1iPuzI1GrkOS5qDeGpE38h/Imwbg/gbNimPkIDzQuIRZHLcshv 8zbAnXmiewVdrYw6h3QTJKTSgOskfjgVA+ezeILtN4P+YnQJhxkdimHkOcaFcAHivuue xjgKUSnyEFKXljumqL9NFUv5DopPtcUNsluJbSFKBRksYLVKOteDADboq3jfJ+xSSGni 5B+X6suIfdVYuuCVJaiOZMmtqQMte9QgRmFezulFopgn0ayyJvfaVyLdWnuww7DNtZYu HLPgmoFyleMaknsM4UhKhQLZYfXmJf9/fF1AcB3YNs8grNHfPuD7r1exTjqM7hdFLDSa qaBQ== 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 :dkim-signature; bh=iumwGpt4e+WNF+ZE/FAdap4KjaewlPejUdadgICQSwM=; fh=X0Lb6G6jJE8+QeYtFGxv2g5f8eI/IotqH0fFq08ifqY=; b=FEsIlubS/Wplg6fPDNE/2P0pg08tYOCqob1jTG7/2iNf3SfqpHA0lYElg3x8QZMIwG tBkoKWFitDwh3z7Ojnq5q4/j2sRW+rJEs7FthPHfceedc+4R3LeM0jy+aZDhMNN/kE65 oFJYUqYdNj46E3v/sMSIgv5YxV944mwgn2WUUJiQwhPIJ15rlEfcu7uzE+WEqAG3dHrO qrlnSG9QUVb47X540qtmaMgZI2hPotRHo912ZXHeIzXTv/BSl0ksz4HlDUdCnNm//hRl pQUAF8yJTbl2xXs2uTKV1hHkVh5Bk90NUUygvRx7b1OPuSCl0fgFBmX2qMDfWkP8LFCS gXQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=Nn+MjaOx; 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-187530-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187530-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 a640c23a62f3a-a5a1794606fsi1762292966b.190.2024.05.23.06.00.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 06:00:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187530-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=Nn+MjaOx; 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-187530-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187530-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 DE8351F21D8D for ; Thu, 23 May 2024 13:00:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75A1214D29C; Thu, 23 May 2024 12:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Nn+MjaOx" 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 9652714AD25; Thu, 23 May 2024 12:59:06 +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=1716469148; cv=none; b=QXk0rOi/E4nQdlk8vy44CdwwJ1FYd5ycR3GgZhyQ+06IpwgS7+dq9O6YXtGYvHOpbIRmrnG474CkKPQNsxawghzk5Vf4+VmC+lcumMwB4Ykk32g49wGKQd1GJzaXhJT34Ts9U7C+4AmJDefapfD7MgkeENmdagXduDzhAyNf+IU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716469148; c=relaxed/simple; bh=3HMy5/V0H521gCFEHwEoQ1S0odb/OYD88xo+TVa9M1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C8/geqt6n2xrOheAh8cqGWXH3s6/qebR9p47Yy7H1yfxWcIu4pNud4WdlvXg97WlXXZaVGlzJVEeoZS1c/25X9JNSQywakHkWqP4sT1f9Z6RfhFZFoDpBapGDgZhPsHu4y64xsZkkN7hrWyAiTVZg2bSHQYT6wHePOSgT4rEOEU= 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=Nn+MjaOx; 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 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716469146; x=1748005146; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3HMy5/V0H521gCFEHwEoQ1S0odb/OYD88xo+TVa9M1E=; b=Nn+MjaOxa1bFlkQs4ji8u/s7thvpMmIcUzYGks+x4ywdu5zoMREEGLxc vRBElHd4U5MHNJFFLF4jm9xSaPdGqTK7y+WKRCFb0cSny+R0xd1qMU/Ue Dlfzk0ISgk3mORZ9EVmUXAj+lXmmuYi1yeQ6gjBYCBI4lWRBeMj8lnA+l JqqmfJiVRx+cJFbKZpwOnh1C7IVh1/jSBiIAKcSK4vTWbjGI0vF8swMBl AxVwjKm5FsELQgUv/D625KQ25vpQPDa/U3qPgb6ep273d82458h0QE9IO QMveTzLwuTAl93tw7thHDxshaeIuTg9C7UovajlFw5ZT61JSN1dmmMPxI Q==; X-CSE-ConnectionGUID: bI+AXJepSNyAsrcrBtlNKA== X-CSE-MsgGUID: P8jlnTc/QN6TD6NpeZzPVA== X-IronPort-AV: E=Sophos;i="6.08,182,1712592000"; d="scan'208";a="16810345" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 23 May 2024 20:59:05 +0800 IronPort-SDR: 664f2ffc_jOHC+XnS10JtpFSluGVJhlhO1csq9YlqqpSszeO6wV2jwdG 4edT+by8Q4VA7H68aZG0U01G33K3mtzfhLh7Sgg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 23 May 2024 05:01:00 -0700 WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip02.wdc.com with ESMTP; 23 May 2024 05:59:04 -0700 From: Avri Altman To: "Martin K . Petersen" Cc: Bart Van Assche , Bean Huo , Peter Wang , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v5 3/3] scsi: ufs: sysfs: Make max_number_of_rtt read-write Date: Thu, 23 May 2024 15:58:26 +0300 Message-ID: <20240523125827.818-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240523125827.818-1-avri.altman@wdc.com> References: <20240523125827.818-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 Given the importance of the RTT parameter, we want to be able to configure it via sysfs. This is because UFS users should be discouraged from change UFS device parameters without the UFSHCI driver being aware of these changes. Signed-off-by: Avri Altman --- Documentation/ABI/testing/sysfs-driver-ufs | 14 +++-- drivers/ufs/core/ufs-sysfs.c | 72 +++++++++++++++++++++- drivers/ufs/core/ufshcd-priv.h | 12 ++++ drivers/ufs/core/ufshcd.c | 12 ---- 4 files changed, 91 insertions(+), 19 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs index 5bf7073b4f75..fe943ce76c60 100644 --- a/Documentation/ABI/testing/sysfs-driver-ufs +++ b/Documentation/ABI/testing/sysfs-driver-ufs @@ -920,14 +920,16 @@ Description: This file shows whether the configuration descriptor is locked. What: /sys/bus/platform/drivers/ufshcd/*/attributes/max_number_of_rtt What: /sys/bus/platform/devices/*.ufs/attributes/max_number_of_rtt -Date: February 2018 -Contact: Stanislav Nijnikov +Date: May 2024 +Contact: Avri Altman Description: This file provides the maximum current number of - outstanding RTTs in device that is allowed. The full - information about the attribute could be found at - UFS specifications 2.1. + outstanding RTTs in device that is allowed. bMaxNumOfRTT is a + read-write persistent attribute and is equal to two after device + manufacturing. It shall not be set to a value greater than + bDeviceRTTCap value, and it may be set only when the hw queues are + empty. - The file is read only. + The file is read write. What: /sys/bus/platform/drivers/ufshcd/*/attributes/exception_event_control What: /sys/bus/platform/devices/*.ufs/attributes/exception_event_control diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c index 3d049967f6bc..97fe1e9e63da 100644 --- a/drivers/ufs/core/ufs-sysfs.c +++ b/drivers/ufs/core/ufs-sysfs.c @@ -1340,6 +1340,77 @@ static const struct attribute_group ufs_sysfs_flags_group = { .attrs = ufs_sysfs_device_flags, }; +static ssize_t max_number_of_rtt_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + u32 rtt; + int ret; + + down(&hba->host_sem); + if (!ufshcd_is_user_access_allowed(hba)) { + up(&hba->host_sem); + return -EBUSY; + } + + ufshcd_rpm_get_sync(hba); + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt); + ufshcd_rpm_put_sync(hba); + + if (ret) + goto out; + + ret = sysfs_emit(buf, "0x%08X\n", rtt); + +out: + up(&hba->host_sem); + return ret; +} + +static ssize_t max_number_of_rtt_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + struct ufs_dev_info *dev_info = &hba->dev_info; + unsigned int rtt; + int ret; + + if (kstrtouint(buf, 0, &rtt)) + return -EINVAL; + + if (rtt > dev_info->rtt_cap) { + dev_err(dev, "rtt can be at most bDeviceRTTCap\n"); + return -EINVAL; + } + + down(&hba->host_sem); + if (!ufshcd_is_user_access_allowed(hba)) { + ret = -EBUSY; + goto out; + } + + ufshcd_rpm_get_sync(hba); + + /* make sure that there are no outstanding requests when rtt is set */ + ufshcd_scsi_block_requests(hba); + blk_mq_wait_quiesce_done(&hba->host->tag_set); + + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, + QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt); + + ufshcd_scsi_unblock_requests(hba); + + ufshcd_rpm_put_sync(hba); + +out: + up(&hba->host_sem); + return ret < 0 ? ret : count; +} + +static DEVICE_ATTR_RW(max_number_of_rtt); + static inline bool ufshcd_is_wb_attrs(enum attr_idn idn) { return idn >= QUERY_ATTR_IDN_WB_FLUSH_STATUS && @@ -1387,7 +1458,6 @@ UFS_ATTRIBUTE(max_data_in_size, _MAX_DATA_IN); UFS_ATTRIBUTE(max_data_out_size, _MAX_DATA_OUT); UFS_ATTRIBUTE(reference_clock_frequency, _REF_CLK_FREQ); UFS_ATTRIBUTE(configuration_descriptor_lock, _CONF_DESC_LOCK); -UFS_ATTRIBUTE(max_number_of_rtt, _MAX_NUM_OF_RTT); UFS_ATTRIBUTE(exception_event_control, _EE_CONTROL); UFS_ATTRIBUTE(exception_event_status, _EE_STATUS); UFS_ATTRIBUTE(ffu_status, _FFU_STATUS); diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index f42d99ce5bf1..691987e2e5f5 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -32,6 +32,18 @@ static inline bool ufshcd_is_wb_buf_flush_allowed(struct ufs_hba *hba) !(hba->quirks & UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL); } +static inline void ufshcd_scsi_unblock_requests(struct ufs_hba *hba) +{ + if (atomic_dec_and_test(&hba->scsi_block_reqs_cnt)) + scsi_unblock_requests(hba->host); +} + +static inline void ufshcd_scsi_block_requests(struct ufs_hba *hba) +{ + if (atomic_inc_return(&hba->scsi_block_reqs_cnt) == 1) + scsi_block_requests(hba->host); +} + #ifdef CONFIG_SCSI_UFS_HWMON void ufs_hwmon_probe(struct ufs_hba *hba, u8 mask); void ufs_hwmon_remove(struct ufs_hba *hba); diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index d8e0e80d66a5..f470180e6efb 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -332,18 +332,6 @@ static void ufshcd_configure_wb(struct ufs_hba *hba) ufshcd_wb_toggle_buf_flush(hba, true); } -static void ufshcd_scsi_unblock_requests(struct ufs_hba *hba) -{ - if (atomic_dec_and_test(&hba->scsi_block_reqs_cnt)) - scsi_unblock_requests(hba->host); -} - -static void ufshcd_scsi_block_requests(struct ufs_hba *hba) -{ - if (atomic_inc_return(&hba->scsi_block_reqs_cnt) == 1) - scsi_block_requests(hba->host); -} - static void ufshcd_add_cmd_upiu_trace(struct ufs_hba *hba, unsigned int tag, enum ufs_trace_str_t str_t) { -- 2.34.1