From patchwork Wed Jul 31 12:20:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 815983 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 E2AE91AD9FF; Wed, 31 Jul 2024 12:22:18 +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=1722428540; cv=none; b=qIRc9Y9Vv4VVWdK5dPSDwGaRPtMtoCZN/xYlrgzJDJIl9/9vhfq3MEQHX3j+ODnXfbFib+WO9QpTi7F0cZCfQsRoMpQfjSnFRxxWLXPopOFnwajgSEat2mSEtIzg/uuAHu0hx60S4DjqCjHy3100SVxlSRTRqS2V6Ak3uQpW7Uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722428540; c=relaxed/simple; bh=VJVT/K2rFT2gV6I6mbycIEfIkRg62vzI6yc7jU/kF9M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h70p4g2nuiW15JiAkG9hIxEDhB68mUSSDlK50sFFG8gcfiE390SpIYja0j1467sp4hKoWuy7EIJ9Wir1cYJa69Z1XBhhQAluKOd7SGp7f4y1/zd04MAYXa0ylBp2N+jA8He1ZdD6uzGV1D7r+Nw4eFDgXPg0/fjuuk2bo0TAMaU= 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=oNGt8+OO; 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="oNGt8+OO" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1722428538; x=1753964538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VJVT/K2rFT2gV6I6mbycIEfIkRg62vzI6yc7jU/kF9M=; b=oNGt8+OO+RITVjXHquc/yGRWhdwp0T71qVHtZN11p/dYc5Pi1uBSY9os 2SVWpKLsX0oRlaOnSEZ0NaxekfxFSkhPRmnk8JLpXd85OBBJfaovL4Ktj 4UGD0Txo88c12sSsdWcBe2cy54R7+eGTFZo2WCZKmN+MJadawYr4vh9wG G5ai7WQV1MIm5c8WA66/2XOYRvgh4lT5ljfxAYGgoqxx/p6OSPg6oEu+K TE134j7/scUUnW4G/dfis4ccNFqtjJARTqtSYl7ZY7fTGBCy75hcVp5Jz TRbaA2ud/Dxu8SZ7dHlyiFcpDoSE97fYVVLAOidOEWo039IzRqpKarnQu g==; X-CSE-ConnectionGUID: 4FphUws6SNSxk+8a7Mzvsw== X-CSE-MsgGUID: p2dJmrwqTxG+lyG9JkB/gA== X-IronPort-AV: E=Sophos;i="6.09,251,1716220800"; d="scan'208";a="24150840" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 31 Jul 2024 20:22:14 +0800 IronPort-SDR: 66aa1e85_I/Te2pDSmPxVoIqxJo5fNYJHzDU+PhCW0ci0bLhfxb4gF1L yUkZV+ijHFVg5fbD9jNpLpfwpTwk03Q8Qa12ttQ== 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; 31 Jul 2024 04:22:45 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 31 Jul 2024 05:22:13 -0700 From: Avri Altman To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH 1/2] scsi: ufs: Prepare to add HCI capabilities sysfs Date: Wed, 31 Jul 2024 15:20:50 +0300 Message-Id: <20240731122051.2058406-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240731122051.2058406-1-avri.altman@wdc.com> References: <20240731122051.2058406-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 Prepare so we'll be able to read various other HCI registers. While at it, fix the HCPID & HCMID register names to stand for what they really are. Signed-off-by: Avri Altman --- drivers/ufs/core/ufs-sysfs.c | 38 +++++++++++++++++++++--------------- include/ufs/ufshci.h | 5 +++-- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c index e80a32421a8c..7a264f8ef140 100644 --- a/drivers/ufs/core/ufs-sysfs.c +++ b/drivers/ufs/core/ufs-sysfs.c @@ -198,33 +198,39 @@ static u32 ufshcd_us_to_ahit(unsigned int timer) FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, scale); } -static ssize_t auto_hibern8_show(struct device *dev, - struct device_attribute *attr, char *buf) +static int ufshcd_read_hci_reg(struct ufs_hba *hba, u32 *val, unsigned int reg) { - u32 ahit; - int ret; - struct ufs_hba *hba = dev_get_drvdata(dev); - - if (!ufshcd_is_auto_hibern8_supported(hba)) - return -EOPNOTSUPP; - down(&hba->host_sem); if (!ufshcd_is_user_access_allowed(hba)) { - ret = -EBUSY; - goto out; + up(&hba->host_sem); + return -EBUSY; } pm_runtime_get_sync(hba->dev); ufshcd_hold(hba); - ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER); + *val = ufshcd_readl(hba, reg); ufshcd_release(hba); pm_runtime_put_sync(hba->dev); - ret = sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit)); - -out: up(&hba->host_sem); - return ret; + return 0; +} + +static ssize_t auto_hibern8_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u32 ahit; + int ret; + struct ufs_hba *hba = dev_get_drvdata(dev); + + if (!ufshcd_is_auto_hibern8_supported(hba)) + return -EOPNOTSUPP; + + ret = ufshcd_read_hci_reg(hba, &ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); + if (ret) + return ret; + + return sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit)); } static ssize_t auto_hibern8_store(struct device *dev, diff --git a/include/ufs/ufshci.h b/include/ufs/ufshci.h index 38fe97971a65..194e3655902e 100644 --- a/include/ufs/ufshci.h +++ b/include/ufs/ufshci.h @@ -25,8 +25,9 @@ enum { REG_CONTROLLER_CAPABILITIES = 0x00, REG_MCQCAP = 0x04, REG_UFS_VERSION = 0x08, - REG_CONTROLLER_DEV_ID = 0x10, - REG_CONTROLLER_PROD_ID = 0x14, + REG_EXT_CONTROLLER_CAPABILITIES = 0x0C, + REG_CONTROLLER_PID = 0x10, + REG_CONTROLLER_MID = 0x14, REG_AUTO_HIBERNATE_IDLE_TIMER = 0x18, REG_INTERRUPT_STATUS = 0x20, REG_INTERRUPT_ENABLE = 0x24, From patchwork Wed Jul 31 12:20:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 816192 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 116CA1B0111; Wed, 31 Jul 2024 12:22:20 +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=1722428541; cv=none; b=Oxh3JU4eCK7xhlFURcnmhZMzlOC+cZDOH50wbAyiXGxl/b91l5ACK8X7zqZM/0P5MZzlFNcICeYHMDFzuaPLInejP6uHLsovhJg8dMKEIrClTh3fsFSxN4iRZTC8mgz1R9o0cfvOsxQa4NtkrY1TMSzwU3AwZNzENBtD83HYuJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722428541; c=relaxed/simple; bh=zYXPutPkojh64QN6h2f7s9rj66jDFKJuMW5LLhTwP58=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dzp1meOd2Cc1fa9XwjWNY0D9Lu6DFa413x/47qi3/0k1dK9kUpLSGRjmg/qZ9PdrxCXH8wr7Nt8x6VpiAwOdxYSgD4D+sZh8YvP/3GXYygs0YNixTNmOa+KTdLGljF0wh1vQYP2OKbrpm1hQ5gBM39tRERdYTe/I+5DPYUWdMxk= 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=X5VS8V5P; 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="X5VS8V5P" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1722428539; x=1753964539; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zYXPutPkojh64QN6h2f7s9rj66jDFKJuMW5LLhTwP58=; b=X5VS8V5P6qavfLmg99pw1rjs0205kx+CelKUAZ5CA2mHh+jt1Iqi2edA RC5FYaeqG3iR6/s6hHoj0nGNteMZVjdEtz7f+z4Xc/vaZrINssnHYdCOO aUzETRbpYbPhC+4vSuAhuU+VG9yJlZ3AQy39FjmtZlej+aC0HgrZGWbyR GLthIRx9e37VQ7zjAGkYoALJ6uVOZ9JeMwTCvSAaotrcreIZmhVqiggaU V1aM0n+p3/jcy3qyx9DgLQbItUsh1rE02aVw/bzcYLAw3N7/mWERIsceA g71/LrCYoQS2w/yFtALGT+NXwv/+qUr04tE9UlR75Xxzf0tapVIASLLaj A==; X-CSE-ConnectionGUID: AIleQELqRp26Glt8PxcTqg== X-CSE-MsgGUID: NfBj7p3pQyidZ8enO5Juaw== X-IronPort-AV: E=Sophos;i="6.09,251,1716220800"; d="scan'208";a="24150851" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 31 Jul 2024 20:22:17 +0800 IronPort-SDR: 66aa1e88_F1cIb0N4fD8OkZPcfzH2lfg/gWf928bQi5lMMrw8UU26Dm4 xdlGWVdUOORFJy1c31RS9lPsxYsX942Nct0F0GQ== 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; 31 Jul 2024 04:22:48 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 31 Jul 2024 05:22:16 -0700 From: Avri Altman To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH 2/2] scsi: ufs: Add HCI capabilities sysfs group Date: Wed, 31 Jul 2024 15:20:51 +0300 Message-Id: <20240731122051.2058406-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240731122051.2058406-1-avri.altman@wdc.com> References: <20240731122051.2058406-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 The standard register map of UFSHCI is comprised of several groups. The first group (starting from offset 0x00), is the host capabilities group. It contains some interesting information, that otherwise is not available, e.g. the UFS version of the platform etc. Signed-off-by: Avri Altman --- drivers/ufs/core/ufs-sysfs.c | 95 ++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c index 7a264f8ef140..9ec3fc2f3af4 100644 --- a/drivers/ufs/core/ufs-sysfs.c +++ b/drivers/ufs/core/ufs-sysfs.c @@ -525,6 +525,100 @@ static const struct attribute_group ufs_sysfs_capabilities_group = { .attrs = ufs_sysfs_capabilities_attrs, }; +static ssize_t capabilities_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + + return sysfs_emit(buf, "0x%x\n", hba->capabilities); +} + +static ssize_t mcq_cap_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + + if (hba->ufs_version < ufshci_version(4, 0)) + return -EOPNOTSUPP; + + return sysfs_emit(buf, "0x%x\n", hba->mcq_capabilities); +} + +static ssize_t version_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + + return sysfs_emit(buf, "0x%x\n", hba->ufs_version); +} + +static ssize_t ext_capabilities_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int ret; + u32 val; + struct ufs_hba *hba = dev_get_drvdata(dev); + + if (hba->ufs_version < ufshci_version(4, 0)) + return -EOPNOTSUPP; + + ret = ufshcd_read_hci_reg(hba, &val, REG_EXT_CONTROLLER_CAPABILITIES); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%x\n", val); +} + +static ssize_t product_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int ret; + u32 val; + struct ufs_hba *hba = dev_get_drvdata(dev); + + ret = ufshcd_read_hci_reg(hba, &val, REG_CONTROLLER_PID); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%x\n", val); +} + +static ssize_t man_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int ret; + u32 val; + struct ufs_hba *hba = dev_get_drvdata(dev); + + ret = ufshcd_read_hci_reg(hba, &val, REG_CONTROLLER_MID); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%x\n", val); +} + +static DEVICE_ATTR_RO(capabilities); +static DEVICE_ATTR_RO(mcq_cap); +static DEVICE_ATTR_RO(version); +static DEVICE_ATTR_RO(ext_capabilities); +static DEVICE_ATTR_RO(product_id); +static DEVICE_ATTR_RO(man_id); + +static struct attribute *ufs_sysfs_ufshci_cap_attrs[] = { + &dev_attr_capabilities.attr, + &dev_attr_mcq_cap.attr, + &dev_attr_version.attr, + &dev_attr_ext_capabilities.attr, + &dev_attr_product_id.attr, + &dev_attr_man_id.attr, + NULL +}; + +static const struct attribute_group ufs_sysfs_ufshci_group = { + .name = "ufshci_capabilities", + .attrs = ufs_sysfs_ufshci_cap_attrs, +}; + static ssize_t monitor_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1508,6 +1602,7 @@ static const struct attribute_group ufs_sysfs_attributes_group = { static const struct attribute_group *ufs_sysfs_groups[] = { &ufs_sysfs_default_group, &ufs_sysfs_capabilities_group, + &ufs_sysfs_ufshci_group, &ufs_sysfs_monitor_group, &ufs_sysfs_power_info_group, &ufs_sysfs_device_descriptor_group,