Imported Upstream version 16.11
[deb_dpdk.git] / lib / librte_port / rte_port_fd.h
similarity index 53%
rename from lib/librte_vhost/vhost_cuse/eventfd_copy.c
rename to lib/librte_port/rte_port_fd.h
index 154b32a..77a2d31 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <unistd.h>
-#include <sys/eventfd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#ifndef __INCLUDE_RTE_PORT_FD_H__
+#define __INCLUDE_RTE_PORT_FD_H__
 
-#include <rte_log.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-#include "eventfd_link/eventfd_link.h"
-#include "eventfd_copy.h"
-#include "vhost-net.h"
+/**
+ * @file
+ * RTE Port FD Device
+ *
+ * fd_reader: input port built on top of valid non-blocking file descriptor
+ * fd_writer: output port built on top of valid non-blocking file descriptor
+ *
+ ***/
 
-static const char eventfd_cdev[] = "/dev/eventfd-link";
+#include <stdint.h>
 
-static int eventfd_link = -1;
+#include <rte_mempool.h>
+#include "rte_port.h"
 
-int
-eventfd_init(void)
-{
-       if (eventfd_link >= 0)
-               return 0;
+/** fd_reader port parameters */
+struct rte_port_fd_reader_params {
+       /** File descriptor */
+       int fd;
 
-       eventfd_link = open(eventfd_cdev, O_RDWR);
-       if (eventfd_link < 0) {
-               RTE_LOG(ERR, VHOST_CONFIG,
-                       "eventfd_link module is not loaded\n");
-               return -1;
-       }
+       /** Maximum Transfer Unit (MTU) */
+       uint32_t mtu;
 
-       return 0;
-}
+       /** Pre-initialized buffer pool */
+       struct rte_mempool *mempool;
+};
 
-int
-eventfd_free(void)
-{
-       if (eventfd_link >= 0)
-               close(eventfd_link);
-       return 0;
-}
+/** fd_reader port operations */
+extern struct rte_port_in_ops rte_port_fd_reader_ops;
 
-/*
- * This function uses the eventfd_link kernel module to copy an eventfd file
- * descriptor provided by QEMU in to our process space.
- */
-int
-eventfd_copy(int target_fd, int target_pid)
-{
-       int ret;
-       struct eventfd_copy2 eventfd_copy2;
-
-
-       /* Open the character device to the kernel module. */
-       /* TODO: check this earlier rather than fail until VM boots! */
-       if (eventfd_init() < 0)
-               return -1;
-
-       eventfd_copy2.fd = target_fd;
-       eventfd_copy2.pid = target_pid;
-       eventfd_copy2.flags = O_NONBLOCK | O_CLOEXEC;
-       /* Call the IOCTL to copy the eventfd. */
-       ret = ioctl(eventfd_link, EVENTFD_COPY2, &eventfd_copy2);
-
-       if (ret < 0) {
-               RTE_LOG(ERR, VHOST_CONFIG,
-                       "EVENTFD_COPY2 ioctl failed\n");
-               return -1;
-       }
-
-       return ret;
+/** fd_writer port parameters */
+struct rte_port_fd_writer_params {
+       /** File descriptor */
+       int fd;
+
+       /**< Recommended write burst size. The actual burst size can be
+        * bigger or smaller than this value.
+        */
+       uint32_t tx_burst_sz;
+};
+
+/** fd_writer port operations */
+extern struct rte_port_out_ops rte_port_fd_writer_ops;
+
+/** fd_writer_nodrop port parameters */
+struct rte_port_fd_writer_nodrop_params {
+       /** File descriptor */
+       int fd;
+
+       /**< Recommended write burst size. The actual burst size can be
+        * bigger or smaller than this value.
+        */
+       uint32_t tx_burst_sz;
+
+       /** Maximum number of retries, 0 for no limit */
+       uint32_t n_retries;
+};
+
+/** fd_writer_nodrop port operations */
+extern struct rte_port_out_ops rte_port_fd_writer_nodrop_ops;
+
+#ifdef __cplusplus
 }
+#endif
+
+#endif