net/virtio-user: support Rx interrupt
[dpdk.git] / drivers / net / virtio / virtio_user_ethdev.c
index 0b226ac..9dd55fa 100644 (file)
@@ -148,6 +148,15 @@ virtio_user_set_config_irq(struct virtio_hw *hw __rte_unused,
        return VIRTIO_MSI_NO_VECTOR;
 }
 
+static uint16_t
+virtio_user_set_queue_irq(struct virtio_hw *hw __rte_unused,
+                         struct virtqueue *vq __rte_unused,
+                         uint16_t vec)
+{
+       /* pretend we have done that */
+       return vec;
+}
+
 /* This function is to get the queue size, aka, number of descs, of a specified
  * queue. Different with the VHOST_USER_GET_QUEUE_NUM, which is used to get the
  * max supported queues.
@@ -226,6 +235,7 @@ const struct virtio_pci_ops virtio_user_ops = {
        .set_features   = virtio_user_set_features,
        .get_isr        = virtio_user_get_isr,
        .set_config_irq = virtio_user_set_config_irq,
+       .set_queue_irq  = virtio_user_set_queue_irq,
        .get_queue_num  = virtio_user_get_queue_num,
        .setup_queue    = virtio_user_setup_queue,
        .del_queue      = virtio_user_del_queue,
@@ -243,6 +253,8 @@ static const char *valid_args[] = {
        VIRTIO_USER_ARG_PATH,
 #define VIRTIO_USER_ARG_QUEUE_SIZE     "queue_size"
        VIRTIO_USER_ARG_QUEUE_SIZE,
+#define VIRTIO_USER_ARG_INTERFACE_NAME "iface"
+       VIRTIO_USER_ARG_INTERFACE_NAME,
        NULL
 };
 
@@ -259,6 +271,9 @@ get_string_arg(const char *key __rte_unused,
 
        *(char **)extra_args = strdup(value);
 
+       if (!*(char **)extra_args)
+               return -ENOMEM;
+
        return 0;
 }
 
@@ -308,6 +323,7 @@ virtio_user_eth_dev_alloc(const char *name)
        }
 
        hw->port_id = data->port_id;
+       dev->port_id = data->port_id;
        virtio_hw_internal[hw->port_id].vtpci_ops = &virtio_user_ops;
        hw->use_msix = 0;
        hw->modern   = 0;
@@ -347,6 +363,7 @@ virtio_user_pmd_probe(const char *name, const char *params)
        uint64_t cq = VIRTIO_USER_DEF_CQ_EN;
        uint64_t queue_size = VIRTIO_USER_DEF_Q_SZ;
        char *path = NULL;
+       char *ifname = NULL;
        char *mac_addr = NULL;
        int ret = -1;
 
@@ -375,6 +392,22 @@ virtio_user_pmd_probe(const char *name, const char *params)
                goto end;
        }
 
+       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_INTERFACE_NAME) == 1) {
+               if (is_vhost_user_by_type(path)) {
+                       PMD_INIT_LOG(ERR,
+                               "arg %s applies only to vhost-kernel backend",
+                               VIRTIO_USER_ARG_INTERFACE_NAME);
+                       goto end;
+               }
+
+               if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_INTERFACE_NAME,
+                                      &get_string_arg, &ifname) < 0) {
+                       PMD_INIT_LOG(ERR, "error to parse %s",
+                                    VIRTIO_USER_ARG_INTERFACE_NAME);
+                       goto end;
+               }
+       }
+
        if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_MAC) == 1) {
                if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_MAC,
                                       &get_string_arg, &mac_addr) < 0) {
@@ -418,6 +451,13 @@ virtio_user_pmd_probe(const char *name, const char *params)
                goto end;
        }
 
+       if (queues > VIRTIO_MAX_VIRTQUEUE_PAIRS) {
+               PMD_INIT_LOG(ERR, "arg %s %" PRIu64 " exceeds the limit %u",
+                       VIRTIO_USER_ARG_QUEUES_NUM, queues,
+                       VIRTIO_MAX_VIRTQUEUE_PAIRS);
+               goto end;
+       }
+
        eth_dev = virtio_user_eth_dev_alloc(name);
        if (!eth_dev) {
                PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
@@ -426,7 +466,7 @@ virtio_user_pmd_probe(const char *name, const char *params)
 
        hw = eth_dev->data->dev_private;
        if (virtio_user_dev_init(hw->virtio_user_dev, path, queues, cq,
-                                queue_size, mac_addr) < 0) {
+                                queue_size, mac_addr, &ifname) < 0) {
                PMD_INIT_LOG(ERR, "virtio_user_dev_init fails");
                virtio_user_eth_dev_free(eth_dev);
                goto end;
@@ -447,6 +487,8 @@ end:
                free(path);
        if (mac_addr)
                free(mac_addr);
+       if (ifname)
+               free(ifname);
        return ret;
 }
 
@@ -492,4 +534,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_virtio_user,
        "mac=<mac addr> "
        "cq=<int> "
        "queue_size=<int> "
-       "queues=<int>");
+       "queues=<int> "
+       "iface=<string>");