Merge branch 'upstream-16.11-stable' into 16.11.x
[deb_dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index 8592485..5a27ab7 100644 (file)
@@ -288,17 +288,6 @@ virtio_dev_queue_release(void *queue __rte_unused)
        /* do nothing */
 }
 
-static int
-virtio_get_queue_type(struct virtio_hw *hw, uint16_t vtpci_queue_idx)
-{
-       if (vtpci_queue_idx == hw->max_queue_pairs * 2)
-               return VTNET_CQ;
-       else if (vtpci_queue_idx % 2 == 0)
-               return VTNET_RQ;
-       else
-               return VTNET_TQ;
-}
-
 static uint16_t
 virtio_get_nr_vq(struct virtio_hw *hw)
 {
@@ -847,7 +836,7 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
                /* Note: limit checked in rte_eth_xstats_names() */
 
                for (i = 0; i < dev->data->nb_rx_queues; i++) {
-                       struct virtqueue *rxvq = dev->data->rx_queues[i];
+                       struct virtnet_rx *rxvq = dev->data->rx_queues[i];
                        if (rxvq == NULL)
                                continue;
                        for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
@@ -860,7 +849,7 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
                }
 
                for (i = 0; i < dev->data->nb_tx_queues; i++) {
-                       struct virtqueue *txvq = dev->data->tx_queues[i];
+                       struct virtnet_tx *txvq = dev->data->tx_queues[i];
                        if (txvq == NULL)
                                continue;
                        for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
@@ -1205,6 +1194,11 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
        /* Reset the device although not necessary at startup */
        vtpci_reset(hw);
 
+       if (hw->vqs) {
+               virtio_dev_free_mbufs(eth_dev);
+               virtio_free_queues(hw);
+       }
+
        /* Tell the host we've noticed this device. */
        vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);
 
@@ -1565,7 +1559,7 @@ virtio_dev_start(struct rte_eth_dev *dev)
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                rxvq = dev->data->rx_queues[i];
                /* Flush the old packets */
-               virtqueue_flush(rxvq->vq);
+               virtqueue_rxvq_flush(rxvq->vq);
                virtqueue_notify(rxvq->vq);
        }
 
@@ -1597,12 +1591,15 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                struct virtnet_rx *rxvq = dev->data->rx_queues[i];
 
+               if (rxvq == NULL || rxvq->vq == NULL)
+                       continue;
+
                PMD_INIT_LOG(DEBUG,
                             "Before freeing rxq[%d] used and unused buf", i);
                VIRTQUEUE_DUMP(rxvq->vq);
 
                PMD_INIT_LOG(DEBUG, "rx_queues[%d]=%p", i, rxvq);
-               while ((buf = virtqueue_detatch_unused(rxvq->vq)) != NULL) {
+               while ((buf = virtqueue_detach_unused(rxvq->vq)) != NULL) {
                        rte_pktmbuf_free(buf);
                        mbuf_num++;
                }
@@ -1616,13 +1613,16 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
        for (i = 0; i < dev->data->nb_tx_queues; i++) {
                struct virtnet_tx *txvq = dev->data->tx_queues[i];
 
+               if (txvq == NULL || txvq->vq == NULL)
+                       continue;
+
                PMD_INIT_LOG(DEBUG,
                             "Before freeing txq[%d] used and unused bufs",
                             i);
                VIRTQUEUE_DUMP(txvq->vq);
 
                mbuf_num = 0;
-               while ((buf = virtqueue_detatch_unused(txvq->vq)) != NULL) {
+               while ((buf = virtqueue_detach_unused(txvq->vq)) != NULL) {
                        rte_pktmbuf_free(buf);
                        mbuf_num++;
                }