]> git.karo-electronics.de Git - linux-beck.git/commitdiff
net/mlx5: Add devlink interface
authorOr Gerlitz <ogerlitz@mellanox.com>
Fri, 1 Jul 2016 11:51:02 +0000 (14:51 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sat, 2 Jul 2016 18:40:40 +0000 (14:40 -0400)
The devlink interface is initially used to set/get the mode of the SRIOV e-switch.

Currently, these are only stubs for get/set, down-stream patch will actually
fill them out.

Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/Kconfig
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
drivers/net/ethernet/mellanox/mlx5/core/main.c

index 1cf722eba607d82e8e34ff498e1b154f8fc8cc5d..aae46884bf93c949325e4bba26316cb9f69e078a 100644 (file)
@@ -4,6 +4,7 @@
 
 config MLX5_CORE
        tristate "Mellanox Technologies ConnectX-4 and Connect-IB core driver"
+       depends on MAY_USE_DEVLINK
        depends on PCI
        default n
        ---help---
index cf959f7b0bea80d0bb14d2e3df33f4f54a71bd3d..7843f981509da1e7eb8e0f3116da967358754da7 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <linux/if_ether.h>
 #include <linux/if_link.h>
+#include <net/devlink.h>
 #include <linux/mlx5/device.h>
 
 #define MLX5_MAX_UC_PER_VPORT(dev) \
@@ -205,6 +206,9 @@ mlx5_eswitch_add_send_to_vport_rule(struct mlx5_eswitch *esw, int vport, u32 sqn
 struct mlx5_flow_rule *
 mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, int vport, u32 tirn);
 
+int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode);
+int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode);
+
 #define MLX5_DEBUG_ESWITCH_MASK BIT(3)
 
 #define esw_info(dev, format, ...)                             \
index 7aad3671a399eebbbff5ef5d9fc4593e6292e2bb..e1727a9b9bcf231e75775299663e06f7438a18ff 100644 (file)
@@ -328,3 +328,13 @@ out:
        kfree(match_c);
        return flow_rule;
 }
+
+int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode)
+{
+       return -EOPNOTSUPP;
+}
+
+int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode)
+{
+       return -EOPNOTSUPP;
+}
index 1f3b6d6a852e1e01b530c00c53d3c00a03f30062..1fb3c681df978cfc49ba5536148cb0ecf26dee3f 100644 (file)
@@ -51,6 +51,7 @@
 #ifdef CONFIG_RFS_ACCEL
 #include <linux/cpu_rmap.h>
 #endif
+#include <net/devlink.h>
 #include "mlx5_core.h"
 #include "fs_core.h"
 #ifdef CONFIG_MLX5_CORE_EN
@@ -1315,19 +1316,28 @@ struct mlx5_core_event_handler {
                      void *data);
 };
 
+static const struct devlink_ops mlx5_devlink_ops = {
+#ifdef CONFIG_MLX5_CORE_EN
+       .eswitch_mode_set = mlx5_devlink_eswitch_mode_set,
+       .eswitch_mode_get = mlx5_devlink_eswitch_mode_get,
+#endif
+};
 
 static int init_one(struct pci_dev *pdev,
                    const struct pci_device_id *id)
 {
        struct mlx5_core_dev *dev;
+       struct devlink *devlink;
        struct mlx5_priv *priv;
        int err;
 
-       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-       if (!dev) {
+       devlink = devlink_alloc(&mlx5_devlink_ops, sizeof(*dev));
+       if (!devlink) {
                dev_err(&pdev->dev, "kzalloc failed\n");
                return -ENOMEM;
        }
+
+       dev = devlink_priv(devlink);
        priv = &dev->priv;
        priv->pci_dev_data = id->driver_data;
 
@@ -1364,15 +1374,21 @@ static int init_one(struct pci_dev *pdev,
                goto clean_health;
        }
 
+       err = devlink_register(devlink, &pdev->dev);
+       if (err)
+               goto clean_load;
+
        return 0;
 
+clean_load:
+       mlx5_unload_one(dev, priv);
 clean_health:
        mlx5_health_cleanup(dev);
 close_pci:
        mlx5_pci_close(dev, priv);
 clean_dev:
        pci_set_drvdata(pdev, NULL);
-       kfree(dev);
+       devlink_free(devlink);
 
        return err;
 }
@@ -1380,8 +1396,10 @@ clean_dev:
 static void remove_one(struct pci_dev *pdev)
 {
        struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
+       struct devlink *devlink = priv_to_devlink(dev);
        struct mlx5_priv *priv = &dev->priv;
 
+       devlink_unregister(devlink);
        if (mlx5_unload_one(dev, priv)) {
                dev_err(&dev->pdev->dev, "mlx5_unload_one failed\n");
                mlx5_health_cleanup(dev);
@@ -1390,7 +1408,7 @@ static void remove_one(struct pci_dev *pdev)
        mlx5_health_cleanup(dev);
        mlx5_pci_close(dev, priv);
        pci_set_drvdata(pdev, NULL);
-       kfree(dev);
+       devlink_free(devlink);
 }
 
 static pci_ers_result_t mlx5_pci_err_detected(struct pci_dev *pdev,