From 904d29a135381d81d0758f16404d33e99623abd5 Mon Sep 17 00:00:00 2001 From: Intel Date: Wed, 18 Sep 2013 12:00:00 +0200 Subject: [PATCH] kni: move FIFO functions Move FIFO functions into kni_fifo.h in order to reuse it for vhost. Signed-off-by: Intel --- lib/librte_eal/linuxapp/kni/kni_fifo.h | 94 ++++++++++++++++++++++++++ lib/librte_eal/linuxapp/kni/kni_net.c | 63 +---------------- 2 files changed, 95 insertions(+), 62 deletions(-) create mode 100644 lib/librte_eal/linuxapp/kni/kni_fifo.h diff --git a/lib/librte_eal/linuxapp/kni/kni_fifo.h b/lib/librte_eal/linuxapp/kni/kni_fifo.h new file mode 100644 index 0000000000..2022cb2743 --- /dev/null +++ b/lib/librte_eal/linuxapp/kni/kni_fifo.h @@ -0,0 +1,94 @@ +/*- + * GPL LICENSE SUMMARY + * + * Copyright(c) 2010-2013 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + */ + +#ifndef _KNI_FIFO_H_ +#define _KNI_FIFO_H_ + +#include + +/** + * Adds num elements into the fifo. Return the number actually written + */ +static inline unsigned +kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) +{ + unsigned i = 0; + unsigned fifo_write = fifo->write; + unsigned fifo_read = fifo->read; + unsigned new_write = fifo_write; + + for (i = 0; i < num; i++) { + new_write = (new_write + 1) & (fifo->len - 1); + + if (new_write == fifo_read) + break; + fifo->buffer[fifo_write] = data[i]; + fifo_write = new_write; + } + fifo->write = fifo_write; + + return i; +} + +/** + * Get up to num elements from the fifo. Return the number actully read + */ +static inline unsigned +kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) +{ + unsigned i = 0; + unsigned new_read = fifo->read; + unsigned fifo_write = fifo->write; + + for (i = 0; i < num; i++) { + if (new_read == fifo_write) + break; + + data[i] = fifo->buffer[new_read]; + new_read = (new_read + 1) & (fifo->len - 1); + } + fifo->read = new_read; + + return i; +} + +/** + * Get the num of elements in the fifo + */ +static inline unsigned +kni_fifo_count(struct rte_kni_fifo *fifo) +{ + return (fifo->len + fifo->write - fifo->read) & ( fifo->len - 1); +} + +/** + * Get the num of available elements in the fifo + */ +static inline unsigned +kni_fifo_free_count(struct rte_kni_fifo *fifo) +{ + return (fifo->read - fifo->write - 1) & (fifo->len - 1); +} + +#endif /* _KNI_FIFO_H_ */ diff --git a/lib/librte_eal/linuxapp/kni/kni_net.c b/lib/librte_eal/linuxapp/kni/kni_net.c index 823c321db9..f98a2ce466 100644 --- a/lib/librte_eal/linuxapp/kni/kni_net.c +++ b/lib/librte_eal/linuxapp/kni/kni_net.c @@ -38,6 +38,7 @@ #include #include +#include #include "kni_dev.h" #define WD_TIMEOUT 5 /*jiffies */ @@ -59,68 +60,6 @@ static int kni_net_process_request(struct kni_dev *kni, /* kni rx function pointer, with default to normal rx */ static kni_net_rx_t kni_net_rx_func = kni_net_rx_normal; - -/** - * Adds num elements into the fifo. Return the number actually written - */ -static inline unsigned -kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) -{ - unsigned i = 0; - unsigned fifo_write = fifo->write; - unsigned fifo_read = fifo->read; - unsigned new_write = fifo_write; - - for (i = 0; i < num; i++) { - new_write = (new_write + 1) & (fifo->len - 1); - - if (new_write == fifo_read) - break; - fifo->buffer[fifo_write] = data[i]; - fifo_write = new_write; - } - fifo->write = fifo_write; - return i; -} - -/** - * Get up to num elements from the fifo. Return the number actully read - */ -static inline unsigned -kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) -{ - unsigned i = 0; - unsigned new_read = fifo->read; - unsigned fifo_write = fifo->write; - for (i = 0; i < num; i++) { - if (new_read == fifo_write) - break; - - data[i] = fifo->buffer[new_read]; - new_read = (new_read + 1) & (fifo->len - 1); - } - fifo->read = new_read; - return i; -} - -/** - * Get the num of elements in the fifo - */ -static inline unsigned -kni_fifo_count(struct rte_kni_fifo *fifo) -{ - return (fifo->len + fifo->write - fifo->read) &( fifo->len - 1); -} - -/** - * Get the num of available lements in the fifo - */ -static inline unsigned -kni_fifo_free_count(struct rte_kni_fifo *fifo) -{ - return (fifo->read - fifo->write - 1) & (fifo->len - 1); -} - /* * Open and close */ -- 2.20.1