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_TO_RETRANSMITS] = "to_retransmits",
72 [BNXT_RE_SEQ_ERR_NAKS_RCVD] = "seq_err_naks_rcvd",
73 [BNXT_RE_MAX_RETRY_EXCEEDED] = "max_retry_exceeded",
74 [BNXT_RE_RNR_NAKS_RCVD] = "rnr_naks_rcvd",
75 [BNXT_RE_MISSING_RESP] = "missin_resp",
76 [BNXT_RE_UNRECOVERABLE_ERR] = "unrecoverable_err",
77 [BNXT_RE_BAD_RESP_ERR] = "bad_resp_err",
78 [BNXT_RE_LOCAL_QP_OP_ERR] = "local_qp_op_err",
79 [BNXT_RE_LOCAL_PROTECTION_ERR] = "local_protection_err",
80 [BNXT_RE_MEM_MGMT_OP_ERR] = "mem_mgmt_op_err",
81 [BNXT_RE_REMOTE_INVALID_REQ_ERR] = "remote_invalid_req_err",
82 [BNXT_RE_REMOTE_ACCESS_ERR] = "remote_access_err",
83 [BNXT_RE_REMOTE_OP_ERR] = "remote_op_err",
84 [BNXT_RE_DUP_REQ] = "dup_req",
85 [BNXT_RE_RES_EXCEED_MAX] = "res_exceed_max",
86 [BNXT_RE_RES_LENGTH_MISMATCH] = "res_length_mismatch",
87 [BNXT_RE_RES_EXCEEDS_WQE] = "res_exceeds_wqe",
88 [BNXT_RE_RES_OPCODE_ERR] = "res_opcode_err",
89 [BNXT_RE_RES_RX_INVALID_RKEY] = "res_rx_invalid_rkey",
90 [BNXT_RE_RES_RX_DOMAIN_ERR] = "res_rx_domain_err",
91 [BNXT_RE_RES_RX_NO_PERM] = "res_rx_no_perm",
92 [BNXT_RE_RES_RX_RANGE_ERR] = "res_rx_range_err",
93 [BNXT_RE_RES_TX_INVALID_RKEY] = "res_tx_invalid_rkey",
94 [BNXT_RE_RES_TX_DOMAIN_ERR] = "res_tx_domain_err",
95 [BNXT_RE_RES_TX_NO_PERM] = "res_tx_no_perm",
96 [BNXT_RE_RES_TX_RANGE_ERR] = "res_tx_range_err",
97 [BNXT_RE_RES_IRRQ_OFLOW] = "res_irrq_oflow",
98 [BNXT_RE_RES_UNSUP_OPCODE] = "res_unsup_opcode",
99 [BNXT_RE_RES_UNALIGNED_ATOMIC] = "res_unaligned_atomic",
100 [BNXT_RE_RES_REM_INV_ERR] = "res_rem_inv_err",
101 [BNXT_RE_RES_MEM_ERROR] = "res_mem_err",
102 [BNXT_RE_RES_SRQ_ERR] = "res_srq_err",
103 [BNXT_RE_RES_CMP_ERR] = "res_cmp_err",
104 [BNXT_RE_RES_INVALID_DUP_RKEY] = "res_invalid_dup_rkey",
105 [BNXT_RE_RES_WQE_FORMAT_ERR] = "res_wqe_format_err",
106 [BNXT_RE_RES_CQ_LOAD_ERR] = "res_cq_load_err",
107 [BNXT_RE_RES_SRQ_LOAD_ERR] = "res_srq_load_err",
108 [BNXT_RE_RES_TX_PCI_ERR] = "res_tx_pci_err",
109 [BNXT_RE_RES_RX_PCI_ERR] = "res_rx_pci_err"
110};
111
112int bnxt_re_ib_get_hw_stats(struct ib_device *ibdev,
113 struct rdma_hw_stats *stats,
114 u8 port, int index)
115{
116 struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
117 struct ctx_hw_stats *bnxt_re_stats = rdev->qplib_ctx.stats.dma;
118 int rc = 0;
119
120 if (!port || !stats)
121 return -EINVAL;
122
123 stats->value[BNXT_RE_ACTIVE_QP] = atomic_read(&rdev->qp_count);
124 stats->value[BNXT_RE_ACTIVE_SRQ] = atomic_read(&rdev->srq_count);
125 stats->value[BNXT_RE_ACTIVE_CQ] = atomic_read(&rdev->cq_count);
126 stats->value[BNXT_RE_ACTIVE_MR] = atomic_read(&rdev->mr_count);
127 stats->value[BNXT_RE_ACTIVE_MW] = atomic_read(&rdev->mw_count);
128 if (bnxt_re_stats) {
129 stats->value[BNXT_RE_RECOVERABLE_ERRORS] =
130 le64_to_cpu(bnxt_re_stats->tx_bcast_pkts);
131 stats->value[BNXT_RE_RX_PKTS] =
132 le64_to_cpu(bnxt_re_stats->rx_ucast_pkts);
133 stats->value[BNXT_RE_RX_BYTES] =
134 le64_to_cpu(bnxt_re_stats->rx_ucast_bytes);
135 stats->value[BNXT_RE_TX_PKTS] =
136 le64_to_cpu(bnxt_re_stats->tx_ucast_pkts);
137 stats->value[BNXT_RE_TX_BYTES] =
138 le64_to_cpu(bnxt_re_stats->tx_ucast_bytes);
139 }
140 if (test_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS, &rdev->flags)) {
141 rc = bnxt_qplib_get_roce_stats(&rdev->rcfw, &rdev->stats);
142 if (rc)
143 clear_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS,
144 &rdev->flags);
145 stats->value[BNXT_RE_TO_RETRANSMITS] =
146 rdev->stats.to_retransmits;
147 stats->value[BNXT_RE_SEQ_ERR_NAKS_RCVD] =
148 rdev->stats.seq_err_naks_rcvd;
149 stats->value[BNXT_RE_MAX_RETRY_EXCEEDED] =
150 rdev->stats.max_retry_exceeded;
151 stats->value[BNXT_RE_RNR_NAKS_RCVD] =
152 rdev->stats.rnr_naks_rcvd;
153 stats->value[BNXT_RE_MISSING_RESP] =
154 rdev->stats.missing_resp;
155 stats->value[BNXT_RE_UNRECOVERABLE_ERR] =
156 rdev->stats.unrecoverable_err;
157 stats->value[BNXT_RE_BAD_RESP_ERR] =
158 rdev->stats.bad_resp_err;
159 stats->value[BNXT_RE_LOCAL_QP_OP_ERR] =
160 rdev->stats.local_qp_op_err;
161 stats->value[BNXT_RE_LOCAL_PROTECTION_ERR] =
162 rdev->stats.local_protection_err;
163 stats->value[BNXT_RE_MEM_MGMT_OP_ERR] =
164 rdev->stats.mem_mgmt_op_err;
165 stats->value[BNXT_RE_REMOTE_INVALID_REQ_ERR] =
166 rdev->stats.remote_invalid_req_err;
167 stats->value[BNXT_RE_REMOTE_ACCESS_ERR] =
168 rdev->stats.remote_access_err;
169 stats->value[BNXT_RE_REMOTE_OP_ERR] =
170 rdev->stats.remote_op_err;
171 stats->value[BNXT_RE_DUP_REQ] =
172 rdev->stats.dup_req;
173 stats->value[BNXT_RE_RES_EXCEED_MAX] =
174 rdev->stats.res_exceed_max;
175 stats->value[BNXT_RE_RES_LENGTH_MISMATCH] =
176 rdev->stats.res_length_mismatch;
177 stats->value[BNXT_RE_RES_EXCEEDS_WQE] =
178 rdev->stats.res_exceeds_wqe;
179 stats->value[BNXT_RE_RES_OPCODE_ERR] =
180 rdev->stats.res_opcode_err;
181 stats->value[BNXT_RE_RES_RX_INVALID_RKEY] =
182 rdev->stats.res_rx_invalid_rkey;
183 stats->value[BNXT_RE_RES_RX_DOMAIN_ERR] =
184 rdev->stats.res_rx_domain_err;
185 stats->value[BNXT_RE_RES_RX_NO_PERM] =
186 rdev->stats.res_rx_no_perm;
187 stats->value[BNXT_RE_RES_RX_RANGE_ERR] =
188 rdev->stats.res_rx_range_err;
189 stats->value[BNXT_RE_RES_TX_INVALID_RKEY] =
190 rdev->stats.res_tx_invalid_rkey;
191 stats->value[BNXT_RE_RES_TX_DOMAIN_ERR] =
192 rdev->stats.res_tx_domain_err;
193 stats->value[BNXT_RE_RES_TX_NO_PERM] =
194 rdev->stats.res_tx_no_perm;
195 stats->value[BNXT_RE_RES_TX_RANGE_ERR] =
196 rdev->stats.res_tx_range_err;
197 stats->value[BNXT_RE_RES_IRRQ_OFLOW] =
198 rdev->stats.res_irrq_oflow;
199 stats->value[BNXT_RE_RES_UNSUP_OPCODE] =
200 rdev->stats.res_unsup_opcode;
201 stats->value[BNXT_RE_RES_UNALIGNED_ATOMIC] =
202 rdev->stats.res_unaligned_atomic;
203 stats->value[BNXT_RE_RES_REM_INV_ERR] =
204 rdev->stats.res_rem_inv_err;
205 stats->value[BNXT_RE_RES_MEM_ERROR] =
206 rdev->stats.res_mem_error;
207 stats->value[BNXT_RE_RES_SRQ_ERR] =
208 rdev->stats.res_srq_err;
209 stats->value[BNXT_RE_RES_CMP_ERR] =
210 rdev->stats.res_cmp_err;
211 stats->value[BNXT_RE_RES_INVALID_DUP_RKEY] =
212 rdev->stats.res_invalid_dup_rkey;
213 stats->value[BNXT_RE_RES_WQE_FORMAT_ERR] =
214 rdev->stats.res_wqe_format_err;
215 stats->value[BNXT_RE_RES_CQ_LOAD_ERR] =
216 rdev->stats.res_cq_load_err;
217 stats->value[BNXT_RE_RES_SRQ_LOAD_ERR] =
218 rdev->stats.res_srq_load_err;
219 stats->value[BNXT_RE_RES_TX_PCI_ERR] =
220 rdev->stats.res_tx_pci_err;
221 stats->value[BNXT_RE_RES_RX_PCI_ERR] =
222 rdev->stats.res_rx_pci_err;
223 }
224
225 return ARRAY_SIZE(bnxt_re_stat_name);
226}
227
228struct rdma_hw_stats *bnxt_re_ib_alloc_hw_stats(struct ib_device *ibdev,
229 u8 port_num)
230{
231 BUILD_BUG_ON(ARRAY_SIZE(bnxt_re_stat_name) != BNXT_RE_NUM_COUNTERS);
232
233 if (!port_num)
234 return NULL;
235
236 return rdma_alloc_hw_stats_struct(bnxt_re_stat_name,
237 ARRAY_SIZE(bnxt_re_stat_name),
238 RDMA_HW_STATS_DEFAULT_LIFESPAN);
239}
240