]> git.droids-corp.org - dpdk.git/commitdiff
ethdev: insert Rx callback as head of list
authorReshma Pattan <reshma.pattan@intel.com>
Wed, 15 Jun 2016 14:06:19 +0000 (15:06 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Thu, 16 Jun 2016 21:38:00 +0000 (23:38 +0200)
Added new public api rte_eth_add_first_rx_callback to add given
callback as head of the list.

The librte_pdump library should display Rx packets of the
NIC even before they are being processed by other callbacks
of the application (because other callbacks of the application
may change the packet data as part of the processing).
So packet capturing framework should register a callback at the
head of the Rx callback list so that callback always gets called
first before any other callbacks of the applications. Hence this API
is introduced.

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
lib/librte_ether/rte_ethdev.c
lib/librte_ether/rte_ethdev.h
lib/librte_ether/rte_ether_version.map

index a3d0441a44b8eb0bfe66b6bf64f617107a86807c..3a304437f32e3a73599f0330f9b701601a3066aa 100644 (file)
@@ -3012,6 +3012,41 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
        return cb;
 }
 
+void *
+rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
+               rte_rx_callback_fn fn, void *user_param)
+{
+#ifndef RTE_ETHDEV_RXTX_CALLBACKS
+       rte_errno = ENOTSUP;
+       return NULL;
+#endif
+       /* check input parameters */
+       if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
+               queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
+               rte_errno = EINVAL;
+               return NULL;
+       }
+
+       struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
+
+       if (cb == NULL) {
+               rte_errno = ENOMEM;
+               return NULL;
+       }
+
+       cb->fn.rx = fn;
+       cb->param = user_param;
+
+       rte_spinlock_lock(&rte_eth_rx_cb_lock);
+       /* Add the callbacks at fisrt position*/
+       cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
+       rte_smp_wmb();
+       rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
+       rte_spinlock_unlock(&rte_eth_rx_cb_lock);
+
+       return cb;
+}
+
 void *
 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
                rte_tx_callback_fn fn, void *user_param)
index 9748ec032df09bc03369d6d559c71d2fb091c13c..c7983d3c8c20209550502d11aa15edd6eecde9e8 100644 (file)
@@ -3866,6 +3866,34 @@ int rte_eth_dev_get_dcb_info(uint8_t port_id,
 void *rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
                rte_rx_callback_fn fn, void *user_param);
 
+/*
+* Add a callback that must be called first on packet RX on a given port
+* and queue.
+*
+* This API configures a first function to be called for each burst of
+* packets received on a given NIC port queue. The return value is a pointer
+* that can be used to later remove the callback using
+* rte_eth_remove_rx_callback().
+*
+* Multiple functions are called in the order that they are added.
+*
+* @param port_id
+*   The port identifier of the Ethernet device.
+* @param queue_id
+*   The queue on the Ethernet device on which the callback is to be added.
+* @param fn
+*   The callback function
+* @param user_param
+*   A generic pointer parameter which will be passed to each invocation of the
+*   callback function on this port and queue.
+*
+* @return
+*   NULL on error.
+*   On success, a pointer value which can later be used to remove the callback.
+*/
+void *rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
+               rte_rx_callback_fn fn, void *user_param);
+
 /**
  * Add a callback to be called on packet TX on a given port and queue.
  *
index 722b4d6a6a34834ca682d2ceee3bcc921ad009f6..4bb1ce6d977ca415a8895e04450e4d739125d425 100644 (file)
@@ -136,5 +136,6 @@ DPDK_16.04 {
 DPDK_16.07 {
        global:
 
+       rte_eth_add_first_rx_callback;
        rte_eth_xstats_get_names;
 } DPDK_16.04;