1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd.
7 * Interrupts handling for failsafe driver.
12 #include "failsafe_private.h"
15 * Uninstall failsafe interrupt vector.
18 * Pointer to failsafe private structure.
21 fs_rx_intr_vec_uninstall(struct fs_priv *priv)
23 struct rte_intr_handle *intr_handle;
25 intr_handle = &priv->intr_handle;
26 if (intr_handle->intr_vec != NULL) {
27 free(intr_handle->intr_vec);
28 intr_handle->intr_vec = NULL;
30 intr_handle->nb_efd = 0;
34 * Installs failsafe interrupt vector to be registered with EAL later on.
37 * Pointer to failsafe private structure.
40 * 0 on success, negative errno value otherwise and rte_errno is set.
43 fs_rx_intr_vec_install(struct fs_priv *priv)
49 struct rte_intr_handle *intr_handle;
51 rxqs_n = priv->dev->data->nb_rx_queues;
52 n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
54 intr_handle = &priv->intr_handle;
55 RTE_ASSERT(intr_handle->intr_vec == NULL);
56 /* Allocate the interrupt vector of the failsafe Rx proxy interrupts */
57 intr_handle->intr_vec = malloc(n * sizeof(intr_handle->intr_vec[0]));
58 if (intr_handle->intr_vec == NULL) {
59 fs_rx_intr_vec_uninstall(priv);
61 ERROR("Failed to allocate memory for interrupt vector,"
62 " Rx interrupts will not be supported");
65 for (i = 0; i < n; i++) {
66 struct rxq *rxq = priv->dev->data->rx_queues[i];
68 /* Skip queues that cannot request interrupts. */
69 if (rxq == NULL || rxq->event_fd < 0) {
70 /* Use invalid intr_vec[] index to disable entry. */
71 intr_handle->intr_vec[i] =
72 RTE_INTR_VEC_RXTX_OFFSET +
73 RTE_MAX_RXTX_INTR_VEC_ID;
76 if (count >= RTE_MAX_RXTX_INTR_VEC_ID) {
78 ERROR("Too many Rx queues for interrupt vector size"
79 " (%d), Rx interrupts cannot be enabled",
80 RTE_MAX_RXTX_INTR_VEC_ID);
81 fs_rx_intr_vec_uninstall(priv);
84 intr_handle->intr_vec[i] = RTE_INTR_VEC_RXTX_OFFSET + count;
85 intr_handle->efds[count] = rxq->event_fd;
89 fs_rx_intr_vec_uninstall(priv);
91 intr_handle->nb_efd = count;
92 intr_handle->efd_counter_size = sizeof(uint64_t);
99 * Uninstall failsafe Rx interrupts subsystem.
102 * Pointer to private structure.
105 * 0 on success, negative errno value otherwise and rte_errno is set.
108 failsafe_rx_intr_uninstall(struct rte_eth_dev *dev)
110 fs_rx_intr_vec_uninstall(PRIV(dev));
111 dev->intr_handle = NULL;
115 * Install failsafe Rx interrupts subsystem.
118 * Pointer to private structure.
121 * 0 on success, negative errno value otherwise and rte_errno is set.
124 failsafe_rx_intr_install(struct rte_eth_dev *dev)
126 struct fs_priv *priv = PRIV(dev);
127 const struct rte_intr_conf *const intr_conf =
128 &priv->dev->data->dev_conf.intr_conf;
130 if (intr_conf->rxq == 0)
132 if (fs_rx_intr_vec_install(priv) < 0)
134 dev->intr_handle = &priv->intr_handle;