[PATCH v4] crypto: caam - map src buffer before access

2013-09-20 Thread Yashpal Dutta
KMap the buffers before copying trailing bytes during hmac into a session
temporary buffer. This is required if pinned buffer from user-space is send
during hmac and is safe even if hmac request is generated from within kernel.

Cc:sta...@vger.kernel.org
Signed-off-by: Yashpal Dutta 
Reviewed-by: Vakul Garg 
Reviewed-by: Horia Geanta  
---
Patch covers review comments on first version of patch.
./scripts/checkpatch.pl --strict 
0001-crypto-caam-map-src-buffer-before-access.patch 

total: 0 errors, 0 warnings, 0 checks, 62 lines checked

The patch fixes driver crashes when a pinned buffer from user-space is sent to 
CAAM driver
for HMAC processing.

Added Cc:sta...@vger.kernel.org

 drivers/crypto/caam/sg_sw_sec4.h |   34 +-
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/caam/sg_sw_sec4.h b/drivers/crypto/caam/sg_sw_sec4.h
index e0037c8..6d21a12 100644
--- a/drivers/crypto/caam/sg_sw_sec4.h
+++ b/drivers/crypto/caam/sg_sw_sec4.h
@@ -117,6 +117,21 @@ static int dma_unmap_sg_chained(struct device *dev, struct 
scatterlist *sg,
return nents;
 }
 
+/* Map SG page in kernel virtual address space and copy */
+static inline void sg_map_copy(u8 *dest, struct scatterlist *sg,
+  int len, int offset)
+{
+   u8 *mapped_addr;
+
+   /*
+* Page here can be user-space pinned using get_user_pages
+* Same must be kmapped before use and kunmapped subsequently
+*/
+   mapped_addr = kmap_atomic(sg_page(sg));
+   memcpy(dest, mapped_addr + offset, len);
+   kunmap_atomic(mapped_addr);
+}
+
 /* Copy from len bytes of sg to dest, starting from beginning */
 static inline void sg_copy(u8 *dest, struct scatterlist *sg, unsigned int len)
 {
@@ -124,15 +139,15 @@ static inline void sg_copy(u8 *dest, struct scatterlist 
*sg, unsigned int len)
int cpy_index = 0, next_cpy_index = current_sg->length;
 
while (next_cpy_index < len) {
-   memcpy(dest + cpy_index, (u8 *) sg_virt(current_sg),
-  current_sg->length);
+   sg_map_copy(dest + cpy_index, current_sg, current_sg->length,
+   current_sg->offset);
current_sg = scatterwalk_sg_next(current_sg);
cpy_index = next_cpy_index;
next_cpy_index += current_sg->length;
}
if (cpy_index < len)
-   memcpy(dest + cpy_index, (u8 *) sg_virt(current_sg),
-  len - cpy_index);
+   sg_map_copy(dest + cpy_index, current_sg, len-cpy_index,
+   current_sg->offset);
 }
 
 /* Copy sg data, from to_skip to end, to dest */
@@ -140,7 +155,7 @@ static inline void sg_copy_part(u8 *dest, struct 
scatterlist *sg,
  int to_skip, unsigned int end)
 {
struct scatterlist *current_sg = sg;
-   int sg_index, cpy_index;
+   int sg_index, cpy_index, offset;
 
sg_index = current_sg->length;
while (sg_index <= to_skip) {
@@ -148,9 +163,10 @@ static inline void sg_copy_part(u8 *dest, struct 
scatterlist *sg,
sg_index += current_sg->length;
}
cpy_index = sg_index - to_skip;
-   memcpy(dest, (u8 *) sg_virt(current_sg) +
-  current_sg->length - cpy_index, cpy_index);
-   current_sg = scatterwalk_sg_next(current_sg);
-   if (end - sg_index)
+   offset = current_sg->offset + current_sg->length - cpy_index;
+   sg_map_copy(dest, current_sg, cpy_index, offset);
+   if (end - sg_index) {
+   current_sg = scatterwalk_sg_next(current_sg);
sg_copy(dest + cpy_index, current_sg, end - sg_index);
+   }
 }
-- 
1.7.10.4


--
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


Re: [PATCH 39/51] DMA-API: others: use dma_set_coherent_mask()

2013-09-20 Thread Tejun Heo
Hey,

On Fri, Sep 20, 2013 at 03:00:18PM +0100, Russell King - ARM Linux wrote:
> Another would be if subsystem maintainers are happy that I carry them,
> I can add the acks, and then later on towards the end of the cycle,
> provide a branch subsystem maintainers could pull.
> 
> Or... if you can think of something easier...

I'm happy with the latter method and it's likely that you'll end up
carrying at least some of the patches through your tree anyway.
Please feel free to add my acks to all libata related patches and
carry them through your tree.

Thanks and have fun routing.

-- 
tejun
--
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


Re: [PATCH 0/4] ARM: NEON based fast(er) AES in CBC/CTR/XTS modes

2013-09-20 Thread Nicolas Pitre
On Fri, 20 Sep 2013, Ard Biesheuvel wrote:

> Note to reviewers:
> Reviewing the file aesbs-core.S may be a bit overwhelming, so if there are any
> questions or concerns, please refer to the link below. This is the original 
> Perl
> script that gets called by OpenSSL's build system during their build to 
> generate
> the .S file on the fly. [In the case of OpenSSL, this is used in some cases to
> target different assemblers or ABIs]. This arrangement is not suitable (or 
> required) for the kernel, so I have taken the generated .S file instead.
> 
> http://git.openssl.org/gitweb/?p=openssl.git;f=crypto/aes/asm/bsaes-armv7.pl;a=blob

You should probably capture this reference in the code, or at least in 
the commit log for the corresponding patch.

> Note to integrators:
> While this implementation is significantly faster, especially in CTR mode, it 
> is
> unclear whether the net impact on power efficiency is favorable or not, so
> please refrain from making any assumptions to that effect.

That definitively should be mentioned in the commit log for patch #4.


Nicolas
--
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 3/4] ARM: move AES typedefs and function prototypes to separate header

2013-09-20 Thread Ard Biesheuvel
Put the struct definitions for AES keys and the asm function prototypes in a
separate header and export the asm functions from the module.
This allows other drivers to use them directly.

Signed-off-by: Ard Biesheuvel 
---
 arch/arm/crypto/aes_glue.c | 22 ++
 arch/arm/crypto/aes_glue.h | 19 +++
 2 files changed, 25 insertions(+), 16 deletions(-)
 create mode 100644 arch/arm/crypto/aes_glue.h

diff --git a/arch/arm/crypto/aes_glue.c b/arch/arm/crypto/aes_glue.c
index 59f7877..3003fa1 100644
--- a/arch/arm/crypto/aes_glue.c
+++ b/arch/arm/crypto/aes_glue.c
@@ -6,22 +6,12 @@
 #include 
 #include 
 
-#define AES_MAXNR 14
+#include "aes_glue.h"
 
-typedef struct {
-   unsigned int rd_key[4 *(AES_MAXNR + 1)];
-   int rounds;
-} AES_KEY;
-
-struct AES_CTX {
-   AES_KEY enc_key;
-   AES_KEY dec_key;
-};
-
-asmlinkage void AES_encrypt(const u8 *in, u8 *out, AES_KEY *ctx);
-asmlinkage void AES_decrypt(const u8 *in, u8 *out, AES_KEY *ctx);
-asmlinkage int private_AES_set_decrypt_key(const unsigned char *userKey, const 
int bits, AES_KEY *key);
-asmlinkage int private_AES_set_encrypt_key(const unsigned char *userKey, const 
int bits, AES_KEY *key);
+EXPORT_SYMBOL(AES_encrypt);
+EXPORT_SYMBOL(AES_decrypt);
+EXPORT_SYMBOL(private_AES_set_encrypt_key);
+EXPORT_SYMBOL(private_AES_set_decrypt_key);
 
 static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 {
@@ -81,7 +71,7 @@ static struct crypto_alg aes_alg = {
.cipher = {
.cia_min_keysize= AES_MIN_KEY_SIZE,
.cia_max_keysize= AES_MAX_KEY_SIZE,
-   .cia_setkey = aes_set_key,
+   .cia_setkey = aes_set_key,
.cia_encrypt= aes_encrypt,
.cia_decrypt= aes_decrypt
}
diff --git a/arch/arm/crypto/aes_glue.h b/arch/arm/crypto/aes_glue.h
new file mode 100644
index 000..cca3e51
--- /dev/null
+++ b/arch/arm/crypto/aes_glue.h
@@ -0,0 +1,19 @@
+
+#define AES_MAXNR 14
+
+struct AES_KEY {
+   unsigned int rd_key[4 * (AES_MAXNR + 1)];
+   int rounds;
+};
+
+struct AES_CTX {
+   struct AES_KEY enc_key;
+   struct AES_KEY dec_key;
+};
+
+asmlinkage void AES_encrypt(const u8 *in, u8 *out, struct AES_KEY *ctx);
+asmlinkage void AES_decrypt(const u8 *in, u8 *out, struct AES_KEY *ctx);
+asmlinkage int private_AES_set_decrypt_key(const unsigned char *userKey,
+  const int bits, struct AES_KEY *key);
+asmlinkage int private_AES_set_encrypt_key(const unsigned char *userKey,
+  const int bits, struct AES_KEY *key);
-- 
1.8.1.2

--
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 0/4] ARM: NEON based fast(er) AES in CBC/CTR/XTS modes

2013-09-20 Thread Ard Biesheuvel
This implementation of the AES algorithm gives around 45% speedup on Cortex-A15
for CTR mode and for XTS in encryption mode. Both CBC and XTS in decryption mode
are slightly faster (5 - 10% on Cortex-A15). [As CBC in encryption mode can only
be performed sequentially, there is no speedup in this case.]

Unlike the core AES cipher (on which this module also depends), this algorithm
uses bit slicing to process up to 8 blocks in parallel in constant time. This
algorithm does not rely on any lookup tables so it is believed to be
invulnerable to cache timing attacks.

The core code has been adopted from the OpenSSL project (in collaboration
with the original author, on cc). For ease of maintenance, this version is
identical to the upstream OpenSSL code, i.e., all modifications that were
required to make it suitable for inclusion into the kernel have already been
merged upstream.

This code passes the builtin test 'modprobe tcrypt.ko mode=10' in both ARM and
Thumb-2 modes.

Note to reviewers:
Reviewing the file aesbs-core.S may be a bit overwhelming, so if there are any
questions or concerns, please refer to the link below. This is the original Perl
script that gets called by OpenSSL's build system during their build to generate
the .S file on the fly. [In the case of OpenSSL, this is used in some cases to
target different assemblers or ABIs]. This arrangement is not suitable (or 
required) for the kernel, so I have taken the generated .S file instead.

http://git.openssl.org/gitweb/?p=openssl.git;f=crypto/aes/asm/bsaes-armv7.pl;a=blob


Note to integrators:
While this implementation is significantly faster, especially in CTR mode, it is
unclear whether the net impact on power efficiency is favorable or not, so
please refrain from making any assumptions to that effect.


Ard Biesheuvel (4):
  crypto: create generic version of ablk_helper
  ARM: pull in  from asm-generic
  ARM: move AES typedefs and function prototypes to separate header
  ARM: add support for bit sliced AES using NEON instructions

 arch/arm/crypto/Makefile |6 +-
 arch/arm/crypto/aes_glue.c   |   22 +-
 arch/arm/crypto/aes_glue.h   |   19 +
 arch/arm/crypto/aesbs-core.S | 2603 ++
 arch/arm/crypto/aesbs-glue.c |  449 
 arch/arm/include/asm/Kbuild  |1 +
 crypto/Kconfig   |   20 +
 crypto/Makefile  |1 +
 crypto/ablk_helper.c |  150 +++
 include/asm-generic/simd.h   |   14 +
 include/crypto/ablk_helper.h |   31 +
 11 files changed, 3298 insertions(+), 18 deletions(-)
 create mode 100644 arch/arm/crypto/aes_glue.h
 create mode 100644 arch/arm/crypto/aesbs-core.S
 create mode 100644 arch/arm/crypto/aesbs-glue.c
 create mode 100644 crypto/ablk_helper.c
 create mode 100644 include/asm-generic/simd.h
 create mode 100644 include/crypto/ablk_helper.h

-- 
1.8.1.2

--
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 2/4] ARM: pull in from asm-generic

2013-09-20 Thread Ard Biesheuvel
Signed-off-by: Ard Biesheuvel 
---
 arch/arm/include/asm/Kbuild | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild
index d3db398..6577b8a 100644
--- a/arch/arm/include/asm/Kbuild
+++ b/arch/arm/include/asm/Kbuild
@@ -24,6 +24,7 @@ generic-y += sembuf.h
 generic-y += serial.h
 generic-y += shmbuf.h
 generic-y += siginfo.h
+generic-y += simd.h
 generic-y += sizes.h
 generic-y += socket.h
 generic-y += sockios.h
-- 
1.8.1.2

--
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 1/4] crypto: create generic version of ablk_helper

2013-09-20 Thread Ard Biesheuvel
Create a generic version of ablk_helper so it can be reused
by other architectures.

Acked-by: Jussi Kivilinna 
Signed-off-by: Ard Biesheuvel 
---
 crypto/Kconfig   |   4 ++
 crypto/Makefile  |   1 +
 crypto/ablk_helper.c | 150 +++
 include/asm-generic/simd.h   |  14 
 include/crypto/ablk_helper.h |  31 +
 5 files changed, 200 insertions(+)
 create mode 100644 crypto/ablk_helper.c
 create mode 100644 include/asm-generic/simd.h
 create mode 100644 include/crypto/ablk_helper.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 69ce573..8179ae6 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -179,6 +179,10 @@ config CRYPTO_ABLK_HELPER_X86
depends on X86
select CRYPTO_CRYPTD
 
+config CRYPTO_ABLK_HELPER
+   tristate
+   select CRYPTO_CRYPTD
+
 config CRYPTO_GLUE_HELPER_X86
tristate
depends on X86
diff --git a/crypto/Makefile b/crypto/Makefile
index 80019ba..5e1bdb1 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -104,3 +104,4 @@ obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o
 obj-$(CONFIG_XOR_BLOCKS) += xor.o
 obj-$(CONFIG_ASYNC_CORE) += async_tx/
 obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/
+obj-$(CONFIG_CRYPTO_ABLK_HELPER) += ablk_helper.o
diff --git a/crypto/ablk_helper.c b/crypto/ablk_helper.c
new file mode 100644
index 000..62568b1
--- /dev/null
+++ b/crypto/ablk_helper.c
@@ -0,0 +1,150 @@
+/*
+ * Shared async block cipher helpers
+ *
+ * Copyright (c) 2012 Jussi Kivilinna 
+ *
+ * Based on aesni-intel_glue.c by:
+ *  Copyright (C) 2008, Intel Corp.
+ *Author: Huang Ying 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
+unsigned int key_len)
+{
+   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+   struct crypto_ablkcipher *child = &ctx->cryptd_tfm->base;
+   int err;
+
+   crypto_ablkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
+   crypto_ablkcipher_set_flags(child, crypto_ablkcipher_get_flags(tfm)
+   & CRYPTO_TFM_REQ_MASK);
+   err = crypto_ablkcipher_setkey(child, key, key_len);
+   crypto_ablkcipher_set_flags(tfm, crypto_ablkcipher_get_flags(child)
+   & CRYPTO_TFM_RES_MASK);
+   return err;
+}
+EXPORT_SYMBOL_GPL(ablk_set_key);
+
+int __ablk_encrypt(struct ablkcipher_request *req)
+{
+   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+   struct blkcipher_desc desc;
+
+   desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
+   desc.info = req->info;
+   desc.flags = 0;
+
+   return crypto_blkcipher_crt(desc.tfm)->encrypt(
+   &desc, req->dst, req->src, req->nbytes);
+}
+EXPORT_SYMBOL_GPL(__ablk_encrypt);
+
+int ablk_encrypt(struct ablkcipher_request *req)
+{
+   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+   if (!may_use_simd()) {
+   struct ablkcipher_request *cryptd_req =
+   ablkcipher_request_ctx(req);
+
+   memcpy(cryptd_req, req, sizeof(*req));
+   ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
+
+   return crypto_ablkcipher_encrypt(cryptd_req);
+   } else {
+   return __ablk_encrypt(req);
+   }
+}
+EXPORT_SYMBOL_GPL(ablk_encrypt);
+
+int ablk_decrypt(struct ablkcipher_request *req)
+{
+   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+   if (!may_use_simd()) {
+   struct ablkcipher_request *cryptd_req =
+   ablkcipher_request_ctx(req);
+
+   memcpy(cryptd_req, req, sizeof(*req));
+   ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
+
+   return crypto_ablkcipher_decrypt(cryptd_req);
+   } else {
+   struct blkcipher_desc desc;
+
+   desc.tfm = cry

Re: [PATCH 24/51] DMA-API: dma: pl330: add dma_set_mask_and_coherent() call

2013-09-20 Thread Heiko Stübner
Am Donnerstag, 19. September 2013, 23:49:01 schrieb Russell King:
> The DMA API requires drivers to call the appropriate dma_set_mask()
> functions before doing any DMA mapping.  Add this required call to
> the AMBA PL08x driver.
^--- copy and paste error - should of course be PL330


> Signed-off-by: Russell King 
> ---
>  drivers/dma/pl330.c |4 
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
> index a562d24..df8b10f 100644
> --- a/drivers/dma/pl330.c
> +++ b/drivers/dma/pl330.c
> @@ -2903,6 +2903,10 @@ pl330_probe(struct amba_device *adev, const struct
> amba_id *id)
> 
>   pdat = dev_get_platdata(&adev->dev);
> 
> + ret = dma_set_mask_and_coherent(&adev->dev, DMA_BIT_MASK(32));
> + if (ret)
> + return ret;
> +
>   /* Allocate a new DMAC and its Channels */
>   pdmac = devm_kzalloc(&adev->dev, sizeof(*pdmac), GFP_KERNEL);
>   if (!pdmac) {

--
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


Re: [PATCH v3] crypto: caam - map src buffer before access

2013-09-20 Thread Greg KH
On Fri, Sep 20, 2013 at 11:24:07PM +0530, Yashpal Dutta wrote:
> KMap the buffers before copying trailing bytes during hmac into a session
> temporary buffer. This is required if pinned buffer from user-space is send
> during hmac and is safe even if hmac request is generated from within kernel.
> 
> Signed-off-by: Yashpal Dutta 
> Reviewed-by: Vakul Garg 
> Reviewed-by: Horia Geanta  
> ---
> Patch covers review comments on first version of patch.
> ./scripts/checkpatch.pl --strict 
> 0001-crypto-caam-map-src-buffer-before-access.patch 
> 
> total: 0 errors, 0 warnings, 0 checks, 62 lines checked
> 
> The patch fixes driver crashes when a pinned buffer from user-space is sent 
> to CAAM driver
> for HMAC processing.
> 
>  drivers/crypto/caam/sg_sw_sec4.h |   34 +-
>  1 file changed, 25 insertions(+), 9 deletions(-)




This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
for how to do this properly.


--
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


Re: [PATCH 42/51] DMA-API: usb: musb: use platform_device_register_full() to avoid directly messing with dma masks

2013-09-20 Thread Felipe Balbi
Hi,

On Fri, Sep 20, 2013 at 02:49:38PM +0100, Russell King - ARM Linux wrote:
> On Fri, Sep 20, 2013 at 08:11:25AM -0500, Felipe Balbi wrote:
> > Hi,
> > 
> > On Fri, Sep 20, 2013 at 12:14:38AM +0100, Russell King wrote:
> > > Use platform_device_register_full() for those drivers which can, to
> > > avoid messing directly with DMA masks.  This can only be done when
> > > the driver does not need to access the allocated musb platform device
> > > from within its callbacks, which may be called during the musb
> > > device probing.
> > > 
> > > Signed-off-by: Russell King 
> > 
> > you want me to carry this one through my tree or you prefer getting my
> > Acked-by ? Either way works for me:
> > 
> > Acked-by: Felipe Balbi 
> > 
> > there's also the third option of me setting up a branch with only this
> > patch and we both merge it, that'd also work.
> 
> I think this patch is sufficiently stand-alone that it should be fine
> if you want to take it through your tree.  That may be better in the
> long run to avoid conflicts with this patch and any future work in
> this area during this cycle.

awesome, i'll take this one early next week.

-- 
balbi


signature.asc
Description: Digital signature


[PATCH 16/51] DMA-API: ppc: vio.c: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 arch/powerpc/kernel/vio.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index 78a3506..96b6c97 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -1413,8 +1413,7 @@ struct vio_dev *vio_register_device_node(struct 
device_node *of_node)
 
/* needed to ensure proper operation of coherent allocations
 * later, in case driver doesn't set it explicitly */
-   dma_set_mask(&viodev->dev, DMA_BIT_MASK(64));
-   dma_set_coherent_mask(&viodev->dev, DMA_BIT_MASK(64));
+   dma_set_mask_and_coherent(&viodev->dev, DMA_BIT_MASK(64));
}
 
/* register with generic device framework */
-- 
1.7.4.4

--
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 23/51] DMA-API: dma: pl08x: add dma_set_mask_and_coherent() call

2013-09-20 Thread Russell King
The DMA API requires drivers to call the appropriate dma_set_mask()
functions before doing any DMA mapping.  Add this required call to
the AMBA PL08x driver.

Signed-off-by: Russell King 
---
 drivers/dma/amba-pl08x.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/dma/amba-pl08x.c b/drivers/dma/amba-pl08x.c
index fce46c5..e51a983 100644
--- a/drivers/dma/amba-pl08x.c
+++ b/drivers/dma/amba-pl08x.c
@@ -2055,6 +2055,11 @@ static int pl08x_probe(struct amba_device *adev, const 
struct amba_id *id)
if (ret)
return ret;
 
+   /* Ensure that we can do DMA */
+   ret = dma_set_mask_and_coherent(&adev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   goto out_no_pl08x;
+
/* Create the driver state holder */
pl08x = kzalloc(sizeof(*pl08x), GFP_KERNEL);
if (!pl08x) {
-- 
1.7.4.4

--
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


Re: [PATCH 01/51] DMA-API: provide a helper to set both DMA and coherent DMA masks

2013-09-20 Thread Russell King - ARM Linux
On Fri, Sep 20, 2013 at 02:21:37AM +0100, Ben Hutchings wrote:
> On Thu, 2013-09-19 at 22:25 +0100, Russell King wrote:
> [...]
> > -dma_set_coherent_mask() will always be able to set the same or a
> > -smaller mask as dma_set_mask(). However for the rare case that a
> > +The coherent coherent mask will always be able to set the same or a
> > +smaller mask as the streaming mask. However for the rare case that a
> [...]
> 
> The new wording doesn't make sense; a mask doesn't set itself.  I would
> suggest:
> 
> "The coherent mask can always be set to the same or a smaller mask than
> the streaming mask."

Yes, the original sentence is not particularly good, but I think even
your modified version can be interpreted as "a mask setting itself"
for all the same reasons that the original can be (which mask does "same"
refer to?)

Even so, I prefer your version.  Thanks. :)
--
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


Re: [PATCH 39/51] DMA-API: others: use dma_set_coherent_mask()

2013-09-20 Thread Russell King - ARM Linux
On Fri, Sep 20, 2013 at 07:16:52AM -0500, Tejun Heo wrote:
> On Fri, Sep 20, 2013 at 12:11:38AM +0100, Russell King wrote:
> > The correct way for a driver to specify the coherent DMA mask is
> > not to directly access the field in the struct device, but to use
> > dma_set_coherent_mask().  Only arch and bus code should access this
> > member directly.
> > 
> > Convert all direct write accesses to using the correct API.
> > 
> > Signed-off-by: Russell King 
> 
> Acked-by: Tejun Heo 
> 
> The patch is pretty widely spread.  I don't mind how it gets routed
> but what's the plan?

The plan is... I'm going to try and avoid going through the hell of
re-posting this patch series to all the recipients another time...
(It's taken some 17 hours and lots of hand holding to get this patch
set out without exim jumping off a cliff into deep OOM - soo deep that
even the OOM killer doesn't run and the CPU is 100% idle because
every single process stuck in an uninterruptible sleep waiting for
every other process to free some memory - ouch!)

I know that dealing with this patch set will be a problem due to how
widespread this is, but much of the driver level changes come down to
depending on a couple of patches.  One solution would be if I published
a branch with just the dependencies in, which subsystem maintainers
could pull, and then apply the appropriate patches on top.

Another would be if subsystem maintainers are happy that I carry them,
I can add the acks, and then later on towards the end of the cycle,
provide a branch subsystem maintainers could pull.

Or... if you can think of something easier...
--
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


Re: [PATCH 42/51] DMA-API: usb: musb: use platform_device_register_full() to avoid directly messing with dma masks

2013-09-20 Thread Russell King - ARM Linux
On Fri, Sep 20, 2013 at 08:11:25AM -0500, Felipe Balbi wrote:
> Hi,
> 
> On Fri, Sep 20, 2013 at 12:14:38AM +0100, Russell King wrote:
> > Use platform_device_register_full() for those drivers which can, to
> > avoid messing directly with DMA masks.  This can only be done when
> > the driver does not need to access the allocated musb platform device
> > from within its callbacks, which may be called during the musb
> > device probing.
> > 
> > Signed-off-by: Russell King 
> 
> you want me to carry this one through my tree or you prefer getting my
> Acked-by ? Either way works for me:
> 
> Acked-by: Felipe Balbi 
> 
> there's also the third option of me setting up a branch with only this
> patch and we both merge it, that'd also work.

I think this patch is sufficiently stand-alone that it should be fine
if you want to take it through your tree.  That may be better in the
long run to avoid conflicts with this patch and any future work in
this area during this cycle.

Thanks.
--
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


Re: [PATCH 42/51] DMA-API: usb: musb: use platform_device_register_full() to avoid directly messing with dma masks

2013-09-20 Thread Felipe Balbi
Hi,

On Fri, Sep 20, 2013 at 12:14:38AM +0100, Russell King wrote:
> Use platform_device_register_full() for those drivers which can, to
> avoid messing directly with DMA masks.  This can only be done when
> the driver does not need to access the allocated musb platform device
> from within its callbacks, which may be called during the musb
> device probing.
> 
> Signed-off-by: Russell King 

you want me to carry this one through my tree or you prefer getting my
Acked-by ? Either way works for me:

Acked-by: Felipe Balbi 

there's also the third option of me setting up a branch with only this
patch and we both merge it, that'd also work.

cheers

-- 
balbi


signature.asc
Description: Digital signature


[PATCH 09/51] DMA-API: net: broadcom/b44: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/net/ethernet/broadcom/b44.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/b44.c 
b/drivers/net/ethernet/broadcom/b44.c
index 9b017d9..b4d2018 100644
--- a/drivers/net/ethernet/broadcom/b44.c
+++ b/drivers/net/ethernet/broadcom/b44.c
@@ -2183,8 +2183,7 @@ static int b44_init_one(struct ssb_device *sdev,
goto err_out_free_dev;
}
 
-   if (dma_set_mask(sdev->dma_dev, DMA_BIT_MASK(30)) ||
-   dma_set_coherent_mask(sdev->dma_dev, DMA_BIT_MASK(30))) {
+   if (dma_set_mask_and_coherent(sdev->dma_dev, DMA_BIT_MASK(30))) {
dev_err(sdev->dev,
"Required 30BIT DMA mask unsupported by the system\n");
goto err_out_powerdown;
-- 
1.7.4.4

--
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 38/51] DMA-API: staging: use dma_set_coherent_mask()

2013-09-20 Thread Russell King
The correct way for a driver to specify the coherent DMA mask is
not to directly access the field in the struct device, but to use
dma_set_coherent_mask().  Only arch and bus code should access this
member directly.

Convert all direct write accesses to using the correct API.

Signed-off-by: Russell King 
---
 drivers/staging/dwc2/platform.c|5 +++--
 drivers/staging/imx-drm/imx-drm-core.c |8 ++--
 drivers/staging/imx-drm/ipuv3-crtc.c   |4 +++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/dwc2/platform.c b/drivers/staging/dwc2/platform.c
index 44cce2f..1d68c49 100644
--- a/drivers/staging/dwc2/platform.c
+++ b/drivers/staging/dwc2/platform.c
@@ -100,8 +100,9 @@ static int dwc2_driver_probe(struct platform_device *dev)
 */
if (!dev->dev.dma_mask)
dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
-   if (!dev->dev.coherent_dma_mask)
-   dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   retval = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
+   if (retval)
+   return retval;
 
irq = platform_get_irq(dev, 0);
if (irq < 0) {
diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 47c5888..847f430 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -805,6 +805,12 @@ static struct drm_driver imx_drm_driver = {
 
 static int imx_drm_platform_probe(struct platform_device *pdev)
 {
+   int ret;
+
+   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
+
imx_drm_device->dev = &pdev->dev;
 
return drm_platform_init(&imx_drm_driver, pdev);
@@ -847,8 +853,6 @@ static int __init imx_drm_init(void)
goto err_pdev;
}
 
-   imx_drm_pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32),
-
ret = platform_driver_register(&imx_drm_pdrv);
if (ret)
goto err_pdrv;
diff --git a/drivers/staging/imx-drm/ipuv3-crtc.c 
b/drivers/staging/imx-drm/ipuv3-crtc.c
index 6fd37a7..9e73e8d 100644
--- a/drivers/staging/imx-drm/ipuv3-crtc.c
+++ b/drivers/staging/imx-drm/ipuv3-crtc.c
@@ -523,7 +523,9 @@ static int ipu_drm_probe(struct platform_device *pdev)
if (!pdata)
return -EINVAL;
 
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
 
ipu_crtc = devm_kzalloc(&pdev->dev, sizeof(*ipu_crtc), GFP_KERNEL);
if (!ipu_crtc)
-- 
1.7.4.4

--
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 37/51] DMA-API: usb: use new dma_coerce_mask_and_coherent()

2013-09-20 Thread Russell King
Signed-off-by: Russell King 
---
 drivers/usb/chipidea/ci_hdrc_imx.c |4 +---
 drivers/usb/dwc3/dwc3-exynos.c |4 +---
 drivers/usb/host/ehci-atmel.c  |4 +---
 drivers/usb/host/ehci-omap.c   |4 +---
 drivers/usb/host/ehci-orion.c  |4 +---
 drivers/usb/host/ehci-platform.c   |5 ++---
 drivers/usb/host/ehci-s5p.c|4 +---
 drivers/usb/host/ehci-spear.c  |4 +---
 drivers/usb/host/ehci-tegra.c  |4 +---
 drivers/usb/host/ohci-at91.c   |4 +---
 drivers/usb/host/ohci-exynos.c |4 +---
 drivers/usb/host/ohci-nxp.c|3 +--
 drivers/usb/host/ohci-octeon.c |3 +--
 drivers/usb/host/ohci-omap3.c  |4 +---
 drivers/usb/host/ohci-pxa27x.c |4 +---
 drivers/usb/host/ohci-spear.c  |4 +---
 drivers/usb/host/uhci-platform.c   |4 +---
 17 files changed, 18 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index bf33bd3..af731db 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -121,9 +121,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 
pdata.phy = data->phy;
 
-   if (!pdev->dev.dma_mask)
-   pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
-   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
if (ret)
goto err_clk;
 
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index c10b324..8b20c70 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -119,9 +119,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 * Since shared usb code relies on it, set it here for now.
 * Once we move to full device tree support this will vanish off.
 */
-   if (!dev->dma_mask)
-   dev->dma_mask = &dev->coherent_dma_mask;
-   ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
+   ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
if (ret)
goto err1;
 
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index 5831a88..8e7323e 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -90,9 +90,7 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev)
 * Since shared usb code relies on it, set it here for now.
 * Once we have dma capability bindings this can go away.
 */
-   if (!pdev->dev.dma_mask)
-   pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
-   retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
if (retval)
goto fail_create_hcd;
 
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index d0759c5..6fa82d6 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -144,9 +144,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
 * Since shared usb code relies on it, set it here for now.
 * Once we have dma capability bindings this can go away.
 */
-   if (!dev->dma_mask)
-   dev->dma_mask = &dev->coherent_dma_mask;
-   ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
+   ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
if (ret)
return ret;
 
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 5870206..2ba7673 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -180,9 +180,7 @@ static int ehci_orion_drv_probe(struct platform_device 
*pdev)
 * set. Since shared usb code relies on it, set it here for
 * now. Once we have dma capability bindings this can go away.
 */
-   if (!pdev->dev.dma_mask)
-   pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
-   err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
if (err)
goto err1;
 
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index 5b0cd2d..7f30b71 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -89,9 +89,8 @@ static int ehci_platform_probe(struct platform_device *dev)
 */
if (!dev_get_platdata(&dev->dev))
dev->dev.platform_data = &ehci_platform_defaults;
-   if (!dev->dev.dma_mask)
-   dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
-   err = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
+
+   err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
if (err)
return err;
 
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
index 10d6a2e

[PATCH v3] crypto: caam - map src buffer before access

2013-09-20 Thread Yashpal Dutta
KMap the buffers before copying trailing bytes during hmac into a session
temporary buffer. This is required if pinned buffer from user-space is send
during hmac and is safe even if hmac request is generated from within kernel.

Signed-off-by: Yashpal Dutta 
Reviewed-by: Vakul Garg 
Reviewed-by: Horia Geanta  
---
Patch covers review comments on first version of patch.
./scripts/checkpatch.pl --strict 
0001-crypto-caam-map-src-buffer-before-access.patch 

total: 0 errors, 0 warnings, 0 checks, 62 lines checked

The patch fixes driver crashes when a pinned buffer from user-space is sent to 
CAAM driver
for HMAC processing.

 drivers/crypto/caam/sg_sw_sec4.h |   34 +-
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/caam/sg_sw_sec4.h b/drivers/crypto/caam/sg_sw_sec4.h
index e0037c8..6d21a12 100644
--- a/drivers/crypto/caam/sg_sw_sec4.h
+++ b/drivers/crypto/caam/sg_sw_sec4.h
@@ -117,6 +117,21 @@ static int dma_unmap_sg_chained(struct device *dev, struct 
scatterlist *sg,
return nents;
 }
 
+/* Map SG page in kernel virtual address space and copy */
+static inline void sg_map_copy(u8 *dest, struct scatterlist *sg,
+  int len, int offset)
+{
+   u8 *mapped_addr;
+
+   /*
+* Page here can be user-space pinned using get_user_pages
+* Same must be kmapped before use and kunmapped subsequently
+*/
+   mapped_addr = kmap_atomic(sg_page(sg));
+   memcpy(dest, mapped_addr + offset, len);
+   kunmap_atomic(mapped_addr);
+}
+
 /* Copy from len bytes of sg to dest, starting from beginning */
 static inline void sg_copy(u8 *dest, struct scatterlist *sg, unsigned int len)
 {
@@ -124,15 +139,15 @@ static inline void sg_copy(u8 *dest, struct scatterlist 
*sg, unsigned int len)
int cpy_index = 0, next_cpy_index = current_sg->length;
 
while (next_cpy_index < len) {
-   memcpy(dest + cpy_index, (u8 *) sg_virt(current_sg),
-  current_sg->length);
+   sg_map_copy(dest + cpy_index, current_sg, current_sg->length,
+   current_sg->offset);
current_sg = scatterwalk_sg_next(current_sg);
cpy_index = next_cpy_index;
next_cpy_index += current_sg->length;
}
if (cpy_index < len)
-   memcpy(dest + cpy_index, (u8 *) sg_virt(current_sg),
-  len - cpy_index);
+   sg_map_copy(dest + cpy_index, current_sg, len-cpy_index,
+   current_sg->offset);
 }
 
 /* Copy sg data, from to_skip to end, to dest */
@@ -140,7 +155,7 @@ static inline void sg_copy_part(u8 *dest, struct 
scatterlist *sg,
  int to_skip, unsigned int end)
 {
struct scatterlist *current_sg = sg;
-   int sg_index, cpy_index;
+   int sg_index, cpy_index, offset;
 
sg_index = current_sg->length;
while (sg_index <= to_skip) {
@@ -148,9 +163,10 @@ static inline void sg_copy_part(u8 *dest, struct 
scatterlist *sg,
sg_index += current_sg->length;
}
cpy_index = sg_index - to_skip;
-   memcpy(dest, (u8 *) sg_virt(current_sg) +
-  current_sg->length - cpy_index, cpy_index);
-   current_sg = scatterwalk_sg_next(current_sg);
-   if (end - sg_index)
+   offset = current_sg->offset + current_sg->length - cpy_index;
+   sg_map_copy(dest, current_sg, cpy_index, offset);
+   if (end - sg_index) {
+   current_sg = scatterwalk_sg_next(current_sg);
sg_copy(dest + cpy_index, current_sg, end - sg_index);
+   }
 }
-- 
1.7.10.4


--
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 36/51] DMA-API: usb: use dma_set_coherent_mask()

2013-09-20 Thread Russell King
The correct way for a driver to specify the coherent DMA mask is
not to directly access the field in the struct device, but to use
dma_set_coherent_mask().  Only arch and bus code should access this
member directly.

Convert all direct write accesses to using the correct API.

Signed-off-by: Russell King 
---
 drivers/usb/chipidea/ci_hdrc_imx.c |5 +++--
 drivers/usb/dwc3/dwc3-exynos.c |5 +++--
 drivers/usb/gadget/lpc32xx_udc.c   |4 +++-
 drivers/usb/host/ehci-atmel.c  |5 +++--
 drivers/usb/host/ehci-octeon.c |4 +++-
 drivers/usb/host/ehci-omap.c   |8 +---
 drivers/usb/host/ehci-orion.c  |5 +++--
 drivers/usb/host/ehci-platform.c   |7 ---
 drivers/usb/host/ehci-s5p.c|5 +++--
 drivers/usb/host/ehci-spear.c  |5 +++--
 drivers/usb/host/ehci-tegra.c  |5 +++--
 drivers/usb/host/ohci-at91.c   |7 ---
 drivers/usb/host/ohci-exynos.c |5 +++--
 drivers/usb/host/ohci-nxp.c|4 +++-
 drivers/usb/host/ohci-octeon.c |4 +++-
 drivers/usb/host/ohci-omap3.c  |8 +---
 drivers/usb/host/ohci-pxa27x.c |6 --
 drivers/usb/host/ohci-spear.c  |5 +++--
 drivers/usb/host/uhci-platform.c   |5 +++--
 19 files changed, 64 insertions(+), 38 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index 74d998d..bf33bd3 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -123,8 +123,9 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 
if (!pdev->dev.dma_mask)
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
-   if (!pdev->dev.coherent_dma_mask)
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   goto err_clk;
 
if (data->usbmisc_data) {
ret = imx_usbmisc_init(data->usbmisc_data);
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index 2f2e88a..c10b324 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -121,8 +121,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 */
if (!dev->dma_mask)
dev->dma_mask = &dev->coherent_dma_mask;
-   if (!dev->coherent_dma_mask)
-   dev->coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
+   if (ret)
+   goto err1;
 
platform_set_drvdata(pdev, exynos);
 
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index 67128be..6a2a65a 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -3078,7 +3078,9 @@ static int __init lpc32xx_udc_probe(struct 
platform_device *pdev)
 udc->isp1301_i2c_client->addr);
 
pdev->dev.dma_mask = &lpc32xx_usbd_dmamask;
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (retval)
+   goto resource_fail;
 
udc->board = &lpc32xx_usbddata;
 
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index 3b645ff..5831a88 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -92,8 +92,9 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev)
 */
if (!pdev->dev.dma_mask)
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
-   if (!pdev->dev.coherent_dma_mask)
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (retval)
+   goto fail_create_hcd;
 
hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
if (!hcd) {
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c
index ab0397e..4c528b2 100644
--- a/drivers/usb/host/ehci-octeon.c
+++ b/drivers/usb/host/ehci-octeon.c
@@ -116,8 +116,10 @@ static int ehci_octeon_drv_probe(struct platform_device 
*pdev)
 * We can DMA from anywhere. But the descriptors must be in
 * the lower 4GB.
 */
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
pdev->dev.dma_mask = &ehci_octeon_dma_mask;
+   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
 
hcd = usb_create_hcd(&ehci_octeon_hc_driver, &pdev->dev, "octeon");
if (!hcd)
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 78b01fa..d0759c5 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -104,7 +104,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
struct resource *res;
struct usb_hcd  *hcd;
void __iomem *regs;
-   int ret = -ENODEV;
+   int ret;
int irq;
 

[PATCH 34/51] DMA-API: net: octeon: use dma_coerce_mask_and_coherent()

2013-09-20 Thread Russell King
The code sequence:
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
bypasses the architectures check on the DMA mask.  It can be replaced
with dma_coerce_mask_and_coherent(), avoiding the direct initialization
of this mask.

Signed-off-by: Russell King 
---
 drivers/net/ethernet/octeon/octeon_mgmt.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/octeon/octeon_mgmt.c 
b/drivers/net/ethernet/octeon/octeon_mgmt.c
index 622aa75..2006a07 100644
--- a/drivers/net/ethernet/octeon/octeon_mgmt.c
+++ b/drivers/net/ethernet/octeon/octeon_mgmt.c
@@ -1552,8 +1552,9 @@ static int octeon_mgmt_probe(struct platform_device *pdev)
 
p->phy_np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
 
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
-   pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
+   result = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+   if (result)
+   goto err;
 
netif_carrier_off(netdev);
result = register_netdev(netdev);
-- 
1.7.4.4

--
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 33/51] DMA-API: net: nxp/lpc_eth: use dma_coerce_mask_and_coherent()

2013-09-20 Thread Russell King
The code sequence:
pldat->pdev->dev.coherent_dma_mask = 0x;
pldat->pdev->dev.dma_mask = &pldat->pdev->dev.coherent_dma_mask;
bypasses the architectures check on the DMA mask.  It can be replaced
with dma_coerce_mask_and_coherent(), avoiding the direct initialization
of this mask.

Signed-off-by: Russell King 
---
 drivers/net/ethernet/nxp/lpc_eth.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/nxp/lpc_eth.c 
b/drivers/net/ethernet/nxp/lpc_eth.c
index a061b93..ba3ca18 100644
--- a/drivers/net/ethernet/nxp/lpc_eth.c
+++ b/drivers/net/ethernet/nxp/lpc_eth.c
@@ -1399,8 +1399,10 @@ static int lpc_eth_drv_probe(struct platform_device 
*pdev)
}
 
if (pldat->dma_buff_base_v == 0) {
-   pldat->pdev->dev.coherent_dma_mask = 0x;
-   pldat->pdev->dev.dma_mask = &pldat->pdev->dev.coherent_dma_mask;
+   ret = dma_coerce_mask_and_coherent(&pdev->dev, 
DMA_BIT_MASK(32));
+   if (ret)
+   goto err_out_free_irq;
+
pldat->dma_buff_size = PAGE_ALIGN(pldat->dma_buff_size);
 
/* Allocate a chunk of memory for the DMA ethernet buffers
-- 
1.7.4.4

--
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 32/51] DMA-API: mmc: sdhci-acpi: use dma_coerce_mask_and_coherent()

2013-09-20 Thread Russell King
The code sequence:
dev->dma_mask = &dev->coherent_dma_mask;
dev->coherent_dma_mask = dma_mask;
bypasses the architectures check on the DMA mask.  It can be replaced
with dma_coerce_mask_and_coherent(), avoiding the direct initialization
of this mask.

Signed-off-by: Russell King 
---
 drivers/mmc/host/sdhci-acpi.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index cdd4ce0..ef19874 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -310,8 +310,9 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
dma_mask = DMA_BIT_MASK(32);
}
 
-   dev->dma_mask = &dev->coherent_dma_mask;
-   dev->coherent_dma_mask = dma_mask;
+   err = dma_coerce_mask_and_coherent(dev, dma_mask);
+   if (err)
+   goto err_free;
}
 
if (c->slot) {
-- 
1.7.4.4

--
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 14/51] DMA-API: net: b43: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/net/wireless/b43/dma.c |9 +++--
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c
index c51d2dc..1d7982a 100644
--- a/drivers/net/wireless/b43/dma.c
+++ b/drivers/net/wireless/b43/dma.c
@@ -1065,12 +1065,9 @@ static int b43_dma_set_mask(struct b43_wldev *dev, u64 
mask)
/* Try to set the DMA mask. If it fails, try falling back to a
 * lower mask, as we can always also support a lower one. */
while (1) {
-   err = dma_set_mask(dev->dev->dma_dev, mask);
-   if (!err) {
-   err = dma_set_coherent_mask(dev->dev->dma_dev, mask);
-   if (!err)
-   break;
-   }
+   err = dma_set_mask_and_coherent(dev->dev->dma_dev, mask);
+   if (!err)
+   break;
if (mask == DMA_BIT_MASK(64)) {
mask = DMA_BIT_MASK(32);
fallback = true;
-- 
1.7.4.4

--
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


Re: [PATCH 39/51] DMA-API: others: use dma_set_coherent_mask()

2013-09-20 Thread Tejun Heo
On Fri, Sep 20, 2013 at 07:16:52AM -0500, Tejun Heo wrote:
> On Fri, Sep 20, 2013 at 12:11:38AM +0100, Russell King wrote:
> > The correct way for a driver to specify the coherent DMA mask is
> > not to directly access the field in the struct device, but to use
> > dma_set_coherent_mask().  Only arch and bus code should access this
> > member directly.
> > 
> > Convert all direct write accesses to using the correct API.
> > 
> > Signed-off-by: Russell King 
> 
> Acked-by: Tejun Heo 
> 
> The patch is pretty widely spread.  I don't mind how it gets routed
> but what's the plan?

Hmm... maybe hte pata_ixp4xx_cf.c part should be moved to the one
which updates pata_octeon_cf.c?

Thanks.

-- 
tejun
--
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


Re: [PATCH 39/51] DMA-API: others: use dma_set_coherent_mask()

2013-09-20 Thread Tejun Heo
On Fri, Sep 20, 2013 at 12:11:38AM +0100, Russell King wrote:
> The correct way for a driver to specify the coherent DMA mask is
> not to directly access the field in the struct device, but to use
> dma_set_coherent_mask().  Only arch and bus code should access this
> member directly.
> 
> Convert all direct write accesses to using the correct API.
> 
> Signed-off-by: Russell King 

Acked-by: Tejun Heo 

The patch is pretty widely spread.  I don't mind how it gets routed
but what's the plan?

Thanks.

-- 
tejun
--
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 31/51] DMA-API: media: omap3isp: use dma_coerce_mask_and_coherent()

2013-09-20 Thread Russell King
The code sequence:
isp->raw_dmamask = DMA_BIT_MASK(32);
isp->dev->dma_mask = &isp->raw_dmamask;
isp->dev->coherent_dma_mask = DMA_BIT_MASK(32);
bypasses the architectures check on the DMA mask.  It can be replaced
with dma_coerce_mask_and_coherent(), avoiding the direct initialization
of this mask.

Signed-off-by: Russell King 
---
 drivers/media/platform/omap3isp/isp.c |6 +++---
 drivers/media/platform/omap3isp/isp.h |3 ---
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/omap3isp/isp.c 
b/drivers/media/platform/omap3isp/isp.c
index df3a0ec..1c36080 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -2182,9 +2182,9 @@ static int isp_probe(struct platform_device *pdev)
isp->pdata = pdata;
isp->ref_count = 0;
 
-   isp->raw_dmamask = DMA_BIT_MASK(32);
-   isp->dev->dma_mask = &isp->raw_dmamask;
-   isp->dev->coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_coerce_mask_and_coherent(isp->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
 
platform_set_drvdata(pdev, isp);
 
diff --git a/drivers/media/platform/omap3isp/isp.h 
b/drivers/media/platform/omap3isp/isp.h
index cd3eff4..ce65d3a 100644
--- a/drivers/media/platform/omap3isp/isp.h
+++ b/drivers/media/platform/omap3isp/isp.h
@@ -152,7 +152,6 @@ struct isp_xclk {
  * @mmio_base_phys: Array with physical L4 bus addresses for ISP register
  *  regions.
  * @mmio_size: Array with ISP register regions size in bytes.
- * @raw_dmamask: Raw DMA mask
  * @stat_lock: Spinlock for handling statistics
  * @isp_mutex: Mutex for serializing requests to ISP.
  * @crashed: Bitmask of crashed entities (indexed by entity ID)
@@ -190,8 +189,6 @@ struct isp_device {
unsigned long mmio_base_phys[OMAP3_ISP_IOMEM_LAST];
resource_size_t mmio_size[OMAP3_ISP_IOMEM_LAST];
 
-   u64 raw_dmamask;
-
/* ISP Obj */
spinlock_t stat_lock;   /* common lock for statistic drivers */
struct mutex isp_mutex; /* For handling ref_count field */
-- 
1.7.4.4

--
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 30/51] DMA-API: dma: dw_dmac.c: convert to use dma_coerce_mask_and_coherent()

2013-09-20 Thread Russell King
This code sequence:
if (!pdev->dev.dma_mask) {
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
}
bypasses the architectures check on the DMA mask.  It can be replaced
with dma_coerce_mask_and_coherent(), avoiding the direct initialization
of this mask.

Signed-off-by: Russell King 
---
 drivers/dma/dw/platform.c |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
index e35d975..453822c 100644
--- a/drivers/dma/dw/platform.c
+++ b/drivers/dma/dw/platform.c
@@ -191,11 +191,9 @@ static int dw_probe(struct platform_device *pdev)
if (IS_ERR(chip->regs))
return PTR_ERR(chip->regs);
 
-   /* Apply default dma_mask if needed */
-   if (!dev->dma_mask) {
-   dev->dma_mask = &dev->coherent_dma_mask;
-   dev->coherent_dma_mask = DMA_BIT_MASK(32);
-   }
+   err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+   if (err)
+   return err;
 
pdata = dev_get_platdata(dev);
if (!pdata)
-- 
1.7.4.4

--
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 29/51] DMA-API: ata: pata_octeon_cf: convert to use dma_coerce_mask_and_coherent()

2013-09-20 Thread Russell King
Convert this code sequence:
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
to use dma_coerce_mask_and_coherent() to avoid bypassing the architecture
check on the DMA mask.

Signed-off-by: Russell King 
---
 drivers/ata/pata_octeon_cf.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
index c51bbb9..6231d43 100644
--- a/drivers/ata/pata_octeon_cf.c
+++ b/drivers/ata/pata_octeon_cf.c
@@ -1014,8 +1014,9 @@ static int octeon_cf_probe(struct platform_device *pdev)
}
cf_port->c0 = ap->ioaddr.ctl_addr;
 
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
-   pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
+   rv = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+   if (rv)
+   return ret;
 
ata_port_desc(ap, "cmd %p ctl %p", base, ap->ioaddr.ctl_addr);
 
-- 
1.7.4.4

--
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 26/51] DMA-API: usb: ohci-sa1111: add a note about DMA masks

2013-09-20 Thread Russell King
Add a comment to explain why this driver doesn't call any of the DMA
API dma_set_mask() functions.

Signed-off-by: Russell King 
---
 drivers/usb/host/ohci-sa.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/host/ohci-sa.c b/drivers/usb/host/ohci-sa.c
index 17b2a7d..aa9e127 100644
--- a/drivers/usb/host/ohci-sa.c
+++ b/drivers/usb/host/ohci-sa.c
@@ -185,6 +185,12 @@ static int ohci_hcd_sa_probe(struct sa_dev *dev)
if (usb_disabled())
return -ENODEV;
 
+   /*
+* We don't call dma_set_mask_and_coherent() here because the
+* DMA mask has already been appropraitely setup by the core
+* SA- bus code (which includes bug workarounds.)
+*/
+
hcd = usb_create_hcd(&ohci_sa_hc_driver, &dev->dev, "sa");
if (!hcd)
return -ENOMEM;
-- 
1.7.4.4

--
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 28/51] DMA-API: sound: fix dma mask handling in a lot of drivers

2013-09-20 Thread Russell King
This code sequence is unsafe in modules:

static u64 mask = DMA_BIT_MASK(something);
...
if (!dev->dma_mask)
dev->dma_mask = &mask;

as if a module is reloaded, the mask will be pointing at the original
module's mask address, and this can lead to oopses.  Moreover, they
all follow this with:

if (!dev->coherent_dma_mask)
dev->coherent_dma_mask = mask;

where 'mask' is the same value as the statically defined mask, and this
bypasses the architecture's check on whether the DMA mask is possible.

Fix these issues by using the new dma_coerce_coherent_and_mask()
function.

Signed-off-by: Russell King 
---
 sound/arm/pxa2xx-pcm.c  |9 +++--
 sound/soc/atmel/atmel-pcm.c |   11 ---
 sound/soc/blackfin/bf5xx-ac97-pcm.c |   11 ---
 sound/soc/blackfin/bf5xx-i2s-pcm.c  |   10 --
 sound/soc/davinci/davinci-pcm.c |9 +++--
 sound/soc/fsl/fsl_dma.c |9 +++--
 sound/soc/fsl/mpc5200_dma.c |   10 --
 sound/soc/jz4740/jz4740-pcm.c   |   12 
 sound/soc/kirkwood/kirkwood-dma.c   |9 +++--
 sound/soc/nuc900/nuc900-pcm.c   |9 -
 sound/soc/omap/omap-pcm.c   |   11 ---
 sound/soc/pxa/pxa2xx-pcm.c  |   11 ---
 sound/soc/s6000/s6000-pcm.c |9 +++--
 sound/soc/samsung/dma.c |   11 ---
 sound/soc/samsung/idma.c|   11 ---
 15 files changed, 55 insertions(+), 97 deletions(-)

diff --git a/sound/arm/pxa2xx-pcm.c b/sound/arm/pxa2xx-pcm.c
index 69a2455..fb3b76f 100644
--- a/sound/arm/pxa2xx-pcm.c
+++ b/sound/arm/pxa2xx-pcm.c
@@ -83,8 +83,6 @@ static struct snd_pcm_ops pxa2xx_pcm_ops = {
.mmap   = pxa2xx_pcm_mmap,
 };
 
-static u64 pxa2xx_pcm_dmamask = 0x;
-
 int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
   struct snd_pcm **rpcm)
 {
@@ -100,10 +98,9 @@ int pxa2xx_pcm_new(struct snd_card *card, struct 
pxa2xx_pcm_client *client,
pcm->private_data = client;
pcm->private_free = pxa2xx_pcm_free_dma_buffers;
 
-   if (!card->dev->dma_mask)
-   card->dev->dma_mask = &pxa2xx_pcm_dmamask;
-   if (!card->dev->coherent_dma_mask)
-   card->dev->coherent_dma_mask = 0x;
+   ret = dma_coerce_mask_and_coherent_mask(card->dev, DMA_BIT_MASK(32));
+   if (ret)
+   goto out;
 
if (play) {
int stream = SNDRV_PCM_STREAM_PLAYBACK;
diff --git a/sound/soc/atmel/atmel-pcm.c b/sound/soc/atmel/atmel-pcm.c
index 3109db7..fbb87e3 100644
--- a/sound/soc/atmel/atmel-pcm.c
+++ b/sound/soc/atmel/atmel-pcm.c
@@ -68,18 +68,15 @@ int atmel_pcm_mmap(struct snd_pcm_substream *substream,
 }
 EXPORT_SYMBOL_GPL(atmel_pcm_mmap);
 
-static u64 atmel_pcm_dmamask = DMA_BIT_MASK(32);
-
 int atmel_pcm_new(struct snd_soc_pcm_runtime *rtd)
 {
struct snd_card *card = rtd->card->snd_card;
struct snd_pcm *pcm = rtd->pcm;
-   int ret = 0;
+   int ret;
 
-   if (!card->dev->dma_mask)
-   card->dev->dma_mask = &atmel_pcm_dmamask;
-   if (!card->dev->coherent_dma_mask)
-   card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
 
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
pr_debug("atmel-pcm: allocating PCM playback DMA buffer\n");
diff --git a/sound/soc/blackfin/bf5xx-ac97-pcm.c 
b/sound/soc/blackfin/bf5xx-ac97-pcm.c
index 53f8408..1d4c676 100644
--- a/sound/soc/blackfin/bf5xx-ac97-pcm.c
+++ b/sound/soc/blackfin/bf5xx-ac97-pcm.c
@@ -415,19 +415,16 @@ static void bf5xx_pcm_free_dma_buffers(struct snd_pcm 
*pcm)
}
 }
 
-static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
-
 static int bf5xx_pcm_ac97_new(struct snd_soc_pcm_runtime *rtd)
 {
struct snd_card *card = rtd->card->snd_card;
struct snd_pcm *pcm = rtd->pcm;
-   int ret = 0;
+   int ret;
 
pr_debug("%s enter\n", __func__);
-   if (!card->dev->dma_mask)
-   card->dev->dma_mask = &bf5xx_pcm_dmamask;
-   if (!card->dev->coherent_dma_mask)
-   card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
 
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
diff --git a/sound/soc/blackfin/bf5xx-i2s-pcm.c 
b/sound/soc/blackfin/bf5xx-i2s-pcm.c
index 9cb4a80..2a5b434 100644
--- a/sound/soc/blackfin/bf5xx-i2s-pcm.c
+++ b/sound/soc/blackfin/bf5xx-i2s-pcm.c
@@ -323,18 +323,16 @@ static struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
.silence= bf5xx_pcm_silence,
 };
 
-static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
-
 static int bf5xx_pcm_i2s_new(struct snd_soc_pcm

[PATCH 27/51] DMA-API: provide a helper to setup DMA masks

2013-09-20 Thread Russell King
Many drivers contain code such as:

dev->dma_mask = &dev->coherent_dma_mask;
dev->coherent_dma_mask = MASK;

Let's move this pattern out of drivers and have the DMA API provide a
helper for it.  This helper uses dma_set_mask_and_coherent() to allow
platform issues to be properly dealt with via dma_set_mask()/
dma_is_supported().

Signed-off-by: Russell King 
---
 include/linux/dma-mapping.h |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index ec951f9..27d1421 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -111,6 +111,16 @@ static inline int dma_set_mask_and_coherent(struct device 
*dev, u64 mask)
return rc;
 }
 
+/*
+ * Similar to the above, except it deals with the case where the device
+ * does not have dev->dma_mask appropriately setup.
+ */
+static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask)
+{
+   dev->dma_mask = &dev->coherent_dma_mask;
+   return dma_set_mask_and_coherent(dev, mask);
+}
+
 extern u64 dma_get_required_mask(struct device *dev);
 
 static inline unsigned int dma_get_max_seg_size(struct device *dev)
-- 
1.7.4.4

--
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 21/51] DMA-API: usb: ssb-hcd: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/usb/host/ssb-hcd.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ssb-hcd.c b/drivers/usb/host/ssb-hcd.c
index 74af2c6..0196f76 100644
--- a/drivers/usb/host/ssb-hcd.c
+++ b/drivers/usb/host/ssb-hcd.c
@@ -163,8 +163,7 @@ static int ssb_hcd_probe(struct ssb_device *dev,
 
/* TODO: Probably need checks here; is the core connected? */
 
-   if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
-   dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
+   if (dma_set_mask_and_coherent(dev->dma_dev, DMA_BIT_MASK(32)))
return -EOPNOTSUPP;
 
usb_dev = kzalloc(sizeof(struct ssb_hcd_device), GFP_KERNEL);
-- 
1.7.4.4

--
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 25/51] DMA-API: video: clcd: add dma_set_mask_and_coherent() call

2013-09-20 Thread Russell King
The DMA API requires drivers to call the appropriate dma_set_mask()
functions before doing any DMA mapping.  Add this required call to
the AMBA PL08x driver.

Signed-off-by: Russell King 
---
 drivers/video/amba-clcd.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/video/amba-clcd.c b/drivers/video/amba-clcd.c
index 0a2cce7..afe4702 100644
--- a/drivers/video/amba-clcd.c
+++ b/drivers/video/amba-clcd.c
@@ -10,6 +10,7 @@
  *
  *  ARM PrimeCell PL110 Color LCD Controller
  */
+#include 
 #include 
 #include 
 #include 
@@ -551,6 +552,10 @@ static int clcdfb_probe(struct amba_device *dev, const 
struct amba_id *id)
if (!board)
return -EINVAL;
 
+   ret = dma_set_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   goto out;
+
ret = amba_request_regions(dev, NULL);
if (ret) {
printk(KERN_ERR "CLCD: unable to reserve regs region\n");
-- 
1.7.4.4

--
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 20/51] DMA-API: usb: bcma: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/usb/host/bcma-hcd.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/bcma-hcd.c b/drivers/usb/host/bcma-hcd.c
index df13d42..205f4a3 100644
--- a/drivers/usb/host/bcma-hcd.c
+++ b/drivers/usb/host/bcma-hcd.c
@@ -227,8 +227,7 @@ static int bcma_hcd_probe(struct bcma_device *dev)
 
/* TODO: Probably need checks here; is the core connected? */
 
-   if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
-   dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
+   if (dma_set_mask_and_coherent(dev->dma_dev, DMA_BIT_MASK(32)))
return -EOPNOTSUPP;
 
usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL);
-- 
1.7.4.4

--
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 15/51] DMA-API: net: b43legacy: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/net/wireless/b43legacy/dma.c |9 +++--
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/b43legacy/dma.c 
b/drivers/net/wireless/b43legacy/dma.c
index 42eb26c..b2ed179 100644
--- a/drivers/net/wireless/b43legacy/dma.c
+++ b/drivers/net/wireless/b43legacy/dma.c
@@ -806,12 +806,9 @@ static int b43legacy_dma_set_mask(struct b43legacy_wldev 
*dev, u64 mask)
/* Try to set the DMA mask. If it fails, try falling back to a
 * lower mask, as we can always also support a lower one. */
while (1) {
-   err = dma_set_mask(dev->dev->dma_dev, mask);
-   if (!err) {
-   err = dma_set_coherent_mask(dev->dev->dma_dev, mask);
-   if (!err)
-   break;
-   }
+   err = dma_set_mask_and_coherent(dev->dev->dma_dev, mask);
+   if (!err)
+   break;
if (mask == DMA_BIT_MASK(64)) {
mask = DMA_BIT_MASK(32);
fallback = true;
-- 
1.7.4.4

--
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 10/51] DMA-API: net: broadcom/bnx2x: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c |8 ++--
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 2f8dbbb..e6c3e66 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -12072,13 +12072,9 @@ static int bnx2x_set_coherency_mask(struct bnx2x *bp)
 {
struct device *dev = &bp->pdev->dev;
 
-   if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
+   if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) == 0) {
bp->flags |= USING_DAC_FLAG;
-   if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
-   dev_err(dev, "dma_set_coherent_mask failed, 
aborting\n");
-   return -EIO;
-   }
-   } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
+   } else if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
dev_err(dev, "System does not support DMA, aborting\n");
return -EIO;
}
-- 
1.7.4.4

--
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 19/51] DMA-API: media: dt3155v4l: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/staging/media/dt3155v4l/dt3155v4l.c |5 +
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.c 
b/drivers/staging/media/dt3155v4l/dt3155v4l.c
index 90d6ac4..081407b 100644
--- a/drivers/staging/media/dt3155v4l/dt3155v4l.c
+++ b/drivers/staging/media/dt3155v4l/dt3155v4l.c
@@ -901,10 +901,7 @@ dt3155_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
int err;
struct dt3155_priv *pd;
 
-   err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
-   if (err)
-   return -ENODEV;
-   err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
if (err)
return -ENODEV;
pd = kzalloc(sizeof(*pd), GFP_KERNEL);
-- 
1.7.4.4

--
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 12/51] DMA-API: net: intel/e1000: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/net/ethernet/intel/e1000/e1000_main.c |9 ++---
 1 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c 
b/drivers/net/ethernet/intel/e1000/e1000_main.c
index 59ad007..34672f8 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_main.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_main.c
@@ -1018,19 +1018,14 @@ static int e1000_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
 */
pci_using_dac = 0;
if ((hw->bus_type == e1000_bus_type_pcix) &&
-   !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
-   /* according to DMA-API-HOWTO, coherent calls will always
-* succeed if the set call did
-*/
-   dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
+   !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
pci_using_dac = 1;
} else {
-   err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+   err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
if (err) {
pr_err("No usable DMA config, aborting\n");
goto err_dma;
}
-   dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
}
 
netdev->netdev_ops = &e1000_netdev_ops;
-- 
1.7.4.4

--
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 18/51] DMA-API: staging: et131x: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/staging/et131x/et131x.c |   17 ++---
 1 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index f73e58f..98edfa8 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -4797,21 +4797,8 @@ static int et131x_pci_setup(struct pci_dev *pdev,
pci_set_master(pdev);
 
/* Check the DMA addressing support of this device */
-   if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
-   rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
-   if (rc < 0) {
-   dev_err(&pdev->dev,
- "Unable to obtain 64 bit DMA for consistent 
allocations\n");
-   goto err_release_res;
-   }
-   } else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
-   rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
-   if (rc < 0) {
-   dev_err(&pdev->dev,
- "Unable to obtain 32 bit DMA for consistent 
allocations\n");
-   goto err_release_res;
-   }
-   } else {
+   if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) {
dev_err(&pdev->dev, "No usable DMA addressing method\n");
rc = -EIO;
goto err_release_res;
-- 
1.7.4.4

--
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 13/51] DMA-API: net: sfc/efx.c: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/net/ethernet/sfc/efx.c |   12 +---
 1 files changed, 1 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index 07c9bc4..2e27837 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -1121,7 +1121,7 @@ static int efx_init_io(struct efx_nic *efx)
 */
while (dma_mask > 0x7fffUL) {
if (dma_supported(&pci_dev->dev, dma_mask)) {
-   rc = dma_set_mask(&pci_dev->dev, dma_mask);
+   rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
if (rc == 0)
break;
}
@@ -1134,16 +1134,6 @@ static int efx_init_io(struct efx_nic *efx)
}
netif_dbg(efx, probe, efx->net_dev,
  "using DMA mask %llx\n", (unsigned long long) dma_mask);
-   rc = dma_set_coherent_mask(&pci_dev->dev, dma_mask);
-   if (rc) {
-   /* dma_set_coherent_mask() is not *allowed* to
-* fail with a mask that dma_set_mask() accepted,
-* but just in case...
-*/
-   netif_err(efx, probe, efx->net_dev,
- "failed to set consistent DMA mask\n");
-   goto fail2;
-   }
 
efx->membase_phys = pci_resource_start(efx->pci_dev, EFX_MEM_BAR);
rc = pci_request_region(pci_dev, EFX_MEM_BAR, "sfc");
-- 
1.7.4.4

--
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 11/51] DMA-API: net: emulex/benet: replace dma_set_mask()+dma_set_coherent_mask() with new helper

2013-09-20 Thread Russell King
Replace the following sequence:

dma_set_mask(dev, mask);
dma_set_coherent_mask(dev, mask);

with a call to the new helper dma_set_mask_and_coherent().

Signed-off-by: Russell King 
---
 drivers/net/ethernet/emulex/benet/be_main.c |   12 ++--
 1 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/emulex/benet/be_main.c 
b/drivers/net/ethernet/emulex/benet/be_main.c
index 3224d28..2084151 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -4335,19 +4335,11 @@ static int be_probe(struct pci_dev *pdev, const struct 
pci_device_id *pdev_id)
adapter->netdev = netdev;
SET_NETDEV_DEV(netdev, &pdev->dev);
 
-   status = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
+   status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
if (!status) {
-   status = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
-   if (status < 0) {
-   dev_err(&pdev->dev, "dma_set_coherent_mask failed\n");
-   goto free_netdev;
-   }
netdev->features |= NETIF_F_HIGHDMA;
} else {
-   status = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
-   if (!status)
-   status = dma_set_coherent_mask(&pdev->dev,
-  DMA_BIT_MASK(32));
+   status = dma_set_mask_and_coherent(&pdev->dev, 
DMA_BIT_MASK(32));
if (status) {
dev_err(&pdev->dev, "Could not set PCI DMA Mask\n");
goto free_netdev;
-- 
1.7.4.4

--
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 24/51] DMA-API: dma: pl330: add dma_set_mask_and_coherent() call

2013-09-20 Thread Russell King
The DMA API requires drivers to call the appropriate dma_set_mask()
functions before doing any DMA mapping.  Add this required call to
the AMBA PL08x driver.

Signed-off-by: Russell King 
---
 drivers/dma/pl330.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index a562d24..df8b10f 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -2903,6 +2903,10 @@ pl330_probe(struct amba_device *adev, const struct 
amba_id *id)
 
pdat = dev_get_platdata(&adev->dev);
 
+   ret = dma_set_mask_and_coherent(&adev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
+
/* Allocate a new DMAC and its Channels */
pdmac = devm_kzalloc(&adev->dev, sizeof(*pdmac), GFP_KERNEL);
if (!pdmac) {
-- 
1.7.4.4

--
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 22/51] DMA-API: amba: get rid of separate dma_mask

2013-09-20 Thread Russell King
AMBA Primecell devices always treat streaming and coherent DMA exactly
the same, so there's no point in having the masks separated.

Signed-off-by: Russell King 
---
 drivers/amba/bus.c   |6 +-
 drivers/of/platform.c|3 ---
 include/linux/amba/bus.h |2 --
 3 files changed, 1 insertions(+), 10 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index c670727..c4876ac 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -552,7 +552,6 @@ amba_aphb_device_add(struct device *parent, const char 
*name,
if (!dev)
return ERR_PTR(-ENOMEM);
 
-   dev->dma_mask = dma_mask;
dev->dev.coherent_dma_mask = dma_mask;
dev->irq[0] = irq1;
dev->irq[1] = irq2;
@@ -619,7 +618,7 @@ static void amba_device_initialize(struct amba_device *dev, 
const char *name)
dev_set_name(&dev->dev, "%s", name);
dev->dev.release = amba_device_release;
dev->dev.bus = &amba_bustype;
-   dev->dev.dma_mask = &dev->dma_mask;
+   dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
dev->res.name = dev_name(&dev->dev);
 }
 
@@ -663,9 +662,6 @@ int amba_device_register(struct amba_device *dev, struct 
resource *parent)
amba_device_initialize(dev, dev->dev.init_name);
dev->dev.init_name = NULL;
 
-   if (!dev->dev.coherent_dma_mask && dev->dma_mask)
-   dev_warn(&dev->dev, "coherent dma mask is unset\n");
-
return amba_device_add(dev, parent);
 }
 
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 9b439ac..54382ba 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -284,9 +284,6 @@ static struct amba_device *of_amba_device_create(struct 
device_node *node,
else
of_device_make_bus_id(&dev->dev);
 
-   /* setup amba-specific device info */
-   dev->dma_mask = ~0;
-
/* Allow the HW Peripheral ID to be overridden */
prop = of_get_property(node, "arm,primecell-periphid", NULL);
if (prop)
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index 43ec7e2..682df0e 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -30,7 +30,6 @@ struct amba_device {
struct device   dev;
struct resource res;
struct clk  *pclk;
-   u64 dma_mask;
unsigned intperiphid;
unsigned intirq[AMBA_NR_IRQS];
 };
@@ -131,7 +130,6 @@ struct amba_device name##_device = {
\
 struct amba_device name##_device = {   \
.dev = __AMBA_DEV(busid, data, ~0ULL),  \
.res = DEFINE_RES_MEM(base, SZ_4K), \
-   .dma_mask = ~0ULL,  \
.irq = irqs,\
.periphid = id, \
 }
-- 
1.7.4.4

--
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 39/51] DMA-API: others: use dma_set_coherent_mask()

2013-09-20 Thread Russell King
The correct way for a driver to specify the coherent DMA mask is
not to directly access the field in the struct device, but to use
dma_set_coherent_mask().  Only arch and bus code should access this
member directly.

Convert all direct write accesses to using the correct API.

Signed-off-by: Russell King 
---
 drivers/ata/pata_ixp4xx_cf.c |5 -
 drivers/gpu/drm/exynos/exynos_drm_drv.c  |6 +-
 drivers/gpu/drm/omapdrm/omap_dmm_tiler.c |5 +++--
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index 1ec53f8..ddf470c 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -144,6 +144,7 @@ static int ixp4xx_pata_probe(struct platform_device *pdev)
struct ata_host *host;
struct ata_port *ap;
struct ixp4xx_pata_data *data = dev_get_platdata(&pdev->dev);
+   int ret;
 
cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -157,7 +158,9 @@ static int ixp4xx_pata_probe(struct platform_device *pdev)
return -ENOMEM;
 
/* acquire resources and fill host */
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
 
data->cs0 = devm_ioremap(&pdev->dev, cs0->start, 0x1000);
data->cs1 = devm_ioremap(&pdev->dev, cs1->start, 0x1000);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c 
b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index bb82ef7..81192d0 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -286,7 +286,11 @@ static struct drm_driver exynos_drm_driver = {
 
 static int exynos_drm_platform_probe(struct platform_device *pdev)
 {
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   int ret;
+
+   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
 
return drm_platform_init(&exynos_drm_driver, pdev);
 }
diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c 
b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
index acf6678..701c4c1 100644
--- a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
+++ b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
@@ -664,8 +664,9 @@ static int omap_dmm_probe(struct platform_device *dev)
}
 
/* set dma mask for device */
-   /* NOTE: this is a workaround for the hwmod not initializing properly */
-   dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   goto fail;
 
omap_dmm->dummy_pa = page_to_phys(omap_dmm->dummy_page);
 
-- 
1.7.4.4

--
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 46/51] ARM: DMA-API: better handing of DMA masks for coherent allocations

2013-09-20 Thread Russell King
We need to start treating DMA masks as something which is specific to
the bus that the device resides on, otherwise we're going to hit all
sorts of nasty issues with LPAE and 32-bit DMA controllers in >32-bit
systems, where memory is offset from PFN 0.

In order to start doing this, we convert the DMA mask to a PFN using
the device specific dma_to_pfn() macro.  This is the reverse of the
pfn_to_dma() macro which is used to get the DMA address for the device.

This gives us a PFN mask, which we can then check against the PFN
limit of the DMA zone.

Signed-off-by: Russell King 
---
 arch/arm/mm/dma-mapping.c |   49 
 arch/arm/mm/init.c|2 +
 arch/arm/mm/mm.h  |2 +
 3 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index f5e1a84..13d55e1 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -173,10 +173,30 @@ static u64 get_coherent_dma_mask(struct device *dev)
return 0;
}
 
-   if ((~mask) & (u64)arm_dma_limit) {
-   dev_warn(dev, "coherent DMA mask %#llx is smaller "
-"than system GFP_DMA mask %#llx\n",
-mask, (u64)arm_dma_limit);
+   /*
+* If the mask allows for more memory than we can address,
+* and we actually have that much memory, then fail the
+* allocation.
+*/
+   if (sizeof(mask) != sizeof(dma_addr_t) &&
+   mask > (dma_addr_t)~0 &&
+   dma_to_pfn(dev, ~0) > arm_dma_pfn_limit) {
+   dev_warn(dev, "Coherent DMA mask %#llx is larger than 
dma_addr_t allows\n",
+mask);
+   dev_warn(dev, "Driver did not use or check the return 
value from dma_set_coherent_mask()?\n");
+   return 0;
+   }
+
+   /*
+* Now check that the mask, when translated to a PFN,
+* fits within the allowable addresses which we can
+* allocate.
+*/
+   if (dma_to_pfn(dev, mask) < arm_dma_pfn_limit) {
+   dev_warn(dev, "Coherent DMA mask %#llx (pfn %#lx-%#lx) 
covers a smaller range of system memory than the DMA zone pfn 0x0-%#lx\n",
+mask,
+dma_to_pfn(dev, 0), dma_to_pfn(dev, mask) + 1,
+arm_dma_pfn_limit + 1);
return 0;
}
}
@@ -1007,8 +1027,27 @@ void arm_dma_sync_sg_for_device(struct device *dev, 
struct scatterlist *sg,
  */
 int dma_supported(struct device *dev, u64 mask)
 {
-   if (mask < (u64)arm_dma_limit)
+   unsigned long limit;
+
+   /*
+* If the mask allows for more memory than we can address,
+* and we actually have that much memory, then we must
+* indicate that DMA to this device is not supported.
+*/
+   if (sizeof(mask) != sizeof(dma_addr_t) &&
+   mask > (dma_addr_t)~0 &&
+   dma_to_pfn(dev, ~0) > arm_dma_pfn_limit)
+   return 0;
+
+   /*
+* Translate the device's DMA mask to a PFN limit.  This
+* PFN number includes the page which we can DMA to.
+*/
+   limit = dma_to_pfn(dev, mask);
+
+   if (limit < arm_dma_pfn_limit)
return 0;
+
return 1;
 }
 EXPORT_SYMBOL(dma_supported);
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index febaee7..8aab24f 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -218,6 +218,7 @@ EXPORT_SYMBOL(arm_dma_zone_size);
  * so a successful GFP_DMA allocation will always satisfy this.
  */
 phys_addr_t arm_dma_limit;
+unsigned long arm_dma_pfn_limit;
 
 static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long 
*hole,
unsigned long dma_size)
@@ -240,6 +241,7 @@ void __init setup_dma_zone(const struct machine_desc *mdesc)
arm_dma_limit = PHYS_OFFSET + arm_dma_zone_size - 1;
} else
arm_dma_limit = 0x;
+   arm_dma_pfn_limit = arm_dma_limit >> PAGE_SHIFT;
 #endif
 }
 
diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h
index d5a4e9a..d5a982d 100644
--- a/arch/arm/mm/mm.h
+++ b/arch/arm/mm/mm.h
@@ -81,8 +81,10 @@ extern __init void add_static_vm_early(struct static_vm 
*svm);
 
 #ifdef CONFIG_ZONE_DMA
 extern phys_addr_t arm_dma_limit;
+extern unsigned long arm_dma_pfn_limit;
 #else
 #define arm_dma_limit ((phys_addr_t)~0)
+#define arm_dma_pfn_limit (~0ul >> PAGE_SHIFT)
 #endif
 
 extern phys_addr_t arm_lowmem_limit;
-- 
1.7.4.4

--
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 45/51] DMA-API: firmware/google/gsmi.c: avoid direct access to DMA masks

2013-09-20 Thread Russell King
This driver doesn't need to directly access DMA masks if it uses the
platform_device_register_full() API rather than
platform_device_register_simple() - the former function can initialize
the DMA mask appropriately.

Signed-off-by: Russell King 
---
 drivers/firmware/google/gsmi.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c
index 6eb535f..e5a67b2 100644
--- a/drivers/firmware/google/gsmi.c
+++ b/drivers/firmware/google/gsmi.c
@@ -764,6 +764,13 @@ static __init int gsmi_system_valid(void)
 static struct kobject *gsmi_kobj;
 static struct efivars efivars;
 
+static const struct platform_device_info gsmi_dev_info = {
+   .name   = "gsmi",
+   .id = -1,
+   /* SMI callbacks require 32bit addresses */
+   .dma_mask   = DMA_BIT_MASK(32),
+};
+
 static __init int gsmi_init(void)
 {
unsigned long flags;
@@ -776,7 +783,7 @@ static __init int gsmi_init(void)
gsmi_dev.smi_cmd = acpi_gbl_FADT.smi_command;
 
/* register device */
-   gsmi_dev.pdev = platform_device_register_simple("gsmi", -1, NULL, 0);
+   gsmi_dev.pdev = platform_device_register_full(&gsmi_dev_info);
if (IS_ERR(gsmi_dev.pdev)) {
printk(KERN_ERR "gsmi: unable to register platform device\n");
return PTR_ERR(gsmi_dev.pdev);
@@ -785,10 +792,6 @@ static __init int gsmi_init(void)
/* SMI access needs to be serialized */
spin_lock_init(&gsmi_dev.lock);
 
-   /* SMI callbacks require 32bit addresses */
-   gsmi_dev.pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
-   gsmi_dev.pdev->dev.dma_mask =
-   &gsmi_dev.pdev->dev.coherent_dma_mask;
ret = -ENOMEM;
gsmi_dev.dma_pool = dma_pool_create("gsmi", &gsmi_dev.pdev->dev,
 GSMI_BUF_SIZE, GSMI_BUF_ALIGN, 0);
-- 
1.7.4.4

--
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 47/51] ARM: 7794/1: block: Rename parameter dma_mask to max_addr for blk_queue_bounce_limit()

2013-09-20 Thread Russell King
From: Santosh Shilimkar 

The blk_queue_bounce_limit() API parameter 'dma_mask' is actually the
maximum address the device can handle rather than a dma_mask. Rename
it accordingly to avoid it being interpreted as dma_mask.

No functional change.

The idea is to fix the bad assumptions about dma_mask wherever it could
be miss-interpreted.

Signed-off-by: Santosh Shilimkar 
Signed-off-by: Russell King 
---
 block/blk-settings.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index c50ecf0..026c151 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -195,17 +195,17 @@ EXPORT_SYMBOL(blk_queue_make_request);
 /**
  * blk_queue_bounce_limit - set bounce buffer limit for queue
  * @q: the request queue for the device
- * @dma_mask: the maximum address the device can handle
+ * @max_addr: the maximum address the device can handle
  *
  * Description:
  *Different hardware can have different requirements as to what pages
  *it can do I/O directly to. A low level driver can call
  *blk_queue_bounce_limit to have lower memory pages allocated as bounce
- *buffers for doing I/O to pages residing above @dma_mask.
+ *buffers for doing I/O to pages residing above @max_addr.
  **/
-void blk_queue_bounce_limit(struct request_queue *q, u64 dma_mask)
+void blk_queue_bounce_limit(struct request_queue *q, u64 max_addr)
 {
-   unsigned long b_pfn = dma_mask >> PAGE_SHIFT;
+   unsigned long b_pfn = max_addr >> PAGE_SHIFT;
int dma = 0;
 
q->bounce_gfp = GFP_NOIO;
-- 
1.7.4.4

--
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 48/51] ARM: 7795/1: mm: dma-mapping: Add dma_max_pfn(dev) helper function

2013-09-20 Thread Russell King
From: Santosh Shilimkar 

Most of the kernel assumes that PFN0 is the start of the physical
memory (RAM). This assumptions is not true on most of the ARM SOCs
and hence and if one try to update the ARM port to follow the assumptions,
we end of breaking the dma bounce limit for few block layer drivers.
One such example is trying to unify the meaning of max*_pfn on ARM
as the bootmem layer expects, breaks few block layer driver dma
bounce limit.

To fix this problem, we introduce dma_max_pfn(dev) generic helper with
a possibility of override from the architecture code. The helper converts
a DMA bitmask of bits to a block PFN number. In all the generic cases,
it is just  "dev->dma_mask >> PAGE_SHIFT" and hence default behavior
is maintained as is.

Subsequent patches will make use of the helper. No functional change.

Signed-off-by: Santosh Shilimkar 
Signed-off-by: Russell King 
---
 include/linux/dma-mapping.h |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 27d1421..fd4aee2 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -153,6 +153,13 @@ static inline int dma_set_seg_boundary(struct device *dev, 
unsigned long mask)
return -EIO;
 }
 
+#ifndef dma_max_pfn
+static inline unsigned long dma_max_pfn(struct device *dev)
+{
+   return *dev->dma_mask >> PAGE_SHIFT;
+}
+#endif
+
 static inline void *dma_zalloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t flag)
 {
-- 
1.7.4.4

--
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 49/51] ARM: 7796/1: scsi: Use dma_max_pfn(dev) helper for bounce_limit calculations

2013-09-20 Thread Russell King
From: Santosh Shilimkar 

DMA bounce limit is the maximum direct DMA'able memory beyond which
bounce buffers has to be used to perform dma operations. SCSI driver
relies on dma_mask but its calculation is based on max_*pfn which
don't have uniform meaning across architectures. So make use of
dma_max_pfn() which is expected to return the DMAable maximum pfn
value across architectures.

Signed-off-by: Santosh Shilimkar 
Signed-off-by: Russell King 
---
 drivers/scsi/scsi_lib.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index d1549b7..7bd7f0d 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1684,7 +1684,7 @@ u64 scsi_calculate_bounce_limit(struct Scsi_Host *shost)
 
host_dev = scsi_get_device(shost);
if (host_dev && host_dev->dma_mask)
-   bounce_limit = *host_dev->dma_mask;
+   bounce_limit = dma_max_pfn(host_dev) << PAGE_SHIFT;
 
return bounce_limit;
 }
-- 
1.7.4.4

--
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 51/51] ARM: 7805/1: mm: change max*pfn to include the physical offset of memory

2013-09-20 Thread Russell King
From: Santosh Shilimkar 

Most of the kernel code assumes that max*pfn is maximum pfns because
the physical start of memory is expected to be PFN0. Since this
assumption is not true on ARM architectures, the meaning of max*pfn
is number of memory pages. This is done to keep drivers happy which
are making use of of these variable to calculate the dma bounce limit
using dma_mask.

Now since we have a architecture override possibility for DMAable
maximum pfns, lets make meaning of max*pfns as maximum pnfs on ARM
as well.

Signed-off-by: Santosh Shilimkar 
Signed-off-by: Russell King 
---
 arch/arm/include/asm/dma-mapping.h |8 
 arch/arm/mm/init.c |   10 --
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/arch/arm/include/asm/dma-mapping.h 
b/arch/arm/include/asm/dma-mapping.h
index 5b579b9..863cd84 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -64,6 +64,7 @@ static inline dma_addr_t virt_to_dma(struct device *dev, void 
*addr)
 {
return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
 }
+
 #else
 static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
 {
@@ -86,6 +87,13 @@ static inline dma_addr_t virt_to_dma(struct device *dev, 
void *addr)
 }
 #endif
 
+/* The ARM override for dma_max_pfn() */
+static inline unsigned long dma_max_pfn(struct device *dev)
+{
+   return PHYS_PFN_OFFSET + dma_to_pfn(dev, *dev->dma_mask);
+}
+#define dma_max_pfn(dev) dma_max_pfn(dev)
+
 /*
  * DMA errors are defined by all-bits-set in the DMA address.
  */
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 8aab24f..d50533c 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -426,12 +426,10 @@ void __init bootmem_init(void)
 * This doesn't seem to be used by the Linux memory manager any
 * more, but is used by ll_rw_block.  If we can get rid of it, we
 * also get rid of some of the stuff above as well.
-*
-* Note: max_low_pfn and max_pfn reflect the number of _pages_ in
-* the system, not the maximum PFN.
 */
-   max_low_pfn = max_low - PHYS_PFN_OFFSET;
-   max_pfn = max_high - PHYS_PFN_OFFSET;
+   min_low_pfn = min;
+   max_low_pfn = max_low;
+   max_pfn = max_high;
 }
 
 /*
@@ -537,7 +535,7 @@ static inline void free_area_high(unsigned long pfn, 
unsigned long end)
 static void __init free_highpages(void)
 {
 #ifdef CONFIG_HIGHMEM
-   unsigned long max_low = max_low_pfn + PHYS_PFN_OFFSET;
+   unsigned long max_low = max_low_pfn;
struct memblock_region *mem, *res;
 
/* set highmem page free */
-- 
1.7.4.4

--
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 v3 0/2] crypto: move ablk_helper out of arch/x86

2013-09-20 Thread Ard Biesheuvel
v3:
- added generic and x86 versions of  containing may_use_simd(), and
  use it to decide whether to take the sync or the async path

v2:
- whitespace fix
- split into two patches so that the first one applies cleanly to the ARM/ARM64
  trees as well
- rebased onto cryptodev/master

Ard Biesheuvel (2):
  crypto: create generic version of ablk_helper
  crypto: move x86 to the generic version of ablk_helper

 arch/x86/crypto/Makefile   |   1 -
 arch/x86/crypto/ablk_helper.c  | 149 
 arch/x86/crypto/aesni-intel_glue.c |   2 +-
 arch/x86/crypto/camellia_aesni_avx2_glue.c |   2 +-
 arch/x86/crypto/camellia_aesni_avx_glue.c  |   2 +-
 arch/x86/crypto/cast5_avx_glue.c   |   2 +-
 arch/x86/crypto/cast6_avx_glue.c   |   2 +-
 arch/x86/crypto/serpent_avx2_glue.c|   2 +-
 arch/x86/crypto/serpent_avx_glue.c |   2 +-
 arch/x86/crypto/serpent_sse2_glue.c|   2 +-
 arch/x86/crypto/twofish_avx_glue.c |   2 +-
 arch/x86/include/asm/crypto/ablk_helper.h  |  31 --
 arch/x86/include/asm/simd.h|  11 +++
 crypto/Kconfig |  23 +++--
 crypto/Makefile|   1 +
 crypto/ablk_helper.c   | 150 +
 include/asm-generic/simd.h |  14 +++
 include/crypto/ablk_helper.h   |  31 ++
 18 files changed, 227 insertions(+), 202 deletions(-)
 delete mode 100644 arch/x86/crypto/ablk_helper.c
 delete mode 100644 arch/x86/include/asm/crypto/ablk_helper.h
 create mode 100644 arch/x86/include/asm/simd.h
 create mode 100644 crypto/ablk_helper.c
 create mode 100644 include/asm-generic/simd.h
 create mode 100644 include/crypto/ablk_helper.h

-- 
1.8.1.2

--
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 v3 1/2] crypto: create generic version of ablk_helper

2013-09-20 Thread Ard Biesheuvel
Create a generic version of ablk_helper so it can be reused
by other architectures.

Acked-by: Jussi Kivilinna 
Signed-off-by: Ard Biesheuvel 
---
 crypto/Kconfig   |   4 ++
 crypto/Makefile  |   1 +
 crypto/ablk_helper.c | 150 +++
 include/asm-generic/simd.h   |  14 
 include/crypto/ablk_helper.h |  31 +
 5 files changed, 200 insertions(+)
 create mode 100644 crypto/ablk_helper.c
 create mode 100644 include/asm-generic/simd.h
 create mode 100644 include/crypto/ablk_helper.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 69ce573..8179ae6 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -179,6 +179,10 @@ config CRYPTO_ABLK_HELPER_X86
depends on X86
select CRYPTO_CRYPTD
 
+config CRYPTO_ABLK_HELPER
+   tristate
+   select CRYPTO_CRYPTD
+
 config CRYPTO_GLUE_HELPER_X86
tristate
depends on X86
diff --git a/crypto/Makefile b/crypto/Makefile
index 2d5ed08..580af97 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -104,3 +104,4 @@ obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o
 obj-$(CONFIG_XOR_BLOCKS) += xor.o
 obj-$(CONFIG_ASYNC_CORE) += async_tx/
 obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/
+obj-$(CONFIG_CRYPTO_ABLK_HELPER) += ablk_helper.o
diff --git a/crypto/ablk_helper.c b/crypto/ablk_helper.c
new file mode 100644
index 000..62568b1
--- /dev/null
+++ b/crypto/ablk_helper.c
@@ -0,0 +1,150 @@
+/*
+ * Shared async block cipher helpers
+ *
+ * Copyright (c) 2012 Jussi Kivilinna 
+ *
+ * Based on aesni-intel_glue.c by:
+ *  Copyright (C) 2008, Intel Corp.
+ *Author: Huang Ying 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ * USA
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
+unsigned int key_len)
+{
+   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+   struct crypto_ablkcipher *child = &ctx->cryptd_tfm->base;
+   int err;
+
+   crypto_ablkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
+   crypto_ablkcipher_set_flags(child, crypto_ablkcipher_get_flags(tfm)
+   & CRYPTO_TFM_REQ_MASK);
+   err = crypto_ablkcipher_setkey(child, key, key_len);
+   crypto_ablkcipher_set_flags(tfm, crypto_ablkcipher_get_flags(child)
+   & CRYPTO_TFM_RES_MASK);
+   return err;
+}
+EXPORT_SYMBOL_GPL(ablk_set_key);
+
+int __ablk_encrypt(struct ablkcipher_request *req)
+{
+   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+   struct blkcipher_desc desc;
+
+   desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
+   desc.info = req->info;
+   desc.flags = 0;
+
+   return crypto_blkcipher_crt(desc.tfm)->encrypt(
+   &desc, req->dst, req->src, req->nbytes);
+}
+EXPORT_SYMBOL_GPL(__ablk_encrypt);
+
+int ablk_encrypt(struct ablkcipher_request *req)
+{
+   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+   if (!may_use_simd()) {
+   struct ablkcipher_request *cryptd_req =
+   ablkcipher_request_ctx(req);
+
+   memcpy(cryptd_req, req, sizeof(*req));
+   ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
+
+   return crypto_ablkcipher_encrypt(cryptd_req);
+   } else {
+   return __ablk_encrypt(req);
+   }
+}
+EXPORT_SYMBOL_GPL(ablk_encrypt);
+
+int ablk_decrypt(struct ablkcipher_request *req)
+{
+   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+   if (!may_use_simd()) {
+   struct ablkcipher_request *cryptd_req =
+   ablkcipher_request_ctx(req);
+
+   memcpy(cryptd_req, req, sizeof(*req));
+   ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
+
+   return crypto_ablkcipher_decrypt(cryptd_req);
+   } else {
+   struct blkcipher_desc desc;
+
+   desc.tfm = cry

[PATCH v3 2/2] crypto: move x86 to the generic version of ablk_helper

2013-09-20 Thread Ard Biesheuvel
Move all users of ablk_helper under x86/ to the generic version
and delete the x86 specific version.

Acked-by: Jussi Kivilinna 
Signed-off-by: Ard Biesheuvel 
---
 arch/x86/crypto/Makefile   |   1 -
 arch/x86/crypto/ablk_helper.c  | 149 -
 arch/x86/crypto/aesni-intel_glue.c |   2 +-
 arch/x86/crypto/camellia_aesni_avx2_glue.c |   2 +-
 arch/x86/crypto/camellia_aesni_avx_glue.c  |   2 +-
 arch/x86/crypto/cast5_avx_glue.c   |   2 +-
 arch/x86/crypto/cast6_avx_glue.c   |   2 +-
 arch/x86/crypto/serpent_avx2_glue.c|   2 +-
 arch/x86/crypto/serpent_avx_glue.c |   2 +-
 arch/x86/crypto/serpent_sse2_glue.c|   2 +-
 arch/x86/crypto/twofish_avx_glue.c |   2 +-
 arch/x86/include/asm/crypto/ablk_helper.h  |  31 --
 arch/x86/include/asm/simd.h|  11 +++
 crypto/Kconfig |  25 ++---
 14 files changed, 30 insertions(+), 205 deletions(-)
 delete mode 100644 arch/x86/crypto/ablk_helper.c
 delete mode 100644 arch/x86/include/asm/crypto/ablk_helper.h
 create mode 100644 arch/x86/include/asm/simd.h

diff --git a/arch/x86/crypto/Makefile b/arch/x86/crypto/Makefile
index 75b08e1e..e0fc24d 100644
--- a/arch/x86/crypto/Makefile
+++ b/arch/x86/crypto/Makefile
@@ -6,7 +6,6 @@ avx_supported := $(call as-instr,vpxor 
%xmm0$(comma)%xmm0$(comma)%xmm0,yes,no)
 avx2_supported := $(call as-instr,vpgatherdd %ymm0$(comma)(%eax$(comma)%ymm1\
$(comma)4)$(comma)%ymm2,yes,no)
 
-obj-$(CONFIG_CRYPTO_ABLK_HELPER_X86) += ablk_helper.o
 obj-$(CONFIG_CRYPTO_GLUE_HELPER_X86) += glue_helper.o
 
 obj-$(CONFIG_CRYPTO_AES_586) += aes-i586.o
diff --git a/arch/x86/crypto/ablk_helper.c b/arch/x86/crypto/ablk_helper.c
deleted file mode 100644
index 43282fe..000
--- a/arch/x86/crypto/ablk_helper.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Shared async block cipher helpers
- *
- * Copyright (c) 2012 Jussi Kivilinna 
- *
- * Based on aesni-intel_glue.c by:
- *  Copyright (C) 2008, Intel Corp.
- *Author: Huang Ying 
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
- * USA
- *
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
-unsigned int key_len)
-{
-   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
-   struct crypto_ablkcipher *child = &ctx->cryptd_tfm->base;
-   int err;
-
-   crypto_ablkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
-   crypto_ablkcipher_set_flags(child, crypto_ablkcipher_get_flags(tfm)
-   & CRYPTO_TFM_REQ_MASK);
-   err = crypto_ablkcipher_setkey(child, key, key_len);
-   crypto_ablkcipher_set_flags(tfm, crypto_ablkcipher_get_flags(child)
-   & CRYPTO_TFM_RES_MASK);
-   return err;
-}
-EXPORT_SYMBOL_GPL(ablk_set_key);
-
-int __ablk_encrypt(struct ablkcipher_request *req)
-{
-   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
-   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
-   struct blkcipher_desc desc;
-
-   desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
-   desc.info = req->info;
-   desc.flags = 0;
-
-   return crypto_blkcipher_crt(desc.tfm)->encrypt(
-   &desc, req->dst, req->src, req->nbytes);
-}
-EXPORT_SYMBOL_GPL(__ablk_encrypt);
-
-int ablk_encrypt(struct ablkcipher_request *req)
-{
-   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
-   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
-
-   if (!irq_fpu_usable()) {
-   struct ablkcipher_request *cryptd_req =
-   ablkcipher_request_ctx(req);
-
-   memcpy(cryptd_req, req, sizeof(*req));
-   ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
-
-   return crypto_ablkcipher_encrypt(cryptd_req);
-   } else {
-   return __ablk_encrypt(req);
-   }
-}
-EXPORT_SYMBOL_GPL(ablk_encrypt);
-
-int ablk_decrypt(struct ablkcipher_request *req)
-{
-   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
-   struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
-
-   if (!ir