blob: ac98721d61f8421ab532a2babc81f35b0c66d78f [file] [log] [blame]
Selvin Xaviera51f06e2014-02-04 11:57:07 +05301/*******************************************************************
2 * This file is part of the Emulex RoCE Device Driver for *
3 * RoCE (RDMA over Converged Ethernet) adapters. *
4 * Copyright (C) 2008-2014 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *
20 * Contact Information:
21 * linux-drivers@emulex.com
22 *
23 * Emulex
24 * 3333 Susan Street
25 * Costa Mesa, CA 92626
26 *******************************************************************/
27
28#include <rdma/ib_addr.h>
Mitesh Ahujacad1fbb2014-12-18 14:12:55 +053029#include <rdma/ib_pma.h>
Selvin Xaviera51f06e2014-02-04 11:57:07 +053030#include "ocrdma_stats.h"
31
32static struct dentry *ocrdma_dbgfs_dir;
33
34static int ocrdma_add_stat(char *start, char *pcur,
35 char *name, u64 count)
36{
37 char buff[128] = {0};
38 int cpy_len = 0;
39
40 snprintf(buff, 128, "%s: %llu\n", name, count);
41 cpy_len = strlen(buff);
42
43 if (pcur + cpy_len > start + OCRDMA_MAX_DBGFS_MEM) {
44 pr_err("%s: No space in stats buff\n", __func__);
45 return 0;
46 }
47
48 memcpy(pcur, buff, cpy_len);
49 return cpy_len;
50}
51
52static bool ocrdma_alloc_stats_mem(struct ocrdma_dev *dev)
53{
54 struct stats_mem *mem = &dev->stats_mem;
55
56 /* Alloc mbox command mem*/
57 mem->size = max_t(u32, sizeof(struct ocrdma_rdma_stats_req),
58 sizeof(struct ocrdma_rdma_stats_resp));
59
60 mem->va = dma_alloc_coherent(&dev->nic_info.pdev->dev, mem->size,
61 &mem->pa, GFP_KERNEL);
62 if (!mem->va) {
63 pr_err("%s: stats mbox allocation failed\n", __func__);
64 return false;
65 }
66
67 memset(mem->va, 0, mem->size);
68
69 /* Alloc debugfs mem */
70 mem->debugfs_mem = kzalloc(OCRDMA_MAX_DBGFS_MEM, GFP_KERNEL);
71 if (!mem->debugfs_mem) {
72 pr_err("%s: stats debugfs mem allocation failed\n", __func__);
73 return false;
74 }
75
76 return true;
77}
78
79static void ocrdma_release_stats_mem(struct ocrdma_dev *dev)
80{
81 struct stats_mem *mem = &dev->stats_mem;
82
83 if (mem->va)
84 dma_free_coherent(&dev->nic_info.pdev->dev, mem->size,
85 mem->va, mem->pa);
86 kfree(mem->debugfs_mem);
87}
88
89static char *ocrdma_resource_stats(struct ocrdma_dev *dev)
90{
91 char *stats = dev->stats_mem.debugfs_mem, *pcur;
92 struct ocrdma_rdma_stats_resp *rdma_stats =
93 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
94 struct ocrdma_rsrc_stats *rsrc_stats = &rdma_stats->act_rsrc_stats;
95
96 memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
97
98 pcur = stats;
99 pcur += ocrdma_add_stat(stats, pcur, "active_dpp_pds",
100 (u64)rsrc_stats->dpp_pds);
101 pcur += ocrdma_add_stat(stats, pcur, "active_non_dpp_pds",
102 (u64)rsrc_stats->non_dpp_pds);
103 pcur += ocrdma_add_stat(stats, pcur, "active_rc_dpp_qps",
104 (u64)rsrc_stats->rc_dpp_qps);
105 pcur += ocrdma_add_stat(stats, pcur, "active_uc_dpp_qps",
106 (u64)rsrc_stats->uc_dpp_qps);
107 pcur += ocrdma_add_stat(stats, pcur, "active_ud_dpp_qps",
108 (u64)rsrc_stats->ud_dpp_qps);
109 pcur += ocrdma_add_stat(stats, pcur, "active_rc_non_dpp_qps",
110 (u64)rsrc_stats->rc_non_dpp_qps);
111 pcur += ocrdma_add_stat(stats, pcur, "active_uc_non_dpp_qps",
112 (u64)rsrc_stats->uc_non_dpp_qps);
113 pcur += ocrdma_add_stat(stats, pcur, "active_ud_non_dpp_qps",
114 (u64)rsrc_stats->ud_non_dpp_qps);
115 pcur += ocrdma_add_stat(stats, pcur, "active_srqs",
116 (u64)rsrc_stats->srqs);
117 pcur += ocrdma_add_stat(stats, pcur, "active_rbqs",
118 (u64)rsrc_stats->rbqs);
119 pcur += ocrdma_add_stat(stats, pcur, "active_64K_nsmr",
120 (u64)rsrc_stats->r64K_nsmr);
121 pcur += ocrdma_add_stat(stats, pcur, "active_64K_to_2M_nsmr",
122 (u64)rsrc_stats->r64K_to_2M_nsmr);
123 pcur += ocrdma_add_stat(stats, pcur, "active_2M_to_44M_nsmr",
124 (u64)rsrc_stats->r2M_to_44M_nsmr);
125 pcur += ocrdma_add_stat(stats, pcur, "active_44M_to_1G_nsmr",
126 (u64)rsrc_stats->r44M_to_1G_nsmr);
127 pcur += ocrdma_add_stat(stats, pcur, "active_1G_to_4G_nsmr",
128 (u64)rsrc_stats->r1G_to_4G_nsmr);
129 pcur += ocrdma_add_stat(stats, pcur, "active_nsmr_count_4G_to_32G",
130 (u64)rsrc_stats->nsmr_count_4G_to_32G);
131 pcur += ocrdma_add_stat(stats, pcur, "active_32G_to_64G_nsmr",
132 (u64)rsrc_stats->r32G_to_64G_nsmr);
133 pcur += ocrdma_add_stat(stats, pcur, "active_64G_to_128G_nsmr",
134 (u64)rsrc_stats->r64G_to_128G_nsmr);
135 pcur += ocrdma_add_stat(stats, pcur, "active_128G_to_higher_nsmr",
136 (u64)rsrc_stats->r128G_to_higher_nsmr);
137 pcur += ocrdma_add_stat(stats, pcur, "active_embedded_nsmr",
138 (u64)rsrc_stats->embedded_nsmr);
139 pcur += ocrdma_add_stat(stats, pcur, "active_frmr",
140 (u64)rsrc_stats->frmr);
141 pcur += ocrdma_add_stat(stats, pcur, "active_prefetch_qps",
142 (u64)rsrc_stats->prefetch_qps);
143 pcur += ocrdma_add_stat(stats, pcur, "active_ondemand_qps",
144 (u64)rsrc_stats->ondemand_qps);
145 pcur += ocrdma_add_stat(stats, pcur, "active_phy_mr",
146 (u64)rsrc_stats->phy_mr);
147 pcur += ocrdma_add_stat(stats, pcur, "active_mw",
148 (u64)rsrc_stats->mw);
149
150 /* Print the threshold stats */
151 rsrc_stats = &rdma_stats->th_rsrc_stats;
152
153 pcur += ocrdma_add_stat(stats, pcur, "threshold_dpp_pds",
154 (u64)rsrc_stats->dpp_pds);
155 pcur += ocrdma_add_stat(stats, pcur, "threshold_non_dpp_pds",
156 (u64)rsrc_stats->non_dpp_pds);
157 pcur += ocrdma_add_stat(stats, pcur, "threshold_rc_dpp_qps",
158 (u64)rsrc_stats->rc_dpp_qps);
159 pcur += ocrdma_add_stat(stats, pcur, "threshold_uc_dpp_qps",
160 (u64)rsrc_stats->uc_dpp_qps);
161 pcur += ocrdma_add_stat(stats, pcur, "threshold_ud_dpp_qps",
162 (u64)rsrc_stats->ud_dpp_qps);
163 pcur += ocrdma_add_stat(stats, pcur, "threshold_rc_non_dpp_qps",
164 (u64)rsrc_stats->rc_non_dpp_qps);
165 pcur += ocrdma_add_stat(stats, pcur, "threshold_uc_non_dpp_qps",
166 (u64)rsrc_stats->uc_non_dpp_qps);
167 pcur += ocrdma_add_stat(stats, pcur, "threshold_ud_non_dpp_qps",
168 (u64)rsrc_stats->ud_non_dpp_qps);
169 pcur += ocrdma_add_stat(stats, pcur, "threshold_srqs",
170 (u64)rsrc_stats->srqs);
171 pcur += ocrdma_add_stat(stats, pcur, "threshold_rbqs",
172 (u64)rsrc_stats->rbqs);
173 pcur += ocrdma_add_stat(stats, pcur, "threshold_64K_nsmr",
174 (u64)rsrc_stats->r64K_nsmr);
175 pcur += ocrdma_add_stat(stats, pcur, "threshold_64K_to_2M_nsmr",
176 (u64)rsrc_stats->r64K_to_2M_nsmr);
177 pcur += ocrdma_add_stat(stats, pcur, "threshold_2M_to_44M_nsmr",
178 (u64)rsrc_stats->r2M_to_44M_nsmr);
179 pcur += ocrdma_add_stat(stats, pcur, "threshold_44M_to_1G_nsmr",
180 (u64)rsrc_stats->r44M_to_1G_nsmr);
181 pcur += ocrdma_add_stat(stats, pcur, "threshold_1G_to_4G_nsmr",
182 (u64)rsrc_stats->r1G_to_4G_nsmr);
183 pcur += ocrdma_add_stat(stats, pcur, "threshold_nsmr_count_4G_to_32G",
184 (u64)rsrc_stats->nsmr_count_4G_to_32G);
185 pcur += ocrdma_add_stat(stats, pcur, "threshold_32G_to_64G_nsmr",
186 (u64)rsrc_stats->r32G_to_64G_nsmr);
187 pcur += ocrdma_add_stat(stats, pcur, "threshold_64G_to_128G_nsmr",
188 (u64)rsrc_stats->r64G_to_128G_nsmr);
189 pcur += ocrdma_add_stat(stats, pcur, "threshold_128G_to_higher_nsmr",
190 (u64)rsrc_stats->r128G_to_higher_nsmr);
191 pcur += ocrdma_add_stat(stats, pcur, "threshold_embedded_nsmr",
192 (u64)rsrc_stats->embedded_nsmr);
193 pcur += ocrdma_add_stat(stats, pcur, "threshold_frmr",
194 (u64)rsrc_stats->frmr);
195 pcur += ocrdma_add_stat(stats, pcur, "threshold_prefetch_qps",
196 (u64)rsrc_stats->prefetch_qps);
197 pcur += ocrdma_add_stat(stats, pcur, "threshold_ondemand_qps",
198 (u64)rsrc_stats->ondemand_qps);
199 pcur += ocrdma_add_stat(stats, pcur, "threshold_phy_mr",
200 (u64)rsrc_stats->phy_mr);
201 pcur += ocrdma_add_stat(stats, pcur, "threshold_mw",
202 (u64)rsrc_stats->mw);
203 return stats;
204}
205
206static char *ocrdma_rx_stats(struct ocrdma_dev *dev)
207{
208 char *stats = dev->stats_mem.debugfs_mem, *pcur;
209 struct ocrdma_rdma_stats_resp *rdma_stats =
210 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
211 struct ocrdma_rx_stats *rx_stats = &rdma_stats->rx_stats;
212
213 memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
214
215 pcur = stats;
216 pcur += ocrdma_add_stat
217 (stats, pcur, "roce_frame_bytes",
218 convert_to_64bit(rx_stats->roce_frame_bytes_lo,
219 rx_stats->roce_frame_bytes_hi));
220 pcur += ocrdma_add_stat(stats, pcur, "roce_frame_icrc_drops",
221 (u64)rx_stats->roce_frame_icrc_drops);
222 pcur += ocrdma_add_stat(stats, pcur, "roce_frame_payload_len_drops",
223 (u64)rx_stats->roce_frame_payload_len_drops);
224 pcur += ocrdma_add_stat(stats, pcur, "ud_drops",
225 (u64)rx_stats->ud_drops);
226 pcur += ocrdma_add_stat(stats, pcur, "qp1_drops",
227 (u64)rx_stats->qp1_drops);
228 pcur += ocrdma_add_stat(stats, pcur, "psn_error_request_packets",
229 (u64)rx_stats->psn_error_request_packets);
230 pcur += ocrdma_add_stat(stats, pcur, "psn_error_resp_packets",
231 (u64)rx_stats->psn_error_resp_packets);
232 pcur += ocrdma_add_stat(stats, pcur, "rnr_nak_timeouts",
233 (u64)rx_stats->rnr_nak_timeouts);
234 pcur += ocrdma_add_stat(stats, pcur, "rnr_nak_receives",
235 (u64)rx_stats->rnr_nak_receives);
236 pcur += ocrdma_add_stat(stats, pcur, "roce_frame_rxmt_drops",
237 (u64)rx_stats->roce_frame_rxmt_drops);
238 pcur += ocrdma_add_stat(stats, pcur, "nak_count_psn_sequence_errors",
239 (u64)rx_stats->nak_count_psn_sequence_errors);
240 pcur += ocrdma_add_stat(stats, pcur, "rc_drop_count_lookup_errors",
241 (u64)rx_stats->rc_drop_count_lookup_errors);
242 pcur += ocrdma_add_stat(stats, pcur, "rq_rnr_naks",
243 (u64)rx_stats->rq_rnr_naks);
244 pcur += ocrdma_add_stat(stats, pcur, "srq_rnr_naks",
245 (u64)rx_stats->srq_rnr_naks);
246 pcur += ocrdma_add_stat(stats, pcur, "roce_frames",
247 convert_to_64bit(rx_stats->roce_frames_lo,
248 rx_stats->roce_frames_hi));
249
250 return stats;
251}
252
Mitesh Ahujacad1fbb2014-12-18 14:12:55 +0530253static u64 ocrdma_sysfs_rcv_pkts(struct ocrdma_dev *dev)
254{
255 struct ocrdma_rdma_stats_resp *rdma_stats =
256 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
257 struct ocrdma_rx_stats *rx_stats = &rdma_stats->rx_stats;
258
259 return convert_to_64bit(rx_stats->roce_frames_lo,
260 rx_stats->roce_frames_hi) + (u64)rx_stats->roce_frame_icrc_drops
261 + (u64)rx_stats->roce_frame_payload_len_drops;
262}
263
264static u64 ocrdma_sysfs_rcv_data(struct ocrdma_dev *dev)
265{
266 struct ocrdma_rdma_stats_resp *rdma_stats =
267 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
268 struct ocrdma_rx_stats *rx_stats = &rdma_stats->rx_stats;
269
270 return (convert_to_64bit(rx_stats->roce_frame_bytes_lo,
271 rx_stats->roce_frame_bytes_hi))/4;
272}
273
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530274static char *ocrdma_tx_stats(struct ocrdma_dev *dev)
275{
276 char *stats = dev->stats_mem.debugfs_mem, *pcur;
277 struct ocrdma_rdma_stats_resp *rdma_stats =
278 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
279 struct ocrdma_tx_stats *tx_stats = &rdma_stats->tx_stats;
280
281 memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
282
283 pcur = stats;
284 pcur += ocrdma_add_stat(stats, pcur, "send_pkts",
285 convert_to_64bit(tx_stats->send_pkts_lo,
286 tx_stats->send_pkts_hi));
287 pcur += ocrdma_add_stat(stats, pcur, "write_pkts",
288 convert_to_64bit(tx_stats->write_pkts_lo,
289 tx_stats->write_pkts_hi));
290 pcur += ocrdma_add_stat(stats, pcur, "read_pkts",
291 convert_to_64bit(tx_stats->read_pkts_lo,
292 tx_stats->read_pkts_hi));
293 pcur += ocrdma_add_stat(stats, pcur, "read_rsp_pkts",
294 convert_to_64bit(tx_stats->read_rsp_pkts_lo,
295 tx_stats->read_rsp_pkts_hi));
296 pcur += ocrdma_add_stat(stats, pcur, "ack_pkts",
297 convert_to_64bit(tx_stats->ack_pkts_lo,
298 tx_stats->ack_pkts_hi));
299 pcur += ocrdma_add_stat(stats, pcur, "send_bytes",
300 convert_to_64bit(tx_stats->send_bytes_lo,
301 tx_stats->send_bytes_hi));
302 pcur += ocrdma_add_stat(stats, pcur, "write_bytes",
303 convert_to_64bit(tx_stats->write_bytes_lo,
304 tx_stats->write_bytes_hi));
305 pcur += ocrdma_add_stat(stats, pcur, "read_req_bytes",
306 convert_to_64bit(tx_stats->read_req_bytes_lo,
307 tx_stats->read_req_bytes_hi));
308 pcur += ocrdma_add_stat(stats, pcur, "read_rsp_bytes",
309 convert_to_64bit(tx_stats->read_rsp_bytes_lo,
310 tx_stats->read_rsp_bytes_hi));
311 pcur += ocrdma_add_stat(stats, pcur, "ack_timeouts",
312 (u64)tx_stats->ack_timeouts);
313
314 return stats;
315}
316
Mitesh Ahujacad1fbb2014-12-18 14:12:55 +0530317static u64 ocrdma_sysfs_xmit_pkts(struct ocrdma_dev *dev)
318{
319 struct ocrdma_rdma_stats_resp *rdma_stats =
320 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
321 struct ocrdma_tx_stats *tx_stats = &rdma_stats->tx_stats;
322
323 return (convert_to_64bit(tx_stats->send_pkts_lo,
324 tx_stats->send_pkts_hi) +
325 convert_to_64bit(tx_stats->write_pkts_lo, tx_stats->write_pkts_hi) +
326 convert_to_64bit(tx_stats->read_pkts_lo, tx_stats->read_pkts_hi) +
327 convert_to_64bit(tx_stats->read_rsp_pkts_lo,
328 tx_stats->read_rsp_pkts_hi) +
329 convert_to_64bit(tx_stats->ack_pkts_lo, tx_stats->ack_pkts_hi));
330}
331
332static u64 ocrdma_sysfs_xmit_data(struct ocrdma_dev *dev)
333{
334 struct ocrdma_rdma_stats_resp *rdma_stats =
335 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
336 struct ocrdma_tx_stats *tx_stats = &rdma_stats->tx_stats;
337
338 return (convert_to_64bit(tx_stats->send_bytes_lo,
339 tx_stats->send_bytes_hi) +
340 convert_to_64bit(tx_stats->write_bytes_lo,
341 tx_stats->write_bytes_hi) +
342 convert_to_64bit(tx_stats->read_req_bytes_lo,
343 tx_stats->read_req_bytes_hi) +
344 convert_to_64bit(tx_stats->read_rsp_bytes_lo,
345 tx_stats->read_rsp_bytes_hi))/4;
346}
347
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530348static char *ocrdma_wqe_stats(struct ocrdma_dev *dev)
349{
350 char *stats = dev->stats_mem.debugfs_mem, *pcur;
351 struct ocrdma_rdma_stats_resp *rdma_stats =
352 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
353 struct ocrdma_wqe_stats *wqe_stats = &rdma_stats->wqe_stats;
354
355 memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
356
357 pcur = stats;
358 pcur += ocrdma_add_stat(stats, pcur, "large_send_rc_wqes",
359 convert_to_64bit(wqe_stats->large_send_rc_wqes_lo,
360 wqe_stats->large_send_rc_wqes_hi));
361 pcur += ocrdma_add_stat(stats, pcur, "large_write_rc_wqes",
362 convert_to_64bit(wqe_stats->large_write_rc_wqes_lo,
363 wqe_stats->large_write_rc_wqes_hi));
364 pcur += ocrdma_add_stat(stats, pcur, "read_wqes",
365 convert_to_64bit(wqe_stats->read_wqes_lo,
366 wqe_stats->read_wqes_hi));
367 pcur += ocrdma_add_stat(stats, pcur, "frmr_wqes",
368 convert_to_64bit(wqe_stats->frmr_wqes_lo,
369 wqe_stats->frmr_wqes_hi));
370 pcur += ocrdma_add_stat(stats, pcur, "mw_bind_wqes",
371 convert_to_64bit(wqe_stats->mw_bind_wqes_lo,
372 wqe_stats->mw_bind_wqes_hi));
373 pcur += ocrdma_add_stat(stats, pcur, "invalidate_wqes",
374 convert_to_64bit(wqe_stats->invalidate_wqes_lo,
375 wqe_stats->invalidate_wqes_hi));
376 pcur += ocrdma_add_stat(stats, pcur, "dpp_wqe_drops",
377 (u64)wqe_stats->dpp_wqe_drops);
378 return stats;
379}
380
381static char *ocrdma_db_errstats(struct ocrdma_dev *dev)
382{
383 char *stats = dev->stats_mem.debugfs_mem, *pcur;
384 struct ocrdma_rdma_stats_resp *rdma_stats =
385 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
386 struct ocrdma_db_err_stats *db_err_stats = &rdma_stats->db_err_stats;
387
388 memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
389
390 pcur = stats;
391 pcur += ocrdma_add_stat(stats, pcur, "sq_doorbell_errors",
392 (u64)db_err_stats->sq_doorbell_errors);
393 pcur += ocrdma_add_stat(stats, pcur, "cq_doorbell_errors",
394 (u64)db_err_stats->cq_doorbell_errors);
395 pcur += ocrdma_add_stat(stats, pcur, "rq_srq_doorbell_errors",
396 (u64)db_err_stats->rq_srq_doorbell_errors);
397 pcur += ocrdma_add_stat(stats, pcur, "cq_overflow_errors",
398 (u64)db_err_stats->cq_overflow_errors);
399 return stats;
400}
401
402static char *ocrdma_rxqp_errstats(struct ocrdma_dev *dev)
403{
404 char *stats = dev->stats_mem.debugfs_mem, *pcur;
405 struct ocrdma_rdma_stats_resp *rdma_stats =
406 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
407 struct ocrdma_rx_qp_err_stats *rx_qp_err_stats =
408 &rdma_stats->rx_qp_err_stats;
409
410 memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
411
412 pcur = stats;
413 pcur += ocrdma_add_stat(stats, pcur, "nak_invalid_requst_errors",
414 (u64)rx_qp_err_stats->nak_invalid_requst_errors);
415 pcur += ocrdma_add_stat(stats, pcur, "nak_remote_operation_errors",
416 (u64)rx_qp_err_stats->nak_remote_operation_errors);
417 pcur += ocrdma_add_stat(stats, pcur, "nak_count_remote_access_errors",
418 (u64)rx_qp_err_stats->nak_count_remote_access_errors);
419 pcur += ocrdma_add_stat(stats, pcur, "local_length_errors",
420 (u64)rx_qp_err_stats->local_length_errors);
421 pcur += ocrdma_add_stat(stats, pcur, "local_protection_errors",
422 (u64)rx_qp_err_stats->local_protection_errors);
423 pcur += ocrdma_add_stat(stats, pcur, "local_qp_operation_errors",
424 (u64)rx_qp_err_stats->local_qp_operation_errors);
425 return stats;
426}
427
428static char *ocrdma_txqp_errstats(struct ocrdma_dev *dev)
429{
430 char *stats = dev->stats_mem.debugfs_mem, *pcur;
431 struct ocrdma_rdma_stats_resp *rdma_stats =
432 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
433 struct ocrdma_tx_qp_err_stats *tx_qp_err_stats =
434 &rdma_stats->tx_qp_err_stats;
435
436 memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
437
438 pcur = stats;
439 pcur += ocrdma_add_stat(stats, pcur, "local_length_errors",
440 (u64)tx_qp_err_stats->local_length_errors);
441 pcur += ocrdma_add_stat(stats, pcur, "local_protection_errors",
442 (u64)tx_qp_err_stats->local_protection_errors);
443 pcur += ocrdma_add_stat(stats, pcur, "local_qp_operation_errors",
444 (u64)tx_qp_err_stats->local_qp_operation_errors);
445 pcur += ocrdma_add_stat(stats, pcur, "retry_count_exceeded_errors",
446 (u64)tx_qp_err_stats->retry_count_exceeded_errors);
447 pcur += ocrdma_add_stat(stats, pcur, "rnr_retry_count_exceeded_errors",
448 (u64)tx_qp_err_stats->rnr_retry_count_exceeded_errors);
449 return stats;
450}
451
452static char *ocrdma_tx_dbg_stats(struct ocrdma_dev *dev)
453{
454 int i;
455 char *pstats = dev->stats_mem.debugfs_mem;
456 struct ocrdma_rdma_stats_resp *rdma_stats =
457 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
458 struct ocrdma_tx_dbg_stats *tx_dbg_stats =
459 &rdma_stats->tx_dbg_stats;
460
461 memset(pstats, 0, (OCRDMA_MAX_DBGFS_MEM));
462
463 for (i = 0; i < 100; i++)
464 pstats += snprintf(pstats, 80, "DW[%d] = 0x%x\n", i,
465 tx_dbg_stats->data[i]);
466
467 return dev->stats_mem.debugfs_mem;
468}
469
470static char *ocrdma_rx_dbg_stats(struct ocrdma_dev *dev)
471{
472 int i;
473 char *pstats = dev->stats_mem.debugfs_mem;
474 struct ocrdma_rdma_stats_resp *rdma_stats =
475 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
476 struct ocrdma_rx_dbg_stats *rx_dbg_stats =
477 &rdma_stats->rx_dbg_stats;
478
479 memset(pstats, 0, (OCRDMA_MAX_DBGFS_MEM));
480
481 for (i = 0; i < 200; i++)
482 pstats += snprintf(pstats, 80, "DW[%d] = 0x%x\n", i,
483 rx_dbg_stats->data[i]);
484
485 return dev->stats_mem.debugfs_mem;
486}
487
488static void ocrdma_update_stats(struct ocrdma_dev *dev)
489{
490 ulong now = jiffies, secs;
491 int status = 0;
Mitesh Ahuja9ba13772014-12-18 14:12:57 +0530492 struct ocrdma_rdma_stats_resp *rdma_stats =
493 (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
494 struct ocrdma_rsrc_stats *rsrc_stats = &rdma_stats->act_rsrc_stats;
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530495
496 secs = jiffies_to_msecs(now - dev->last_stats_time) / 1000U;
497 if (secs) {
498 /* update */
499 status = ocrdma_mbx_rdma_stats(dev, false);
500 if (status)
501 pr_err("%s: stats mbox failed with status = %d\n",
502 __func__, status);
Mitesh Ahuja9ba13772014-12-18 14:12:57 +0530503 /* Update PD counters from PD resource manager */
504 if (dev->pd_mgr->pd_prealloc_valid) {
505 rsrc_stats->dpp_pds = dev->pd_mgr->pd_dpp_count;
506 rsrc_stats->non_dpp_pds = dev->pd_mgr->pd_norm_count;
507 /* Threshold stata*/
508 rsrc_stats = &rdma_stats->th_rsrc_stats;
509 rsrc_stats->dpp_pds = dev->pd_mgr->pd_dpp_thrsh;
510 rsrc_stats->non_dpp_pds = dev->pd_mgr->pd_norm_thrsh;
511 }
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530512 dev->last_stats_time = jiffies;
513 }
514}
515
Mitesh Ahujacad1fbb2014-12-18 14:12:55 +0530516int ocrdma_pma_counters(struct ocrdma_dev *dev,
517 struct ib_mad *out_mad)
518{
519 struct ib_pma_portcounters *pma_cnt;
520
521 memset(out_mad->data, 0, sizeof out_mad->data);
522 pma_cnt = (void *)(out_mad->data + 40);
523 ocrdma_update_stats(dev);
524
525 pma_cnt->port_xmit_data = cpu_to_be32(ocrdma_sysfs_xmit_data(dev));
526 pma_cnt->port_rcv_data = cpu_to_be32(ocrdma_sysfs_rcv_data(dev));
527 pma_cnt->port_xmit_packets = cpu_to_be32(ocrdma_sysfs_xmit_pkts(dev));
528 pma_cnt->port_rcv_packets = cpu_to_be32(ocrdma_sysfs_rcv_pkts(dev));
529 return 0;
530}
531
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530532static ssize_t ocrdma_dbgfs_ops_read(struct file *filp, char __user *buffer,
533 size_t usr_buf_len, loff_t *ppos)
534{
535 struct ocrdma_stats *pstats = filp->private_data;
536 struct ocrdma_dev *dev = pstats->dev;
537 ssize_t status = 0;
538 char *data = NULL;
539
540 /* No partial reads */
541 if (*ppos != 0)
542 return 0;
543
544 mutex_lock(&dev->stats_lock);
545
546 ocrdma_update_stats(dev);
547
548 switch (pstats->type) {
549 case OCRDMA_RSRC_STATS:
550 data = ocrdma_resource_stats(dev);
551 break;
552 case OCRDMA_RXSTATS:
553 data = ocrdma_rx_stats(dev);
554 break;
555 case OCRDMA_WQESTATS:
556 data = ocrdma_wqe_stats(dev);
557 break;
558 case OCRDMA_TXSTATS:
559 data = ocrdma_tx_stats(dev);
560 break;
561 case OCRDMA_DB_ERRSTATS:
562 data = ocrdma_db_errstats(dev);
563 break;
564 case OCRDMA_RXQP_ERRSTATS:
565 data = ocrdma_rxqp_errstats(dev);
566 break;
567 case OCRDMA_TXQP_ERRSTATS:
568 data = ocrdma_txqp_errstats(dev);
569 break;
570 case OCRDMA_TX_DBG_STATS:
571 data = ocrdma_tx_dbg_stats(dev);
572 break;
573 case OCRDMA_RX_DBG_STATS:
574 data = ocrdma_rx_dbg_stats(dev);
575 break;
576
577 default:
578 status = -EFAULT;
579 goto exit;
580 }
581
582 if (usr_buf_len < strlen(data)) {
583 status = -ENOSPC;
584 goto exit;
585 }
586
587 status = simple_read_from_buffer(buffer, usr_buf_len, ppos, data,
588 strlen(data));
589exit:
590 mutex_unlock(&dev->stats_lock);
591 return status;
592}
593
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530594static const struct file_operations ocrdma_dbg_ops = {
595 .owner = THIS_MODULE,
Duan Jiong0cc65dd2014-04-16 09:37:49 +0800596 .open = simple_open,
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530597 .read = ocrdma_dbgfs_ops_read,
598};
599
600void ocrdma_add_port_stats(struct ocrdma_dev *dev)
601{
602 if (!ocrdma_dbgfs_dir)
603 return;
604
605 /* Create post stats base dir */
606 dev->dir = debugfs_create_dir(dev->ibdev.name, ocrdma_dbgfs_dir);
607 if (!dev->dir)
608 goto err;
609
610 dev->rsrc_stats.type = OCRDMA_RSRC_STATS;
611 dev->rsrc_stats.dev = dev;
612 if (!debugfs_create_file("resource_stats", S_IRUSR, dev->dir,
613 &dev->rsrc_stats, &ocrdma_dbg_ops))
614 goto err;
615
616 dev->rx_stats.type = OCRDMA_RXSTATS;
617 dev->rx_stats.dev = dev;
618 if (!debugfs_create_file("rx_stats", S_IRUSR, dev->dir,
619 &dev->rx_stats, &ocrdma_dbg_ops))
620 goto err;
621
622 dev->wqe_stats.type = OCRDMA_WQESTATS;
623 dev->wqe_stats.dev = dev;
624 if (!debugfs_create_file("wqe_stats", S_IRUSR, dev->dir,
625 &dev->wqe_stats, &ocrdma_dbg_ops))
626 goto err;
627
628 dev->tx_stats.type = OCRDMA_TXSTATS;
629 dev->tx_stats.dev = dev;
630 if (!debugfs_create_file("tx_stats", S_IRUSR, dev->dir,
631 &dev->tx_stats, &ocrdma_dbg_ops))
632 goto err;
633
634 dev->db_err_stats.type = OCRDMA_DB_ERRSTATS;
635 dev->db_err_stats.dev = dev;
636 if (!debugfs_create_file("db_err_stats", S_IRUSR, dev->dir,
637 &dev->db_err_stats, &ocrdma_dbg_ops))
638 goto err;
639
640
641 dev->tx_qp_err_stats.type = OCRDMA_TXQP_ERRSTATS;
642 dev->tx_qp_err_stats.dev = dev;
643 if (!debugfs_create_file("tx_qp_err_stats", S_IRUSR, dev->dir,
644 &dev->tx_qp_err_stats, &ocrdma_dbg_ops))
645 goto err;
646
647 dev->rx_qp_err_stats.type = OCRDMA_RXQP_ERRSTATS;
648 dev->rx_qp_err_stats.dev = dev;
649 if (!debugfs_create_file("rx_qp_err_stats", S_IRUSR, dev->dir,
650 &dev->rx_qp_err_stats, &ocrdma_dbg_ops))
651 goto err;
652
653
654 dev->tx_dbg_stats.type = OCRDMA_TX_DBG_STATS;
655 dev->tx_dbg_stats.dev = dev;
656 if (!debugfs_create_file("tx_dbg_stats", S_IRUSR, dev->dir,
657 &dev->tx_dbg_stats, &ocrdma_dbg_ops))
658 goto err;
659
660 dev->rx_dbg_stats.type = OCRDMA_RX_DBG_STATS;
661 dev->rx_dbg_stats.dev = dev;
662 if (!debugfs_create_file("rx_dbg_stats", S_IRUSR, dev->dir,
663 &dev->rx_dbg_stats, &ocrdma_dbg_ops))
664 goto err;
665
666 /* Now create dma_mem for stats mbx command */
667 if (!ocrdma_alloc_stats_mem(dev))
668 goto err;
669
670 mutex_init(&dev->stats_lock);
671
672 return;
673err:
674 ocrdma_release_stats_mem(dev);
675 debugfs_remove_recursive(dev->dir);
676 dev->dir = NULL;
677}
678
679void ocrdma_rem_port_stats(struct ocrdma_dev *dev)
680{
681 if (!dev->dir)
682 return;
683 mutex_destroy(&dev->stats_lock);
684 ocrdma_release_stats_mem(dev);
685 debugfs_remove(dev->dir);
686}
687
688void ocrdma_init_debugfs(void)
689{
690 /* Create base dir in debugfs root dir */
691 ocrdma_dbgfs_dir = debugfs_create_dir("ocrdma", NULL);
692}
693
694void ocrdma_rem_debugfs(void)
695{
696 debugfs_remove_recursive(ocrdma_dbgfs_dir);
697}