ethdev: allow event registration for all ports

Add option to register event callback for all ports by one call to
rte_eth_dev_callback_register using port_id=RTE_ETH_ALL.

In this case the callback is also registered to invalid ports.

Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
This commit is contained in:
Matan Azrad 2018-01-04 17:01:09 +01:00 committed by Ferruh Yigit
parent cebe3d7b3d
commit 9ec0b3869d
2 changed files with 89 additions and 42 deletions

View File

@ -176,7 +176,6 @@ eth_dev_get(uint16_t port_id)
eth_dev->data = &rte_eth_dev_data[port_id];
eth_dev->state = RTE_ETH_DEV_ATTACHED;
TAILQ_INIT(&(eth_dev->link_intr_cbs));
eth_dev_last_created_port = port_id;
@ -2850,6 +2849,14 @@ rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
}
RTE_INIT(eth_dev_init_cb_lists)
{
int i;
for (i = 0; i < RTE_MAX_ETHPORTS; i++)
TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
}
int
rte_eth_dev_callback_register(uint16_t port_id,
enum rte_eth_event_type event,
@ -2857,15 +2864,29 @@ rte_eth_dev_callback_register(uint16_t port_id,
{
struct rte_eth_dev *dev;
struct rte_eth_dev_callback *user_cb;
uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
uint16_t last_port;
if (!cb_fn)
return -EINVAL;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
RTE_LOG(ERR, EAL, "Invalid port_id=%d\n", port_id);
return -EINVAL;
}
if (port_id == RTE_ETH_ALL) {
next_port = 0;
last_port = RTE_MAX_ETHPORTS - 1;
} else {
next_port = last_port = port_id;
}
dev = &rte_eth_devices[port_id];
rte_spinlock_lock(&rte_eth_dev_cb_lock);
do {
dev = &rte_eth_devices[next_port];
TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
if (user_cb->cb_fn == cb_fn &&
user_cb->cb_arg == cb_arg &&
@ -2882,12 +2903,20 @@ rte_eth_dev_callback_register(uint16_t port_id,
user_cb->cb_fn = cb_fn;
user_cb->cb_arg = cb_arg;
user_cb->event = event;
TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
}
TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
user_cb, next);
} else {
rte_spinlock_unlock(&rte_eth_dev_cb_lock);
rte_eth_dev_callback_unregister(port_id, event,
cb_fn, cb_arg);
return -ENOMEM;
}
}
} while (++next_port <= last_port);
rte_spinlock_unlock(&rte_eth_dev_cb_lock);
return (user_cb == NULL) ? -ENOMEM : 0;
return 0;
}
int
@ -2898,23 +2927,36 @@ rte_eth_dev_callback_unregister(uint16_t port_id,
int ret;
struct rte_eth_dev *dev;
struct rte_eth_dev_callback *cb, *next;
uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
uint16_t last_port;
if (!cb_fn)
return -EINVAL;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
RTE_LOG(ERR, EAL, "Invalid port_id=%d\n", port_id);
return -EINVAL;
}
if (port_id == RTE_ETH_ALL) {
next_port = 0;
last_port = RTE_MAX_ETHPORTS - 1;
} else {
next_port = last_port = port_id;
}
dev = &rte_eth_devices[port_id];
rte_spinlock_lock(&rte_eth_dev_cb_lock);
do {
dev = &rte_eth_devices[next_port];
ret = 0;
for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
cb = next) {
next = TAILQ_NEXT(cb, next);
if (cb->cb_fn != cb_fn || cb->event != event ||
(cb->cb_arg != (void *)-1 &&
cb->cb_arg != cb_arg))
(cb->cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
continue;
/*
@ -2928,6 +2970,7 @@ rte_eth_dev_callback_unregister(uint16_t port_id,
ret = -EAGAIN;
}
}
} while (++next_port <= last_port);
rte_spinlock_unlock(&rte_eth_dev_cb_lock);
return ret;

View File

@ -1108,6 +1108,8 @@ struct rte_eth_dcb_info {
struct rte_eth_dev;
#define RTE_ETH_ALL RTE_MAX_ETHPORTS
struct rte_eth_dev_callback;
/** @internal Structure to keep track of registered callbacks */
TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback);
@ -3507,10 +3509,11 @@ typedef int (*rte_eth_dev_cb_fn)(uint16_t port_id,
/**
* Register a callback function for specific port id.
* Register a callback function for port event.
*
* @param port_id
* Port id.
* RTE_ETH_ALL means register the event for all port ids.
* @param event
* Event interested.
* @param cb_fn
@ -3527,10 +3530,11 @@ int rte_eth_dev_callback_register(uint16_t port_id,
rte_eth_dev_cb_fn cb_fn, void *cb_arg);
/**
* Unregister a callback function for specific port id.
* Unregister a callback function for port event.
*
* @param port_id
* Port id.
* RTE_ETH_ALL means unregister the event for all port ids.
* @param event
* Event interested.
* @param cb_fn