net/sfc: factor out libefx-based Rx datapath
[dpdk.git] / drivers / net / sfc / sfc_ev.c
index fe6de6f..c6b02f2 100644 (file)
@@ -1,5 +1,7 @@
 /*-
- * Copyright (c) 2016 Solarflare Communications Inc.
+ *   BSD LICENSE
+ *
+ * Copyright (c) 2016-2017 Solarflare Communications Inc.
  * All rights reserved.
  *
  * This software was jointly developed between OKTET Labs (under contract
@@ -69,25 +71,37 @@ sfc_ev_initialized(void *arg)
 }
 
 static boolean_t
-sfc_ev_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
-         uint32_t size, uint16_t flags)
+sfc_ev_nop_rx(void *arg, uint32_t label, uint32_t id,
+             uint32_t size, uint16_t flags)
 {
        struct sfc_evq *evq = arg;
-       struct sfc_rxq *rxq;
+
+       sfc_err(evq->sa,
+               "EVQ %u unexpected Rx event label=%u id=%#x size=%u flags=%#x",
+               evq->evq_index, label, id, size, flags);
+       return B_TRUE;
+}
+
+static boolean_t
+sfc_ev_efx_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
+             uint32_t size, uint16_t flags)
+{
+       struct sfc_evq *evq = arg;
+       struct sfc_efx_rxq *rxq;
        unsigned int stop;
        unsigned int pending_id;
        unsigned int delta;
        unsigned int i;
-       struct sfc_rx_sw_desc *rxd;
+       struct sfc_efx_rx_sw_desc *rxd;
 
        if (unlikely(evq->exception))
                goto done;
 
-       rxq = evq->rxq;
+       rxq = sfc_efx_rxq_by_dp_rxq(evq->dp_rxq);
 
        SFC_ASSERT(rxq != NULL);
        SFC_ASSERT(rxq->evq == evq);
-       SFC_ASSERT(rxq->state & SFC_RXQ_STARTED);
+       SFC_ASSERT(rxq->flags & SFC_EFX_RXQ_FLAG_STARTED);
 
        stop = (id + 1) & rxq->ptr_mask;
        pending_id = rxq->pending & rxq->ptr_mask;
@@ -104,8 +118,8 @@ sfc_ev_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
                        evq->exception = B_TRUE;
                        sfc_err(evq->sa,
                                "EVQ %u RxQ %u invalid RX abort "
-                               "(id=%#x size=%u flags=%#x); needs restart\n",
-                               evq->evq_index, sfc_rxq_sw_index(rxq),
+                               "(id=%#x size=%u flags=%#x); needs restart",
+                               evq->evq_index, rxq->dp.dpq.queue_id,
                                id, size, flags);
                        goto done;
                }
@@ -119,9 +133,9 @@ sfc_ev_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
 
                sfc_err(evq->sa,
                        "EVQ %u RxQ %u completion out of order "
-                       "(id=%#x delta=%u flags=%#x); needs restart\n",
-                       evq->evq_index, sfc_rxq_sw_index(rxq), id, delta,
-                       flags);
+                       "(id=%#x delta=%u flags=%#x); needs restart",
+                       evq->evq_index, rxq->dp.dpq.queue_id,
+                       id, delta, flags);
 
                goto done;
        }
@@ -141,6 +155,16 @@ done:
        return B_FALSE;
 }
 
+static boolean_t
+sfc_ev_nop_tx(void *arg, uint32_t label, uint32_t id)
+{
+       struct sfc_evq *evq = arg;
+
+       sfc_err(evq->sa, "EVQ %u unexpected Tx event label=%u id=%#x",
+               evq->evq_index, label, id);
+       return B_TRUE;
+}
+
 static boolean_t
 sfc_ev_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
 {
@@ -195,13 +219,27 @@ sfc_ev_exception(void *arg, __rte_unused uint32_t code,
        return B_TRUE;
 }
 
+static boolean_t
+sfc_ev_nop_rxq_flush_done(void *arg, uint32_t rxq_hw_index)
+{
+       struct sfc_evq *evq = arg;
+
+       sfc_err(evq->sa, "EVQ %u unexpected RxQ %u flush done",
+               evq->evq_index, rxq_hw_index);
+       return B_TRUE;
+}
+
 static boolean_t
 sfc_ev_rxq_flush_done(void *arg, __rte_unused uint32_t rxq_hw_index)
 {
        struct sfc_evq *evq = arg;
+       struct sfc_dp_rxq *dp_rxq;
        struct sfc_rxq *rxq;
 
-       rxq = evq->rxq;
+       dp_rxq = evq->dp_rxq;
+       SFC_ASSERT(dp_rxq != NULL);
+
+       rxq = sfc_rxq_by_dp_rxq(dp_rxq);
        SFC_ASSERT(rxq != NULL);
        SFC_ASSERT(rxq->hw_index == rxq_hw_index);
        SFC_ASSERT(rxq->evq == evq);
@@ -210,13 +248,27 @@ sfc_ev_rxq_flush_done(void *arg, __rte_unused uint32_t rxq_hw_index)
        return B_FALSE;
 }
 
+static boolean_t
+sfc_ev_nop_rxq_flush_failed(void *arg, uint32_t rxq_hw_index)
+{
+       struct sfc_evq *evq = arg;
+
+       sfc_err(evq->sa, "EVQ %u unexpected RxQ %u flush failed",
+               evq->evq_index, rxq_hw_index);
+       return B_TRUE;
+}
+
 static boolean_t
 sfc_ev_rxq_flush_failed(void *arg, __rte_unused uint32_t rxq_hw_index)
 {
        struct sfc_evq *evq = arg;
+       struct sfc_dp_rxq *dp_rxq;
        struct sfc_rxq *rxq;
 
-       rxq = evq->rxq;
+       dp_rxq = evq->dp_rxq;
+       SFC_ASSERT(dp_rxq != NULL);
+
+       rxq = sfc_rxq_by_dp_rxq(dp_rxq);
        SFC_ASSERT(rxq != NULL);
        SFC_ASSERT(rxq->hw_index == rxq_hw_index);
        SFC_ASSERT(rxq->evq == evq);
@@ -225,6 +277,16 @@ sfc_ev_rxq_flush_failed(void *arg, __rte_unused uint32_t rxq_hw_index)
        return B_FALSE;
 }
 
+static boolean_t
+sfc_ev_nop_txq_flush_done(void *arg, uint32_t txq_hw_index)
+{
+       struct sfc_evq *evq = arg;
+
+       sfc_err(evq->sa, "EVQ %u unexpected TxQ %u flush done",
+               evq->evq_index, txq_hw_index);
+       return B_TRUE;
+}
+
 static boolean_t
 sfc_ev_txq_flush_done(void *arg, __rte_unused uint32_t txq_hw_index)
 {
@@ -280,6 +342,16 @@ sfc_ev_timer(void *arg, uint32_t index)
        return B_TRUE;
 }
 
+static boolean_t
+sfc_ev_nop_link_change(void *arg, __rte_unused efx_link_mode_t link_mode)
+{
+       struct sfc_evq *evq = arg;
+
+       sfc_err(evq->sa, "EVQ %u unexpected link change event",
+               evq->evq_index);
+       return B_TRUE;
+}
+
 static boolean_t
 sfc_ev_link_change(void *arg, efx_link_mode_t link_mode)
 {
@@ -312,17 +384,62 @@ sfc_ev_link_change(void *arg, efx_link_mode_t link_mode)
 
 static const efx_ev_callbacks_t sfc_ev_callbacks = {
        .eec_initialized        = sfc_ev_initialized,
-       .eec_rx                 = sfc_ev_rx,
-       .eec_tx                 = sfc_ev_tx,
+       .eec_rx                 = sfc_ev_nop_rx,
+       .eec_tx                 = sfc_ev_nop_tx,
+       .eec_exception          = sfc_ev_exception,
+       .eec_rxq_flush_done     = sfc_ev_nop_rxq_flush_done,
+       .eec_rxq_flush_failed   = sfc_ev_nop_rxq_flush_failed,
+       .eec_txq_flush_done     = sfc_ev_nop_txq_flush_done,
+       .eec_software           = sfc_ev_software,
+       .eec_sram               = sfc_ev_sram,
+       .eec_wake_up            = sfc_ev_wake_up,
+       .eec_timer              = sfc_ev_timer,
+       .eec_link_change        = sfc_ev_link_change,
+};
+
+static const efx_ev_callbacks_t sfc_ev_callbacks_efx_rx = {
+       .eec_initialized        = sfc_ev_initialized,
+       .eec_rx                 = sfc_ev_efx_rx,
+       .eec_tx                 = sfc_ev_nop_tx,
        .eec_exception          = sfc_ev_exception,
        .eec_rxq_flush_done     = sfc_ev_rxq_flush_done,
        .eec_rxq_flush_failed   = sfc_ev_rxq_flush_failed,
+       .eec_txq_flush_done     = sfc_ev_nop_txq_flush_done,
+       .eec_software           = sfc_ev_software,
+       .eec_sram               = sfc_ev_sram,
+       .eec_wake_up            = sfc_ev_wake_up,
+       .eec_timer              = sfc_ev_timer,
+       .eec_link_change        = sfc_ev_nop_link_change,
+};
+
+static const efx_ev_callbacks_t sfc_ev_callbacks_dp_rx = {
+       .eec_initialized        = sfc_ev_initialized,
+       .eec_rx                 = sfc_ev_nop_rx,
+       .eec_tx                 = sfc_ev_nop_tx,
+       .eec_exception          = sfc_ev_exception,
+       .eec_rxq_flush_done     = sfc_ev_rxq_flush_done,
+       .eec_rxq_flush_failed   = sfc_ev_rxq_flush_failed,
+       .eec_txq_flush_done     = sfc_ev_nop_txq_flush_done,
+       .eec_software           = sfc_ev_software,
+       .eec_sram               = sfc_ev_sram,
+       .eec_wake_up            = sfc_ev_wake_up,
+       .eec_timer              = sfc_ev_timer,
+       .eec_link_change        = sfc_ev_nop_link_change,
+};
+
+static const efx_ev_callbacks_t sfc_ev_callbacks_tx = {
+       .eec_initialized        = sfc_ev_initialized,
+       .eec_rx                 = sfc_ev_nop_rx,
+       .eec_tx                 = sfc_ev_tx,
+       .eec_exception          = sfc_ev_exception,
+       .eec_rxq_flush_done     = sfc_ev_nop_rxq_flush_done,
+       .eec_rxq_flush_failed   = sfc_ev_nop_rxq_flush_failed,
        .eec_txq_flush_done     = sfc_ev_txq_flush_done,
        .eec_software           = sfc_ev_software,
        .eec_sram               = sfc_ev_sram,
        .eec_wake_up            = sfc_ev_wake_up,
        .eec_timer              = sfc_ev_timer,
-       .eec_link_change        = sfc_ev_link_change,
+       .eec_link_change        = sfc_ev_nop_link_change,
 };
 
 
@@ -334,14 +451,16 @@ sfc_ev_qpoll(struct sfc_evq *evq)
 
        /* Synchronize the DMA memory for reading not required */
 
-       efx_ev_qpoll(evq->common, &evq->read_ptr, &sfc_ev_callbacks, evq);
+       efx_ev_qpoll(evq->common, &evq->read_ptr, evq->callbacks, evq);
 
        if (unlikely(evq->exception) && sfc_adapter_trylock(evq->sa)) {
                struct sfc_adapter *sa = evq->sa;
                int rc;
 
-               if ((evq->rxq != NULL) && (evq->rxq->state & SFC_RXQ_RUNNING)) {
-                       unsigned int rxq_sw_index = sfc_rxq_sw_index(evq->rxq);
+               if (evq->dp_rxq != NULL) {
+                       unsigned int rxq_sw_index;
+
+                       rxq_sw_index = evq->dp_rxq->dpq.queue_id;
 
                        sfc_warn(sa,
                                 "restart RxQ %u because of exception on its EvQ %u",
@@ -425,6 +544,18 @@ sfc_ev_qstart(struct sfc_adapter *sa, unsigned int sw_index)
        if (rc != 0)
                goto fail_ev_qcreate;
 
+       SFC_ASSERT(evq->dp_rxq == NULL || evq->txq == NULL);
+       if (evq->dp_rxq != 0) {
+               if (strcmp(sa->dp_rx->dp.name, SFC_KVARG_DATAPATH_EFX) == 0)
+                       evq->callbacks = &sfc_ev_callbacks_efx_rx;
+               else
+                       evq->callbacks = &sfc_ev_callbacks_dp_rx;
+       } else if (evq->txq != 0) {
+               evq->callbacks = &sfc_ev_callbacks_tx;
+       } else {
+               evq->callbacks = &sfc_ev_callbacks;
+       }
+
        evq->init_state = SFC_EVQ_STARTING;
 
        /* Wait for the initialization event */
@@ -483,6 +614,7 @@ sfc_ev_qstop(struct sfc_adapter *sa, unsigned int sw_index)
                return;
 
        evq->init_state = SFC_EVQ_INITIALIZED;
+       evq->callbacks = NULL;
        evq->read_ptr = 0;
        evq->exception = B_FALSE;