Skip to content

Commit 3b751a2

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5: E-Switch, Introduce get vf statistics
Add support to get VF statistics using query vport counter command. Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: Or Gerlitz <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9e7ea35 commit 3b751a2

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,3 +1213,70 @@ int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
12131213

12141214
return modify_esw_vport_cvlan(esw->dev, vport, vlan, qos, set);
12151215
}
1216+
1217+
int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw,
1218+
int vport,
1219+
struct ifla_vf_stats *vf_stats)
1220+
{
1221+
int outlen = MLX5_ST_SZ_BYTES(query_vport_counter_out);
1222+
u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)];
1223+
int err = 0;
1224+
u32 *out;
1225+
1226+
if (!ESW_ALLOWED(esw))
1227+
return -EPERM;
1228+
if (!LEGAL_VPORT(esw, vport))
1229+
return -EINVAL;
1230+
1231+
out = mlx5_vzalloc(outlen);
1232+
if (!out)
1233+
return -ENOMEM;
1234+
1235+
memset(in, 0, sizeof(in));
1236+
1237+
MLX5_SET(query_vport_counter_in, in, opcode,
1238+
MLX5_CMD_OP_QUERY_VPORT_COUNTER);
1239+
MLX5_SET(query_vport_counter_in, in, op_mod, 0);
1240+
MLX5_SET(query_vport_counter_in, in, vport_number, vport);
1241+
if (vport)
1242+
MLX5_SET(query_vport_counter_in, in, other_vport, 1);
1243+
1244+
memset(out, 0, outlen);
1245+
err = mlx5_cmd_exec(esw->dev, in, sizeof(in), out, outlen);
1246+
if (err)
1247+
goto free_out;
1248+
1249+
#define MLX5_GET_CTR(p, x) \
1250+
MLX5_GET64(query_vport_counter_out, p, x)
1251+
1252+
memset(vf_stats, 0, sizeof(*vf_stats));
1253+
vf_stats->rx_packets =
1254+
MLX5_GET_CTR(out, received_eth_unicast.packets) +
1255+
MLX5_GET_CTR(out, received_eth_multicast.packets) +
1256+
MLX5_GET_CTR(out, received_eth_broadcast.packets);
1257+
1258+
vf_stats->rx_bytes =
1259+
MLX5_GET_CTR(out, received_eth_unicast.octets) +
1260+
MLX5_GET_CTR(out, received_eth_multicast.octets) +
1261+
MLX5_GET_CTR(out, received_eth_broadcast.octets);
1262+
1263+
vf_stats->tx_packets =
1264+
MLX5_GET_CTR(out, transmitted_eth_unicast.packets) +
1265+
MLX5_GET_CTR(out, transmitted_eth_multicast.packets) +
1266+
MLX5_GET_CTR(out, transmitted_eth_broadcast.packets);
1267+
1268+
vf_stats->tx_bytes =
1269+
MLX5_GET_CTR(out, transmitted_eth_unicast.octets) +
1270+
MLX5_GET_CTR(out, transmitted_eth_multicast.octets) +
1271+
MLX5_GET_CTR(out, transmitted_eth_broadcast.octets);
1272+
1273+
vf_stats->multicast =
1274+
MLX5_GET_CTR(out, received_eth_multicast.packets);
1275+
1276+
vf_stats->broadcast =
1277+
MLX5_GET_CTR(out, received_eth_broadcast.packets);
1278+
1279+
free_out:
1280+
kvfree(out);
1281+
return err;
1282+
}

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,8 @@ int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
153153
int vport, u16 vlan, u8 qos);
154154
int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
155155
int vport, struct ifla_vf_info *ivi);
156+
int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw,
157+
int vport,
158+
struct ifla_vf_stats *vf_stats);
156159

157160
#endif /* __MLX5_ESWITCH_H__ */

0 commit comments

Comments
 (0)