xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.h (revision 91a4855d6c03e770e42f17c798a36a3c46e63de2) !
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3 
4 #ifndef _FBNIC_HW_STATS_H_
5 #define _FBNIC_HW_STATS_H_
6 
7 #include <linux/ethtool.h>
8 #include <linux/spinlock.h>
9 
10 #include "fbnic_csr.h"
11 
12 struct fbnic_stat_counter {
13 	u64 value;
14 	union {
15 		u32 old_reg_value_32;
16 		u64 old_reg_value_64;
17 	} u;
18 	bool reported;
19 };
20 
21 struct fbnic_hw_stat {
22 	struct fbnic_stat_counter frames;
23 	struct fbnic_stat_counter bytes;
24 };
25 
26 struct fbnic_fec_stats {
27 	struct fbnic_stat_counter corrected_blocks, uncorrectable_blocks;
28 };
29 
30 struct fbnic_pcs_stats {
31 	struct {
32 		struct fbnic_stat_counter lanes[FBNIC_PCS_MAX_LANES];
33 	} SymbolErrorDuringCarrier;
34 };
35 
36 /* Note: not updated by fbnic_get_hw_stats() */
37 struct fbnic_eth_ctrl_stats {
38 	struct fbnic_stat_counter MACControlFramesTransmitted;
39 	struct fbnic_stat_counter MACControlFramesReceived;
40 };
41 
42 /* Note: not updated by fbnic_get_hw_stats() */
43 struct fbnic_rmon_stats {
44 	struct fbnic_stat_counter undersize_pkts;
45 	struct fbnic_stat_counter oversize_pkts;
46 	struct fbnic_stat_counter fragments;
47 	struct fbnic_stat_counter jabbers;
48 
49 	struct fbnic_stat_counter hist[ETHTOOL_RMON_HIST_MAX];
50 	struct fbnic_stat_counter hist_tx[ETHTOOL_RMON_HIST_MAX];
51 };
52 
53 /* Note: not updated by fbnic_get_hw_stats() */
54 struct fbnic_pause_stats {
55 	struct fbnic_stat_counter tx_pause_frames;
56 	struct fbnic_stat_counter rx_pause_frames;
57 	struct fbnic_stat_counter tx_pause_storm_events;
58 };
59 
60 struct fbnic_eth_mac_stats {
61 	struct fbnic_stat_counter FramesTransmittedOK;
62 	struct fbnic_stat_counter FramesReceivedOK;
63 	struct fbnic_stat_counter FrameCheckSequenceErrors;
64 	struct fbnic_stat_counter AlignmentErrors;
65 	struct fbnic_stat_counter OctetsTransmittedOK;
66 	struct fbnic_stat_counter FramesLostDueToIntMACXmitError;
67 	struct fbnic_stat_counter OctetsReceivedOK;
68 	struct fbnic_stat_counter FramesLostDueToIntMACRcvError;
69 	struct fbnic_stat_counter MulticastFramesXmittedOK;
70 	struct fbnic_stat_counter BroadcastFramesXmittedOK;
71 	struct fbnic_stat_counter MulticastFramesReceivedOK;
72 	struct fbnic_stat_counter BroadcastFramesReceivedOK;
73 	struct fbnic_stat_counter FrameTooLongErrors;
74 };
75 
76 struct fbnic_phy_stats {
77 	struct fbnic_fec_stats fec;
78 	struct fbnic_pcs_stats pcs;
79 };
80 
81 struct fbnic_mac_stats {
82 	struct fbnic_eth_mac_stats eth_mac;
83 	struct fbnic_pause_stats pause;
84 	struct fbnic_eth_ctrl_stats eth_ctrl;
85 	struct fbnic_rmon_stats rmon;
86 };
87 
88 struct fbnic_tmi_stats {
89 	struct fbnic_hw_stat drop;
90 	struct fbnic_stat_counter ptp_illegal_req, ptp_good_ts, ptp_bad_ts;
91 };
92 
93 struct fbnic_tti_stats {
94 	struct fbnic_hw_stat cm_drop, frame_drop, tbi_drop;
95 };
96 
97 struct fbnic_rpc_stats {
98 	struct fbnic_stat_counter unkn_etype, unkn_ext_hdr;
99 	struct fbnic_stat_counter ipv4_frag, ipv6_frag, ipv4_esp, ipv6_esp;
100 	struct fbnic_stat_counter tcp_opt_err, out_of_hdr_err, ovr_size_err;
101 };
102 
103 struct fbnic_rxb_enqueue_stats {
104 	struct fbnic_hw_stat drbo;
105 	struct fbnic_stat_counter integrity_err, mac_err;
106 	struct fbnic_stat_counter parser_err, frm_err;
107 };
108 
109 struct fbnic_rxb_fifo_stats {
110 	struct fbnic_hw_stat drop, trunc;
111 	struct fbnic_stat_counter trans_drop, trans_ecn;
112 	struct fbnic_stat_counter level;
113 };
114 
115 struct fbnic_rxb_dequeue_stats {
116 	struct fbnic_hw_stat intf, pbuf;
117 };
118 
119 struct fbnic_rxb_stats {
120 	struct fbnic_rxb_enqueue_stats enq[FBNIC_RXB_ENQUEUE_INDICES];
121 	struct fbnic_rxb_fifo_stats fifo[FBNIC_RXB_FIFO_INDICES];
122 	struct fbnic_rxb_dequeue_stats deq[FBNIC_RXB_DEQUEUE_INDICES];
123 };
124 
125 struct fbnic_hw_q_stats {
126 	struct fbnic_stat_counter rde_pkt_err;
127 	struct fbnic_stat_counter rde_pkt_cq_drop;
128 	struct fbnic_stat_counter rde_pkt_bdq_drop;
129 };
130 
131 struct fbnic_pcie_stats {
132 	struct fbnic_stat_counter ob_rd_tlp, ob_rd_dword;
133 	struct fbnic_stat_counter ob_wr_tlp, ob_wr_dword;
134 	struct fbnic_stat_counter ob_cpl_tlp, ob_cpl_dword;
135 
136 	struct fbnic_stat_counter ob_rd_no_tag;
137 	struct fbnic_stat_counter ob_rd_no_cpl_cred;
138 	struct fbnic_stat_counter ob_rd_no_np_cred;
139 };
140 
141 struct fbnic_hw_stats {
142 	struct fbnic_phy_stats phy;
143 	struct fbnic_mac_stats mac;
144 	struct fbnic_tmi_stats tmi;
145 	struct fbnic_tti_stats tti;
146 	struct fbnic_rpc_stats rpc;
147 	struct fbnic_rxb_stats rxb;
148 	struct fbnic_hw_q_stats hw_q[FBNIC_MAX_QUEUES];
149 	struct fbnic_pcie_stats pcie;
150 
151 	/* Lock protecting the access to hw stats */
152 	spinlock_t lock;
153 };
154 
155 u64 fbnic_stat_rd64(struct fbnic_dev *fbd, u32 reg, u32 offset);
156 
157 void fbnic_reset_hw_stats(struct fbnic_dev *fbd);
158 void fbnic_init_hw_stats(struct fbnic_dev *fbd);
159 void fbnic_get_hw_q_stats(struct fbnic_dev *fbd,
160 			  struct fbnic_hw_q_stats *hw_q);
161 void fbnic_get_hw_stats32(struct fbnic_dev *fbd);
162 void fbnic_get_hw_stats(struct fbnic_dev *fbd);
163 
164 #endif /* _FBNIC_HW_STATS_H_ */
165