New upstream version 16.11.3
[deb_dpdk.git] / drivers / net / ena / ena_ethdev.c
index ab9a178..6efe0c3 100644 (file)
@@ -357,12 +357,9 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev)
 
        rc = ena_com_set_host_attributes(ena_dev);
        if (rc) {
-               if (rc == -EPERM)
-                       RTE_LOG(ERR, PMD, "Cannot set host attributes\n");
-               else
-                       RTE_LOG(ERR, PMD, "Cannot set host attributes\n");
-
-               goto err;
+               RTE_LOG(ERR, PMD, "Cannot set host attributes\n");
+               if (rc != -EPERM)
+                       goto err;
        }
 
        return;
@@ -413,11 +410,9 @@ static void ena_config_debug_area(struct ena_adapter *adapter)
 
        rc = ena_com_set_host_attributes(&adapter->ena_dev);
        if (rc) {
-               if (rc == -EPERM)
-                       RTE_LOG(WARNING, PMD, "Cannot set host attributes\n");
-               else
-                       RTE_LOG(ERR, PMD, "Cannot set host attributes\n");
-               goto err;
+               RTE_LOG(WARNING, PMD, "Cannot set host attributes\n");
+               if (rc != -EPERM)
+                       goto err;
        }
 
        return;
@@ -682,11 +677,10 @@ static void ena_rx_queue_release_bufs(struct ena_ring *ring)
 
 static void ena_tx_queue_release_bufs(struct ena_ring *ring)
 {
-       unsigned int ring_mask = ring->ring_size - 1;
+       unsigned int i;
 
-       while (ring->next_to_clean != ring->next_to_use) {
-               struct ena_tx_buffer *tx_buf =
-                       &ring->tx_buffer_info[ring->next_to_clean & ring_mask];
+       for (i = 0; i < ring->ring_size; ++i) {
+               struct ena_tx_buffer *tx_buf = &ring->tx_buffer_info[i];
 
                if (tx_buf->mbuf)
                        rte_pktmbuf_free(tx_buf->mbuf);
@@ -913,7 +907,7 @@ static int ena_start(struct rte_eth_dev *dev)
 
 static int ena_queue_restart(struct ena_ring *ring)
 {
-       int rc;
+       int rc, bufs_num;
 
        ena_assert_msg(ring->configured == 1,
                       "Trying to restart unconfigured queue\n");
@@ -924,9 +918,10 @@ static int ena_queue_restart(struct ena_ring *ring)
        if (ring->type == ENA_RING_TYPE_TX)
                return 0;
 
-       rc = ena_populate_rx_queue(ring, ring->ring_size);
-       if ((unsigned int)rc != ring->ring_size) {
-               PMD_INIT_LOG(ERR, "Failed to populate rx ring !\n");
+       bufs_num = ring->ring_size - 1;
+       rc = ena_populate_rx_queue(ring, bufs_num);
+       if (rc != bufs_num) {
+               PMD_INIT_LOG(ERR, "Failed to populate rx ring !");
                return (-1);
        }
 
@@ -1137,7 +1132,7 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)
                return 0;
 
        in_use = rxq->next_to_use - rxq->next_to_clean;
-       ena_assert_msg(((in_use + count) <= ring_size), "bad ring state");
+       ena_assert_msg(((in_use + count) < ring_size), "bad ring state");
 
        count = RTE_MIN(count,
                        (uint16_t)(ring_size - (next_to_use & ring_mask)));
@@ -1165,6 +1160,8 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)
                rc = ena_com_add_single_rx_desc(rxq->ena_com_io_sq,
                                                &ebuf, next_to_use_masked);
                if (unlikely(rc)) {
+                       rte_mempool_put_bulk(rxq->mb_pool, (void **)(&mbuf),
+                                            count - i);
                        RTE_LOG(WARNING, PMD, "failed adding rx desc\n");
                        break;
                }
@@ -1228,14 +1225,14 @@ static int ena_device_init(struct ena_com_dev *ena_dev,
                goto err_mmio_read_less;
        }
 
-       ena_config_host_info(ena_dev);
-
        /* To enable the msix interrupts the driver needs to know the number
         * of queues. So the driver uses polling mode to retrieve this
         * information.
         */
        ena_com_set_admin_polling_mode(ena_dev, true);
 
+       ena_config_host_info(ena_dev);
+
        /* Get Device Attributes and features */
        rc = ena_com_get_dev_attr_feat(ena_dev, get_feat_ctx);
        if (rc) {
@@ -1561,12 +1558,13 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                recv_idx++;
        }
 
+       rx_ring->next_to_clean = next_to_clean;
+
+       desc_in_use = desc_in_use - completed + 1;
        /* Burst refill to save doorbells, memory barriers, const interval */
        if (ring_size - desc_in_use > ENA_RING_DESCS_RATIO(ring_size))
                ena_populate_rx_queue(rx_ring, ring_size - desc_in_use);
 
-       rx_ring->next_to_clean = next_to_clean;
-
        return recv_idx;
 }
 
@@ -1684,6 +1682,7 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                /* Free whole mbuf chain  */
                mbuf = tx_info->mbuf;
                rte_pktmbuf_free(mbuf);
+               tx_info->mbuf = NULL;
 
                /* Put back descriptor to the ring for reuse */
                tx_ring->empty_tx_reqs[next_to_clean & ring_mask] = req_id;