1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2020 Xilinx, Inc.
4 * Copyright(c) 2016-2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
11 * At the momemt of writing DPDK v16.07 has notion of two types of
12 * interrupts: LSC (link status change) and RXQ (receive indication).
13 * It allows to register interrupt callback for entire device which is
14 * not intended to be used for receive indication (i.e. link status
15 * change indication only). The handler has no information which HW
16 * interrupt has triggered it, so we don't know which event queue should
17 * be polled/reprimed (except qmask in the case of legacy line interrupt).
20 #include <rte_common.h>
21 #include <rte_interrupts.h>
30 sfc_intr_handle_mgmt_evq(struct sfc_adapter *sa)
34 rte_spinlock_lock(&sa->mgmt_evq_lock);
38 if (!sa->mgmt_evq_running) {
39 sfc_log_init(sa, "interrupt on not running management EVQ %u",
44 if (sfc_ev_qprime(evq) != 0)
45 sfc_err(sa, "cannot prime EVQ %u", evq->evq_index);
48 rte_spinlock_unlock(&sa->mgmt_evq_lock);
52 sfc_intr_line_handler(void *cb_arg)
54 struct sfc_adapter *sa = (struct sfc_adapter *)cb_arg;
55 efx_nic_t *enp = sa->nic;
58 unsigned int lsc_seq = sa->port.lsc_seq;
59 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev);
61 sfc_log_init(sa, "entry");
63 if (sa->state != SFC_ADAPTER_STARTED &&
64 sa->state != SFC_ADAPTER_STARTING &&
65 sa->state != SFC_ADAPTER_STOPPING) {
67 "interrupt on stopped adapter, don't reenable");
71 efx_intr_status_line(enp, &fatal, &qmask);
73 (void)efx_intr_disable(enp);
74 (void)efx_intr_fatal(enp);
75 sfc_err(sa, "fatal, interrupts disabled");
79 if (qmask & (1 << sa->mgmt_evq_index))
80 sfc_intr_handle_mgmt_evq(sa);
82 if (rte_intr_ack(&pci_dev->intr_handle) != 0)
83 sfc_err(sa, "cannot reenable interrupts");
85 sfc_log_init(sa, "done");
88 if (lsc_seq != sa->port.lsc_seq) {
89 sfc_notice(sa, "link status change event: link %s",
90 sa->eth_dev->data->dev_link.link_status ?
92 rte_eth_dev_callback_process(sa->eth_dev,
93 RTE_ETH_EVENT_INTR_LSC,
99 sfc_intr_message_handler(void *cb_arg)
101 struct sfc_adapter *sa = (struct sfc_adapter *)cb_arg;
102 efx_nic_t *enp = sa->nic;
104 unsigned int lsc_seq = sa->port.lsc_seq;
105 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev);
107 sfc_log_init(sa, "entry");
109 if (sa->state != SFC_ADAPTER_STARTED &&
110 sa->state != SFC_ADAPTER_STARTING &&
111 sa->state != SFC_ADAPTER_STOPPING) {
112 sfc_log_init(sa, "adapter not-started, don't reenable");
116 efx_intr_status_message(enp, sa->mgmt_evq_index, &fatal);
118 (void)efx_intr_disable(enp);
119 (void)efx_intr_fatal(enp);
120 sfc_err(sa, "fatal, interrupts disabled");
124 sfc_intr_handle_mgmt_evq(sa);
126 if (rte_intr_ack(&pci_dev->intr_handle) != 0)
127 sfc_err(sa, "cannot reenable interrupts");
129 sfc_log_init(sa, "done");
132 if (lsc_seq != sa->port.lsc_seq) {
133 sfc_notice(sa, "link status change event");
134 rte_eth_dev_callback_process(sa->eth_dev,
135 RTE_ETH_EVENT_INTR_LSC,
141 sfc_intr_start(struct sfc_adapter *sa)
143 struct sfc_intr *intr = &sa->intr;
144 struct rte_intr_handle *intr_handle;
145 struct rte_pci_device *pci_dev;
148 sfc_log_init(sa, "entry");
151 * The EFX common code event queue module depends on the interrupt
152 * module. Ensure that the interrupt module is always initialized
153 * (even if interrupts are not used). Status memory is required
154 * for Siena only and may be NULL for EF10.
156 sfc_log_init(sa, "efx_intr_init");
157 rc = efx_intr_init(sa->nic, intr->type, NULL);
161 pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev);
162 intr_handle = &pci_dev->intr_handle;
164 if (intr->handler != NULL) {
165 if (intr->rxq_intr && rte_intr_cap_multiple(intr_handle)) {
166 uint32_t intr_vector;
168 intr_vector = sa->eth_dev->data->nb_rx_queues;
169 rc = rte_intr_efd_enable(intr_handle, intr_vector);
171 goto fail_rte_intr_efd_enable;
173 if (rte_intr_dp_is_en(intr_handle)) {
174 intr_handle->intr_vec =
175 rte_calloc("intr_vec",
176 sa->eth_dev->data->nb_rx_queues, sizeof(int),
178 if (intr_handle->intr_vec == NULL) {
180 "Failed to allocate %d rx_queues intr_vec",
181 sa->eth_dev->data->nb_rx_queues);
182 goto fail_intr_vector_alloc;
186 sfc_log_init(sa, "rte_intr_callback_register");
187 rc = rte_intr_callback_register(intr_handle, intr->handler,
191 "cannot register interrupt handler (rc=%d)",
194 * Convert error code from negative returned by RTE API
195 * to positive used in the driver.
198 goto fail_rte_intr_cb_reg;
201 sfc_log_init(sa, "rte_intr_enable");
202 rc = rte_intr_enable(intr_handle);
204 sfc_err(sa, "cannot enable interrupts (rc=%d)", rc);
206 * Convert error code from negative returned by RTE API
207 * to positive used in the driver.
210 goto fail_rte_intr_enable;
213 sfc_log_init(sa, "efx_intr_enable");
214 efx_intr_enable(sa->nic);
217 sfc_log_init(sa, "done type=%u max_intr=%d nb_efd=%u vec=%p",
218 intr_handle->type, intr_handle->max_intr,
219 intr_handle->nb_efd, intr_handle->intr_vec);
222 fail_rte_intr_enable:
223 rte_intr_callback_unregister(intr_handle, intr->handler, (void *)sa);
225 fail_rte_intr_cb_reg:
226 rte_free(intr_handle->intr_vec);
228 fail_intr_vector_alloc:
229 rte_intr_efd_disable(intr_handle);
231 fail_rte_intr_efd_enable:
232 efx_intr_fini(sa->nic);
235 sfc_log_init(sa, "failed %d", rc);
240 sfc_intr_stop(struct sfc_adapter *sa)
242 struct sfc_intr *intr = &sa->intr;
243 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev);
245 sfc_log_init(sa, "entry");
247 if (intr->handler != NULL) {
248 struct rte_intr_handle *intr_handle;
251 efx_intr_disable(sa->nic);
253 intr_handle = &pci_dev->intr_handle;
255 rte_free(intr_handle->intr_vec);
256 rte_intr_efd_disable(intr_handle);
258 if (rte_intr_disable(intr_handle) != 0)
259 sfc_err(sa, "cannot disable interrupts");
261 while ((rc = rte_intr_callback_unregister(intr_handle,
262 intr->handler, (void *)sa)) == -EAGAIN)
266 "cannot unregister interrupt handler %d",
270 efx_intr_fini(sa->nic);
272 sfc_log_init(sa, "done");
276 sfc_intr_configure(struct sfc_adapter *sa)
278 struct sfc_intr *intr = &sa->intr;
280 sfc_log_init(sa, "entry");
282 intr->handler = NULL;
283 intr->lsc_intr = (sa->eth_dev->data->dev_conf.intr_conf.lsc != 0);
284 intr->rxq_intr = (sa->eth_dev->data->dev_conf.intr_conf.rxq != 0);
286 if (!intr->lsc_intr && !intr->rxq_intr)
289 switch (intr->type) {
290 case EFX_INTR_MESSAGE:
291 intr->handler = sfc_intr_message_handler;
294 intr->handler = sfc_intr_line_handler;
296 case EFX_INTR_INVALID:
297 sfc_warn(sa, "interrupts are not supported");
300 sfc_panic(sa, "unexpected EFX interrupt type %u\n", intr->type);
305 sfc_log_init(sa, "done");
310 sfc_intr_close(struct sfc_adapter *sa)
312 sfc_log_init(sa, "entry");
314 sfc_log_init(sa, "done");
318 sfc_intr_attach(struct sfc_adapter *sa)
320 struct sfc_intr *intr = &sa->intr;
321 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev);
323 sfc_log_init(sa, "entry");
325 switch (pci_dev->intr_handle.type) {
326 #ifdef RTE_EXEC_ENV_LINUX
327 case RTE_INTR_HANDLE_UIO_INTX:
328 case RTE_INTR_HANDLE_VFIO_LEGACY:
329 intr->type = EFX_INTR_LINE;
331 case RTE_INTR_HANDLE_UIO:
332 case RTE_INTR_HANDLE_VFIO_MSI:
333 case RTE_INTR_HANDLE_VFIO_MSIX:
334 intr->type = EFX_INTR_MESSAGE;
338 intr->type = EFX_INTR_INVALID;
342 sfc_log_init(sa, "done");
347 sfc_intr_detach(struct sfc_adapter *sa)
349 sfc_log_init(sa, "entry");
351 sa->intr.type = EFX_INTR_INVALID;
353 sfc_log_init(sa, "done");