@@ -80,7 +80,6 @@ unsigned int mlx5_core_debug_mask;
module_param_named(debug_mask, mlx5_core_debug_mask, uint, 0644);
MODULE_PARM_DESC(debug_mask, "debug mask: 1 = dump cmd data, 2 = dump cmd exec time, 3 = both. Default=0");
-#define MLX5_DEFAULT_PROF 2
static unsigned int prof_sel = MLX5_DEFAULT_PROF;
module_param_named(prof_sel, prof_sel, uint, 0444);
MODULE_PARM_DESC(prof_sel, "profile selector. Valid range 0 - 2");
@@ -1197,8 +1196,8 @@ static void mlx5_unload(struct mlx5_core_dev *dev)
mlx5_put_uars_page(dev, dev->priv.uar);
}
-static int mlx5_load_one(struct mlx5_core_dev *dev, bool boot,
- const struct mlx5_core_dev *irq_dev)
+int mlx5_load_one(struct mlx5_core_dev *dev, bool boot,
+ const struct mlx5_core_dev *irq_dev)
{
int err = 0;
@@ -1256,7 +1255,7 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, bool boot,
return err;
}
-static int mlx5_unload_one(struct mlx5_core_dev *dev, bool cleanup)
+int mlx5_unload_one(struct mlx5_core_dev *dev, bool cleanup)
{
if (cleanup) {
mlx5_unregister_device(dev);
@@ -1288,7 +1287,7 @@ static int mlx5_unload_one(struct mlx5_core_dev *dev, bool cleanup)
return 0;
}
-static int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
+int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
{
struct mlx5_priv *priv = &dev->priv;
int err;
@@ -1334,7 +1333,7 @@ static int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
return err;
}
-static void mlx5_mdev_uninit(struct mlx5_core_dev *dev)
+void mlx5_mdev_uninit(struct mlx5_core_dev *dev)
{
mlx5_pagealloc_cleanup(dev);
mlx5_health_cleanup(dev);
@@ -8,6 +8,7 @@
#include "sf.h"
#include "mlx5_core.h"
#include "eswitch.h"
+#include "devlink.h"
static int
mlx5_cmd_query_sf_partitions(struct mlx5_core_dev *mdev, u32 *out, int outlen)
@@ -205,3 +206,69 @@ u16 mlx5_core_max_sfs(const struct mlx5_core_dev *dev,
{
return mlx5_core_is_sf_supported(dev) ? sf_table->max_sfs : 0;
}
+
+int mlx5_sf_load(struct mlx5_sf *sf, struct device *device,
+ const struct mlx5_core_dev *parent_dev)
+{
+ struct mlx5_core_dev *dev;
+ struct devlink *devlink;
+ int err;
+
+ devlink = mlx5_devlink_alloc();
+ if (!devlink)
+ return -ENOMEM;
+
+ dev = devlink_priv(devlink);
+ dev->device = device;
+ dev->pdev = parent_dev->pdev;
+ dev->bar_addr = sf->base_addr;
+ dev->iseg_base = sf->base_addr;
+ dev->coredev_type = MLX5_COREDEV_SF;
+
+ dev->iseg = ioremap(dev->iseg_base, sizeof(*dev->iseg));
+ if (!dev->iseg) {
+ mlx5_core_warn(dev, "remap error for sf=%d\n", sf->idx);
+ err = -ENOMEM;
+ goto remap_err;
+ }
+
+ err = mlx5_mdev_init(dev, MLX5_DEFAULT_PROF);
+ if (err) {
+ mlx5_core_warn(dev, "mlx5_mdev_init on sf=%d err=%d\n",
+ sf->idx, err);
+ goto mdev_err;
+ }
+
+ err = mlx5_load_one(dev, true, parent_dev);
+ if (err) {
+ mlx5_core_warn(dev, "mlx5_load_one sf=%d err=%d\n",
+ sf->idx, err);
+ goto load_one_err;
+ }
+ err = devlink_register(devlink, device);
+ if (err)
+ goto devlink_err;
+ sf->dev = dev;
+ return 0;
+
+devlink_err:
+ mlx5_unload_one(sf->dev, true);
+load_one_err:
+ mlx5_mdev_uninit(dev);
+mdev_err:
+ iounmap(dev->iseg);
+remap_err:
+ mlx5_devlink_free(devlink);
+ return err;
+}
+
+void mlx5_sf_unload(struct mlx5_sf *sf)
+{
+ struct devlink *devlink = priv_to_devlink(sf->dev);
+
+ devlink_unregister(devlink);
+ mlx5_unload_one(sf->dev, true);
+ mlx5_mdev_uninit(sf->dev);
+ iounmap(sf->dev->iseg);
+ mlx5_devlink_free(devlink);
+}
@@ -9,6 +9,7 @@
#include <linux/idr.h>
struct mlx5_sf {
+ struct mlx5_core_dev *dev;
phys_addr_t base_addr;
u16 idx; /* Index allocated by the SF table bitmap */
};
@@ -50,6 +51,10 @@ u16 mlx5_core_max_sfs(const struct mlx5_core_dev *dev,
u16 mlx5_get_free_sfs(struct mlx5_core_dev *dev,
struct mlx5_sf_table *sf_table);
+int mlx5_sf_load(struct mlx5_sf *sf, struct device *device,
+ const struct mlx5_core_dev *parent_dev);
+void mlx5_sf_unload(struct mlx5_sf *sf);
+
#else
static inline u16 mlx5_core_max_sfs(const struct mlx5_core_dev *dev,
const struct mlx5_sf_table *sf_table)
@@ -116,6 +116,8 @@ enum mlx5_semaphore_space_address {
MLX5_SEMAPHORE_SW_RESET = 0x20,
};
+#define MLX5_DEFAULT_PROF 2
+
int mlx5_query_hca_caps(struct mlx5_core_dev *dev);
int mlx5_query_board_id(struct mlx5_core_dev *dev);
int mlx5_cmd_init_hca(struct mlx5_core_dev *dev, uint32_t *sw_owner_id);
@@ -246,6 +248,12 @@ enum {
u8 mlx5_get_nic_state(struct mlx5_core_dev *dev);
void mlx5_set_nic_state(struct mlx5_core_dev *dev, u8 state);
+int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx);
+void mlx5_mdev_uninit(struct mlx5_core_dev *dev);
+int mlx5_load_one(struct mlx5_core_dev *dev, bool boot,
+ const struct mlx5_core_dev *irq_dev);
+int mlx5_unload_one(struct mlx5_core_dev *dev, bool cleanup);
+
#ifdef CONFIG_MLX5_MDEV
void mlx5_meddev_init(struct mlx5_eswitch *esw);
void mlx5_meddev_cleanup(struct mlx5_eswitch *esw);