@@ -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+
98126static 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+
248347static 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
263362static 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};
0 commit comments