summaryrefslogtreecommitdiff
path: root/lib/librte_kni/rte_kni.c
diff options
context:
space:
mode:
authorFerruh Yigit <ferruh.yigit@intel.com>2016-08-25 12:30:34 +0100
committerThomas Monjalon <thomas.monjalon@6wind.com>2016-09-21 19:18:44 +0200
commit8451269e6d7ba7501723fe2efd05745010295bac (patch)
tree74ba5324a452843d55790046ddc61f28cf49b5be /lib/librte_kni/rte_kni.c
parentf503b8cff520c5b17d929c7ee8304c2eab7bb20b (diff)
downloaddpdk-8451269e6d7ba7501723fe2efd05745010295bac.zip
dpdk-8451269e6d7ba7501723fe2efd05745010295bac.tar.gz
dpdk-8451269e6d7ba7501723fe2efd05745010295bac.tar.xz
kni: remove continuous memory restriction
Use mempool buf_addr and buf_physaddr fields for address translation. Since each mbuf address calculated separately, the restriction of all mbufs should come from a continuous memory restriction is no more valid. mbuf related FIFO's content changed, rx_q and alloc_q now carries physical address of mbufs. tx_q and free_q content not changed, they still carries virtual address of mbufs. Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Diffstat (limited to 'lib/librte_kni/rte_kni.c')
-rw-r--r--lib/librte_kni/rte_kni.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index d88a70d..a80cefd 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -416,14 +416,6 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
dev_info.sync_va = mz->addr;
dev_info.sync_phys = mz->phys_addr;
-
- /* MBUF mempool */
- /* KNI currently requires to have only one memory chunk */
- if (pktmbuf_pool->nb_mem_chunks != 1)
- goto kni_fail;
-
- dev_info.mbuf_va = STAILQ_FIRST(&pktmbuf_pool->mem_list)->addr;
- dev_info.mbuf_phys = STAILQ_FIRST(&pktmbuf_pool->mem_list)->phys_addr;
ctx->pktmbuf_pool = pktmbuf_pool;
ctx->group_id = conf->group_id;
ctx->slot_id = slot->id;
@@ -459,6 +451,20 @@ kni_free_fifo(struct rte_kni_fifo *fifo)
} while (ret);
}
+static void
+kni_free_fifo_phy(struct rte_kni_fifo *fifo)
+{
+ void *mbuf_phys;
+ int ret;
+
+ do {
+ ret = kni_fifo_get(fifo, &mbuf_phys, 1);
+ /*
+ * TODO: free mbufs
+ */
+ } while (ret);
+}
+
int
rte_kni_release(struct rte_kni *kni)
{
@@ -476,8 +482,8 @@ rte_kni_release(struct rte_kni *kni)
/* mbufs in all fifo should be released, except request/response */
kni_free_fifo(kni->tx_q);
- kni_free_fifo(kni->rx_q);
- kni_free_fifo(kni->alloc_q);
+ kni_free_fifo_phy(kni->rx_q);
+ kni_free_fifo_phy(kni->alloc_q);
kni_free_fifo(kni->free_q);
slot_id = kni->slot_id;
@@ -543,10 +549,25 @@ rte_kni_handle_request(struct rte_kni *kni)
return 0;
}
+static void *
+va2pa(struct rte_mbuf *m)
+{
+ return (void *)((unsigned long)m -
+ ((unsigned long)m->buf_addr -
+ (unsigned long)m->buf_physaddr));
+}
+
unsigned
rte_kni_tx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned num)
{
- unsigned ret = kni_fifo_put(kni->rx_q, (void **)mbufs, num);
+ void *phy_mbufs[num];
+ unsigned int ret;
+ unsigned int i;
+
+ for (i = 0; i < num; i++)
+ phy_mbufs[i] = va2pa(mbufs[i]);
+
+ ret = kni_fifo_put(kni->rx_q, phy_mbufs, num);
/* Get mbufs from free_q and then free them */
kni_free_mbufs(kni);
@@ -584,6 +605,7 @@ kni_allocate_mbufs(struct rte_kni *kni)
{
int i, ret;
struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM];
+ void *phys[MAX_MBUF_BURST_NUM];
RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pool) !=
offsetof(struct rte_kni_mbuf, pool));
@@ -613,13 +635,14 @@ kni_allocate_mbufs(struct rte_kni *kni)
RTE_LOG(ERR, KNI, "Out of memory\n");
break;
}
+ phys[i] = va2pa(pkts[i]);
}
/* No pkt mbuf alocated */
if (i <= 0)
return;
- ret = kni_fifo_put(kni->alloc_q, (void **)pkts, i);
+ ret = kni_fifo_put(kni->alloc_q, phys, i);
/* Check if any mbufs not put into alloc_q, and then free them */
if (ret >= 0 && ret < i && ret < MAX_MBUF_BURST_NUM) {