Skip to content

Commit 370bad0

Browse files
ogerlitzdavem330
authored andcommitted
net/mlx5e: Support HW (offloaded) and SW counters for SRIOV switchdev mode
Switchdev driver net-device port statistics should follow the model introduced in commit a5ea31f 'Merge branch net-offloaded-stats'. For VF reps we return the SRIOV eswitch vport stats as the usual ones and SW stats if asked. For the PF, if we're in the switchdev mode, we return the uplink stats and SW stats if asked, otherwise as before. The uplink stats are implemented using the PPCNT 802_3 counters which are already being read/cached by the driver. Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3df5b3c commit 370bad0

4 files changed

Lines changed: 128 additions & 24 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/en.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
874874
void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
875875
int mlx5e_attr_get(struct net_device *dev, struct switchdev_attr *attr);
876876
void mlx5e_handle_rx_cqe_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
877+
void mlx5e_update_hw_rep_counters(struct mlx5e_priv *priv);
877878

878879
int mlx5e_create_direct_rqts(struct mlx5e_priv *priv);
879880
void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt);
@@ -890,12 +891,16 @@ struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
890891
void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv);
891892
int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
892893
void mlx5e_detach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
893-
struct rtnl_link_stats64 *
894-
mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats);
895894
u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout);
896895
void mlx5e_add_vxlan_port(struct net_device *netdev,
897896
struct udp_tunnel_info *ti);
898897
void mlx5e_del_vxlan_port(struct net_device *netdev,
899898
struct udp_tunnel_info *ti);
900899

900+
int mlx5e_get_offload_stats(int attr_id, const struct net_device *dev,
901+
void *sp);
902+
bool mlx5e_has_offload_stats(const struct net_device *dev, int attr_id);
903+
904+
bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv);
905+
bool mlx5e_is_vf_vport_rep(struct mlx5e_priv *priv);
901906
#endif /* __MLX5_EN_H__ */

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,6 @@ static void mlx5e_rq_free_mpwqe_info(struct mlx5e_rq *rq)
470470
kfree(rq->mpwqe.info);
471471
}
472472

473-
static bool mlx5e_is_vf_vport_rep(struct mlx5e_priv *priv)
474-
{
475-
struct mlx5_eswitch_rep *rep = (struct mlx5_eswitch_rep *)priv->ppriv;
476-
477-
if (rep && rep->vport != FDB_UPLINK_VPORT)
478-
return true;
479-
480-
return false;
481-
}
482-
483473
static int mlx5e_create_rq(struct mlx5e_channel *c,
484474
struct mlx5e_rq_param *param,
485475
struct mlx5e_rq *rq)
@@ -2664,21 +2654,28 @@ static int mlx5e_ndo_setup_tc(struct net_device *dev, u32 handle,
26642654
return mlx5e_setup_tc(dev, tc->tc);
26652655
}
26662656

2667-
struct rtnl_link_stats64 *
2657+
static struct rtnl_link_stats64 *
26682658
mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
26692659
{
26702660
struct mlx5e_priv *priv = netdev_priv(dev);
26712661
struct mlx5e_sw_stats *sstats = &priv->stats.sw;
26722662
struct mlx5e_vport_stats *vstats = &priv->stats.vport;
26732663
struct mlx5e_pport_stats *pstats = &priv->stats.pport;
26742664

2675-
stats->rx_packets = sstats->rx_packets;
2676-
stats->rx_bytes = sstats->rx_bytes;
2677-
stats->tx_packets = sstats->tx_packets;
2678-
stats->tx_bytes = sstats->tx_bytes;
2665+
if (mlx5e_is_uplink_rep(priv)) {
2666+
stats->rx_packets = PPORT_802_3_GET(pstats, a_frames_received_ok);
2667+
stats->rx_bytes = PPORT_802_3_GET(pstats, a_octets_received_ok);
2668+
stats->tx_packets = PPORT_802_3_GET(pstats, a_frames_transmitted_ok);
2669+
stats->tx_bytes = PPORT_802_3_GET(pstats, a_octets_transmitted_ok);
2670+
} else {
2671+
stats->rx_packets = sstats->rx_packets;
2672+
stats->rx_bytes = sstats->rx_bytes;
2673+
stats->tx_packets = sstats->tx_packets;
2674+
stats->tx_bytes = sstats->tx_bytes;
2675+
stats->tx_dropped = sstats->tx_queue_dropped;
2676+
}
26792677

26802678
stats->rx_dropped = priv->stats.qcnt.rx_out_of_buffer;
2681-
stats->tx_dropped = sstats->tx_queue_dropped;
26822679

26832680
stats->rx_length_errors =
26842681
PPORT_802_3_GET(pstats, a_in_range_length_errors) +
@@ -3290,6 +3287,8 @@ static const struct net_device_ops mlx5e_netdev_ops_sriov = {
32903287
#ifdef CONFIG_NET_POLL_CONTROLLER
32913288
.ndo_poll_controller = mlx5e_netpoll,
32923289
#endif
3290+
.ndo_has_offload_stats = mlx5e_has_offload_stats,
3291+
.ndo_get_offload_stats = mlx5e_get_offload_stats,
32933292
};
32943293

32953294
static int mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev)

‎drivers/net/ethernet/mellanox/mlx5/core/en_rep.c‎

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,29 @@ static void mlx5e_rep_get_strings(struct net_device *dev,
7272
}
7373
}
7474

75-
static void mlx5e_update_sw_rep_counters(struct mlx5e_priv *priv)
75+
static void mlx5e_rep_update_hw_counters(struct mlx5e_priv *priv)
76+
{
77+
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
78+
struct mlx5_eswitch_rep *rep = priv->ppriv;
79+
struct rtnl_link_stats64 *vport_stats;
80+
struct ifla_vf_stats vf_stats;
81+
int err;
82+
83+
err = mlx5_eswitch_get_vport_stats(esw, rep->vport, &vf_stats);
84+
if (err) {
85+
pr_warn("vport %d error %d reading stats\n", rep->vport, err);
86+
return;
87+
}
88+
89+
vport_stats = &priv->stats.vf_vport;
90+
/* flip tx/rx as we are reporting the counters for the switch vport */
91+
vport_stats->rx_packets = vf_stats.tx_packets;
92+
vport_stats->rx_bytes = vf_stats.tx_bytes;
93+
vport_stats->tx_packets = vf_stats.rx_packets;
94+
vport_stats->tx_bytes = vf_stats.rx_bytes;
95+
}
96+
97+
static void mlx5e_rep_update_sw_counters(struct mlx5e_priv *priv)
7698
{
7799
struct mlx5e_sw_stats *s = &priv->stats.sw;
78100
struct mlx5e_rq_stats *rq_stats;
@@ -95,6 +117,12 @@ static void mlx5e_update_sw_rep_counters(struct mlx5e_priv *priv)
95117
}
96118
}
97119

120+
static void mlx5e_rep_update_stats(struct mlx5e_priv *priv)
121+
{
122+
mlx5e_rep_update_sw_counters(priv);
123+
mlx5e_rep_update_hw_counters(priv);
124+
}
125+
98126
static void mlx5e_rep_get_ethtool_stats(struct net_device *dev,
99127
struct ethtool_stats *stats, u64 *data)
100128
{
@@ -106,7 +134,7 @@ static void mlx5e_rep_get_ethtool_stats(struct net_device *dev,
106134

107135
mutex_lock(&priv->state_lock);
108136
if (test_bit(MLX5E_STATE_OPENED, &priv->state))
109-
mlx5e_update_sw_rep_counters(priv);
137+
mlx5e_rep_update_sw_counters(priv);
110138
mutex_unlock(&priv->state_lock);
111139

112140
for (i = 0; i < NUM_VPORT_REP_COUNTERS; i++)
@@ -245,6 +273,77 @@ static int mlx5e_rep_ndo_setup_tc(struct net_device *dev, u32 handle,
245273
}
246274
}
247275

276+
bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv)
277+
{
278+
struct mlx5_eswitch_rep *rep = (struct mlx5_eswitch_rep *)priv->ppriv;
279+
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
280+
281+
if (rep && rep->vport == FDB_UPLINK_VPORT && esw->mode == SRIOV_OFFLOADS)
282+
return true;
283+
284+
return false;
285+
}
286+
287+
bool mlx5e_is_vf_vport_rep(struct mlx5e_priv *priv)
288+
{
289+
struct mlx5_eswitch_rep *rep = (struct mlx5_eswitch_rep *)priv->ppriv;
290+
291+
if (rep && rep->vport != FDB_UPLINK_VPORT)
292+
return true;
293+
294+
return false;
295+
}
296+
297+
bool mlx5e_has_offload_stats(const struct net_device *dev, int attr_id)
298+
{
299+
struct mlx5e_priv *priv = netdev_priv(dev);
300+
301+
switch (attr_id) {
302+
case IFLA_OFFLOAD_XSTATS_CPU_HIT:
303+
if (mlx5e_is_vf_vport_rep(priv) || mlx5e_is_uplink_rep(priv))
304+
return true;
305+
}
306+
307+
return false;
308+
}
309+
310+
static int
311+
mlx5e_get_sw_stats64(const struct net_device *dev,
312+
struct rtnl_link_stats64 *stats)
313+
{
314+
struct mlx5e_priv *priv = netdev_priv(dev);
315+
struct mlx5e_sw_stats *sstats = &priv->stats.sw;
316+
317+
stats->rx_packets = sstats->rx_packets;
318+
stats->rx_bytes = sstats->rx_bytes;
319+
stats->tx_packets = sstats->tx_packets;
320+
stats->tx_bytes = sstats->tx_bytes;
321+
322+
stats->tx_dropped = sstats->tx_queue_dropped;
323+
324+
return 0;
325+
}
326+
327+
int mlx5e_get_offload_stats(int attr_id, const struct net_device *dev,
328+
void *sp)
329+
{
330+
switch (attr_id) {
331+
case IFLA_OFFLOAD_XSTATS_CPU_HIT:
332+
return mlx5e_get_sw_stats64(dev, sp);
333+
}
334+
335+
return -EINVAL;
336+
}
337+
338+
static struct rtnl_link_stats64 *
339+
mlx5e_rep_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
340+
{
341+
struct mlx5e_priv *priv = netdev_priv(dev);
342+
343+
memcpy(stats, &priv->stats.vf_vport, sizeof(*stats));
344+
return stats;
345+
}
346+
248347
static const struct switchdev_ops mlx5e_rep_switchdev_ops = {
249348
.switchdev_port_attr_get = mlx5e_attr_get,
250349
};
@@ -255,9 +354,9 @@ static const struct net_device_ops mlx5e_netdev_ops_rep = {
255354
.ndo_start_xmit = mlx5e_xmit,
256355
.ndo_get_phys_port_name = mlx5e_rep_get_phys_port_name,
257356
.ndo_setup_tc = mlx5e_rep_ndo_setup_tc,
258-
.ndo_get_stats64 = mlx5e_get_stats,
259-
.ndo_udp_tunnel_add = mlx5e_add_vxlan_port,
260-
.ndo_udp_tunnel_del = mlx5e_del_vxlan_port,
357+
.ndo_get_stats64 = mlx5e_rep_get_stats,
358+
.ndo_has_offload_stats = mlx5e_has_offload_stats,
359+
.ndo_get_offload_stats = mlx5e_get_offload_stats,
261360
};
262361

263362
static void mlx5e_build_rep_netdev_priv(struct mlx5_core_dev *mdev,
@@ -407,7 +506,7 @@ static struct mlx5e_profile mlx5e_rep_profile = {
407506
.cleanup_rx = mlx5e_cleanup_rep_rx,
408507
.init_tx = mlx5e_init_rep_tx,
409508
.cleanup_tx = mlx5e_cleanup_nic_tx,
410-
.update_stats = mlx5e_update_sw_rep_counters,
509+
.update_stats = mlx5e_rep_update_stats,
411510
.max_nch = mlx5e_get_rep_max_num_channels,
412511
.max_tc = 1,
413512
};

‎drivers/net/ethernet/mellanox/mlx5/core/en_stats.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ struct mlx5e_stats {
407407
struct mlx5e_vport_stats vport;
408408
struct mlx5e_pport_stats pport;
409409
struct mlx5e_pcie_stats pcie;
410+
struct rtnl_link_stats64 vf_vport;
410411
};
411412

412413
static const struct counter_desc mlx5e_pme_status_desc[] = {

0 commit comments

Comments
 (0)