net/sfc: fix leak if EvQ DMA space allocation fails
[dpdk.git] / drivers / net / sfc / sfc_ev.c
index bb22001..800b08e 100644 (file)
@@ -83,25 +83,25 @@ sfc_ev_nop_rx(void *arg, uint32_t label, uint32_t id,
 }
 
 static boolean_t
-sfc_ev_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
-         uint32_t size, uint16_t flags)
+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_rxq *rxq;
+       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;
@@ -119,7 +119,7 @@ sfc_ev_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
                        sfc_err(evq->sa,
                                "EVQ %u RxQ %u invalid RX abort "
                                "(id=%#x size=%u flags=%#x); needs restart",
-                               evq->evq_index, sfc_rxq_sw_index(rxq),
+                               evq->evq_index, rxq->dp.dpq.queue_id,
                                id, size, flags);
                        goto done;
                }
@@ -134,8 +134,8 @@ 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",
-                       evq->evq_index, sfc_rxq_sw_index(rxq), id, delta,
-                       flags);
+                       evq->evq_index, rxq->dp.dpq.queue_id,
+                       id, delta, flags);
 
                goto done;
        }
@@ -155,6 +155,20 @@ done:
        return B_FALSE;
 }
 
+static boolean_t
+sfc_ev_dp_rx(void *arg, __rte_unused uint32_t label, uint32_t id,
+            __rte_unused uint32_t size, __rte_unused uint16_t flags)
+{
+       struct sfc_evq *evq = arg;
+       struct sfc_dp_rxq *dp_rxq;
+
+       dp_rxq = evq->dp_rxq;
+       SFC_ASSERT(dp_rxq != NULL);
+
+       SFC_ASSERT(evq->sa->dp_rx->qrx_ev != NULL);
+       return evq->sa->dp_rx->qrx_ev(dp_rxq, id);
+}
+
 static boolean_t
 sfc_ev_nop_tx(void *arg, uint32_t label, uint32_t id)
 {
@@ -169,16 +183,18 @@ static boolean_t
 sfc_ev_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
 {
        struct sfc_evq *evq = arg;
-       struct sfc_txq *txq;
+       struct sfc_dp_txq *dp_txq;
+       struct sfc_efx_txq *txq;
        unsigned int stop;
        unsigned int delta;
 
-       txq = evq->txq;
+       dp_txq = evq->dp_txq;
+       SFC_ASSERT(dp_txq != NULL);
 
-       SFC_ASSERT(txq != NULL);
+       txq = sfc_efx_txq_by_dp_txq(dp_txq);
        SFC_ASSERT(txq->evq == evq);
 
-       if (unlikely((txq->state & SFC_TXQ_STARTED) == 0))
+       if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_STARTED) == 0))
                goto done;
 
        stop = (id + 1) & txq->ptr_mask;
@@ -192,6 +208,19 @@ done:
        return B_FALSE;
 }
 
+static boolean_t
+sfc_ev_dp_tx(void *arg, __rte_unused uint32_t label, uint32_t id)
+{
+       struct sfc_evq *evq = arg;
+       struct sfc_dp_txq *dp_txq;
+
+       dp_txq = evq->dp_txq;
+       SFC_ASSERT(dp_txq != NULL);
+
+       SFC_ASSERT(evq->sa->dp_tx->qtx_ev != NULL);
+       return evq->sa->dp_tx->qtx_ev(dp_txq, id);
+}
+
 static boolean_t
 sfc_ev_exception(void *arg, __rte_unused uint32_t code,
                 __rte_unused uint32_t data)
@@ -233,9 +262,13 @@ 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);
@@ -258,9 +291,13 @@ 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);
@@ -283,9 +320,13 @@ static boolean_t
 sfc_ev_txq_flush_done(void *arg, __rte_unused uint32_t txq_hw_index)
 {
        struct sfc_evq *evq = arg;
+       struct sfc_dp_txq *dp_txq;
        struct sfc_txq *txq;
 
-       txq = evq->txq;
+       dp_txq = evq->dp_txq;
+       SFC_ASSERT(dp_txq != NULL);
+
+       txq = sfc_txq_by_dp_txq(dp_txq);
        SFC_ASSERT(txq != NULL);
        SFC_ASSERT(txq->hw_index == txq_hw_index);
        SFC_ASSERT(txq->evq == evq);
@@ -389,9 +430,24 @@ static const efx_ev_callbacks_t sfc_ev_callbacks = {
        .eec_link_change        = sfc_ev_link_change,
 };
 
-static const efx_ev_callbacks_t sfc_ev_callbacks_rx = {
+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_rx,
+       .eec_rx                 = sfc_ev_dp_rx,
        .eec_tx                 = sfc_ev_nop_tx,
        .eec_exception          = sfc_ev_exception,
        .eec_rxq_flush_done     = sfc_ev_rxq_flush_done,
@@ -404,7 +460,7 @@ static const efx_ev_callbacks_t sfc_ev_callbacks_rx = {
        .eec_link_change        = sfc_ev_nop_link_change,
 };
 
-static const efx_ev_callbacks_t sfc_ev_callbacks_tx = {
+static const efx_ev_callbacks_t sfc_ev_callbacks_efx_tx = {
        .eec_initialized        = sfc_ev_initialized,
        .eec_rx                 = sfc_ev_nop_rx,
        .eec_tx                 = sfc_ev_tx,
@@ -419,6 +475,21 @@ static const efx_ev_callbacks_t sfc_ev_callbacks_tx = {
        .eec_link_change        = sfc_ev_nop_link_change,
 };
 
+static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {
+       .eec_initialized        = sfc_ev_initialized,
+       .eec_rx                 = sfc_ev_nop_rx,
+       .eec_tx                 = sfc_ev_dp_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_nop_link_change,
+};
+
 
 void
 sfc_ev_qpoll(struct sfc_evq *evq)
@@ -434,8 +505,10 @@ sfc_ev_qpoll(struct sfc_evq *evq)
                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",
@@ -448,8 +521,10 @@ sfc_ev_qpoll(struct sfc_evq *evq)
                                        rxq_sw_index);
                }
 
-               if (evq->txq != NULL) {
-                       unsigned int txq_sw_index = sfc_txq_sw_index(evq->txq);
+               if (evq->dp_txq != NULL) {
+                       unsigned int txq_sw_index;
+
+                       txq_sw_index = evq->dp_txq->dpq.queue_id;
 
                        sfc_warn(sa,
                                 "restart TxQ %u because of exception on its EvQ %u",
@@ -519,13 +594,20 @@ sfc_ev_qstart(struct sfc_adapter *sa, unsigned int sw_index)
        if (rc != 0)
                goto fail_ev_qcreate;
 
-       SFC_ASSERT(evq->rxq == NULL || evq->txq == NULL);
-       if (evq->rxq != 0)
-               evq->callbacks = &sfc_ev_callbacks_rx;
-       else if (evq->txq != 0)
-               evq->callbacks = &sfc_ev_callbacks_tx;
-       else
+       SFC_ASSERT(evq->dp_rxq == NULL || evq->dp_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->dp_txq != 0) {
+               if (strcmp(sa->dp_tx->dp.name, SFC_KVARG_DATAPATH_EFX) == 0)
+                       evq->callbacks = &sfc_ev_callbacks_efx_tx;
+               else
+                       evq->callbacks = &sfc_ev_callbacks_dp_tx;
+       } else {
                evq->callbacks = &sfc_ev_callbacks;
+       }
 
        evq->init_state = SFC_EVQ_STARTING;
 
@@ -718,10 +800,11 @@ sfc_ev_qinit(struct sfc_adapter *sa, unsigned int sw_index,
        SFC_ASSERT(entries <= evq_info->max_entries);
        evq_info->entries = entries;
 
+       rc = ENOMEM;
        evq = rte_zmalloc_socket("sfc-evq", sizeof(*evq), RTE_CACHE_LINE_SIZE,
                                 socket_id);
        if (evq == NULL)
-               return ENOMEM;
+               goto fail_evq_alloc;
 
        evq->sa = sa;
        evq->evq_index = sw_index;
@@ -730,13 +813,21 @@ sfc_ev_qinit(struct sfc_adapter *sa, unsigned int sw_index,
        rc = sfc_dma_alloc(sa, "evq", sw_index, EFX_EVQ_SIZE(evq_info->entries),
                           socket_id, &evq->mem);
        if (rc != 0)
-               return rc;
+               goto fail_dma_alloc;
 
        evq->init_state = SFC_EVQ_INITIALIZED;
 
        evq_info->evq = evq;
 
        return 0;
+
+fail_dma_alloc:
+       rte_free(evq);
+
+fail_evq_alloc:
+
+       sfc_log_init(sa, "failed %d", rc);
+       return rc;
 }
 
 void