net/bnxt: remove extra blank line
[dpdk.git] / drivers / net / virtio / virtio_rxtx.c
index f915b8a..4028300 100644 (file)
@@ -15,7 +15,7 @@
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
 #include <rte_ether.h>
-#include <rte_ethdev_driver.h>
+#include <ethdev_driver.h>
 #include <rte_prefetch.h>
 #include <rte_string_fns.h>
 #include <rte_errno.h>
@@ -27,7 +27,7 @@
 
 #include "virtio_logs.h"
 #include "virtio_ethdev.h"
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtqueue.h"
 #include "virtio_rxtx.h"
 #include "virtio_rxtx_simple.h"
@@ -147,7 +147,7 @@ virtqueue_dequeue_burst_rx_packed(struct virtqueue *vq,
 
        for (i = 0; i < num; i++) {
                used_idx = vq->vq_used_cons_idx;
-               /* desc_is_used has a load-acquire or rte_cio_rmb inside
+               /* desc_is_used has a load-acquire or rte_io_rmb inside
                 * and wait for used desc in virtqueue.
                 */
                if (!desc_is_used(&desc[used_idx], vq))
@@ -271,13 +271,10 @@ virtqueue_enqueue_refill_inorder(struct virtqueue *vq,
                dxp->cookie = (void *)cookies[i];
                dxp->ndescs = 1;
 
-               start_dp[idx].addr =
-                               VIRTIO_MBUF_ADDR(cookies[i], vq) +
-                               RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
-               start_dp[idx].len =
-                               cookies[i]->buf_len -
-                               RTE_PKTMBUF_HEADROOM +
-                               hw->vtnet_hdr_size;
+               start_dp[idx].addr = cookies[i]->buf_iova +
+                       RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
+               start_dp[idx].len = cookies[i]->buf_len -
+                       RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size;
                start_dp[idx].flags =  VRING_DESC_F_WRITE;
 
                vq_update_avail_ring(vq, idx);
@@ -313,12 +310,10 @@ virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf **cookie,
                dxp->cookie = (void *)cookie[i];
                dxp->ndescs = 1;
 
-               start_dp[idx].addr =
-                       VIRTIO_MBUF_ADDR(cookie[i], vq) +
+               start_dp[idx].addr = cookie[i]->buf_iova +
                        RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
-               start_dp[idx].len =
-                       cookie[i]->buf_len - RTE_PKTMBUF_HEADROOM +
-                       hw->vtnet_hdr_size;
+               start_dp[idx].len = cookie[i]->buf_len -
+                       RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size;
                start_dp[idx].flags = VRING_DESC_F_WRITE;
                vq->vq_desc_head_idx = start_dp[idx].next;
                vq_update_avail_ring(vq, idx);
@@ -355,10 +350,10 @@ virtqueue_enqueue_recv_refill_packed(struct virtqueue *vq,
                dxp->cookie = (void *)cookie[i];
                dxp->ndescs = 1;
 
-               start_dp[idx].addr = VIRTIO_MBUF_ADDR(cookie[i], vq) +
-                               RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
-               start_dp[idx].len = cookie[i]->buf_len - RTE_PKTMBUF_HEADROOM
-                                       + hw->vtnet_hdr_size;
+               start_dp[idx].addr = cookie[i]->buf_iova +
+                       RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
+               start_dp[idx].len = cookie[i]->buf_len -
+                       RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size;
 
                vq->vq_desc_head_idx = dxp->next;
                if (vq->vq_desc_head_idx == VQ_RING_DESC_CHAIN_END)
@@ -455,8 +450,7 @@ virtqueue_enqueue_xmit_inorder(struct virtnet_tx *txvq,
                else
                        virtqueue_xmit_offload(hdr, cookies[i], true);
 
-               start_dp[idx].addr  =
-                       VIRTIO_MBUF_DATA_DMA_ADDR(cookies[i], vq) - head_size;
+               start_dp[idx].addr  = rte_mbuf_data_iova(cookies[i]) - head_size;
                start_dp[idx].len   = cookies[i]->data_len + head_size;
                start_dp[idx].flags = 0;
 
@@ -503,7 +497,7 @@ virtqueue_enqueue_xmit_packed_fast(struct virtnet_tx *txvq,
        else
                virtqueue_xmit_offload(hdr, cookie, true);
 
-       dp->addr = VIRTIO_MBUF_DATA_DMA_ADDR(cookie, vq) - head_size;
+       dp->addr = rte_mbuf_data_iova(cookie) - head_size;
        dp->len  = cookie->data_len + head_size;
        dp->id   = id;
 
@@ -590,7 +584,7 @@ virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct rte_mbuf *cookie,
        virtqueue_xmit_offload(hdr, cookie, vq->hw->has_tx_offload);
 
        do {
-               start_dp[idx].addr  = VIRTIO_MBUF_DATA_DMA_ADDR(cookie, vq);
+               start_dp[idx].addr  = rte_mbuf_data_iova(cookie);
                start_dp[idx].len   = cookie->data_len;
                if (prepend_header) {
                        start_dp[idx].addr -= head_size;
@@ -634,9 +628,9 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
                        const struct rte_eth_rxconf *rx_conf,
                        struct rte_mempool *mp)
 {
-       uint16_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
+       uint16_t vq_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
        struct virtio_hw *hw = dev->data->dev_private;
-       struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+       struct virtqueue *vq = hw->vqs[vq_idx];
        struct virtnet_rx *rxvq;
        uint16_t rx_free_thresh;
 
@@ -684,21 +678,21 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 int
 virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 {
-       uint16_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
+       uint16_t vq_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
        struct virtio_hw *hw = dev->data->dev_private;
-       struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+       struct virtqueue *vq = hw->vqs[vq_idx];
        struct virtnet_rx *rxvq = &vq->rxq;
        struct rte_mbuf *m;
        uint16_t desc_idx;
        int error, nbufs, i;
-       bool in_order = vtpci_with_feature(hw, VIRTIO_F_IN_ORDER);
+       bool in_order = virtio_with_feature(hw, VIRTIO_F_IN_ORDER);
 
        PMD_INIT_FUNC_TRACE();
 
        /* Allocate blank mbufs for the each rx descriptor */
        nbufs = 0;
 
-       if (hw->use_vec_rx && !vtpci_packed_queue(hw)) {
+       if (hw->use_vec_rx && !virtio_with_packed_queue(hw)) {
                for (desc_idx = 0; desc_idx < vq->vq_nentries;
                     desc_idx++) {
                        vq->vq_split.ring.avail->ring[desc_idx] = desc_idx;
@@ -716,12 +710,12 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
                        &rxvq->fake_mbuf;
        }
 
-       if (hw->use_vec_rx && !vtpci_packed_queue(hw)) {
+       if (hw->use_vec_rx && !virtio_with_packed_queue(hw)) {
                while (vq->vq_free_cnt >= RTE_VIRTIO_VPMD_RX_REARM_THRESH) {
                        virtio_rxq_rearm_vec(rxvq);
                        nbufs += RTE_VIRTIO_VPMD_RX_REARM_THRESH;
                }
-       } else if (!vtpci_packed_queue(vq->hw) && in_order) {
+       } else if (!virtio_with_packed_queue(vq->hw) && in_order) {
                if ((!virtqueue_full(vq))) {
                        uint16_t free_cnt = vq->vq_free_cnt;
                        struct rte_mbuf *pkts[free_cnt];
@@ -747,7 +741,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
                                break;
 
                        /* Enqueue allocated buffers */
-                       if (vtpci_packed_queue(vq->hw))
+                       if (virtio_with_packed_queue(vq->hw))
                                error = virtqueue_enqueue_recv_refill_packed(vq,
                                                &m, 1);
                        else
@@ -760,7 +754,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
                        nbufs++;
                }
 
-               if (!vtpci_packed_queue(vq->hw))
+               if (!virtio_with_packed_queue(vq->hw))
                        vq_update_avail_idx(vq);
        }
 
@@ -785,9 +779,9 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,
                        unsigned int socket_id __rte_unused,
                        const struct rte_eth_txconf *tx_conf)
 {
-       uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
+       uint8_t vq_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
        struct virtio_hw *hw = dev->data->dev_private;
-       struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+       struct virtqueue *vq = hw->vqs[vq_idx];
        struct virtnet_tx *txvq;
        uint16_t tx_free_thresh;
 
@@ -829,14 +823,14 @@ int
 virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,
                                uint16_t queue_idx)
 {
-       uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
+       uint8_t vq_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
        struct virtio_hw *hw = dev->data->dev_private;
-       struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+       struct virtqueue *vq = hw->vqs[vq_idx];
 
        PMD_INIT_FUNC_TRACE();
 
-       if (!vtpci_packed_queue(hw)) {
-               if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER))
+       if (!virtio_with_packed_queue(hw)) {
+               if (virtio_with_feature(hw, VIRTIO_F_IN_ORDER))
                        vq->vq_split.ring.desc[vq->vq_nentries - 1].next = 0;
        }
 
@@ -853,7 +847,7 @@ virtio_discard_rxbuf(struct virtqueue *vq, struct rte_mbuf *m)
         * Requeue the discarded mbuf. This should always be
         * successful since it was just dequeued.
         */
-       if (vtpci_packed_queue(vq->hw))
+       if (virtio_with_packed_queue(vq->hw))
                error = virtqueue_enqueue_recv_refill_packed(vq, &m, 1);
        else
                error = virtqueue_enqueue_recv_refill(vq, &m, 1);
@@ -910,9 +904,10 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr)
                         */
                        uint16_t csum = 0, off;
 
-                       rte_raw_cksum_mbuf(m, hdr->csum_start,
+                       if (rte_raw_cksum_mbuf(m, hdr->csum_start,
                                rte_pktmbuf_pkt_len(m) - hdr->csum_start,
-                               &csum);
+                               &csum) < 0)
+                               return -EINVAL;
                        if (likely(csum != 0xffff))
                                csum = ~csum;
                        off = hdr->csum_offset + hdr->csum_start;
@@ -1214,7 +1209,7 @@ virtio_recv_pkts_inorder(void *rx_queue,
                         ((char *)rxm->buf_addr + RTE_PKTMBUF_HEADROOM
                         - hdr_size);
 
-               if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
+               if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
                        seg_num = header->num_buffers;
                        if (seg_num == 0)
                                seg_num = 1;
@@ -1740,7 +1735,7 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
        struct virtio_hw *hw = vq->hw;
        uint16_t hdr_size = hw->vtnet_hdr_size;
        uint16_t nb_tx = 0;
-       bool in_order = vtpci_with_feature(hw, VIRTIO_F_IN_ORDER);
+       bool in_order = virtio_with_feature(hw, VIRTIO_F_IN_ORDER);
 
        if (unlikely(hw->started == 0 && tx_pkts != hw->inject_pkts))
                return nb_tx;
@@ -1756,11 +1751,11 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
 
        for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
                struct rte_mbuf *txm = tx_pkts[nb_tx];
-               int can_push = 0, slots, need;
+               int can_push = 0, use_indirect = 0, slots, need;
 
                /* optimize ring usage */
-               if ((vtpci_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
-                     vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) &&
+               if ((virtio_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
+                     virtio_with_feature(hw, VIRTIO_F_VERSION_1)) &&
                    rte_mbuf_refcnt_read(txm) == 1 &&
                    RTE_MBUF_DIRECT(txm) &&
                    txm->nb_segs == 1 &&
@@ -1768,12 +1763,15 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
                    rte_is_aligned(rte_pktmbuf_mtod(txm, char *),
                           __alignof__(struct virtio_net_hdr_mrg_rxbuf)))
                        can_push = 1;
-
+               else if (virtio_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
+                        txm->nb_segs < VIRTIO_MAX_TX_INDIRECT)
+                       use_indirect = 1;
                /* How many main ring entries are needed to this Tx?
+                * indirect   => 1
                 * any_layout => number of segments
                 * default    => number of segments + 1
                 */
-               slots = txm->nb_segs + !can_push;
+               slots = use_indirect ? 1 : (txm->nb_segs + !can_push);
                need = slots - vq->vq_free_cnt;
 
                /* Positive value indicates it need free vring descriptors */
@@ -1791,7 +1789,8 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
                if (can_push)
                        virtqueue_enqueue_xmit_packed_fast(txvq, txm, in_order);
                else
-                       virtqueue_enqueue_xmit_packed(txvq, txm, slots, 0,
+                       virtqueue_enqueue_xmit_packed(txvq, txm, slots,
+                                                     use_indirect, 0,
                                                      in_order);
 
                virtio_update_packet_stats(&txvq->stats, txm);
@@ -1836,8 +1835,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
                int can_push = 0, use_indirect = 0, slots, need;
 
                /* optimize ring usage */
-               if ((vtpci_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
-                     vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) &&
+               if ((virtio_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
+                     virtio_with_feature(hw, VIRTIO_F_VERSION_1)) &&
                    rte_mbuf_refcnt_read(txm) == 1 &&
                    RTE_MBUF_DIRECT(txm) &&
                    txm->nb_segs == 1 &&
@@ -1845,7 +1844,7 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
                    rte_is_aligned(rte_pktmbuf_mtod(txm, char *),
                                   __alignof__(struct virtio_net_hdr_mrg_rxbuf)))
                        can_push = 1;
-               else if (vtpci_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
+               else if (virtio_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
                         txm->nb_segs < VIRTIO_MAX_TX_INDIRECT)
                        use_indirect = 1;
 
@@ -1938,8 +1937,8 @@ virtio_xmit_pkts_inorder(void *tx_queue,
                int slots;
 
                /* optimize ring usage */
-               if ((vtpci_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
-                    vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) &&
+               if ((virtio_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
+                    virtio_with_feature(hw, VIRTIO_F_VERSION_1)) &&
                     rte_mbuf_refcnt_read(txm) == 1 &&
                     RTE_MBUF_DIRECT(txm) &&
                     txm->nb_segs == 1 &&
@@ -2020,8 +2019,7 @@ virtio_xmit_pkts_inorder(void *tx_queue,
        return nb_tx;
 }
 
-#ifndef CC_AVX512_SUPPORT
-uint16_t
+__rte_weak uint16_t
 virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused,
                            struct rte_mbuf **rx_pkts __rte_unused,
                            uint16_t nb_pkts __rte_unused)
@@ -2029,11 +2027,10 @@ virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused,
        return 0;
 }
 
-uint16_t
+__rte_weak uint16_t
 virtio_xmit_pkts_packed_vec(void *tx_queue __rte_unused,
                            struct rte_mbuf **tx_pkts __rte_unused,
                            uint16_t nb_pkts __rte_unused)
 {
        return 0;
 }
-#endif /* ifndef CC_AVX512_SUPPORT */