examples/fips_validation: fix buffer overflow
[dpdk.git] / lib / librte_eventdev / rte_event_eth_rx_adapter.h
index 97f25e9..2dd259c 100644 (file)
  * rte_event_eth_rx_adapter_service_id_get() function can be used to retrieve
  * the service function ID of the adapter in this case.
  *
- * Note:
- * 1) Devices created after an instance of rte_event_eth_rx_adapter_create
- *  should be added to a new instance of the rx adapter.
+ * For SW based packet transfers, i.e., when the
+ * RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT is not set in the adapter's
+ * capabilities flags for a particular ethernet device, the service function
+ * temporarily enqueues events to an event buffer before batch enqueuing these
+ * to the event device. If the buffer fills up, the service function stops
+ * dequeuing packets from the ethernet device. The application may want to
+ * monitor the buffer fill level and instruct the service function to
+ * selectively buffer events. The application may also use some other
+ * criteria to decide which packets should enter the event device even when
+ * the event buffer fill level is low or may want to enqueue packets to an
+ * internal event port. The rte_event_eth_rx_adapter_cb_register() function
+ * allows the application to register a callback that selects which packets are
+ * enqueued to the event device by the SW adapter. The callback interface is
+ * event based so the callback can also modify the event data if it needs to.
  */
 
 #ifdef __cplusplus
@@ -87,9 +98,6 @@ extern "C" {
  */
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Adapter configuration structure that the adapter configuration callback
  * function is expected to fill out
  * @see rte_event_eth_rx_adapter_conf_cb
@@ -107,9 +115,6 @@ struct rte_event_eth_rx_adapter_conf {
 };
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Function type used for adapter configuration callback. The callback is
  * used to fill in members of the struct rte_event_eth_rx_adapter_conf, this
  * callback is invoked when creating a SW service for packet transfer from
@@ -135,9 +140,6 @@ typedef int (*rte_event_eth_rx_adapter_conf_cb) (uint8_t id, uint8_t dev_id,
                        void *arg);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Rx queue configuration structure
  */
 struct rte_event_eth_rx_adapter_queue_conf {
@@ -172,9 +174,6 @@ struct rte_event_eth_rx_adapter_queue_conf {
 };
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * A structure used to retrieve statistics for an eth rx adapter instance.
  */
 struct rte_event_eth_rx_adapter_stats {
@@ -186,6 +185,8 @@ struct rte_event_eth_rx_adapter_stats {
        /**< Eventdev enqueue count */
        uint64_t rx_enq_retry;
        /**< Eventdev enqueue retry count */
+       uint64_t rx_dropped;
+       /**< Received packet dropped count */
        uint64_t rx_enq_start_ts;
        /**< Rx enqueue start timestamp */
        uint64_t rx_enq_block_cycles;
@@ -203,9 +204,55 @@ struct rte_event_eth_rx_adapter_stats {
 };
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
  *
+ * Callback function invoked by the SW adapter before it continues
+ * to process events. The callback is passed the size of the enqueue
+ * buffer in the SW adapter and the occupancy of the buffer. The
+ * callback can use these values to decide which events are
+ * enqueued to the event device by the SW adapter. The callback may
+ * also enqueue events internally using its own event port. The SW
+ * adapter populates the event information based on the Rx queue
+ * configuration in the adapter. The callback can modify the this event
+ * information for the events to be enqueued by the SW adapter.
+ *
+ * The callback return value is the number of events from the
+ * beginning of the event array that are to be enqueued by
+ * the SW adapter. It is the callback's responsibility to arrange
+ * these events at the beginning of the array, if these events are
+ * not contiguous in the original array. The *nb_dropped* parameter is
+ * a pointer to the number of events dropped by the callback, this
+ * number is used by the adapter to indicate the number of dropped packets
+ * as part of its statistics.
+ *
+ * @param eth_dev_id
+ *  Port identifier of the Ethernet device.
+ * @param queue_id
+ *  Receive queue index.
+ * @param enqueue_buf_size
+ *  Total enqueue buffer size.
+ * @param enqueue_buf_count
+ *  Event count in enqueue buffer.
+ * @param[in, out] ev
+ *  Event array.
+ * @param nb_event
+ *  Event array length.
+ * @param cb_arg
+ *  Callback argument.
+ * @param[out] nb_dropped
+ *  Packets dropped by callback.
+ * @return
+ *  - The number of events to be enqueued by the SW adapter.
+ */
+typedef uint16_t (*rte_event_eth_rx_adapter_cb_fn)(uint16_t eth_dev_id,
+                                               uint16_t queue_id,
+                                               uint32_t enqueue_buf_size,
+                                               uint32_t enqueue_buf_count,
+                                               struct rte_event *ev,
+                                               uint16_t nb_event,
+                                               void *cb_arg,
+                                               uint16_t *nb_dropped);
+
+/**
  * Create a new ethernet Rx event adapter with the specified identifier.
  *
  * @param id
@@ -231,9 +278,6 @@ int rte_event_eth_rx_adapter_create_ext(uint8_t id, uint8_t dev_id,
                                void *conf_arg);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Create a new ethernet Rx event adapter with the specified identifier.
  * This function uses an internal configuration function that creates an event
  * port. This default function reconfigures the event device with an
@@ -260,9 +304,6 @@ int rte_event_eth_rx_adapter_create(uint8_t id, uint8_t dev_id,
                                struct rte_event_port_conf *port_config);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Free an event adapter
  *
  * @param id
@@ -276,9 +317,6 @@ int rte_event_eth_rx_adapter_create(uint8_t id, uint8_t dev_id,
 int rte_event_eth_rx_adapter_free(uint8_t id);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Add receive queue to an event adapter. After a queue has been
  * added to the event adapter, the result of the application calling
  * rte_eth_rx_burst(eth_dev_id, rx_queue_id, ..) is undefined.
@@ -316,9 +354,6 @@ int rte_event_eth_rx_adapter_queue_add(uint8_t id,
                        const struct rte_event_eth_rx_adapter_queue_conf *conf);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Delete receive queue from an event adapter.
  *
  * @param id
@@ -343,9 +378,6 @@ int rte_event_eth_rx_adapter_queue_del(uint8_t id, uint16_t eth_dev_id,
                                       int32_t rx_queue_id);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Start ethernet Rx event adapter
  *
  * @param id
@@ -354,13 +386,14 @@ int rte_event_eth_rx_adapter_queue_del(uint8_t id, uint16_t eth_dev_id,
  * @return
  *  - 0: Success, Adapter started correctly.
  *  - <0: Error code on failure.
+ *
+ * @note
+ *  The eventdev to which the event_eth_rx_adapter is connected needs to
+ *  be started before calling rte_event_eth_rx_adapter_start().
  */
 int rte_event_eth_rx_adapter_start(uint8_t id);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Stop  ethernet Rx event adapter
  *
  * @param id
@@ -373,9 +406,6 @@ int rte_event_eth_rx_adapter_start(uint8_t id);
 int rte_event_eth_rx_adapter_stop(uint8_t id);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Retrieve statistics for an adapter
  *
  * @param id
@@ -389,12 +419,9 @@ int rte_event_eth_rx_adapter_stop(uint8_t id);
  *  - <0: Error code on failure.
  */
 int rte_event_eth_rx_adapter_stats_get(uint8_t id,
-                               struct rte_event_eth_rx_adapter_stats *stats);
+                                 struct rte_event_eth_rx_adapter_stats *stats);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Reset statistics for an adapter.
  *
  * @param id
@@ -407,9 +434,6 @@ int rte_event_eth_rx_adapter_stats_get(uint8_t id,
 int rte_event_eth_rx_adapter_stats_reset(uint8_t id);
 
 /**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
  * Retrieve the service ID of an adapter. If the adapter doesn't use
  * a rte_service function, this function returns -ESRCH.
  *
@@ -426,6 +450,27 @@ int rte_event_eth_rx_adapter_stats_reset(uint8_t id);
  */
 int rte_event_eth_rx_adapter_service_id_get(uint8_t id, uint32_t *service_id);
 
+/**
+ * Register callback to process Rx packets, this is supported for
+ * SW based packet transfers.
+ * @see rte_event_eth_rx_cb_fn
+ *
+ * @param id
+ *  Adapter identifier.
+ * @param eth_dev_id
+ *  Port identifier of Ethernet device.
+ * @param cb_fn
+ *  Callback function.
+ * @param cb_arg
+ *  Callback arg.
+ * @return
+ *  - 0: Success
+ *  - <0: Error code on failure.
+ */
+int rte_event_eth_rx_adapter_cb_register(uint8_t id, uint16_t eth_dev_id,
+                                        rte_event_eth_rx_adapter_cb_fn cb_fn,
+                                        void *cb_arg);
+
 #ifdef __cplusplus
 }
 #endif