@@ -28,6 +28,68 @@ MODULE_DESCRIPTION(DRV_STRING);
2828MODULE_LICENSE ("GPL" );
2929MODULE_DEVICE_TABLE (pci , rvu_rep_id_table );
3030
31+ static void rvu_rep_get_stats (struct work_struct * work )
32+ {
33+ struct delayed_work * del_work = to_delayed_work (work );
34+ struct nix_stats_req * req ;
35+ struct nix_stats_rsp * rsp ;
36+ struct rep_stats * stats ;
37+ struct otx2_nic * priv ;
38+ struct rep_dev * rep ;
39+ int err ;
40+
41+ rep = container_of (del_work , struct rep_dev , stats_wrk );
42+ priv = rep -> mdev ;
43+
44+ mutex_lock (& priv -> mbox .lock );
45+ req = otx2_mbox_alloc_msg_nix_lf_stats (& priv -> mbox );
46+ if (!req ) {
47+ mutex_unlock (& priv -> mbox .lock );
48+ return ;
49+ }
50+ req -> pcifunc = rep -> pcifunc ;
51+ err = otx2_sync_mbox_msg_busy_poll (& priv -> mbox );
52+ if (err )
53+ goto exit ;
54+
55+ rsp = (struct nix_stats_rsp * )
56+ otx2_mbox_get_rsp (& priv -> mbox .mbox , 0 , & req -> hdr );
57+
58+ if (IS_ERR (rsp )) {
59+ err = PTR_ERR (rsp );
60+ goto exit ;
61+ }
62+
63+ stats = & rep -> stats ;
64+ stats -> rx_bytes = rsp -> rx .octs ;
65+ stats -> rx_frames = rsp -> rx .ucast + rsp -> rx .bcast +
66+ rsp -> rx .mcast ;
67+ stats -> rx_drops = rsp -> rx .drop ;
68+ stats -> rx_mcast_frames = rsp -> rx .mcast ;
69+ stats -> tx_bytes = rsp -> tx .octs ;
70+ stats -> tx_frames = rsp -> tx .ucast + rsp -> tx .bcast + rsp -> tx .mcast ;
71+ stats -> tx_drops = rsp -> tx .drop ;
72+ exit :
73+ mutex_unlock (& priv -> mbox .lock );
74+ }
75+
76+ static void rvu_rep_get_stats64 (struct net_device * dev ,
77+ struct rtnl_link_stats64 * stats )
78+ {
79+ struct rep_dev * rep = netdev_priv (dev );
80+
81+ stats -> rx_packets = rep -> stats .rx_frames ;
82+ stats -> rx_bytes = rep -> stats .rx_bytes ;
83+ stats -> rx_dropped = rep -> stats .rx_drops ;
84+ stats -> multicast = rep -> stats .rx_mcast_frames ;
85+
86+ stats -> tx_packets = rep -> stats .tx_frames ;
87+ stats -> tx_bytes = rep -> stats .tx_bytes ;
88+ stats -> tx_dropped = rep -> stats .tx_drops ;
89+
90+ schedule_delayed_work (& rep -> stats_wrk , msecs_to_jiffies (100 ));
91+ }
92+
3193static int rvu_eswitch_config (struct otx2_nic * priv , u8 ena )
3294{
3395 struct esw_cfg_req * req ;
@@ -87,6 +149,7 @@ static const struct net_device_ops rvu_rep_netdev_ops = {
87149 .ndo_open = rvu_rep_open ,
88150 .ndo_stop = rvu_rep_stop ,
89151 .ndo_start_xmit = rvu_rep_xmit ,
152+ .ndo_get_stats64 = rvu_rep_get_stats64 ,
90153};
91154
92155static int rvu_rep_napi_init (struct otx2_nic * priv ,
@@ -290,6 +353,8 @@ int rvu_rep_create(struct otx2_nic *priv, struct netlink_ext_ack *extack)
290353 free_netdev (ndev );
291354 goto exit ;
292355 }
356+
357+ INIT_DELAYED_WORK (& rep -> stats_wrk , rvu_rep_get_stats );
293358 }
294359 err = rvu_rep_napi_init (priv , extack );
295360 if (err )
0 commit comments