Skip to content

Commit e754651

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5: Introduce access functions to modify/query vport state
In preparation for SR-IOV we add here an API to enable each e-switch manager (PF) to configure its VFs link states in e-switch preparation for ethernet sriov. Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: Or Gerlitz <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e16aea2 commit e754651

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void mlx5e_update_carrier(struct mlx5e_priv *priv)
6363
u8 port_state;
6464

6565
port_state = mlx5_query_vport_state(mdev,
66-
MLX5_QUERY_VPORT_STATE_IN_OP_MOD_VNIC_VPORT);
66+
MLX5_QUERY_VPORT_STATE_IN_OP_MOD_VNIC_VPORT, 0);
6767

6868
if (port_state == VPORT_STATE_UP)
6969
netif_carrier_on(priv->netdev);

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

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,75 @@
3636
#include <linux/mlx5/vport.h>
3737
#include "mlx5_core.h"
3838

39-
u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod)
39+
static int _mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod,
40+
u16 vport, u32 *out, int outlen)
4041
{
41-
u32 in[MLX5_ST_SZ_DW(query_vport_state_in)];
42-
u32 out[MLX5_ST_SZ_DW(query_vport_state_out)];
4342
int err;
43+
u32 in[MLX5_ST_SZ_DW(query_vport_state_in)];
4444

4545
memset(in, 0, sizeof(in));
4646

4747
MLX5_SET(query_vport_state_in, in, opcode,
4848
MLX5_CMD_OP_QUERY_VPORT_STATE);
4949
MLX5_SET(query_vport_state_in, in, op_mod, opmod);
50+
MLX5_SET(query_vport_state_in, in, vport_number, vport);
51+
if (vport)
52+
MLX5_SET(query_vport_state_in, in, other_vport, 1);
5053

51-
err = mlx5_cmd_exec_check_status(mdev, in, sizeof(in), out,
52-
sizeof(out));
54+
err = mlx5_cmd_exec_check_status(mdev, in, sizeof(in), out, outlen);
5355
if (err)
5456
mlx5_core_warn(mdev, "MLX5_CMD_OP_QUERY_VPORT_STATE failed\n");
5557

58+
return err;
59+
}
60+
61+
u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport)
62+
{
63+
u32 out[MLX5_ST_SZ_DW(query_vport_state_out)] = {0};
64+
65+
_mlx5_query_vport_state(mdev, opmod, vport, out, sizeof(out));
66+
5667
return MLX5_GET(query_vport_state_out, out, state);
5768
}
58-
EXPORT_SYMBOL(mlx5_query_vport_state);
69+
EXPORT_SYMBOL_GPL(mlx5_query_vport_state);
70+
71+
u8 mlx5_query_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport)
72+
{
73+
u32 out[MLX5_ST_SZ_DW(query_vport_state_out)] = {0};
74+
75+
_mlx5_query_vport_state(mdev, opmod, vport, out, sizeof(out));
76+
77+
return MLX5_GET(query_vport_state_out, out, admin_state);
78+
}
79+
EXPORT_SYMBOL(mlx5_query_vport_admin_state);
80+
81+
int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
82+
u16 vport, u8 state)
83+
{
84+
u32 in[MLX5_ST_SZ_DW(modify_vport_state_in)];
85+
u32 out[MLX5_ST_SZ_DW(modify_vport_state_out)];
86+
int err;
87+
88+
memset(in, 0, sizeof(in));
89+
90+
MLX5_SET(modify_vport_state_in, in, opcode,
91+
MLX5_CMD_OP_MODIFY_VPORT_STATE);
92+
MLX5_SET(modify_vport_state_in, in, op_mod, opmod);
93+
MLX5_SET(modify_vport_state_in, in, vport_number, vport);
94+
95+
if (vport)
96+
MLX5_SET(modify_vport_state_in, in, other_vport, 1);
97+
98+
MLX5_SET(modify_vport_state_in, in, admin_state, state);
99+
100+
err = mlx5_cmd_exec_check_status(mdev, in, sizeof(in), out,
101+
sizeof(out));
102+
if (err)
103+
mlx5_core_warn(mdev, "MLX5_CMD_OP_MODIFY_VPORT_STATE failed\n");
104+
105+
return err;
106+
}
107+
EXPORT_SYMBOL(mlx5_modify_vport_admin_state);
59108

60109
static int mlx5_query_nic_vport_context(struct mlx5_core_dev *mdev, u16 vport,
61110
u32 *out, int outlen)

include/linux/mlx5/mlx5_ifc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,6 +2946,7 @@ struct mlx5_ifc_query_vport_state_out_bits {
29462946

29472947
enum {
29482948
MLX5_QUERY_VPORT_STATE_IN_OP_MOD_VNIC_VPORT = 0x0,
2949+
MLX5_QUERY_VPORT_STATE_IN_OP_MOD_ESW_VPORT = 0x1,
29492950
};
29502951

29512952
struct mlx5_ifc_query_vport_state_in_bits {

include/linux/mlx5/vport.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
#include <linux/mlx5/driver.h>
3737
#include <linux/mlx5/device.h>
3838

39-
u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod);
39+
u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport);
40+
u8 mlx5_query_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
41+
u16 vport);
42+
int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
43+
u16 vport, u8 state);
4044
int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
4145
u16 vport, u8 *addr);
4246
int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *dev,

0 commit comments

Comments
 (0)