New upstream version 16.11.4
[deb_dpdk.git] / drivers / net / virtio / virtio_rxtx.c
index a33ef1a..43fac63 100644 (file)
@@ -72,7 +72,7 @@
 #define VIRTIO_SIMPLE_FLAGS ((uint32_t)ETH_TXQ_FLAGS_NOMULTSEGS | \
        ETH_TXQ_FLAGS_NOOFFLOADS)
 
-static void
+void
 vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx)
 {
        struct vring_desc *dp, *dp_tail;
@@ -291,6 +291,10 @@ virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct rte_mbuf *cookie,
                /* prepend cannot fail, checked by caller */
                hdr = (struct virtio_net_hdr *)
                        rte_pktmbuf_prepend(cookie, head_size);
+               /* rte_pktmbuf_prepend() counts the hdr size to the pkt length,
+                * which is wrong. Below subtract restores correct pkt size.
+                */
+               cookie->pkt_len -= head_size;
                /* if offload disabled, it is not zeroed below, do it now */
                if (offload == 0) {
                        ASSIGN_UNLESS_EQUAL(hdr->csum_start, 0);
@@ -412,9 +416,6 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
        struct virtio_hw *hw = dev->data->dev_private;
        struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
        struct virtnet_rx *rxvq;
-       int error, nbufs;
-       struct rte_mbuf *m;
-       uint16_t desc_idx;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -431,10 +432,24 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
        }
        dev->data->rx_queues[queue_idx] = rxvq;
 
+       return 0;
+}
+
+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;
+       struct virtio_hw *hw = dev->data->dev_private;
+       struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+       struct virtnet_rx *rxvq = &vq->rxq;
+       struct rte_mbuf *m;
+       uint16_t desc_idx;
+       int error, nbufs;
+
+       PMD_INIT_FUNC_TRACE();
 
        /* Allocate blank mbufs for the each rx descriptor */
        nbufs = 0;
-       error = ENOSPC;
 
        if (hw->use_simple_rxtx) {
                for (desc_idx = 0; desc_idx < vq->vq_nentries;
@@ -525,7 +540,6 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,
        struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
        struct virtnet_tx *txvq;
        uint16_t tx_free_thresh;
-       uint16_t desc_idx;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -554,9 +568,24 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,
 
        vq->vq_free_thresh = tx_free_thresh;
 
-       if (hw->use_simple_rxtx) {
-               uint16_t mid_idx  = vq->vq_nentries >> 1;
+       dev->data->tx_queues[queue_idx] = txvq;
+       return 0;
+}
+
+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;
+       struct virtio_hw *hw = dev->data->dev_private;
+       struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+       uint16_t mid_idx = vq->vq_nentries >> 1;
+       struct virtnet_tx *txvq = &vq->txq;
+       uint16_t desc_idx;
 
+       PMD_INIT_FUNC_TRACE();
+
+       if (hw->use_simple_rxtx) {
                for (desc_idx = 0; desc_idx < mid_idx; desc_idx++) {
                        vq->vq_ring.avail->ring[desc_idx] =
                                desc_idx + mid_idx;
@@ -578,7 +607,6 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,
 
        VIRTQUEUE_DUMP(vq);
 
-       dev->data->tx_queues[queue_idx] = txvq;
        return 0;
 }
 
@@ -661,7 +689,7 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr)
                         * In case of SCTP, this will be wrong since it's a CRC
                         * but there's nothing we can do.
                         */
-                       uint16_t csum, off;
+                       uint16_t csum = 0, off;
 
                        rte_raw_cksum_mbuf(m, hdr->csum_start,
                                rte_pktmbuf_pkt_len(m) - hdr->csum_start,