net/txgbe: support MTU set
[dpdk.git] / drivers / vdpa / ifc / ifcvf_vdpa.c
index 0418f9a..6a1b44b 100644 (file)
@@ -16,6 +16,7 @@
 #include <rte_bus_pci.h>
 #include <rte_vhost.h>
 #include <rte_vdpa.h>
+#include <rte_vdpa_dev.h>
 #include <rte_vfio.h>
 #include <rte_spinlock.h>
 #include <rte_log.h>
@@ -24,6 +25,7 @@
 
 #include "base/ifcvf.h"
 
+RTE_LOG_REGISTER(ifcvf_vdpa_logtype, pmd.net.ifcvf_vdpa, NOTICE);
 #define DRV_LOG(level, fmt, args...) \
        rte_log(RTE_LOG_ ## level, ifcvf_vdpa_logtype, \
                "IFCVF %s(): " fmt "\n", __func__, ##args)
@@ -44,11 +46,10 @@ static const char * const ifcvf_valid_arguments[] = {
        NULL
 };
 
-static int ifcvf_vdpa_logtype;
-
 struct ifcvf_internal {
        struct rte_pci_device *pdev;
        struct ifcvf_hw hw;
+       int configured;
        int vfio_container_fd;
        int vfio_group_fd;
        int vfio_dev_fd;
@@ -839,7 +840,7 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal)
        vdpa_ifcvf_stop(internal);
        vdpa_disable_vfio_intr(internal);
 
-       ret = rte_vhost_host_notifier_ctrl(vid, false);
+       ret = rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, false);
        if (ret && ret != -ENOTSUP)
                goto error;
 
@@ -858,7 +859,7 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal)
        if (ret)
                goto stop_vf;
 
-       rte_vhost_host_notifier_ctrl(vid, true);
+       rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, true);
 
        internal->sw_fallback_running = true;
 
@@ -881,7 +882,7 @@ ifcvf_dev_config(int vid)
        struct internal_list *list;
        struct ifcvf_internal *internal;
 
-       vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid));
+       vdev = rte_vhost_get_vdpa_device(vid);
        list = find_internal_resource_by_vdev(vdev);
        if (list == NULL) {
                DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
@@ -893,10 +894,11 @@ ifcvf_dev_config(int vid)
        rte_atomic32_set(&internal->dev_attached, 1);
        update_datapath(internal);
 
-       if (rte_vhost_host_notifier_ctrl(vid, true) != 0)
+       if (rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, true) != 0)
                DRV_LOG(NOTICE, "vDPA (%s): software relay is used.",
                                vdev->device->name);
 
+       internal->configured = 1;
        return 0;
 }
 
@@ -907,7 +909,7 @@ ifcvf_dev_close(int vid)
        struct internal_list *list;
        struct ifcvf_internal *internal;
 
-       vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid));
+       vdev = rte_vhost_get_vdpa_device(vid);
        list = find_internal_resource_by_vdev(vdev);
        if (list == NULL) {
                DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
@@ -935,6 +937,7 @@ ifcvf_dev_close(int vid)
                update_datapath(internal);
        }
 
+       internal->configured = 0;
        return 0;
 }
 
@@ -947,7 +950,7 @@ ifcvf_set_features(int vid)
        struct ifcvf_internal *internal;
        uint64_t log_base = 0, log_size = 0;
 
-       vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid));
+       vdev = rte_vhost_get_vdpa_device(vid);
        list = find_internal_resource_by_vdev(vdev);
        if (list == NULL) {
                DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
@@ -978,7 +981,7 @@ ifcvf_get_vfio_group_fd(int vid)
        struct rte_vdpa_device *vdev;
        struct internal_list *list;
 
-       vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid));
+       vdev = rte_vhost_get_vdpa_device(vid);
        list = find_internal_resource_by_vdev(vdev);
        if (list == NULL) {
                DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
@@ -994,7 +997,7 @@ ifcvf_get_vfio_device_fd(int vid)
        struct rte_vdpa_device *vdev;
        struct internal_list *list;
 
-       vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid));
+       vdev = rte_vhost_get_vdpa_device(vid);
        list = find_internal_resource_by_vdev(vdev);
        if (list == NULL) {
                DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
@@ -1013,7 +1016,7 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
        struct vfio_region_info reg = { .argsz = sizeof(reg) };
        int ret;
 
-       vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid));
+       vdev = rte_vhost_get_vdpa_device(vid);
        list = find_internal_resource_by_vdev(vdev);
        if (list == NULL) {
                DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
@@ -1073,7 +1076,8 @@ ifcvf_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features)
                 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ | \
                 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD | \
                 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | \
-                1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD)
+                1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD | \
+                1ULL << VHOST_USER_PROTOCOL_F_STATUS)
 static int
 ifcvf_get_protocol_features(struct rte_vdpa_device *vdev, uint64_t *features)
 {
@@ -1083,13 +1087,61 @@ ifcvf_get_protocol_features(struct rte_vdpa_device *vdev, uint64_t *features)
        return 0;
 }
 
+static int
+ifcvf_set_vring_state(int vid, int vring, int state)
+{
+       struct rte_vdpa_device *vdev;
+       struct internal_list *list;
+       struct ifcvf_internal *internal;
+       struct ifcvf_hw *hw;
+       struct ifcvf_pci_common_cfg *cfg;
+       int ret = 0;
+
+       vdev = rte_vhost_get_vdpa_device(vid);
+       list = find_internal_resource_by_vdev(vdev);
+       if (list == NULL) {
+               DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
+               return -1;
+       }
+
+       internal = list->internal;
+       if (vring < 0 || vring >= internal->max_queues * 2) {
+               DRV_LOG(ERR, "Vring index %d not correct", vring);
+               return -1;
+       }
+
+       hw = &internal->hw;
+       if (!internal->configured)
+               goto exit;
+
+       cfg = hw->common_cfg;
+       IFCVF_WRITE_REG16(vring, &cfg->queue_select);
+       IFCVF_WRITE_REG16(!!state, &cfg->queue_enable);
+
+       if (!state && hw->vring[vring].enable) {
+               ret = vdpa_disable_vfio_intr(internal);
+               if (ret)
+                       return ret;
+       }
+
+       if (state && !hw->vring[vring].enable) {
+               ret = vdpa_enable_vfio_intr(internal, 0);
+               if (ret)
+                       return ret;
+       }
+
+exit:
+       hw->vring[vring].enable = !!state;
+       return 0;
+}
+
 static struct rte_vdpa_dev_ops ifcvf_ops = {
        .get_queue_num = ifcvf_get_queue_num,
        .get_features = ifcvf_get_vdpa_features,
        .get_protocol_features = ifcvf_get_protocol_features,
        .dev_conf = ifcvf_dev_config,
        .dev_close = ifcvf_dev_close,
-       .set_vring_state = NULL,
+       .set_vring_state = ifcvf_set_vring_state,
        .set_features = ifcvf_set_features,
        .migration_done = NULL,
        .get_vfio_group_fd = ifcvf_get_vfio_group_fd,
@@ -1169,6 +1221,7 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
                goto error;
        }
 
+       internal->configured = 0;
        internal->max_queues = IFCVF_MAX_QUEUES;
        features = ifcvf_get_features(&internal->hw);
        internal->features = (features &
@@ -1271,10 +1324,3 @@ static struct rte_pci_driver rte_ifcvf_vdpa = {
 RTE_PMD_REGISTER_PCI(net_ifcvf, rte_ifcvf_vdpa);
 RTE_PMD_REGISTER_PCI_TABLE(net_ifcvf, pci_id_ifcvf_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_ifcvf, "* vfio-pci");
-
-RTE_INIT(ifcvf_vdpa_init_log)
-{
-       ifcvf_vdpa_logtype = rte_log_register("pmd.net.ifcvf_vdpa");
-       if (ifcvf_vdpa_logtype >= 0)
-               rte_log_set_level(ifcvf_vdpa_logtype, RTE_LOG_NOTICE);
-}