[PATCH v3 12/18] crypto: switch af_alg_make_sg() to iov_iter

2015-02-03 Thread Al Viro
From: Al Viro 

With that, all ->sendmsg() instances are converted to iov_iter primitives
and are agnostic wrt the kind of iov_iter they are working with.
So's the last remaining ->recvmsg() instance that wasn't kind-agnostic yet.
All ->sendmsg() and ->recvmsg() advance ->msg_iter by the amount actually
copied and none of them modifies the underlying iovec, etc.

Cc: linux-crypto@vger.kernel.org
Signed-off-by: Al Viro 
---
 crypto/af_alg.c | 40 --
 crypto/algif_hash.c | 45 --
 crypto/algif_skcipher.c | 74 ++---
 include/crypto/if_alg.h |  3 +-
 4 files changed, 62 insertions(+), 100 deletions(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 4665b79c..eb78fe8 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -338,49 +338,31 @@ static const struct net_proto_family alg_family = {
.owner  =   THIS_MODULE,
 };
 
-int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len,
-  int write)
+int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len)
 {
-   unsigned long from = (unsigned long)addr;
-   unsigned long npages;
-   unsigned off;
-   int err;
-   int i;
-
-   err = -EFAULT;
-   if (!access_ok(write ? VERIFY_READ : VERIFY_WRITE, addr, len))
-   goto out;
-
-   off = from & ~PAGE_MASK;
-   npages = (off + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
-   if (npages > ALG_MAX_PAGES)
-   npages = ALG_MAX_PAGES;
+   size_t off;
+   ssize_t n;
+   int npages, i;
 
-   err = get_user_pages_fast(from, npages, write, sgl->pages);
-   if (err < 0)
-   goto out;
+   n = iov_iter_get_pages(iter, sgl->pages, len, ALG_MAX_PAGES, &off);
+   if (n < 0)
+   return n;
 
-   npages = err;
-   err = -EINVAL;
+   npages = PAGE_ALIGN(off + n);
if (WARN_ON(npages == 0))
-   goto out;
-
-   err = 0;
+   return -EINVAL;
 
sg_init_table(sgl->sg, npages);
 
-   for (i = 0; i < npages; i++) {
+   for (i = 0, len = n; i < npages; i++) {
int plen = min_t(int, len, PAGE_SIZE - off);
 
sg_set_page(sgl->sg + i, sgl->pages[i], plen, off);
 
off = 0;
len -= plen;
-   err += plen;
}
-
-out:
-   return err;
+   return n;
 }
 EXPORT_SYMBOL_GPL(af_alg_make_sg);
 
diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
index 01f56eb..01da360 100644
--- a/crypto/algif_hash.c
+++ b/crypto/algif_hash.c
@@ -41,8 +41,6 @@ static int hash_sendmsg(struct kiocb *unused, struct socket 
*sock,
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
struct hash_ctx *ctx = ask->private;
-   unsigned long iovlen;
-   const struct iovec *iov;
long copied = 0;
int err;
 
@@ -58,37 +56,28 @@ static int hash_sendmsg(struct kiocb *unused, struct socket 
*sock,
 
ctx->more = 0;
 
-   for (iov = msg->msg_iter.iov, iovlen = msg->msg_iter.nr_segs; iovlen > 
0;
-iovlen--, iov++) {
-   unsigned long seglen = iov->iov_len;
-   char __user *from = iov->iov_base;
+   while (iov_iter_count(&msg->msg_iter)) {
+   int len = iov_iter_count(&msg->msg_iter);
 
-   while (seglen) {
-   int len = min_t(unsigned long, seglen, limit);
-   int newlen;
+   if (len > limit)
+   len = limit;
 
-   newlen = af_alg_make_sg(&ctx->sgl, from, len, 0);
-   if (newlen < 0) {
-   err = copied ? 0 : newlen;
-   goto unlock;
-   }
-
-   ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL,
-   newlen);
-
-   err = af_alg_wait_for_completion(
-   crypto_ahash_update(&ctx->req),
-   &ctx->completion);
+   len = af_alg_make_sg(&ctx->sgl, &msg->msg_iter, len);
+   if (len < 0) {
+   err = copied ? 0 : len;
+   goto unlock;
+   }
 
-   af_alg_free_sg(&ctx->sgl);
+   ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len);
 
-   if (err)
-   goto unlock;
+   err = af_alg_wait_for_completion(crypto_ahash_update(&ctx->req),
+&ctx->completion);
+   af_alg_free_sg(&ctx->sgl);
+   if (err)
+   goto unlock;
 
-   seglen -= newlen;
-   from += newlen;
-   copied += newlen;
-   }
+   copied

[PATCH v1 0/5] crypto: ccp - CCP driver updates 2015-01-28

2015-02-03 Thread Tom Lendacky
For some reason this series never reached the mailing list... resending.

The following series of patches includes functional updates to the
driver as well as some trivial changes.

- Fix checks/warnings from checkpatch
- Update how the CCP is built (Kconfig and Makefile)
- Use dma_set_mask_and_coherent to set the DMA mask
- Use devm_ calls where appropriate
- Add ACPI support
  
This patch series is based on cryptodev-2.6.

---

Tom Lendacky (5):
  crypto: ccp - Updates for checkpatch warnings/errors
  crypto: ccp - Update CCP build support
  crypto: ccp - Use dma_set_mask_and_coherent to set DMA mask
  crypto: ccp - Convert calls to their devm_ counterparts
  crypto: ccp - Add ACPI support


 drivers/crypto/Kconfig   |2 -
 drivers/crypto/ccp/Makefile  |9 +-
 drivers/crypto/ccp/ccp-crypto-aes-cmac.c |   12 ++-
 drivers/crypto/ccp/ccp-crypto-aes-xts.c  |4 -
 drivers/crypto/ccp/ccp-crypto-aes.c  |3 -
 drivers/crypto/ccp/ccp-crypto-main.c |5 +
 drivers/crypto/ccp/ccp-crypto-sha.c  |   12 ++-
 drivers/crypto/ccp/ccp-crypto.h  |3 -
 drivers/crypto/ccp/ccp-dev.c |7 +-
 drivers/crypto/ccp/ccp-dev.h |   12 +--
 drivers/crypto/ccp/ccp-ops.c |   24 +++---
 drivers/crypto/ccp/ccp-pci.c |   21 ++
 drivers/crypto/ccp/ccp-platform.c|  111 ++
 13 files changed, 143 insertions(+), 82 deletions(-)

-- 
Tom Lendacky
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 3/5] crypto: ccp - Use dma_set_mask_and_coherent to set DMA mask

2015-02-03 Thread Tom Lendacky
Replace the setting of the DMA masks with the dma_set_mask_and_coherent
function call.

Signed-off-by: Tom Lendacky 
---
 drivers/crypto/ccp/ccp-platform.c |7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-platform.c 
b/drivers/crypto/ccp/ccp-platform.c
index 9e09c50..04265a3 100644
--- a/drivers/crypto/ccp/ccp-platform.c
+++ b/drivers/crypto/ccp/ccp-platform.c
@@ -109,8 +109,11 @@ static int ccp_platform_probe(struct platform_device *pdev)
 
if (!dev->dma_mask)
dev->dma_mask = &dev->coherent_dma_mask;
-   *(dev->dma_mask) = DMA_BIT_MASK(48);
-   dev->coherent_dma_mask = DMA_BIT_MASK(48);
+   ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
+   if (ret) {
+   dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret);
+   goto e_free;
+   }
 
if (of_property_read_bool(dev->of_node, "dma-coherent"))
ccp->axcache = CACHE_WB_NO_ALLOC;

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 4/5] crypto: ccp - Convert calls to their devm_ counterparts

2015-02-03 Thread Tom Lendacky
Where applicable, convert calls to their devm_ counterparts, e.g. kzalloc
to devm_kzalloc.

Signed-off-by: Tom Lendacky 
---
 drivers/crypto/ccp/ccp-dev.c  |2 +-
 drivers/crypto/ccp/ccp-pci.c  |   19 +--
 drivers/crypto/ccp/ccp-platform.c |   11 +++
 3 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
index 68c637a..861bacc 100644
--- a/drivers/crypto/ccp/ccp-dev.c
+++ b/drivers/crypto/ccp/ccp-dev.c
@@ -295,7 +295,7 @@ struct ccp_device *ccp_alloc_struct(struct device *dev)
 {
struct ccp_device *ccp;
 
-   ccp = kzalloc(sizeof(*ccp), GFP_KERNEL);
+   ccp = devm_kzalloc(dev, sizeof(*ccp), GFP_KERNEL);
if (!ccp)
return NULL;
ccp->dev = dev;
diff --git a/drivers/crypto/ccp/ccp-pci.c b/drivers/crypto/ccp/ccp-pci.c
index 1980f77..af190d4 100644
--- a/drivers/crypto/ccp/ccp-pci.c
+++ b/drivers/crypto/ccp/ccp-pci.c
@@ -174,11 +174,10 @@ static int ccp_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)
if (!ccp)
goto e_err;
 
-   ccp_pci = kzalloc(sizeof(*ccp_pci), GFP_KERNEL);
-   if (!ccp_pci) {
-   ret = -ENOMEM;
-   goto e_free1;
-   }
+   ccp_pci = devm_kzalloc(dev, sizeof(*ccp_pci), GFP_KERNEL);
+   if (!ccp_pci)
+   goto e_err;
+
ccp->dev_specific = ccp_pci;
ccp->get_irq = ccp_get_irqs;
ccp->free_irq = ccp_free_irqs;
@@ -186,7 +185,7 @@ static int ccp_pci_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
ret = pci_request_regions(pdev, "ccp");
if (ret) {
dev_err(dev, "pci_request_regions failed (%d)\n", ret);
-   goto e_free2;
+   goto e_err;
}
 
ret = pci_enable_device(pdev);
@@ -239,12 +238,6 @@ e_device:
 e_regions:
pci_release_regions(pdev);
 
-e_free2:
-   kfree(ccp_pci);
-
-e_free1:
-   kfree(ccp);
-
 e_err:
dev_notice(dev, "initialization failed\n");
return ret;
@@ -266,8 +259,6 @@ static void ccp_pci_remove(struct pci_dev *pdev)
 
pci_release_regions(pdev);
 
-   kfree(ccp);
-
dev_notice(dev, "disabled\n");
 }
 
diff --git a/drivers/crypto/ccp/ccp-platform.c 
b/drivers/crypto/ccp/ccp-platform.c
index 04265a3..20661f0 100644
--- a/drivers/crypto/ccp/ccp-platform.c
+++ b/drivers/crypto/ccp/ccp-platform.c
@@ -103,7 +103,7 @@ static int ccp_platform_probe(struct platform_device *pdev)
ccp->io_map = devm_ioremap_resource(dev, ior);
if (IS_ERR(ccp->io_map)) {
ret = PTR_ERR(ccp->io_map);
-   goto e_free;
+   goto e_err;
}
ccp->io_regs = ccp->io_map;
 
@@ -112,7 +112,7 @@ static int ccp_platform_probe(struct platform_device *pdev)
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
if (ret) {
dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret);
-   goto e_free;
+   goto e_err;
}
 
if (of_property_read_bool(dev->of_node, "dma-coherent"))
@@ -124,15 +124,12 @@ static int ccp_platform_probe(struct platform_device 
*pdev)
 
ret = ccp_init(ccp);
if (ret)
-   goto e_free;
+   goto e_err;
 
dev_notice(dev, "enabled\n");
 
return 0;
 
-e_free:
-   kfree(ccp);
-
 e_err:
dev_notice(dev, "initialization failed\n");
return ret;
@@ -145,8 +142,6 @@ static int ccp_platform_remove(struct platform_device *pdev)
 
ccp_destroy(ccp);
 
-   kfree(ccp);
-
dev_notice(dev, "disabled\n");
 
return 0;

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 2/5] crypto: ccp - Update CCP build support

2015-02-03 Thread Tom Lendacky
Add HAS_IOMEM as a Kconfig dependency. Always include ccp-platform.c
in the CCP build and conditionally include ccp-pci.c.

Signed-off-by: Tom Lendacky 
---
 drivers/crypto/Kconfig  |2 +-
 drivers/crypto/ccp/Makefile |9 ++---
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 2fb0fdf..b840b79 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -391,7 +391,7 @@ config CRYPTO_DEV_ATMEL_SHA
 
 config CRYPTO_DEV_CCP
bool "Support for AMD Cryptographic Coprocessor"
-   depends on (X86 && PCI) || ARM64
+   depends on ((X86 && PCI) || ARM64) && HAS_IOMEM
default n
help
  The AMD Cryptographic Coprocessor provides hardware support
diff --git a/drivers/crypto/ccp/Makefile b/drivers/crypto/ccp/Makefile
index 7f592d8..55a1f39 100644
--- a/drivers/crypto/ccp/Makefile
+++ b/drivers/crypto/ccp/Makefile
@@ -1,11 +1,6 @@
 obj-$(CONFIG_CRYPTO_DEV_CCP_DD) += ccp.o
-ccp-objs := ccp-dev.o ccp-ops.o
-ifdef CONFIG_X86
-ccp-objs += ccp-pci.o
-endif
-ifdef CONFIG_ARM64
-ccp-objs += ccp-platform.o
-endif
+ccp-objs := ccp-dev.o ccp-ops.o ccp-platform.o
+ccp-$(CONFIG_PCI) += ccp-pci.o
 
 obj-$(CONFIG_CRYPTO_DEV_CCP_CRYPTO) += ccp-crypto.o
 ccp-crypto-objs := ccp-crypto-main.o \

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 1/5] crypto: ccp - Updates for checkpatch warnings/errors

2015-02-03 Thread Tom Lendacky
Changes to address warnings and errors reported by the checkpatch
script.

Signed-off-by: Tom Lendacky 
---
 drivers/crypto/ccp/ccp-crypto-aes-cmac.c |   12 +++-
 drivers/crypto/ccp/ccp-crypto-aes-xts.c  |4 +---
 drivers/crypto/ccp/ccp-crypto-aes.c  |3 +--
 drivers/crypto/ccp/ccp-crypto-main.c |5 ++---
 drivers/crypto/ccp/ccp-crypto-sha.c  |   12 +++-
 drivers/crypto/ccp/ccp-crypto.h  |3 ---
 drivers/crypto/ccp/ccp-dev.c |5 +
 drivers/crypto/ccp/ccp-dev.h |   12 
 drivers/crypto/ccp/ccp-ops.c |   24 
 drivers/crypto/ccp/ccp-pci.c |2 +-
 drivers/crypto/ccp/ccp-platform.c|1 -
 11 files changed, 36 insertions(+), 47 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c 
b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
index 8e162ad..ea7e844 100644
--- a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
+++ b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
@@ -23,7 +23,6 @@
 
 #include "ccp-crypto.h"
 
-
 static int ccp_aes_cmac_complete(struct crypto_async_request *async_req,
 int ret)
 {
@@ -38,11 +37,13 @@ static int ccp_aes_cmac_complete(struct 
crypto_async_request *async_req,
if (rctx->hash_rem) {
/* Save remaining data to buffer */
unsigned int offset = rctx->nbytes - rctx->hash_rem;
+
scatterwalk_map_and_copy(rctx->buf, rctx->src,
 offset, rctx->hash_rem, 0);
rctx->buf_count = rctx->hash_rem;
-   } else
+   } else {
rctx->buf_count = 0;
+   }
 
/* Update result area if supplied */
if (req->result)
@@ -202,7 +203,7 @@ static int ccp_aes_cmac_digest(struct ahash_request *req)
 }
 
 static int ccp_aes_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
-  unsigned int key_len)
+  unsigned int key_len)
 {
struct ccp_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm));
struct ccp_crypto_ahash_alg *alg =
@@ -292,7 +293,8 @@ static int ccp_aes_cmac_cra_init(struct crypto_tfm *tfm)
crypto_ahash_set_reqsize(ahash, sizeof(struct ccp_aes_cmac_req_ctx));
 
cipher_tfm = crypto_alloc_cipher("aes", 0,
-   CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
+CRYPTO_ALG_ASYNC |
+CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(cipher_tfm)) {
pr_warn("could not load aes cipher driver\n");
return PTR_ERR(cipher_tfm);
@@ -354,7 +356,7 @@ int ccp_register_aes_cmac_algs(struct list_head *head)
ret = crypto_register_ahash(alg);
if (ret) {
pr_err("%s ahash algorithm registration error (%d)\n",
-   base->cra_name, ret);
+  base->cra_name, ret);
kfree(ccp_alg);
return ret;
}
diff --git a/drivers/crypto/ccp/ccp-crypto-aes-xts.c 
b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
index 0cc5594..52c7395 100644
--- a/drivers/crypto/ccp/ccp-crypto-aes-xts.c
+++ b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
@@ -21,7 +21,6 @@
 
 #include "ccp-crypto.h"
 
-
 struct ccp_aes_xts_def {
const char *name;
const char *drv_name;
@@ -216,7 +215,6 @@ static void ccp_aes_xts_cra_exit(struct crypto_tfm *tfm)
ctx->u.aes.tfm_ablkcipher = NULL;
 }
 
-
 static int ccp_register_aes_xts_alg(struct list_head *head,
const struct ccp_aes_xts_def *def)
 {
@@ -255,7 +253,7 @@ static int ccp_register_aes_xts_alg(struct list_head *head,
ret = crypto_register_alg(alg);
if (ret) {
pr_err("%s ablkcipher algorithm registration error (%d)\n",
-   alg->cra_name, ret);
+  alg->cra_name, ret);
kfree(ccp_alg);
return ret;
}
diff --git a/drivers/crypto/ccp/ccp-crypto-aes.c 
b/drivers/crypto/ccp/ccp-crypto-aes.c
index e46490d..7984f91 100644
--- a/drivers/crypto/ccp/ccp-crypto-aes.c
+++ b/drivers/crypto/ccp/ccp-crypto-aes.c
@@ -22,7 +22,6 @@
 
 #include "ccp-crypto.h"
 
-
 static int ccp_aes_complete(struct crypto_async_request *async_req, int ret)
 {
struct ablkcipher_request *req = ablkcipher_request_cast(async_req);
@@ -345,7 +344,7 @@ static int ccp_register_aes_alg(struct list_head *head,
ret = crypto_register_alg(alg);
if (ret) {
pr_err("%s ablkcipher algorithm registration error (%d)\n",
-   alg->cra_name, ret);
+  alg->cra_name, ret);
kfree(ccp_alg);
return ret;
}
diff --git a/drivers/crypto/ccp/ccp-crypto-main.c 
b/drivers/crypto/ccp/ccp-crypto-main.c
index 4d4e016..bdec01e 100644
--- a/drivers/crypto/ccp/ccp-crypto-main.c
+++ b/drivers/crypto

[PATCH v1 5/5] crypto: ccp - Add ACPI support

2015-02-03 Thread Tom Lendacky
Add support for ACPI to the CCP platform driver.

Signed-off-by: Tom Lendacky 
---
 drivers/crypto/Kconfig|2 -
 drivers/crypto/ccp/ccp-platform.c |   96 +++--
 2 files changed, 93 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index b840b79..7e94413 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -391,7 +391,7 @@ config CRYPTO_DEV_ATMEL_SHA
 
 config CRYPTO_DEV_CCP
bool "Support for AMD Cryptographic Coprocessor"
-   depends on ((X86 && PCI) || ARM64) && HAS_IOMEM
+   depends on ((X86 && PCI) || (ARM64 && (OF_ADDRESS || ACPI))) && 
HAS_IOMEM
default n
help
  The AMD Cryptographic Coprocessor provides hardware support
diff --git a/drivers/crypto/ccp/ccp-platform.c 
b/drivers/crypto/ccp/ccp-platform.c
index 20661f0..b1c20b2 100644
--- a/drivers/crypto/ccp/ccp-platform.c
+++ b/drivers/crypto/ccp/ccp-platform.c
@@ -23,9 +23,16 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "ccp-dev.h"
 
+struct ccp_platform {
+   int use_acpi;
+   int coherent;
+};
+
 static int ccp_get_irq(struct ccp_device *ccp)
 {
struct device *dev = ccp->dev;
@@ -83,10 +90,64 @@ static struct resource *ccp_find_mmio_area(struct 
ccp_device *ccp)
return NULL;
 }
 
+#ifdef CONFIG_ACPI
+static int ccp_acpi_support(struct ccp_device *ccp)
+{
+   struct ccp_platform *ccp_platform = ccp->dev_specific;
+   struct acpi_device *adev = ACPI_COMPANION(ccp->dev);
+   acpi_handle handle;
+   acpi_status status;
+   unsigned long long data;
+   int cca;
+
+   /* Retrieve the device cache coherency value */
+   handle = adev->handle;
+   do {
+   status = acpi_evaluate_integer(handle, "_CCA", NULL, &data);
+   if (!ACPI_FAILURE(status)) {
+   cca = data;
+   break;
+   }
+   } while (!ACPI_FAILURE(status));
+
+   if (ACPI_FAILURE(status)) {
+   dev_err(ccp->dev, "error obtaining acpi coherency value\n");
+   return -EINVAL;
+   }
+
+   ccp_platform->coherent = !!cca;
+
+   return 0;
+}
+#else  /* CONFIG_ACPI */
+static int ccp_acpi_support(struct ccp_device *ccp)
+{
+   return -EINVAL;
+}
+#endif
+
+#ifdef CONFIG_OF
+static int ccp_of_support(struct ccp_device *ccp)
+{
+   struct ccp_platform *ccp_platform = ccp->dev_specific;
+
+   ccp_platform->coherent = of_dma_is_coherent(ccp->dev->of_node);
+
+   return 0;
+}
+#else
+static int ccp_of_support(struct ccp_device *ccp)
+{
+   return -EINVAL;
+}
+#endif
+
 static int ccp_platform_probe(struct platform_device *pdev)
 {
struct ccp_device *ccp;
+   struct ccp_platform *ccp_platform;
struct device *dev = &pdev->dev;
+   struct acpi_device *adev = ACPI_COMPANION(dev);
struct resource *ior;
int ret;
 
@@ -95,10 +156,16 @@ static int ccp_platform_probe(struct platform_device *pdev)
if (!ccp)
goto e_err;
 
-   ccp->dev_specific = NULL;
+   ccp_platform = devm_kzalloc(dev, sizeof(*ccp_platform), GFP_KERNEL);
+   if (!ccp_platform)
+   goto e_err;
+
+   ccp->dev_specific = ccp_platform;
ccp->get_irq = ccp_get_irqs;
ccp->free_irq = ccp_free_irqs;
 
+   ccp_platform->use_acpi = (!adev || acpi_disabled) ? 0 : 1;
+
ior = ccp_find_mmio_area(ccp);
ccp->io_map = devm_ioremap_resource(dev, ior);
if (IS_ERR(ccp->io_map)) {
@@ -115,7 +182,14 @@ static int ccp_platform_probe(struct platform_device *pdev)
goto e_err;
}
 
-   if (of_property_read_bool(dev->of_node, "dma-coherent"))
+   if (ccp_platform->use_acpi)
+   ret = ccp_acpi_support(ccp);
+   else
+   ret = ccp_of_support(ccp);
+   if (ret)
+   goto e_err;
+
+   if (ccp_platform->coherent)
ccp->axcache = CACHE_WB_NO_ALLOC;
else
ccp->axcache = CACHE_NONE;
@@ -197,15 +271,29 @@ static int ccp_platform_resume(struct platform_device 
*pdev)
 }
 #endif
 
-static const struct of_device_id ccp_platform_ids[] = {
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id ccp_acpi_match[] = {
+   { "AMDI0C00", 0 },
+   { },
+};
+#endif
+
+#ifdef CONFIG_OF
+static const struct of_device_id ccp_of_match[] = {
{ .compatible = "amd,ccp-seattle-v1a" },
{ },
 };
+#endif
 
 static struct platform_driver ccp_platform_driver = {
.driver = {
.name = "AMD Cryptographic Coprocessor",
-   .of_match_table = ccp_platform_ids,
+#ifdef CONFIG_ACPI
+   .acpi_match_table = ccp_acpi_match,
+#endif
+#ifdef CONFIG_OF
+   .of_match_table = ccp_of_match,
+#endif
},
.probe = ccp_platform_probe,
.remove = ccp_platform_remove,

--
To unsubscribe from this list: send the line "unsu

[PATCH] crypto: tcrypt speed: fix filter for aead algorithms

2015-02-03 Thread Cristian Stoica
test_aead_speed is written for sync algorithms without specifically
requiring them. The effect is that an async algorithm may be used without
setting up the request callback, this leading to a kernel panic.

Signed-off-by: Cristian Stoica 
---
 crypto/tcrypt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 4b9e23f..5dc5a25 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -314,7 +314,8 @@ static void test_aead_speed(const char *algo, int enc, 
unsigned int secs,
asg = &sg[8];
sgout = &asg[8];
 
-   tfm = crypto_alloc_aead(algo, 0, 0);
+   /* This test is not for ASYNC algorithms */
+   tfm = crypto_alloc_aead(algo, 0, CRYPTO_ALG_ASYNC);
 
if (IS_ERR(tfm)) {
pr_err("alg: aead: Failed to load transform for %s: %ld\n", 
algo,
-- 
2.0.5

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html