virtio: remove configurable queue size support

Native virtio device through legacy driver can't support configurable queue size.

Change-Id: I76c446a071bef8a469873010325d830586aa84bd
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
diff --git a/src/vnet/devices/virtio/cli.c b/src/vnet/devices/virtio/cli.c
index 92e7e93..956284c 100644
--- a/src/vnet/devices/virtio/cli.c
+++ b/src/vnet/devices/virtio/cli.c
@@ -29,7 +29,6 @@
 {
   unformat_input_t _line_input, *line_input = &_line_input;
   virtio_pci_create_if_args_t args;
-  u32 tmp;
   u64 feature_mask = (u64) ~ (0ULL);
 
   /* Get a line of input. */
@@ -43,10 +42,6 @@
 	;
       else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask))
 	args.features = feature_mask;
-      else if (unformat (line_input, "rx-queue-size %u", &tmp))
-	args.rxq_size = tmp;
-      else if (unformat (line_input, "tx-queue-size %u", &tmp))
-	args.txq_size = tmp;
       else
 	return clib_error_return (0, "unknown input `%U'",
 				  format_unformat_error, input);
@@ -62,7 +57,7 @@
 VLIB_CLI_COMMAND (virtio_pci_create_command, static) = {
   .path = "create interface virtio",
   .short_help = "create interface virtio <pci-address> "
-                "[feature-mask <hex-mask>] [rx-queue-size <size>] [tx-queue-size <size>]",
+                "[feature-mask <hex-mask>]",
   .function = virtio_pci_create_command_fn,
 };
 /* *INDENT-ON* */
diff --git a/src/vnet/devices/virtio/pci.c b/src/vnet/devices/virtio/pci.c
index 31027f7..b02b79d 100644
--- a/src/vnet/devices/virtio/pci.c
+++ b/src/vnet/devices/virtio/pci.c
@@ -177,16 +177,21 @@
   return queue_num;
 }
 
-
-static void
+static int
 virtio_pci_legacy_setup_queue (vlib_main_t * vm, virtio_if_t * vif,
 			       u16 queue_id, void *p)
 {
   u64 addr = vlib_physmem_get_pa (vm, p) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT;
+  u32 addr2 = 0;
   vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL,
 			 &queue_id);
   vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN,
 			 (u32 *) & addr);
+  vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN,
+			&addr2);
+  if ((u32) addr == addr2)
+    return 0;
+  return 1;
 }
 
 static void
@@ -693,20 +698,19 @@
 				 queue_size - n_alloc);
 	}
       while (n_alloc != queue_size);
-      vif->num_txqs++;
       virtio_log_debug (vim, vif, "tx-queue: number %u, size %u", queue_num,
 			queue_size);
     }
   else
     {
-      vif->num_rxqs++;
       virtio_log_debug (vim, vif, "rx-queue: number %u, size %u", queue_num,
 			queue_size);
     }
   vring->size = queue_size;
-  virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr);
-  vring->kick_fd = -1;
+  if (virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr))
+    return clib_error_return (0, "error in queue address setup");
 
+  vring->kick_fd = -1;
   return error;
 }
 
@@ -949,12 +953,24 @@
   for (int i = 0; i < vif->max_queue_pairs; i++)
     {
       if ((error = virtio_pci_vring_init (vm, vif, RX_QUEUE (i))))
-	virtio_log_warning (vim, vif, "%s (%u) %s", "error in rxq-queue",
-			    RX_QUEUE (i), "initialization");
+	{
+	  virtio_log_warning (vim, vif, "%s (%u) %s", "error in rxq-queue",
+			      RX_QUEUE (i), "initialization");
+	}
+      else
+	{
+	  vif->num_rxqs++;
+	}
 
       if ((error = virtio_pci_vring_init (vm, vif, TX_QUEUE (i))))
-	virtio_log_warning (vim, vif, "%s (%u) %s", "error in txq-queue",
-			    TX_QUEUE (i), "initialization");
+	{
+	  virtio_log_warning (vim, vif, "%s (%u) %s", "error in txq-queue",
+			      TX_QUEUE (i), "initialization");
+	}
+      else
+	{
+	  vif->num_txqs++;
+	}
     }
 
   if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
@@ -1006,25 +1022,6 @@
   vlib_pci_dev_handle_t h;
   clib_error_t *error = 0;
 
-  if (args->rxq_size == 0)
-    args->rxq_size = VIRTIO_NUM_RX_DESC;
-  if (args->txq_size == 0)
-    args->txq_size = VIRTIO_NUM_TX_DESC;
-
-  if (!virtio_pci_queue_size_valid (args->rxq_size) ||
-      !virtio_pci_queue_size_valid (args->txq_size))
-    {
-      args->rv = VNET_API_ERROR_INVALID_VALUE;
-      args->error =
-	clib_error_return (error,
-			   "queue size must be <= 4096, >= 64, "
-			   "and multiples of 64");
-      vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s",
-		format_vlib_pci_addr, &args->addr,
-		"queue size must be <= 4096, >= 64, and multiples of 64");
-      return;
-    }
-
   /* *INDENT-OFF* */
   pool_foreach (vif, vim->interfaces, ({
     if (vif->pci_addr.as_u32 == args->addr)
diff --git a/src/vnet/devices/virtio/pci.h b/src/vnet/devices/virtio/pci.h
index 40648c8..dcf9b14 100644
--- a/src/vnet/devices/virtio/pci.h
+++ b/src/vnet/devices/virtio/pci.h
@@ -227,8 +227,6 @@
 typedef struct
 {
   u32 addr;
-  u16 rxq_size;
-  u16 txq_size;
   /* return */
   i32 rv;
   u32 sw_if_index;
diff --git a/src/vnet/devices/virtio/virtio.api b/src/vnet/devices/virtio/virtio.api
index cb67296..3a40fa9 100644
--- a/src/vnet/devices/virtio/virtio.api
+++ b/src/vnet/devices/virtio/virtio.api
@@ -33,8 +33,6 @@
   u32 pci_addr;
   u8 use_random_mac;
   u8 mac_address[6];
-  u16 tx_ring_sz; /* optional, default is 256 entries, must be power of 2 */
-  u16 rx_ring_sz; /* optional, default is 256 entries, must be power of 2 */
   u64 features;
 };
 
diff --git a/src/vnet/devices/virtio/virtio_api.c b/src/vnet/devices/virtio/virtio_api.c
index ff123ae..82ff791 100644
--- a/src/vnet/devices/virtio/virtio_api.c
+++ b/src/vnet/devices/virtio/virtio_api.c
@@ -65,8 +65,6 @@
       clib_memcpy (ap->mac_addr, mp->mac_address, 6);
       ap->mac_addr_set = 1;
     }
-  ap->rxq_size = ntohs (mp->rx_ring_sz);
-  ap->txq_size = ntohs (mp->tx_ring_sz);
   ap->sw_if_index = (u32) ~ 0;
   ap->features = clib_net_to_host_u64 (mp->features);