LCOV - code coverage report
Current view: top level - drivers/net/sfc - sfc_ev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 323 0.0 %
Date: 2025-08-01 17:49:26 Functions: 0 39 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 128 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *
       3                 :            :  * Copyright(c) 2019-2021 Xilinx, Inc.
       4                 :            :  * Copyright(c) 2016-2019 Solarflare Communications Inc.
       5                 :            :  *
       6                 :            :  * This software was jointly developed between OKTET Labs (under contract
       7                 :            :  * for Solarflare) and Solarflare Communications, Inc.
       8                 :            :  */
       9                 :            : 
      10                 :            : #include <rte_debug.h>
      11                 :            : #include <rte_cycles.h>
      12                 :            : #include <rte_alarm.h>
      13                 :            : #include <rte_branch_prediction.h>
      14                 :            : 
      15                 :            : #include "efx.h"
      16                 :            : 
      17                 :            : #include "sfc.h"
      18                 :            : #include "sfc_debug.h"
      19                 :            : #include "sfc_log.h"
      20                 :            : #include "sfc_ev.h"
      21                 :            : #include "sfc_rx.h"
      22                 :            : #include "sfc_tx.h"
      23                 :            : #include "sfc_kvargs.h"
      24                 :            : 
      25                 :            : 
      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)
      32                 :            : 
      33                 :            : /* Management event queue polling period in microseconds */
      34                 :            : #define SFC_MGMT_EV_QPOLL_PERIOD_US     (US_PER_S)
      35                 :            : 
      36                 :            : static const char *
      37                 :            : sfc_evq_type2str(enum sfc_evq_type type)
      38                 :            : {
      39                 :          0 :         switch (type) {
      40                 :            :         case SFC_EVQ_TYPE_MGMT:
      41                 :            :                 return "mgmt-evq";
      42                 :          0 :         case SFC_EVQ_TYPE_RX:
      43                 :          0 :                 return "rx-evq";
      44                 :          0 :         case SFC_EVQ_TYPE_TX:
      45                 :          0 :                 return "tx-evq";
      46                 :          0 :         default:
      47                 :            :                 SFC_ASSERT(B_FALSE);
      48                 :          0 :                 return NULL;
      49                 :            :         }
      50                 :            : }
      51                 :            : 
      52                 :            : static boolean_t
      53                 :          0 : sfc_ev_initialized(void *arg)
      54                 :            : {
      55                 :            :         struct sfc_evq *evq = arg;
      56                 :            : 
      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);
      60                 :            : 
      61                 :          0 :         evq->init_state = SFC_EVQ_STARTED;
      62                 :            : 
      63                 :          0 :         return B_FALSE;
      64                 :            : }
      65                 :            : 
      66                 :            : static boolean_t
      67                 :          0 : sfc_ev_nop_rx(void *arg, uint32_t label, uint32_t id,
      68                 :            :               uint32_t size, uint16_t flags)
      69                 :            : {
      70                 :            :         struct sfc_evq *evq = arg;
      71                 :            : 
      72                 :          0 :         sfc_err(evq->sa,
      73                 :            :                 "EVQ %u unexpected Rx event label=%u id=%#x size=%u flags=%#x",
      74                 :            :                 evq->evq_index, label, id, size, flags);
      75                 :          0 :         return B_TRUE;
      76                 :            : }
      77                 :            : 
      78                 :            : static boolean_t
      79                 :          0 : sfc_ev_efx_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
      80                 :            :               uint32_t size, uint16_t flags)
      81                 :            : {
      82                 :            :         struct sfc_evq *evq = arg;
      83                 :            :         struct sfc_efx_rxq *rxq;
      84                 :            :         unsigned int stop;
      85                 :            :         unsigned int pending_id;
      86                 :            :         unsigned int delta;
      87                 :            :         unsigned int i;
      88                 :            :         struct sfc_efx_rx_sw_desc *rxd;
      89                 :            : 
      90         [ #  # ]:          0 :         if (unlikely(evq->exception))
      91                 :          0 :                 goto done;
      92                 :            : 
      93         [ #  # ]:          0 :         rxq = sfc_efx_rxq_by_dp_rxq(evq->dp_rxq);
      94                 :            : 
      95                 :            :         SFC_ASSERT(rxq != NULL);
      96                 :            :         SFC_ASSERT(rxq->evq == evq);
      97                 :            :         SFC_ASSERT(rxq->flags & SFC_EFX_RXQ_FLAG_STARTED);
      98                 :            : 
      99                 :          0 :         stop = (id + 1) & rxq->ptr_mask;
     100                 :          0 :         pending_id = rxq->pending & rxq->ptr_mask;
     101         [ #  # ]:          0 :         delta = (stop >= pending_id) ? (stop - pending_id) :
     102                 :          0 :                 (rxq->ptr_mask + 1 - pending_id + stop);
     103                 :            : 
     104         [ #  # ]:          0 :         if (delta == 0) {
     105                 :            :                 /*
     106                 :            :                  * Rx event with no new descriptors done and zero length
     107                 :            :                  * is used to abort scattered packet when there is no room
     108                 :            :                  * for the tail.
     109                 :            :                  */
     110         [ #  # ]:          0 :                 if (unlikely(size != 0)) {
     111                 :          0 :                         evq->exception = B_TRUE;
     112                 :          0 :                         sfc_err(evq->sa,
     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,
     116                 :            :                                 id, size, flags);
     117                 :          0 :                         goto done;
     118                 :            :                 }
     119                 :            : 
     120                 :            :                 /* Add discard flag to the first fragment */
     121                 :          0 :                 rxq->sw_desc[pending_id].flags |= EFX_DISCARD;
     122                 :            :                 /* Remove continue flag from the last fragment */
     123                 :          0 :                 rxq->sw_desc[id].flags &= ~EFX_PKT_CONT;
     124         [ #  # ]:          0 :         } else if (unlikely(delta > rxq->batch_max)) {
     125                 :          0 :                 evq->exception = B_TRUE;
     126                 :            : 
     127                 :          0 :                 sfc_err(evq->sa,
     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,
     131                 :            :                         id, delta, flags);
     132                 :            : 
     133                 :          0 :                 goto done;
     134                 :            :         }
     135                 :            : 
     136         [ #  # ]:          0 :         for (i = pending_id; i != stop; i = (i + 1) & rxq->ptr_mask) {
     137                 :          0 :                 rxd = &rxq->sw_desc[i];
     138                 :            : 
     139                 :          0 :                 rxd->flags = flags;
     140                 :            : 
     141                 :            :                 SFC_ASSERT(size < (1 << 16));
     142                 :          0 :                 rxd->size = (uint16_t)size;
     143                 :            :         }
     144                 :            : 
     145                 :          0 :         rxq->pending += delta;
     146                 :            : 
     147                 :          0 : done:
     148                 :          0 :         return B_FALSE;
     149                 :            : }
     150                 :            : 
     151                 :            : static boolean_t
     152                 :          0 : 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)
     154                 :            : {
     155                 :            :         struct sfc_evq *evq = arg;
     156                 :            :         struct sfc_dp_rxq *dp_rxq;
     157                 :            : 
     158                 :          0 :         dp_rxq = evq->dp_rxq;
     159                 :            :         SFC_ASSERT(dp_rxq != NULL);
     160                 :            : 
     161                 :            :         SFC_ASSERT(evq->sa->priv.dp_rx->qrx_ev != NULL);
     162                 :          0 :         return evq->sa->priv.dp_rx->qrx_ev(dp_rxq, id);
     163                 :            : }
     164                 :            : 
     165                 :            : static boolean_t
     166                 :          0 : sfc_ev_nop_rx_packets(void *arg, uint32_t label, unsigned int num_packets,
     167                 :            :                       uint32_t flags)
     168                 :            : {
     169                 :            :         struct sfc_evq *evq = arg;
     170                 :            : 
     171                 :          0 :         sfc_err(evq->sa,
     172                 :            :                 "EVQ %u unexpected Rx packets event label=%u num=%u flags=%#x",
     173                 :            :                 evq->evq_index, label, num_packets, flags);
     174                 :          0 :         return B_TRUE;
     175                 :            : }
     176                 :            : 
     177                 :            : static boolean_t
     178                 :          0 : sfc_ev_dp_rx_packets(void *arg, __rte_unused uint32_t label,
     179                 :            :                      unsigned int num_packets, __rte_unused uint32_t flags)
     180                 :            : {
     181                 :            :         struct sfc_evq *evq = arg;
     182                 :            :         struct sfc_dp_rxq *dp_rxq;
     183                 :            : 
     184                 :          0 :         dp_rxq = evq->dp_rxq;
     185                 :            :         SFC_ASSERT(dp_rxq != NULL);
     186                 :            : 
     187                 :            :         SFC_ASSERT(evq->sa->priv.dp_rx->qrx_ev != NULL);
     188                 :          0 :         return evq->sa->priv.dp_rx->qrx_ev(dp_rxq, num_packets);
     189                 :            : }
     190                 :            : 
     191                 :            : static boolean_t
     192                 :          0 : sfc_ev_nop_rx_ps(void *arg, uint32_t label, uint32_t id,
     193                 :            :                  uint32_t pkt_count, uint16_t flags)
     194                 :            : {
     195                 :            :         struct sfc_evq *evq = arg;
     196                 :            : 
     197                 :          0 :         sfc_err(evq->sa,
     198                 :            :                 "EVQ %u unexpected packed stream Rx event label=%u id=%#x pkt_count=%u flags=%#x",
     199                 :            :                 evq->evq_index, label, id, pkt_count, flags);
     200                 :          0 :         return B_TRUE;
     201                 :            : }
     202                 :            : 
     203                 :            : /* It is not actually used on datapath, but required on RxQ flush */
     204                 :            : static boolean_t
     205                 :          0 : sfc_ev_dp_rx_ps(void *arg, __rte_unused uint32_t label, uint32_t id,
     206                 :            :                 __rte_unused uint32_t pkt_count, __rte_unused uint16_t flags)
     207                 :            : {
     208                 :            :         struct sfc_evq *evq = arg;
     209                 :            :         struct sfc_dp_rxq *dp_rxq;
     210                 :            : 
     211                 :          0 :         dp_rxq = evq->dp_rxq;
     212                 :            :         SFC_ASSERT(dp_rxq != NULL);
     213                 :            : 
     214         [ #  # ]:          0 :         if (evq->sa->priv.dp_rx->qrx_ps_ev != NULL)
     215                 :          0 :                 return evq->sa->priv.dp_rx->qrx_ps_ev(dp_rxq, id);
     216                 :            :         else
     217                 :            :                 return B_FALSE;
     218                 :            : }
     219                 :            : 
     220                 :            : static boolean_t
     221                 :          0 : sfc_ev_nop_tx(void *arg, uint32_t label, uint32_t id)
     222                 :            : {
     223                 :            :         struct sfc_evq *evq = arg;
     224                 :            : 
     225                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected Tx event label=%u id=%#x",
     226                 :            :                 evq->evq_index, label, id);
     227                 :          0 :         return B_TRUE;
     228                 :            : }
     229                 :            : 
     230                 :            : static boolean_t
     231                 :          0 : sfc_ev_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
     232                 :            : {
     233                 :            :         struct sfc_evq *evq = arg;
     234                 :            :         struct sfc_dp_txq *dp_txq;
     235                 :            :         struct sfc_efx_txq *txq;
     236                 :            :         unsigned int stop;
     237                 :            :         unsigned int delta;
     238                 :            : 
     239         [ #  # ]:          0 :         dp_txq = evq->dp_txq;
     240                 :            :         SFC_ASSERT(dp_txq != NULL);
     241                 :            : 
     242                 :            :         txq = sfc_efx_txq_by_dp_txq(dp_txq);
     243                 :            :         SFC_ASSERT(txq->evq == evq);
     244                 :            : 
     245         [ #  # ]:          0 :         if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_STARTED) == 0))
     246                 :          0 :                 goto done;
     247                 :            : 
     248                 :          0 :         stop = (id + 1) & txq->ptr_mask;
     249                 :          0 :         id = txq->pending & txq->ptr_mask;
     250                 :            : 
     251         [ #  # ]:          0 :         delta = (stop >= id) ? (stop - id) : (txq->ptr_mask + 1 - id + stop);
     252                 :            : 
     253                 :          0 :         txq->pending += delta;
     254                 :            : 
     255                 :          0 : done:
     256                 :          0 :         return B_FALSE;
     257                 :            : }
     258                 :            : 
     259                 :            : static boolean_t
     260                 :          0 : sfc_ev_dp_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
     261                 :            : {
     262                 :            :         struct sfc_evq *evq = arg;
     263                 :            :         struct sfc_dp_txq *dp_txq;
     264                 :            : 
     265                 :          0 :         dp_txq = evq->dp_txq;
     266                 :            :         SFC_ASSERT(dp_txq != NULL);
     267                 :            : 
     268                 :            :         SFC_ASSERT(evq->sa->priv.dp_tx->qtx_ev != NULL);
     269                 :          0 :         return evq->sa->priv.dp_tx->qtx_ev(dp_txq, id);
     270                 :            : }
     271                 :            : 
     272                 :            : static boolean_t
     273                 :          0 : sfc_ev_nop_tx_ndescs(void *arg, uint32_t label, unsigned int ndescs)
     274                 :            : {
     275                 :            :         struct sfc_evq *evq = arg;
     276                 :            : 
     277                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected Tx event label=%u ndescs=%#x",
     278                 :            :                 evq->evq_index, label, ndescs);
     279                 :          0 :         return B_TRUE;
     280                 :            : }
     281                 :            : 
     282                 :            : static boolean_t
     283                 :          0 : sfc_ev_dp_tx_ndescs(void *arg, __rte_unused uint32_t label,
     284                 :            :                       unsigned int ndescs)
     285                 :            : {
     286                 :            :         struct sfc_evq *evq = arg;
     287                 :            :         struct sfc_dp_txq *dp_txq;
     288                 :            : 
     289                 :          0 :         dp_txq = evq->dp_txq;
     290                 :            :         SFC_ASSERT(dp_txq != NULL);
     291                 :            : 
     292                 :            :         SFC_ASSERT(evq->sa->priv.dp_tx->qtx_ev != NULL);
     293                 :          0 :         return evq->sa->priv.dp_tx->qtx_ev(dp_txq, ndescs);
     294                 :            : }
     295                 :            : 
     296                 :            : static boolean_t
     297                 :          0 : sfc_ev_exception(void *arg, uint32_t code, __rte_unused uint32_t data)
     298                 :            : {
     299                 :            :         struct sfc_evq *evq = arg;
     300                 :            : 
     301         [ #  # ]:          0 :         if (code == EFX_EXCEPTION_UNKNOWN_SENSOREVT)
     302                 :            :                 return B_FALSE;
     303                 :            : 
     304                 :          0 :         evq->exception = B_TRUE;
     305         [ #  # ]:          0 :         sfc_warn(evq->sa,
     306                 :            :                  "hardware exception %s (code=%u, data=%#x) on EVQ %u;"
     307                 :            :                  " needs recovery",
     308                 :            :                  (code == EFX_EXCEPTION_RX_RECOVERY) ? "RX_RECOVERY" :
     309                 :            :                  (code == EFX_EXCEPTION_RX_DSC_ERROR) ? "RX_DSC_ERROR" :
     310                 :            :                  (code == EFX_EXCEPTION_TX_DSC_ERROR) ? "TX_DSC_ERROR" :
     311                 :            :                  (code == EFX_EXCEPTION_FWALERT_SRAM) ? "FWALERT_SRAM" :
     312                 :            :                  (code == EFX_EXCEPTION_UNKNOWN_FWALERT) ? "UNKNOWN_FWALERT" :
     313                 :            :                  (code == EFX_EXCEPTION_RX_ERROR) ? "RX_ERROR" :
     314                 :            :                  (code == EFX_EXCEPTION_TX_ERROR) ? "TX_ERROR" :
     315                 :            :                  (code == EFX_EXCEPTION_EV_ERROR) ? "EV_ERROR" :
     316                 :            :                  "UNKNOWN",
     317                 :            :                  code, data, evq->evq_index);
     318                 :            : 
     319                 :          0 :         return B_TRUE;
     320                 :            : }
     321                 :            : 
     322                 :            : static boolean_t
     323                 :          0 : sfc_ev_nop_rxq_flush_done(void *arg, uint32_t rxq_hw_index)
     324                 :            : {
     325                 :            :         struct sfc_evq *evq = arg;
     326                 :            : 
     327                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected RxQ %u flush done",
     328                 :            :                 evq->evq_index, rxq_hw_index);
     329                 :          0 :         return B_TRUE;
     330                 :            : }
     331                 :            : 
     332                 :            : static boolean_t
     333                 :          0 : sfc_ev_rxq_flush_done(void *arg, __rte_unused uint32_t rxq_hw_index)
     334                 :            : {
     335                 :            :         struct sfc_evq *evq = arg;
     336                 :            :         struct sfc_dp_rxq *dp_rxq;
     337                 :            :         struct sfc_rxq *rxq;
     338                 :            : 
     339                 :          0 :         dp_rxq = evq->dp_rxq;
     340                 :            :         SFC_ASSERT(dp_rxq != NULL);
     341                 :            : 
     342                 :          0 :         rxq = sfc_rxq_by_dp_rxq(dp_rxq);
     343                 :            :         SFC_ASSERT(rxq != NULL);
     344                 :            :         SFC_ASSERT(rxq->hw_index == rxq_hw_index);
     345                 :            :         SFC_ASSERT(rxq->evq == evq);
     346                 :            :         RTE_SET_USED(rxq);
     347                 :            : 
     348                 :          0 :         sfc_rx_qflush_done(sfc_rxq_info_by_dp_rxq(dp_rxq));
     349                 :            : 
     350                 :          0 :         return B_FALSE;
     351                 :            : }
     352                 :            : 
     353                 :            : static boolean_t
     354                 :          0 : sfc_ev_nop_rxq_flush_failed(void *arg, uint32_t rxq_hw_index)
     355                 :            : {
     356                 :            :         struct sfc_evq *evq = arg;
     357                 :            : 
     358                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected RxQ %u flush failed",
     359                 :            :                 evq->evq_index, rxq_hw_index);
     360                 :          0 :         return B_TRUE;
     361                 :            : }
     362                 :            : 
     363                 :            : static boolean_t
     364                 :          0 : sfc_ev_rxq_flush_failed(void *arg, __rte_unused uint32_t rxq_hw_index)
     365                 :            : {
     366                 :            :         struct sfc_evq *evq = arg;
     367                 :            :         struct sfc_dp_rxq *dp_rxq;
     368                 :            :         struct sfc_rxq *rxq;
     369                 :            : 
     370                 :          0 :         dp_rxq = evq->dp_rxq;
     371                 :            :         SFC_ASSERT(dp_rxq != NULL);
     372                 :            : 
     373                 :          0 :         rxq = sfc_rxq_by_dp_rxq(dp_rxq);
     374                 :            :         SFC_ASSERT(rxq != NULL);
     375                 :            :         SFC_ASSERT(rxq->hw_index == rxq_hw_index);
     376                 :            :         SFC_ASSERT(rxq->evq == evq);
     377                 :            :         RTE_SET_USED(rxq);
     378                 :            : 
     379                 :          0 :         sfc_rx_qflush_failed(sfc_rxq_info_by_dp_rxq(dp_rxq));
     380                 :            : 
     381                 :          0 :         return B_FALSE;
     382                 :            : }
     383                 :            : 
     384                 :            : static boolean_t
     385                 :          0 : sfc_ev_nop_txq_flush_done(void *arg, uint32_t txq_hw_index)
     386                 :            : {
     387                 :            :         struct sfc_evq *evq = arg;
     388                 :            : 
     389                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected TxQ %u flush done",
     390                 :            :                 evq->evq_index, txq_hw_index);
     391                 :          0 :         return B_TRUE;
     392                 :            : }
     393                 :            : 
     394                 :            : static boolean_t
     395                 :          0 : sfc_ev_txq_flush_done(void *arg, __rte_unused uint32_t txq_hw_index)
     396                 :            : {
     397                 :            :         struct sfc_evq *evq = arg;
     398                 :            :         struct sfc_dp_txq *dp_txq;
     399                 :            :         struct sfc_txq *txq;
     400                 :            : 
     401                 :          0 :         dp_txq = evq->dp_txq;
     402                 :            :         SFC_ASSERT(dp_txq != NULL);
     403                 :            : 
     404                 :          0 :         txq = sfc_txq_by_dp_txq(dp_txq);
     405                 :            :         SFC_ASSERT(txq != NULL);
     406                 :            :         SFC_ASSERT(txq->hw_index == txq_hw_index);
     407                 :            :         SFC_ASSERT(txq->evq == evq);
     408                 :            :         RTE_SET_USED(txq);
     409                 :            : 
     410                 :          0 :         sfc_tx_qflush_done(sfc_txq_info_by_dp_txq(dp_txq));
     411                 :            : 
     412                 :          0 :         return B_FALSE;
     413                 :            : }
     414                 :            : 
     415                 :            : static boolean_t
     416                 :          0 : sfc_ev_software(void *arg, uint16_t magic)
     417                 :            : {
     418                 :            :         struct sfc_evq *evq = arg;
     419                 :            : 
     420                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected software event magic=%#.4x",
     421                 :            :                 evq->evq_index, magic);
     422                 :          0 :         return B_TRUE;
     423                 :            : }
     424                 :            : 
     425                 :            : static boolean_t
     426                 :          0 : sfc_ev_sram(void *arg, uint32_t code)
     427                 :            : {
     428                 :            :         struct sfc_evq *evq = arg;
     429                 :            : 
     430                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected SRAM event code=%u",
     431                 :            :                 evq->evq_index, code);
     432                 :          0 :         return B_TRUE;
     433                 :            : }
     434                 :            : 
     435                 :            : static boolean_t
     436                 :          0 : sfc_ev_wake_up(void *arg, uint32_t index)
     437                 :            : {
     438                 :            :         struct sfc_evq *evq = arg;
     439                 :            : 
     440                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected wake up event index=%u",
     441                 :            :                 evq->evq_index, index);
     442                 :          0 :         return B_TRUE;
     443                 :            : }
     444                 :            : 
     445                 :            : static boolean_t
     446                 :          0 : sfc_ev_timer(void *arg, uint32_t index)
     447                 :            : {
     448                 :            :         struct sfc_evq *evq = arg;
     449                 :            : 
     450                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected timer event index=%u",
     451                 :            :                 evq->evq_index, index);
     452                 :          0 :         return B_TRUE;
     453                 :            : }
     454                 :            : 
     455                 :            : static boolean_t
     456                 :          0 : sfc_ev_nop_link_change(void *arg, __rte_unused efx_link_mode_t link_mode)
     457                 :            : {
     458                 :            :         struct sfc_evq *evq = arg;
     459                 :            : 
     460                 :          0 :         sfc_err(evq->sa, "EVQ %u unexpected link change event",
     461                 :            :                 evq->evq_index);
     462                 :          0 :         return B_TRUE;
     463                 :            : }
     464                 :            : 
     465                 :            : static boolean_t
     466                 :          0 : sfc_ev_link_change(void *arg, efx_link_mode_t link_mode)
     467                 :            : {
     468                 :            :         struct sfc_evq *evq = arg;
     469                 :          0 :         struct sfc_adapter *sa = evq->sa;
     470                 :          0 :         struct rte_eth_link new_link = {0};
     471                 :            : 
     472         [ #  # ]:          0 :         if (sa->link_ev_need_poll) {
     473                 :            :                 efx_link_mode_t new_mode;
     474                 :            :                 bool poll_done = false;
     475                 :            : 
     476                 :            :                 /*
     477                 :            :                  * The event provides only the general status. When the link is
     478                 :            :                  * up, poll the port to get the speed, but it is not compulsory.
     479                 :            :                  */
     480         [ #  # ]:          0 :                 if (link_mode != EFX_LINK_DOWN) {
     481                 :            :                         int ret = 0;
     482                 :            : 
     483         [ #  # ]:          0 :                         if (sfc_adapter_trylock(sa)) {
     484                 :            :                                 /* Never poll when the adaptor is going down. */
     485         [ #  # ]:          0 :                                 if (sa->state == SFC_ETHDEV_STARTED) {
     486                 :          0 :                                         ret = efx_port_poll(sa->nic, &new_mode);
     487                 :            :                                         poll_done = true;
     488                 :            :                                 }
     489                 :            : 
     490                 :            :                                 sfc_adapter_unlock(sa);
     491                 :            :                         }
     492                 :            : 
     493         [ #  # ]:          0 :                         if (ret != 0) {
     494                 :          0 :                                 sfc_warn(sa, "port poll failed on link event");
     495                 :            :                                 poll_done = false;
     496                 :            :                         }
     497                 :            :                 }
     498                 :            : 
     499         [ #  # ]:          0 :                 if (poll_done) {
     500                 :          0 :                         link_mode = new_mode;
     501                 :          0 :                         goto decode_comprehensive;
     502                 :            :                 }
     503                 :            : 
     504                 :          0 :                 new_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
     505                 :          0 :                 new_link.link_autoneg = RTE_ETH_LINK_AUTONEG;
     506                 :            : 
     507         [ #  # ]:          0 :                 if (link_mode == EFX_LINK_DOWN) {
     508                 :          0 :                         new_link.link_speed  = RTE_ETH_SPEED_NUM_NONE;
     509                 :          0 :                         new_link.link_status = RTE_ETH_LINK_DOWN;
     510                 :            :                 } else {
     511                 :          0 :                         new_link.link_speed  = RTE_ETH_SPEED_NUM_UNKNOWN;
     512                 :          0 :                         new_link.link_status = RTE_ETH_LINK_UP;
     513                 :            :                 }
     514                 :            : 
     515                 :          0 :                 goto set;
     516                 :            :         }
     517                 :            : 
     518                 :          0 : decode_comprehensive:
     519                 :          0 :         sfc_port_link_mode_to_info(link_mode, &new_link);
     520                 :            : 
     521                 :          0 : set:
     522         [ #  # ]:          0 :         if (rte_eth_linkstatus_set(sa->eth_dev, &new_link) == 0)
     523                 :          0 :                 evq->sa->port.lsc_seq++;
     524                 :            : 
     525                 :          0 :         return B_FALSE;
     526                 :            : }
     527                 :            : 
     528                 :            : static const efx_ev_callbacks_t sfc_ev_callbacks = {
     529                 :            :         .eec_initialized        = sfc_ev_initialized,
     530                 :            :         .eec_rx                 = sfc_ev_nop_rx,
     531                 :            :         .eec_rx_packets         = sfc_ev_nop_rx_packets,
     532                 :            :         .eec_rx_ps              = sfc_ev_nop_rx_ps,
     533                 :            :         .eec_tx                 = sfc_ev_nop_tx,
     534                 :            :         .eec_tx_ndescs          = sfc_ev_nop_tx_ndescs,
     535                 :            :         .eec_exception          = sfc_ev_exception,
     536                 :            :         .eec_rxq_flush_done     = sfc_ev_nop_rxq_flush_done,
     537                 :            :         .eec_rxq_flush_failed   = sfc_ev_nop_rxq_flush_failed,
     538                 :            :         .eec_txq_flush_done     = sfc_ev_nop_txq_flush_done,
     539                 :            :         .eec_software           = sfc_ev_software,
     540                 :            :         .eec_sram               = sfc_ev_sram,
     541                 :            :         .eec_wake_up            = sfc_ev_wake_up,
     542                 :            :         .eec_timer              = sfc_ev_timer,
     543                 :            :         .eec_link_change        = sfc_ev_link_change,
     544                 :            : };
     545                 :            : 
     546                 :            : static const efx_ev_callbacks_t sfc_ev_callbacks_efx_rx = {
     547                 :            :         .eec_initialized        = sfc_ev_initialized,
     548                 :            :         .eec_rx                 = sfc_ev_efx_rx,
     549                 :            :         .eec_rx_packets         = sfc_ev_nop_rx_packets,
     550                 :            :         .eec_rx_ps              = sfc_ev_nop_rx_ps,
     551                 :            :         .eec_tx                 = sfc_ev_nop_tx,
     552                 :            :         .eec_tx_ndescs          = sfc_ev_nop_tx_ndescs,
     553                 :            :         .eec_exception          = sfc_ev_exception,
     554                 :            :         .eec_rxq_flush_done     = sfc_ev_rxq_flush_done,
     555                 :            :         .eec_rxq_flush_failed   = sfc_ev_rxq_flush_failed,
     556                 :            :         .eec_txq_flush_done     = sfc_ev_nop_txq_flush_done,
     557                 :            :         .eec_software           = sfc_ev_software,
     558                 :            :         .eec_sram               = sfc_ev_sram,
     559                 :            :         .eec_wake_up            = sfc_ev_wake_up,
     560                 :            :         .eec_timer              = sfc_ev_timer,
     561                 :            :         .eec_link_change        = sfc_ev_nop_link_change,
     562                 :            : };
     563                 :            : 
     564                 :            : static const efx_ev_callbacks_t sfc_ev_callbacks_dp_rx = {
     565                 :            :         .eec_initialized        = sfc_ev_initialized,
     566                 :            :         .eec_rx                 = sfc_ev_dp_rx,
     567                 :            :         .eec_rx_packets         = sfc_ev_dp_rx_packets,
     568                 :            :         .eec_rx_ps              = sfc_ev_dp_rx_ps,
     569                 :            :         .eec_tx                 = sfc_ev_nop_tx,
     570                 :            :         .eec_tx_ndescs          = sfc_ev_nop_tx_ndescs,
     571                 :            :         .eec_exception          = sfc_ev_exception,
     572                 :            :         .eec_rxq_flush_done     = sfc_ev_rxq_flush_done,
     573                 :            :         .eec_rxq_flush_failed   = sfc_ev_rxq_flush_failed,
     574                 :            :         .eec_txq_flush_done     = sfc_ev_nop_txq_flush_done,
     575                 :            :         .eec_software           = sfc_ev_software,
     576                 :            :         .eec_sram               = sfc_ev_sram,
     577                 :            :         .eec_wake_up            = sfc_ev_wake_up,
     578                 :            :         .eec_timer              = sfc_ev_timer,
     579                 :            :         .eec_link_change        = sfc_ev_nop_link_change,
     580                 :            : };
     581                 :            : 
     582                 :            : static const efx_ev_callbacks_t sfc_ev_callbacks_efx_tx = {
     583                 :            :         .eec_initialized        = sfc_ev_initialized,
     584                 :            :         .eec_rx                 = sfc_ev_nop_rx,
     585                 :            :         .eec_rx_packets         = sfc_ev_nop_rx_packets,
     586                 :            :         .eec_rx_ps              = sfc_ev_nop_rx_ps,
     587                 :            :         .eec_tx                 = sfc_ev_tx,
     588                 :            :         .eec_tx_ndescs          = sfc_ev_nop_tx_ndescs,
     589                 :            :         .eec_exception          = sfc_ev_exception,
     590                 :            :         .eec_rxq_flush_done     = sfc_ev_nop_rxq_flush_done,
     591                 :            :         .eec_rxq_flush_failed   = sfc_ev_nop_rxq_flush_failed,
     592                 :            :         .eec_txq_flush_done     = sfc_ev_txq_flush_done,
     593                 :            :         .eec_software           = sfc_ev_software,
     594                 :            :         .eec_sram               = sfc_ev_sram,
     595                 :            :         .eec_wake_up            = sfc_ev_wake_up,
     596                 :            :         .eec_timer              = sfc_ev_timer,
     597                 :            :         .eec_link_change        = sfc_ev_nop_link_change,
     598                 :            : };
     599                 :            : 
     600                 :            : static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {
     601                 :            :         .eec_initialized        = sfc_ev_initialized,
     602                 :            :         .eec_rx                 = sfc_ev_nop_rx,
     603                 :            :         .eec_rx_packets         = sfc_ev_nop_rx_packets,
     604                 :            :         .eec_rx_ps              = sfc_ev_nop_rx_ps,
     605                 :            :         .eec_tx                 = sfc_ev_dp_tx,
     606                 :            :         .eec_tx_ndescs          = sfc_ev_dp_tx_ndescs,
     607                 :            :         .eec_exception          = sfc_ev_exception,
     608                 :            :         .eec_rxq_flush_done     = sfc_ev_nop_rxq_flush_done,
     609                 :            :         .eec_rxq_flush_failed   = sfc_ev_nop_rxq_flush_failed,
     610                 :            :         .eec_txq_flush_done     = sfc_ev_txq_flush_done,
     611                 :            :         .eec_software           = sfc_ev_software,
     612                 :            :         .eec_sram               = sfc_ev_sram,
     613                 :            :         .eec_wake_up            = sfc_ev_wake_up,
     614                 :            :         .eec_timer              = sfc_ev_timer,
     615                 :            :         .eec_link_change        = sfc_ev_nop_link_change,
     616                 :            : };
     617                 :            : 
     618                 :            : 
     619                 :            : void
     620                 :          0 : sfc_ev_qpoll(struct sfc_evq *evq)
     621                 :            : {
     622                 :            :         struct sfc_adapter *sa;
     623                 :            : 
     624                 :            :         SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED ||
     625                 :            :                    evq->init_state == SFC_EVQ_STARTING);
     626                 :            : 
     627                 :            :         /* Synchronize the DMA memory for reading not required */
     628                 :            : 
     629                 :          0 :         efx_ev_qpoll(evq->common, &evq->read_ptr, evq->callbacks, evq);
     630                 :            : 
     631                 :          0 :         sa = evq->sa;
     632   [ #  #  #  # ]:          0 :         if (unlikely(evq->exception) && sfc_adapter_trylock(sa)) {
     633                 :            :                 int rc;
     634                 :            : 
     635         [ #  # ]:          0 :                 if (evq->dp_rxq != NULL) {
     636                 :            :                         sfc_sw_index_t rxq_sw_index;
     637                 :            : 
     638                 :          0 :                         rxq_sw_index = evq->dp_rxq->dpq.queue_id;
     639                 :            : 
     640                 :          0 :                         sfc_warn(sa,
     641                 :            :                                  "restart RxQ %u because of exception on its EvQ %u",
     642                 :            :                                  rxq_sw_index, evq->evq_index);
     643                 :            : 
     644                 :          0 :                         sfc_rx_qstop(sa, rxq_sw_index);
     645                 :          0 :                         rc = sfc_rx_qstart(sa, rxq_sw_index);
     646         [ #  # ]:          0 :                         if (rc != 0)
     647                 :          0 :                                 sfc_err(sa, "cannot restart RxQ %u",
     648                 :            :                                         rxq_sw_index);
     649                 :            :                 }
     650                 :            : 
     651         [ #  # ]:          0 :                 if (evq->dp_txq != NULL) {
     652                 :            :                         sfc_sw_index_t txq_sw_index;
     653                 :            : 
     654                 :          0 :                         txq_sw_index = evq->dp_txq->dpq.queue_id;
     655                 :            : 
     656                 :          0 :                         sfc_warn(sa,
     657                 :            :                                  "restart TxQ %u because of exception on its EvQ %u",
     658                 :            :                                  txq_sw_index, evq->evq_index);
     659                 :            : 
     660                 :          0 :                         sfc_tx_qstop(sa, txq_sw_index);
     661                 :          0 :                         rc = sfc_tx_qstart(sa, txq_sw_index);
     662         [ #  # ]:          0 :                         if (rc != 0)
     663                 :          0 :                                 sfc_err(sa, "cannot restart TxQ %u",
     664                 :            :                                         txq_sw_index);
     665                 :            :                 }
     666                 :            : 
     667         [ #  # ]:          0 :                 if (evq->exception)
     668                 :          0 :                         sfc_panic(sa, "unrecoverable exception on EvQ %u",
     669                 :            :                                   evq->evq_index);
     670                 :            : 
     671                 :            :                 sfc_adapter_unlock(sa);
     672                 :            :         }
     673                 :            : 
     674                 :            :         /* Poll-mode driver does not re-prime the event queue for interrupts */
     675                 :          0 : }
     676                 :            : 
     677                 :            : void
     678                 :          0 : sfc_ev_mgmt_qpoll(struct sfc_adapter *sa)
     679                 :            : {
     680         [ #  # ]:          0 :         if (rte_spinlock_trylock(&sa->mgmt_evq_lock)) {
     681         [ #  # ]:          0 :                 if (sa->mgmt_evq_running)
     682                 :          0 :                         sfc_ev_qpoll(sa->mgmt_evq);
     683                 :            : 
     684                 :            :                 rte_spinlock_unlock(&sa->mgmt_evq_lock);
     685                 :            :         }
     686                 :          0 : }
     687                 :            : 
     688                 :            : int
     689                 :          0 : sfc_ev_qprime(struct sfc_evq *evq)
     690                 :            : {
     691                 :            :         SFC_ASSERT(evq->init_state == SFC_EVQ_STARTED);
     692                 :          0 :         return efx_ev_qprime(evq->common, evq->read_ptr);
     693                 :            : }
     694                 :            : 
     695                 :            : /* Event queue HW index allocation scheme is described in sfc_ev.h. */
     696                 :            : int
     697                 :          0 : sfc_ev_qstart(struct sfc_evq *evq, unsigned int hw_index)
     698                 :            : {
     699                 :          0 :         struct sfc_adapter *sa = evq->sa;
     700                 :            :         efsys_mem_t *esmp;
     701                 :          0 :         uint32_t evq_flags = sa->evq_flags;
     702                 :            :         uint32_t irq = 0;
     703                 :            :         unsigned int total_delay_us;
     704                 :            :         unsigned int delay_us;
     705                 :            :         int rc;
     706                 :            : 
     707                 :          0 :         sfc_log_init(sa, "hw_index=%u", hw_index);
     708                 :            : 
     709                 :          0 :         esmp = &evq->mem;
     710                 :            : 
     711                 :          0 :         evq->evq_index = hw_index;
     712                 :            : 
     713                 :            :         /* Clear all events */
     714         [ #  # ]:          0 :         (void)memset((void *)esmp->esm_base, 0xff,
     715                 :          0 :                      efx_evq_size(sa->nic, evq->entries, evq_flags));
     716                 :            : 
     717   [ #  #  #  # ]:          0 :         if (sa->intr.lsc_intr && hw_index == sa->mgmt_evq_index) {
     718                 :            :                 evq_flags |= EFX_EVQ_FLAGS_NOTIFY_INTERRUPT;
     719                 :            :                 irq = 0;
     720   [ #  #  #  # ]:          0 :         } else if (sa->intr.rxq_intr && evq->dp_rxq != NULL) {
     721                 :            :                 sfc_ethdev_qid_t ethdev_qid;
     722                 :            : 
     723                 :            :                 ethdev_qid =
     724                 :          0 :                         sfc_ethdev_rx_qid_by_rxq_sw_index(sfc_sa2shared(sa),
     725         [ #  # ]:          0 :                                 evq->dp_rxq->dpq.queue_id);
     726         [ #  # ]:          0 :                 if (ethdev_qid != SFC_ETHDEV_QID_INVALID) {
     727                 :            :                         evq_flags |= EFX_EVQ_FLAGS_NOTIFY_INTERRUPT;
     728                 :            :                         /*
     729                 :            :                          * The first interrupt is used for management EvQ
     730                 :            :                          * (LSC etc). RxQ interrupts follow it.
     731                 :            :                          */
     732                 :          0 :                         irq = 1 + ethdev_qid;
     733                 :            :                 } else {
     734                 :          0 :                         evq_flags |= EFX_EVQ_FLAGS_NOTIFY_DISABLED;
     735                 :            :                 }
     736                 :            :         } else {
     737                 :          0 :                 evq_flags |= EFX_EVQ_FLAGS_NOTIFY_DISABLED;
     738                 :            :         }
     739                 :            : 
     740                 :          0 :         evq->init_state = SFC_EVQ_STARTING;
     741                 :            : 
     742                 :            :         /* Create the common code event queue */
     743                 :          0 :         rc = efx_ev_qcreate_irq(sa->nic, hw_index, esmp, evq->entries,
     744                 :            :                                 0 /* unused on EF10 */, 0, evq_flags,
     745                 :            :                                 irq, &evq->common);
     746         [ #  # ]:          0 :         if (rc != 0)
     747                 :          0 :                 goto fail_ev_qcreate;
     748                 :            : 
     749                 :            :         SFC_ASSERT(evq->dp_rxq == NULL || evq->dp_txq == NULL);
     750         [ #  # ]:          0 :         if (evq->dp_rxq != 0) {
     751         [ #  # ]:          0 :                 if (strcmp(sa->priv.dp_rx->dp.name,
     752                 :            :                            SFC_KVARG_DATAPATH_EFX) == 0)
     753                 :          0 :                         evq->callbacks = &sfc_ev_callbacks_efx_rx;
     754                 :            :                 else
     755                 :          0 :                         evq->callbacks = &sfc_ev_callbacks_dp_rx;
     756         [ #  # ]:          0 :         } else if (evq->dp_txq != 0) {
     757         [ #  # ]:          0 :                 if (strcmp(sa->priv.dp_tx->dp.name,
     758                 :            :                            SFC_KVARG_DATAPATH_EFX) == 0)
     759                 :          0 :                         evq->callbacks = &sfc_ev_callbacks_efx_tx;
     760                 :            :                 else
     761                 :          0 :                         evq->callbacks = &sfc_ev_callbacks_dp_tx;
     762                 :            :         } else {
     763                 :          0 :                 evq->callbacks = &sfc_ev_callbacks;
     764                 :            :         }
     765                 :            : 
     766                 :            :         /*
     767                 :            :          * Poll once to ensure that eec_initialized callback is invoked in
     768                 :            :          * case if the hardware does not support INIT_DONE events. If the
     769                 :            :          * hardware supports INIT_DONE events, this will do nothing, and the
     770                 :            :          * corresponding event will be processed by sfc_ev_qpoll() below.
     771                 :            :          */
     772                 :          0 :         efx_ev_qcreate_check_init_done(evq->common, evq->callbacks, evq);
     773                 :            : 
     774                 :            :         /* Wait for the initialization event */
     775                 :            :         total_delay_us = 0;
     776                 :            :         delay_us = SFC_EVQ_INIT_BACKOFF_START_US;
     777                 :            :         do {
     778                 :          0 :                 (void)sfc_ev_qpoll(evq);
     779                 :            : 
     780                 :            :                 /* Check to see if the initialization complete indication
     781                 :            :                  * posted by the hardware.
     782                 :            :                  */
     783         [ #  # ]:          0 :                 if (evq->init_state == SFC_EVQ_STARTED)
     784                 :          0 :                         goto done;
     785                 :            : 
     786                 :            :                 /* Give event queue some time to init */
     787                 :          0 :                 rte_delay_us(delay_us);
     788                 :            : 
     789                 :          0 :                 total_delay_us += delay_us;
     790                 :            : 
     791                 :            :                 /* Exponential backoff */
     792                 :          0 :                 delay_us *= 2;
     793                 :            :                 if (delay_us > SFC_EVQ_INIT_BACKOFF_MAX_US)
     794                 :            :                         delay_us = SFC_EVQ_INIT_BACKOFF_MAX_US;
     795                 :            : 
     796         [ #  # ]:          0 :         } while (total_delay_us < SFC_EVQ_INIT_TIMEOUT_US);
     797                 :            : 
     798                 :            :         rc = ETIMEDOUT;
     799                 :          0 :         goto fail_timedout;
     800                 :            : 
     801                 :            : done:
     802                 :          0 :         return 0;
     803                 :            : 
     804                 :            : fail_timedout:
     805                 :          0 :         efx_ev_qdestroy(evq->common);
     806                 :            : 
     807                 :          0 : fail_ev_qcreate:
     808                 :          0 :         evq->init_state = SFC_EVQ_INITIALIZED;
     809                 :          0 :         sfc_log_init(sa, "failed %d", rc);
     810                 :          0 :         return rc;
     811                 :            : }
     812                 :            : 
     813                 :            : void
     814                 :          0 : sfc_ev_qstop(struct sfc_evq *evq)
     815                 :            : {
     816         [ #  # ]:          0 :         if (evq == NULL)
     817                 :            :                 return;
     818                 :            : 
     819                 :          0 :         sfc_log_init(evq->sa, "hw_index=%u", evq->evq_index);
     820                 :            : 
     821         [ #  # ]:          0 :         if (evq->init_state != SFC_EVQ_STARTED)
     822                 :            :                 return;
     823                 :            : 
     824                 :          0 :         evq->init_state = SFC_EVQ_INITIALIZED;
     825                 :          0 :         evq->callbacks = NULL;
     826                 :          0 :         evq->read_ptr = 0;
     827                 :          0 :         evq->exception = B_FALSE;
     828                 :            : 
     829                 :          0 :         efx_ev_qdestroy(evq->common);
     830                 :            : 
     831                 :          0 :         evq->evq_index = 0;
     832                 :            : }
     833                 :            : 
     834                 :            : static void
     835                 :          0 : sfc_ev_mgmt_periodic_qpoll(void *arg)
     836                 :            : {
     837                 :            :         struct sfc_adapter *sa = arg;
     838                 :            :         int rc;
     839                 :            : 
     840                 :          0 :         sfc_ev_mgmt_qpoll(sa);
     841                 :            : 
     842                 :          0 :         rc = rte_eal_alarm_set(SFC_MGMT_EV_QPOLL_PERIOD_US,
     843                 :            :                                sfc_ev_mgmt_periodic_qpoll, sa);
     844         [ #  # ]:          0 :         if (rc == -ENOTSUP) {
     845                 :          0 :                 sfc_warn(sa, "alarms are not supported");
     846                 :          0 :                 sfc_warn(sa, "management EVQ must be polled indirectly using no-wait link status update");
     847         [ #  # ]:          0 :         } else if (rc != 0) {
     848                 :          0 :                 sfc_err(sa,
     849                 :            :                         "cannot rearm management EVQ polling alarm (rc=%d)",
     850                 :            :                         rc);
     851                 :            :         }
     852                 :          0 : }
     853                 :            : 
     854                 :            : static void
     855                 :            : sfc_ev_mgmt_periodic_qpoll_start(struct sfc_adapter *sa)
     856                 :            : {
     857                 :          0 :         sfc_ev_mgmt_periodic_qpoll(sa);
     858                 :            : }
     859                 :            : 
     860                 :            : static void
     861                 :            : sfc_ev_mgmt_periodic_qpoll_stop(struct sfc_adapter *sa)
     862                 :            : {
     863                 :          0 :         rte_eal_alarm_cancel(sfc_ev_mgmt_periodic_qpoll, sa);
     864                 :            : }
     865                 :            : 
     866                 :            : int
     867                 :          0 : sfc_ev_start(struct sfc_adapter *sa)
     868                 :            : {
     869                 :            :         int rc;
     870                 :            : 
     871                 :          0 :         sfc_log_init(sa, "entry");
     872                 :            : 
     873                 :          0 :         rc = efx_ev_init(sa->nic);
     874         [ #  # ]:          0 :         if (rc != 0)
     875                 :          0 :                 goto fail_ev_init;
     876                 :            : 
     877                 :            :         /* Start management EVQ used for global events */
     878                 :            : 
     879                 :            :         /*
     880                 :            :          * Management event queue start polls the queue, but it cannot
     881                 :            :          * interfere with other polling contexts since mgmt_evq_running
     882                 :            :          * is false yet.
     883                 :            :          */
     884                 :          0 :         rc = sfc_ev_qstart(sa->mgmt_evq, sa->mgmt_evq_index);
     885         [ #  # ]:          0 :         if (rc != 0)
     886                 :          0 :                 goto fail_mgmt_evq_start;
     887                 :            : 
     888                 :          0 :         rte_spinlock_lock(&sa->mgmt_evq_lock);
     889                 :          0 :         sa->mgmt_evq_running = true;
     890                 :            :         rte_spinlock_unlock(&sa->mgmt_evq_lock);
     891                 :            : 
     892         [ #  # ]:          0 :         if (sa->intr.lsc_intr) {
     893                 :          0 :                 rc = sfc_ev_qprime(sa->mgmt_evq);
     894         [ #  # ]:          0 :                 if (rc != 0)
     895                 :          0 :                         goto fail_mgmt_evq_prime;
     896                 :            :         }
     897                 :            : 
     898                 :            :         /*
     899                 :            :          * Start management EVQ polling. If interrupts are disabled
     900                 :            :          * (not used), it is required to process link status change
     901                 :            :          * and other device level events to avoid unrecoverable
     902                 :            :          * error because the event queue overflow.
     903                 :            :          */
     904                 :            :         sfc_ev_mgmt_periodic_qpoll_start(sa);
     905                 :            : 
     906                 :            :         /*
     907                 :            :          * Rx/Tx event queues are started/stopped when corresponding
     908                 :            :          * Rx/Tx queue is started/stopped.
     909                 :            :          */
     910                 :            : 
     911                 :          0 :         return 0;
     912                 :            : 
     913                 :            : fail_mgmt_evq_prime:
     914                 :          0 :         sfc_ev_qstop(sa->mgmt_evq);
     915                 :            : 
     916                 :          0 : fail_mgmt_evq_start:
     917                 :          0 :         efx_ev_fini(sa->nic);
     918                 :            : 
     919                 :          0 : fail_ev_init:
     920                 :          0 :         sfc_log_init(sa, "failed %d", rc);
     921                 :          0 :         return rc;
     922                 :            : }
     923                 :            : 
     924                 :            : void
     925                 :          0 : sfc_ev_stop(struct sfc_adapter *sa)
     926                 :            : {
     927                 :          0 :         sfc_log_init(sa, "entry");
     928                 :            : 
     929                 :            :         sfc_ev_mgmt_periodic_qpoll_stop(sa);
     930                 :            : 
     931                 :          0 :         rte_spinlock_lock(&sa->mgmt_evq_lock);
     932                 :          0 :         sa->mgmt_evq_running = false;
     933                 :            :         rte_spinlock_unlock(&sa->mgmt_evq_lock);
     934                 :            : 
     935                 :          0 :         sfc_ev_qstop(sa->mgmt_evq);
     936                 :            : 
     937                 :          0 :         efx_ev_fini(sa->nic);
     938                 :          0 : }
     939                 :            : 
     940                 :            : int
     941                 :          0 : sfc_ev_qinit(struct sfc_adapter *sa,
     942                 :            :              enum sfc_evq_type type, unsigned int type_index,
     943                 :            :              unsigned int entries, int socket_id, struct sfc_evq **evqp)
     944                 :            : {
     945                 :            :         struct sfc_evq *evq;
     946                 :            :         int rc;
     947                 :            : 
     948   [ #  #  #  # ]:          0 :         sfc_log_init(sa, "type=%s type_index=%u",
     949                 :            :                      sfc_evq_type2str(type), type_index);
     950                 :            : 
     951                 :            :         SFC_ASSERT(rte_is_power_of_2(entries));
     952                 :            : 
     953                 :            :         rc = ENOMEM;
     954                 :          0 :         evq = rte_zmalloc_socket("sfc-evq", sizeof(*evq), RTE_CACHE_LINE_SIZE,
     955                 :            :                                  socket_id);
     956         [ #  # ]:          0 :         if (evq == NULL)
     957                 :          0 :                 goto fail_evq_alloc;
     958                 :            : 
     959                 :          0 :         evq->sa = sa;
     960                 :          0 :         evq->type = type;
     961                 :          0 :         evq->entries = entries;
     962                 :            : 
     963                 :            :         /* Allocate DMA space */
     964   [ #  #  #  # ]:          0 :         rc = sfc_dma_alloc(sa, sfc_evq_type2str(type), type_index,
     965                 :            :                            EFX_NIC_DMA_ADDR_EVENT_RING,
     966                 :          0 :                            efx_evq_size(sa->nic, evq->entries, sa->evq_flags),
     967                 :            :                            socket_id, &evq->mem);
     968         [ #  # ]:          0 :         if (rc != 0)
     969                 :          0 :                 goto fail_dma_alloc;
     970                 :            : 
     971                 :          0 :         evq->init_state = SFC_EVQ_INITIALIZED;
     972                 :            : 
     973                 :          0 :         sa->evq_count++;
     974                 :            : 
     975                 :          0 :         *evqp = evq;
     976                 :            : 
     977                 :          0 :         return 0;
     978                 :            : 
     979                 :            : fail_dma_alloc:
     980                 :          0 :         rte_free(evq);
     981                 :            : 
     982                 :          0 : fail_evq_alloc:
     983                 :            : 
     984                 :          0 :         sfc_log_init(sa, "failed %d", rc);
     985                 :          0 :         return rc;
     986                 :            : }
     987                 :            : 
     988                 :            : void
     989                 :          0 : sfc_ev_qfini(struct sfc_evq *evq)
     990                 :            : {
     991                 :          0 :         struct sfc_adapter *sa = evq->sa;
     992                 :            : 
     993                 :            :         SFC_ASSERT(evq->init_state == SFC_EVQ_INITIALIZED);
     994                 :            : 
     995                 :          0 :         sfc_dma_free(sa, &evq->mem);
     996                 :            : 
     997                 :          0 :         rte_free(evq);
     998                 :            : 
     999                 :            :         SFC_ASSERT(sa->evq_count > 0);
    1000                 :          0 :         sa->evq_count--;
    1001                 :          0 : }
    1002                 :            : 
    1003                 :            : static int
    1004                 :          0 : sfc_kvarg_perf_profile_handler(__rte_unused const char *key,
    1005                 :            :                                const char *value_str, void *opaque)
    1006                 :            : {
    1007                 :            :         uint32_t *value = opaque;
    1008                 :            : 
    1009         [ #  # ]:          0 :         if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_THROUGHPUT) == 0)
    1010                 :          0 :                 *value = EFX_EVQ_FLAGS_TYPE_THROUGHPUT;
    1011         [ #  # ]:          0 :         else if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_LOW_LATENCY) == 0)
    1012                 :          0 :                 *value = EFX_EVQ_FLAGS_TYPE_LOW_LATENCY;
    1013         [ #  # ]:          0 :         else if (strcasecmp(value_str, SFC_KVARG_PERF_PROFILE_AUTO) == 0)
    1014                 :          0 :                 *value = EFX_EVQ_FLAGS_TYPE_AUTO;
    1015                 :            :         else
    1016                 :            :                 return -EINVAL;
    1017                 :            : 
    1018                 :            :         return 0;
    1019                 :            : }
    1020                 :            : 
    1021                 :            : int
    1022                 :          0 : sfc_ev_attach(struct sfc_adapter *sa)
    1023                 :            : {
    1024                 :            :         int rc;
    1025                 :            : 
    1026                 :          0 :         sfc_log_init(sa, "entry");
    1027                 :            : 
    1028                 :          0 :         sa->evq_flags = EFX_EVQ_FLAGS_TYPE_THROUGHPUT;
    1029                 :          0 :         rc = sfc_kvargs_process(sa, SFC_KVARG_PERF_PROFILE,
    1030                 :            :                                 sfc_kvarg_perf_profile_handler,
    1031                 :          0 :                                 &sa->evq_flags);
    1032         [ #  # ]:          0 :         if (rc != 0) {
    1033                 :          0 :                 sfc_err(sa, "invalid %s parameter value",
    1034                 :            :                         SFC_KVARG_PERF_PROFILE);
    1035                 :          0 :                 goto fail_kvarg_perf_profile;
    1036                 :            :         }
    1037                 :            : 
    1038                 :          0 :         sa->mgmt_evq_index = sfc_mgmt_evq_sw_index(sfc_sa2shared(sa));
    1039                 :            :         rte_spinlock_init(&sa->mgmt_evq_lock);
    1040                 :            : 
    1041                 :          0 :         rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_MGMT, 0, sa->evq_min_entries,
    1042                 :            :                           sa->socket_id, &sa->mgmt_evq);
    1043         [ #  # ]:          0 :         if (rc != 0)
    1044                 :          0 :                 goto fail_mgmt_evq_init;
    1045                 :            : 
    1046                 :            :         /*
    1047                 :            :          * Rx/Tx event queues are created/destroyed when corresponding
    1048                 :            :          * Rx/Tx queue is created/destroyed.
    1049                 :            :          */
    1050                 :            : 
    1051                 :            :         return 0;
    1052                 :            : 
    1053                 :            : fail_mgmt_evq_init:
    1054                 :            : 
    1055                 :          0 : fail_kvarg_perf_profile:
    1056                 :          0 :         sfc_log_init(sa, "failed %d", rc);
    1057                 :          0 :         return rc;
    1058                 :            : }
    1059                 :            : 
    1060                 :            : void
    1061                 :          0 : sfc_ev_detach(struct sfc_adapter *sa)
    1062                 :            : {
    1063                 :          0 :         sfc_log_init(sa, "entry");
    1064                 :            : 
    1065                 :          0 :         sfc_ev_qfini(sa->mgmt_evq);
    1066                 :            : 
    1067         [ #  # ]:          0 :         if (sa->evq_count != 0)
    1068                 :          0 :                 sfc_err(sa, "%u EvQs are not destroyed before detach",
    1069                 :            :                         sa->evq_count);
    1070                 :          0 : }

Generated by: LCOV version 1.14