1 /*
2 * Copyright (c) 2015-2024, Broadcom. All rights reserved. The term
3 * Broadcom refers to Broadcom Limited and/or its subsidiaries.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Description: statistics related data structures
29 */
30
31 #ifndef __STATS_H__
32 #define __STATS_H__
33
34 #define BNXT_RE_CFA_STAT_BYTES_MASK 0xFFFFFFFFF
35 #define BNXT_RE_CFA_STAT_PKTS_MASK 0xFFFFFFF
36 enum {
37 BYTE_MASK = 0,
38 PKTS_MASK = 1
39 };
40
41 struct bnxt_re_cnp_counters {
42 u64 cnp_tx_pkts;
43 u64 cnp_tx_bytes;
44 u64 cnp_rx_pkts;
45 u64 cnp_rx_bytes;
46 u64 ecn_marked;
47 };
48
49 struct bnxt_re_ro_counters {
50 u64 tx_pkts;
51 u64 tx_bytes;
52 u64 rx_pkts;
53 u64 rx_bytes;
54 };
55
56 struct bnxt_re_flow_counters {
57 struct bnxt_re_ro_counters ro_stats;
58 struct bnxt_re_cnp_counters cnp_stats;
59 };
60
61 struct bnxt_re_ext_cntr {
62 u64 atomic_req;
63 u64 read_req;
64 u64 read_resp;
65 u64 write_req;
66 u64 send_req;
67 };
68
69 struct bnxt_re_ext_good {
70 u64 rx_pkts;
71 u64 rx_bytes;
72 };
73
74 struct bnxt_re_ext_rstat {
75 struct bnxt_re_ext_cntr tx;
76 struct bnxt_re_ext_cntr rx;
77 struct bnxt_re_ext_good grx;
78 u64 rx_dcn_payload_cut;
79 u64 te_bypassed;
80 };
81
82 struct bnxt_re_rdata_counters {
83 u64 tx_ucast_pkts;
84 u64 tx_mcast_pkts;
85 u64 tx_bcast_pkts;
86 u64 tx_discard_pkts;
87 u64 tx_error_pkts;
88 u64 tx_ucast_bytes;
89 u64 tx_mcast_bytes;
90 u64 tx_bcast_bytes;
91 u64 rx_ucast_pkts;
92 u64 rx_mcast_pkts;
93 u64 rx_bcast_pkts;
94 u64 rx_discard_pkts;
95 u64 rx_error_pkts;
96 u64 rx_ucast_bytes;
97 u64 rx_mcast_bytes;
98 u64 rx_bcast_bytes;
99 u64 rx_agg_pkts;
100 u64 rx_agg_bytes;
101 u64 rx_agg_events;
102 u64 rx_agg_aborts;
103 };
104
105 struct bnxt_re_cc_stat {
106 struct bnxt_re_cnp_counters prev[2];
107 struct bnxt_re_cnp_counters cur[2];
108 bool is_first;
109 };
110
111 struct bnxt_re_ext_roce_stats {
112 u64 oob;
113 u64 oos;
114 u64 seq_err_naks_rcvd;
115 u64 rnr_naks_rcvd;
116 u64 missing_resp;
117 u64 to_retransmits;
118 u64 dup_req;
119 };
120
121 struct bnxt_re_rstat {
122 struct bnxt_re_ro_counters prev[2];
123 struct bnxt_re_ro_counters cur[2];
124 struct bnxt_re_rdata_counters rstat[2];
125 struct bnxt_re_ext_rstat ext_rstat[2];
126 struct bnxt_re_ext_roce_stats e_errs;
127 struct bnxt_qplib_roce_stats errs;
128 unsigned long long prev_oob;
129 };
130
131 struct bnxt_re_res_cntrs {
132 atomic_t qp_count;
133 atomic_t rc_qp_count;
134 atomic_t ud_qp_count;
135 atomic_t cq_count;
136 atomic_t srq_count;
137 atomic_t mr_count;
138 atomic_t mw_count;
139 atomic_t ah_count;
140 atomic_t pd_count;
141 atomic_t resize_count;
142 atomic_t max_qp_count;
143 atomic_t max_rc_qp_count;
144 atomic_t max_ud_qp_count;
145 atomic_t max_cq_count;
146 atomic_t max_srq_count;
147 atomic_t max_mr_count;
148 atomic_t max_mw_count;
149 atomic_t max_ah_count;
150 atomic_t max_pd_count;
151 };
152
153 struct bnxt_re_device_stats {
154 struct bnxt_re_rstat dstat;
155 struct bnxt_re_res_cntrs rsors;
156 struct bnxt_re_cc_stat cnps;
157 unsigned long read_tstamp;
158 /* To be used in case to disable stats query from worker or change
159 * query interval. 0 means stats_query disabled.
160 */
161 u32 stats_query_sec;
162 /* A free running counter to be used along with stats_query_sec to
163 * decide whether to issue the command to FW.
164 */
165 u32 stats_query_counter;
166 };
167
bnxt_re_get_cfa_stat_mask(struct bnxt_qplib_chip_ctx * cctx,bool type)168 static inline u64 bnxt_re_get_cfa_stat_mask(struct bnxt_qplib_chip_ctx *cctx,
169 bool type)
170 {
171 u64 mask;
172
173 if (type == BYTE_MASK) {
174 mask = BNXT_RE_CFA_STAT_BYTES_MASK; /* 36 bits */
175 if (_is_chip_gen_p5_p7(cctx))
176 mask >>= 0x01; /* 35 bits */
177 } else {
178 mask = BNXT_RE_CFA_STAT_PKTS_MASK; /* 28 bits */
179 if (_is_chip_gen_p5_p7(cctx))
180 mask |= (0x10000000ULL); /* 29 bits */
181 }
182
183 return mask;
184 }
185
bnxt_re_stat_diff(u64 cur,u64 * prev,u64 mask)186 static inline u64 bnxt_re_stat_diff(u64 cur, u64 *prev, u64 mask)
187 {
188 u64 diff;
189
190 if (!cur)
191 return 0;
192 diff = (cur - *prev) & mask;
193 if (diff)
194 *prev = cur;
195 return diff;
196 }
197
bnxt_re_clear_rsors_stat(struct bnxt_re_res_cntrs * rsors)198 static inline void bnxt_re_clear_rsors_stat(struct bnxt_re_res_cntrs *rsors)
199 {
200 atomic_set(&rsors->qp_count, 0);
201 atomic_set(&rsors->cq_count, 0);
202 atomic_set(&rsors->srq_count, 0);
203 atomic_set(&rsors->mr_count, 0);
204 atomic_set(&rsors->mw_count, 0);
205 atomic_set(&rsors->ah_count, 0);
206 atomic_set(&rsors->pd_count, 0);
207 atomic_set(&rsors->resize_count, 0);
208 atomic_set(&rsors->max_qp_count, 0);
209 atomic_set(&rsors->max_cq_count, 0);
210 atomic_set(&rsors->max_srq_count, 0);
211 atomic_set(&rsors->max_mr_count, 0);
212 atomic_set(&rsors->max_mw_count, 0);
213 atomic_set(&rsors->max_ah_count, 0);
214 atomic_set(&rsors->max_pd_count, 0);
215 atomic_set(&rsors->max_rc_qp_count, 0);
216 atomic_set(&rsors->max_ud_qp_count, 0);
217 }
218
219 enum bnxt_re_hw_stats {
220 BNXT_RE_LINK_STATE,
221 BNXT_RE_MAX_QP,
222 BNXT_RE_MAX_SRQ,
223 BNXT_RE_MAX_CQ,
224 BNXT_RE_MAX_MR,
225 BNXT_RE_MAX_MW,
226 BNXT_RE_MAX_AH,
227 BNXT_RE_MAX_PD,
228 BNXT_RE_ACTIVE_QP,
229 BNXT_RE_ACTIVE_RC_QP,
230 BNXT_RE_ACTIVE_UD_QP,
231 BNXT_RE_ACTIVE_SRQ,
232 BNXT_RE_ACTIVE_CQ,
233 BNXT_RE_ACTIVE_MR,
234 BNXT_RE_ACTIVE_MW,
235 BNXT_RE_ACTIVE_AH,
236 BNXT_RE_ACTIVE_PD,
237 BNXT_RE_QP_WATERMARK,
238 BNXT_RE_RC_QP_WATERMARK,
239 BNXT_RE_UD_QP_WATERMARK,
240 BNXT_RE_SRQ_WATERMARK,
241 BNXT_RE_CQ_WATERMARK,
242 BNXT_RE_MR_WATERMARK,
243 BNXT_RE_MW_WATERMARK,
244 BNXT_RE_AH_WATERMARK,
245 BNXT_RE_PD_WATERMARK,
246 BNXT_RE_RESIZE_CQ_COUNT,
247 BNXT_RE_HW_RETRANSMISSION,
248 BNXT_RE_RECOVERABLE_ERRORS,
249 BNXT_RE_RX_PKTS,
250 BNXT_RE_RX_BYTES,
251 BNXT_RE_TX_PKTS,
252 BNXT_RE_TX_BYTES,
253 BNXT_RE_CNP_TX_PKTS,
254 BNXT_RE_CNP_TX_BYTES,
255 BNXT_RE_CNP_RX_PKTS,
256 BNXT_RE_CNP_RX_BYTES,
257 BNXT_RE_ROCE_ONLY_RX_PKTS,
258 BNXT_RE_ROCE_ONLY_RX_BYTES,
259 BNXT_RE_ROCE_ONLY_TX_PKTS,
260 BNXT_RE_ROCE_ONLY_TX_BYTES,
261 BNXT_RE_RX_ROCE_ERROR_PKTS,
262 BNXT_RE_RX_ROCE_DISCARD_PKTS,
263 BNXT_RE_TX_ROCE_ERROR_PKTS,
264 BNXT_RE_TX_ROCE_DISCARDS_PKTS,
265 BNXT_RE_RES_OOB_DROP_COUNT,
266 BNXT_RE_TX_ATOMIC_REQ,
267 BNXT_RE_RX_ATOMIC_REQ,
268 BNXT_RE_TX_READ_REQ,
269 BNXT_RE_TX_READ_RESP,
270 BNXT_RE_RX_READ_REQ,
271 BNXT_RE_RX_READ_RESP,
272 BNXT_RE_TX_WRITE_REQ,
273 BNXT_RE_RX_WRITE_REQ,
274 BNXT_RE_TX_SEND_REQ,
275 BNXT_RE_RX_SEND_REQ,
276 BNXT_RE_RX_GOOD_PKTS,
277 BNXT_RE_RX_GOOD_BYTES,
278 BNXT_RE_RX_DCN_PAYLOAD_CUT,
279 BNXT_RE_TE_BYPASSED,
280 BNXT_RE_RX_ECN_MARKED_PKTS,
281 BNXT_RE_MAX_RETRY_EXCEEDED,
282 BNXT_RE_TO_RETRANSMITS,
283 BNXT_RE_SEQ_ERR_NAKS_RCVD,
284 BNXT_RE_RNR_NAKS_RCVD,
285 BNXT_RE_MISSING_RESP,
286 BNXT_RE_DUP_REQS,
287 BNXT_RE_UNRECOVERABLE_ERR,
288 BNXT_RE_BAD_RESP_ERR,
289 BNXT_RE_LOCAL_QP_OP_ERR,
290 BNXT_RE_LOCAL_PROTECTION_ERR,
291 BNXT_RE_MEM_MGMT_OP_ERR,
292 BNXT_RE_REMOTE_INVALID_REQ_ERR,
293 BNXT_RE_REMOTE_ACCESS_ERR,
294 BNXT_RE_REMOTE_OP_ERR,
295 BNXT_RE_RES_EXCEED_MAX,
296 BNXT_RE_RES_LENGTH_MISMATCH,
297 BNXT_RE_RES_EXCEEDS_WQE,
298 BNXT_RE_RES_OPCODE_ERR,
299 BNXT_RE_RES_RX_INVALID_RKEY,
300 BNXT_RE_RES_RX_DOMAIN_ERR,
301 BNXT_RE_RES_RX_NO_PERM,
302 BNXT_RE_RES_RX_RANGE_ERR,
303 BNXT_RE_RES_TX_INVALID_RKEY,
304 BNXT_RE_RES_TX_DOMAIN_ERR,
305 BNXT_RE_RES_TX_NO_PERM,
306 BNXT_RE_RES_TX_RANGE_ERR,
307 BNXT_RE_RES_IRRQ_OFLOW,
308 BNXT_RE_RES_UNSUP_OPCODE,
309 BNXT_RE_RES_UNALIGNED_ATOMIC,
310 BNXT_RE_RES_REM_INV_ERR,
311 BNXT_RE_RES_MEM_ERROR64,
312 BNXT_RE_RES_SRQ_ERR,
313 BNXT_RE_RES_CMP_ERR,
314 BNXT_RE_RES_INVALID_DUP_RKEY,
315 BNXT_RE_RES_WQE_FORMAT_ERR,
316 BNXT_RE_RES_CQ_LOAD_ERR,
317 BNXT_RE_RES_SRQ_LOAD_ERR,
318 BNXT_RE_RES_TX_PCI_ERR,
319 BNXT_RE_RES_RX_PCI_ERR,
320 BNXT_RE_RES_OOS_DROP_COUNT,
321 BNXT_RE_NUM_IRQ_STARTED,
322 BNXT_RE_NUM_IRQ_STOPPED,
323 BNXT_RE_POLL_IN_INTR_EN,
324 BNXT_RE_POLL_IN_INTR_DIS,
325 BNXT_RE_CMDQ_FULL_DBG_CNT,
326 BNXT_RE_FW_SERVICE_PROF_TYPE_SUP,
327 BNXT_RE_DBQ_INT_RECV,
328 BNXT_RE_DBQ_INT_EN,
329 BNXT_RE_DBQ_PACING_RESCHED,
330 BNXT_RE_DBQ_PACING_CMPL,
331 BNXT_RE_DBQ_PACING_ALERT,
332 BNXT_RE_DBQ_DBR_FIFO_REG,
333 BNXT_RE_DBQ_NUM_EXT_COUNTERS
334 };
335
336 #define BNXT_RE_NUM_STD_COUNTERS (BNXT_RE_OUT_OF_SEQ_ERR + 1)
337
338 struct bnxt_re_stats {
339 struct bnxt_qplib_roce_stats errs;
340 struct bnxt_qplib_ext_stat ext_stat;
341 };
342
343 struct rdma_hw_stats *bnxt_re_alloc_hw_port_stats(struct ib_device *ibdev,
344 u8 port_num);
345 int bnxt_re_get_hw_stats(struct ib_device *ibdev,
346 struct rdma_hw_stats *stats,
347 u8 port, int index);
348 int bnxt_re_get_device_stats(struct bnxt_re_dev *rdev);
349 int bnxt_re_get_flow_stats_from_service_pf(struct bnxt_re_dev *rdev,
350 struct bnxt_re_flow_counters *stats,
351 struct bnxt_qplib_query_stats_info *sinfo);
352 int bnxt_re_get_qos_stats(struct bnxt_re_dev *rdev);
353 #endif /* __STATS_H__ */
354