[qca-nss-drv] Pass device pointer to dma map/unmap
Passing NULL to dma map/unmap would fail on some platform (ex. ARM64).
Pass the original device pointer instead.
Change-Id: I1c36adc0eaf592dd704781a2ea1651b864680f4a
Signed-off-by: Stephen Wang <wstephen@codeaurora.org>
diff --git a/nss_core.c b/nss_core.c
index f5b3c11..6699b55 100644
--- a/nss_core.c
+++ b/nss_core.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
@@ -662,7 +662,7 @@
nss_assert(desc->payload_offs + desc->payload_len <= PAGE_SIZE);
- dma_unmap_page(NULL, (desc->buffer + desc->payload_offs), desc->payload_len, DMA_FROM_DEVICE);
+ dma_unmap_page(nss_ctx->dev, (desc->buffer + desc->payload_offs), desc->payload_len, DMA_FROM_DEVICE);
/*
* The first and last bits are both set. Hence the received frame can't have
@@ -807,7 +807,7 @@
nbuf->data = nbuf->head + desc->payload_offs;
nbuf->len = desc->payload_len;
nbuf->tail = nbuf->data + nbuf->len;
- dma_unmap_single(NULL, (desc->buffer + desc->payload_offs), desc->payload_len, DMA_FROM_DEVICE);
+ dma_unmap_single(nss_ctx->dev, (desc->buffer + desc->payload_offs), desc->payload_len, DMA_FROM_DEVICE);
prefetch((void *)(nbuf->data));
if (likely(bit_flags & N2H_BIT_FLAG_FIRST_SEGMENT) && likely(bit_flags & N2H_BIT_FLAG_LAST_SEGMENT)) {
@@ -1038,7 +1038,7 @@
* No need to invalidate for Tx Completions, so set dma direction = DMA_TO_DEVICE;
* Similarly prefetch is not needed for an empty buffer.
*/
- dma_unmap_single(NULL, (desc->buffer + desc->payload_offs), desc->payload_len, DMA_TO_DEVICE);
+ dma_unmap_single(nss_ctx->dev, (desc->buffer + desc->payload_offs), desc->payload_len, DMA_TO_DEVICE);
goto consume;
}
@@ -1047,7 +1047,7 @@
* one of them is actually looked at.
*/
if ((unlikely(buffer_type == N2H_BUFFER_SHAPER_BOUNCED_INTERFACE)) || (unlikely(buffer_type == N2H_BUFFER_SHAPER_BOUNCED_BRIDGE))) {
- dma_unmap_page(NULL, (desc->buffer + desc->payload_offs), desc->payload_len, DMA_TO_DEVICE);
+ dma_unmap_page(nss_ctx->dev, (desc->buffer + desc->payload_offs), desc->payload_len, DMA_TO_DEVICE);
goto consume;
}
@@ -1323,7 +1323,7 @@
nbuf->truesize += PAGE_SIZE;
/* Map the page for jumbo */
- buffer = dma_map_page(NULL, npage, 0, PAGE_SIZE, DMA_FROM_DEVICE);
+ buffer = dma_map_page(nss_ctx->dev, npage, 0, PAGE_SIZE, DMA_FROM_DEVICE);
desc->buffer_len = PAGE_SIZE;
desc->payload_offs = 0;
@@ -1341,7 +1341,7 @@
/*
* Map the skb
*/
- buffer = dma_map_single(NULL, nbuf->head, jumbo_mru, DMA_FROM_DEVICE);
+ buffer = dma_map_single(nss_ctx->dev, nbuf->head, jumbo_mru, DMA_FROM_DEVICE);
desc->buffer_len = jumbo_mru;
desc->payload_offs = (uint16_t) (nbuf->data - nbuf->head);
@@ -1360,12 +1360,12 @@
* Map the skb
*/
payload_len = max_buf_size + NET_SKB_PAD;
- buffer = dma_map_single(NULL, nbuf->head, payload_len, DMA_FROM_DEVICE);
+ buffer = dma_map_single(nss_ctx->dev, nbuf->head, payload_len, DMA_FROM_DEVICE);
desc->buffer_len = payload_len;
desc->payload_offs = (uint16_t) (nbuf->data - nbuf->head);
}
- if (unlikely(dma_mapping_error(NULL, buffer))) {
+ if (unlikely(dma_mapping_error(nss_ctx->dev, buffer))) {
/*
* ERR:
*/
@@ -1661,7 +1661,7 @@
* nss_core_send_unwind_dma()
* It unwinds (or unmap) DMA from descriptors
*/
-static inline void nss_core_send_unwind_dma(struct h2n_desc_if_instance *desc_if,
+static inline void nss_core_send_unwind_dma(struct device *dev, struct h2n_desc_if_instance *desc_if,
uint16_t hlos_index, int16_t count, bool is_fraglist)
{
struct h2n_descriptor *desc_ring = desc_if->desc;
@@ -1672,9 +1672,9 @@
for (i = 0; i < count; i++) {
desc = &desc_ring[hlos_index];
if (is_fraglist) {
- dma_unmap_single(NULL, desc->buffer, desc->buffer_len, DMA_TO_DEVICE);
+ dma_unmap_single(dev, desc->buffer, desc->buffer_len, DMA_TO_DEVICE);
} else {
- dma_unmap_page(NULL, desc->buffer, desc->buffer_len, DMA_TO_DEVICE);
+ dma_unmap_page(dev, desc->buffer, desc->buffer_len, DMA_TO_DEVICE);
}
hlos_index = (hlos_index + 1) & mask;
}
@@ -1835,8 +1835,8 @@
* and then map Rx over the entire buffer.
*/
sz = max((uint16_t)(nbuf->tail - nbuf->head), (uint16_t)(nss_ctx->max_buf_size + NET_SKB_PAD));
- frag0phyaddr = (uint32_t)dma_map_single(NULL, nbuf->head, sz, DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(NULL, frag0phyaddr))) {
+ frag0phyaddr = (uint32_t)dma_map_single(nss_ctx->dev, nbuf->head, sz, DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(nss_ctx->dev, frag0phyaddr))) {
goto no_reuse;
}
@@ -1860,8 +1860,8 @@
#endif
frag0phyaddr = 0;
- frag0phyaddr = (uint32_t)dma_map_single(NULL, nbuf->head, (nbuf->tail - nbuf->head), DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(NULL, frag0phyaddr))) {
+ frag0phyaddr = (uint32_t)dma_map_single(nss_ctx->dev, nbuf->head, (nbuf->tail - nbuf->head), DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(nss_ctx->dev, frag0phyaddr))) {
nss_warning("%p: DMA mapping failed for virtual address = %x", nss_ctx, (uint32_t)nbuf->head);
return 0;
}
@@ -1895,8 +1895,8 @@
uint16_t mask;
uint32_t frag0phyaddr = 0;
- frag0phyaddr = (uint32_t)dma_map_single(NULL, nbuf->head, (nbuf->tail - nbuf->head), DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(NULL, frag0phyaddr))) {
+ frag0phyaddr = (uint32_t)dma_map_single(nss_ctx->dev, nbuf->head, (nbuf->tail - nbuf->head), DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(nss_ctx->dev, frag0phyaddr))) {
nss_warning("%p: DMA mapping failed for virtual address = %x", nss_ctx, (uint32_t)nbuf->head);
return 0;
}
@@ -1927,10 +1927,10 @@
for (i = 0; i < nr_frags; i++) {
frag = &skb_shinfo(nbuf)->frags[i];
- buffer = skb_frag_dma_map(NULL, frag, 0, skb_frag_size(frag), DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(NULL, buffer))) {
+ buffer = skb_frag_dma_map(nss_ctx->dev, frag, 0, skb_frag_size(frag), DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(nss_ctx->dev, buffer))) {
nss_warning("%p: DMA mapping failed for fragment", nss_ctx);
- nss_core_send_unwind_dma(desc_if, hlos_index, i + 1, is_fraglist);
+ nss_core_send_unwind_dma(nss_ctx->dev, desc_if, hlos_index, i + 1, is_fraglist);
return -(i + 1);
}
@@ -1978,8 +1978,8 @@
int16_t i;
uint32_t frag0phyaddr = 0;
- frag0phyaddr = (uint32_t)dma_map_single(NULL, nbuf->head, (nbuf->tail - nbuf->head), DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(NULL, frag0phyaddr))) {
+ frag0phyaddr = (uint32_t)dma_map_single(nss_ctx->dev, nbuf->head, (nbuf->tail - nbuf->head), DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(nss_ctx->dev, frag0phyaddr))) {
nss_warning("%p: DMA mapping failed for virtual address = %x", nss_ctx, (uint32_t)nbuf->head);
return 0;
}
@@ -2014,10 +2014,10 @@
skb_walk_frags(nbuf, iter) {
uint32_t nr_frags;
- buffer = (uint32_t)dma_map_single(NULL, iter->head, (iter->tail - iter->head), DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(NULL, buffer))) {
+ buffer = (uint32_t)dma_map_single(nss_ctx->dev, iter->head, (iter->tail - iter->head), DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(nss_ctx->dev, buffer))) {
nss_warning("%p: DMA mapping failed for virtual address = %x", nss_ctx, (uint32_t)iter->head);
- nss_core_send_unwind_dma(desc_if, hlos_index, i + 1, is_fraglist);
+ nss_core_send_unwind_dma(nss_ctx->dev, desc_if, hlos_index, i + 1, is_fraglist);
return -(i+1);
}
@@ -2028,7 +2028,7 @@
nr_frags = skb_shinfo(iter)->nr_frags;
if (unlikely(nr_frags > 0)) {
nss_warning("%p: fraglist with page data are not supported: %p\n", nss_ctx, iter);
- nss_core_send_unwind_dma(desc_if, hlos_index, i + 1, is_fraglist);
+ nss_core_send_unwind_dma(nss_ctx->dev, desc_if, hlos_index, i + 1, is_fraglist);
return -(i+1);
}
diff --git a/nss_core.h b/nss_core.h
index 4c659df..7a23849 100644
--- a/nss_core.h
+++ b/nss_core.h
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
@@ -870,6 +870,7 @@
struct nss_ctx_instance {
struct nss_top_instance *nss_top;
/* Back pointer to NSS Top */
+ struct device *dev; /* Pointer to the original device from probe */
uint32_t id; /* Core ID for this instance */
uint32_t nmap; /* Pointer to NSS CSM registers */
uint32_t vmap; /* Virt mem pointer to virtual register map */
diff --git a/nss_hal/nss_hal.c b/nss_hal/nss_hal.c
index 0858d73..da94470 100644
--- a/nss_hal/nss_hal.c
+++ b/nss_hal/nss_hal.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
@@ -541,6 +541,11 @@
nss_top->num_nss++;
/*
+ * dev is required for dma map/unmap
+ */
+ nss_ctx->dev = &nss_dev->dev;
+
+ /*
* Enable interrupts for NSS core
*/
nss_hal_enable_interrupt(nss_ctx, nss_ctx->int_ctx[0].shift_factor, NSS_HAL_SUPPORTED_INTERRUPTS);
diff --git a/nss_log.c b/nss_log.c
index aba17bd..ba4973d 100644
--- a/nss_log.c
+++ b/nss_log.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
@@ -471,8 +471,8 @@
}
memset(addr, 0, size);
- dma_addr = (uint32_t)dma_map_single(NULL, addr, size, DMA_FROM_DEVICE);
- if (unlikely(dma_mapping_error(NULL, dma_addr))) {
+ dma_addr = (uint32_t)dma_map_single(nss_ctx->dev, addr, size, DMA_FROM_DEVICE);
+ if (unlikely(dma_mapping_error(nss_ctx->dev, dma_addr))) {
nss_warning("%p: Failed to map address in DMA", nss_ctx);
goto fail2;
}
@@ -557,7 +557,7 @@
old_size = sizeof (struct nss_log_descriptor) +
(sizeof (struct nss_log_entry) * old_rbe.nentries);
- dma_unmap_single(NULL, old_rbe.dma_addr, old_size, DMA_FROM_DEVICE);
+ dma_unmap_single(nss_ctx->dev, old_rbe.dma_addr, old_size, DMA_FROM_DEVICE);
kfree(old_rbe.addr);
} else {
/*
diff --git a/nss_n2h.c b/nss_n2h.c
index 54df82b..f6586dd 100644
--- a/nss_n2h.c
+++ b/nss_n2h.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
@@ -930,7 +930,7 @@
}
buf_pool->nss_buf_pool_vaddr[page_count] = kern_addr;
- buf_pool->nss_buf_pool_addr[page_count] = dma_map_single(NULL, kern_addr, PAGE_SIZE, DMA_TO_DEVICE);
+ buf_pool->nss_buf_pool_addr[page_count] = dma_map_single(nss_ctx->dev, kern_addr, PAGE_SIZE, DMA_TO_DEVICE);
}
buf_pool->nss_buf_num_pages = page_count;