| 5820 | } |
| 5821 | |
| 5822 | const struct rte_eth_rxtx_callback * |
| 5823 | rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id, |
| 5824 | rte_tx_callback_fn fn, void *user_param) |
| 5825 | { |
| 5826 | #ifndef RTE_ETHDEV_RXTX_CALLBACKS |
| 5827 | rte_errno = ENOTSUP; |
| 5828 | return NULL; |
| 5829 | #endif |
| 5830 | struct rte_eth_dev *dev; |
| 5831 | |
| 5832 | /* check input parameters */ |
| 5833 | if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL || |
| 5834 | queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) { |
| 5835 | rte_errno = EINVAL; |
| 5836 | return NULL; |
| 5837 | } |
| 5838 | |
| 5839 | dev = &rte_eth_devices[port_id]; |
| 5840 | if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) { |
| 5841 | rte_errno = EINVAL; |
| 5842 | return NULL; |
| 5843 | } |
| 5844 | |
| 5845 | struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); |
| 5846 | |
| 5847 | if (cb == NULL) { |
| 5848 | rte_errno = ENOMEM; |
| 5849 | return NULL; |
| 5850 | } |
| 5851 | |
| 5852 | cb->fn.tx = fn; |
| 5853 | cb->param = user_param; |
| 5854 | |
| 5855 | rte_spinlock_lock(ð_dev_tx_cb_lock); |
| 5856 | /* Add the callbacks in fifo order. */ |
| 5857 | struct rte_eth_rxtx_callback *tail = |
| 5858 | rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id]; |
| 5859 | |
| 5860 | if (!tail) { |
| 5861 | /* Stores to cb->fn and cb->param should complete before |
| 5862 | * cb is visible to data plane. |
| 5863 | */ |
| 5864 | rte_atomic_store_explicit( |
| 5865 | &rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id], |
| 5866 | cb, rte_memory_order_release); |
| 5867 | |
| 5868 | } else { |
| 5869 | while (tail->next) |
| 5870 | tail = tail->next; |
| 5871 | /* Stores to cb->fn and cb->param should complete before |
| 5872 | * cb is visible to data plane. |
| 5873 | */ |
| 5874 | rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release); |
| 5875 | } |
| 5876 | rte_spinlock_unlock(ð_dev_tx_cb_lock); |
| 5877 | |
| 5878 | rte_eth_trace_add_tx_callback(port_id, queue_id, fn, user_param, cb); |
| 5879 |
no test coverage detected