Skip to content

Commit a671385

Browse files
tianx666NipaLocal
authored andcommitted
xsc: add ndo_get_stats64
Added basic network interface statistics. Co-developed-by: Honggang Wei <[email protected]> Signed-off-by: Honggang Wei <[email protected]> Co-developed-by: Lei Yan <[email protected]> Signed-off-by: Lei Yan <[email protected]> Signed-off-by: Xin Tian <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 27ba6e1 commit a671385

File tree

8 files changed

+124
-3
lines changed

8 files changed

+124
-3
lines changed

drivers/net/ethernet/yunsilicon/xsc/net/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/yunsilicon/xsc
66

77
obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc_eth.o
88

9-
xsc_eth-y := main.o xsc_eth_wq.o xsc_eth_txrx.o xsc_eth_tx.o xsc_eth_rx.o
9+
xsc_eth-y := main.o xsc_eth_wq.o xsc_eth_txrx.o xsc_eth_tx.o xsc_eth_rx.o xsc_eth_stats.o

drivers/net/ethernet/yunsilicon/xsc/net/main.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,20 @@ static int xsc_eth_open_qp_sq(struct xsc_channel *c,
559559
u8 ele_log_size = psq_param->sq_attr.ele_log_size;
560560
u8 q_log_size = psq_param->sq_attr.q_log_size;
561561
struct xsc_modify_raw_qp_mbox_in *modify_in;
562+
struct xsc_channel_stats *channel_stats;
562563
struct xsc_create_qp_mbox_in *in;
563564
struct xsc_core_device *xdev;
564565
struct xsc_adapter *adapter;
566+
struct xsc_stats *stats;
565567
unsigned int hw_npages;
566568
int inlen;
567569
int ret;
568570

569571
adapter = c->adapter;
570572
xdev = adapter->xdev;
573+
stats = adapter->stats;
574+
channel_stats = &stats->channel_stats[c->chl_idx];
575+
psq->stats = &channel_stats->sq[sq_idx];
571576
psq_param->wq.db_numa_node = cpu_to_node(c->cpu);
572577

573578
ret = xsc_eth_wq_cyc_create(xdev, &psq_param->wq,
@@ -868,11 +873,16 @@ static int xsc_eth_alloc_rq(struct xsc_channel *c,
868873
u8 q_log_size = prq_param->rq_attr.q_log_size;
869874
struct page_pool_params pagepool_params = {0};
870875
struct xsc_adapter *adapter = c->adapter;
876+
struct xsc_channel_stats *channel_stats;
871877
u32 pool_size = 1 << q_log_size;
878+
struct xsc_stats *stats;
872879
int ret = 0;
873880
u32 wq_sz;
874881
int i, f;
875882

883+
stats = c->adapter->stats;
884+
channel_stats = &stats->channel_stats[c->chl_idx];
885+
prq->stats = &channel_stats->rq;
876886
prq_param->wq.db_numa_node = cpu_to_node(c->cpu);
877887

878888
ret = xsc_eth_wq_cyc_create(c->adapter->xdev, &prq_param->wq,
@@ -1653,6 +1663,14 @@ static int xsc_eth_close(struct net_device *netdev)
16531663
return ret;
16541664
}
16551665

1666+
static void xsc_eth_get_stats(struct net_device *netdev,
1667+
struct rtnl_link_stats64 *stats)
1668+
{
1669+
struct xsc_adapter *adapter = netdev_priv(netdev);
1670+
1671+
xsc_eth_fold_sw_stats64(adapter, stats);
1672+
}
1673+
16561674
static int xsc_eth_set_hw_mtu(struct xsc_core_device *xdev,
16571675
u16 mtu, u16 rx_buf_sz)
16581676
{
@@ -1684,6 +1702,7 @@ static const struct net_device_ops xsc_netdev_ops = {
16841702
.ndo_open = xsc_eth_open,
16851703
.ndo_stop = xsc_eth_close,
16861704
.ndo_start_xmit = xsc_eth_xmit_start,
1705+
.ndo_get_stats64 = xsc_eth_get_stats,
16871706
};
16881707

16891708
static void xsc_eth_build_nic_netdev(struct xsc_adapter *adapter)
@@ -1897,14 +1916,22 @@ static int xsc_eth_probe(struct auxiliary_device *adev,
18971916
goto err_nic_cleanup;
18981917
}
18991918

1919+
adapter->stats = kvzalloc(sizeof(*adapter->stats), GFP_KERNEL);
1920+
if (!adapter->stats) {
1921+
err = -ENOMEM;
1922+
goto err_detach;
1923+
}
1924+
19001925
err = register_netdev(netdev);
19011926
if (err) {
19021927
netdev_err(netdev, "register_netdev failed, err=%d\n", err);
1903-
goto err_detach;
1928+
goto err_free_stats;
19041929
}
19051930

19061931
return 0;
19071932

1933+
err_free_stats:
1934+
kvfree(adapter->stats);
19081935
err_detach:
19091936
xsc_eth_detach(xdev, adapter);
19101937
err_nic_cleanup:
@@ -1929,7 +1956,7 @@ static void xsc_eth_remove(struct auxiliary_device *adev)
19291956
return;
19301957

19311958
unregister_netdev(adapter->netdev);
1932-
1959+
kvfree(adapter->stats);
19331960
free_netdev(adapter->netdev);
19341961

19351962
xdev->eth_priv = NULL;

drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "common/xsc_device.h"
1212
#include "xsc_eth_common.h"
13+
#include "xsc_eth_stats.h"
1314

1415
#define XSC_INVALID_LKEY 0x100
1516

@@ -47,6 +48,8 @@ struct xsc_adapter {
4748

4849
u32 status;
4950
struct mutex status_lock; /*protect status */
51+
52+
struct xsc_stats *stats;
5053
};
5154

5255
static inline struct net_device *xsc_dev_to_netdev(struct xsc_core_device *xdev)

drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_rx.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ static void xsc_complete_rx_cqe(struct xsc_rq *rq,
155155
struct sk_buff *skb,
156156
struct xsc_wqe_frag_info *wi)
157157
{
158+
struct xsc_rq_stats *stats = rq->stats;
159+
160+
stats->packets++;
161+
stats->bytes += cqe_bcnt;
158162
xsc_build_rx_skb(cqe, cqe_bcnt, rq, skb, wi);
159163
}
160164

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (C) 2021-2025, Shanghai Yunsilicon Technology Co., Ltd.
3+
* All rights reserved.
4+
*/
5+
6+
#include "xsc_eth_stats.h"
7+
#include "xsc_eth.h"
8+
9+
static int xsc_get_netdev_max_channels(struct xsc_adapter *adapter)
10+
{
11+
struct net_device *netdev = adapter->netdev;
12+
13+
return min_t(unsigned int, netdev->num_rx_queues,
14+
netdev->num_tx_queues);
15+
}
16+
17+
static int xsc_get_netdev_max_tc(struct xsc_adapter *adapter)
18+
{
19+
return adapter->nic_param.num_tc;
20+
}
21+
22+
void xsc_eth_fold_sw_stats64(struct xsc_adapter *adapter,
23+
struct rtnl_link_stats64 *s)
24+
{
25+
int i, j;
26+
27+
for (i = 0; i < xsc_get_netdev_max_channels(adapter); i++) {
28+
struct xsc_channel_stats *channel_stats;
29+
struct xsc_rq_stats *rq_stats;
30+
31+
channel_stats = &adapter->stats->channel_stats[i];
32+
rq_stats = &channel_stats->rq;
33+
34+
s->rx_packets += rq_stats->packets;
35+
s->rx_bytes += rq_stats->bytes;
36+
37+
for (j = 0; j < xsc_get_netdev_max_tc(adapter); j++) {
38+
struct xsc_sq_stats *sq_stats = &channel_stats->sq[j];
39+
40+
s->tx_packets += sq_stats->packets;
41+
s->tx_bytes += sq_stats->bytes;
42+
s->tx_dropped += sq_stats->dropped;
43+
}
44+
}
45+
}
46+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (C) 2021-2025, Shanghai Yunsilicon Technology Co., Ltd.
3+
* All rights reserved.
4+
*/
5+
6+
#ifndef __XSC_EN_STATS_H
7+
#define __XSC_EN_STATS_H
8+
9+
#include "xsc_eth_common.h"
10+
11+
struct xsc_rq_stats {
12+
u64 packets;
13+
u64 bytes;
14+
};
15+
16+
struct xsc_sq_stats {
17+
u64 packets;
18+
u64 bytes;
19+
u64 dropped;
20+
};
21+
22+
struct xsc_channel_stats {
23+
struct xsc_sq_stats sq[XSC_MAX_NUM_TC];
24+
struct xsc_rq_stats rq;
25+
} ____cacheline_aligned_in_smp;
26+
27+
struct xsc_stats {
28+
struct xsc_channel_stats channel_stats[XSC_ETH_MAX_NUM_CHANNELS];
29+
};
30+
31+
void xsc_eth_fold_sw_stats64(struct xsc_adapter *adapter,
32+
struct rtnl_link_stats64 *s);
33+
34+
#endif /* XSC_EN_STATS_H */

drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ static uint32_t xsc_eth_xmit_frame(struct sk_buff *skb,
221221
u16 pi)
222222
{
223223
struct xsc_core_device *xdev = sq->cq.xdev;
224+
struct xsc_sq_stats *stats = sq->stats;
224225
struct xsc_send_wqe_ctrl_seg *cseg;
225226
struct xsc_wqe_data_seg *dseg;
226227
struct xsc_tx_wqe_info *wi;
@@ -242,11 +243,13 @@ static uint32_t xsc_eth_xmit_frame(struct sk_buff *skb,
242243
ihs = xsc_tx_get_gso_ihs(sq, skb);
243244
num_bytes = skb->len +
244245
(skb_shinfo(skb)->gso_segs - 1) * ihs;
246+
stats->packets += skb_shinfo(skb)->gso_segs;
245247
} else {
246248
opcode = XSC_OPCODE_RAW;
247249
mss = 0;
248250
ihs = 0;
249251
num_bytes = skb->len;
252+
stats->packets++;
250253
}
251254

252255
/*linear data in skb*/
@@ -284,10 +287,12 @@ static uint32_t xsc_eth_xmit_frame(struct sk_buff *skb,
284287

285288
xsc_txwqe_complete(sq, skb, opcode, ds_cnt, num_wqebbs, num_bytes,
286289
num_dma, wi);
290+
stats->bytes += num_bytes;
287291

288292
return NETDEV_TX_OK;
289293

290294
err_drop:
295+
stats->dropped++;
291296
dev_kfree_skb_any(skb);
292297

293298
return NETDEV_TX_OK;

drivers/net/ethernet/yunsilicon/xsc/net/xsc_queue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct xsc_rq {
124124

125125
unsigned long state;
126126
struct work_struct recover_work;
127+
struct xsc_rq_stats *stats;
127128

128129
u32 hw_mtu;
129130
u32 frags_sz;
@@ -171,6 +172,7 @@ struct xsc_sq {
171172
/* read only */
172173
struct xsc_wq_cyc wq;
173174
u32 dma_fifo_mask;
175+
struct xsc_sq_stats *stats;
174176
struct {
175177
struct xsc_sq_dma *dma_fifo;
176178
struct xsc_tx_wqe_info *wqe_info;

0 commit comments

Comments
 (0)