Harmonize vec/pool_get_aligned object sizes and alignment requests
[vpp.git] / src / plugins / memif / private.h
index 985ac5e..5c8a919 100644 (file)
 
 #if MEMIF_DEBUG == 1
 #define memif_file_add(a, b) do {                                      \
-  ASSERT (*a == ~0);                                                   \
-  *a = unix_file_add (&unix_main, b);                                  \
-  clib_warning ("unix_file_add fd %d private_data %u idx %u",          \
+  *a = clib_file_add (&file_main, b);                                  \
+  clib_warning ("clib_file_add fd %d private_data %u idx %u",          \
                (b)->file_descriptor, (b)->private_data, *a);           \
 } while (0)
 
 #define memif_file_del(a) do {                                         \
-  clib_warning ("unix_file_del idx %u",a - unix_main.file_pool);       \
-  unix_file_del (&unix_main, a);                                       \
+  clib_warning ("clib_file_del idx %u",a - file_main.file_pool);       \
+  clib_file_del (&file_main, a);                                       \
 } while (0)
 
 #define memif_file_del_by_index(a) do {                                        \
-  clib_warning ("unix_file_del idx %u", a);                            \
-  unix_file_del_by_index (&unix_main, a);                              \
+  clib_warning ("clib_file_del idx %u", a);                            \
+  clib_file_del_by_index (&file_main, a);                              \
 } while (0)
 #else
 #define memif_file_add(a, b) do {                                      \
-  ASSERT (*a == ~0);                                                   \
-  *a = unix_file_add (&unix_main, b);                                  \
+  *a = clib_file_add (&file_main, b);                                  \
 } while (0)
-#define memif_file_del(a) unix_file_del(&unix_main, a)
-#define memif_file_del_by_index(a) unix_file_del_by_index(&unix_main, a)
+#define memif_file_del(a) clib_file_del(&file_main, a)
+#define memif_file_del_by_index(a) clib_file_del_by_index(&file_main, a)
 #endif
 
 typedef struct
 {
   u8 *filename;
-  int fd;
-  uword unix_file_index;
-  uword *pending_file_indices;
+  u32 socket_id;
+  clib_socket_t *sock;
+  clib_socket_t **pending_clients;
   int ref_cnt;
   int is_listener;
 
@@ -82,9 +80,12 @@ typedef struct
 
 typedef struct
 {
+  /* Required for vec_validate_aligned */
+  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
   void *shm;
   memif_region_size_t region_size;
   int fd;
+  u8 is_external;
 } memif_region_t;
 
 typedef struct
@@ -103,11 +104,15 @@ typedef struct
 
   u16 last_head;
   u16 last_tail;
+  u32 *buffers;
 
   /* interrupts */
   int int_fd;
-  uword int_unix_file_index;
+  uword int_clib_file_index;
   u64 int_count;
+
+  /* queue type */
+  memif_ring_type_t type;
 } memif_queue_t;
 
 #define foreach_memif_if_flag \
@@ -115,7 +120,9 @@ typedef struct
   _(1, IS_SLAVE, "slave")              \
   _(2, CONNECTING, "connecting")       \
   _(3, CONNECTED, "connected")         \
-  _(4, DELETING, "deleting")
+  _(4, DELETING, "deleting")           \
+  _(5, ZERO_COPY, "zero-copy")         \
+  _(6, ERROR, "error")
 
 typedef enum
 {
@@ -138,9 +145,8 @@ typedef struct
   u32 per_interface_next_index;
 
   /* socket connection */
+  clib_socket_t *sock;
   uword socket_file_index;
-  int conn_fd;
-  uword conn_unix_file_index;
   memif_msg_fifo_elt_t *msg_queue;
   u8 *secret;
 
@@ -150,9 +156,6 @@ typedef struct
   memif_queue_t *tx_queues;
 
   /* remote info */
-  pid_t remote_pid;
-  uid_t remote_uid;
-  gid_t remote_gid;
   u8 *remote_name;
   u8 *remote_if_name;
 
@@ -177,6 +180,36 @@ typedef struct
   u8 *remote_disc_string;
 } memif_if_t;
 
+typedef struct
+{
+  u32 packet_len;
+  u16 first_buffer_vec_index;
+} memif_packet_op_t;
+
+typedef struct
+{
+  void *data;
+  u32 data_len;
+  i16 buffer_offset;
+  u16 buffer_vec_index;
+} memif_copy_op_t;
+
+#define MEMIF_RX_VECTOR_SZ VLIB_FRAME_SIZE
+
+typedef struct
+{
+  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
+
+  /* copy vector */
+  memif_packet_op_t packet_ops[MEMIF_RX_VECTOR_SZ];
+  memif_copy_op_t *copy_ops;
+  u32 *buffers;
+
+  /* buffer template */
+  vlib_buffer_t buffer_template;
+  memif_desc_t desc_template;
+} memif_per_thread_data_t;
+
 typedef struct
 {
   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
@@ -189,10 +222,10 @@ typedef struct
 
   /* pool of all unix socket files */
   memif_socket_file_t *socket_files;
-  mhash_t socket_file_index_by_filename;
+  uword *socket_file_index_by_sock_id; /* map user socket id to pool idx */
 
-  /* rx buffer cache */
-  u32 **rx_buffers;
+  /* per thread data */
+  memif_per_thread_data_t *per_thread_data;
 
 } memif_main_t;
 
@@ -209,9 +242,10 @@ enum
 typedef struct
 {
   memif_interface_id_t id;
-  u8 *socket_filename;
+  u32 socket_id;
   u8 *secret;
   u8 is_master;
+  u8 is_zero_copy;
   memif_interface_mode_t mode:8;
   memif_log2_ring_size_t log2_ring_size;
   u16 buffer_size;
@@ -224,28 +258,12 @@ typedef struct
   u32 sw_if_index;
 } memif_create_if_args_t;
 
+int memif_socket_filename_add_del (u8 is_add, u32 sock_id,
+                                  u8 * sock_filename);
 int memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args);
 int memif_delete_if (vlib_main_t * vm, memif_if_t * mif);
 clib_error_t *memif_plugin_api_hookup (vlib_main_t * vm);
 
-#ifndef __NR_memfd_create
-#if defined __x86_64__
-#define __NR_memfd_create 319
-#elif defined __arm__
-#define __NR_memfd_create 385
-#elif defined __aarch64__
-#define __NR_memfd_create 279
-#else
-#error "__NR_memfd_create unknown for this architecture"
-#endif
-#endif
-
-static inline int
-memfd_create (const char *name, unsigned int flags)
-{
-  return syscall (__NR_memfd_create, name, flags);
-}
-
 static_always_inline void *
 memif_get_buffer (memif_if_t * mif, memif_ring_t * ring, u16 slot)
 {
@@ -253,31 +271,20 @@ memif_get_buffer (memif_if_t * mif, memif_ring_t * ring, u16 slot)
   return mif->regions[region].shm + ring->desc[slot].offset;
 }
 
-#ifndef F_LINUX_SPECIFIC_BASE
-#define F_LINUX_SPECIFIC_BASE 1024
-#endif
-#define MFD_ALLOW_SEALING       0x0002U
-#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
-#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
-
-#define F_SEAL_SEAL     0x0001 /* prevent further seals from being set */
-#define F_SEAL_SHRINK   0x0002 /* prevent file from shrinking */
-#define F_SEAL_GROW     0x0004 /* prevent file from growing */
-#define F_SEAL_WRITE    0x0008 /* prevent writes */
-
 /* memif.c */
 clib_error_t *memif_init_regions_and_queues (memif_if_t * mif);
 clib_error_t *memif_connect (memif_if_t * mif);
 void memif_disconnect (memif_if_t * mif, clib_error_t * err);
 
 /* socket.c */
-clib_error_t *memif_conn_fd_accept_ready (unix_file_t * uf);
-clib_error_t *memif_master_conn_fd_read_ready (unix_file_t * uf);
-clib_error_t *memif_slave_conn_fd_read_ready (unix_file_t * uf);
-clib_error_t *memif_master_conn_fd_write_ready (unix_file_t * uf);
-clib_error_t *memif_slave_conn_fd_write_ready (unix_file_t * uf);
-clib_error_t *memif_master_conn_fd_error (unix_file_t * uf);
-clib_error_t *memif_slave_conn_fd_error (unix_file_t * uf);
+void memif_socket_close (clib_socket_t ** sock);
+clib_error_t *memif_conn_fd_accept_ready (clib_file_t * uf);
+clib_error_t *memif_master_conn_fd_read_ready (clib_file_t * uf);
+clib_error_t *memif_slave_conn_fd_read_ready (clib_file_t * uf);
+clib_error_t *memif_master_conn_fd_write_ready (clib_file_t * uf);
+clib_error_t *memif_slave_conn_fd_write_ready (clib_file_t * uf);
+clib_error_t *memif_master_conn_fd_error (clib_file_t * uf);
+clib_error_t *memif_slave_conn_fd_error (clib_file_t * uf);
 clib_error_t *memif_msg_send_disconnect (memif_if_t * mif,
                                         clib_error_t * err);
 u8 *format_memif_device_name (u8 * s, va_list * args);