app/eventdev: add ethernet device setup helpers
[dpdk.git] / drivers / net / mrvl / mrvl_ethdev.c
index 5c3b700..4294c56 100644 (file)
@@ -150,21 +150,18 @@ struct mrvl_txq {
        int queue_id;
        int port_id;
        uint64_t bytes_sent;
+       struct mrvl_shadow_txq shadow_txqs[RTE_MAX_LCORE];
 };
 
-/*
- * Every tx queue should have dedicated shadow tx queue.
- *
- * Ports assigned by DPDK might not start at zero or be continuous so
- * as a workaround define shadow queues for each possible port so that
- * we eventually fit somewhere.
- */
-struct mrvl_shadow_txq shadow_txqs[RTE_MAX_ETHPORTS][RTE_MAX_LCORE];
-
 static int mrvl_lcore_first;
 static int mrvl_lcore_last;
 static int mrvl_dev_num;
 
+static int mrvl_fill_bpool(struct mrvl_rxq *rxq, int num);
+static inline void mrvl_free_sent_buffers(struct pp2_ppio *ppio,
+                       struct pp2_hif *hif, unsigned int core_id,
+                       struct mrvl_shadow_txq *sq, int qid, int force);
+
 static inline int
 mrvl_get_bpool_size(int pp2_id, int pool_id)
 {
@@ -461,19 +458,12 @@ mrvl_dev_start(struct rte_eth_dev *dev)
 {
        struct mrvl_priv *priv = dev->data->dev_private;
        char match[MRVL_MATCH_LEN];
-       int ret;
+       int ret = 0, def_init_size;
 
        snprintf(match, sizeof(match), "ppio-%d:%d",
                 priv->pp_id, priv->ppio_id);
        priv->ppio_params.match = match;
 
-       /*
-        * Calculate the maximum bpool size for refill feature to 1.5 of the
-        * configured size. In case the bpool size will exceed this value,
-        * superfluous buffers will be removed
-        */
-       priv->bpool_max_size = priv->bpool_init_size +
-                             (priv->bpool_init_size >> 1);
        /*
         * Calculate the minimum bpool size for refill feature as follows:
         * 2 default burst sizes multiply by number of rx queues.
@@ -482,6 +472,29 @@ mrvl_dev_start(struct rte_eth_dev *dev)
         */
        priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
 
+       /* In case initial bpool size configured in queues setup is
+        * smaller than minimum size add more buffers
+        */
+       def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2;
+       if (priv->bpool_init_size < def_init_size) {
+               int buffs_to_add = def_init_size - priv->bpool_init_size;
+
+               priv->bpool_init_size += buffs_to_add;
+               ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add);
+               if (ret)
+                       RTE_LOG(ERR, PMD, "Failed to add buffers to bpool\n");
+       }
+
+       /*
+        * Calculate the maximum bpool size for refill feature as follows:
+        * maximum number of descriptors in rx queue multiply by number
+        * of rx queues plus minimum bpool size.
+        * In case the bpool size will exceed this value, superfluous buffers
+        * will be removed
+        */
+       priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) +
+                               priv->bpool_min_size;
+
        ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
        if (ret) {
                RTE_LOG(ERR, PMD, "Failed to init ppio\n");
@@ -576,21 +589,32 @@ mrvl_flush_rx_queues(struct rte_eth_dev *dev)
 static void
 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev)
 {
-       int i;
+       int i, j;
+       struct mrvl_txq *txq;
 
        RTE_LOG(INFO, PMD, "Flushing tx shadow queues\n");
-       for (i = 0; i < RTE_MAX_LCORE; i++) {
-               struct mrvl_shadow_txq *sq =
-                       &shadow_txqs[dev->data->port_id][i];
+       for (i = 0; i < dev->data->nb_tx_queues; i++) {
+               txq = (struct mrvl_txq *)dev->data->tx_queues[i];
+
+               for (j = 0; j < RTE_MAX_LCORE; j++) {
+                       struct mrvl_shadow_txq *sq;
+
+                       if (!hifs[j])
+                               continue;
 
-               while (sq->tail != sq->head) {
-                       uint64_t addr = cookie_addr_high |
+                       sq = &txq->shadow_txqs[j];
+                       mrvl_free_sent_buffers(txq->priv->ppio,
+                               hifs[j], j, sq, txq->queue_id, 1);
+                       while (sq->tail != sq->head) {
+                               uint64_t addr = cookie_addr_high |
                                        sq->ent[sq->tail].buff.cookie;
-                       rte_pktmbuf_free((struct rte_mbuf *)addr);
-                       sq->tail = (sq->tail + 1) & MRVL_PP2_TX_SHADOWQ_MASK;
+                               rte_pktmbuf_free(
+                                       (struct rte_mbuf *)addr);
+                               sq->tail = (sq->tail + 1) &
+                                           MRVL_PP2_TX_SHADOWQ_MASK;
+                       }
+                       memset(sq, 0, sizeof(*sq));
                }
-
-               memset(sq, 0, sizeof(*sq));
        }
 }
 
@@ -1769,14 +1793,15 @@ mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                                q->priv->bpool_init_size);
 
                        for (i = 0; i < pkt_to_remove; i++) {
-                               pp2_bpool_get_buff(hif, bpool, &buff);
+                               ret = pp2_bpool_get_buff(hif, bpool, &buff);
+                               if (ret)
+                                       break;
                                mbuf = (struct rte_mbuf *)
                                        (cookie_addr_high | buff.cookie);
                                rte_pktmbuf_free(mbuf);
                        }
                        mrvl_port_bpool_size
-                               [bpool->pp2_id][bpool->id][core_id] -=
-                                                               pkt_to_remove;
+                               [bpool->pp2_id][bpool->id][core_id] -= i;
                }
                rte_spinlock_unlock(&q->priv->lock);
        }
@@ -1913,6 +1938,7 @@ skip:
                sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
                sq->size -= num;
                num = 0;
+               skip_bufs = 0;
        }
 
        if (likely(num)) {
@@ -1939,7 +1965,7 @@ static uint16_t
 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 {
        struct mrvl_txq *q = txq;
-       struct mrvl_shadow_txq *sq = &shadow_txqs[q->port_id][rte_lcore_id()];
+       struct mrvl_shadow_txq *sq;
        struct pp2_hif *hif;
        struct pp2_ppio_desc descs[nb_pkts];
        unsigned int core_id = rte_lcore_id();
@@ -1948,6 +1974,7 @@ mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
        uint64_t addr;
 
        hif = mrvl_get_hif(q->priv, core_id);
+       sq = &q->shadow_txqs[core_id];
 
        if (unlikely(!q->priv->ppio || !hif))
                return 0;