Commit feae9087 authored by Or Gerlitz's avatar Or Gerlitz Committed by David S. Miller

net/mlx5: Add devlink interface

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: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 08f4b591
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
config MLX5_CORE config MLX5_CORE
tristate "Mellanox Technologies ConnectX-4 and Connect-IB core driver" tristate "Mellanox Technologies ConnectX-4 and Connect-IB core driver"
depends on MAY_USE_DEVLINK
depends on PCI depends on PCI
default n default n
---help--- ---help---
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <linux/if_ether.h> #include <linux/if_ether.h>
#include <linux/if_link.h> #include <linux/if_link.h>
#include <net/devlink.h>
#include <linux/mlx5/device.h> #include <linux/mlx5/device.h>
#define MLX5_MAX_UC_PER_VPORT(dev) \ #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 ...@@ -205,6 +206,9 @@ mlx5_eswitch_add_send_to_vport_rule(struct mlx5_eswitch *esw, int vport, u32 sqn
struct mlx5_flow_rule * struct mlx5_flow_rule *
mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, int vport, u32 tirn); 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 MLX5_DEBUG_ESWITCH_MASK BIT(3)
#define esw_info(dev, format, ...) \ #define esw_info(dev, format, ...) \
......
...@@ -328,3 +328,13 @@ mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, int vport, u32 tirn) ...@@ -328,3 +328,13 @@ mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, int vport, u32 tirn)
kfree(match_c); kfree(match_c);
return flow_rule; 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;
}
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#ifdef CONFIG_RFS_ACCEL #ifdef CONFIG_RFS_ACCEL
#include <linux/cpu_rmap.h> #include <linux/cpu_rmap.h>
#endif #endif
#include <net/devlink.h>
#include "mlx5_core.h" #include "mlx5_core.h"
#include "fs_core.h" #include "fs_core.h"
#ifdef CONFIG_MLX5_CORE_EN #ifdef CONFIG_MLX5_CORE_EN
...@@ -1315,19 +1316,28 @@ struct mlx5_core_event_handler { ...@@ -1315,19 +1316,28 @@ struct mlx5_core_event_handler {
void *data); 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, static int init_one(struct pci_dev *pdev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
struct mlx5_core_dev *dev; struct mlx5_core_dev *dev;
struct devlink *devlink;
struct mlx5_priv *priv; struct mlx5_priv *priv;
int err; int err;
dev = kzalloc(sizeof(*dev), GFP_KERNEL); devlink = devlink_alloc(&mlx5_devlink_ops, sizeof(*dev));
if (!dev) { if (!devlink) {
dev_err(&pdev->dev, "kzalloc failed\n"); dev_err(&pdev->dev, "kzalloc failed\n");
return -ENOMEM; return -ENOMEM;
} }
dev = devlink_priv(devlink);
priv = &dev->priv; priv = &dev->priv;
priv->pci_dev_data = id->driver_data; priv->pci_dev_data = id->driver_data;
...@@ -1364,15 +1374,21 @@ static int init_one(struct pci_dev *pdev, ...@@ -1364,15 +1374,21 @@ static int init_one(struct pci_dev *pdev,
goto clean_health; goto clean_health;
} }
err = devlink_register(devlink, &pdev->dev);
if (err)
goto clean_load;
return 0; return 0;
clean_load:
mlx5_unload_one(dev, priv);
clean_health: clean_health:
mlx5_health_cleanup(dev); mlx5_health_cleanup(dev);
close_pci: close_pci:
mlx5_pci_close(dev, priv); mlx5_pci_close(dev, priv);
clean_dev: clean_dev:
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
kfree(dev); devlink_free(devlink);
return err; return err;
} }
...@@ -1380,8 +1396,10 @@ static int init_one(struct pci_dev *pdev, ...@@ -1380,8 +1396,10 @@ static int init_one(struct pci_dev *pdev,
static void remove_one(struct pci_dev *pdev) static void remove_one(struct pci_dev *pdev)
{ {
struct mlx5_core_dev *dev = pci_get_drvdata(pdev); struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
struct devlink *devlink = priv_to_devlink(dev);
struct mlx5_priv *priv = &dev->priv; struct mlx5_priv *priv = &dev->priv;
devlink_unregister(devlink);
if (mlx5_unload_one(dev, priv)) { if (mlx5_unload_one(dev, priv)) {
dev_err(&dev->pdev->dev, "mlx5_unload_one failed\n"); dev_err(&dev->pdev->dev, "mlx5_unload_one failed\n");
mlx5_health_cleanup(dev); mlx5_health_cleanup(dev);
...@@ -1390,7 +1408,7 @@ static void remove_one(struct pci_dev *pdev) ...@@ -1390,7 +1408,7 @@ static void remove_one(struct pci_dev *pdev)
mlx5_health_cleanup(dev); mlx5_health_cleanup(dev);
mlx5_pci_close(dev, priv); mlx5_pci_close(dev, priv);
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
kfree(dev); devlink_free(devlink);
} }
static pci_ers_result_t mlx5_pci_err_detected(struct pci_dev *pdev, static pci_ers_result_t mlx5_pci_err_detected(struct pci_dev *pdev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment