1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016-2018 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
10 #include <rte_debug.h>
11 #include <rte_cycles.h>
12 #include <rte_alarm.h>
13 #include <rte_branch_prediction.h>
18 #include "sfc_debug.h"
23 #include "sfc_kvargs.h"
26 /* Initial delay when waiting for event queue init complete event */
27 #define SFC_EVQ_INIT_BACKOFF_START_US (1)
28 /* Maximum delay between event queue polling attempts */
29 #define SFC_EVQ_INIT_BACKOFF_MAX_US (10 * 1000)
30 /* Event queue init approx timeout */
31 #define SFC_EVQ_INIT_TIMEOUT_US (2 * US_PER_S)
33 /* Management event queue polling period in microseconds */
34 #define SFC_MGMT_EV_QPOLL_PERIOD_US (US_PER_S)
37 sfc_evq_type2str(enum sfc_evq_type type)
40 case SFC_EVQ_TYPE_MGMT:
53 sfc_ev_initialized(void *arg)
55 struct sfc_evq *evq = arg;
57 /* Init done events may be duplicated on SFN7xxx (SFC bug 31631) */
58 SFC_ASSERT(evq->init_state == SFC_EVQ_STARTING ||
59 evq->init_state == SFC_EVQ_STARTED);
61 evq->init_state = SFC_EVQ_STARTED;
67 sfc_ev_nop_rx(void *arg, uint32_t label, uint32_t id,
68 uint32_t size, uint16_t flags)
70 struct sfc_evq *evq = arg;
73 "EVQ %u unexpected Rx event label=%u id=%#x size=%u flags=%#x",
74 evq->evq_index, label, id, size, flags);
79 sfc_ev_efx_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
80 uint32_t size, uint16_t flags)
82 struct sfc_evq *evq = arg;
83 struct sfc_efx_rxq *rxq;
85 unsigned int pending_id;
88 struct sfc_efx_rx_sw_desc *rxd;
90 if (unlikely(evq->exception))
93 rxq = sfc_efx_rxq_by_dp_rxq(evq->dp_rxq);
95 SFC_ASSERT(rxq != NULL);
96 SFC_ASSERT(rxq->evq == evq);
97 SFC_ASSERT(rxq->flags & SFC_EFX_RXQ_FLAG_STARTED);
99 stop = (id + 1) & rxq->ptr_mask;
100 pending_id = rxq->pending & rxq->ptr_mask;
101 delta = (stop >= pending_id) ? (stop - pending_id) :
102 (rxq->ptr_mask + 1 - pending_id + stop);
106 * Rx event with no new descriptors done and zero length
107 * is used to abort scattered packet when there is no room
110 if (unlikely(size != 0)) {
111 evq->exception = B_TRUE;
113 "EVQ %u RxQ %u invalid RX abort "
114 "(id=%#x size=%u flags=%#x); needs restart",
115 evq->evq_index, rxq->dp.dpq.queue_id,
120 /* Add discard flag to the first fragment */
121 rxq->sw_desc[pending_id].flags |= EFX_DISCARD;
122 /* Remove continue flag from the last fragment */
123 rxq->sw_desc[id].flags &= ~EFX_PKT_CONT;
124 } else if (unlikely(delta > rxq->batch_max)) {
125 evq->exception = B_TRUE;
128 "EVQ %u RxQ %u completion out of order "
129 "(id=%#x delta=%u flags=%#x); needs restart",
130 evq->evq_index, rxq->dp.dpq.queue_id,
136 for (i = pending_id; i != stop; i = (i + 1) & rxq->ptr_mask) {
137 rxd = &rxq->sw_desc[i];
141 SFC_ASSERT(size < (1 << 16));
142 rxd->size = (uint16_t)size;
145 rxq->pending += delta;
152 sfc_ev_dp_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
153 __rte_unused uint32_t size, __rte_unused uint16_t flags)
155 struct sfc_evq *evq = arg;
156 struct sfc_dp_rxq *dp_rxq;
158 dp_rxq = evq->dp_rxq;
159 SFC_ASSERT(dp_rxq != NULL);
161 SFC_ASSERT(evq->sa->priv.dp_rx->qrx_ev != NULL);
162 return evq->sa->priv.dp_rx->qrx_ev(dp_rxq, id);
166 sfc_ev_nop_rx_ps(void *arg, uint32_t label, uint32_t id,
167 uint32_t pkt_count, uint16_t flags)
169 struct sfc_evq *evq = arg;
172 "EVQ %u unexpected packed stream Rx event label=%u id=%#x pkt_count=%u flags=%#x",
173 evq->evq_index, label, id, pkt_count, flags);
177 /* It is not actually used on datapath, but required on RxQ flush */
179 sfc_ev_dp_rx_ps(void *arg, __rte_unused uint32_t label, uint32_t id,
180 __rte_unused uint32_t pkt_count, __rte_unused uint16_t flags)
182 struct sfc_evq *evq = arg;
183 struct sfc_dp_rxq *dp_rxq;
185 dp_rxq = evq->dp_rxq;
186 SFC_ASSERT(dp_rxq != NULL);
188 if (evq->sa->priv.dp_rx->qrx_ps_ev != NULL)
189 return evq->sa->priv.dp_rx->qrx_ps_ev(dp_rxq, id);
195 sfc_ev_nop_tx(void *arg, uint32_t label, uint32_t id)
197 struct sfc_evq *evq = arg;
199 sfc_err(evq->sa, "EVQ %u unexpected Tx event label=%u id=%#x",
200 evq->evq_index, label, id);
205 sfc_ev_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
207 struct sfc_evq *evq = arg;
208 struct sfc_dp_txq *dp_txq;
209 struct sfc_efx_txq *txq;
213 dp_txq = evq->dp_txq;
214 SFC_ASSERT(dp_txq != NULL);
216 txq = sfc_efx_txq_by_dp_txq(dp_txq);
217 SFC_ASSERT(txq->evq == evq);
219 if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_STARTED) == 0))
222 stop = (id + 1) & txq->ptr_mask;
223 id = txq->pending & txq->ptr_mask;
225 delta = (stop >= id) ? (stop - id) : (txq->ptr_mask + 1 - id + stop);
227 txq->pending += delta;
234 sfc_ev_dp_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
236 struct sfc_evq *evq = arg;
237 struct sfc_dp_txq *dp_txq;
239 dp_txq = evq->dp_txq;
240 SFC_ASSERT(dp_txq != NULL);
242 SFC_ASSERT(evq->sa->priv.dp_tx->qtx_ev != NULL);
243 return evq->sa->priv.dp_tx->qtx_ev(dp_txq, id);
247 sfc_ev_exception(void *arg, uint32_t code, __rte_unused uint32_t data)
249 struct sfc_evq *evq = arg;
251 if (code == EFX_EXCEPTION_UNKNOWN_SENSOREVT)
254 evq->exception = B_TRUE;
256 "hardware exception %s (code=%u, data=%#x) on EVQ %u;"
258 (code == EFX_EXCEPTION_RX_RECOVERY) ? "RX_RECOVERY" :
259 (code == EFX_EXCEPTION_RX_DSC_ERROR) ? "RX_DSC_ERROR" :
260 (code == EFX_EXCEPTION_TX_DSC_ERROR) ? "TX_DSC_ERROR" :
261 (code == EFX_EXCEPTION_FWALERT_SRAM) ? "FWALERT_SRAM" :
262 (code == EFX_EXCEPTION_UNKNOWN_FWALERT) ? "UNKNOWN_FWALERT" :
263 (code == EFX_EXCEPTION_RX_ERROR) ? "RX_ERROR" :
264 (code == EFX_EXCEPTION_TX_ERROR) ? "TX_ERROR" :
265 (code == EFX_EXCEPTION_EV_ERROR) ? "EV_ERROR" :
267 code, data, evq->evq_index);
273 sfc_ev_nop_rxq_flush_done(void *arg, uint32_t rxq_hw_index)
275 struct sfc_evq *evq = arg;
277 sfc_err(evq->sa, "EVQ %u unexpected RxQ %u flush done",
278 evq->evq_index, rxq_hw_index);
283 sfc_ev_rxq_flush_done(void *arg, __rte_unused uint32_t rxq_hw_index)
285 struct sfc_evq *evq = arg;
286 struct sfc_dp_rxq *dp_rxq;
289 dp_rxq = evq->dp_rxq;
290 SFC_ASSERT(dp_rxq != NULL);
292 rxq = sfc_rxq_by_dp_rxq(dp_rxq);
293 SFC_ASSERT(rxq != NULL);
294 SFC_ASSERT(rxq->hw_index == rxq_hw_index);
295 SFC_ASSERT(rxq->evq == evq);
298 sfc_rx_qflush_done(sfc_rxq_info_by_dp_rxq(dp_rxq));
304 sfc_ev_nop_rxq_flush_failed(void *arg, uint32_t rxq_hw_index)
306 struct sfc_evq *evq = arg;
308 sfc_err(evq->sa, "EVQ %u unexpected RxQ %u flush failed",
309 evq->evq_index, rxq_hw_index);
314 sfc_ev_rxq_flush_failed(void *arg, __rte_unused uint32_t rxq_hw_index)
316 struct sfc_evq *evq = arg;
317 struct sfc_dp_rxq *dp_rxq;
320 dp_rxq = evq->dp_rxq;
321 SFC_ASSERT(dp_rxq != NULL);
323 rxq = sfc_rxq_by_dp_rxq(dp_rxq);
324 SFC_ASSERT(rxq != NULL);
325 SFC_ASSERT(rxq->hw_index == rxq_hw_index);
326 SFC_ASSERT(rxq->evq == evq);
329 sfc_rx_qflush_failed(sfc_rxq_info_by_dp_rxq(dp_rxq));
335 sfc_ev_nop_txq_flush_done(void *arg, uint32_t txq_hw_index)
337 struct sfc_evq *evq = arg;
339 sfc_err(evq->sa, "EVQ %u unexpected TxQ %u flush done",
340 evq->evq_index, txq_hw_index);
345 sfc_ev_txq_flush_done(void *arg, __rte_unused uint32_t txq_hw_index)
347 struct sfc_evq *evq = arg;
348 struct sfc_dp_txq *dp_txq;
351 dp_txq = evq->dp_txq;
352 SFC_ASSERT(dp_txq != NULL);
354 txq = sfc_txq_by_dp_txq(dp_txq);
355 SFC_ASSERT(txq != NULL);
356 SFC_ASSERT(txq->hw_index == txq_hw_index);
357 SFC_ASSERT(txq->evq == evq);
358 sfc_tx_qflush_done(txq);
364 sfc_ev_software(void *arg, uint16_t magic)
366 struct sfc_evq *evq = arg;
368 sfc_err(evq->sa, "EVQ %u unexpected software event magic=%#.4x",
369 evq->evq_index, magic);
374 sfc_ev_sram(void *arg, uint32_t code)
376 struct sfc_evq *evq = arg;
378 sfc_err(evq->sa, "EVQ %u unexpected SRAM event code=%u",
379 evq->evq_index, code);
384 sfc_ev_wake_up(void *arg, uint32_t index)
386 struct sfc_evq *evq = arg;
388 sfc_err(evq->sa, "EVQ %u unexpected wake up event index=%u",
389 evq->evq_index, index);
394 sfc_ev_timer(void *arg, uint32_t index)
396 struct sfc_evq *evq = arg;
398 sfc_err(evq->sa, "EVQ %u unexpected timer event index=%u",
399 evq->evq_index, index);
404 sfc_ev_nop_link_change(void *arg, __rte_unused efx_link_mode_t link_mode)
406 struct sfc_evq *evq = arg;
408 sfc_err(evq->sa, "EVQ %u unexpected link change event",
414 sfc_ev_link_change(void *arg, efx_link_mode_t link_mode)
416 struct sfc_evq *evq = arg;
417 struct sfc_adapter *sa = evq->sa;
418 struct rte_eth_link new_link;
420 sfc_port_link_mode_to_info(link_mode, &new_link);
421 if (rte_eth_linkstatus_set(sa->eth_dev, &new_link))
422 evq->sa->port.lsc_seq++;
427 static const efx_ev_callbacks_t sfc_ev_callbacks = {
428 .eec_initialized = sfc_ev_initialized,
429 .eec_rx = sfc_ev_nop_rx,
430 .eec_rx_ps = sfc_ev_nop_rx_ps,
431 .eec_tx = sfc_ev_nop_tx,
432 .eec_exception = sfc_ev_exception,
433 .eec_rxq_flush_done = sfc_ev_nop_rxq_flush_done,
434 .eec_rxq_flush_failed = sfc_ev_nop_rxq_flush_failed,
435 .eec_txq_flush_done = sfc_ev_nop_txq_flush_done,
436 .eec_software = sfc_ev_software,
437 .eec_sram = sfc_ev_sram,
438 .eec_wake_up = sfc_ev_wake_up,
439 .eec_timer = sfc_ev_timer,
440 .eec_link_change = sfc_ev_link_change,
443 static const efx_ev_callbacks_t sfc_ev_callbacks_efx_rx = {
444 .eec_initialized = sfc_ev_initialized,
445 .eec_rx = sfc_ev_efx_rx,
446 .eec_rx_ps = sfc_ev_nop_rx_ps,
447 .eec_tx = sfc_ev_nop_tx,
448 .eec_exception = sfc_ev_exception,
449 .eec_rxq_flush_done = sfc_ev_rxq_flush_done,
450 .eec_rxq_flush_failed = sfc_ev_rxq_flush_failed,
451 .eec_txq_flush_done = sfc_ev_nop_txq_flush_done,
452 .eec_software = sfc_ev_software,
453 .eec_sram = sfc_ev_sram,
454 .eec_wake_up = sfc_ev_wake_up,
455 .eec_timer = sfc_ev_timer,
456 .eec_link_change = sfc_ev_nop_link_change,
459 static const efx_ev_callbacks_t sfc_ev_callbacks_dp_rx = {
460 .eec_initialized = sfc_ev_initialized,
461 .eec_rx = sfc_ev_dp_rx,
462 .eec_rx_ps = sfc_ev_dp_rx_ps,
463 .eec_tx = sfc_ev_nop_tx,
464 .eec_exception = sfc_ev_exception,
465 .eec_rxq_flush_done = sfc_ev_rxq_flush_done,
466 .eec_rxq_flush_failed = sfc_ev_rxq_flush_failed,
467 .eec_txq_flush_done = sfc_ev_nop_txq_flush_done,
468 .eec_software = sfc_ev_software,
469 .eec_sram = sfc_ev_sram,
470 .eec_wake_up = sfc_ev_wake_up,
471 .eec_timer = sfc_ev_timer,
472 .eec_link_change = sfc_ev_nop_link_change,
475 static const efx_ev_callbacks_t sfc_ev_callbacks_efx_tx = {
476 .eec_initialized = sfc_ev_initialized,
477 .eec_rx = sfc_ev_nop_rx,
478 .eec_rx_ps = sfc_ev_nop_rx_ps,
480 .eec_exception = sfc_ev_exception,
481 .eec_rxq_flush_done = sfc_ev_nop_rxq_flush_done,
482 .eec_rxq_flush_failed = sfc_ev_nop_rxq_flush_failed,
483 .eec_txq_flush_done = sfc_ev_txq_flush_done,
484 .eec_software = sfc_ev_software,
485 .eec_sram = sfc_ev_sram,
486 .eec_wake_up = sfc_ev_wake_up,
487 .eec_timer = sfc_ev_timer,
488 .eec_link_change = sfc_ev_nop_link_change,
491 static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {
492 .eec_initialized = sfc_ev_initialized,
493 .eec_rx = sfc_ev_nop_rx,
494 .eec_rx_ps = sfc_ev_nop_rx_ps,
495 .eec_tx = sfc_ev_dp_tx,
496 .eec_exception = sfc_ev_exception,
497 .eec_rxq_flush_done = sfc_ev_nop_rxq_flush_done,
498 .eec_rxq_flush_failed = sfc_ev_nop_rxq_flush_failed,
499 .eec_txq_flush_done = sfc_ev_txq_flush_done,
500 .eec_software = sfc_ev_software,
501 .eec_sram = sfc_ev_sram,
502 .eec_wake_up = sfc_ev_wake_up,
503 .eec_timer = sfc_ev_timer,
504 .eec_link_change = sfc_ev_nop_link_change,
509 sfc_ev_qpoll(struct sfc_evq *evq)
511 SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED ||
512 evq->init_state == SFC_EVQ_STARTING);
514 /* Synchronize the DMA memory for reading not required */
516 efx_ev_qpoll(evq->common, &evq->read_ptr, evq->callbacks, evq);
518 if (unlikely(evq->exception) && sfc_adapter_trylock(evq->sa)) {
519 struct sfc_adapter *sa = evq->sa;
522 if (evq->dp_rxq != NULL) {
523 unsigned int rxq_sw_index;
525 rxq_sw_index = evq->dp_rxq->dpq.queue_id;
528 "restart RxQ %u because of exception on its EvQ %u",
529 rxq_sw_index, evq->evq_index);
531 sfc_rx_qstop(sa, rxq_sw_index);
532 rc = sfc_rx_qstart(sa, rxq_sw_index);
534 sfc_err(sa, "cannot restart RxQ %u",
538 if (evq->dp_txq != NULL) {
539 unsigned int txq_sw_index;
541 txq_sw_index = evq->dp_txq->dpq.queue_id;
544 "restart TxQ %u because of exception on its EvQ %u",
545 txq_sw_index, evq->evq_index);
547 sfc_tx_qstop(sa, txq_sw_index);
548 rc = sfc_tx_qstart(sa, txq_sw_index);
550 sfc_err(sa, "cannot restart TxQ %u",
555 sfc_panic(sa, "unrecoverable exception on EvQ %u",
558 sfc_adapter_unlock(sa);
561 /* Poll-mode driver does not re-prime the event queue for interrupts */
565 sfc_ev_mgmt_qpoll(struct sfc_adapter *sa)
567 if (rte_spinlock_trylock(&sa->mgmt_evq_lock)) {
568 if (sa->mgmt_evq_running)
569 sfc_ev_qpoll(sa->mgmt_evq);
571 rte_spinlock_unlock(&sa->mgmt_evq_lock);
576 sfc_ev_qprime(struct sfc_evq *evq)
578 SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED);
579 return efx_ev_qprime(evq->common, evq->read_ptr);
582 /* Event queue HW index allocation scheme is described in sfc_ev.h. */
584 sfc_ev_qstart(struct sfc_evq *evq, unsigned int hw_index)
586 struct sfc_adapter *sa = evq->sa;
588 uint32_t evq_flags = sa->evq_flags;
589 unsigned int total_delay_us;
590 unsigned int delay_us;
593 sfc_log_init(sa, "hw_index=%u", hw_index);
597 evq->evq_index = hw_index;
599 /* Clear all events */
600 (void)memset((void *)esmp->esm_base, 0xff, EFX_EVQ_SIZE(evq->entries));
602 if (sa->intr.lsc_intr && hw_index == sa->mgmt_evq_index)
603 evq_flags |= EFX_EVQ_FLAGS_NOTIFY_INTERRUPT;
605 evq_flags |= EFX_EVQ_FLAGS_NOTIFY_DISABLED;
607 /* Create the common code event queue */
608 rc = efx_ev_qcreate(sa->nic, hw_index, esmp, evq->entries,
609 0 /* unused on EF10 */, 0, evq_flags,
612 goto fail_ev_qcreate;
614 SFC_ASSERT(evq->dp_rxq == NULL || evq->dp_txq == NULL);
615 if (evq->dp_rxq != 0) {
616 if (strcmp(sa->priv.dp_rx->dp.name,
617 SFC_KVARG_DATAPATH_EFX) == 0)
618 evq->callbacks = &sfc_ev_callbacks_efx_rx;
620 evq->callbacks = &sfc_ev_callbacks_dp_rx;
621 } else if (evq->dp_txq != 0) {
622 if (strcmp(sa->priv.dp_tx->dp.name,
623 SFC_KVARG_DATAPATH_EFX) == 0)
624 evq->callbacks = &sfc_ev_callbacks_efx_tx;
626 evq->callbacks = &sfc_ev_callbacks_dp_tx;
628 evq->callbacks = &sfc_ev_callbacks;
631 evq->init_state = SFC_EVQ_STARTING;
633 /* Wait for the initialization event */
635 delay_us = SFC_EVQ_INIT_BACKOFF_START_US;
637 (void)sfc_ev_qpoll(evq);
639 /* Check to see if the initialization complete indication
640 * posted by the hardware.
642 if (evq->init_state == SFC_EVQ_STARTED)
645 /* Give event queue some time to init */
646 rte_delay_us(delay_us);
648 total_delay_us += delay_us;
650 /* Exponential backoff */
652 if (delay_us > SFC_EVQ_INIT_BACKOFF_MAX_US)
653 delay_us = SFC_EVQ_INIT_BACKOFF_MAX_US;
655 } while (total_delay_us < SFC_EVQ_INIT_TIMEOUT_US);
664 evq->init_state = SFC_EVQ_INITIALIZED;
665 efx_ev_qdestroy(evq->common);
668 sfc_log_init(sa, "failed %d", rc);
673 sfc_ev_qstop(struct sfc_evq *evq)
678 sfc_log_init(evq->sa, "hw_index=%u", evq->evq_index);
680 if (evq->init_state != SFC_EVQ_STARTED)
683 evq->init_state = SFC_EVQ_INITIALIZED;
684 evq->callbacks = NULL;
686 evq->exception = B_FALSE;
688 efx_ev_qdestroy(evq->common);
694 sfc_ev_mgmt_periodic_qpoll(void *arg)
696 struct sfc_adapter *sa = arg;
699 sfc_ev_mgmt_qpoll(sa);
701 rc = rte_eal_alarm_set(SFC_MGMT_EV_QPOLL_PERIOD_US,
702 sfc_ev_mgmt_periodic_qpoll, sa);
703 if (rc == -ENOTSUP) {
704 sfc_warn(sa, "alarms are not supported");
705 sfc_warn(sa, "management EVQ must be polled indirectly using no-wait link status update");
706 } else if (rc != 0) {
708 "cannot rearm management EVQ polling alarm (rc=%d)",
714 sfc_ev_mgmt_periodic_qpoll_start(struct sfc_adapter *sa)
716 sfc_ev_mgmt_periodic_qpoll(sa);
720 sfc_ev_mgmt_periodic_qpoll_stop(struct sfc_adapter *sa)
722 rte_eal_alarm_cancel(sfc_ev_mgmt_periodic_qpoll, sa);
726 sfc_ev_start(struct sfc_adapter *sa)
730 sfc_log_init(sa, "entry");
732 rc = efx_ev_init(sa->nic);
736 /* Start management EVQ used for global events */
739 * Management event queue start polls the queue, but it cannot
740 * interfere with other polling contexts since mgmt_evq_running
743 rc = sfc_ev_qstart(sa->mgmt_evq, sa->mgmt_evq_index);
745 goto fail_mgmt_evq_start;
747 rte_spinlock_lock(&sa->mgmt_evq_lock);
748 sa->mgmt_evq_running = true;
749 rte_spinlock_unlock(&sa->mgmt_evq_lock);
751 if (sa->intr.lsc_intr) {
752 rc = sfc_ev_qprime(sa->mgmt_evq);
754 goto fail_mgmt_evq_prime;
758 * Start management EVQ polling. If interrupts are disabled
759 * (not used), it is required to process link status change
760 * and other device level events to avoid unrecoverable
761 * error because the event queue overflow.
763 sfc_ev_mgmt_periodic_qpoll_start(sa);
766 * Rx/Tx event queues are started/stopped when corresponding
767 * Rx/Tx queue is started/stopped.
773 sfc_ev_qstop(sa->mgmt_evq);
776 efx_ev_fini(sa->nic);
779 sfc_log_init(sa, "failed %d", rc);
784 sfc_ev_stop(struct sfc_adapter *sa)
786 sfc_log_init(sa, "entry");
788 sfc_ev_mgmt_periodic_qpoll_stop(sa);
790 rte_spinlock_lock(&sa->mgmt_evq_lock);
791 sa->mgmt_evq_running = false;
792 rte_spinlock_unlock(&sa->mgmt_evq_lock);
794 sfc_ev_qstop(sa->mgmt_evq);
796 efx_ev_fini(sa->nic);
800 sfc_ev_qinit(struct sfc_adapter *sa,
801 enum sfc_evq_type type, unsigned int type_index,
802 unsigned int entries, int socket_id, struct sfc_evq **evqp)
807 sfc_log_init(sa, "type=%s type_index=%u",
808 sfc_evq_type2str(type), type_index);
810 SFC_ASSERT(rte_is_power_of_2(entries));
813 evq = rte_zmalloc_socket("sfc-evq", sizeof(*evq), RTE_CACHE_LINE_SIZE,
820 evq->entries = entries;
822 /* Allocate DMA space */
823 rc = sfc_dma_alloc(sa, sfc_evq_type2str(type), type_index,
824 EFX_EVQ_SIZE(evq->entries), socket_id, &evq->mem);
828 evq->init_state = SFC_EVQ_INITIALIZED;
841 sfc_log_init(sa, "failed %d", rc);
846 sfc_ev_qfini(struct sfc_evq *evq)
848 struct sfc_adapter *sa = evq->sa;
850 SFC_ASSERT(evq->init_state == SFC_EVQ_INITIALIZED);
852 sfc_dma_free(sa, &evq->mem);
856 SFC_ASSERT(sa->evq_count > 0);
861 sfc_kvarg_perf_profile_handler(__rte_unused const char *key,
862 const char *value_str, void *opaque)
864 uint32_t *value = opaque;
866 if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_THROUGHPUT) == 0)
867 *value = EFX_EVQ_FLAGS_TYPE_THROUGHPUT;
868 else if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_LOW_LATENCY) == 0)
869 *value = EFX_EVQ_FLAGS_TYPE_LOW_LATENCY;
870 else if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_AUTO) == 0)
871 *value = EFX_EVQ_FLAGS_TYPE_AUTO;
879 sfc_ev_attach(struct sfc_adapter *sa)
883 sfc_log_init(sa, "entry");
885 sa->evq_flags = EFX_EVQ_FLAGS_TYPE_THROUGHPUT;
886 rc = sfc_kvargs_process(sa, SFC_KVARG_PERF_PROFILE,
887 sfc_kvarg_perf_profile_handler,
890 sfc_err(sa, "invalid %s parameter value",
891 SFC_KVARG_PERF_PROFILE);
892 goto fail_kvarg_perf_profile;
895 sa->mgmt_evq_index = 0;
896 rte_spinlock_init(&sa->mgmt_evq_lock);
898 rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_MGMT, 0, SFC_MGMT_EVQ_ENTRIES,
899 sa->socket_id, &sa->mgmt_evq);
901 goto fail_mgmt_evq_init;
904 * Rx/Tx event queues are created/destroyed when corresponding
905 * Rx/Tx queue is created/destroyed.
912 fail_kvarg_perf_profile:
913 sfc_log_init(sa, "failed %d", rc);
918 sfc_ev_detach(struct sfc_adapter *sa)
920 sfc_log_init(sa, "entry");
922 sfc_ev_qfini(sa->mgmt_evq);
924 if (sa->evq_count != 0)
925 sfc_err(sa, "%u EvQs are not destroyed before detach",