diff options
author | LEROY Christophe <christophe.leroy@c-s.fr> | 2018-02-26 11:40:06 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2018-03-09 09:45:35 -0500 |
commit | 6a4967c3e1fc1f2fd19283e5c98076a65f7b29ff (patch) | |
tree | 922e9735fd3593d1d9aed008c753182f936fe2e1 /drivers/crypto | |
parent | ad4cd51fb8375109edb377712b5f9c0c31ece33e (diff) |
crypto: talitos - do not perform unnecessary dma synchronisation
req_ctx->hw_context is mainly used only by the HW. So it is not needed
to sync the HW and the CPU each time hw_context in DMA mapped.
This patch modifies the DMA mapping in order to limit synchronisation
to necessary situations.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r-- | drivers/crypto/talitos.c | 85 |
1 files changed, 63 insertions, 22 deletions
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index bb44df1c1f2d..447cb8b1b16a 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c | |||
@@ -104,16 +104,34 @@ static void to_talitos_ptr_ext_or(struct talitos_ptr *ptr, u8 val, bool is_sec1) | |||
104 | /* | 104 | /* |
105 | * map virtual single (contiguous) pointer to h/w descriptor pointer | 105 | * map virtual single (contiguous) pointer to h/w descriptor pointer |
106 | */ | 106 | */ |
107 | static void __map_single_talitos_ptr(struct device *dev, | ||
108 | struct talitos_ptr *ptr, | ||
109 | unsigned int len, void *data, | ||
110 | enum dma_data_direction dir, | ||
111 | unsigned long attrs) | ||
112 | { | ||
113 | dma_addr_t dma_addr = dma_map_single_attrs(dev, data, len, dir, attrs); | ||
114 | struct talitos_private *priv = dev_get_drvdata(dev); | ||
115 | bool is_sec1 = has_ftr_sec1(priv); | ||
116 | |||
117 | to_talitos_ptr(ptr, dma_addr, len, is_sec1); | ||
118 | } | ||
119 | |||
107 | static void map_single_talitos_ptr(struct device *dev, | 120 | static void map_single_talitos_ptr(struct device *dev, |
108 | struct talitos_ptr *ptr, | 121 | struct talitos_ptr *ptr, |
109 | unsigned int len, void *data, | 122 | unsigned int len, void *data, |
110 | enum dma_data_direction dir) | 123 | enum dma_data_direction dir) |
111 | { | 124 | { |
112 | dma_addr_t dma_addr = dma_map_single(dev, data, len, dir); | 125 | __map_single_talitos_ptr(dev, ptr, len, data, dir, 0); |
113 | struct talitos_private *priv = dev_get_drvdata(dev); | 126 | } |
114 | bool is_sec1 = has_ftr_sec1(priv); | ||
115 | 127 | ||
116 | to_talitos_ptr(ptr, dma_addr, len, is_sec1); | 128 | static void map_single_talitos_ptr_nosync(struct device *dev, |
129 | struct talitos_ptr *ptr, | ||
130 | unsigned int len, void *data, | ||
131 | enum dma_data_direction dir) | ||
132 | { | ||
133 | __map_single_talitos_ptr(dev, ptr, len, data, dir, | ||
134 | DMA_ATTR_SKIP_CPU_SYNC); | ||
117 | } | 135 | } |
118 | 136 | ||
119 | /* | 137 | /* |
@@ -1785,10 +1803,10 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, | |||
1785 | 1803 | ||
1786 | /* hash context in */ | 1804 | /* hash context in */ |
1787 | if (!req_ctx->first || req_ctx->swinit) { | 1805 | if (!req_ctx->first || req_ctx->swinit) { |
1788 | map_single_talitos_ptr(dev, &desc->ptr[1], | 1806 | map_single_talitos_ptr_nosync(dev, &desc->ptr[1], |
1789 | req_ctx->hw_context_size, | 1807 | req_ctx->hw_context_size, |
1790 | (char *)req_ctx->hw_context, | 1808 | req_ctx->hw_context, |
1791 | DMA_TO_DEVICE); | 1809 | DMA_TO_DEVICE); |
1792 | req_ctx->swinit = 0; | 1810 | req_ctx->swinit = 0; |
1793 | } | 1811 | } |
1794 | /* Indicate next op is not the first. */ | 1812 | /* Indicate next op is not the first. */ |
@@ -1832,9 +1850,10 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, | |||
1832 | crypto_ahash_digestsize(tfm), | 1850 | crypto_ahash_digestsize(tfm), |
1833 | areq->result, DMA_FROM_DEVICE); | 1851 | areq->result, DMA_FROM_DEVICE); |
1834 | else | 1852 | else |
1835 | map_single_talitos_ptr(dev, &desc->ptr[5], | 1853 | map_single_talitos_ptr_nosync(dev, &desc->ptr[5], |
1836 | req_ctx->hw_context_size, | 1854 | req_ctx->hw_context_size, |
1837 | req_ctx->hw_context, DMA_FROM_DEVICE); | 1855 | req_ctx->hw_context, |
1856 | DMA_FROM_DEVICE); | ||
1838 | 1857 | ||
1839 | /* last DWORD empty */ | 1858 | /* last DWORD empty */ |
1840 | 1859 | ||
@@ -1857,10 +1876,10 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, | |||
1857 | copy_talitos_ptr(&desc2->ptr[1], &desc->ptr[1], | 1876 | copy_talitos_ptr(&desc2->ptr[1], &desc->ptr[1], |
1858 | is_sec1); | 1877 | is_sec1); |
1859 | else | 1878 | else |
1860 | map_single_talitos_ptr(dev, &desc2->ptr[1], | 1879 | map_single_talitos_ptr_nosync(dev, &desc2->ptr[1], |
1861 | req_ctx->hw_context_size, | 1880 | req_ctx->hw_context_size, |
1862 | req_ctx->hw_context, | 1881 | req_ctx->hw_context, |
1863 | DMA_TO_DEVICE); | 1882 | DMA_TO_DEVICE); |
1864 | copy_talitos_ptr(&desc2->ptr[2], &desc->ptr[2], is_sec1); | 1883 | copy_talitos_ptr(&desc2->ptr[2], &desc->ptr[2], is_sec1); |
1865 | sg_count = talitos_sg_map(dev, req_ctx->psrc, length, edesc, | 1884 | sg_count = talitos_sg_map(dev, req_ctx->psrc, length, edesc, |
1866 | &desc2->ptr[3], sg_count, offset, 0); | 1885 | &desc2->ptr[3], sg_count, offset, 0); |
@@ -1868,10 +1887,10 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc, | |||
1868 | sync_needed = true; | 1887 | sync_needed = true; |
1869 | copy_talitos_ptr(&desc2->ptr[5], &desc->ptr[5], is_sec1); | 1888 | copy_talitos_ptr(&desc2->ptr[5], &desc->ptr[5], is_sec1); |
1870 | if (req_ctx->last) | 1889 | if (req_ctx->last) |
1871 | map_single_talitos_ptr(dev, &desc->ptr[5], | 1890 | map_single_talitos_ptr_nosync(dev, &desc->ptr[5], |
1872 | req_ctx->hw_context_size, | 1891 | req_ctx->hw_context_size, |
1873 | req_ctx->hw_context, | 1892 | req_ctx->hw_context, |
1874 | DMA_FROM_DEVICE); | 1893 | DMA_FROM_DEVICE); |
1875 | 1894 | ||
1876 | next_desc = dma_map_single(dev, &desc2->hdr1, TALITOS_DESC_SIZE, | 1895 | next_desc = dma_map_single(dev, &desc2->hdr1, TALITOS_DESC_SIZE, |
1877 | DMA_BIDIRECTIONAL); | 1896 | DMA_BIDIRECTIONAL); |
@@ -1909,8 +1928,11 @@ static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, | |||
1909 | static int ahash_init(struct ahash_request *areq) | 1928 | static int ahash_init(struct ahash_request *areq) |
1910 | { | 1929 | { |
1911 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); | 1930 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
1931 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); | ||
1932 | struct device *dev = ctx->dev; | ||
1912 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | 1933 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
1913 | unsigned int size; | 1934 | unsigned int size; |
1935 | dma_addr_t dma; | ||
1914 | 1936 | ||
1915 | /* Initialize the context */ | 1937 | /* Initialize the context */ |
1916 | req_ctx->buf_idx = 0; | 1938 | req_ctx->buf_idx = 0; |
@@ -1922,6 +1944,10 @@ static int ahash_init(struct ahash_request *areq) | |||
1922 | : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512; | 1944 | : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512; |
1923 | req_ctx->hw_context_size = size; | 1945 | req_ctx->hw_context_size = size; |
1924 | 1946 | ||
1947 | dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size, | ||
1948 | DMA_TO_DEVICE); | ||
1949 | dma_unmap_single(dev, dma, req_ctx->hw_context_size, DMA_TO_DEVICE); | ||
1950 | |||
1925 | return 0; | 1951 | return 0; |
1926 | } | 1952 | } |
1927 | 1953 | ||
@@ -1933,9 +1959,6 @@ static int ahash_init_sha224_swinit(struct ahash_request *areq) | |||
1933 | { | 1959 | { |
1934 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | 1960 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
1935 | 1961 | ||
1936 | ahash_init(areq); | ||
1937 | req_ctx->swinit = 1;/* prevent h/w initting context with sha256 values*/ | ||
1938 | |||
1939 | req_ctx->hw_context[0] = SHA224_H0; | 1962 | req_ctx->hw_context[0] = SHA224_H0; |
1940 | req_ctx->hw_context[1] = SHA224_H1; | 1963 | req_ctx->hw_context[1] = SHA224_H1; |
1941 | req_ctx->hw_context[2] = SHA224_H2; | 1964 | req_ctx->hw_context[2] = SHA224_H2; |
@@ -1949,6 +1972,9 @@ static int ahash_init_sha224_swinit(struct ahash_request *areq) | |||
1949 | req_ctx->hw_context[8] = 0; | 1972 | req_ctx->hw_context[8] = 0; |
1950 | req_ctx->hw_context[9] = 0; | 1973 | req_ctx->hw_context[9] = 0; |
1951 | 1974 | ||
1975 | ahash_init(areq); | ||
1976 | req_ctx->swinit = 1;/* prevent h/w initting context with sha256 values*/ | ||
1977 | |||
1952 | return 0; | 1978 | return 0; |
1953 | } | 1979 | } |
1954 | 1980 | ||
@@ -2105,6 +2131,14 @@ static int ahash_export(struct ahash_request *areq, void *out) | |||
2105 | { | 2131 | { |
2106 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | 2132 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
2107 | struct talitos_export_state *export = out; | 2133 | struct talitos_export_state *export = out; |
2134 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); | ||
2135 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); | ||
2136 | struct device *dev = ctx->dev; | ||
2137 | dma_addr_t dma; | ||
2138 | |||
2139 | dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size, | ||
2140 | DMA_FROM_DEVICE); | ||
2141 | dma_unmap_single(dev, dma, req_ctx->hw_context_size, DMA_FROM_DEVICE); | ||
2108 | 2142 | ||
2109 | memcpy(export->hw_context, req_ctx->hw_context, | 2143 | memcpy(export->hw_context, req_ctx->hw_context, |
2110 | req_ctx->hw_context_size); | 2144 | req_ctx->hw_context_size); |
@@ -2122,8 +2156,11 @@ static int ahash_import(struct ahash_request *areq, const void *in) | |||
2122 | { | 2156 | { |
2123 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); | 2157 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
2124 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); | 2158 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
2159 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); | ||
2160 | struct device *dev = ctx->dev; | ||
2125 | const struct talitos_export_state *export = in; | 2161 | const struct talitos_export_state *export = in; |
2126 | unsigned int size; | 2162 | unsigned int size; |
2163 | dma_addr_t dma; | ||
2127 | 2164 | ||
2128 | memset(req_ctx, 0, sizeof(*req_ctx)); | 2165 | memset(req_ctx, 0, sizeof(*req_ctx)); |
2129 | size = (crypto_ahash_digestsize(tfm) <= SHA256_DIGEST_SIZE) | 2166 | size = (crypto_ahash_digestsize(tfm) <= SHA256_DIGEST_SIZE) |
@@ -2138,6 +2175,10 @@ static int ahash_import(struct ahash_request *areq, const void *in) | |||
2138 | req_ctx->to_hash_later = export->to_hash_later; | 2175 | req_ctx->to_hash_later = export->to_hash_later; |
2139 | req_ctx->nbuf = export->nbuf; | 2176 | req_ctx->nbuf = export->nbuf; |
2140 | 2177 | ||
2178 | dma = dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size, | ||
2179 | DMA_TO_DEVICE); | ||
2180 | dma_unmap_single(dev, dma, req_ctx->hw_context_size, DMA_TO_DEVICE); | ||
2181 | |||
2141 | return 0; | 2182 | return 0; |
2142 | } | 2183 | } |
2143 | 2184 | ||