summaryrefslogtreecommitdiffstats
path: root/drivers/net/tap/tap_intr.c
blob: b0e1991471c25e1f8b87623c5da584d84a8a6f84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright 2018 Mellanox Technologies, Ltd.
 */

/**
 * @file
 * Interrupts handling for tap driver.
 */

#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>

#include <rte_eth_tap.h>
#include <rte_errno.h>
#include <rte_interrupts.h>


/**
 * Unregister Rx interrupts free the queue interrupt vector.
 *
 * @param dev
 *   Pointer to the tap rte_eth_dev structure.
 */
static void
tap_rx_intr_vec_uninstall(struct rte_eth_dev *dev)
{
	struct pmd_internals *pmd = dev->data->dev_private;
	struct rte_intr_handle *intr_handle = &pmd->intr_handle;

	rte_intr_free_epoll_fd(intr_handle);
	free(intr_handle->intr_vec);
	intr_handle->intr_vec = NULL;
	intr_handle->nb_efd = 0;
}

/**
 * Allocate Rx queue interrupt vector and register Rx interrupts.
 *
 * @param dev
 *   Pointer to the tap rte_eth_dev device structure.
 *
 * @return
 *   0 on success, negative errno value otherwise and rte_errno is set.
 */
static int
tap_rx_intr_vec_install(struct rte_eth_dev *dev)
{
	struct pmd_internals *pmd = dev->data->dev_private;
	unsigned int rxqs_n = pmd->dev->data->nb_rx_queues;
	struct rte_intr_handle *intr_handle = &pmd->intr_handle;
	unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
	unsigned int i;
	unsigned int count = 0;

	if (!dev->data->dev_conf.intr_conf.rxq)
		return 0;
	intr_handle->intr_vec = malloc(sizeof(intr_handle->intr_vec[rxqs_n]));
	if (intr_handle->intr_vec == NULL) {
		rte_errno = ENOMEM;
		RTE_LOG(ERR, PMD,
			"failed to allocate memory for interrupt vector,"
			" Rx interrupts will not be supported");
		return -rte_errno;
	}
	for (i = 0; i < n; i++) {
		struct rx_queue *rxq = pmd->dev->data->rx_queues[i];

		/* Skip queues that cannot request interrupts. */
		if (!rxq || rxq->fd <= 0) {
			/* Use invalid intr_vec[] index to disable entry. */
			intr_handle->intr_vec[i] =
				RTE_INTR_VEC_RXTX_OFFSET +
				RTE_MAX_RXTX_INTR_VEC_ID;
			continue;
		}
		intr_handle->intr_vec[i] = RTE_INTR_VEC_RXTX_OFFSET + count;
		intr_handle->efds[count] = rxq->fd;
		count++;
	}
	if (!count)
		tap_rx_intr_vec_uninstall(dev);
	else
		intr_handle->nb_efd = count;
	return 0;
}

/**
 * Register or unregister the Rx interrupts.
 *
 * @param dev
 *   Pointer to the tap rte_eth_dev device structure.
 * @param set
 *   should the operation be register or unregister the interrupts.
 *
 * @return
 *   0 on success, negative errno value otherwise and rte_errno is set.
 */
int
tap_rx_intr_vec_set(struct rte_eth_dev *dev, int set)
{
	tap_rx_intr_vec_uninstall(dev);
	if (set)
		return tap_rx_intr_vec_install(dev);
	return 0;
}