| 5719 | |
| 5720 | |
| 5721 | const struct rte_eth_rxtx_callback * |
| 5722 | rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id, |
| 5723 | rte_rx_callback_fn fn, void *user_param) |
| 5724 | { |
| 5725 | #ifndef RTE_ETHDEV_RXTX_CALLBACKS |
| 5726 | rte_errno = ENOTSUP; |
| 5727 | return NULL; |
| 5728 | #endif |
| 5729 | struct rte_eth_dev *dev; |
| 5730 | |
| 5731 | /* check input parameters */ |
| 5732 | if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL || |
| 5733 | queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) { |
| 5734 | rte_errno = EINVAL; |
| 5735 | return NULL; |
| 5736 | } |
| 5737 | dev = &rte_eth_devices[port_id]; |
| 5738 | if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) { |
| 5739 | rte_errno = EINVAL; |
| 5740 | return NULL; |
| 5741 | } |
| 5742 | struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); |
| 5743 | |
| 5744 | if (cb == NULL) { |
| 5745 | rte_errno = ENOMEM; |
| 5746 | return NULL; |
| 5747 | } |
| 5748 | |
| 5749 | cb->fn.rx = fn; |
| 5750 | cb->param = user_param; |
| 5751 | |
| 5752 | rte_spinlock_lock(ð_dev_rx_cb_lock); |
| 5753 | /* Add the callbacks in fifo order. */ |
| 5754 | struct rte_eth_rxtx_callback *tail = |
| 5755 | rte_eth_devices[port_id].post_rx_burst_cbs[queue_id]; |
| 5756 | |
| 5757 | if (!tail) { |
| 5758 | /* Stores to cb->fn and cb->param should complete before |
| 5759 | * cb is visible to data plane. |
| 5760 | */ |
| 5761 | rte_atomic_store_explicit( |
| 5762 | &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id], |
| 5763 | cb, rte_memory_order_release); |
| 5764 | |
| 5765 | } else { |
| 5766 | while (tail->next) |
| 5767 | tail = tail->next; |
| 5768 | /* Stores to cb->fn and cb->param should complete before |
| 5769 | * cb is visible to data plane. |
| 5770 | */ |
| 5771 | rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release); |
| 5772 | } |
| 5773 | rte_spinlock_unlock(ð_dev_rx_cb_lock); |
| 5774 | |
| 5775 | rte_eth_trace_add_rx_callback(port_id, queue_id, fn, user_param, cb); |
| 5776 | |
| 5777 | return cb; |
| 5778 | } |
no test coverage detected