crypto: caam - handle core endianness != caam endianness
[deliverable/linux.git] / drivers / crypto / caam / desc_constr.h
index 98d07de24fc48c975faf1e13e65d248cc48edd90..ae3aef6e9feeba2bb10b0e06ffe3008b22d1ca49 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "desc.h"
+#include "regs.h"
 
 #define IMMEDIATE (1 << 23)
 #define CAAM_CMD_SZ sizeof(u32)
                               LDST_SRCDST_WORD_DECOCTRL | \
                               (LDOFF_ENABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
 
+extern bool caam_little_end;
+
 static inline int desc_len(u32 *desc)
 {
-       return *desc & HDR_DESCLEN_MASK;
+       return caam32_to_cpu(*desc) & HDR_DESCLEN_MASK;
 }
 
 static inline int desc_bytes(void *desc)
@@ -52,7 +55,7 @@ static inline void *sh_desc_pdb(u32 *desc)
 
 static inline void init_desc(u32 *desc, u32 options)
 {
-       *desc = (options | HDR_ONE) + 1;
+       *desc = cpu_to_caam32((options | HDR_ONE) + 1);
 }
 
 static inline void init_sh_desc(u32 *desc, u32 options)
@@ -78,9 +81,10 @@ static inline void append_ptr(u32 *desc, dma_addr_t ptr)
 {
        dma_addr_t *offset = (dma_addr_t *)desc_end(desc);
 
-       *offset = ptr;
+       *offset = cpu_to_caam_dma(ptr);
 
-       (*desc) += CAAM_PTR_SZ / CAAM_CMD_SZ;
+       (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) +
+                               CAAM_PTR_SZ / CAAM_CMD_SZ);
 }
 
 static inline void init_job_desc_shared(u32 *desc, dma_addr_t ptr, int len,
@@ -99,16 +103,17 @@ static inline void append_data(u32 *desc, void *data, int len)
        if (len) /* avoid sparse warning: memcpy with byte count of 0 */
                memcpy(offset, data, len);
 
-       (*desc) += (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
+       (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) +
+                               (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ);
 }
 
 static inline void append_cmd(u32 *desc, u32 command)
 {
        u32 *cmd = desc_end(desc);
 
-       *cmd = command;
+       *cmd = cpu_to_caam32(command);
 
-       (*desc)++;
+       (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + 1);
 }
 
 #define append_u32 append_cmd
@@ -117,16 +122,22 @@ static inline void append_u64(u32 *desc, u64 data)
 {
        u32 *offset = desc_end(desc);
 
-       *offset = upper_32_bits(data);
-       *(++offset) = lower_32_bits(data);
+       /* Only 32-bit alignment is guaranteed in descriptor buffer */
+       if (caam_little_end) {
+               *offset = cpu_to_caam32(lower_32_bits(data));
+               *(++offset) = cpu_to_caam32(upper_32_bits(data));
+       } else {
+               *offset = cpu_to_caam32(upper_32_bits(data));
+               *(++offset) = cpu_to_caam32(lower_32_bits(data));
+       }
 
-       (*desc) += 2;
+       (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + 2);
 }
 
 /* Write command without affecting header, and return pointer to next word */
 static inline u32 *write_cmd(u32 *desc, u32 command)
 {
-       *desc = command;
+       *desc = cpu_to_caam32(command);
 
        return desc + 1;
 }
@@ -168,14 +179,17 @@ APPEND_CMD_RET(move, MOVE)
 
 static inline void set_jump_tgt_here(u32 *desc, u32 *jump_cmd)
 {
-       *jump_cmd = *jump_cmd | (desc_len(desc) - (jump_cmd - desc));
+       *jump_cmd = cpu_to_caam32(caam32_to_cpu(*jump_cmd) |
+                                 (desc_len(desc) - (jump_cmd - desc)));
 }
 
 static inline void set_move_tgt_here(u32 *desc, u32 *move_cmd)
 {
-       *move_cmd &= ~MOVE_OFFSET_MASK;
-       *move_cmd = *move_cmd | ((desc_len(desc) << (MOVE_OFFSET_SHIFT + 2)) &
-                                MOVE_OFFSET_MASK);
+       u32 val = caam32_to_cpu(*move_cmd);
+
+       val &= ~MOVE_OFFSET_MASK;
+       val |= (desc_len(desc) << (MOVE_OFFSET_SHIFT + 2)) & MOVE_OFFSET_MASK;
+       *move_cmd = cpu_to_caam32(val);
 }
 
 #define APPEND_CMD(cmd, op) \
This page took 0.025734 seconds and 5 git commands to generate.