@@ -1807,12 +1807,19 @@ static void sdhci_msm_set_clock(struct sdhci_host *host, unsigned int clock)
1807
1807
1808
1808
#ifdef CONFIG_MMC_CRYPTO
1809
1809
1810
+ static const struct blk_crypto_ll_ops sdhci_msm_crypto_ops ; /* forward decl */
1811
+
1810
1812
static int sdhci_msm_ice_init (struct sdhci_msm_host * msm_host ,
1811
1813
struct cqhci_host * cq_host )
1812
1814
{
1813
1815
struct mmc_host * mmc = msm_host -> mmc ;
1816
+ struct blk_crypto_profile * profile = & mmc -> crypto_profile ;
1814
1817
struct device * dev = mmc_dev (mmc );
1815
1818
struct qcom_ice * ice ;
1819
+ union cqhci_crypto_capabilities caps ;
1820
+ union cqhci_crypto_cap_entry cap ;
1821
+ int err ;
1822
+ int i ;
1816
1823
1817
1824
if (!(cqhci_readl (cq_host , CQHCI_CAP ) & CQHCI_CAP_CS ))
1818
1825
return 0 ;
@@ -1827,8 +1834,37 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
1827
1834
return PTR_ERR_OR_ZERO (ice );
1828
1835
1829
1836
msm_host -> ice = ice ;
1830
- mmc -> caps2 |= MMC_CAP2_CRYPTO ;
1831
1837
1838
+ /* Initialize the blk_crypto_profile */
1839
+
1840
+ caps .reg_val = cpu_to_le32 (cqhci_readl (cq_host , CQHCI_CCAP ));
1841
+
1842
+ /* The number of keyslots supported is (CFGC+1) */
1843
+ err = devm_blk_crypto_profile_init (dev , profile , caps .config_count + 1 );
1844
+ if (err )
1845
+ return err ;
1846
+
1847
+ profile -> ll_ops = sdhci_msm_crypto_ops ;
1848
+ profile -> max_dun_bytes_supported = 4 ;
1849
+ profile -> dev = dev ;
1850
+
1851
+ /*
1852
+ * Currently this driver only supports AES-256-XTS. All known versions
1853
+ * of ICE support it, but to be safe make sure it is really declared in
1854
+ * the crypto capability registers. The crypto capability registers
1855
+ * also give the supported data unit size(s).
1856
+ */
1857
+ for (i = 0 ; i < caps .num_crypto_cap ; i ++ ) {
1858
+ cap .reg_val = cpu_to_le32 (cqhci_readl (cq_host ,
1859
+ CQHCI_CRYPTOCAP +
1860
+ i * sizeof (__le32 )));
1861
+ if (cap .algorithm_id == CQHCI_CRYPTO_ALG_AES_XTS &&
1862
+ cap .key_size == CQHCI_CRYPTO_KEY_SIZE_256 )
1863
+ profile -> modes_supported [BLK_ENCRYPTION_MODE_AES_256_XTS ] |=
1864
+ cap .sdus_mask * 512 ;
1865
+ }
1866
+
1867
+ mmc -> caps2 |= MMC_CAP2_CRYPTO ;
1832
1868
return 0 ;
1833
1869
}
1834
1870
@@ -1854,35 +1890,55 @@ static __maybe_unused int sdhci_msm_ice_suspend(struct sdhci_msm_host *msm_host)
1854
1890
return 0 ;
1855
1891
}
1856
1892
1857
- /*
1858
- * Program a key into a QC ICE keyslot, or evict a keyslot. QC ICE requires
1859
- * vendor-specific SCM calls for this; it doesn't support the standard way.
1860
- */
1861
- static int sdhci_msm_program_key (struct cqhci_host * cq_host ,
1862
- const union cqhci_crypto_cfg_entry * cfg ,
1863
- int slot )
1893
+ static inline struct sdhci_msm_host *
1894
+ sdhci_msm_host_from_crypto_profile (struct blk_crypto_profile * profile )
1864
1895
{
1865
- struct sdhci_host * host = mmc_priv (cq_host -> mmc );
1896
+ struct mmc_host * mmc = mmc_from_crypto_profile (profile );
1897
+ struct sdhci_host * host = mmc_priv (mmc );
1866
1898
struct sdhci_pltfm_host * pltfm_host = sdhci_priv (host );
1867
1899
struct sdhci_msm_host * msm_host = sdhci_pltfm_priv (pltfm_host );
1868
- union cqhci_crypto_cap_entry cap ;
1869
1900
1870
- if (!(cfg -> config_enable & CQHCI_CRYPTO_CONFIGURATION_ENABLE ))
1871
- return qcom_ice_evict_key (msm_host -> ice , slot );
1901
+ return msm_host ;
1902
+ }
1903
+
1904
+ /*
1905
+ * Program a key into a QC ICE keyslot. QC ICE requires a QC-specific SCM call
1906
+ * for this; it doesn't support the standard way.
1907
+ */
1908
+ static int sdhci_msm_ice_keyslot_program (struct blk_crypto_profile * profile ,
1909
+ const struct blk_crypto_key * key ,
1910
+ unsigned int slot )
1911
+ {
1912
+ struct sdhci_msm_host * msm_host =
1913
+ sdhci_msm_host_from_crypto_profile (profile );
1872
1914
1873
1915
/* Only AES-256-XTS has been tested so far. */
1874
- cap = cq_host -> crypto_cap_array [cfg -> crypto_cap_idx ];
1875
- if (cap .algorithm_id != CQHCI_CRYPTO_ALG_AES_XTS ||
1876
- cap .key_size != CQHCI_CRYPTO_KEY_SIZE_256 )
1877
- return - EINVAL ;
1916
+ if (key -> crypto_cfg .crypto_mode != BLK_ENCRYPTION_MODE_AES_256_XTS )
1917
+ return - EOPNOTSUPP ;
1878
1918
1879
1919
return qcom_ice_program_key (msm_host -> ice ,
1880
1920
QCOM_ICE_CRYPTO_ALG_AES_XTS ,
1881
1921
QCOM_ICE_CRYPTO_KEY_SIZE_256 ,
1882
- cfg -> crypto_key ,
1883
- cfg -> data_unit_size , slot );
1922
+ key -> raw ,
1923
+ key -> crypto_cfg .data_unit_size / 512 ,
1924
+ slot );
1884
1925
}
1885
1926
1927
+ static int sdhci_msm_ice_keyslot_evict (struct blk_crypto_profile * profile ,
1928
+ const struct blk_crypto_key * key ,
1929
+ unsigned int slot )
1930
+ {
1931
+ struct sdhci_msm_host * msm_host =
1932
+ sdhci_msm_host_from_crypto_profile (profile );
1933
+
1934
+ return qcom_ice_evict_key (msm_host -> ice , slot );
1935
+ }
1936
+
1937
+ static const struct blk_crypto_ll_ops sdhci_msm_crypto_ops = {
1938
+ .keyslot_program = sdhci_msm_ice_keyslot_program ,
1939
+ .keyslot_evict = sdhci_msm_ice_keyslot_evict ,
1940
+ };
1941
+
1886
1942
#else /* CONFIG_MMC_CRYPTO */
1887
1943
1888
1944
static inline int sdhci_msm_ice_init (struct sdhci_msm_host * msm_host ,
@@ -1988,7 +2044,7 @@ static const struct cqhci_host_ops sdhci_msm_cqhci_ops = {
1988
2044
.enable = sdhci_msm_cqe_enable ,
1989
2045
.disable = sdhci_msm_cqe_disable ,
1990
2046
#ifdef CONFIG_MMC_CRYPTO
1991
- .program_key = sdhci_msm_program_key ,
2047
+ .uses_custom_crypto_profile = true ,
1992
2048
#endif
1993
2049
};
1994
2050
0 commit comments