crypto/dpaa_sec: use virt2memseg instead of iteration
[dpdk.git] / drivers / crypto / dpaa_sec / dpaa_sec.c
index 18681cf..a14e669 100644 (file)
@@ -84,7 +84,7 @@ dpaa_sec_alloc_ctx(dpaa_sec_session *ses)
        dcbz_64(&ctx->job.sg[SG_CACHELINE_3]);
 
        ctx->ctx_pool = ses->ctx_pool;
-       ctx->vtop_offset = (uint64_t) ctx
+       ctx->vtop_offset = (size_t) ctx
                                - rte_mempool_virt2iova(ctx);
 
        return ctx;
@@ -93,43 +93,25 @@ dpaa_sec_alloc_ctx(dpaa_sec_session *ses)
 static inline rte_iova_t
 dpaa_mem_vtop(void *vaddr)
 {
-       const struct rte_memseg *memseg = rte_eal_get_physmem_layout();
-       uint64_t vaddr_64, paddr;
-       int i;
-
-       vaddr_64 = (uint64_t)vaddr;
-       for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr_64 != 0; i++) {
-               if (vaddr_64 >= memseg[i].addr_64 &&
-                   vaddr_64 < memseg[i].addr_64 + memseg[i].len) {
-                       paddr = memseg[i].iova +
-                               (vaddr_64 - memseg[i].addr_64);
-
-                       return (rte_iova_t)paddr;
-               }
-       }
-       return (rte_iova_t)(NULL);
+       const struct rte_memseg *ms;
+
+       ms = rte_mem_virt2memseg(vaddr);
+       if (ms)
+               return ms->iova + RTE_PTR_DIFF(vaddr, ms->addr);
+       return (size_t)NULL;
 }
 
 /* virtual address conversin when mempool support is available for ctx */
 static inline phys_addr_t
 dpaa_mem_vtop_ctx(struct dpaa_sec_op_ctx *ctx, void *vaddr)
 {
-       return (uint64_t)vaddr - ctx->vtop_offset;
+       return (size_t)vaddr - ctx->vtop_offset;
 }
 
 static inline void *
 dpaa_mem_ptov(rte_iova_t paddr)
 {
-       const struct rte_memseg *memseg = rte_eal_get_physmem_layout();
-       int i;
-
-       for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr_64 != 0; i++) {
-               if (paddr >= memseg[i].iova &&
-                   (char *)paddr < (char *)memseg[i].iova + memseg[i].len)
-                       return (void *)(memseg[i].addr_64 +
-                                       (paddr - memseg[i].iova));
-       }
-       return NULL;
+       return rte_mem_iova2virt(paddr);
 }
 
 static void
@@ -406,7 +388,7 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                        return -ENOTSUP;
                }
 
-               alginfo_c.key = (uint64_t)ses->cipher_key.data;
+               alginfo_c.key = (size_t)ses->cipher_key.data;
                alginfo_c.keylen = ses->cipher_key.length;
                alginfo_c.key_enc_flags = 0;
                alginfo_c.key_type = RTA_DATA_IMM;
@@ -424,7 +406,7 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                        return -ENOTSUP;
                }
 
-               alginfo_a.key = (uint64_t)ses->auth_key.data;
+               alginfo_a.key = (size_t)ses->auth_key.data;
                alginfo_a.keylen = ses->auth_key.length;
                alginfo_a.key_enc_flags = 0;
                alginfo_a.key_type = RTA_DATA_IMM;
@@ -439,7 +421,7 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                        PMD_TX_LOG(ERR, "not supported aead alg\n");
                        return -ENOTSUP;
                }
-               alginfo.key = (uint64_t)ses->aead_key.data;
+               alginfo.key = (size_t)ses->aead_key.data;
                alginfo.keylen = ses->aead_key.length;
                alginfo.key_enc_flags = 0;
                alginfo.key_type = RTA_DATA_IMM;
@@ -463,7 +445,7 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                        return -ENOTSUP;
                }
 
-               alginfo_c.key = (uint64_t)ses->cipher_key.data;
+               alginfo_c.key = (size_t)ses->cipher_key.data;
                alginfo_c.keylen = ses->cipher_key.length;
                alginfo_c.key_enc_flags = 0;
                alginfo_c.key_type = RTA_DATA_IMM;
@@ -474,7 +456,7 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                        return -ENOTSUP;
                }
 
-               alginfo_a.key = (uint64_t)ses->auth_key.data;
+               alginfo_a.key = (size_t)ses->auth_key.data;
                alginfo_a.keylen = ses->auth_key.length;
                alginfo_a.key_enc_flags = 0;
                alginfo_a.key_type = RTA_DATA_IMM;
@@ -493,15 +475,15 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                if (cdb->sh_desc[2] & 1)
                        alginfo_c.key_type = RTA_DATA_IMM;
                else {
-                       alginfo_c.key = (uint64_t)dpaa_mem_vtop(
-                                                       (void *)alginfo_c.key);
+                       alginfo_c.key = (size_t)dpaa_mem_vtop(
+                                               (void *)(size_t)alginfo_c.key);
                        alginfo_c.key_type = RTA_DATA_PTR;
                }
                if (cdb->sh_desc[2] & (1<<1))
                        alginfo_a.key_type = RTA_DATA_IMM;
                else {
-                       alginfo_a.key = (uint64_t)dpaa_mem_vtop(
-                                                       (void *)alginfo_a.key);
+                       alginfo_a.key = (size_t)dpaa_mem_vtop(
+                                               (void *)(size_t)alginfo_a.key);
                        alginfo_a.key_type = RTA_DATA_PTR;
                }
                cdb->sh_desc[0] = 0;