Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1335379lqb; Thu, 30 May 2024 07:26:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLXQJxcvlEKbP3POVBWP97+6Sy+PFgfJ6c14NvmYxiQv3DdDKcFjI5AbRm7+zJdOtJ7VMAZusWAiQZz9QIMiZPh8Rd+QEEcsDh9cNOtg== X-Google-Smtp-Source: AGHT+IHfRaQkcb7DabFWXmGd4W4HYzmY4+Cx5q2xpQ0GsfZJWW0ysgWhnHRkTI3DYDp9wxfR4lta X-Received: by 2002:a05:6102:2438:b0:48b:a1f8:8a29 with SMTP id ada2fe7eead31-48bae9f0843mr2223869137.9.1717079198335; Thu, 30 May 2024 07:26:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717079198; cv=pass; d=google.com; s=arc-20160816; b=FaBAj+q30TSe4UCnNwQTQcQMywdZM3pN/l2QI7kByPFHVx6oR1TmaOP/boeZFler+N zCvzCLJ9MeD3m4BH9Vx9HRb6YeSMrD+5T6w8B/ar+v8KsshPK5Bs4/VhUhopKdSxDnuC QRHfEH1+deCZwFZGFGXgi8PZQHYMO9nsXH87OWVMClq07Yor6PsDnZkjMxdW8Rhoi4O3 Wh6ZrYLvM6VXxX75vo/rU020FafCVr8lgSXVsGJqDdkj2SAhsa09dDNCqY6t+ZC/UIrb nantXqyDEmhORGd3i3sbwjHaxufz5OEhZE9vXHLbKptD2D3VPFx7L9SIBgvMR0Uz+fMf 43Gw== 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=//Bp4VHoBVaHUBKJtEtoCNE5SyKLmeRrbZpyP5cT+Ak=; fh=X0Lb6G6jJE8+QeYtFGxv2g5f8eI/IotqH0fFq08ifqY=; b=pSVyZxk2am/s8EE/PddU+gMkiijFFf0FFGQim/0bveFaWbix4Q/yq6bucTQg2oDlb/ +m3KD/Y1SNFJ/X0Rrr1/Wu7y5MIWE4DPuWINayXBlsvqxsIOjgEE9lS2MCz75/uFXuAC /LQmTym4KWaFQUIK46WD9DRaZ9XcPdcc3kymQ8USjahTOHajp0Z8bJvbuL9K9SqBd079 TrU+0HDtfGX2A0Dp2Q2M0DwNqJYR+/gJ5O8dIbxo7VP6sVgwW4VzHKTpYKWo6yJ8dMhA lKU0kdpBqR96mB61+zjbpq7wKhW/et9KFPzrY/MdrYaaqKrF5+tgMEsE/+HVcgcamkUj blTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=mgyk1izo; 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-195516-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195516-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-48a3a353b8asi3225794137.471.2024.05.30.07.26.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 07:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195516-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=mgyk1izo; 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-195516-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195516-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id F19691C23A8B for ; Thu, 30 May 2024 14:26:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06F0317D8B8; Thu, 30 May 2024 14:25:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="mgyk1izo" Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 DE36617CA0C; Thu, 30 May 2024 14:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717079130; cv=none; b=mJhOXN+mna+go2qG7Wm56R9i1QIqfk4v8OXbiFXo97BBg3ta0few9cnyhg/m8fuIZCj3EtChc6f8IPVr3pC/NHSxnizpj5VyPaZ4sHWZhPJaMy0y3J8Ze8ctrqxRi4v5O23zOJrD1jwKC9Z57WVMGAjEeLP3lTNJL9bKYgXOa/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717079130; c=relaxed/simple; bh=Be0e/vNxgm3ptlT7UnPrSlYrs+tflE84SuIM05UQEE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JUlvK6KpqQpZNUETKe+ux25JSW6dM10mphguKUzaIKYG4T1GTVFZLKAhS9od6ubLwRGwmzM5BpWl+cPnUEJT26mZlUbLcw4VEYLz2OMzdtkIvf4ZQpM/s9Yar/8Jlk/zPCrsQiQ+W9uaAPoBHoR1ekMjZEw0VUVTOmNsXJzEgzs= 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=mgyk1izo; arc=none smtp.client-ip=68.232.141.245 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=1717079127; x=1748615127; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Be0e/vNxgm3ptlT7UnPrSlYrs+tflE84SuIM05UQEE8=; b=mgyk1izoxMRTzlJBRCtuDYte6YFpzU0k0GTLRP+sW+F3CVFfDW0aTBqr vx0ke26huUS+zKoV6qFMpESK9tD4AMe9Kq8vUl5wevh1DIt3cAO5myQB/ ZsSAsRvsa8F009bV383ceH4xJ+bEy13W2pJGR4KLswbVu++8mFi3AoNdV dXLrD1qb6NT+THBdXNmhxWsEL19xm9SV61WExoFSuLOs6/7oAzIKs4jWv rOOVYI44s7ClbABFvWVzDmp/T+Qp3DC0xHp07WJ5Z9HmidV5+H8dpxv/k RFk6VJPtQEGzsEmo3BPgdxZyyMg5U5LkRIQRdciTomWgKe2Ro0wOthv2V g==; X-CSE-ConnectionGUID: zpE7Bmb6RAWHp4FctYhKag== X-CSE-MsgGUID: XxvMD7hXSRqartnapI6SiA== X-IronPort-AV: E=Sophos;i="6.08,201,1712592000"; d="scan'208";a="17923531" 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; 30 May 2024 22:25:21 +0800 IronPort-SDR: 66587eab_BvYxVTzoCd4Eef1RHRPstdLjKI2CqGVdRYx048VK4DV+xA7 Kd2gsOaWBohw9bDBuunftqKvG2p0dfTZ7eEDxSQ== 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; 30 May 2024 06:27:08 -0700 WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip01.wdc.com with ESMTP; 30 May 2024 07:25:19 -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 v7 1/3] scsi: ufs: Allow RTT negotiation Date: Thu, 30 May 2024 17:25:07 +0300 Message-ID: <20240530142510.734-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240530142510.734-1-avri.altman@wdc.com> References: <20240530142510.734-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 The rtt-upiu packets precede any data-out upiu packets, thus synchronizing the data input to the device: this mostly applies to write operations, but there are other operations that requires rtt as well. There are several rules binding this rtt - data-out dialog, specifically There can be at most outstanding bMaxNumOfRTT such packets. This might have an effect on write performance (sequential write in particular), as each data-out upiu must wait for its rtt sibling. UFSHCI expects bMaxNumOfRTT to be min(bDeviceRTTCap, NORTT). However, as of today, there does not appears to be no-one who sets it: not the host controller nor the driver. It wasn't an issue up to now: bMaxNumOfRTT is set to 2 after manufacturing, and wasn't limiting the write performance. UFS4.0, and specifically gear 5 changes this, and requires the device to be more attentive. This doesn't come free - the device has to allocate more resources to that end, but the sequential write performance improvement is significant. Early measurements shows 25% gain when moving from rtt 2 to 9. Therefore, set bMaxNumOfRTT to be min(bDeviceRTTCap, NORTT) as UFSHCI expects. Signed-off-by: Avri Altman Reviewed-by: Bean Huo Reviewed-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 38 ++++++++++++++++++++++++++++++++++++++ include/ufs/ufs.h | 2 ++ include/ufs/ufshcd.h | 2 ++ include/ufs/ufshci.h | 1 + 4 files changed, 43 insertions(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 0cf07194bbe8..dda6d7e44436 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -102,6 +102,9 @@ /* Default RTC update every 10 seconds */ #define UFS_RTC_UPDATE_INTERVAL_MS (10 * MSEC_PER_SEC) +/* bMaxNumOfRTT is equal to two after device manufacturing */ +#define DEFAULT_MAX_NUM_RTT 2 + /* UFSHC 4.0 compliant HC support this mode. */ static bool use_mcq_mode = true; @@ -2405,6 +2408,8 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba) ((hba->capabilities & MASK_TASK_MANAGEMENT_REQUEST_SLOTS) >> 16) + 1; hba->reserved_slot = hba->nutrs - 1; + hba->nortt = FIELD_GET(MASK_NUMBER_OUTSTANDING_RTT, hba->capabilities) + 1; + /* Read crypto capabilities */ err = ufshcd_hba_init_crypto_capabilities(hba); if (err) { @@ -8121,6 +8126,35 @@ static void ufshcd_ext_iid_probe(struct ufs_hba *hba, u8 *desc_buf) dev_info->b_ext_iid_en = ext_iid_en; } +static void ufshcd_set_rtt(struct ufs_hba *hba) +{ + struct ufs_dev_info *dev_info = &hba->dev_info; + u32 rtt = 0; + u32 dev_rtt = 0; + + /* RTT override makes sense only for UFS-4.0 and above */ + if (dev_info->wspecversion < 0x400) + return; + + if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &dev_rtt)) { + dev_err(hba->dev, "failed reading bMaxNumOfRTT\n"); + return; + } + + /* do not override if it was already written */ + if (dev_rtt != DEFAULT_MAX_NUM_RTT) + return; + + rtt = min_t(int, dev_info->rtt_cap, hba->nortt); + if (rtt == dev_rtt) + return; + + if (ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, + QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt)) + dev_err(hba->dev, "failed writing bMaxNumOfRTT\n"); +} + void ufshcd_fixup_dev_quirks(struct ufs_hba *hba, const struct ufs_dev_quirk *fixups) { @@ -8256,6 +8290,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba) desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1]; dev_info->bqueuedepth = desc_buf[DEVICE_DESC_PARAM_Q_DPTH]; + dev_info->rtt_cap = desc_buf[DEVICE_DESC_PARAM_RTT_CAP]; + model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME]; err = ufshcd_read_string_desc(hba, model_index, @@ -8508,6 +8544,8 @@ static int ufshcd_device_params_init(struct ufs_hba *hba) goto out; } + ufshcd_set_rtt(hba); + ufshcd_get_ref_clk_gating_wait(hba); if (!ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG, diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h index b6003749bc83..853e95957c31 100644 --- a/include/ufs/ufs.h +++ b/include/ufs/ufs.h @@ -592,6 +592,8 @@ struct ufs_dev_info { enum ufs_rtc_time rtc_type; time64_t rtc_time_baseline; u32 rtc_update_period; + + u8 rtt_cap; /* bDeviceRTTCap */ }; /* diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index bad88bd91995..d74bd2d67b06 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -819,6 +819,7 @@ enum ufshcd_mcq_opr { * @capabilities: UFS Controller Capabilities * @mcq_capabilities: UFS Multi Circular Queue capabilities * @nutrs: Transfer Request Queue depth supported by controller + * @nortt - Max outstanding RTTs supported by controller * @nutmrs: Task Management Queue depth supported by controller * @reserved_slot: Used to submit device commands. Protected by @dev_cmd.lock. * @ufs_version: UFS Version to which controller complies @@ -957,6 +958,7 @@ struct ufs_hba { u32 capabilities; int nutrs; + int nortt; u32 mcq_capabilities; int nutmrs; u32 reserved_slot; diff --git a/include/ufs/ufshci.h b/include/ufs/ufshci.h index 385e1c6b8d60..c50f92bf2e1d 100644 --- a/include/ufs/ufshci.h +++ b/include/ufs/ufshci.h @@ -68,6 +68,7 @@ enum { /* Controller capability masks */ enum { MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F, + MASK_NUMBER_OUTSTANDING_RTT = 0x0000FF00, MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000, MASK_EHSLUTRD_SUPPORTED = 0x00400000, MASK_AUTO_HIBERN8_SUPPORT = 0x00800000, -- 2.34.1