diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-23 19:18:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-23 19:18:25 -0500 |
commit | 26b265cd29dde56bf0901c421eabc7ae815f38c4 (patch) | |
tree | 83a5418c96ccde8522bda6614063b665fe5e0ec9 /drivers/crypto/caam/caamhash.c | |
parent | 2e7babfa892a55588467ef03b545002e32f31528 (diff) | |
parent | f262f0f5cad0c9eca61d1d383e3b67b57dcbe5ea (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto update from Herbert Xu:
- Made x86 ablk_helper generic for ARM
- Phase out chainiv in favour of eseqiv (affects IPsec)
- Fixed aes-cbc IV corruption on s390
- Added constant-time crypto_memneq which replaces memcmp
- Fixed aes-ctr in omap-aes
- Added OMAP3 ROM RNG support
- Add PRNG support for MSM SoC's
- Add and use Job Ring API in caam
- Misc fixes
[ NOTE! This pull request was sent within the merge window, but Herbert
has some questionable email sending setup that makes him public enemy
#1 as far as gmail is concerned. So most of his emails seem to be
trapped by gmail as spam, resulting in me not seeing them. - Linus ]
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (49 commits)
crypto: s390 - Fix aes-cbc IV corruption
crypto: omap-aes - Fix CTR mode counter length
crypto: omap-sham - Add missing modalias
padata: make the sequence counter an atomic_t
crypto: caam - Modify the interface layers to use JR API's
crypto: caam - Add API's to allocate/free Job Rings
crypto: caam - Add Platform driver for Job Ring
hwrng: msm - Add PRNG support for MSM SoC's
ARM: DT: msm: Add Qualcomm's PRNG driver binding document
crypto: skcipher - Use eseqiv even on UP machines
crypto: talitos - Simplify key parsing
crypto: picoxcell - Simplify and harden key parsing
crypto: ixp4xx - Simplify and harden key parsing
crypto: authencesn - Simplify key parsing
crypto: authenc - Export key parsing helper function
crypto: mv_cesa: remove deprecated IRQF_DISABLED
hwrng: OMAP3 ROM Random Number Generator support
crypto: sha256_ssse3 - also test for BMI2
crypto: mv_cesa - Remove redundant of_match_ptr
crypto: sahara - Remove redundant of_match_ptr
...
Diffstat (limited to 'drivers/crypto/caam/caamhash.c')
-rw-r--r-- | drivers/crypto/caam/caamhash.c | 88 |
1 files changed, 26 insertions, 62 deletions
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index e732bd962e98..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 | |||
98 | static struct list_head hash_list; | ||
99 | |||
97 | /* ahash per-session context */ | 100 | /* ahash per-session context */ |
98 | struct caam_hash_ctx { | 101 | struct caam_hash_ctx { |
99 | struct device *jrdev; | 102 | struct device *jrdev; |
@@ -1653,7 +1656,6 @@ static struct caam_hash_template driver_hash[] = { | |||
1653 | 1656 | ||
1654 | struct caam_hash_alg { | 1657 | struct 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,15 +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 | 1683 | ||
1684 | /* | 1684 | /* |
1685 | * distribute tfms across job rings to ensure in-order | 1685 | * Get a Job ring from Job Ring driver to ensure in-order |
1686 | * crypto request processing per tfm | 1686 | * crypto request processing per tfm |
1687 | */ | 1687 | */ |
1688 | ctx->jrdev = priv->jrdev[tgt_jr % priv->total_jobrs]; | 1688 | ctx->jrdev = caam_jr_alloc(); |
1689 | 1689 | if (IS_ERR(ctx->jrdev)) { | |
1690 | pr_err("Job Ring Device allocation for transform failed\n"); | ||
1691 | return PTR_ERR(ctx->jrdev); | ||
1692 | } | ||
1690 | /* copy descriptor header template value */ | 1693 | /* copy descriptor header template value */ |
1691 | ctx->alg_type = OP_TYPE_CLASS2_ALG | caam_hash->alg_type; | 1694 | ctx->alg_type = OP_TYPE_CLASS2_ALG | caam_hash->alg_type; |
1692 | ctx->alg_op = OP_TYPE_CLASS2_ALG | caam_hash->alg_op; | 1695 | ctx->alg_op = OP_TYPE_CLASS2_ALG | caam_hash->alg_op; |
@@ -1729,35 +1732,18 @@ static void caam_hash_cra_exit(struct crypto_tfm *tfm) | |||
1729 | !dma_mapping_error(ctx->jrdev, ctx->sh_desc_finup_dma)) | 1732 | !dma_mapping_error(ctx->jrdev, ctx->sh_desc_finup_dma)) |
1730 | dma_unmap_single(ctx->jrdev, ctx->sh_desc_finup_dma, | 1733 | dma_unmap_single(ctx->jrdev, ctx->sh_desc_finup_dma, |
1731 | 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); | ||
1732 | } | 1737 | } |
1733 | 1738 | ||
1734 | static void __exit caam_algapi_hash_exit(void) | 1739 | static void __exit caam_algapi_hash_exit(void) |
1735 | { | 1740 | { |
1736 | struct device_node *dev_node; | ||
1737 | struct platform_device *pdev; | ||
1738 | struct device *ctrldev; | ||
1739 | struct caam_drv_private *priv; | ||
1740 | struct caam_hash_alg *t_alg, *n; | 1741 | struct caam_hash_alg *t_alg, *n; |
1741 | 1742 | ||
1742 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); | 1743 | if (!hash_list.next) |
1743 | if (!dev_node) { | ||
1744 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0"); | ||
1745 | if (!dev_node) | ||
1746 | return; | ||
1747 | } | ||
1748 | |||
1749 | pdev = of_find_device_by_node(dev_node); | ||
1750 | if (!pdev) | ||
1751 | return; | 1744 | return; |
1752 | 1745 | ||
1753 | ctrldev = &pdev->dev; | 1746 | list_for_each_entry_safe(t_alg, n, &hash_list, entry) { |
1754 | of_node_put(dev_node); | ||
1755 | priv = dev_get_drvdata(ctrldev); | ||
1756 | |||
1757 | if (!priv->hash_list.next) | ||
1758 | return; | ||
1759 | |||
1760 | list_for_each_entry_safe(t_alg, n, &priv->hash_list, entry) { | ||
1761 | crypto_unregister_ahash(&t_alg->ahash_alg); | 1747 | crypto_unregister_ahash(&t_alg->ahash_alg); |
1762 | list_del(&t_alg->entry); | 1748 | list_del(&t_alg->entry); |
1763 | kfree(t_alg); | 1749 | kfree(t_alg); |
@@ -1765,7 +1751,7 @@ static void __exit caam_algapi_hash_exit(void) | |||
1765 | } | 1751 | } |
1766 | 1752 | ||
1767 | static struct caam_hash_alg * | 1753 | static struct caam_hash_alg * |
1768 | caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template, | 1754 | caam_hash_alloc(struct caam_hash_template *template, |
1769 | bool keyed) | 1755 | bool keyed) |
1770 | { | 1756 | { |
1771 | struct caam_hash_alg *t_alg; | 1757 | struct caam_hash_alg *t_alg; |
@@ -1774,7 +1760,7 @@ caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template, | |||
1774 | 1760 | ||
1775 | t_alg = kzalloc(sizeof(struct caam_hash_alg), GFP_KERNEL); | 1761 | t_alg = kzalloc(sizeof(struct caam_hash_alg), GFP_KERNEL); |
1776 | if (!t_alg) { | 1762 | if (!t_alg) { |
1777 | dev_err(ctrldev, "failed to allocate t_alg\n"); | 1763 | pr_err("failed to allocate t_alg\n"); |
1778 | return ERR_PTR(-ENOMEM); | 1764 | return ERR_PTR(-ENOMEM); |
1779 | } | 1765 | } |
1780 | 1766 | ||
@@ -1805,37 +1791,15 @@ caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template, | |||
1805 | 1791 | ||
1806 | t_alg->alg_type = template->alg_type; | 1792 | t_alg->alg_type = template->alg_type; |
1807 | t_alg->alg_op = template->alg_op; | 1793 | t_alg->alg_op = template->alg_op; |
1808 | t_alg->ctrldev = ctrldev; | ||
1809 | 1794 | ||
1810 | return t_alg; | 1795 | return t_alg; |
1811 | } | 1796 | } |
1812 | 1797 | ||
1813 | static int __init caam_algapi_hash_init(void) | 1798 | static int __init caam_algapi_hash_init(void) |
1814 | { | 1799 | { |
1815 | struct device_node *dev_node; | ||
1816 | struct platform_device *pdev; | ||
1817 | struct device *ctrldev; | ||
1818 | struct caam_drv_private *priv; | ||
1819 | int i = 0, err = 0; | 1800 | int i = 0, err = 0; |
1820 | 1801 | ||
1821 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); | 1802 | INIT_LIST_HEAD(&hash_list); |
1822 | if (!dev_node) { | ||
1823 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0"); | ||
1824 | if (!dev_node) | ||
1825 | return -ENODEV; | ||
1826 | } | ||
1827 | |||
1828 | pdev = of_find_device_by_node(dev_node); | ||
1829 | if (!pdev) | ||
1830 | return -ENODEV; | ||
1831 | |||
1832 | ctrldev = &pdev->dev; | ||
1833 | priv = dev_get_drvdata(ctrldev); | ||
1834 | of_node_put(dev_node); | ||
1835 | |||
1836 | INIT_LIST_HEAD(&priv->hash_list); | ||
1837 | |||
1838 | atomic_set(&priv->tfm_count, -1); | ||
1839 | 1803 | ||
1840 | /* register crypto algorithms the device supports */ | 1804 | /* register crypto algorithms the device supports */ |
1841 | for (i = 0; i < ARRAY_SIZE(driver_hash); i++) { | 1805 | for (i = 0; i < ARRAY_SIZE(driver_hash); i++) { |
@@ -1843,38 +1807,38 @@ static int __init caam_algapi_hash_init(void) | |||
1843 | struct caam_hash_alg *t_alg; | 1807 | struct caam_hash_alg *t_alg; |
1844 | 1808 | ||
1845 | /* register hmac version */ | 1809 | /* register hmac version */ |
1846 | t_alg = caam_hash_alloc(ctrldev, &driver_hash[i], true); | 1810 | t_alg = caam_hash_alloc(&driver_hash[i], true); |
1847 | if (IS_ERR(t_alg)) { | 1811 | if (IS_ERR(t_alg)) { |
1848 | err = PTR_ERR(t_alg); | 1812 | err = PTR_ERR(t_alg); |
1849 | dev_warn(ctrldev, "%s alg allocation failed\n", | 1813 | pr_warn("%s alg allocation failed\n", |
1850 | driver_hash[i].driver_name); | 1814 | driver_hash[i].driver_name); |
1851 | continue; | 1815 | continue; |
1852 | } | 1816 | } |
1853 | 1817 | ||
1854 | err = crypto_register_ahash(&t_alg->ahash_alg); | 1818 | err = crypto_register_ahash(&t_alg->ahash_alg); |
1855 | if (err) { | 1819 | if (err) { |
1856 | dev_warn(ctrldev, "%s alg registration failed\n", | 1820 | pr_warn("%s alg registration failed\n", |
1857 | t_alg->ahash_alg.halg.base.cra_driver_name); | 1821 | t_alg->ahash_alg.halg.base.cra_driver_name); |
1858 | kfree(t_alg); | 1822 | kfree(t_alg); |
1859 | } else | 1823 | } else |
1860 | list_add_tail(&t_alg->entry, &priv->hash_list); | 1824 | list_add_tail(&t_alg->entry, &hash_list); |
1861 | 1825 | ||
1862 | /* register unkeyed version */ | 1826 | /* register unkeyed version */ |
1863 | t_alg = caam_hash_alloc(ctrldev, &driver_hash[i], false); | 1827 | t_alg = caam_hash_alloc(&driver_hash[i], false); |
1864 | if (IS_ERR(t_alg)) { | 1828 | if (IS_ERR(t_alg)) { |
1865 | err = PTR_ERR(t_alg); | 1829 | err = PTR_ERR(t_alg); |
1866 | dev_warn(ctrldev, "%s alg allocation failed\n", | 1830 | pr_warn("%s alg allocation failed\n", |
1867 | driver_hash[i].driver_name); | 1831 | driver_hash[i].driver_name); |
1868 | continue; | 1832 | continue; |
1869 | } | 1833 | } |
1870 | 1834 | ||
1871 | err = crypto_register_ahash(&t_alg->ahash_alg); | 1835 | err = crypto_register_ahash(&t_alg->ahash_alg); |
1872 | if (err) { | 1836 | if (err) { |
1873 | dev_warn(ctrldev, "%s alg registration failed\n", | 1837 | pr_warn("%s alg registration failed\n", |
1874 | t_alg->ahash_alg.halg.base.cra_driver_name); | 1838 | t_alg->ahash_alg.halg.base.cra_driver_name); |
1875 | kfree(t_alg); | 1839 | kfree(t_alg); |
1876 | } else | 1840 | } else |
1877 | list_add_tail(&t_alg->entry, &priv->hash_list); | 1841 | list_add_tail(&t_alg->entry, &hash_list); |
1878 | } | 1842 | } |
1879 | 1843 | ||
1880 | return err; | 1844 | return err; |