Skip to content

Commit c1e10d5

Browse files
danish-tidavem330
authored andcommitted
net: ti: icssg-prueth: Add ICSSG Stats
Add icssg_stats.c to help dump, icssg related driver statistics. ICSSG has hardware registers for providing statistics like total rx bytes, total tx bytes, etc. These registers are of 32 bits and hence in case of 1G link, they overflows in around 32 seconds. The behaviour of these registers is such that they don't roll back to 0 after overflow but rather stay at UINT_MAX. These registers support a feature where the value written to them is subtracted from the register. This feature can be utilized to fix the overflowing of stats. This solution uses a Workqueues based solution where a function gets called before the registers overflow (every 25 seconds in 1G link, 25000 seconds in 100M link), this function saves the register values in local variables and writes the last read value to the register. So any update during the read will be taken care of. Signed-off-by: MD Danish Anwar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 128d587 commit c1e10d5

File tree

5 files changed

+219
-0
lines changed

5 files changed

+219
-0
lines changed

drivers/net/ethernet/ti/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ icssg-prueth-y := k3-cppi-desc-pool.o \
3636
icssg/icssg_queues.o \
3737
icssg/icssg_config.o \
3838
icssg/icssg_mii_cfg.o \
39+
icssg/icssg_stats.o \

drivers/net/ethernet/ti/icssg/icssg_prueth.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/bitops.h>
1010
#include <linux/clk.h>
11+
#include <linux/delay.h>
1112
#include <linux/dma-mapping.h>
1213
#include <linux/dma/ti-cppi5.h>
1314
#include <linux/etherdevice.h>
@@ -1090,6 +1091,8 @@ static int emac_ndo_open(struct net_device *ndev)
10901091

10911092
prueth->emacs_initialized++;
10921093

1094+
queue_work(system_long_wq, &emac->stats_work.work);
1095+
10931096
return 0;
10941097

10951098
reset_tx_chan:
@@ -1164,6 +1167,9 @@ static int emac_ndo_stop(struct net_device *ndev)
11641167

11651168
cancel_work_sync(&emac->rx_mode_work);
11661169

1170+
/* Destroying the queued work in ndo_stop() */
1171+
cancel_delayed_work_sync(&emac->stats_work);
1172+
11671173
/* stop PRUs */
11681174
prueth_emac_stop(emac);
11691175

@@ -1313,6 +1319,8 @@ static int prueth_netdev_init(struct prueth *prueth,
13131319
}
13141320
INIT_WORK(&emac->rx_mode_work, emac_ndo_set_rx_mode_work);
13151321

1322+
INIT_DELAYED_WORK(&emac->stats_work, emac_stats_work_handler);
1323+
13161324
ret = pruss_request_mem_region(prueth->pruss,
13171325
port == PRUETH_PORT_MII0 ?
13181326
PRUSS_MEM_DRAM0 : PRUSS_MEM_DRAM1,

drivers/net/ethernet/ti/icssg/icssg_prueth.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949

5050
#define ICSSG_MAX_RFLOWS 8 /* per slice */
5151

52+
/* Number of ICSSG related stats */
53+
#define ICSSG_NUM_STATS 60
54+
5255
/* Firmware status codes */
5356
#define ICSS_HS_FW_READY 0x55555555
5457
#define ICSS_HS_FW_DEAD 0xDEAD0000 /* lower 16 bits contain error code */
@@ -153,6 +156,9 @@ struct prueth_emac {
153156
struct workqueue_struct *cmd_wq;
154157

155158
struct pruss_mem_region dram;
159+
160+
struct delayed_work stats_work;
161+
u64 stats[ICSSG_NUM_STATS];
156162
};
157163

158164
/**
@@ -246,4 +252,6 @@ u32 icssg_queue_level(struct prueth *prueth, int queue);
246252
#define prueth_napi_to_tx_chn(pnapi) \
247253
container_of(pnapi, struct prueth_tx_chn, napi_tx)
248254

255+
void emac_stats_work_handler(struct work_struct *work);
256+
void emac_update_hardware_stats(struct prueth_emac *emac);
249257
#endif /* __NET_TI_ICSSG_PRUETH_H */
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Texas Instruments ICSSG Ethernet driver
3+
*
4+
* Copyright (C) 2018-2021 Texas Instruments Incorporated - https://www.ti.com/
5+
*
6+
*/
7+
8+
#include "icssg_prueth.h"
9+
#include "icssg_stats.h"
10+
#include <linux/regmap.h>
11+
12+
static u32 stats_base[] = { 0x54c, /* Slice 0 stats start */
13+
0xb18, /* Slice 1 stats start */
14+
};
15+
16+
void emac_update_hardware_stats(struct prueth_emac *emac)
17+
{
18+
struct prueth *prueth = emac->prueth;
19+
int slice = prueth_emac_slice(emac);
20+
u32 base = stats_base[slice];
21+
u32 val;
22+
int i;
23+
24+
for (i = 0; i < ARRAY_SIZE(icssg_all_stats); i++) {
25+
regmap_read(prueth->miig_rt,
26+
base + icssg_all_stats[i].offset,
27+
&val);
28+
regmap_write(prueth->miig_rt,
29+
base + icssg_all_stats[i].offset,
30+
val);
31+
32+
emac->stats[i] += val;
33+
}
34+
}
35+
36+
void emac_stats_work_handler(struct work_struct *work)
37+
{
38+
struct prueth_emac *emac = container_of(work, struct prueth_emac,
39+
stats_work.work);
40+
emac_update_hardware_stats(emac);
41+
42+
queue_delayed_work(system_long_wq, &emac->stats_work,
43+
msecs_to_jiffies((STATS_TIME_LIMIT_1G_MS * 1000) / emac->speed));
44+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Texas Instruments ICSSG Ethernet driver
3+
*
4+
* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
5+
*
6+
*/
7+
8+
#ifndef __NET_TI_ICSSG_STATS_H
9+
#define __NET_TI_ICSSG_STATS_H
10+
11+
#include "icssg_prueth.h"
12+
13+
#define STATS_TIME_LIMIT_1G_MS 25000 /* 25 seconds @ 1G */
14+
15+
struct miig_stats_regs {
16+
/* Rx */
17+
u32 rx_packets;
18+
u32 rx_broadcast_frames;
19+
u32 rx_multicast_frames;
20+
u32 rx_crc_errors;
21+
u32 rx_mii_error_frames;
22+
u32 rx_odd_nibble_frames;
23+
u32 rx_frame_max_size;
24+
u32 rx_max_size_error_frames;
25+
u32 rx_frame_min_size;
26+
u32 rx_min_size_error_frames;
27+
u32 rx_over_errors;
28+
u32 rx_class0_hits;
29+
u32 rx_class1_hits;
30+
u32 rx_class2_hits;
31+
u32 rx_class3_hits;
32+
u32 rx_class4_hits;
33+
u32 rx_class5_hits;
34+
u32 rx_class6_hits;
35+
u32 rx_class7_hits;
36+
u32 rx_class8_hits;
37+
u32 rx_class9_hits;
38+
u32 rx_class10_hits;
39+
u32 rx_class11_hits;
40+
u32 rx_class12_hits;
41+
u32 rx_class13_hits;
42+
u32 rx_class14_hits;
43+
u32 rx_class15_hits;
44+
u32 rx_smd_frags;
45+
u32 rx_bucket1_size;
46+
u32 rx_bucket2_size;
47+
u32 rx_bucket3_size;
48+
u32 rx_bucket4_size;
49+
u32 rx_64B_frames;
50+
u32 rx_bucket1_frames;
51+
u32 rx_bucket2_frames;
52+
u32 rx_bucket3_frames;
53+
u32 rx_bucket4_frames;
54+
u32 rx_bucket5_frames;
55+
u32 rx_bytes;
56+
u32 rx_tx_total_bytes;
57+
/* Tx */
58+
u32 tx_packets;
59+
u32 tx_broadcast_frames;
60+
u32 tx_multicast_frames;
61+
u32 tx_odd_nibble_frames;
62+
u32 tx_underflow_errors;
63+
u32 tx_frame_max_size;
64+
u32 tx_max_size_error_frames;
65+
u32 tx_frame_min_size;
66+
u32 tx_min_size_error_frames;
67+
u32 tx_bucket1_size;
68+
u32 tx_bucket2_size;
69+
u32 tx_bucket3_size;
70+
u32 tx_bucket4_size;
71+
u32 tx_64B_frames;
72+
u32 tx_bucket1_frames;
73+
u32 tx_bucket2_frames;
74+
u32 tx_bucket3_frames;
75+
u32 tx_bucket4_frames;
76+
u32 tx_bucket5_frames;
77+
u32 tx_bytes;
78+
};
79+
80+
#define ICSSG_STATS(field, stats_type) \
81+
{ \
82+
#field, \
83+
offsetof(struct miig_stats_regs, field), \
84+
stats_type \
85+
}
86+
87+
struct icssg_stats {
88+
char name[ETH_GSTRING_LEN];
89+
u32 offset;
90+
bool standard_stats;
91+
};
92+
93+
static const struct icssg_stats icssg_all_stats[] = {
94+
/* Rx */
95+
ICSSG_STATS(rx_packets, true),
96+
ICSSG_STATS(rx_broadcast_frames, false),
97+
ICSSG_STATS(rx_multicast_frames, true),
98+
ICSSG_STATS(rx_crc_errors, true),
99+
ICSSG_STATS(rx_mii_error_frames, false),
100+
ICSSG_STATS(rx_odd_nibble_frames, false),
101+
ICSSG_STATS(rx_frame_max_size, true),
102+
ICSSG_STATS(rx_max_size_error_frames, false),
103+
ICSSG_STATS(rx_frame_min_size, true),
104+
ICSSG_STATS(rx_min_size_error_frames, false),
105+
ICSSG_STATS(rx_over_errors, true),
106+
ICSSG_STATS(rx_class0_hits, false),
107+
ICSSG_STATS(rx_class1_hits, false),
108+
ICSSG_STATS(rx_class2_hits, false),
109+
ICSSG_STATS(rx_class3_hits, false),
110+
ICSSG_STATS(rx_class4_hits, false),
111+
ICSSG_STATS(rx_class5_hits, false),
112+
ICSSG_STATS(rx_class6_hits, false),
113+
ICSSG_STATS(rx_class7_hits, false),
114+
ICSSG_STATS(rx_class8_hits, false),
115+
ICSSG_STATS(rx_class9_hits, false),
116+
ICSSG_STATS(rx_class10_hits, false),
117+
ICSSG_STATS(rx_class11_hits, false),
118+
ICSSG_STATS(rx_class12_hits, false),
119+
ICSSG_STATS(rx_class13_hits, false),
120+
ICSSG_STATS(rx_class14_hits, false),
121+
ICSSG_STATS(rx_class15_hits, false),
122+
ICSSG_STATS(rx_smd_frags, false),
123+
ICSSG_STATS(rx_bucket1_size, true),
124+
ICSSG_STATS(rx_bucket2_size, true),
125+
ICSSG_STATS(rx_bucket3_size, true),
126+
ICSSG_STATS(rx_bucket4_size, true),
127+
ICSSG_STATS(rx_64B_frames, true),
128+
ICSSG_STATS(rx_bucket1_frames, true),
129+
ICSSG_STATS(rx_bucket2_frames, true),
130+
ICSSG_STATS(rx_bucket3_frames, true),
131+
ICSSG_STATS(rx_bucket4_frames, true),
132+
ICSSG_STATS(rx_bucket5_frames, true),
133+
ICSSG_STATS(rx_bytes, true),
134+
ICSSG_STATS(rx_tx_total_bytes, false),
135+
/* Tx */
136+
ICSSG_STATS(tx_packets, true),
137+
ICSSG_STATS(tx_broadcast_frames, false),
138+
ICSSG_STATS(tx_multicast_frames, false),
139+
ICSSG_STATS(tx_odd_nibble_frames, false),
140+
ICSSG_STATS(tx_underflow_errors, false),
141+
ICSSG_STATS(tx_frame_max_size, true),
142+
ICSSG_STATS(tx_max_size_error_frames, false),
143+
ICSSG_STATS(tx_frame_min_size, true),
144+
ICSSG_STATS(tx_min_size_error_frames, false),
145+
ICSSG_STATS(tx_bucket1_size, true),
146+
ICSSG_STATS(tx_bucket2_size, true),
147+
ICSSG_STATS(tx_bucket3_size, true),
148+
ICSSG_STATS(tx_bucket4_size, true),
149+
ICSSG_STATS(tx_64B_frames, true),
150+
ICSSG_STATS(tx_bucket1_frames, true),
151+
ICSSG_STATS(tx_bucket2_frames, true),
152+
ICSSG_STATS(tx_bucket3_frames, true),
153+
ICSSG_STATS(tx_bucket4_frames, true),
154+
ICSSG_STATS(tx_bucket5_frames, true),
155+
ICSSG_STATS(tx_bytes, true),
156+
};
157+
158+
#endif /* __NET_TI_ICSSG_STATS_H */

0 commit comments

Comments
 (0)