Skip to content

Commit 6a32732

Browse files
paravmellanoxSaeed Mahameed
authored andcommitted
net/mlx5: SF, Port function state change support
Support changing the state of the SF port's function through devlink. When activating the SF port's function, enable the hca in the device followed by adding its auxiliary device. When deactivating the SF port's function, delete its auxiliary device followed by disabling the vHCA. Port function attributes get/set callbacks are invoked with devlink instance lock held. Such callbacks need to synchronize with sf port table getting disabled either via sriov sysfs callback. Such callbacks synchronize with table disable context holding table refcount. $ devlink dev eswitch set pci/0000:06:00.0 mode switchdev $ devlink port show pci/0000:06:00.0/65535: type eth netdev ens2f0np0 flavour physical port 0 splittable false $ devlink port add pci/0000:06:00.0 flavour pcisf pfnum 0 sfnum 88 pci/0000:06:00.0/32768: type eth netdev eth6 flavour pcisf controller 0 pfnum 0 sfnum 88 external false splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached $ devlink port show ens2f0npf0sf88 pci/0000:06:00.0/32768: type eth netdev ens2f0npf0sf88 flavour pcisf controller 0 pfnum 0 sfnum 88 external false splittable false function: hw_addr 00:00:00:00:88:88 state inactive opstate detached $ devlink port function set pci/0000:06:00.0/32768 hw_addr 00:00:00:00:88:88 state active $ devlink port show ens2f0npf0sf88 -jp { "port": { "pci/0000:06:00.0/32768": { "type": "eth", "netdev": "ens2f0npf0sf88", "flavour": "pcisf", "controller": 0, "pfnum": 0, "sfnum": 88, "external": false, "splittable": false, "function": { "hw_addr": "00:00:00:00:88:88", "state": "active", "opstate": "attached" } } } } On port function activation, an auxiliary device is created in below example. $ devlink dev show devlink dev show auxiliary/mlx5_core.sf.4 $ devlink port show auxiliary/mlx5_core.sf.4/1 auxiliary/mlx5_core.sf.4/1: type eth netdev p0sf88 flavour virtual port 0 splittable false Signed-off-by: Parav Pandit <[email protected]> Reviewed-by: Vu Pham <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 8f01054 commit 6a32732

File tree

7 files changed

+431
-27
lines changed

7 files changed

+431
-27
lines changed

drivers/net/ethernet/mellanox/mlx5/core/devlink.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ static const struct devlink_ops mlx5_devlink_ops = {
195195
#ifdef CONFIG_MLX5_SF_MANAGER
196196
.port_new = mlx5_devlink_sf_port_new,
197197
.port_del = mlx5_devlink_sf_port_del,
198+
.port_fn_state_get = mlx5_devlink_sf_port_fn_state_get,
199+
.port_fn_state_set = mlx5_devlink_sf_port_fn_state_set,
198200
#endif
199201
.flash_update = mlx5_devlink_flash_update,
200202
.info_get = mlx5_devlink_info_get,

drivers/net/ethernet/mellanox/mlx5/core/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include "diag/rsc_dump.h"
7676
#include "sf/vhca_event.h"
7777
#include "sf/dev/dev.h"
78+
#include "sf/sf.h"
7879

7980
MODULE_AUTHOR("Eli Cohen <[email protected]>");
8081
MODULE_DESCRIPTION("Mellanox 5th generation network adapters (ConnectX series) core driver");
@@ -1161,6 +1162,12 @@ static int mlx5_load(struct mlx5_core_dev *dev)
11611162

11621163
mlx5_vhca_event_start(dev);
11631164

1165+
err = mlx5_sf_hw_table_create(dev);
1166+
if (err) {
1167+
mlx5_core_err(dev, "sf table create failed %d\n", err);
1168+
goto err_vhca;
1169+
}
1170+
11641171
err = mlx5_ec_init(dev);
11651172
if (err) {
11661173
mlx5_core_err(dev, "Failed to init embedded CPU\n");
@@ -1180,6 +1187,8 @@ static int mlx5_load(struct mlx5_core_dev *dev)
11801187
err_sriov:
11811188
mlx5_ec_cleanup(dev);
11821189
err_ec:
1190+
mlx5_sf_hw_table_destroy(dev);
1191+
err_vhca:
11831192
mlx5_vhca_event_stop(dev);
11841193
mlx5_cleanup_fs(dev);
11851194
err_fs:
@@ -1209,6 +1218,7 @@ static void mlx5_unload(struct mlx5_core_dev *dev)
12091218
mlx5_sf_dev_table_destroy(dev);
12101219
mlx5_sriov_detach(dev);
12111220
mlx5_ec_cleanup(dev);
1221+
mlx5_sf_hw_table_destroy(dev);
12121222
mlx5_vhca_event_stop(dev);
12131223
mlx5_cleanup_fs(dev);
12141224
mlx5_accel_ipsec_cleanup(dev);

drivers/net/ethernet/mellanox/mlx5/core/sf/cmd.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,25 @@ int mlx5_cmd_dealloc_sf(struct mlx5_core_dev *dev, u16 function_id)
2525

2626
return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
2727
}
28+
29+
int mlx5_cmd_sf_enable_hca(struct mlx5_core_dev *dev, u16 func_id)
30+
{
31+
u32 out[MLX5_ST_SZ_DW(enable_hca_out)] = {};
32+
u32 in[MLX5_ST_SZ_DW(enable_hca_in)] = {};
33+
34+
MLX5_SET(enable_hca_in, in, opcode, MLX5_CMD_OP_ENABLE_HCA);
35+
MLX5_SET(enable_hca_in, in, function_id, func_id);
36+
MLX5_SET(enable_hca_in, in, embedded_cpu_function, 0);
37+
return mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out));
38+
}
39+
40+
int mlx5_cmd_sf_disable_hca(struct mlx5_core_dev *dev, u16 func_id)
41+
{
42+
u32 out[MLX5_ST_SZ_DW(disable_hca_out)] = {};
43+
u32 in[MLX5_ST_SZ_DW(disable_hca_in)] = {};
44+
45+
MLX5_SET(disable_hca_in, in, opcode, MLX5_CMD_OP_DISABLE_HCA);
46+
MLX5_SET(disable_hca_in, in, function_id, func_id);
47+
MLX5_SET(enable_hca_in, in, embedded_cpu_function, 0);
48+
return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
49+
}

0 commit comments

Comments
 (0)