|
15 | 15 | #include <linux/reset-controller.h>
|
16 | 16 | #include <linux/devfreq.h>
|
17 | 17 |
|
| 18 | +#include <soc/qcom/ice.h> |
| 19 | + |
18 | 20 | #include <ufs/ufshcd.h>
|
19 | 21 | #include "ufshcd-pltfrm.h"
|
20 | 22 | #include <ufs/unipro.h>
|
@@ -55,6 +57,100 @@ static struct ufs_qcom_host *rcdev_to_ufs_host(struct reset_controller_dev *rcd)
|
55 | 57 | return container_of(rcd, struct ufs_qcom_host, rcdev);
|
56 | 58 | }
|
57 | 59 |
|
| 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 | + |
58 | 154 | static int ufs_qcom_host_clk_get(struct device *dev,
|
59 | 155 | const char *name, struct clk **clk_out, bool optional)
|
60 | 156 | {
|
@@ -607,7 +703,7 @@ static int ufs_qcom_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
|
607 | 703 | ufs_qcom_disable_lane_clks(host);
|
608 | 704 | }
|
609 | 705 |
|
610 |
| - return 0; |
| 706 | + return ufs_qcom_ice_suspend(host); |
611 | 707 | }
|
612 | 708 |
|
613 | 709 | 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)
|
853 | 949 | hba->caps |= UFSHCD_CAP_CLK_SCALING | UFSHCD_CAP_WB_WITH_CLK_SCALING;
|
854 | 950 | hba->caps |= UFSHCD_CAP_AUTO_BKOPS_SUSPEND;
|
855 | 951 | hba->caps |= UFSHCD_CAP_WB_EN;
|
856 |
| - hba->caps |= UFSHCD_CAP_CRYPTO; |
857 | 952 | hba->caps |= UFSHCD_CAP_AGGR_POWER_COLLAPSE;
|
858 | 953 | hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND;
|
859 | 954 |
|
|
0 commit comments