Skip to content

Commit 56541c7

Browse files
abelvesamartinkpetersen
authored andcommitted
scsi: ufs: ufs-qcom: Switch to the new ICE API
Now that there is a new dedicated ICE driver, drop the ufs-qcom-ice and use the new ICE api provided by the Qualcomm soc driver ice. The platforms that already have ICE support will use the API as library since there will not be a devicetree node, but instead they have reg range. In this case, the of_qcom_ice_get will return an ICE instance created for the consumer's device. But if there are platforms that do not have ice reg in the consumer devicetree node and instead provide a dedicated ICE devicetree node, the of_qcom_ice_get will look up the device based on qcom,ice property and will get the ICE instance registered by the probe function of the ice driver. The ICE clock is now handle by the new driver. This is done by enabling it on the creation of the ICE instance and then enabling/disabling it on UFS runtime resume/suspend. Signed-off-by: Abel Vesa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Eric Biggers <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 29a6d12 commit 56541c7

File tree

5 files changed

+104
-277
lines changed

5 files changed

+104
-277
lines changed

drivers/ufs/host/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ config SCSI_UFS_QCOM
5959
depends on SCSI_UFSHCD_PLATFORM && ARCH_QCOM
6060
depends on GENERIC_MSI_IRQ
6161
depends on RESET_CONTROLLER
62-
select QCOM_SCM if SCSI_UFS_CRYPTO
62+
select QCOM_INLINE_CRYPTO_ENGINE if SCSI_UFS_CRYPTO
6363
help
6464
This selects the QCOM specific additions to UFSHCD platform driver.
6565
UFS host on QCOM needs some vendor specific configuration before

drivers/ufs/host/Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
obj-$(CONFIG_SCSI_UFS_DWC_TC_PCI) += tc-dwc-g210-pci.o ufshcd-dwc.o tc-dwc-g210.o
44
obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o ufshcd-dwc.o tc-dwc-g210.o
55
obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o
6-
obj-$(CONFIG_SCSI_UFS_QCOM) += ufs_qcom.o
7-
ufs_qcom-y += ufs-qcom.o
8-
ufs_qcom-$(CONFIG_SCSI_UFS_CRYPTO) += ufs-qcom-ice.o
6+
obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
97
obj-$(CONFIG_SCSI_UFS_EXYNOS) += ufs-exynos.o
108
obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
119
obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o

drivers/ufs/host/ufs-qcom-ice.c

-244
This file was deleted.

drivers/ufs/host/ufs-qcom.c

+97-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/reset-controller.h>
1616
#include <linux/devfreq.h>
1717

18+
#include <soc/qcom/ice.h>
19+
1820
#include <ufs/ufshcd.h>
1921
#include "ufshcd-pltfrm.h"
2022
#include <ufs/unipro.h>
@@ -55,6 +57,100 @@ static struct ufs_qcom_host *rcdev_to_ufs_host(struct reset_controller_dev *rcd)
5557
return container_of(rcd, struct ufs_qcom_host, rcdev);
5658
}
5759

60+
#ifdef CONFIG_SCSI_UFS_CRYPTO
61+
62+
static inline void ufs_qcom_ice_enable(struct ufs_qcom_host *host)
63+
{
64+
if (host->hba->caps & UFSHCD_CAP_CRYPTO)
65+
qcom_ice_enable(host->ice);
66+
}
67+
68+
static int ufs_qcom_ice_init(struct ufs_qcom_host *host)
69+
{
70+
struct ufs_hba *hba = host->hba;
71+
struct device *dev = hba->dev;
72+
struct qcom_ice *ice;
73+
74+
ice = of_qcom_ice_get(dev);
75+
if (ice == ERR_PTR(-EOPNOTSUPP)) {
76+
dev_warn(dev, "Disabling inline encryption support\n");
77+
ice = NULL;
78+
}
79+
80+
if (IS_ERR_OR_NULL(ice))
81+
return PTR_ERR_OR_ZERO(ice);
82+
83+
host->ice = ice;
84+
hba->caps |= UFSHCD_CAP_CRYPTO;
85+
86+
return 0;
87+
}
88+
89+
static inline int ufs_qcom_ice_resume(struct ufs_qcom_host *host)
90+
{
91+
if (host->hba->caps & UFSHCD_CAP_CRYPTO)
92+
return qcom_ice_resume(host->ice);
93+
94+
return 0;
95+
}
96+
97+
static inline int ufs_qcom_ice_suspend(struct ufs_qcom_host *host)
98+
{
99+
if (host->hba->caps & UFSHCD_CAP_CRYPTO)
100+
return qcom_ice_suspend(host->ice);
101+
102+
return 0;
103+
}
104+
105+
static int ufs_qcom_ice_program_key(struct ufs_hba *hba,
106+
const union ufs_crypto_cfg_entry *cfg,
107+
int slot)
108+
{
109+
struct ufs_qcom_host *host = ufshcd_get_variant(hba);
110+
union ufs_crypto_cap_entry cap;
111+
bool config_enable =
112+
cfg->config_enable & UFS_CRYPTO_CONFIGURATION_ENABLE;
113+
114+
/* Only AES-256-XTS has been tested so far. */
115+
cap = hba->crypto_cap_array[cfg->crypto_cap_idx];
116+
if (cap.algorithm_id != UFS_CRYPTO_ALG_AES_XTS ||
117+
cap.key_size != UFS_CRYPTO_KEY_SIZE_256)
118+
return -EINVAL;
119+
120+
if (config_enable)
121+
return qcom_ice_program_key(host->ice,
122+
QCOM_ICE_CRYPTO_ALG_AES_XTS,
123+
QCOM_ICE_CRYPTO_KEY_SIZE_256,
124+
cfg->crypto_key,
125+
cfg->data_unit_size, slot);
126+
else
127+
return qcom_ice_evict_key(host->ice, slot);
128+
}
129+
130+
#else
131+
132+
#define ufs_qcom_ice_program_key NULL
133+
134+
static inline void ufs_qcom_ice_enable(struct ufs_qcom_host *host)
135+
{
136+
}
137+
138+
static int ufs_qcom_ice_init(struct ufs_qcom_host *host)
139+
{
140+
return 0;
141+
}
142+
143+
static inline int ufs_qcom_ice_resume(struct ufs_qcom_host *host)
144+
{
145+
return 0;
146+
}
147+
148+
static inline int ufs_qcom_ice_suspend(struct ufs_qcom_host *host)
149+
{
150+
return 0;
151+
}
152+
#endif
153+
58154
static int ufs_qcom_host_clk_get(struct device *dev,
59155
const char *name, struct clk **clk_out, bool optional)
60156
{
@@ -607,7 +703,7 @@ static int ufs_qcom_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
607703
ufs_qcom_disable_lane_clks(host);
608704
}
609705

610-
return 0;
706+
return ufs_qcom_ice_suspend(host);
611707
}
612708

613709
static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
@@ -853,7 +949,6 @@ static void ufs_qcom_set_caps(struct ufs_hba *hba)
853949
hba->caps |= UFSHCD_CAP_CLK_SCALING | UFSHCD_CAP_WB_WITH_CLK_SCALING;
854950
hba->caps |= UFSHCD_CAP_AUTO_BKOPS_SUSPEND;
855951
hba->caps |= UFSHCD_CAP_WB_EN;
856-
hba->caps |= UFSHCD_CAP_CRYPTO;
857952
hba->caps |= UFSHCD_CAP_AGGR_POWER_COLLAPSE;
858953
hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND;
859954

0 commit comments

Comments
 (0)