1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#include <linux/interrupt.h>
41#include <linux/types.h>
42#include <linux/spinlock.h>
43#include <linux/sched.h>
44#include <linux/slab.h>
45#include <linux/pci.h>
46#include <linux/prefetch.h>
47#include <linux/delay.h>
48
49#include <rdma/ib_addr.h>
50
51#include "bnxt_ulp.h"
52#include "roce_hsi.h"
53#include "qplib_res.h"
54#include "qplib_sp.h"
55#include "qplib_fp.h"
56#include "qplib_rcfw.h"
57#include "bnxt_re.h"
58#include "hw_counters.h"
59
60static const char * const bnxt_re_stat_name[] = {
61 [BNXT_RE_ACTIVE_QP] = "active_qps",
62 [BNXT_RE_ACTIVE_SRQ] = "active_srqs",
63 [BNXT_RE_ACTIVE_CQ] = "active_cqs",
64 [BNXT_RE_ACTIVE_MR] = "active_mrs",
65 [BNXT_RE_ACTIVE_MW] = "active_mws",
66 [BNXT_RE_RX_PKTS] = "rx_pkts",
67 [BNXT_RE_RX_BYTES] = "rx_bytes",
68 [BNXT_RE_TX_PKTS] = "tx_pkts",
69 [BNXT_RE_TX_BYTES] = "tx_bytes",
70 [BNXT_RE_RECOVERABLE_ERRORS] = "recoverable_errors",
71 [BNXT_RE_RX_DROPS] = "rx_roce_drops",
72 [BNXT_RE_RX_DISCARDS] = "rx_roce_discards",
73 [BNXT_RE_TO_RETRANSMITS] = "to_retransmits",
74 [BNXT_RE_SEQ_ERR_NAKS_RCVD] = "seq_err_naks_rcvd",
75 [BNXT_RE_MAX_RETRY_EXCEEDED] = "max_retry_exceeded",
76 [BNXT_RE_RNR_NAKS_RCVD] = "rnr_naks_rcvd",
77 [BNXT_RE_MISSING_RESP] = "missing_resp",
78 [BNXT_RE_UNRECOVERABLE_ERR] = "unrecoverable_err",
79 [BNXT_RE_BAD_RESP_ERR] = "bad_resp_err",
80 [BNXT_RE_LOCAL_QP_OP_ERR] = "local_qp_op_err",
81 [BNXT_RE_LOCAL_PROTECTION_ERR] = "local_protection_err",
82 [BNXT_RE_MEM_MGMT_OP_ERR] = "mem_mgmt_op_err",
83 [BNXT_RE_REMOTE_INVALID_REQ_ERR] = "remote_invalid_req_err",
84 [BNXT_RE_REMOTE_ACCESS_ERR] = "remote_access_err",
85 [BNXT_RE_REMOTE_OP_ERR] = "remote_op_err",
86 [BNXT_RE_DUP_REQ] = "dup_req",
87 [BNXT_RE_RES_EXCEED_MAX] = "res_exceed_max",
88 [BNXT_RE_RES_LENGTH_MISMATCH] = "res_length_mismatch",
89 [BNXT_RE_RES_EXCEEDS_WQE] = "res_exceeds_wqe",
90 [BNXT_RE_RES_OPCODE_ERR] = "res_opcode_err",
91 [BNXT_RE_RES_RX_INVALID_RKEY] = "res_rx_invalid_rkey",
92 [BNXT_RE_RES_RX_DOMAIN_ERR] = "res_rx_domain_err",
93 [BNXT_RE_RES_RX_NO_PERM] = "res_rx_no_perm",
94 [BNXT_RE_RES_RX_RANGE_ERR] = "res_rx_range_err",
95 [BNXT_RE_RES_TX_INVALID_RKEY] = "res_tx_invalid_rkey",
96 [BNXT_RE_RES_TX_DOMAIN_ERR] = "res_tx_domain_err",
97 [BNXT_RE_RES_TX_NO_PERM] = "res_tx_no_perm",
98 [BNXT_RE_RES_TX_RANGE_ERR] = "res_tx_range_err",
99 [BNXT_RE_RES_IRRQ_OFLOW] = "res_irrq_oflow",
100 [BNXT_RE_RES_UNSUP_OPCODE] = "res_unsup_opcode",
101 [BNXT_RE_RES_UNALIGNED_ATOMIC] = "res_unaligned_atomic",
102 [BNXT_RE_RES_REM_INV_ERR] = "res_rem_inv_err",
103 [BNXT_RE_RES_MEM_ERROR] = "res_mem_err",
104 [BNXT_RE_RES_SRQ_ERR] = "res_srq_err",
105 [BNXT_RE_RES_CMP_ERR] = "res_cmp_err",
106 [BNXT_RE_RES_INVALID_DUP_RKEY] = "res_invalid_dup_rkey",
107 [BNXT_RE_RES_WQE_FORMAT_ERR] = "res_wqe_format_err",
108 [BNXT_RE_RES_CQ_LOAD_ERR] = "res_cq_load_err",
109 [BNXT_RE_RES_SRQ_LOAD_ERR] = "res_srq_load_err",
110 [BNXT_RE_RES_TX_PCI_ERR] = "res_tx_pci_err",
111 [BNXT_RE_RES_RX_PCI_ERR] = "res_rx_pci_err",
112 [BNXT_RE_OUT_OF_SEQ_ERR] = "oos_drop_count"
113};
114
115int bnxt_re_ib_get_hw_stats(struct ib_device *ibdev,
116 struct rdma_hw_stats *stats,
117 u8 port, int index)
118{
119 struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
120 struct ctx_hw_stats *bnxt_re_stats = rdev->qplib_ctx.stats.dma;
121 int rc = 0;
122
123 if (!port || !stats)
124 return -EINVAL;
125
126 stats->value[BNXT_RE_ACTIVE_QP] = atomic_read(&rdev->qp_count);
127 stats->value[BNXT_RE_ACTIVE_SRQ] = atomic_read(&rdev->srq_count);
128 stats->value[BNXT_RE_ACTIVE_CQ] = atomic_read(&rdev->cq_count);
129 stats->value[BNXT_RE_ACTIVE_MR] = atomic_read(&rdev->mr_count);
130 stats->value[BNXT_RE_ACTIVE_MW] = atomic_read(&rdev->mw_count);
131 if (bnxt_re_stats) {
132 stats->value[BNXT_RE_RECOVERABLE_ERRORS] =
133 le64_to_cpu(bnxt_re_stats->tx_bcast_pkts);
134 stats->value[BNXT_RE_RX_DROPS] =
135 le64_to_cpu(bnxt_re_stats->rx_error_pkts);
136 stats->value[BNXT_RE_RX_DISCARDS] =
137 le64_to_cpu(bnxt_re_stats->rx_discard_pkts);
138 stats->value[BNXT_RE_RX_PKTS] =
139 le64_to_cpu(bnxt_re_stats->rx_ucast_pkts);
140 stats->value[BNXT_RE_RX_BYTES] =
141 le64_to_cpu(bnxt_re_stats->rx_ucast_bytes);
142 stats->value[BNXT_RE_TX_PKTS] =
143 le64_to_cpu(bnxt_re_stats->tx_ucast_pkts);
144 stats->value[BNXT_RE_TX_BYTES] =
145 le64_to_cpu(bnxt_re_stats->tx_ucast_bytes);
146 }
147 if (test_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS, &rdev->flags)) {
148 rc = bnxt_qplib_get_roce_stats(&rdev->rcfw, &rdev->stats);
149 if (rc)
150 clear_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS,
151 &rdev->flags);
152 stats->value[BNXT_RE_TO_RETRANSMITS] =
153 rdev->stats.to_retransmits;
154 stats->value[BNXT_RE_SEQ_ERR_NAKS_RCVD] =
155 rdev->stats.seq_err_naks_rcvd;
156 stats->value[BNXT_RE_MAX_RETRY_EXCEEDED] =
157 rdev->stats.max_retry_exceeded;
158 stats->value[BNXT_RE_RNR_NAKS_RCVD] =
159 rdev->stats.rnr_naks_rcvd;
160 stats->value[BNXT_RE_MISSING_RESP] =
161 rdev->stats.missing_resp;
162 stats->value[BNXT_RE_UNRECOVERABLE_ERR] =
163 rdev->stats.unrecoverable_err;
164 stats->value[BNXT_RE_BAD_RESP_ERR] =
165 rdev->stats.bad_resp_err;
166 stats->value[BNXT_RE_LOCAL_QP_OP_ERR] =
167 rdev->stats.local_qp_op_err;
168 stats->value[BNXT_RE_LOCAL_PROTECTION_ERR] =
169 rdev->stats.local_protection_err;
170 stats->value[BNXT_RE_MEM_MGMT_OP_ERR] =
171 rdev->stats.mem_mgmt_op_err;
172 stats->value[BNXT_RE_REMOTE_INVALID_REQ_ERR] =
173 rdev->stats.remote_invalid_req_err;
174 stats->value[BNXT_RE_REMOTE_ACCESS_ERR] =
175 rdev->stats.remote_access_err;
176 stats->value[BNXT_RE_REMOTE_OP_ERR] =
177 rdev->stats.remote_op_err;
178 stats->value[BNXT_RE_DUP_REQ] =
179 rdev->stats.dup_req;
180 stats->value[BNXT_RE_RES_EXCEED_MAX] =
181 rdev->stats.res_exceed_max;
182 stats->value[BNXT_RE_RES_LENGTH_MISMATCH] =
183 rdev->stats.res_length_mismatch;
184 stats->value[BNXT_RE_RES_EXCEEDS_WQE] =
185 rdev->stats.res_exceeds_wqe;
186 stats->value[BNXT_RE_RES_OPCODE_ERR] =
187 rdev->stats.res_opcode_err;
188 stats->value[BNXT_RE_RES_RX_INVALID_RKEY] =
189 rdev->stats.res_rx_invalid_rkey;
190 stats->value[BNXT_RE_RES_RX_DOMAIN_ERR] =
191 rdev->stats.res_rx_domain_err;
192 stats->value[BNXT_RE_RES_RX_NO_PERM] =
193 rdev->stats.res_rx_no_perm;
194 stats->value[BNXT_RE_RES_RX_RANGE_ERR] =
195 rdev->stats.res_rx_range_err;
196 stats->value[BNXT_RE_RES_TX_INVALID_RKEY] =
197 rdev->stats.res_tx_invalid_rkey;
198 stats->value[BNXT_RE_RES_TX_DOMAIN_ERR] =
199 rdev->stats.res_tx_domain_err;
200 stats->value[BNXT_RE_RES_TX_NO_PERM] =
201 rdev->stats.res_tx_no_perm;
202 stats->value[BNXT_RE_RES_TX_RANGE_ERR] =
203 rdev->stats.res_tx_range_err;
204 stats->value[BNXT_RE_RES_IRRQ_OFLOW] =
205 rdev->stats.res_irrq_oflow;
206 stats->value[BNXT_RE_RES_UNSUP_OPCODE] =
207 rdev->stats.res_unsup_opcode;
208 stats->value[BNXT_RE_RES_UNALIGNED_ATOMIC] =
209 rdev->stats.res_unaligned_atomic;
210 stats->value[BNXT_RE_RES_REM_INV_ERR] =
211 rdev->stats.res_rem_inv_err;
212 stats->value[BNXT_RE_RES_MEM_ERROR] =
213 rdev->stats.res_mem_error;
214 stats->value[BNXT_RE_RES_SRQ_ERR] =
215 rdev->stats.res_srq_err;
216 stats->value[BNXT_RE_RES_CMP_ERR] =
217 rdev->stats.res_cmp_err;
218 stats->value[BNXT_RE_RES_INVALID_DUP_RKEY] =
219 rdev->stats.res_invalid_dup_rkey;
220 stats->value[BNXT_RE_RES_WQE_FORMAT_ERR] =
221 rdev->stats.res_wqe_format_err;
222 stats->value[BNXT_RE_RES_CQ_LOAD_ERR] =
223 rdev->stats.res_cq_load_err;
224 stats->value[BNXT_RE_RES_SRQ_LOAD_ERR] =
225 rdev->stats.res_srq_load_err;
226 stats->value[BNXT_RE_RES_TX_PCI_ERR] =
227 rdev->stats.res_tx_pci_err;
228 stats->value[BNXT_RE_RES_RX_PCI_ERR] =
229 rdev->stats.res_rx_pci_err;
230 stats->value[BNXT_RE_OUT_OF_SEQ_ERR] =
231 rdev->stats.res_oos_drop_count;
232 }
233
234 return ARRAY_SIZE(bnxt_re_stat_name);
235}
236
237struct rdma_hw_stats *bnxt_re_ib_alloc_hw_stats(struct ib_device *ibdev,
238 u8 port_num)
239{
240 BUILD_BUG_ON(ARRAY_SIZE(bnxt_re_stat_name) != BNXT_RE_NUM_COUNTERS);
241
242 if (!port_num)
243 return NULL;
244
245 return rdma_alloc_hw_stats_struct(bnxt_re_stat_name,
246 ARRAY_SIZE(bnxt_re_stat_name),
247 RDMA_HW_STATS_DEFAULT_LIFESPAN);
248}
249