ocrdma_stats.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. /* This file is part of the Emulex RoCE Device Driver for
  2. * RoCE (RDMA over Converged Ethernet) adapters.
  3. * Copyright (C) 2012-2015 Emulex. All rights reserved.
  4. * EMULEX and SLI are trademarks of Emulex.
  5. * www.emulex.com
  6. *
  7. * This software is available to you under a choice of one of two licenses.
  8. * You may choose to be licensed under the terms of the GNU General Public
  9. * License (GPL) Version 2, available from the file COPYING in the main
  10. * directory of this source tree, or the BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the distribution.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  33. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * Contact Information:
  36. * linux-drivers@emulex.com
  37. *
  38. * Emulex
  39. * 3333 Susan Street
  40. * Costa Mesa, CA 92626
  41. */
  42. #include <rdma/ib_addr.h>
  43. #include <rdma/ib_pma.h>
  44. #include "ocrdma_stats.h"
  45. static struct dentry *ocrdma_dbgfs_dir;
  46. static int ocrdma_add_stat(char *start, char *pcur,
  47. char *name, u64 count)
  48. {
  49. char buff[128] = {0};
  50. int cpy_len = 0;
  51. snprintf(buff, 128, "%s: %llu\n", name, count);
  52. cpy_len = strlen(buff);
  53. if (pcur + cpy_len > start + OCRDMA_MAX_DBGFS_MEM) {
  54. pr_err("%s: No space in stats buff\n", __func__);
  55. return 0;
  56. }
  57. memcpy(pcur, buff, cpy_len);
  58. return cpy_len;
  59. }
  60. bool ocrdma_alloc_stats_resources(struct ocrdma_dev *dev)
  61. {
  62. struct stats_mem *mem = &dev->stats_mem;
  63. mutex_init(&dev->stats_lock);
  64. /* Alloc mbox command mem*/
  65. mem->size = max_t(u32, sizeof(struct ocrdma_rdma_stats_req),
  66. sizeof(struct ocrdma_rdma_stats_resp));
  67. mem->va = dma_zalloc_coherent(&dev->nic_info.pdev->dev, mem->size,
  68. &mem->pa, GFP_KERNEL);
  69. if (!mem->va) {
  70. pr_err("%s: stats mbox allocation failed\n", __func__);
  71. return false;
  72. }
  73. /* Alloc debugfs mem */
  74. mem->debugfs_mem = kzalloc(OCRDMA_MAX_DBGFS_MEM, GFP_KERNEL);
  75. if (!mem->debugfs_mem)
  76. return false;
  77. return true;
  78. }
  79. void ocrdma_release_stats_resources(struct ocrdma_dev *dev)
  80. {
  81. struct stats_mem *mem = &dev->stats_mem;
  82. if (mem->va)
  83. dma_free_coherent(&dev->nic_info.pdev->dev, mem->size,
  84. mem->va, mem->pa);
  85. mem->va = NULL;
  86. kfree(mem->debugfs_mem);
  87. }
  88. static char *ocrdma_resource_stats(struct ocrdma_dev *dev)
  89. {
  90. char *stats = dev->stats_mem.debugfs_mem, *pcur;
  91. struct ocrdma_rdma_stats_resp *rdma_stats =
  92. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  93. struct ocrdma_rsrc_stats *rsrc_stats = &rdma_stats->act_rsrc_stats;
  94. memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
  95. pcur = stats;
  96. pcur += ocrdma_add_stat(stats, pcur, "active_dpp_pds",
  97. (u64)rsrc_stats->dpp_pds);
  98. pcur += ocrdma_add_stat(stats, pcur, "active_non_dpp_pds",
  99. (u64)rsrc_stats->non_dpp_pds);
  100. pcur += ocrdma_add_stat(stats, pcur, "active_rc_dpp_qps",
  101. (u64)rsrc_stats->rc_dpp_qps);
  102. pcur += ocrdma_add_stat(stats, pcur, "active_uc_dpp_qps",
  103. (u64)rsrc_stats->uc_dpp_qps);
  104. pcur += ocrdma_add_stat(stats, pcur, "active_ud_dpp_qps",
  105. (u64)rsrc_stats->ud_dpp_qps);
  106. pcur += ocrdma_add_stat(stats, pcur, "active_rc_non_dpp_qps",
  107. (u64)rsrc_stats->rc_non_dpp_qps);
  108. pcur += ocrdma_add_stat(stats, pcur, "active_uc_non_dpp_qps",
  109. (u64)rsrc_stats->uc_non_dpp_qps);
  110. pcur += ocrdma_add_stat(stats, pcur, "active_ud_non_dpp_qps",
  111. (u64)rsrc_stats->ud_non_dpp_qps);
  112. pcur += ocrdma_add_stat(stats, pcur, "active_srqs",
  113. (u64)rsrc_stats->srqs);
  114. pcur += ocrdma_add_stat(stats, pcur, "active_rbqs",
  115. (u64)rsrc_stats->rbqs);
  116. pcur += ocrdma_add_stat(stats, pcur, "active_64K_nsmr",
  117. (u64)rsrc_stats->r64K_nsmr);
  118. pcur += ocrdma_add_stat(stats, pcur, "active_64K_to_2M_nsmr",
  119. (u64)rsrc_stats->r64K_to_2M_nsmr);
  120. pcur += ocrdma_add_stat(stats, pcur, "active_2M_to_44M_nsmr",
  121. (u64)rsrc_stats->r2M_to_44M_nsmr);
  122. pcur += ocrdma_add_stat(stats, pcur, "active_44M_to_1G_nsmr",
  123. (u64)rsrc_stats->r44M_to_1G_nsmr);
  124. pcur += ocrdma_add_stat(stats, pcur, "active_1G_to_4G_nsmr",
  125. (u64)rsrc_stats->r1G_to_4G_nsmr);
  126. pcur += ocrdma_add_stat(stats, pcur, "active_nsmr_count_4G_to_32G",
  127. (u64)rsrc_stats->nsmr_count_4G_to_32G);
  128. pcur += ocrdma_add_stat(stats, pcur, "active_32G_to_64G_nsmr",
  129. (u64)rsrc_stats->r32G_to_64G_nsmr);
  130. pcur += ocrdma_add_stat(stats, pcur, "active_64G_to_128G_nsmr",
  131. (u64)rsrc_stats->r64G_to_128G_nsmr);
  132. pcur += ocrdma_add_stat(stats, pcur, "active_128G_to_higher_nsmr",
  133. (u64)rsrc_stats->r128G_to_higher_nsmr);
  134. pcur += ocrdma_add_stat(stats, pcur, "active_embedded_nsmr",
  135. (u64)rsrc_stats->embedded_nsmr);
  136. pcur += ocrdma_add_stat(stats, pcur, "active_frmr",
  137. (u64)rsrc_stats->frmr);
  138. pcur += ocrdma_add_stat(stats, pcur, "active_prefetch_qps",
  139. (u64)rsrc_stats->prefetch_qps);
  140. pcur += ocrdma_add_stat(stats, pcur, "active_ondemand_qps",
  141. (u64)rsrc_stats->ondemand_qps);
  142. pcur += ocrdma_add_stat(stats, pcur, "active_phy_mr",
  143. (u64)rsrc_stats->phy_mr);
  144. pcur += ocrdma_add_stat(stats, pcur, "active_mw",
  145. (u64)rsrc_stats->mw);
  146. /* Print the threshold stats */
  147. rsrc_stats = &rdma_stats->th_rsrc_stats;
  148. pcur += ocrdma_add_stat(stats, pcur, "threshold_dpp_pds",
  149. (u64)rsrc_stats->dpp_pds);
  150. pcur += ocrdma_add_stat(stats, pcur, "threshold_non_dpp_pds",
  151. (u64)rsrc_stats->non_dpp_pds);
  152. pcur += ocrdma_add_stat(stats, pcur, "threshold_rc_dpp_qps",
  153. (u64)rsrc_stats->rc_dpp_qps);
  154. pcur += ocrdma_add_stat(stats, pcur, "threshold_uc_dpp_qps",
  155. (u64)rsrc_stats->uc_dpp_qps);
  156. pcur += ocrdma_add_stat(stats, pcur, "threshold_ud_dpp_qps",
  157. (u64)rsrc_stats->ud_dpp_qps);
  158. pcur += ocrdma_add_stat(stats, pcur, "threshold_rc_non_dpp_qps",
  159. (u64)rsrc_stats->rc_non_dpp_qps);
  160. pcur += ocrdma_add_stat(stats, pcur, "threshold_uc_non_dpp_qps",
  161. (u64)rsrc_stats->uc_non_dpp_qps);
  162. pcur += ocrdma_add_stat(stats, pcur, "threshold_ud_non_dpp_qps",
  163. (u64)rsrc_stats->ud_non_dpp_qps);
  164. pcur += ocrdma_add_stat(stats, pcur, "threshold_srqs",
  165. (u64)rsrc_stats->srqs);
  166. pcur += ocrdma_add_stat(stats, pcur, "threshold_rbqs",
  167. (u64)rsrc_stats->rbqs);
  168. pcur += ocrdma_add_stat(stats, pcur, "threshold_64K_nsmr",
  169. (u64)rsrc_stats->r64K_nsmr);
  170. pcur += ocrdma_add_stat(stats, pcur, "threshold_64K_to_2M_nsmr",
  171. (u64)rsrc_stats->r64K_to_2M_nsmr);
  172. pcur += ocrdma_add_stat(stats, pcur, "threshold_2M_to_44M_nsmr",
  173. (u64)rsrc_stats->r2M_to_44M_nsmr);
  174. pcur += ocrdma_add_stat(stats, pcur, "threshold_44M_to_1G_nsmr",
  175. (u64)rsrc_stats->r44M_to_1G_nsmr);
  176. pcur += ocrdma_add_stat(stats, pcur, "threshold_1G_to_4G_nsmr",
  177. (u64)rsrc_stats->r1G_to_4G_nsmr);
  178. pcur += ocrdma_add_stat(stats, pcur, "threshold_nsmr_count_4G_to_32G",
  179. (u64)rsrc_stats->nsmr_count_4G_to_32G);
  180. pcur += ocrdma_add_stat(stats, pcur, "threshold_32G_to_64G_nsmr",
  181. (u64)rsrc_stats->r32G_to_64G_nsmr);
  182. pcur += ocrdma_add_stat(stats, pcur, "threshold_64G_to_128G_nsmr",
  183. (u64)rsrc_stats->r64G_to_128G_nsmr);
  184. pcur += ocrdma_add_stat(stats, pcur, "threshold_128G_to_higher_nsmr",
  185. (u64)rsrc_stats->r128G_to_higher_nsmr);
  186. pcur += ocrdma_add_stat(stats, pcur, "threshold_embedded_nsmr",
  187. (u64)rsrc_stats->embedded_nsmr);
  188. pcur += ocrdma_add_stat(stats, pcur, "threshold_frmr",
  189. (u64)rsrc_stats->frmr);
  190. pcur += ocrdma_add_stat(stats, pcur, "threshold_prefetch_qps",
  191. (u64)rsrc_stats->prefetch_qps);
  192. pcur += ocrdma_add_stat(stats, pcur, "threshold_ondemand_qps",
  193. (u64)rsrc_stats->ondemand_qps);
  194. pcur += ocrdma_add_stat(stats, pcur, "threshold_phy_mr",
  195. (u64)rsrc_stats->phy_mr);
  196. pcur += ocrdma_add_stat(stats, pcur, "threshold_mw",
  197. (u64)rsrc_stats->mw);
  198. return stats;
  199. }
  200. static char *ocrdma_rx_stats(struct ocrdma_dev *dev)
  201. {
  202. char *stats = dev->stats_mem.debugfs_mem, *pcur;
  203. struct ocrdma_rdma_stats_resp *rdma_stats =
  204. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  205. struct ocrdma_rx_stats *rx_stats = &rdma_stats->rx_stats;
  206. memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
  207. pcur = stats;
  208. pcur += ocrdma_add_stat
  209. (stats, pcur, "roce_frame_bytes",
  210. convert_to_64bit(rx_stats->roce_frame_bytes_lo,
  211. rx_stats->roce_frame_bytes_hi));
  212. pcur += ocrdma_add_stat(stats, pcur, "roce_frame_icrc_drops",
  213. (u64)rx_stats->roce_frame_icrc_drops);
  214. pcur += ocrdma_add_stat(stats, pcur, "roce_frame_payload_len_drops",
  215. (u64)rx_stats->roce_frame_payload_len_drops);
  216. pcur += ocrdma_add_stat(stats, pcur, "ud_drops",
  217. (u64)rx_stats->ud_drops);
  218. pcur += ocrdma_add_stat(stats, pcur, "qp1_drops",
  219. (u64)rx_stats->qp1_drops);
  220. pcur += ocrdma_add_stat(stats, pcur, "psn_error_request_packets",
  221. (u64)rx_stats->psn_error_request_packets);
  222. pcur += ocrdma_add_stat(stats, pcur, "psn_error_resp_packets",
  223. (u64)rx_stats->psn_error_resp_packets);
  224. pcur += ocrdma_add_stat(stats, pcur, "rnr_nak_timeouts",
  225. (u64)rx_stats->rnr_nak_timeouts);
  226. pcur += ocrdma_add_stat(stats, pcur, "rnr_nak_receives",
  227. (u64)rx_stats->rnr_nak_receives);
  228. pcur += ocrdma_add_stat(stats, pcur, "roce_frame_rxmt_drops",
  229. (u64)rx_stats->roce_frame_rxmt_drops);
  230. pcur += ocrdma_add_stat(stats, pcur, "nak_count_psn_sequence_errors",
  231. (u64)rx_stats->nak_count_psn_sequence_errors);
  232. pcur += ocrdma_add_stat(stats, pcur, "rc_drop_count_lookup_errors",
  233. (u64)rx_stats->rc_drop_count_lookup_errors);
  234. pcur += ocrdma_add_stat(stats, pcur, "rq_rnr_naks",
  235. (u64)rx_stats->rq_rnr_naks);
  236. pcur += ocrdma_add_stat(stats, pcur, "srq_rnr_naks",
  237. (u64)rx_stats->srq_rnr_naks);
  238. pcur += ocrdma_add_stat(stats, pcur, "roce_frames",
  239. convert_to_64bit(rx_stats->roce_frames_lo,
  240. rx_stats->roce_frames_hi));
  241. return stats;
  242. }
  243. static u64 ocrdma_sysfs_rcv_pkts(struct ocrdma_dev *dev)
  244. {
  245. struct ocrdma_rdma_stats_resp *rdma_stats =
  246. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  247. struct ocrdma_rx_stats *rx_stats = &rdma_stats->rx_stats;
  248. return convert_to_64bit(rx_stats->roce_frames_lo,
  249. rx_stats->roce_frames_hi) + (u64)rx_stats->roce_frame_icrc_drops
  250. + (u64)rx_stats->roce_frame_payload_len_drops;
  251. }
  252. static u64 ocrdma_sysfs_rcv_data(struct ocrdma_dev *dev)
  253. {
  254. struct ocrdma_rdma_stats_resp *rdma_stats =
  255. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  256. struct ocrdma_rx_stats *rx_stats = &rdma_stats->rx_stats;
  257. return (convert_to_64bit(rx_stats->roce_frame_bytes_lo,
  258. rx_stats->roce_frame_bytes_hi))/4;
  259. }
  260. static char *ocrdma_tx_stats(struct ocrdma_dev *dev)
  261. {
  262. char *stats = dev->stats_mem.debugfs_mem, *pcur;
  263. struct ocrdma_rdma_stats_resp *rdma_stats =
  264. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  265. struct ocrdma_tx_stats *tx_stats = &rdma_stats->tx_stats;
  266. memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
  267. pcur = stats;
  268. pcur += ocrdma_add_stat(stats, pcur, "send_pkts",
  269. convert_to_64bit(tx_stats->send_pkts_lo,
  270. tx_stats->send_pkts_hi));
  271. pcur += ocrdma_add_stat(stats, pcur, "write_pkts",
  272. convert_to_64bit(tx_stats->write_pkts_lo,
  273. tx_stats->write_pkts_hi));
  274. pcur += ocrdma_add_stat(stats, pcur, "read_pkts",
  275. convert_to_64bit(tx_stats->read_pkts_lo,
  276. tx_stats->read_pkts_hi));
  277. pcur += ocrdma_add_stat(stats, pcur, "read_rsp_pkts",
  278. convert_to_64bit(tx_stats->read_rsp_pkts_lo,
  279. tx_stats->read_rsp_pkts_hi));
  280. pcur += ocrdma_add_stat(stats, pcur, "ack_pkts",
  281. convert_to_64bit(tx_stats->ack_pkts_lo,
  282. tx_stats->ack_pkts_hi));
  283. pcur += ocrdma_add_stat(stats, pcur, "send_bytes",
  284. convert_to_64bit(tx_stats->send_bytes_lo,
  285. tx_stats->send_bytes_hi));
  286. pcur += ocrdma_add_stat(stats, pcur, "write_bytes",
  287. convert_to_64bit(tx_stats->write_bytes_lo,
  288. tx_stats->write_bytes_hi));
  289. pcur += ocrdma_add_stat(stats, pcur, "read_req_bytes",
  290. convert_to_64bit(tx_stats->read_req_bytes_lo,
  291. tx_stats->read_req_bytes_hi));
  292. pcur += ocrdma_add_stat(stats, pcur, "read_rsp_bytes",
  293. convert_to_64bit(tx_stats->read_rsp_bytes_lo,
  294. tx_stats->read_rsp_bytes_hi));
  295. pcur += ocrdma_add_stat(stats, pcur, "ack_timeouts",
  296. (u64)tx_stats->ack_timeouts);
  297. return stats;
  298. }
  299. static u64 ocrdma_sysfs_xmit_pkts(struct ocrdma_dev *dev)
  300. {
  301. struct ocrdma_rdma_stats_resp *rdma_stats =
  302. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  303. struct ocrdma_tx_stats *tx_stats = &rdma_stats->tx_stats;
  304. return (convert_to_64bit(tx_stats->send_pkts_lo,
  305. tx_stats->send_pkts_hi) +
  306. convert_to_64bit(tx_stats->write_pkts_lo, tx_stats->write_pkts_hi) +
  307. convert_to_64bit(tx_stats->read_pkts_lo, tx_stats->read_pkts_hi) +
  308. convert_to_64bit(tx_stats->read_rsp_pkts_lo,
  309. tx_stats->read_rsp_pkts_hi) +
  310. convert_to_64bit(tx_stats->ack_pkts_lo, tx_stats->ack_pkts_hi));
  311. }
  312. static u64 ocrdma_sysfs_xmit_data(struct ocrdma_dev *dev)
  313. {
  314. struct ocrdma_rdma_stats_resp *rdma_stats =
  315. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  316. struct ocrdma_tx_stats *tx_stats = &rdma_stats->tx_stats;
  317. return (convert_to_64bit(tx_stats->send_bytes_lo,
  318. tx_stats->send_bytes_hi) +
  319. convert_to_64bit(tx_stats->write_bytes_lo,
  320. tx_stats->write_bytes_hi) +
  321. convert_to_64bit(tx_stats->read_req_bytes_lo,
  322. tx_stats->read_req_bytes_hi) +
  323. convert_to_64bit(tx_stats->read_rsp_bytes_lo,
  324. tx_stats->read_rsp_bytes_hi))/4;
  325. }
  326. static char *ocrdma_wqe_stats(struct ocrdma_dev *dev)
  327. {
  328. char *stats = dev->stats_mem.debugfs_mem, *pcur;
  329. struct ocrdma_rdma_stats_resp *rdma_stats =
  330. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  331. struct ocrdma_wqe_stats *wqe_stats = &rdma_stats->wqe_stats;
  332. memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
  333. pcur = stats;
  334. pcur += ocrdma_add_stat(stats, pcur, "large_send_rc_wqes",
  335. convert_to_64bit(wqe_stats->large_send_rc_wqes_lo,
  336. wqe_stats->large_send_rc_wqes_hi));
  337. pcur += ocrdma_add_stat(stats, pcur, "large_write_rc_wqes",
  338. convert_to_64bit(wqe_stats->large_write_rc_wqes_lo,
  339. wqe_stats->large_write_rc_wqes_hi));
  340. pcur += ocrdma_add_stat(stats, pcur, "read_wqes",
  341. convert_to_64bit(wqe_stats->read_wqes_lo,
  342. wqe_stats->read_wqes_hi));
  343. pcur += ocrdma_add_stat(stats, pcur, "frmr_wqes",
  344. convert_to_64bit(wqe_stats->frmr_wqes_lo,
  345. wqe_stats->frmr_wqes_hi));
  346. pcur += ocrdma_add_stat(stats, pcur, "mw_bind_wqes",
  347. convert_to_64bit(wqe_stats->mw_bind_wqes_lo,
  348. wqe_stats->mw_bind_wqes_hi));
  349. pcur += ocrdma_add_stat(stats, pcur, "invalidate_wqes",
  350. convert_to_64bit(wqe_stats->invalidate_wqes_lo,
  351. wqe_stats->invalidate_wqes_hi));
  352. pcur += ocrdma_add_stat(stats, pcur, "dpp_wqe_drops",
  353. (u64)wqe_stats->dpp_wqe_drops);
  354. return stats;
  355. }
  356. static char *ocrdma_db_errstats(struct ocrdma_dev *dev)
  357. {
  358. char *stats = dev->stats_mem.debugfs_mem, *pcur;
  359. struct ocrdma_rdma_stats_resp *rdma_stats =
  360. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  361. struct ocrdma_db_err_stats *db_err_stats = &rdma_stats->db_err_stats;
  362. memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
  363. pcur = stats;
  364. pcur += ocrdma_add_stat(stats, pcur, "sq_doorbell_errors",
  365. (u64)db_err_stats->sq_doorbell_errors);
  366. pcur += ocrdma_add_stat(stats, pcur, "cq_doorbell_errors",
  367. (u64)db_err_stats->cq_doorbell_errors);
  368. pcur += ocrdma_add_stat(stats, pcur, "rq_srq_doorbell_errors",
  369. (u64)db_err_stats->rq_srq_doorbell_errors);
  370. pcur += ocrdma_add_stat(stats, pcur, "cq_overflow_errors",
  371. (u64)db_err_stats->cq_overflow_errors);
  372. return stats;
  373. }
  374. static char *ocrdma_rxqp_errstats(struct ocrdma_dev *dev)
  375. {
  376. char *stats = dev->stats_mem.debugfs_mem, *pcur;
  377. struct ocrdma_rdma_stats_resp *rdma_stats =
  378. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  379. struct ocrdma_rx_qp_err_stats *rx_qp_err_stats =
  380. &rdma_stats->rx_qp_err_stats;
  381. memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
  382. pcur = stats;
  383. pcur += ocrdma_add_stat(stats, pcur, "nak_invalid_requst_errors",
  384. (u64)rx_qp_err_stats->nak_invalid_requst_errors);
  385. pcur += ocrdma_add_stat(stats, pcur, "nak_remote_operation_errors",
  386. (u64)rx_qp_err_stats->nak_remote_operation_errors);
  387. pcur += ocrdma_add_stat(stats, pcur, "nak_count_remote_access_errors",
  388. (u64)rx_qp_err_stats->nak_count_remote_access_errors);
  389. pcur += ocrdma_add_stat(stats, pcur, "local_length_errors",
  390. (u64)rx_qp_err_stats->local_length_errors);
  391. pcur += ocrdma_add_stat(stats, pcur, "local_protection_errors",
  392. (u64)rx_qp_err_stats->local_protection_errors);
  393. pcur += ocrdma_add_stat(stats, pcur, "local_qp_operation_errors",
  394. (u64)rx_qp_err_stats->local_qp_operation_errors);
  395. return stats;
  396. }
  397. static char *ocrdma_txqp_errstats(struct ocrdma_dev *dev)
  398. {
  399. char *stats = dev->stats_mem.debugfs_mem, *pcur;
  400. struct ocrdma_rdma_stats_resp *rdma_stats =
  401. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  402. struct ocrdma_tx_qp_err_stats *tx_qp_err_stats =
  403. &rdma_stats->tx_qp_err_stats;
  404. memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
  405. pcur = stats;
  406. pcur += ocrdma_add_stat(stats, pcur, "local_length_errors",
  407. (u64)tx_qp_err_stats->local_length_errors);
  408. pcur += ocrdma_add_stat(stats, pcur, "local_protection_errors",
  409. (u64)tx_qp_err_stats->local_protection_errors);
  410. pcur += ocrdma_add_stat(stats, pcur, "local_qp_operation_errors",
  411. (u64)tx_qp_err_stats->local_qp_operation_errors);
  412. pcur += ocrdma_add_stat(stats, pcur, "retry_count_exceeded_errors",
  413. (u64)tx_qp_err_stats->retry_count_exceeded_errors);
  414. pcur += ocrdma_add_stat(stats, pcur, "rnr_retry_count_exceeded_errors",
  415. (u64)tx_qp_err_stats->rnr_retry_count_exceeded_errors);
  416. return stats;
  417. }
  418. static char *ocrdma_tx_dbg_stats(struct ocrdma_dev *dev)
  419. {
  420. int i;
  421. char *pstats = dev->stats_mem.debugfs_mem;
  422. struct ocrdma_rdma_stats_resp *rdma_stats =
  423. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  424. struct ocrdma_tx_dbg_stats *tx_dbg_stats =
  425. &rdma_stats->tx_dbg_stats;
  426. memset(pstats, 0, (OCRDMA_MAX_DBGFS_MEM));
  427. for (i = 0; i < 100; i++)
  428. pstats += snprintf(pstats, 80, "DW[%d] = 0x%x\n", i,
  429. tx_dbg_stats->data[i]);
  430. return dev->stats_mem.debugfs_mem;
  431. }
  432. static char *ocrdma_rx_dbg_stats(struct ocrdma_dev *dev)
  433. {
  434. int i;
  435. char *pstats = dev->stats_mem.debugfs_mem;
  436. struct ocrdma_rdma_stats_resp *rdma_stats =
  437. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  438. struct ocrdma_rx_dbg_stats *rx_dbg_stats =
  439. &rdma_stats->rx_dbg_stats;
  440. memset(pstats, 0, (OCRDMA_MAX_DBGFS_MEM));
  441. for (i = 0; i < 200; i++)
  442. pstats += snprintf(pstats, 80, "DW[%d] = 0x%x\n", i,
  443. rx_dbg_stats->data[i]);
  444. return dev->stats_mem.debugfs_mem;
  445. }
  446. static char *ocrdma_driver_dbg_stats(struct ocrdma_dev *dev)
  447. {
  448. char *stats = dev->stats_mem.debugfs_mem, *pcur;
  449. memset(stats, 0, (OCRDMA_MAX_DBGFS_MEM));
  450. pcur = stats;
  451. pcur += ocrdma_add_stat(stats, pcur, "async_cq_err",
  452. (u64)(dev->async_err_stats
  453. [OCRDMA_CQ_ERROR].counter));
  454. pcur += ocrdma_add_stat(stats, pcur, "async_cq_overrun_err",
  455. (u64)dev->async_err_stats
  456. [OCRDMA_CQ_OVERRUN_ERROR].counter);
  457. pcur += ocrdma_add_stat(stats, pcur, "async_cq_qpcat_err",
  458. (u64)dev->async_err_stats
  459. [OCRDMA_CQ_QPCAT_ERROR].counter);
  460. pcur += ocrdma_add_stat(stats, pcur, "async_qp_access_err",
  461. (u64)dev->async_err_stats
  462. [OCRDMA_QP_ACCESS_ERROR].counter);
  463. pcur += ocrdma_add_stat(stats, pcur, "async_qp_commm_est_evt",
  464. (u64)dev->async_err_stats
  465. [OCRDMA_QP_COMM_EST_EVENT].counter);
  466. pcur += ocrdma_add_stat(stats, pcur, "async_sq_drained_evt",
  467. (u64)dev->async_err_stats
  468. [OCRDMA_SQ_DRAINED_EVENT].counter);
  469. pcur += ocrdma_add_stat(stats, pcur, "async_dev_fatal_evt",
  470. (u64)dev->async_err_stats
  471. [OCRDMA_DEVICE_FATAL_EVENT].counter);
  472. pcur += ocrdma_add_stat(stats, pcur, "async_srqcat_err",
  473. (u64)dev->async_err_stats
  474. [OCRDMA_SRQCAT_ERROR].counter);
  475. pcur += ocrdma_add_stat(stats, pcur, "async_srq_limit_evt",
  476. (u64)dev->async_err_stats
  477. [OCRDMA_SRQ_LIMIT_EVENT].counter);
  478. pcur += ocrdma_add_stat(stats, pcur, "async_qp_last_wqe_evt",
  479. (u64)dev->async_err_stats
  480. [OCRDMA_QP_LAST_WQE_EVENT].counter);
  481. pcur += ocrdma_add_stat(stats, pcur, "cqe_loc_len_err",
  482. (u64)dev->cqe_err_stats
  483. [OCRDMA_CQE_LOC_LEN_ERR].counter);
  484. pcur += ocrdma_add_stat(stats, pcur, "cqe_loc_qp_op_err",
  485. (u64)dev->cqe_err_stats
  486. [OCRDMA_CQE_LOC_QP_OP_ERR].counter);
  487. pcur += ocrdma_add_stat(stats, pcur, "cqe_loc_eec_op_err",
  488. (u64)dev->cqe_err_stats
  489. [OCRDMA_CQE_LOC_EEC_OP_ERR].counter);
  490. pcur += ocrdma_add_stat(stats, pcur, "cqe_loc_prot_err",
  491. (u64)dev->cqe_err_stats
  492. [OCRDMA_CQE_LOC_PROT_ERR].counter);
  493. pcur += ocrdma_add_stat(stats, pcur, "cqe_wr_flush_err",
  494. (u64)dev->cqe_err_stats
  495. [OCRDMA_CQE_WR_FLUSH_ERR].counter);
  496. pcur += ocrdma_add_stat(stats, pcur, "cqe_mw_bind_err",
  497. (u64)dev->cqe_err_stats
  498. [OCRDMA_CQE_MW_BIND_ERR].counter);
  499. pcur += ocrdma_add_stat(stats, pcur, "cqe_bad_resp_err",
  500. (u64)dev->cqe_err_stats
  501. [OCRDMA_CQE_BAD_RESP_ERR].counter);
  502. pcur += ocrdma_add_stat(stats, pcur, "cqe_loc_access_err",
  503. (u64)dev->cqe_err_stats
  504. [OCRDMA_CQE_LOC_ACCESS_ERR].counter);
  505. pcur += ocrdma_add_stat(stats, pcur, "cqe_rem_inv_req_err",
  506. (u64)dev->cqe_err_stats
  507. [OCRDMA_CQE_REM_INV_REQ_ERR].counter);
  508. pcur += ocrdma_add_stat(stats, pcur, "cqe_rem_access_err",
  509. (u64)dev->cqe_err_stats
  510. [OCRDMA_CQE_REM_ACCESS_ERR].counter);
  511. pcur += ocrdma_add_stat(stats, pcur, "cqe_rem_op_err",
  512. (u64)dev->cqe_err_stats
  513. [OCRDMA_CQE_REM_OP_ERR].counter);
  514. pcur += ocrdma_add_stat(stats, pcur, "cqe_retry_exc_err",
  515. (u64)dev->cqe_err_stats
  516. [OCRDMA_CQE_RETRY_EXC_ERR].counter);
  517. pcur += ocrdma_add_stat(stats, pcur, "cqe_rnr_retry_exc_err",
  518. (u64)dev->cqe_err_stats
  519. [OCRDMA_CQE_RNR_RETRY_EXC_ERR].counter);
  520. pcur += ocrdma_add_stat(stats, pcur, "cqe_loc_rdd_viol_err",
  521. (u64)dev->cqe_err_stats
  522. [OCRDMA_CQE_LOC_RDD_VIOL_ERR].counter);
  523. pcur += ocrdma_add_stat(stats, pcur, "cqe_rem_inv_rd_req_err",
  524. (u64)dev->cqe_err_stats
  525. [OCRDMA_CQE_REM_INV_RD_REQ_ERR].counter);
  526. pcur += ocrdma_add_stat(stats, pcur, "cqe_rem_abort_err",
  527. (u64)dev->cqe_err_stats
  528. [OCRDMA_CQE_REM_ABORT_ERR].counter);
  529. pcur += ocrdma_add_stat(stats, pcur, "cqe_inv_eecn_err",
  530. (u64)dev->cqe_err_stats
  531. [OCRDMA_CQE_INV_EECN_ERR].counter);
  532. pcur += ocrdma_add_stat(stats, pcur, "cqe_inv_eec_state_err",
  533. (u64)dev->cqe_err_stats
  534. [OCRDMA_CQE_INV_EEC_STATE_ERR].counter);
  535. pcur += ocrdma_add_stat(stats, pcur, "cqe_fatal_err",
  536. (u64)dev->cqe_err_stats
  537. [OCRDMA_CQE_FATAL_ERR].counter);
  538. pcur += ocrdma_add_stat(stats, pcur, "cqe_resp_timeout_err",
  539. (u64)dev->cqe_err_stats
  540. [OCRDMA_CQE_RESP_TIMEOUT_ERR].counter);
  541. pcur += ocrdma_add_stat(stats, pcur, "cqe_general_err",
  542. (u64)dev->cqe_err_stats
  543. [OCRDMA_CQE_GENERAL_ERR].counter);
  544. return stats;
  545. }
  546. static void ocrdma_update_stats(struct ocrdma_dev *dev)
  547. {
  548. ulong now = jiffies, secs;
  549. int status;
  550. struct ocrdma_rdma_stats_resp *rdma_stats =
  551. (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
  552. struct ocrdma_rsrc_stats *rsrc_stats = &rdma_stats->act_rsrc_stats;
  553. secs = jiffies_to_msecs(now - dev->last_stats_time) / 1000U;
  554. if (secs) {
  555. /* update */
  556. status = ocrdma_mbx_rdma_stats(dev, false);
  557. if (status)
  558. pr_err("%s: stats mbox failed with status = %d\n",
  559. __func__, status);
  560. /* Update PD counters from PD resource manager */
  561. if (dev->pd_mgr->pd_prealloc_valid) {
  562. rsrc_stats->dpp_pds = dev->pd_mgr->pd_dpp_count;
  563. rsrc_stats->non_dpp_pds = dev->pd_mgr->pd_norm_count;
  564. /* Threshold stata*/
  565. rsrc_stats = &rdma_stats->th_rsrc_stats;
  566. rsrc_stats->dpp_pds = dev->pd_mgr->pd_dpp_thrsh;
  567. rsrc_stats->non_dpp_pds = dev->pd_mgr->pd_norm_thrsh;
  568. }
  569. dev->last_stats_time = jiffies;
  570. }
  571. }
  572. static ssize_t ocrdma_dbgfs_ops_write(struct file *filp,
  573. const char __user *buffer,
  574. size_t count, loff_t *ppos)
  575. {
  576. char tmp_str[32];
  577. long reset;
  578. int status;
  579. struct ocrdma_stats *pstats = filp->private_data;
  580. struct ocrdma_dev *dev = pstats->dev;
  581. if (*ppos != 0 || count == 0 || count > sizeof(tmp_str))
  582. goto err;
  583. if (copy_from_user(tmp_str, buffer, count))
  584. goto err;
  585. tmp_str[count-1] = '\0';
  586. if (kstrtol(tmp_str, 10, &reset))
  587. goto err;
  588. switch (pstats->type) {
  589. case OCRDMA_RESET_STATS:
  590. if (reset) {
  591. status = ocrdma_mbx_rdma_stats(dev, true);
  592. if (status) {
  593. pr_err("Failed to reset stats = %d\n", status);
  594. goto err;
  595. }
  596. }
  597. break;
  598. default:
  599. goto err;
  600. }
  601. return count;
  602. err:
  603. return -EFAULT;
  604. }
  605. int ocrdma_pma_counters(struct ocrdma_dev *dev,
  606. struct ib_mad *out_mad)
  607. {
  608. struct ib_pma_portcounters *pma_cnt;
  609. memset(out_mad->data, 0, sizeof out_mad->data);
  610. pma_cnt = (void *)(out_mad->data + 40);
  611. ocrdma_update_stats(dev);
  612. pma_cnt->port_xmit_data = cpu_to_be32(ocrdma_sysfs_xmit_data(dev));
  613. pma_cnt->port_rcv_data = cpu_to_be32(ocrdma_sysfs_rcv_data(dev));
  614. pma_cnt->port_xmit_packets = cpu_to_be32(ocrdma_sysfs_xmit_pkts(dev));
  615. pma_cnt->port_rcv_packets = cpu_to_be32(ocrdma_sysfs_rcv_pkts(dev));
  616. return 0;
  617. }
  618. static ssize_t ocrdma_dbgfs_ops_read(struct file *filp, char __user *buffer,
  619. size_t usr_buf_len, loff_t *ppos)
  620. {
  621. struct ocrdma_stats *pstats = filp->private_data;
  622. struct ocrdma_dev *dev = pstats->dev;
  623. ssize_t status = 0;
  624. char *data = NULL;
  625. /* No partial reads */
  626. if (*ppos != 0)
  627. return 0;
  628. mutex_lock(&dev->stats_lock);
  629. ocrdma_update_stats(dev);
  630. switch (pstats->type) {
  631. case OCRDMA_RSRC_STATS:
  632. data = ocrdma_resource_stats(dev);
  633. break;
  634. case OCRDMA_RXSTATS:
  635. data = ocrdma_rx_stats(dev);
  636. break;
  637. case OCRDMA_WQESTATS:
  638. data = ocrdma_wqe_stats(dev);
  639. break;
  640. case OCRDMA_TXSTATS:
  641. data = ocrdma_tx_stats(dev);
  642. break;
  643. case OCRDMA_DB_ERRSTATS:
  644. data = ocrdma_db_errstats(dev);
  645. break;
  646. case OCRDMA_RXQP_ERRSTATS:
  647. data = ocrdma_rxqp_errstats(dev);
  648. break;
  649. case OCRDMA_TXQP_ERRSTATS:
  650. data = ocrdma_txqp_errstats(dev);
  651. break;
  652. case OCRDMA_TX_DBG_STATS:
  653. data = ocrdma_tx_dbg_stats(dev);
  654. break;
  655. case OCRDMA_RX_DBG_STATS:
  656. data = ocrdma_rx_dbg_stats(dev);
  657. break;
  658. case OCRDMA_DRV_STATS:
  659. data = ocrdma_driver_dbg_stats(dev);
  660. break;
  661. default:
  662. status = -EFAULT;
  663. goto exit;
  664. }
  665. if (usr_buf_len < strlen(data)) {
  666. status = -ENOSPC;
  667. goto exit;
  668. }
  669. status = simple_read_from_buffer(buffer, usr_buf_len, ppos, data,
  670. strlen(data));
  671. exit:
  672. mutex_unlock(&dev->stats_lock);
  673. return status;
  674. }
  675. static const struct file_operations ocrdma_dbg_ops = {
  676. .owner = THIS_MODULE,
  677. .open = simple_open,
  678. .read = ocrdma_dbgfs_ops_read,
  679. .write = ocrdma_dbgfs_ops_write,
  680. };
  681. void ocrdma_add_port_stats(struct ocrdma_dev *dev)
  682. {
  683. if (!ocrdma_dbgfs_dir)
  684. return;
  685. /* Create post stats base dir */
  686. dev->dir = debugfs_create_dir(dev->ibdev.name, ocrdma_dbgfs_dir);
  687. if (!dev->dir)
  688. goto err;
  689. dev->rsrc_stats.type = OCRDMA_RSRC_STATS;
  690. dev->rsrc_stats.dev = dev;
  691. if (!debugfs_create_file("resource_stats", S_IRUSR, dev->dir,
  692. &dev->rsrc_stats, &ocrdma_dbg_ops))
  693. goto err;
  694. dev->rx_stats.type = OCRDMA_RXSTATS;
  695. dev->rx_stats.dev = dev;
  696. if (!debugfs_create_file("rx_stats", S_IRUSR, dev->dir,
  697. &dev->rx_stats, &ocrdma_dbg_ops))
  698. goto err;
  699. dev->wqe_stats.type = OCRDMA_WQESTATS;
  700. dev->wqe_stats.dev = dev;
  701. if (!debugfs_create_file("wqe_stats", S_IRUSR, dev->dir,
  702. &dev->wqe_stats, &ocrdma_dbg_ops))
  703. goto err;
  704. dev->tx_stats.type = OCRDMA_TXSTATS;
  705. dev->tx_stats.dev = dev;
  706. if (!debugfs_create_file("tx_stats", S_IRUSR, dev->dir,
  707. &dev->tx_stats, &ocrdma_dbg_ops))
  708. goto err;
  709. dev->db_err_stats.type = OCRDMA_DB_ERRSTATS;
  710. dev->db_err_stats.dev = dev;
  711. if (!debugfs_create_file("db_err_stats", S_IRUSR, dev->dir,
  712. &dev->db_err_stats, &ocrdma_dbg_ops))
  713. goto err;
  714. dev->tx_qp_err_stats.type = OCRDMA_TXQP_ERRSTATS;
  715. dev->tx_qp_err_stats.dev = dev;
  716. if (!debugfs_create_file("tx_qp_err_stats", S_IRUSR, dev->dir,
  717. &dev->tx_qp_err_stats, &ocrdma_dbg_ops))
  718. goto err;
  719. dev->rx_qp_err_stats.type = OCRDMA_RXQP_ERRSTATS;
  720. dev->rx_qp_err_stats.dev = dev;
  721. if (!debugfs_create_file("rx_qp_err_stats", S_IRUSR, dev->dir,
  722. &dev->rx_qp_err_stats, &ocrdma_dbg_ops))
  723. goto err;
  724. dev->tx_dbg_stats.type = OCRDMA_TX_DBG_STATS;
  725. dev->tx_dbg_stats.dev = dev;
  726. if (!debugfs_create_file("tx_dbg_stats", S_IRUSR, dev->dir,
  727. &dev->tx_dbg_stats, &ocrdma_dbg_ops))
  728. goto err;
  729. dev->rx_dbg_stats.type = OCRDMA_RX_DBG_STATS;
  730. dev->rx_dbg_stats.dev = dev;
  731. if (!debugfs_create_file("rx_dbg_stats", S_IRUSR, dev->dir,
  732. &dev->rx_dbg_stats, &ocrdma_dbg_ops))
  733. goto err;
  734. dev->driver_stats.type = OCRDMA_DRV_STATS;
  735. dev->driver_stats.dev = dev;
  736. if (!debugfs_create_file("driver_dbg_stats", S_IRUSR, dev->dir,
  737. &dev->driver_stats, &ocrdma_dbg_ops))
  738. goto err;
  739. dev->reset_stats.type = OCRDMA_RESET_STATS;
  740. dev->reset_stats.dev = dev;
  741. if (!debugfs_create_file("reset_stats", 0200, dev->dir,
  742. &dev->reset_stats, &ocrdma_dbg_ops))
  743. goto err;
  744. return;
  745. err:
  746. debugfs_remove_recursive(dev->dir);
  747. dev->dir = NULL;
  748. }
  749. void ocrdma_rem_port_stats(struct ocrdma_dev *dev)
  750. {
  751. if (!dev->dir)
  752. return;
  753. debugfs_remove_recursive(dev->dir);
  754. }
  755. void ocrdma_init_debugfs(void)
  756. {
  757. /* Create base dir in debugfs root dir */
  758. ocrdma_dbgfs_dir = debugfs_create_dir("ocrdma", NULL);
  759. }
  760. void ocrdma_rem_debugfs(void)
  761. {
  762. debugfs_remove_recursive(ocrdma_dbgfs_dir);
  763. }