Skip to content

Commit e1d7d34

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5: Update access functions to Query/Modify vport MAC address
In preparation for SR-IOV we add here an API to enable each e-switch client (PF/VF) to configure its L2 MAC addresses and for the e-switch manager (usually the PF) to access them in order to be able to configure them into the e-switch. Therefore we now pass vport num parameter to mlx5_query_nic_vport_context, so PF can access other vports contexts. preperation for ethernet sriov and l2 table management. Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 54f0a41 commit e1d7d34

File tree

3 files changed

+81
-13
lines changed

3 files changed

+81
-13
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
@@ -2028,7 +2028,7 @@ static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
20282028
{
20292029
struct mlx5e_priv *priv = netdev_priv(netdev);
20302030

2031-
mlx5_query_nic_vport_mac_address(priv->mdev, netdev->dev_addr);
2031+
mlx5_query_nic_vport_mac_address(priv->mdev, 0, netdev->dev_addr);
20322032
}
20332033

20342034
static void mlx5e_build_netdev(struct net_device *netdev)

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

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,98 @@ u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod)
5757
}
5858
EXPORT_SYMBOL(mlx5_query_vport_state);
5959

60-
void mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev, u8 *addr)
60+
static int mlx5_query_nic_vport_context(struct mlx5_core_dev *mdev, u16 vport,
61+
u32 *out, int outlen)
62+
{
63+
u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)];
64+
65+
memset(in, 0, sizeof(in));
66+
67+
MLX5_SET(query_nic_vport_context_in, in, opcode,
68+
MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
69+
70+
MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
71+
if (vport)
72+
MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
73+
74+
return mlx5_cmd_exec_check_status(mdev, in, sizeof(in), out, outlen);
75+
}
76+
77+
static int mlx5_modify_nic_vport_context(struct mlx5_core_dev *mdev, void *in,
78+
int inlen)
79+
{
80+
u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
81+
82+
MLX5_SET(modify_nic_vport_context_in, in, opcode,
83+
MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
84+
85+
memset(out, 0, sizeof(out));
86+
return mlx5_cmd_exec_check_status(mdev, in, inlen, out, sizeof(out));
87+
}
88+
89+
int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
90+
u16 vport, u8 *addr)
6191
{
62-
u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)];
6392
u32 *out;
6493
int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
6594
u8 *out_addr;
95+
int err;
6696

6797
out = mlx5_vzalloc(outlen);
6898
if (!out)
69-
return;
99+
return -ENOMEM;
70100

71101
out_addr = MLX5_ADDR_OF(query_nic_vport_context_out, out,
72102
nic_vport_context.permanent_address);
73103

74-
memset(in, 0, sizeof(in));
75-
76-
MLX5_SET(query_nic_vport_context_in, in, opcode,
77-
MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
78-
79-
memset(out, 0, outlen);
80-
mlx5_cmd_exec_check_status(mdev, in, sizeof(in), out, outlen);
104+
err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
105+
if (err)
106+
goto out;
81107

82108
ether_addr_copy(addr, &out_addr[2]);
83109

110+
out:
84111
kvfree(out);
112+
return err;
113+
}
114+
EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_address);
115+
116+
int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
117+
u16 vport, u8 *addr)
118+
{
119+
void *in;
120+
int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
121+
int err;
122+
void *nic_vport_ctx;
123+
u8 *perm_mac;
124+
125+
in = mlx5_vzalloc(inlen);
126+
if (!in) {
127+
mlx5_core_warn(mdev, "failed to allocate inbox\n");
128+
return -ENOMEM;
129+
}
130+
131+
MLX5_SET(modify_nic_vport_context_in, in,
132+
field_select.permanent_address, 1);
133+
MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
134+
135+
if (vport)
136+
MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
137+
138+
nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
139+
in, nic_vport_context);
140+
perm_mac = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx,
141+
permanent_address);
142+
143+
ether_addr_copy(&perm_mac[2], addr);
144+
145+
err = mlx5_modify_nic_vport_context(mdev, in, inlen);
146+
147+
kvfree(in);
148+
149+
return err;
85150
}
86-
EXPORT_SYMBOL(mlx5_query_nic_vport_mac_address);
151+
EXPORT_SYMBOL(mlx5_modify_nic_vport_mac_address);
87152

88153
int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 other_vport,
89154
u8 port_num, u16 vf_num, u16 gid_index,

include/linux/mlx5/vport.h

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

3838
u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod);
39-
void mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev, u8 *addr);
39+
int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
40+
u16 vport, u8 *addr);
41+
int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *dev,
42+
u16 vport, u8 *addr);
4043
int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 other_vport,
4144
u8 port_num, u16 vf_num, u16 gid_index,
4245
union ib_gid *gid);

0 commit comments

Comments
 (0)