lib: remove direct access to interrupt handle

Removing direct access to interrupt handle structure fields,
rather use respective get set APIs for the same.
Making changes to all the libraries access the interrupt handle fields.

Signed-off-by: Harman Kalra <hkalra@marvell.com>
Signed-off-by: David Marchand <david.marchand@redhat.com>
Tested-by: Raslan Darawsheh <rasland@nvidia.com>
This commit is contained in:
Harman Kalra 2021-10-23 02:19:32 +05:30 committed by David Marchand
parent 90b13ab8d4
commit c2bd9367e1
3 changed files with 43 additions and 32 deletions

View File

@ -1094,7 +1094,7 @@ rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op,
VALID_QUEUE_OR_RET_ERR(queue_id, dev);
intr_handle = dev->intr_handle;
if (!intr_handle || !intr_handle->intr_vec) {
if (intr_handle == NULL) {
rte_bbdev_log(ERR, "Device %u intr handle unset\n", dev_id);
return -ENOTSUP;
}
@ -1105,7 +1105,7 @@ rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op,
return -ENOTSUP;
}
vec = intr_handle->intr_vec[queue_id];
vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
ret = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
if (ret && (ret != -EEXIST)) {
rte_bbdev_log(ERR,

View File

@ -23,10 +23,7 @@
#include "eal_private.h"
static struct rte_intr_handle intr_handle = {
.type = RTE_INTR_HANDLE_DEV_EVENT,
.fd = -1,
};
static struct rte_intr_handle *intr_handle;
static rte_rwlock_t monitor_lock = RTE_RWLOCK_INITIALIZER;
static uint32_t monitor_refcount;
static bool hotplug_handle;
@ -109,12 +106,11 @@ static int
dev_uev_socket_fd_create(void)
{
struct sockaddr_nl addr;
int ret;
int ret, fd;
intr_handle.fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC |
SOCK_NONBLOCK,
NETLINK_KOBJECT_UEVENT);
if (intr_handle.fd < 0) {
fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK,
NETLINK_KOBJECT_UEVENT);
if (fd < 0) {
RTE_LOG(ERR, EAL, "create uevent fd failed.\n");
return -1;
}
@ -124,16 +120,19 @@ dev_uev_socket_fd_create(void)
addr.nl_pid = 0;
addr.nl_groups = 0xffffffff;
ret = bind(intr_handle.fd, (struct sockaddr *) &addr, sizeof(addr));
ret = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
if (ret < 0) {
RTE_LOG(ERR, EAL, "Failed to bind uevent socket.\n");
goto err;
}
if (rte_intr_fd_set(intr_handle, fd))
goto err;
return 0;
err:
close(intr_handle.fd);
intr_handle.fd = -1;
close(fd);
fd = -1;
return ret;
}
@ -217,9 +216,9 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length)
static void
dev_delayed_unregister(void *param)
{
rte_intr_callback_unregister(&intr_handle, dev_uev_handler, param);
close(intr_handle.fd);
intr_handle.fd = -1;
rte_intr_callback_unregister(intr_handle, dev_uev_handler, param);
close(rte_intr_fd_get(intr_handle));
rte_intr_fd_set(intr_handle, -1);
}
static void
@ -235,7 +234,8 @@ dev_uev_handler(__rte_unused void *param)
memset(&uevent, 0, sizeof(struct rte_dev_event));
memset(buf, 0, EAL_UEV_MSG_LEN);
ret = recv(intr_handle.fd, buf, EAL_UEV_MSG_LEN, MSG_DONTWAIT);
ret = recv(rte_intr_fd_get(intr_handle), buf, EAL_UEV_MSG_LEN,
MSG_DONTWAIT);
if (ret < 0 && errno == EAGAIN)
return;
else if (ret <= 0) {
@ -311,24 +311,35 @@ rte_dev_event_monitor_start(void)
goto exit;
}
intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
if (intr_handle == NULL) {
RTE_LOG(ERR, EAL, "Fail to allocate intr_handle\n");
goto exit;
}
if (rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_DEV_EVENT))
goto exit;
if (rte_intr_fd_set(intr_handle, -1))
goto exit;
ret = dev_uev_socket_fd_create();
if (ret) {
RTE_LOG(ERR, EAL, "error create device event fd.\n");
goto exit;
}
ret = rte_intr_callback_register(&intr_handle, dev_uev_handler, NULL);
ret = rte_intr_callback_register(intr_handle, dev_uev_handler, NULL);
if (ret) {
RTE_LOG(ERR, EAL, "fail to register uevent callback.\n");
close(intr_handle.fd);
intr_handle.fd = -1;
close(rte_intr_fd_get(intr_handle));
goto exit;
}
monitor_refcount++;
exit:
rte_intr_instance_free(intr_handle);
rte_rwlock_write_unlock(&monitor_lock);
return ret;
}
@ -350,15 +361,15 @@ rte_dev_event_monitor_stop(void)
goto exit;
}
ret = rte_intr_callback_unregister(&intr_handle, dev_uev_handler,
ret = rte_intr_callback_unregister(intr_handle, dev_uev_handler,
(void *)-1);
if (ret < 0) {
RTE_LOG(ERR, EAL, "fail to unregister uevent callback.\n");
goto exit;
}
close(intr_handle.fd);
intr_handle.fd = -1;
close(rte_intr_fd_get(intr_handle));
rte_intr_instance_free(intr_handle);
monitor_refcount--;

View File

@ -4819,13 +4819,13 @@ rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
}
intr_handle = dev->intr_handle;
if (!intr_handle->intr_vec) {
if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n");
return -EPERM;
}
for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
vec = intr_handle->intr_vec[qid];
vec = rte_intr_vec_list_index_get(intr_handle, qid);
rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
if (rc && rc != -EEXIST) {
RTE_ETHDEV_LOG(ERR,
@ -4860,15 +4860,15 @@ rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
}
intr_handle = dev->intr_handle;
if (!intr_handle->intr_vec) {
if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n");
return -1;
}
vec = intr_handle->intr_vec[queue_id];
vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
(vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
fd = intr_handle->efds[efd_idx];
fd = rte_intr_efds_index_get(intr_handle, efd_idx);
return fd;
}
@ -5046,12 +5046,12 @@ rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
}
intr_handle = dev->intr_handle;
if (!intr_handle->intr_vec) {
if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n");
return -EPERM;
}
vec = intr_handle->intr_vec[queue_id];
vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
if (rc && rc != -EEXIST) {
RTE_ETHDEV_LOG(ERR,