Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net/mlx5: Support devlink port state for host PF

Add support for devlink port function state get/set operations for the
host physical function (PF). Until now, mlx5 only allowed state get/set
for subfunctions (SFs) ports. This change enables an administrator with
eSwitch manager privileges to query or modify the host PF’s function
state, allowing it to be explicitly inactivated or activated. While
inactivated, the administrator can modify the functions attributes, such
as enable/disable roce.

$ devlink port show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608: type eth netdev eth1 flavour pcipf controller 1 pfnum 0 external true splittable false
function:
hw_addr a0:88:c2:45:17:7c state active opstate attached roce enable max_io_eqs 120
$ devlink port function set pci/0000:03:00.0/196608 state inactive
$ devlink port show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608: type eth netdev eth1 flavour pcipf controller 1 pfnum 0 external true splittable false
function:
hw_addr a0:88:c2:45:17:7c state inactive opstate detached roce enable max_io_eqs 120

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260203102402.1712218-1-tariqt@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Moshe Shemesh and committed by
Paolo Abeni
0e6c95c9 021718d2

+108 -12
+3 -2
drivers/net/ethernet/mellanox/mlx5/core/ecpf.c
··· 2 2 /* Copyright (c) 2019 Mellanox Technologies. */ 3 3 4 4 #include "ecpf.h" 5 + #include "eswitch.h" 5 6 6 7 bool mlx5_read_embedded_cpu(struct mlx5_core_dev *dev) 7 8 { ··· 50 49 /* ECPF shall enable HCA for host PF in the same way a PF 51 50 * does this for its VFs when ECPF is not a eswitch manager. 52 51 */ 53 - err = mlx5_cmd_host_pf_enable_hca(dev); 52 + err = mlx5_esw_host_pf_enable_hca(dev); 54 53 if (err) 55 54 mlx5_core_err(dev, "Failed to enable external host PF HCA err(%d)\n", err); 56 55 ··· 64 63 if (mlx5_ecpf_esw_admins_host_pf(dev)) 65 64 return; 66 65 67 - err = mlx5_cmd_host_pf_disable_hca(dev); 66 + err = mlx5_esw_host_pf_disable_hca(dev); 68 67 if (err) { 69 68 mlx5_core_err(dev, "Failed to disable external host PF HCA err(%d)\n", err); 70 69 return;
+38 -10
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
··· 1304 1304 return err; 1305 1305 } 1306 1306 1307 - static int host_pf_enable_hca(struct mlx5_core_dev *dev) 1307 + int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev) 1308 1308 { 1309 - if (!mlx5_core_is_ecpf(dev)) 1309 + struct mlx5_eswitch *esw = dev->priv.eswitch; 1310 + struct mlx5_vport *vport; 1311 + int err; 1312 + 1313 + if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw)) 1310 1314 return 0; 1315 + 1316 + vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_PF); 1317 + if (IS_ERR(vport)) 1318 + return PTR_ERR(vport); 1311 1319 1312 1320 /* Once vport and representor are ready, take out the external host PF 1313 1321 * out of initializing state. Enabling HCA clears the iser->initializing 1314 1322 * bit and host PF driver loading can progress. 1315 1323 */ 1316 - return mlx5_cmd_host_pf_enable_hca(dev); 1324 + err = mlx5_cmd_host_pf_enable_hca(dev); 1325 + if (err) 1326 + return err; 1327 + 1328 + vport->pf_activated = true; 1329 + 1330 + return 0; 1317 1331 } 1318 1332 1319 - static void host_pf_disable_hca(struct mlx5_core_dev *dev) 1333 + int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev) 1320 1334 { 1321 - if (!mlx5_core_is_ecpf(dev)) 1322 - return; 1335 + struct mlx5_eswitch *esw = dev->priv.eswitch; 1336 + struct mlx5_vport *vport; 1337 + int err; 1323 1338 1324 - mlx5_cmd_host_pf_disable_hca(dev); 1339 + if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw)) 1340 + return 0; 1341 + 1342 + vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_PF); 1343 + if (IS_ERR(vport)) 1344 + return PTR_ERR(vport); 1345 + 1346 + err = mlx5_cmd_host_pf_disable_hca(dev); 1347 + if (err) 1348 + return err; 1349 + 1350 + vport->pf_activated = false; 1351 + 1352 + return 0; 1325 1353 } 1326 1354 1327 1355 /* mlx5_eswitch_enable_pf_vf_vports() enables vports of PF, ECPF and VFs ··· 1375 1347 1376 1348 if (mlx5_esw_host_functions_enabled(esw->dev)) { 1377 1349 /* Enable external host PF HCA */ 1378 - ret = host_pf_enable_hca(esw->dev); 1350 + ret = mlx5_esw_host_pf_enable_hca(esw->dev); 1379 1351 if (ret) 1380 1352 goto pf_hca_err; 1381 1353 } ··· 1419 1391 mlx5_eswitch_unload_pf_vf_vport(esw, MLX5_VPORT_ECPF); 1420 1392 ecpf_err: 1421 1393 if (mlx5_esw_host_functions_enabled(esw->dev)) 1422 - host_pf_disable_hca(esw->dev); 1394 + mlx5_esw_host_pf_disable_hca(esw->dev); 1423 1395 pf_hca_err: 1424 1396 if (pf_needed && mlx5_esw_host_functions_enabled(esw->dev)) 1425 1397 mlx5_eswitch_unload_pf_vf_vport(esw, MLX5_VPORT_PF); ··· 1444 1416 } 1445 1417 1446 1418 if (mlx5_esw_host_functions_enabled(esw->dev)) 1447 - host_pf_disable_hca(esw->dev); 1419 + mlx5_esw_host_pf_disable_hca(esw->dev); 1448 1420 1449 1421 if ((mlx5_core_is_ecpf_esw_manager(esw->dev) || 1450 1422 esw->mode == MLX5_ESWITCH_LEGACY) &&
+10
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
··· 243 243 u16 vport; 244 244 bool enabled; 245 245 bool max_eqs_set; 246 + bool pf_activated; 246 247 enum mlx5_eswitch_vport_event enabled_events; 247 248 int index; 248 249 struct mlx5_devlink_port *dl_port; ··· 588 587 struct netlink_ext_ack *extack); 589 588 int mlx5_devlink_port_fn_migratable_set(struct devlink_port *port, bool enable, 590 589 struct netlink_ext_ack *extack); 590 + int mlx5_devlink_pf_port_fn_state_get(struct devlink_port *port, 591 + enum devlink_port_fn_state *state, 592 + enum devlink_port_fn_opstate *opstate, 593 + struct netlink_ext_ack *extack); 594 + int mlx5_devlink_pf_port_fn_state_set(struct devlink_port *port, 595 + enum devlink_port_fn_state state, 596 + struct netlink_ext_ack *extack); 591 597 #ifdef CONFIG_XFRM_OFFLOAD 592 598 int mlx5_devlink_port_fn_ipsec_crypto_get(struct devlink_port *port, bool *is_enabled, 593 599 struct netlink_ext_ack *extack); ··· 642 634 struct mlx5_core_dev *dev1); 643 635 644 636 const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev); 637 + int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev); 638 + int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev); 645 639 646 640 void mlx5_esw_adjacent_vhcas_setup(struct mlx5_eswitch *esw); 647 641 void mlx5_esw_adjacent_vhcas_cleanup(struct mlx5_eswitch *esw);
+55
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
··· 4696 4696 return err; 4697 4697 } 4698 4698 4699 + int mlx5_devlink_pf_port_fn_state_get(struct devlink_port *port, 4700 + enum devlink_port_fn_state *state, 4701 + enum devlink_port_fn_opstate *opstate, 4702 + struct netlink_ext_ack *extack) 4703 + { 4704 + struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port); 4705 + const u32 *query_out; 4706 + bool pf_disabled; 4707 + 4708 + if (vport->vport != MLX5_VPORT_PF) { 4709 + NL_SET_ERR_MSG_MOD(extack, "State get is not supported for VF"); 4710 + return -EOPNOTSUPP; 4711 + } 4712 + 4713 + *state = vport->pf_activated ? 4714 + DEVLINK_PORT_FN_STATE_ACTIVE : DEVLINK_PORT_FN_STATE_INACTIVE; 4715 + 4716 + query_out = mlx5_esw_query_functions(vport->dev); 4717 + if (IS_ERR(query_out)) 4718 + return PTR_ERR(query_out); 4719 + 4720 + pf_disabled = MLX5_GET(query_esw_functions_out, query_out, 4721 + host_params_context.host_pf_disabled); 4722 + 4723 + *opstate = pf_disabled ? DEVLINK_PORT_FN_OPSTATE_DETACHED : 4724 + DEVLINK_PORT_FN_OPSTATE_ATTACHED; 4725 + 4726 + kvfree(query_out); 4727 + return 0; 4728 + } 4729 + 4730 + int mlx5_devlink_pf_port_fn_state_set(struct devlink_port *port, 4731 + enum devlink_port_fn_state state, 4732 + struct netlink_ext_ack *extack) 4733 + { 4734 + struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port); 4735 + struct mlx5_core_dev *dev; 4736 + 4737 + if (vport->vport != MLX5_VPORT_PF) { 4738 + NL_SET_ERR_MSG_MOD(extack, "State set is not supported for VF"); 4739 + return -EOPNOTSUPP; 4740 + } 4741 + 4742 + dev = vport->dev; 4743 + 4744 + switch (state) { 4745 + case DEVLINK_PORT_FN_STATE_ACTIVE: 4746 + return mlx5_esw_host_pf_enable_hca(dev); 4747 + case DEVLINK_PORT_FN_STATE_INACTIVE: 4748 + return mlx5_esw_host_pf_disable_hca(dev); 4749 + default: 4750 + return -EOPNOTSUPP; 4751 + } 4752 + } 4753 + 4699 4754 int 4700 4755 mlx5_eswitch_restore_ipsec_rule(struct mlx5_eswitch *esw, struct mlx5_flow_handle *rule, 4701 4756 struct mlx5_esw_flow_attr *esw_attr, int attr_idx)