4 * Copyright (c) 2016-2017 Solarflare Communications Inc.
7 * This software was jointly developed between OKTET Labs (under contract
8 * for Solarflare) and Solarflare Communications, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <rte_debug.h>
33 #include <rte_cycles.h>
34 #include <rte_alarm.h>
35 #include <rte_branch_prediction.h>
40 #include "sfc_debug.h"
45 #include "sfc_kvargs.h"
48 /* Initial delay when waiting for event queue init complete event */
49 #define SFC_EVQ_INIT_BACKOFF_START_US (1)
50 /* Maximum delay between event queue polling attempts */
51 #define SFC_EVQ_INIT_BACKOFF_MAX_US (10 * 1000)
52 /* Event queue init approx timeout */
53 #define SFC_EVQ_INIT_TIMEOUT_US (2 * US_PER_S)
55 /* Management event queue polling period in microseconds */
56 #define SFC_MGMT_EV_QPOLL_PERIOD_US (US_PER_S)
60 sfc_ev_initialized(void *arg)
62 struct sfc_evq *evq = arg;
64 /* Init done events may be duplicated on SFN7xxx (SFC bug 31631) */
65 SFC_ASSERT(evq->init_state == SFC_EVQ_STARTING ||
66 evq->init_state == SFC_EVQ_STARTED);
68 evq->init_state = SFC_EVQ_STARTED;
74 sfc_ev_nop_rx(void *arg, uint32_t label, uint32_t id,
75 uint32_t size, uint16_t flags)
77 struct sfc_evq *evq = arg;
80 "EVQ %u unexpected Rx event label=%u id=%#x size=%u flags=%#x",
81 evq->evq_index, label, id, size, flags);
86 sfc_ev_efx_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
87 uint32_t size, uint16_t flags)
89 struct sfc_evq *evq = arg;
90 struct sfc_efx_rxq *rxq;
92 unsigned int pending_id;
95 struct sfc_efx_rx_sw_desc *rxd;
97 if (unlikely(evq->exception))
100 rxq = sfc_efx_rxq_by_dp_rxq(evq->dp_rxq);
102 SFC_ASSERT(rxq != NULL);
103 SFC_ASSERT(rxq->evq == evq);
104 SFC_ASSERT(rxq->flags & SFC_EFX_RXQ_FLAG_STARTED);
106 stop = (id + 1) & rxq->ptr_mask;
107 pending_id = rxq->pending & rxq->ptr_mask;
108 delta = (stop >= pending_id) ? (stop - pending_id) :
109 (rxq->ptr_mask + 1 - pending_id + stop);
113 * Rx event with no new descriptors done and zero length
114 * is used to abort scattered packet when there is no room
117 if (unlikely(size != 0)) {
118 evq->exception = B_TRUE;
120 "EVQ %u RxQ %u invalid RX abort "
121 "(id=%#x size=%u flags=%#x); needs restart",
122 evq->evq_index, rxq->dp.dpq.queue_id,
127 /* Add discard flag to the first fragment */
128 rxq->sw_desc[pending_id].flags |= EFX_DISCARD;
129 /* Remove continue flag from the last fragment */
130 rxq->sw_desc[id].flags &= ~EFX_PKT_CONT;
131 } else if (unlikely(delta > rxq->batch_max)) {
132 evq->exception = B_TRUE;
135 "EVQ %u RxQ %u completion out of order "
136 "(id=%#x delta=%u flags=%#x); needs restart",
137 evq->evq_index, rxq->dp.dpq.queue_id,
143 for (i = pending_id; i != stop; i = (i + 1) & rxq->ptr_mask) {
144 rxd = &rxq->sw_desc[i];
148 SFC_ASSERT(size < (1 << 16));
149 rxd->size = (uint16_t)size;
152 rxq->pending += delta;
159 sfc_ev_dp_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
160 __rte_unused uint32_t size, __rte_unused uint16_t flags)
162 struct sfc_evq *evq = arg;
163 struct sfc_dp_rxq *dp_rxq;
165 dp_rxq = evq->dp_rxq;
166 SFC_ASSERT(dp_rxq != NULL);
168 SFC_ASSERT(evq->sa->dp_rx->qrx_ev != NULL);
169 return evq->sa->dp_rx->qrx_ev(dp_rxq, id);
173 sfc_ev_nop_tx(void *arg, uint32_t label, uint32_t id)
175 struct sfc_evq *evq = arg;
177 sfc_err(evq->sa, "EVQ %u unexpected Tx event label=%u id=%#x",
178 evq->evq_index, label, id);
183 sfc_ev_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
185 struct sfc_evq *evq = arg;
186 struct sfc_dp_txq *dp_txq;
187 struct sfc_efx_txq *txq;
191 dp_txq = evq->dp_txq;
192 SFC_ASSERT(dp_txq != NULL);
194 txq = sfc_efx_txq_by_dp_txq(dp_txq);
195 SFC_ASSERT(txq->evq == evq);
197 if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_STARTED) == 0))
200 stop = (id + 1) & txq->ptr_mask;
201 id = txq->pending & txq->ptr_mask;
203 delta = (stop >= id) ? (stop - id) : (txq->ptr_mask + 1 - id + stop);
205 txq->pending += delta;
212 sfc_ev_dp_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
214 struct sfc_evq *evq = arg;
215 struct sfc_dp_txq *dp_txq;
217 dp_txq = evq->dp_txq;
218 SFC_ASSERT(dp_txq != NULL);
220 SFC_ASSERT(evq->sa->dp_tx->qtx_ev != NULL);
221 return evq->sa->dp_tx->qtx_ev(dp_txq, id);
225 sfc_ev_exception(void *arg, __rte_unused uint32_t code,
226 __rte_unused uint32_t data)
228 struct sfc_evq *evq = arg;
230 if (code == EFX_EXCEPTION_UNKNOWN_SENSOREVT)
233 evq->exception = B_TRUE;
235 "hardware exception %s (code=%u, data=%#x) on EVQ %u;"
237 (code == EFX_EXCEPTION_RX_RECOVERY) ? "RX_RECOVERY" :
238 (code == EFX_EXCEPTION_RX_DSC_ERROR) ? "RX_DSC_ERROR" :
239 (code == EFX_EXCEPTION_TX_DSC_ERROR) ? "TX_DSC_ERROR" :
240 (code == EFX_EXCEPTION_FWALERT_SRAM) ? "FWALERT_SRAM" :
241 (code == EFX_EXCEPTION_UNKNOWN_FWALERT) ? "UNKNOWN_FWALERT" :
242 (code == EFX_EXCEPTION_RX_ERROR) ? "RX_ERROR" :
243 (code == EFX_EXCEPTION_TX_ERROR) ? "TX_ERROR" :
244 (code == EFX_EXCEPTION_EV_ERROR) ? "EV_ERROR" :
246 code, data, evq->evq_index);
252 sfc_ev_nop_rxq_flush_done(void *arg, uint32_t rxq_hw_index)
254 struct sfc_evq *evq = arg;
256 sfc_err(evq->sa, "EVQ %u unexpected RxQ %u flush done",
257 evq->evq_index, rxq_hw_index);
262 sfc_ev_rxq_flush_done(void *arg, __rte_unused uint32_t rxq_hw_index)
264 struct sfc_evq *evq = arg;
265 struct sfc_dp_rxq *dp_rxq;
268 dp_rxq = evq->dp_rxq;
269 SFC_ASSERT(dp_rxq != NULL);
271 rxq = sfc_rxq_by_dp_rxq(dp_rxq);
272 SFC_ASSERT(rxq != NULL);
273 SFC_ASSERT(rxq->hw_index == rxq_hw_index);
274 SFC_ASSERT(rxq->evq == evq);
275 sfc_rx_qflush_done(rxq);
281 sfc_ev_nop_rxq_flush_failed(void *arg, uint32_t rxq_hw_index)
283 struct sfc_evq *evq = arg;
285 sfc_err(evq->sa, "EVQ %u unexpected RxQ %u flush failed",
286 evq->evq_index, rxq_hw_index);
291 sfc_ev_rxq_flush_failed(void *arg, __rte_unused uint32_t rxq_hw_index)
293 struct sfc_evq *evq = arg;
294 struct sfc_dp_rxq *dp_rxq;
297 dp_rxq = evq->dp_rxq;
298 SFC_ASSERT(dp_rxq != NULL);
300 rxq = sfc_rxq_by_dp_rxq(dp_rxq);
301 SFC_ASSERT(rxq != NULL);
302 SFC_ASSERT(rxq->hw_index == rxq_hw_index);
303 SFC_ASSERT(rxq->evq == evq);
304 sfc_rx_qflush_failed(rxq);
310 sfc_ev_nop_txq_flush_done(void *arg, uint32_t txq_hw_index)
312 struct sfc_evq *evq = arg;
314 sfc_err(evq->sa, "EVQ %u unexpected TxQ %u flush done",
315 evq->evq_index, txq_hw_index);
320 sfc_ev_txq_flush_done(void *arg, __rte_unused uint32_t txq_hw_index)
322 struct sfc_evq *evq = arg;
323 struct sfc_dp_txq *dp_txq;
326 dp_txq = evq->dp_txq;
327 SFC_ASSERT(dp_txq != NULL);
329 txq = sfc_txq_by_dp_txq(dp_txq);
330 SFC_ASSERT(txq != NULL);
331 SFC_ASSERT(txq->hw_index == txq_hw_index);
332 SFC_ASSERT(txq->evq == evq);
333 sfc_tx_qflush_done(txq);
339 sfc_ev_software(void *arg, uint16_t magic)
341 struct sfc_evq *evq = arg;
343 sfc_err(evq->sa, "EVQ %u unexpected software event magic=%#.4x",
344 evq->evq_index, magic);
349 sfc_ev_sram(void *arg, uint32_t code)
351 struct sfc_evq *evq = arg;
353 sfc_err(evq->sa, "EVQ %u unexpected SRAM event code=%u",
354 evq->evq_index, code);
359 sfc_ev_wake_up(void *arg, uint32_t index)
361 struct sfc_evq *evq = arg;
363 sfc_err(evq->sa, "EVQ %u unexpected wake up event index=%u",
364 evq->evq_index, index);
369 sfc_ev_timer(void *arg, uint32_t index)
371 struct sfc_evq *evq = arg;
373 sfc_err(evq->sa, "EVQ %u unexpected timer event index=%u",
374 evq->evq_index, index);
379 sfc_ev_nop_link_change(void *arg, __rte_unused efx_link_mode_t link_mode)
381 struct sfc_evq *evq = arg;
383 sfc_err(evq->sa, "EVQ %u unexpected link change event",
389 sfc_ev_link_change(void *arg, efx_link_mode_t link_mode)
391 struct sfc_evq *evq = arg;
392 struct sfc_adapter *sa = evq->sa;
393 struct rte_eth_link *dev_link = &sa->eth_dev->data->dev_link;
394 struct rte_eth_link new_link;
395 uint64_t new_link_u64;
396 uint64_t old_link_u64;
398 EFX_STATIC_ASSERT(sizeof(*dev_link) == sizeof(rte_atomic64_t));
400 sfc_port_link_mode_to_info(link_mode, &new_link);
402 new_link_u64 = *(uint64_t *)&new_link;
404 old_link_u64 = rte_atomic64_read((rte_atomic64_t *)dev_link);
405 if (old_link_u64 == new_link_u64)
408 if (rte_atomic64_cmpset((volatile uint64_t *)dev_link,
409 old_link_u64, new_link_u64)) {
410 evq->sa->port.lsc_seq++;
418 static const efx_ev_callbacks_t sfc_ev_callbacks = {
419 .eec_initialized = sfc_ev_initialized,
420 .eec_rx = sfc_ev_nop_rx,
421 .eec_tx = sfc_ev_nop_tx,
422 .eec_exception = sfc_ev_exception,
423 .eec_rxq_flush_done = sfc_ev_nop_rxq_flush_done,
424 .eec_rxq_flush_failed = sfc_ev_nop_rxq_flush_failed,
425 .eec_txq_flush_done = sfc_ev_nop_txq_flush_done,
426 .eec_software = sfc_ev_software,
427 .eec_sram = sfc_ev_sram,
428 .eec_wake_up = sfc_ev_wake_up,
429 .eec_timer = sfc_ev_timer,
430 .eec_link_change = sfc_ev_link_change,
433 static const efx_ev_callbacks_t sfc_ev_callbacks_efx_rx = {
434 .eec_initialized = sfc_ev_initialized,
435 .eec_rx = sfc_ev_efx_rx,
436 .eec_tx = sfc_ev_nop_tx,
437 .eec_exception = sfc_ev_exception,
438 .eec_rxq_flush_done = sfc_ev_rxq_flush_done,
439 .eec_rxq_flush_failed = sfc_ev_rxq_flush_failed,
440 .eec_txq_flush_done = sfc_ev_nop_txq_flush_done,
441 .eec_software = sfc_ev_software,
442 .eec_sram = sfc_ev_sram,
443 .eec_wake_up = sfc_ev_wake_up,
444 .eec_timer = sfc_ev_timer,
445 .eec_link_change = sfc_ev_nop_link_change,
448 static const efx_ev_callbacks_t sfc_ev_callbacks_dp_rx = {
449 .eec_initialized = sfc_ev_initialized,
450 .eec_rx = sfc_ev_dp_rx,
451 .eec_tx = sfc_ev_nop_tx,
452 .eec_exception = sfc_ev_exception,
453 .eec_rxq_flush_done = sfc_ev_rxq_flush_done,
454 .eec_rxq_flush_failed = sfc_ev_rxq_flush_failed,
455 .eec_txq_flush_done = sfc_ev_nop_txq_flush_done,
456 .eec_software = sfc_ev_software,
457 .eec_sram = sfc_ev_sram,
458 .eec_wake_up = sfc_ev_wake_up,
459 .eec_timer = sfc_ev_timer,
460 .eec_link_change = sfc_ev_nop_link_change,
463 static const efx_ev_callbacks_t sfc_ev_callbacks_efx_tx = {
464 .eec_initialized = sfc_ev_initialized,
465 .eec_rx = sfc_ev_nop_rx,
467 .eec_exception = sfc_ev_exception,
468 .eec_rxq_flush_done = sfc_ev_nop_rxq_flush_done,
469 .eec_rxq_flush_failed = sfc_ev_nop_rxq_flush_failed,
470 .eec_txq_flush_done = sfc_ev_txq_flush_done,
471 .eec_software = sfc_ev_software,
472 .eec_sram = sfc_ev_sram,
473 .eec_wake_up = sfc_ev_wake_up,
474 .eec_timer = sfc_ev_timer,
475 .eec_link_change = sfc_ev_nop_link_change,
478 static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {
479 .eec_initialized = sfc_ev_initialized,
480 .eec_rx = sfc_ev_nop_rx,
481 .eec_tx = sfc_ev_dp_tx,
482 .eec_exception = sfc_ev_exception,
483 .eec_rxq_flush_done = sfc_ev_nop_rxq_flush_done,
484 .eec_rxq_flush_failed = sfc_ev_nop_rxq_flush_failed,
485 .eec_txq_flush_done = sfc_ev_txq_flush_done,
486 .eec_software = sfc_ev_software,
487 .eec_sram = sfc_ev_sram,
488 .eec_wake_up = sfc_ev_wake_up,
489 .eec_timer = sfc_ev_timer,
490 .eec_link_change = sfc_ev_nop_link_change,
495 sfc_ev_qpoll(struct sfc_evq *evq)
497 SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED ||
498 evq->init_state == SFC_EVQ_STARTING);
500 /* Synchronize the DMA memory for reading not required */
502 efx_ev_qpoll(evq->common, &evq->read_ptr, evq->callbacks, evq);
504 if (unlikely(evq->exception) && sfc_adapter_trylock(evq->sa)) {
505 struct sfc_adapter *sa = evq->sa;
508 if (evq->dp_rxq != NULL) {
509 unsigned int rxq_sw_index;
511 rxq_sw_index = evq->dp_rxq->dpq.queue_id;
514 "restart RxQ %u because of exception on its EvQ %u",
515 rxq_sw_index, evq->evq_index);
517 sfc_rx_qstop(sa, rxq_sw_index);
518 rc = sfc_rx_qstart(sa, rxq_sw_index);
520 sfc_err(sa, "cannot restart RxQ %u",
524 if (evq->dp_txq != NULL) {
525 unsigned int txq_sw_index;
527 txq_sw_index = evq->dp_txq->dpq.queue_id;
530 "restart TxQ %u because of exception on its EvQ %u",
531 txq_sw_index, evq->evq_index);
533 sfc_tx_qstop(sa, txq_sw_index);
534 rc = sfc_tx_qstart(sa, txq_sw_index);
536 sfc_err(sa, "cannot restart TxQ %u",
541 sfc_panic(sa, "unrecoverable exception on EvQ %u",
544 sfc_adapter_unlock(sa);
547 /* Poll-mode driver does not re-prime the event queue for interrupts */
551 sfc_ev_mgmt_qpoll(struct sfc_adapter *sa)
553 if (rte_spinlock_trylock(&sa->mgmt_evq_lock)) {
554 struct sfc_evq *mgmt_evq = sa->evq_info[sa->mgmt_evq_index].evq;
556 if (mgmt_evq->init_state == SFC_EVQ_STARTED)
557 sfc_ev_qpoll(mgmt_evq);
559 rte_spinlock_unlock(&sa->mgmt_evq_lock);
564 sfc_ev_qprime(struct sfc_evq *evq)
566 SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED);
567 return efx_ev_qprime(evq->common, evq->read_ptr);
571 sfc_ev_qstart(struct sfc_adapter *sa, unsigned int sw_index)
573 const struct sfc_evq_info *evq_info;
576 unsigned int total_delay_us;
577 unsigned int delay_us;
580 sfc_log_init(sa, "sw_index=%u", sw_index);
582 evq_info = &sa->evq_info[sw_index];
586 /* Clear all events */
587 (void)memset((void *)esmp->esm_base, 0xff,
588 EFX_EVQ_SIZE(evq_info->entries));
590 /* Create the common code event queue */
591 rc = efx_ev_qcreate(sa->nic, sw_index, esmp, evq_info->entries,
592 0 /* unused on EF10 */, 0, evq_info->flags,
595 goto fail_ev_qcreate;
597 SFC_ASSERT(evq->dp_rxq == NULL || evq->dp_txq == NULL);
598 if (evq->dp_rxq != 0) {
599 if (strcmp(sa->dp_rx->dp.name, SFC_KVARG_DATAPATH_EFX) == 0)
600 evq->callbacks = &sfc_ev_callbacks_efx_rx;
602 evq->callbacks = &sfc_ev_callbacks_dp_rx;
603 } else if (evq->dp_txq != 0) {
604 if (strcmp(sa->dp_tx->dp.name, SFC_KVARG_DATAPATH_EFX) == 0)
605 evq->callbacks = &sfc_ev_callbacks_efx_tx;
607 evq->callbacks = &sfc_ev_callbacks_dp_tx;
609 evq->callbacks = &sfc_ev_callbacks;
612 evq->init_state = SFC_EVQ_STARTING;
614 /* Wait for the initialization event */
616 delay_us = SFC_EVQ_INIT_BACKOFF_START_US;
618 (void)sfc_ev_qpoll(evq);
620 /* Check to see if the initialization complete indication
621 * posted by the hardware.
623 if (evq->init_state == SFC_EVQ_STARTED)
626 /* Give event queue some time to init */
627 rte_delay_us(delay_us);
629 total_delay_us += delay_us;
631 /* Exponential backoff */
633 if (delay_us > SFC_EVQ_INIT_BACKOFF_MAX_US)
634 delay_us = SFC_EVQ_INIT_BACKOFF_MAX_US;
636 } while (total_delay_us < SFC_EVQ_INIT_TIMEOUT_US);
645 evq->init_state = SFC_EVQ_INITIALIZED;
646 efx_ev_qdestroy(evq->common);
649 sfc_log_init(sa, "failed %d", rc);
654 sfc_ev_qstop(struct sfc_adapter *sa, unsigned int sw_index)
656 const struct sfc_evq_info *evq_info;
659 sfc_log_init(sa, "sw_index=%u", sw_index);
661 SFC_ASSERT(sw_index < sa->evq_count);
663 evq_info = &sa->evq_info[sw_index];
666 if (evq == NULL || evq->init_state != SFC_EVQ_STARTED)
669 evq->init_state = SFC_EVQ_INITIALIZED;
670 evq->callbacks = NULL;
672 evq->exception = B_FALSE;
674 efx_ev_qdestroy(evq->common);
678 sfc_ev_mgmt_periodic_qpoll(void *arg)
680 struct sfc_adapter *sa = arg;
683 sfc_ev_mgmt_qpoll(sa);
685 rc = rte_eal_alarm_set(SFC_MGMT_EV_QPOLL_PERIOD_US,
686 sfc_ev_mgmt_periodic_qpoll, sa);
687 if (rc == -ENOTSUP) {
688 sfc_warn(sa, "alarms are not supported");
689 sfc_warn(sa, "management EVQ must be polled indirectly using no-wait link status update");
690 } else if (rc != 0) {
692 "cannot rearm management EVQ polling alarm (rc=%d)",
698 sfc_ev_mgmt_periodic_qpoll_start(struct sfc_adapter *sa)
700 sfc_ev_mgmt_periodic_qpoll(sa);
704 sfc_ev_mgmt_periodic_qpoll_stop(struct sfc_adapter *sa)
706 rte_eal_alarm_cancel(sfc_ev_mgmt_periodic_qpoll, sa);
710 sfc_ev_start(struct sfc_adapter *sa)
714 sfc_log_init(sa, "entry");
716 rc = efx_ev_init(sa->nic);
720 /* Start management EVQ used for global events */
721 rte_spinlock_lock(&sa->mgmt_evq_lock);
723 rc = sfc_ev_qstart(sa, sa->mgmt_evq_index);
725 goto fail_mgmt_evq_start;
727 if (sa->intr.lsc_intr) {
728 rc = sfc_ev_qprime(sa->evq_info[sa->mgmt_evq_index].evq);
730 goto fail_evq0_prime;
733 rte_spinlock_unlock(&sa->mgmt_evq_lock);
736 * Start management EVQ polling. If interrupts are disabled
737 * (not used), it is required to process link status change
738 * and other device level events to avoid unrecoverable
739 * error because the event queue overflow.
741 sfc_ev_mgmt_periodic_qpoll_start(sa);
744 * Rx/Tx event queues are started/stopped when corresponding
745 * Rx/Tx queue is started/stopped.
754 rte_spinlock_unlock(&sa->mgmt_evq_lock);
755 efx_ev_fini(sa->nic);
758 sfc_log_init(sa, "failed %d", rc);
763 sfc_ev_stop(struct sfc_adapter *sa)
765 unsigned int sw_index;
767 sfc_log_init(sa, "entry");
769 sfc_ev_mgmt_periodic_qpoll_stop(sa);
771 /* Make sure that all event queues are stopped */
772 sw_index = sa->evq_count;
773 while (sw_index-- > 0) {
774 if (sw_index == sa->mgmt_evq_index) {
775 /* Locks are required for the management EVQ */
776 rte_spinlock_lock(&sa->mgmt_evq_lock);
777 sfc_ev_qstop(sa, sa->mgmt_evq_index);
778 rte_spinlock_unlock(&sa->mgmt_evq_lock);
780 sfc_ev_qstop(sa, sw_index);
784 efx_ev_fini(sa->nic);
788 sfc_ev_qinit(struct sfc_adapter *sa, unsigned int sw_index,
789 unsigned int entries, int socket_id)
791 struct sfc_evq_info *evq_info;
795 sfc_log_init(sa, "sw_index=%u", sw_index);
797 evq_info = &sa->evq_info[sw_index];
799 SFC_ASSERT(rte_is_power_of_2(entries));
800 SFC_ASSERT(entries <= evq_info->max_entries);
801 evq_info->entries = entries;
803 evq = rte_zmalloc_socket("sfc-evq", sizeof(*evq), RTE_CACHE_LINE_SIZE,
809 evq->evq_index = sw_index;
811 /* Allocate DMA space */
812 rc = sfc_dma_alloc(sa, "evq", sw_index, EFX_EVQ_SIZE(evq_info->entries),
813 socket_id, &evq->mem);
817 evq->init_state = SFC_EVQ_INITIALIZED;
825 sfc_ev_qfini(struct sfc_adapter *sa, unsigned int sw_index)
829 sfc_log_init(sa, "sw_index=%u", sw_index);
831 evq = sa->evq_info[sw_index].evq;
833 SFC_ASSERT(evq->init_state == SFC_EVQ_INITIALIZED);
835 sa->evq_info[sw_index].evq = NULL;
837 sfc_dma_free(sa, &evq->mem);
843 sfc_ev_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
845 struct sfc_evq_info *evq_info = &sa->evq_info[sw_index];
846 unsigned int max_entries;
848 sfc_log_init(sa, "sw_index=%u", sw_index);
850 max_entries = sfc_evq_max_entries(sa, sw_index);
851 SFC_ASSERT(rte_is_power_of_2(max_entries));
853 evq_info->max_entries = max_entries;
854 evq_info->flags = sa->evq_flags |
855 ((sa->intr.lsc_intr && sw_index == sa->mgmt_evq_index) ?
856 EFX_EVQ_FLAGS_NOTIFY_INTERRUPT :
857 EFX_EVQ_FLAGS_NOTIFY_DISABLED);
863 sfc_kvarg_perf_profile_handler(__rte_unused const char *key,
864 const char *value_str, void *opaque)
866 uint64_t *value = opaque;
868 if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_THROUGHPUT) == 0)
869 *value = EFX_EVQ_FLAGS_TYPE_THROUGHPUT;
870 else if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_LOW_LATENCY) == 0)
871 *value = EFX_EVQ_FLAGS_TYPE_LOW_LATENCY;
872 else if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_AUTO) == 0)
873 *value = EFX_EVQ_FLAGS_TYPE_AUTO;
881 sfc_ev_qfini_info(struct sfc_adapter *sa, unsigned int sw_index)
883 sfc_log_init(sa, "sw_index=%u", sw_index);
885 /* Nothing to cleanup */
889 sfc_ev_init(struct sfc_adapter *sa)
892 unsigned int sw_index;
894 sfc_log_init(sa, "entry");
896 sa->evq_flags = EFX_EVQ_FLAGS_TYPE_THROUGHPUT;
897 rc = sfc_kvargs_process(sa, SFC_KVARG_PERF_PROFILE,
898 sfc_kvarg_perf_profile_handler,
901 sfc_err(sa, "invalid %s parameter value",
902 SFC_KVARG_PERF_PROFILE);
903 goto fail_kvarg_perf_profile;
906 sa->evq_count = sfc_ev_qcount(sa);
907 sa->mgmt_evq_index = 0;
908 rte_spinlock_init(&sa->mgmt_evq_lock);
910 /* Allocate EVQ info array */
912 sa->evq_info = rte_calloc_socket("sfc-evqs", sa->evq_count,
913 sizeof(struct sfc_evq_info), 0,
915 if (sa->evq_info == NULL)
916 goto fail_evqs_alloc;
918 for (sw_index = 0; sw_index < sa->evq_count; ++sw_index) {
919 rc = sfc_ev_qinit_info(sa, sw_index);
921 goto fail_ev_qinit_info;
924 rc = sfc_ev_qinit(sa, sa->mgmt_evq_index, SFC_MGMT_EVQ_ENTRIES,
927 goto fail_mgmt_evq_init;
930 * Rx/Tx event queues are created/destroyed when corresponding
931 * Rx/Tx queue is created/destroyed.
938 while (sw_index-- > 0)
939 sfc_ev_qfini_info(sa, sw_index);
941 rte_free(sa->evq_info);
947 fail_kvarg_perf_profile:
948 sfc_log_init(sa, "failed %d", rc);
953 sfc_ev_fini(struct sfc_adapter *sa)
957 sfc_log_init(sa, "entry");
959 /* Cleanup all event queues */
960 sw_index = sa->evq_count;
961 while (--sw_index >= 0) {
962 if (sa->evq_info[sw_index].evq != NULL)
963 sfc_ev_qfini(sa, sw_index);
964 sfc_ev_qfini_info(sa, sw_index);
967 rte_free(sa->evq_info);