summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTero Kristo <t-kristo@ti.com>2018-02-27 08:30:36 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2018-03-09 09:45:37 -0500
commitc9af5995d5a84ca191b0ec5514cc385715d89171 (patch)
tree7b31c56a9557814b46506a9aad55e955c85c1f73
parent065fa2523da83c674d8533144d9c9bac986ccf80 (diff)
crypto: omap-sham - make fallback size configurable
Crypto driver fallback size can now be configured from userspace. This allows optimizing the DMA usage based on use case. Default fallback size of 256 is still used. Signed-off-by: Tero Kristo <t-kristo@ti.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/omap-sham.c56
1 files changed, 53 insertions, 3 deletions
diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index ce398b7a2b1c..7fb9eef4e724 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -229,6 +229,7 @@ struct omap_sham_dev {
229 u8 xmit_buf[BUFLEN] OMAP_ALIGNED; 229 u8 xmit_buf[BUFLEN] OMAP_ALIGNED;
230 230
231 unsigned long flags; 231 unsigned long flags;
232 int fallback_sz;
232 struct crypto_queue queue; 233 struct crypto_queue queue;
233 struct ahash_request *req; 234 struct ahash_request *req;
234 235
@@ -1009,7 +1010,7 @@ static int omap_sham_update_req(struct omap_sham_dev *dd)
1009 ctx->total, ctx->digcnt, (ctx->flags & BIT(FLAGS_FINUP)) != 0); 1010 ctx->total, ctx->digcnt, (ctx->flags & BIT(FLAGS_FINUP)) != 0);
1010 1011
1011 if (ctx->total < get_block_size(ctx) || 1012 if (ctx->total < get_block_size(ctx) ||
1012 ctx->total < OMAP_SHA_DMA_THRESHOLD) 1013 ctx->total < dd->fallback_sz)
1013 ctx->flags |= BIT(FLAGS_CPU); 1014 ctx->flags |= BIT(FLAGS_CPU);
1014 1015
1015 if (ctx->flags & BIT(FLAGS_CPU)) 1016 if (ctx->flags & BIT(FLAGS_CPU))
@@ -1265,11 +1266,11 @@ static int omap_sham_final(struct ahash_request *req)
1265 /* 1266 /*
1266 * OMAP HW accel works only with buffers >= 9. 1267 * OMAP HW accel works only with buffers >= 9.
1267 * HMAC is always >= 9 because ipad == block size. 1268 * HMAC is always >= 9 because ipad == block size.
1268 * If buffersize is less than DMA_THRESHOLD, we use fallback 1269 * If buffersize is less than fallback_sz, we use fallback
1269 * SW encoding, as using DMA + HW in this case doesn't provide 1270 * SW encoding, as using DMA + HW in this case doesn't provide
1270 * any benefit. 1271 * any benefit.
1271 */ 1272 */
1272 if (!ctx->digcnt && ctx->bufcnt < OMAP_SHA_DMA_THRESHOLD) 1273 if (!ctx->digcnt && ctx->bufcnt < ctx->dd->fallback_sz)
1273 return omap_sham_final_shash(req); 1274 return omap_sham_final_shash(req);
1274 else if (ctx->bufcnt) 1275 else if (ctx->bufcnt)
1275 return omap_sham_enqueue(req, OP_FINAL); 1276 return omap_sham_enqueue(req, OP_FINAL);
@@ -2020,6 +2021,47 @@ err:
2020 return err; 2021 return err;
2021} 2022}
2022 2023
2024static ssize_t fallback_show(struct device *dev, struct device_attribute *attr,
2025 char *buf)
2026{
2027 struct omap_sham_dev *dd = dev_get_drvdata(dev);
2028
2029 return sprintf(buf, "%d\n", dd->fallback_sz);
2030}
2031
2032static ssize_t fallback_store(struct device *dev, struct device_attribute *attr,
2033 const char *buf, size_t size)
2034{
2035 struct omap_sham_dev *dd = dev_get_drvdata(dev);
2036 ssize_t status;
2037 long value;
2038
2039 status = kstrtol(buf, 0, &value);
2040 if (status)
2041 return status;
2042
2043 /* HW accelerator only works with buffers > 9 */
2044 if (value < 9) {
2045 dev_err(dev, "minimum fallback size 9\n");
2046 return -EINVAL;
2047 }
2048
2049 dd->fallback_sz = value;
2050
2051 return size;
2052}
2053
2054static DEVICE_ATTR_RW(fallback);
2055
2056static struct attribute *omap_sham_attrs[] = {
2057 &dev_attr_fallback.attr,
2058 NULL,
2059};
2060
2061static struct attribute_group omap_sham_attr_group = {
2062 .attrs = omap_sham_attrs,
2063};
2064
2023static int omap_sham_probe(struct platform_device *pdev) 2065static int omap_sham_probe(struct platform_device *pdev)
2024{ 2066{
2025 struct omap_sham_dev *dd; 2067 struct omap_sham_dev *dd;
@@ -2081,6 +2123,8 @@ static int omap_sham_probe(struct platform_device *pdev)
2081 pm_runtime_use_autosuspend(dev); 2123 pm_runtime_use_autosuspend(dev);
2082 pm_runtime_set_autosuspend_delay(dev, DEFAULT_AUTOSUSPEND_DELAY); 2124 pm_runtime_set_autosuspend_delay(dev, DEFAULT_AUTOSUSPEND_DELAY);
2083 2125
2126 dd->fallback_sz = OMAP_SHA_DMA_THRESHOLD;
2127
2084 pm_runtime_enable(dev); 2128 pm_runtime_enable(dev);
2085 pm_runtime_irq_safe(dev); 2129 pm_runtime_irq_safe(dev);
2086 2130
@@ -2118,6 +2162,12 @@ static int omap_sham_probe(struct platform_device *pdev)
2118 } 2162 }
2119 } 2163 }
2120 2164
2165 err = sysfs_create_group(&dev->kobj, &omap_sham_attr_group);
2166 if (err) {
2167 dev_err(dev, "could not create sysfs device attrs\n");
2168 goto err_algs;
2169 }
2170
2121 return 0; 2171 return 0;
2122 2172
2123err_algs: 2173err_algs: