aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/caam/caamhash.c
diff options
context:
space:
mode:
authorVictoria Milhoan <vicki.milhoan@freescale.com>2015-08-05 14:28:48 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-08-10 11:19:04 -0400
commitbf83490ee4207de3af59b63870eb9f72f1e523f1 (patch)
treee150894338ef2e9fda858a8d35ae46570dbdffed /drivers/crypto/caam/caamhash.c
parent350cdfeba888c21341ad2989c5930a2708def579 (diff)
crypto: caam - Detect hardware features during algorithm registration
Register only algorithms supported by CAAM hardware, using the CHA version and instantiation registers to identify hardware capabilities. Signed-off-by: Victoria Milhoan <vicki.milhoan@freescale.com> Tested-by: Horia Geantă <horia.geanta@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/caam/caamhash.c')
-rw-r--r--drivers/crypto/caam/caamhash.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 16c03f84fd9a..bb0935a3817c 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1883,8 +1883,10 @@ static int __init caam_algapi_hash_init(void)
1883 struct device_node *dev_node; 1883 struct device_node *dev_node;
1884 struct platform_device *pdev; 1884 struct platform_device *pdev;
1885 struct device *ctrldev; 1885 struct device *ctrldev;
1886 void *priv;
1887 int i = 0, err = 0; 1886 int i = 0, err = 0;
1887 struct caam_drv_private *priv;
1888 unsigned int md_limit = SHA512_DIGEST_SIZE;
1889 u32 cha_inst, cha_vid;
1888 1890
1889 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); 1891 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
1890 if (!dev_node) { 1892 if (!dev_node) {
@@ -1910,19 +1912,40 @@ static int __init caam_algapi_hash_init(void)
1910 if (!priv) 1912 if (!priv)
1911 return -ENODEV; 1913 return -ENODEV;
1912 1914
1915 /*
1916 * Register crypto algorithms the device supports. First, identify
1917 * presence and attributes of MD block.
1918 */
1919 cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls);
1920 cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls);
1921
1922 /*
1923 * Skip registration of any hashing algorithms if MD block
1924 * is not present.
1925 */
1926 if (!((cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT))
1927 return -ENODEV;
1928
1929 /* Limit digest size based on LP256 */
1930 if ((cha_vid & CHA_ID_LS_MD_MASK) == CHA_ID_LS_MD_LP256)
1931 md_limit = SHA256_DIGEST_SIZE;
1932
1913 INIT_LIST_HEAD(&hash_list); 1933 INIT_LIST_HEAD(&hash_list);
1914 1934
1915 /* register crypto algorithms the device supports */ 1935 /* register crypto algorithms the device supports */
1916 for (i = 0; i < ARRAY_SIZE(driver_hash); i++) { 1936 for (i = 0; i < ARRAY_SIZE(driver_hash); i++) {
1917 /* TODO: check if h/w supports alg */
1918 struct caam_hash_alg *t_alg; 1937 struct caam_hash_alg *t_alg;
1938 struct caam_hash_template *alg = driver_hash + i;
1939
1940 /* If MD size is not supported by device, skip registration */
1941 if (alg->template_ahash.halg.digestsize > md_limit)
1942 continue;
1919 1943
1920 /* register hmac version */ 1944 /* register hmac version */
1921 t_alg = caam_hash_alloc(&driver_hash[i], true); 1945 t_alg = caam_hash_alloc(alg, true);
1922 if (IS_ERR(t_alg)) { 1946 if (IS_ERR(t_alg)) {
1923 err = PTR_ERR(t_alg); 1947 err = PTR_ERR(t_alg);
1924 pr_warn("%s alg allocation failed\n", 1948 pr_warn("%s alg allocation failed\n", alg->driver_name);
1925 driver_hash[i].driver_name);
1926 continue; 1949 continue;
1927 } 1950 }
1928 1951
@@ -1935,11 +1958,10 @@ static int __init caam_algapi_hash_init(void)
1935 list_add_tail(&t_alg->entry, &hash_list); 1958 list_add_tail(&t_alg->entry, &hash_list);
1936 1959
1937 /* register unkeyed version */ 1960 /* register unkeyed version */
1938 t_alg = caam_hash_alloc(&driver_hash[i], false); 1961 t_alg = caam_hash_alloc(alg, false);
1939 if (IS_ERR(t_alg)) { 1962 if (IS_ERR(t_alg)) {
1940 err = PTR_ERR(t_alg); 1963 err = PTR_ERR(t_alg);
1941 pr_warn("%s alg allocation failed\n", 1964 pr_warn("%s alg allocation failed\n", alg->driver_name);
1942 driver_hash[i].driver_name);
1943 continue; 1965 continue;
1944 } 1966 }
1945 1967