@@ -77,4 +77,4 @@ mlx5_core-$(CONFIG_MLX5_SW_STEERING) += steering/dr_domain.o steering/dr_table.o
#
# Mdev basic
#
-mlx5_core-$(CONFIG_MLX5_MDEV) += meddev/sf.o meddev/mdev.o
+mlx5_core-$(CONFIG_MLX5_MDEV) += meddev/sf.o meddev/mdev.o meddev/mdev_driver.o
@@ -40,6 +40,9 @@
#include <linux/io-mapping.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
+#ifdef CONFIG_MLX5_MDEV
+#include <linux/mdev.h>
+#endif
#include <linux/mlx5/driver.h>
#include <linux/mlx5/cq.h>
#include <linux/mlx5/qp.h>
@@ -1653,7 +1656,11 @@ static int __init init(void)
mlx5e_init();
#endif
- return 0;
+ err = mlx5_meddev_register_driver();
+ if (err) {
+ pci_unregister_driver(&mlx5_core_driver);
+ goto err_debug;
+ }
err_debug:
mlx5_unregister_debugfs();
@@ -1662,6 +1669,8 @@ static int __init init(void)
static void __exit cleanup(void)
{
+ mlx5_meddev_unregister_driver();
+
#ifdef CONFIG_MLX5_CORE_EN
mlx5e_cleanup();
#endif
new file mode 100644
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-19 Mellanox Technologies
+
+#include <linux/module.h>
+#include <net/devlink.h>
+#include <linux/mdev.h>
+
+#include "mlx5_core.h"
+#include "meddev/sf.h"
+
+static int mlx5_meddev_probe(struct device *dev)
+{
+ struct mdev_device *meddev = mdev_from_dev(dev);
+ struct mlx5_core_dev *parent_coredev;
+ struct device *parent_dev;
+ struct mlx5_sf *sf;
+
+ parent_dev = mdev_parent_dev(meddev);
+ parent_coredev = mlx5_get_core_dev(parent_dev);
+ if (!parent_coredev)
+ return -ENODEV;
+
+ sf = mdev_get_drvdata(meddev);
+
+ return mlx5_sf_load(sf, dev, parent_coredev);
+}
+
+static void mlx5_meddev_remove(struct device *dev)
+{
+ struct mdev_device *meddev = mdev_from_dev(dev);
+ struct mlx5_sf *sf = mdev_get_drvdata(meddev);
+
+ mlx5_sf_unload(sf);
+}
+
+static struct mdev_driver mlx5_meddev_driver = {
+ .name = KBUILD_MODNAME,
+ .probe = mlx5_meddev_probe,
+ .remove = mlx5_meddev_remove,
+};
+
+int mlx5_meddev_register_driver(void)
+{
+ return mdev_register_driver(&mlx5_meddev_driver, THIS_MODULE);
+}
+
+void mlx5_meddev_unregister_driver(void)
+{
+ mdev_unregister_driver(&mlx5_meddev_driver);
+}
@@ -260,6 +260,9 @@ void mlx5_meddev_cleanup(struct mlx5_eswitch *esw);
int mlx5_meddev_register(struct mlx5_eswitch *esw);
void mlx5_meddev_unregister(struct mlx5_eswitch *esw);
bool mlx5_meddev_can_and_mark_cleanup(struct mlx5_eswitch *esw);
+
+int mlx5_meddev_register_driver(void);
+void mlx5_meddev_unregister_driver(void);
#else
static inline void mlx5_meddev_init(struct mlx5_core_dev *dev)
{
@@ -282,6 +285,15 @@ static inline bool mlx5_meddev_can_and_mark_cleanup(struct mlx5_eswitch *esw)
{
return true;
}
+
+static inline int mlx5_meddev_register_driver(void)
+{
+ return 0;
+}
+
+static inline void mlx5_meddev_unregister_driver(void)
+{
+}
#endif
struct mlx5_core_dev *mlx5_get_core_dev(const struct device *dev);