aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto
diff options
context:
space:
mode:
authorRuchika Gupta <ruchika.gupta@freescale.com>2013-10-25 02:31:03 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2013-10-30 00:02:58 -0400
commitcfc6f11b768a9bdda17aac280474de1f0e344fea (patch)
tree54fdff4a8b4878c575ef85745b1dffd643c069dd /drivers/crypto
parent07defbfb0fd662272dff5207001a0a5e09aeaeec (diff)
crypto: caam - Modify the interface layers to use JR API's
- Earlier interface layers - caamalg, caamhash, caamrng were directly using the Controller driver private structure to access the Job ring. - Changed the above to use alloc/free API's provided by Job Ring Drive Signed-off-by: Ruchika Gupta <ruchika.gupta@freescale.com> Reviewed-by: Garg Vakul-B16394 <vakul@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/caam/caamalg.c92
-rw-r--r--drivers/crypto/caam/caamhash.c97
-rw-r--r--drivers/crypto/caam/caamrng.c37
-rw-r--r--drivers/crypto/caam/intern.h7
4 files changed, 55 insertions, 178 deletions
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index ad9781e646c0..4f44b71b9e24 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -86,6 +86,7 @@
86#else 86#else
87#define debug(format, arg...) 87#define debug(format, arg...)
88#endif 88#endif
89static struct list_head alg_list;
89 90
90/* Set DK bit in class 1 operation if shared */ 91/* Set DK bit in class 1 operation if shared */
91static inline void append_dec_op1(u32 *desc, u32 type) 92static inline void append_dec_op1(u32 *desc, u32 type)
@@ -2057,7 +2058,6 @@ static struct caam_alg_template driver_algs[] = {
2057 2058
2058struct caam_crypto_alg { 2059struct caam_crypto_alg {
2059 struct list_head entry; 2060 struct list_head entry;
2060 struct device *ctrldev;
2061 int class1_alg_type; 2061 int class1_alg_type;
2062 int class2_alg_type; 2062 int class2_alg_type;
2063 int alg_op; 2063 int alg_op;
@@ -2070,16 +2070,12 @@ static int caam_cra_init(struct crypto_tfm *tfm)
2070 struct caam_crypto_alg *caam_alg = 2070 struct caam_crypto_alg *caam_alg =
2071 container_of(alg, struct caam_crypto_alg, crypto_alg); 2071 container_of(alg, struct caam_crypto_alg, crypto_alg);
2072 struct caam_ctx *ctx = crypto_tfm_ctx(tfm); 2072 struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
2073 struct caam_drv_private *priv = dev_get_drvdata(caam_alg->ctrldev);
2074 struct platform_device *pdev;
2075 int tgt_jr = atomic_inc_return(&priv->tfm_count);
2076 2073
2077 /* 2074 ctx->jrdev = caam_jr_alloc();
2078 * distribute tfms across job rings to ensure in-order 2075 if (IS_ERR(ctx->jrdev)) {
2079 * crypto request processing per tfm 2076 pr_err("Job Ring Device allocation for transform failed\n");
2080 */ 2077 return PTR_ERR(ctx->jrdev);
2081 pdev = priv->jrpdev[(tgt_jr / 2) % priv->total_jobrs]; 2078 }
2082 ctx->jrdev = &pdev->dev;
2083 2079
2084 /* copy descriptor header template value */ 2080 /* copy descriptor header template value */
2085 ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam_alg->class1_alg_type; 2081 ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam_alg->class1_alg_type;
@@ -2106,44 +2102,26 @@ static void caam_cra_exit(struct crypto_tfm *tfm)
2106 dma_unmap_single(ctx->jrdev, ctx->sh_desc_givenc_dma, 2102 dma_unmap_single(ctx->jrdev, ctx->sh_desc_givenc_dma,
2107 desc_bytes(ctx->sh_desc_givenc), 2103 desc_bytes(ctx->sh_desc_givenc),
2108 DMA_TO_DEVICE); 2104 DMA_TO_DEVICE);
2105
2106 caam_jr_free(ctx->jrdev);
2109} 2107}
2110 2108
2111static void __exit caam_algapi_exit(void) 2109static void __exit caam_algapi_exit(void)
2112{ 2110{
2113 2111
2114 struct device_node *dev_node;
2115 struct platform_device *pdev;
2116 struct device *ctrldev;
2117 struct caam_drv_private *priv;
2118 struct caam_crypto_alg *t_alg, *n; 2112 struct caam_crypto_alg *t_alg, *n;
2119 2113
2120 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); 2114 if (!alg_list.next)
2121 if (!dev_node) {
2122 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
2123 if (!dev_node)
2124 return;
2125 }
2126
2127 pdev = of_find_device_by_node(dev_node);
2128 if (!pdev)
2129 return;
2130
2131 ctrldev = &pdev->dev;
2132 of_node_put(dev_node);
2133 priv = dev_get_drvdata(ctrldev);
2134
2135 if (!priv->alg_list.next)
2136 return; 2115 return;
2137 2116
2138 list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { 2117 list_for_each_entry_safe(t_alg, n, &alg_list, entry) {
2139 crypto_unregister_alg(&t_alg->crypto_alg); 2118 crypto_unregister_alg(&t_alg->crypto_alg);
2140 list_del(&t_alg->entry); 2119 list_del(&t_alg->entry);
2141 kfree(t_alg); 2120 kfree(t_alg);
2142 } 2121 }
2143} 2122}
2144 2123
2145static struct caam_crypto_alg *caam_alg_alloc(struct device *ctrldev, 2124static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template
2146 struct caam_alg_template
2147 *template) 2125 *template)
2148{ 2126{
2149 struct caam_crypto_alg *t_alg; 2127 struct caam_crypto_alg *t_alg;
@@ -2151,7 +2129,7 @@ static struct caam_crypto_alg *caam_alg_alloc(struct device *ctrldev,
2151 2129
2152 t_alg = kzalloc(sizeof(struct caam_crypto_alg), GFP_KERNEL); 2130 t_alg = kzalloc(sizeof(struct caam_crypto_alg), GFP_KERNEL);
2153 if (!t_alg) { 2131 if (!t_alg) {
2154 dev_err(ctrldev, "failed to allocate t_alg\n"); 2132 pr_err("failed to allocate t_alg\n");
2155 return ERR_PTR(-ENOMEM); 2133 return ERR_PTR(-ENOMEM);
2156 } 2134 }
2157 2135
@@ -2183,69 +2161,39 @@ static struct caam_crypto_alg *caam_alg_alloc(struct device *ctrldev,
2183 t_alg->class1_alg_type = template->class1_alg_type; 2161 t_alg->class1_alg_type = template->class1_alg_type;
2184 t_alg->class2_alg_type = template->class2_alg_type; 2162 t_alg->class2_alg_type = template->class2_alg_type;
2185 t_alg->alg_op = template->alg_op; 2163 t_alg->alg_op = template->alg_op;
2186 t_alg->ctrldev = ctrldev;
2187 2164
2188 return t_alg; 2165 return t_alg;
2189} 2166}
2190 2167
2191static int __init caam_algapi_init(void) 2168static int __init caam_algapi_init(void)
2192{ 2169{
2193 struct device_node *dev_node;
2194 struct platform_device *pdev;
2195 struct device *ctrldev;
2196 struct caam_drv_private *priv;
2197 int i = 0, err = 0; 2170 int i = 0, err = 0;
2198 2171
2199 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); 2172 INIT_LIST_HEAD(&alg_list);
2200 if (!dev_node) {
2201 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
2202 if (!dev_node)
2203 return -ENODEV;
2204 }
2205
2206 pdev = of_find_device_by_node(dev_node);
2207 if (!pdev)
2208 return -ENODEV;
2209
2210 ctrldev = &pdev->dev;
2211 priv = dev_get_drvdata(ctrldev);
2212 of_node_put(dev_node);
2213
2214 /*
2215 * If priv is NULL, it's probably because the caam driver wasn't
2216 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
2217 */
2218 if (!priv)
2219 return -ENODEV;
2220
2221 INIT_LIST_HEAD(&priv->alg_list);
2222
2223 atomic_set(&priv->tfm_count, -1);
2224 2173
2225 /* register crypto algorithms the device supports */ 2174 /* register crypto algorithms the device supports */
2226 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { 2175 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
2227 /* TODO: check if h/w supports alg */ 2176 /* TODO: check if h/w supports alg */
2228 struct caam_crypto_alg *t_alg; 2177 struct caam_crypto_alg *t_alg;
2229 2178
2230 t_alg = caam_alg_alloc(ctrldev, &driver_algs[i]); 2179 t_alg = caam_alg_alloc(&driver_algs[i]);
2231 if (IS_ERR(t_alg)) { 2180 if (IS_ERR(t_alg)) {
2232 err = PTR_ERR(t_alg); 2181 err = PTR_ERR(t_alg);
2233 dev_warn(ctrldev, "%s alg allocation failed\n", 2182 pr_warn("%s alg allocation failed\n",
2234 driver_algs[i].driver_name); 2183 driver_algs[i].driver_name);
2235 continue; 2184 continue;
2236 } 2185 }
2237 2186
2238 err = crypto_register_alg(&t_alg->crypto_alg); 2187 err = crypto_register_alg(&t_alg->crypto_alg);
2239 if (err) { 2188 if (err) {
2240 dev_warn(ctrldev, "%s alg registration failed\n", 2189 pr_warn("%s alg registration failed\n",
2241 t_alg->crypto_alg.cra_driver_name); 2190 t_alg->crypto_alg.cra_driver_name);
2242 kfree(t_alg); 2191 kfree(t_alg);
2243 } else 2192 } else
2244 list_add_tail(&t_alg->entry, &priv->alg_list); 2193 list_add_tail(&t_alg->entry, &alg_list);
2245 } 2194 }
2246 if (!list_empty(&priv->alg_list)) 2195 if (!list_empty(&alg_list))
2247 dev_info(ctrldev, "%s algorithms registered in /proc/crypto\n", 2196 pr_info("caam algorithms registered in /proc/crypto\n");
2248 (char *)of_get_property(dev_node, "compatible", NULL));
2249 2197
2250 return err; 2198 return err;
2251} 2199}
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 91a93541ed7f..0378328f47a7 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -94,6 +94,9 @@
94#define debug(format, arg...) 94#define debug(format, arg...)
95#endif 95#endif
96 96
97
98static struct list_head hash_list;
99
97/* ahash per-session context */ 100/* ahash per-session context */
98struct caam_hash_ctx { 101struct caam_hash_ctx {
99 struct device *jrdev; 102 struct device *jrdev;
@@ -1653,7 +1656,6 @@ static struct caam_hash_template driver_hash[] = {
1653 1656
1654struct caam_hash_alg { 1657struct caam_hash_alg {
1655 struct list_head entry; 1658 struct list_head entry;
1656 struct device *ctrldev;
1657 int alg_type; 1659 int alg_type;
1658 int alg_op; 1660 int alg_op;
1659 struct ahash_alg ahash_alg; 1661 struct ahash_alg ahash_alg;
@@ -1670,7 +1672,6 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
1670 struct caam_hash_alg *caam_hash = 1672 struct caam_hash_alg *caam_hash =
1671 container_of(alg, struct caam_hash_alg, ahash_alg); 1673 container_of(alg, struct caam_hash_alg, ahash_alg);
1672 struct caam_hash_ctx *ctx = crypto_tfm_ctx(tfm); 1674 struct caam_hash_ctx *ctx = crypto_tfm_ctx(tfm);
1673 struct caam_drv_private *priv = dev_get_drvdata(caam_hash->ctrldev);
1674 /* Sizes for MDHA running digests: MD5, SHA1, 224, 256, 384, 512 */ 1675 /* Sizes for MDHA running digests: MD5, SHA1, 224, 256, 384, 512 */
1675 static const u8 runninglen[] = { HASH_MSG_LEN + MD5_DIGEST_SIZE, 1676 static const u8 runninglen[] = { HASH_MSG_LEN + MD5_DIGEST_SIZE,
1676 HASH_MSG_LEN + SHA1_DIGEST_SIZE, 1677 HASH_MSG_LEN + SHA1_DIGEST_SIZE,
@@ -1678,17 +1679,17 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
1678 HASH_MSG_LEN + SHA256_DIGEST_SIZE, 1679 HASH_MSG_LEN + SHA256_DIGEST_SIZE,
1679 HASH_MSG_LEN + 64, 1680 HASH_MSG_LEN + 64,
1680 HASH_MSG_LEN + SHA512_DIGEST_SIZE }; 1681 HASH_MSG_LEN + SHA512_DIGEST_SIZE };
1681 int tgt_jr = atomic_inc_return(&priv->tfm_count);
1682 int ret = 0; 1682 int ret = 0;
1683 struct platform_device *pdev;
1684 1683
1685 /* 1684 /*
1686 * distribute tfms across job rings to ensure in-order 1685 * Get a Job ring from Job Ring driver to ensure in-order
1687 * crypto request processing per tfm 1686 * crypto request processing per tfm
1688 */ 1687 */
1689 pdev = priv->jrpdev[tgt_jr % priv->total_jobrs]; 1688 ctx->jrdev = caam_jr_alloc();
1690 ctx->jrdev = &pdev->dev; 1689 if (IS_ERR(ctx->jrdev)) {
1691 1690 pr_err("Job Ring Device allocation for transform failed\n");
1691 return PTR_ERR(ctx->jrdev);
1692 }
1692 /* copy descriptor header template value */ 1693 /* copy descriptor header template value */
1693 ctx->alg_type = OP_TYPE_CLASS2_ALG | caam_hash->alg_type; 1694 ctx->alg_type = OP_TYPE_CLASS2_ALG | caam_hash->alg_type;
1694 ctx->alg_op = OP_TYPE_CLASS2_ALG | caam_hash->alg_op; 1695 ctx->alg_op = OP_TYPE_CLASS2_ALG | caam_hash->alg_op;
@@ -1731,35 +1732,18 @@ static void caam_hash_cra_exit(struct crypto_tfm *tfm)
1731 !dma_mapping_error(ctx->jrdev, ctx->sh_desc_finup_dma)) 1732 !dma_mapping_error(ctx->jrdev, ctx->sh_desc_finup_dma))
1732 dma_unmap_single(ctx->jrdev, ctx->sh_desc_finup_dma, 1733 dma_unmap_single(ctx->jrdev, ctx->sh_desc_finup_dma,
1733 desc_bytes(ctx->sh_desc_finup), DMA_TO_DEVICE); 1734 desc_bytes(ctx->sh_desc_finup), DMA_TO_DEVICE);
1735
1736 caam_jr_free(ctx->jrdev);
1734} 1737}
1735 1738
1736static void __exit caam_algapi_hash_exit(void) 1739static void __exit caam_algapi_hash_exit(void)
1737{ 1740{
1738 struct device_node *dev_node;
1739 struct platform_device *pdev;
1740 struct device *ctrldev;
1741 struct caam_drv_private *priv;
1742 struct caam_hash_alg *t_alg, *n; 1741 struct caam_hash_alg *t_alg, *n;
1743 1742
1744 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); 1743 if (!hash_list.next)
1745 if (!dev_node) {
1746 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
1747 if (!dev_node)
1748 return;
1749 }
1750
1751 pdev = of_find_device_by_node(dev_node);
1752 if (!pdev)
1753 return;
1754
1755 ctrldev = &pdev->dev;
1756 of_node_put(dev_node);
1757 priv = dev_get_drvdata(ctrldev);
1758
1759 if (!priv->hash_list.next)
1760 return; 1744 return;
1761 1745
1762 list_for_each_entry_safe(t_alg, n, &priv->hash_list, entry) { 1746 list_for_each_entry_safe(t_alg, n, &hash_list, entry) {
1763 crypto_unregister_ahash(&t_alg->ahash_alg); 1747 crypto_unregister_ahash(&t_alg->ahash_alg);
1764 list_del(&t_alg->entry); 1748 list_del(&t_alg->entry);
1765 kfree(t_alg); 1749 kfree(t_alg);
@@ -1767,7 +1751,7 @@ static void __exit caam_algapi_hash_exit(void)
1767} 1751}
1768 1752
1769static struct caam_hash_alg * 1753static struct caam_hash_alg *
1770caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template, 1754caam_hash_alloc(struct caam_hash_template *template,
1771 bool keyed) 1755 bool keyed)
1772{ 1756{
1773 struct caam_hash_alg *t_alg; 1757 struct caam_hash_alg *t_alg;
@@ -1776,7 +1760,7 @@ caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template,
1776 1760
1777 t_alg = kzalloc(sizeof(struct caam_hash_alg), GFP_KERNEL); 1761 t_alg = kzalloc(sizeof(struct caam_hash_alg), GFP_KERNEL);
1778 if (!t_alg) { 1762 if (!t_alg) {
1779 dev_err(ctrldev, "failed to allocate t_alg\n"); 1763 pr_err("failed to allocate t_alg\n");
1780 return ERR_PTR(-ENOMEM); 1764 return ERR_PTR(-ENOMEM);
1781 } 1765 }
1782 1766
@@ -1807,44 +1791,15 @@ caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template,
1807 1791
1808 t_alg->alg_type = template->alg_type; 1792 t_alg->alg_type = template->alg_type;
1809 t_alg->alg_op = template->alg_op; 1793 t_alg->alg_op = template->alg_op;
1810 t_alg->ctrldev = ctrldev;
1811 1794
1812 return t_alg; 1795 return t_alg;
1813} 1796}
1814 1797
1815static int __init caam_algapi_hash_init(void) 1798static int __init caam_algapi_hash_init(void)
1816{ 1799{
1817 struct device_node *dev_node;
1818 struct platform_device *pdev;
1819 struct device *ctrldev;
1820 struct caam_drv_private *priv;
1821 int i = 0, err = 0; 1800 int i = 0, err = 0;
1822 1801
1823 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); 1802 INIT_LIST_HEAD(&hash_list);
1824 if (!dev_node) {
1825 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
1826 if (!dev_node)
1827 return -ENODEV;
1828 }
1829
1830 pdev = of_find_device_by_node(dev_node);
1831 if (!pdev)
1832 return -ENODEV;
1833
1834 ctrldev = &pdev->dev;
1835 priv = dev_get_drvdata(ctrldev);
1836 of_node_put(dev_node);
1837
1838 /*
1839 * If priv is NULL, it's probably because the caam driver wasn't
1840 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
1841 */
1842 if (!priv)
1843 return -ENODEV;
1844
1845 INIT_LIST_HEAD(&priv->hash_list);
1846
1847 atomic_set(&priv->tfm_count, -1);
1848 1803
1849 /* register crypto algorithms the device supports */ 1804 /* register crypto algorithms the device supports */
1850 for (i = 0; i < ARRAY_SIZE(driver_hash); i++) { 1805 for (i = 0; i < ARRAY_SIZE(driver_hash); i++) {
@@ -1852,38 +1807,38 @@ static int __init caam_algapi_hash_init(void)
1852 struct caam_hash_alg *t_alg; 1807 struct caam_hash_alg *t_alg;
1853 1808
1854 /* register hmac version */ 1809 /* register hmac version */
1855 t_alg = caam_hash_alloc(ctrldev, &driver_hash[i], true); 1810 t_alg = caam_hash_alloc(&driver_hash[i], true);
1856 if (IS_ERR(t_alg)) { 1811 if (IS_ERR(t_alg)) {
1857 err = PTR_ERR(t_alg); 1812 err = PTR_ERR(t_alg);
1858 dev_warn(ctrldev, "%s alg allocation failed\n", 1813 pr_warn("%s alg allocation failed\n",
1859 driver_hash[i].driver_name); 1814 driver_hash[i].driver_name);
1860 continue; 1815 continue;
1861 } 1816 }
1862 1817
1863 err = crypto_register_ahash(&t_alg->ahash_alg); 1818 err = crypto_register_ahash(&t_alg->ahash_alg);
1864 if (err) { 1819 if (err) {
1865 dev_warn(ctrldev, "%s alg registration failed\n", 1820 pr_warn("%s alg registration failed\n",
1866 t_alg->ahash_alg.halg.base.cra_driver_name); 1821 t_alg->ahash_alg.halg.base.cra_driver_name);
1867 kfree(t_alg); 1822 kfree(t_alg);
1868 } else 1823 } else
1869 list_add_tail(&t_alg->entry, &priv->hash_list); 1824 list_add_tail(&t_alg->entry, &hash_list);
1870 1825
1871 /* register unkeyed version */ 1826 /* register unkeyed version */
1872 t_alg = caam_hash_alloc(ctrldev, &driver_hash[i], false); 1827 t_alg = caam_hash_alloc(&driver_hash[i], false);
1873 if (IS_ERR(t_alg)) { 1828 if (IS_ERR(t_alg)) {
1874 err = PTR_ERR(t_alg); 1829 err = PTR_ERR(t_alg);
1875 dev_warn(ctrldev, "%s alg allocation failed\n", 1830 pr_warn("%s alg allocation failed\n",
1876 driver_hash[i].driver_name); 1831 driver_hash[i].driver_name);
1877 continue; 1832 continue;
1878 } 1833 }
1879 1834
1880 err = crypto_register_ahash(&t_alg->ahash_alg); 1835 err = crypto_register_ahash(&t_alg->ahash_alg);
1881 if (err) { 1836 if (err) {
1882 dev_warn(ctrldev, "%s alg registration failed\n", 1837 pr_warn("%s alg registration failed\n",
1883 t_alg->ahash_alg.halg.base.cra_driver_name); 1838 t_alg->ahash_alg.halg.base.cra_driver_name);
1884 kfree(t_alg); 1839 kfree(t_alg);
1885 } else 1840 } else
1886 list_add_tail(&t_alg->entry, &priv->hash_list); 1841 list_add_tail(&t_alg->entry, &hash_list);
1887 } 1842 }
1888 1843
1889 return err; 1844 return err;
diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index 4e4ed155c5be..28486b19fc36 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -273,42 +273,23 @@ static struct hwrng caam_rng = {
273 273
274static void __exit caam_rng_exit(void) 274static void __exit caam_rng_exit(void)
275{ 275{
276 caam_jr_free(rng_ctx.jrdev);
276 hwrng_unregister(&caam_rng); 277 hwrng_unregister(&caam_rng);
277} 278}
278 279
279static int __init caam_rng_init(void) 280static int __init caam_rng_init(void)
280{ 281{
281 struct device_node *dev_node; 282 struct device *dev;
282 struct platform_device *pdev, *jrpdev;
283 struct device *ctrldev;
284 struct caam_drv_private *priv;
285
286 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
287 if (!dev_node) {
288 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
289 if (!dev_node)
290 return -ENODEV;
291 }
292
293 pdev = of_find_device_by_node(dev_node);
294 if (!pdev)
295 return -ENODEV;
296 283
297 ctrldev = &pdev->dev; 284 dev = caam_jr_alloc();
298 priv = dev_get_drvdata(ctrldev); 285 if (IS_ERR(dev)) {
299 of_node_put(dev_node); 286 pr_err("Job Ring Device allocation for transform failed\n");
300 287 return PTR_ERR(dev);
301 /* 288 }
302 * If priv is NULL, it's probably because the caam driver wasn't
303 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
304 */
305 if (!priv)
306 return -ENODEV;
307 289
308 jrpdev = priv->jrpdev[0]; 290 caam_init_rng(&rng_ctx, dev);
309 caam_init_rng(&rng_ctx, &jrpdev->dev);
310 291
311 dev_info(&jrpdev->dev, "registering rng-caam\n"); 292 dev_info(dev, "registering rng-caam\n");
312 return hwrng_register(&caam_rng); 293 return hwrng_register(&caam_rng);
313} 294}
314 295
diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h
index b781445d2fcc..6d85fcc5bd0a 100644
--- a/drivers/crypto/caam/intern.h
+++ b/drivers/crypto/caam/intern.h
@@ -83,13 +83,6 @@ struct caam_drv_private {
83 u8 qi_present; /* Nonzero if QI present in device */ 83 u8 qi_present; /* Nonzero if QI present in device */
84 int secvio_irq; /* Security violation interrupt number */ 84 int secvio_irq; /* Security violation interrupt number */
85 85
86 /* which jr allocated to scatterlist crypto */
87 atomic_t tfm_count ____cacheline_aligned;
88 /* list of registered crypto algorithms (mk generic context handle?) */
89 struct list_head alg_list;
90 /* list of registered hash algorithms (mk generic context handle?) */
91 struct list_head hash_list;
92
93#define RNG4_MAX_HANDLES 2 86#define RNG4_MAX_HANDLES 2
94 /* RNG4 block */ 87 /* RNG4 block */
95 u32 rng4_sh_init; /* This bitmap shows which of the State 88 u32 rng4_sh_init; /* This bitmap shows which of the State