avf: add avf flow framework
[vpp.git] / src / plugins / avf / avf.h
index 025fa6e..6c09084 100644 (file)
@@ -29,6 +29,9 @@
 
 #include <vnet/interface.h>
 
+#include <vnet/devices/devices.h>
+#include <vnet/flow/flow.h>
+
 #define AVF_QUEUE_SZ_MAX                4096
 #define AVF_QUEUE_SZ_MIN                64
 
@@ -97,16 +100,17 @@ extern vlib_log_class_registration_t avf_log;
             format_vlib_pci_addr, &dev->pci_addr, \
             ## __VA_ARGS__)
 
-#define foreach_avf_device_flags \
-  _(0, INITIALIZED, "initialized") \
-  _(1, ERROR, "error") \
-  _(2, ADMIN_UP, "admin-up") \
-  _(3, VA_DMA, "vaddr-dma") \
-  _(4, LINK_UP, "link-up") \
-  _(5, SHARED_TXQ_LOCK, "shared-txq-lock") \
-  _(6, ELOG, "elog") \
-  _(7, PROMISC, "promisc") \
-  _(8, RX_INT, "rx-interrupts")
+#define foreach_avf_device_flags                                              \
+  _ (0, INITIALIZED, "initialized")                                           \
+  _ (1, ERROR, "error")                                                       \
+  _ (2, ADMIN_UP, "admin-up")                                                 \
+  _ (3, VA_DMA, "vaddr-dma")                                                  \
+  _ (4, LINK_UP, "link-up")                                                   \
+  _ (5, SHARED_TXQ_LOCK, "shared-txq-lock")                                   \
+  _ (6, ELOG, "elog")                                                         \
+  _ (7, PROMISC, "promisc")                                                   \
+  _ (8, RX_INT, "rx-interrupts")                                              \
+  _ (9, RX_FLOW_OFFLOAD, "rx-flow-offload")
 
 enum
 {
@@ -164,6 +168,7 @@ typedef struct
   u16 n_enqueued;
   u8 int_mode;
   u8 buffer_pool_index;
+  u32 queue_index;
 } avf_rxq_t;
 
 typedef struct
@@ -180,6 +185,20 @@ typedef struct
   u16 *rs_slots;
 } avf_txq_t;
 
+typedef struct
+{
+  u32 flow_index;
+  u32 mark;
+  struct avf_fdir_conf *rcfg;
+} avf_flow_entry_t;
+
+typedef struct
+{
+  u32 flow_id;
+  u16 next_index;
+  i16 buffer_advance;
+} avf_flow_lookup_entry_t;
+
 typedef struct
 {
   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
@@ -223,6 +242,10 @@ typedef struct
   virtchnl_link_speed_t link_speed;
   vlib_pci_addr_t pci_addr;
 
+  /* flow */
+  avf_flow_entry_t *flow_entries;              /* pool */
+  avf_flow_lookup_entry_t *flow_lookup_entries; /* pool */
+
   /* stats */
   virtchnl_eth_stats_t eth_stats;
   virtchnl_eth_stats_t last_cleared_eth_stats;
@@ -245,6 +268,7 @@ typedef enum
 {
   AVF_PROCESS_REQ_ADD_DEL_ETH_ADDR = 1,
   AVF_PROCESS_REQ_CONFIG_PROMISC_MDDE = 2,
+  AVF_PROCESS_REQ_PROGRAM_FLOW = 3,
 } avf_process_req_type_t;
 
 typedef struct
@@ -254,6 +278,13 @@ typedef struct
   u32 calling_process_index;
   u8 eth_addr[6];
   int is_add, is_enable;
+
+  /* below parameters are used for 'program flow' event */
+  u8 *rule;
+  u32 rule_len;
+  u8 *program_status;
+  u32 status_len;
+
   clib_error_t *error;
 } avf_process_req_t;
 
@@ -302,10 +333,15 @@ extern vlib_node_registration_t avf_input_node;
 extern vlib_node_registration_t avf_process_node;
 extern vnet_device_class_t avf_device_class;
 
+clib_error_t *avf_program_flow (u32 dev_instance, int is_add, u8 *rule,
+                               u32 rule_len, u8 *program_status,
+                               u32 status_len);
+
 /* format.c */
 format_function_t format_avf_device;
 format_function_t format_avf_device_name;
 format_function_t format_avf_input_trace;
+vnet_flow_dev_ops_function_t avf_flow_ops_fn;
 
 static_always_inline avf_device_t *
 avf_get_device (u32 dev_instance)
@@ -372,6 +408,17 @@ avf_reg_flush (avf_device_t * ad)
   asm volatile ("":::"memory");
 }
 
+static inline void
+avf_tail_write (volatile u32 *addr, u32 val)
+{
+#ifdef __MOVDIRI__
+  _mm_sfence ();
+  _directstoreu_u32 ((void *) addr, val);
+#else
+  clib_atomic_store_rel_n (addr, val);
+#endif
+}
+
 static_always_inline int
 avf_rxd_is_not_eop (avf_rx_desc_t * d)
 {