aboutsummaryrefslogtreecommitdiffstats
path: root/lib/librte_kni/rte_kni.c
diff options
context:
space:
mode:
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>2017-06-08 09:46:51 -0600
committerChristian Ehrhardt <christian.ehrhardt@canonical.com>2017-06-08 09:51:02 -0600
commitaab0c291a90f701b60f8c9a88cbcc265cba0ec8b (patch)
treebfa7bf9663cb9a518d81f18e3a2c792eee8fa1c8 /lib/librte_kni/rte_kni.c
parentce3d555e43e3795b5d9507fcfc76b7a0a92fd0d6 (diff)
Imported Upstream version 16.11.2
Change-Id: I947038e46a2c747296dc7aa7522239733ca2f659 Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Diffstat (limited to 'lib/librte_kni/rte_kni.c')
-rw-r--r--lib/librte_kni/rte_kni.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index a80cefd2..c3f9208c 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -451,17 +451,35 @@ kni_free_fifo(struct rte_kni_fifo *fifo)
} while (ret);
}
+static void *
+va2pa(struct rte_mbuf *m)
+{
+ return (void *)((unsigned long)m -
+ ((unsigned long)m->buf_addr -
+ (unsigned long)m->buf_physaddr));
+}
+
+static void
+obj_free(struct rte_mempool *mp __rte_unused, void *opaque, void *obj,
+ unsigned obj_idx __rte_unused)
+{
+ struct rte_mbuf *m = obj;
+ void *mbuf_phys = opaque;
+
+ if (va2pa(m) == mbuf_phys)
+ rte_pktmbuf_free(m);
+}
+
static void
-kni_free_fifo_phy(struct rte_kni_fifo *fifo)
+kni_free_fifo_phy(struct rte_mempool *mp, struct rte_kni_fifo *fifo)
{
void *mbuf_phys;
int ret;
do {
ret = kni_fifo_get(fifo, &mbuf_phys, 1);
- /*
- * TODO: free mbufs
- */
+ if (ret)
+ rte_mempool_obj_iter(mp, obj_free, mbuf_phys);
} while (ret);
}
@@ -470,6 +488,7 @@ rte_kni_release(struct rte_kni *kni)
{
struct rte_kni_device_info dev_info;
uint32_t slot_id;
+ uint32_t retry = 5;
if (!kni || !kni->in_use)
return -1;
@@ -481,9 +500,16 @@ rte_kni_release(struct rte_kni *kni)
}
/* mbufs in all fifo should be released, except request/response */
+
+ /* wait until all rxq packets processed by kernel */
+ while (kni_fifo_count(kni->rx_q) && retry--)
+ usleep(1000);
+
+ if (kni_fifo_count(kni->rx_q))
+ RTE_LOG(ERR, KNI, "Fail to free all Rx-q items\n");
+
+ kni_free_fifo_phy(kni->pktmbuf_pool, kni->alloc_q);
kni_free_fifo(kni->tx_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;
@@ -549,14 +575,6 @@ 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)
{