> Add .unplug callback to handle driver removal, device unmapping, and
> interrupt cleanup. This enables use of the generic bus cleanup helper.
> 
> The cleanup function was already performing these operations, so it seems
> safe to expose them through the unplug operation.
> 
> Signed-off-by: David Marchand <[email protected]>

Reviewed-by: Long Li <[email protected]>


> ---
>  doc/guides/rel_notes/release_26_07.rst |  4 +++
>  drivers/bus/vmbus/vmbus_common.c       | 41 ++++++++++++--------------
>  2 files changed, 23 insertions(+), 22 deletions(-)
> 
> diff --git a/doc/guides/rel_notes/release_26_07.rst
> b/doc/guides/rel_notes/release_26_07.rst
> index 5d7aa8d1bf..55d3b44527 100644
> --- a/doc/guides/rel_notes/release_26_07.rst
> +++ b/doc/guides/rel_notes/release_26_07.rst
> @@ -114,6 +114,10 @@ New Features
> 
>    Added no-IOMMU mode for devices without or not enabling IOMMU/SVA.
> 
> +* **Added unplug operation support to VMBUS bus.**
> +
> +  Implemented device unplug operation to allow runtime removal of VMBUS
> devices.
> +
>  * **Added selective Rx in ethdev API.**
> 
>    Some parts of packets may be discarded in Rx diff --git
> a/drivers/bus/vmbus/vmbus_common.c
> b/drivers/bus/vmbus/vmbus_common.c
> index a6e3a24a7c..cd6e851e4c 100644
> --- a/drivers/bus/vmbus/vmbus_common.c
> +++ b/drivers/bus/vmbus/vmbus_common.c
> @@ -144,34 +144,29 @@ rte_vmbus_probe(void)  }
> 
>  static int
> -rte_vmbus_cleanup(struct rte_bus *bus)
> +vmbus_unplug_device(struct rte_device *rte_dev)
>  {
> -     struct rte_vmbus_device *dev;
> -     int error = 0;
> -
> -     RTE_BUS_FOREACH_DEV(dev, bus) {
> -             const struct rte_vmbus_driver *drv;
> -             int ret;
> -
> -             if (!rte_dev_is_probed(&dev->device))
> -                     continue;
> -             drv = RTE_BUS_DRIVER(dev->device.driver, *drv);
> -             if (drv->remove == NULL)
> -                     continue;
> +     const struct rte_vmbus_driver *drv = RTE_BUS_DRIVER(rte_dev-
> >driver, *drv);
> +     struct rte_vmbus_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
> +     int ret = 0;
> 
> +     if (drv->remove != NULL) {
>               ret = drv->remove(dev);
>               if (ret < 0)
> -                     error = -1;
> +                     return ret;
> +     }
> 
> -             rte_vmbus_unmap_device(dev);
> -             rte_intr_instance_free(dev->intr_handle);
> +     rte_vmbus_unmap_device(dev);
> +     rte_intr_instance_free(dev->intr_handle);
> +     dev->intr_handle = NULL;
> 
> -             dev->device.driver = NULL;
> -             rte_bus_remove_device(bus, &dev->device);
> -             free(dev);
> -     }
> +     return 0;
> +}
> 
> -     return error;
> +static void
> +vmbus_free_device(struct rte_device *dev) {
> +     free(RTE_BUS_DEVICE(dev, struct rte_vmbus_device));
>  }
> 
>  static int
> @@ -222,10 +217,12 @@ rte_vmbus_unregister(struct rte_vmbus_driver
> *driver)  struct rte_bus rte_vmbus_bus = {
>       .scan = rte_vmbus_scan,
>       .probe = rte_bus_generic_probe,
> -     .cleanup = rte_vmbus_cleanup,
> +     .free_device = vmbus_free_device,
> +     .cleanup = rte_bus_generic_cleanup,
>       .find_device = rte_bus_generic_find_device,
>       .match = vmbus_bus_match,
>       .probe_device = vmbus_probe_device,
> +     .unplug_device = vmbus_unplug_device,
>       .parse = vmbus_parse,
>       .dev_compare = vmbus_dev_compare,
>  };
> --
> 2.54.0

Reply via email to