PageRenderTime 79ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/scsi/lpfc/lpfc_debugfs.c

http://github.com/mirrors/linux
C | 6513 lines | 4590 code | 705 blank | 1218 comment | 900 complexity | bb68be07d654c3c150c885b902e6526c MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2007-2015 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * *
  10. * This program is free software; you can redistribute it and/or *
  11. * modify it under the terms of version 2 of the GNU General *
  12. * Public License as published by the Free Software Foundation. *
  13. * This program is distributed in the hope that it will be useful. *
  14. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  15. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  16. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  17. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  18. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  19. * more details, a copy of which can be found in the file COPYING *
  20. * included with this package. *
  21. *******************************************************************/
  22. #include <linux/blkdev.h>
  23. #include <linux/delay.h>
  24. #include <linux/module.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/idr.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/kthread.h>
  29. #include <linux/slab.h>
  30. #include <linux/pci.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/ctype.h>
  33. #include <linux/vmalloc.h>
  34. #include <scsi/scsi.h>
  35. #include <scsi/scsi_device.h>
  36. #include <scsi/scsi_host.h>
  37. #include <scsi/scsi_transport_fc.h>
  38. #include <scsi/fc/fc_fs.h>
  39. #include <linux/nvme-fc-driver.h>
  40. #include "lpfc_hw4.h"
  41. #include "lpfc_hw.h"
  42. #include "lpfc_sli.h"
  43. #include "lpfc_sli4.h"
  44. #include "lpfc_nl.h"
  45. #include "lpfc_disc.h"
  46. #include "lpfc.h"
  47. #include "lpfc_scsi.h"
  48. #include "lpfc_nvme.h"
  49. #include "lpfc_nvmet.h"
  50. #include "lpfc_logmsg.h"
  51. #include "lpfc_crtn.h"
  52. #include "lpfc_vport.h"
  53. #include "lpfc_version.h"
  54. #include "lpfc_compat.h"
  55. #include "lpfc_debugfs.h"
  56. #include "lpfc_bsg.h"
  57. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  58. /*
  59. * debugfs interface
  60. *
  61. * To access this interface the user should:
  62. * # mount -t debugfs none /sys/kernel/debug
  63. *
  64. * The lpfc debugfs directory hierarchy is:
  65. * /sys/kernel/debug/lpfc/fnX/vportY
  66. * where X is the lpfc hba function unique_id
  67. * where Y is the vport VPI on that hba
  68. *
  69. * Debugging services available per vport:
  70. * discovery_trace
  71. * This is an ACSII readable file that contains a trace of the last
  72. * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
  73. * See lpfc_debugfs.h for different categories of discovery events.
  74. * To enable the discovery trace, the following module parameters must be set:
  75. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  76. * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
  77. * EACH vport. X MUST also be a power of 2.
  78. * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
  79. * lpfc_debugfs.h .
  80. *
  81. * slow_ring_trace
  82. * This is an ACSII readable file that contains a trace of the last
  83. * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
  84. * To enable the slow ring trace, the following module parameters must be set:
  85. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  86. * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
  87. * the HBA. X MUST also be a power of 2.
  88. */
  89. static int lpfc_debugfs_enable = 1;
  90. module_param(lpfc_debugfs_enable, int, S_IRUGO);
  91. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  92. /* This MUST be a power of 2 */
  93. static int lpfc_debugfs_max_disc_trc;
  94. module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
  95. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  96. "Set debugfs discovery trace depth");
  97. /* This MUST be a power of 2 */
  98. static int lpfc_debugfs_max_slow_ring_trc;
  99. module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
  100. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  101. "Set debugfs slow ring trace depth");
  102. /* This MUST be a power of 2 */
  103. static int lpfc_debugfs_max_nvmeio_trc;
  104. module_param(lpfc_debugfs_max_nvmeio_trc, int, 0444);
  105. MODULE_PARM_DESC(lpfc_debugfs_max_nvmeio_trc,
  106. "Set debugfs NVME IO trace depth");
  107. static int lpfc_debugfs_mask_disc_trc;
  108. module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
  109. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  110. "Set debugfs discovery trace mask");
  111. #include <linux/debugfs.h>
  112. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  113. static unsigned long lpfc_debugfs_start_time = 0L;
  114. /* iDiag */
  115. static struct lpfc_idiag idiag;
  116. /**
  117. * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
  118. * @vport: The vport to gather the log info from.
  119. * @buf: The buffer to dump log into.
  120. * @size: The maximum amount of data to process.
  121. *
  122. * Description:
  123. * This routine gathers the lpfc discovery debugfs data from the @vport and
  124. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  125. * in the log and process the log until the end of the buffer. Then it will
  126. * gather from the beginning of the log and process until the current entry.
  127. *
  128. * Notes:
  129. * Discovery logging will be disabled while while this routine dumps the log.
  130. *
  131. * Return Value:
  132. * This routine returns the amount of bytes that were dumped into @buf and will
  133. * not exceed @size.
  134. **/
  135. static int
  136. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  137. {
  138. int i, index, len, enable;
  139. uint32_t ms;
  140. struct lpfc_debugfs_trc *dtp;
  141. char *buffer;
  142. buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
  143. if (!buffer)
  144. return 0;
  145. enable = lpfc_debugfs_enable;
  146. lpfc_debugfs_enable = 0;
  147. len = 0;
  148. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  149. (lpfc_debugfs_max_disc_trc - 1);
  150. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  151. dtp = vport->disc_trc + i;
  152. if (!dtp->fmt)
  153. continue;
  154. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  155. snprintf(buffer,
  156. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  157. dtp->seq_cnt, ms, dtp->fmt);
  158. len += scnprintf(buf+len, size-len, buffer,
  159. dtp->data1, dtp->data2, dtp->data3);
  160. }
  161. for (i = 0; i < index; i++) {
  162. dtp = vport->disc_trc + i;
  163. if (!dtp->fmt)
  164. continue;
  165. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  166. snprintf(buffer,
  167. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  168. dtp->seq_cnt, ms, dtp->fmt);
  169. len += scnprintf(buf+len, size-len, buffer,
  170. dtp->data1, dtp->data2, dtp->data3);
  171. }
  172. lpfc_debugfs_enable = enable;
  173. kfree(buffer);
  174. return len;
  175. }
  176. /**
  177. * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
  178. * @phba: The HBA to gather the log info from.
  179. * @buf: The buffer to dump log into.
  180. * @size: The maximum amount of data to process.
  181. *
  182. * Description:
  183. * This routine gathers the lpfc slow ring debugfs data from the @phba and
  184. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  185. * in the log and process the log until the end of the buffer. Then it will
  186. * gather from the beginning of the log and process until the current entry.
  187. *
  188. * Notes:
  189. * Slow ring logging will be disabled while while this routine dumps the log.
  190. *
  191. * Return Value:
  192. * This routine returns the amount of bytes that were dumped into @buf and will
  193. * not exceed @size.
  194. **/
  195. static int
  196. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  197. {
  198. int i, index, len, enable;
  199. uint32_t ms;
  200. struct lpfc_debugfs_trc *dtp;
  201. char *buffer;
  202. buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
  203. if (!buffer)
  204. return 0;
  205. enable = lpfc_debugfs_enable;
  206. lpfc_debugfs_enable = 0;
  207. len = 0;
  208. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  209. (lpfc_debugfs_max_slow_ring_trc - 1);
  210. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  211. dtp = phba->slow_ring_trc + i;
  212. if (!dtp->fmt)
  213. continue;
  214. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  215. snprintf(buffer,
  216. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  217. dtp->seq_cnt, ms, dtp->fmt);
  218. len += scnprintf(buf+len, size-len, buffer,
  219. dtp->data1, dtp->data2, dtp->data3);
  220. }
  221. for (i = 0; i < index; i++) {
  222. dtp = phba->slow_ring_trc + i;
  223. if (!dtp->fmt)
  224. continue;
  225. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  226. snprintf(buffer,
  227. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  228. dtp->seq_cnt, ms, dtp->fmt);
  229. len += scnprintf(buf+len, size-len, buffer,
  230. dtp->data1, dtp->data2, dtp->data3);
  231. }
  232. lpfc_debugfs_enable = enable;
  233. kfree(buffer);
  234. return len;
  235. }
  236. static int lpfc_debugfs_last_hbq = -1;
  237. /**
  238. * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
  239. * @phba: The HBA to gather host buffer info from.
  240. * @buf: The buffer to dump log into.
  241. * @size: The maximum amount of data to process.
  242. *
  243. * Description:
  244. * This routine dumps the host buffer queue info from the @phba to @buf up to
  245. * @size number of bytes. A header that describes the current hbq state will be
  246. * dumped to @buf first and then info on each hbq entry will be dumped to @buf
  247. * until @size bytes have been dumped or all the hbq info has been dumped.
  248. *
  249. * Notes:
  250. * This routine will rotate through each configured HBQ each time called.
  251. *
  252. * Return Value:
  253. * This routine returns the amount of bytes that were dumped into @buf and will
  254. * not exceed @size.
  255. **/
  256. static int
  257. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  258. {
  259. int len = 0;
  260. int i, j, found, posted, low;
  261. uint32_t phys, raw_index, getidx;
  262. struct lpfc_hbq_init *hip;
  263. struct hbq_s *hbqs;
  264. struct lpfc_hbq_entry *hbqe;
  265. struct lpfc_dmabuf *d_buf;
  266. struct hbq_dmabuf *hbq_buf;
  267. if (phba->sli_rev != 3)
  268. return 0;
  269. spin_lock_irq(&phba->hbalock);
  270. /* toggle between multiple hbqs, if any */
  271. i = lpfc_sli_hbq_count();
  272. if (i > 1) {
  273. lpfc_debugfs_last_hbq++;
  274. if (lpfc_debugfs_last_hbq >= i)
  275. lpfc_debugfs_last_hbq = 0;
  276. }
  277. else
  278. lpfc_debugfs_last_hbq = 0;
  279. i = lpfc_debugfs_last_hbq;
  280. len += scnprintf(buf+len, size-len, "HBQ %d Info\n", i);
  281. hbqs = &phba->hbqs[i];
  282. posted = 0;
  283. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  284. posted++;
  285. hip = lpfc_hbq_defs[i];
  286. len += scnprintf(buf+len, size-len,
  287. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  288. hip->hbq_index, hip->profile, hip->rn,
  289. hip->buffer_count, hip->init_count, hip->add_count, posted);
  290. raw_index = phba->hbq_get[i];
  291. getidx = le32_to_cpu(raw_index);
  292. len += scnprintf(buf+len, size-len,
  293. "entries:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  294. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  295. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  296. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  297. for (j=0; j<hbqs->entry_count; j++) {
  298. len += scnprintf(buf+len, size-len,
  299. "%03d: %08x %04x %05x ", j,
  300. le32_to_cpu(hbqe->bde.addrLow),
  301. le32_to_cpu(hbqe->bde.tus.w),
  302. le32_to_cpu(hbqe->buffer_tag));
  303. i = 0;
  304. found = 0;
  305. /* First calculate if slot has an associated posted buffer */
  306. low = hbqs->hbqPutIdx - posted;
  307. if (low >= 0) {
  308. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  309. len += scnprintf(buf + len, size - len,
  310. "Unused\n");
  311. goto skipit;
  312. }
  313. }
  314. else {
  315. if ((j >= hbqs->hbqPutIdx) &&
  316. (j < (hbqs->entry_count+low))) {
  317. len += scnprintf(buf + len, size - len,
  318. "Unused\n");
  319. goto skipit;
  320. }
  321. }
  322. /* Get the Buffer info for the posted buffer */
  323. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  324. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  325. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  326. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  327. len += scnprintf(buf+len, size-len,
  328. "Buf%d: x%px %06x\n", i,
  329. hbq_buf->dbuf.virt, hbq_buf->tag);
  330. found = 1;
  331. break;
  332. }
  333. i++;
  334. }
  335. if (!found) {
  336. len += scnprintf(buf+len, size-len, "No DMAinfo?\n");
  337. }
  338. skipit:
  339. hbqe++;
  340. if (len > LPFC_HBQINFO_SIZE - 54)
  341. break;
  342. }
  343. spin_unlock_irq(&phba->hbalock);
  344. return len;
  345. }
  346. static int lpfc_debugfs_last_xripool;
  347. /**
  348. * lpfc_debugfs_common_xri_data - Dump Hardware Queue info to a buffer
  349. * @phba: The HBA to gather host buffer info from.
  350. * @buf: The buffer to dump log into.
  351. * @size: The maximum amount of data to process.
  352. *
  353. * Description:
  354. * This routine dumps the Hardware Queue info from the @phba to @buf up to
  355. * @size number of bytes. A header that describes the current hdwq state will be
  356. * dumped to @buf first and then info on each hdwq entry will be dumped to @buf
  357. * until @size bytes have been dumped or all the hdwq info has been dumped.
  358. *
  359. * Notes:
  360. * This routine will rotate through each configured Hardware Queue each
  361. * time called.
  362. *
  363. * Return Value:
  364. * This routine returns the amount of bytes that were dumped into @buf and will
  365. * not exceed @size.
  366. **/
  367. static int
  368. lpfc_debugfs_commonxripools_data(struct lpfc_hba *phba, char *buf, int size)
  369. {
  370. struct lpfc_sli4_hdw_queue *qp;
  371. int len = 0;
  372. int i, out;
  373. unsigned long iflag;
  374. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  375. if (len > (LPFC_DUMP_MULTIXRIPOOL_SIZE - 80))
  376. break;
  377. qp = &phba->sli4_hba.hdwq[lpfc_debugfs_last_xripool];
  378. len += scnprintf(buf + len, size - len, "HdwQ %d Info ", i);
  379. spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag);
  380. spin_lock(&qp->io_buf_list_get_lock);
  381. spin_lock(&qp->io_buf_list_put_lock);
  382. out = qp->total_io_bufs - (qp->get_io_bufs + qp->put_io_bufs +
  383. qp->abts_scsi_io_bufs + qp->abts_nvme_io_bufs);
  384. len += scnprintf(buf + len, size - len,
  385. "tot:%d get:%d put:%d mt:%d "
  386. "ABTS scsi:%d nvme:%d Out:%d\n",
  387. qp->total_io_bufs, qp->get_io_bufs, qp->put_io_bufs,
  388. qp->empty_io_bufs, qp->abts_scsi_io_bufs,
  389. qp->abts_nvme_io_bufs, out);
  390. spin_unlock(&qp->io_buf_list_put_lock);
  391. spin_unlock(&qp->io_buf_list_get_lock);
  392. spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag);
  393. lpfc_debugfs_last_xripool++;
  394. if (lpfc_debugfs_last_xripool >= phba->cfg_hdw_queue)
  395. lpfc_debugfs_last_xripool = 0;
  396. }
  397. return len;
  398. }
  399. /**
  400. * lpfc_debugfs_multixripools_data - Display multi-XRI pools information
  401. * @phba: The HBA to gather host buffer info from.
  402. * @buf: The buffer to dump log into.
  403. * @size: The maximum amount of data to process.
  404. *
  405. * Description:
  406. * This routine displays current multi-XRI pools information including XRI
  407. * count in public, private and txcmplq. It also displays current high and
  408. * low watermark.
  409. *
  410. * Return Value:
  411. * This routine returns the amount of bytes that were dumped into @buf and will
  412. * not exceed @size.
  413. **/
  414. static int
  415. lpfc_debugfs_multixripools_data(struct lpfc_hba *phba, char *buf, int size)
  416. {
  417. u32 i;
  418. u32 hwq_count;
  419. struct lpfc_sli4_hdw_queue *qp;
  420. struct lpfc_multixri_pool *multixri_pool;
  421. struct lpfc_pvt_pool *pvt_pool;
  422. struct lpfc_pbl_pool *pbl_pool;
  423. u32 txcmplq_cnt;
  424. char tmp[LPFC_DEBUG_OUT_LINE_SZ] = {0};
  425. if (phba->sli_rev != LPFC_SLI_REV4)
  426. return 0;
  427. if (!phba->sli4_hba.hdwq)
  428. return 0;
  429. if (!phba->cfg_xri_rebalancing) {
  430. i = lpfc_debugfs_commonxripools_data(phba, buf, size);
  431. return i;
  432. }
  433. /*
  434. * Pbl: Current number of free XRIs in public pool
  435. * Pvt: Current number of free XRIs in private pool
  436. * Busy: Current number of outstanding XRIs
  437. * HWM: Current high watermark
  438. * pvt_empty: Incremented by 1 when IO submission fails (no xri)
  439. * pbl_empty: Incremented by 1 when all pbl_pool are empty during
  440. * IO submission
  441. */
  442. scnprintf(tmp, sizeof(tmp),
  443. "HWQ: Pbl Pvt Busy HWM | pvt_empty pbl_empty ");
  444. if (strlcat(buf, tmp, size) >= size)
  445. return strnlen(buf, size);
  446. #ifdef LPFC_MXP_STAT
  447. /*
  448. * MAXH: Max high watermark seen so far
  449. * above_lmt: Incremented by 1 if xri_owned > xri_limit during
  450. * IO submission
  451. * below_lmt: Incremented by 1 if xri_owned <= xri_limit during
  452. * IO submission
  453. * locPbl_hit: Incremented by 1 if successfully get a batch of XRI from
  454. * local pbl_pool
  455. * othPbl_hit: Incremented by 1 if successfully get a batch of XRI from
  456. * other pbl_pool
  457. */
  458. scnprintf(tmp, sizeof(tmp),
  459. "MAXH above_lmt below_lmt locPbl_hit othPbl_hit");
  460. if (strlcat(buf, tmp, size) >= size)
  461. return strnlen(buf, size);
  462. /*
  463. * sPbl: snapshot of Pbl 15 sec after stat gets cleared
  464. * sPvt: snapshot of Pvt 15 sec after stat gets cleared
  465. * sBusy: snapshot of Busy 15 sec after stat gets cleared
  466. */
  467. scnprintf(tmp, sizeof(tmp),
  468. " | sPbl sPvt sBusy");
  469. if (strlcat(buf, tmp, size) >= size)
  470. return strnlen(buf, size);
  471. #endif
  472. scnprintf(tmp, sizeof(tmp), "\n");
  473. if (strlcat(buf, tmp, size) >= size)
  474. return strnlen(buf, size);
  475. hwq_count = phba->cfg_hdw_queue;
  476. for (i = 0; i < hwq_count; i++) {
  477. qp = &phba->sli4_hba.hdwq[i];
  478. multixri_pool = qp->p_multixri_pool;
  479. if (!multixri_pool)
  480. continue;
  481. pbl_pool = &multixri_pool->pbl_pool;
  482. pvt_pool = &multixri_pool->pvt_pool;
  483. txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
  484. scnprintf(tmp, sizeof(tmp),
  485. "%03d: %4d %4d %4d %4d | %10d %10d ",
  486. i, pbl_pool->count, pvt_pool->count,
  487. txcmplq_cnt, pvt_pool->high_watermark,
  488. qp->empty_io_bufs, multixri_pool->pbl_empty_count);
  489. if (strlcat(buf, tmp, size) >= size)
  490. break;
  491. #ifdef LPFC_MXP_STAT
  492. scnprintf(tmp, sizeof(tmp),
  493. "%4d %10d %10d %10d %10d",
  494. multixri_pool->stat_max_hwm,
  495. multixri_pool->above_limit_count,
  496. multixri_pool->below_limit_count,
  497. multixri_pool->local_pbl_hit_count,
  498. multixri_pool->other_pbl_hit_count);
  499. if (strlcat(buf, tmp, size) >= size)
  500. break;
  501. scnprintf(tmp, sizeof(tmp),
  502. " | %4d %4d %5d",
  503. multixri_pool->stat_pbl_count,
  504. multixri_pool->stat_pvt_count,
  505. multixri_pool->stat_busy_count);
  506. if (strlcat(buf, tmp, size) >= size)
  507. break;
  508. #endif
  509. scnprintf(tmp, sizeof(tmp), "\n");
  510. if (strlcat(buf, tmp, size) >= size)
  511. break;
  512. }
  513. return strnlen(buf, size);
  514. }
  515. #ifdef LPFC_HDWQ_LOCK_STAT
  516. static int lpfc_debugfs_last_lock;
  517. /**
  518. * lpfc_debugfs_lockstat_data - Dump Hardware Queue info to a buffer
  519. * @phba: The HBA to gather host buffer info from.
  520. * @buf: The buffer to dump log into.
  521. * @size: The maximum amount of data to process.
  522. *
  523. * Description:
  524. * This routine dumps the Hardware Queue info from the @phba to @buf up to
  525. * @size number of bytes. A header that describes the current hdwq state will be
  526. * dumped to @buf first and then info on each hdwq entry will be dumped to @buf
  527. * until @size bytes have been dumped or all the hdwq info has been dumped.
  528. *
  529. * Notes:
  530. * This routine will rotate through each configured Hardware Queue each
  531. * time called.
  532. *
  533. * Return Value:
  534. * This routine returns the amount of bytes that were dumped into @buf and will
  535. * not exceed @size.
  536. **/
  537. static int
  538. lpfc_debugfs_lockstat_data(struct lpfc_hba *phba, char *buf, int size)
  539. {
  540. struct lpfc_sli4_hdw_queue *qp;
  541. int len = 0;
  542. int i;
  543. if (phba->sli_rev != LPFC_SLI_REV4)
  544. return 0;
  545. if (!phba->sli4_hba.hdwq)
  546. return 0;
  547. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  548. if (len > (LPFC_HDWQINFO_SIZE - 100))
  549. break;
  550. qp = &phba->sli4_hba.hdwq[lpfc_debugfs_last_lock];
  551. len += scnprintf(buf + len, size - len, "HdwQ %03d Lock ", i);
  552. if (phba->cfg_xri_rebalancing) {
  553. len += scnprintf(buf + len, size - len,
  554. "get_pvt:%d mv_pvt:%d "
  555. "mv2pub:%d mv2pvt:%d "
  556. "put_pvt:%d put_pub:%d wq:%d\n",
  557. qp->lock_conflict.alloc_pvt_pool,
  558. qp->lock_conflict.mv_from_pvt_pool,
  559. qp->lock_conflict.mv_to_pub_pool,
  560. qp->lock_conflict.mv_to_pvt_pool,
  561. qp->lock_conflict.free_pvt_pool,
  562. qp->lock_conflict.free_pub_pool,
  563. qp->lock_conflict.wq_access);
  564. } else {
  565. len += scnprintf(buf + len, size - len,
  566. "get:%d put:%d free:%d wq:%d\n",
  567. qp->lock_conflict.alloc_xri_get,
  568. qp->lock_conflict.alloc_xri_put,
  569. qp->lock_conflict.free_xri,
  570. qp->lock_conflict.wq_access);
  571. }
  572. lpfc_debugfs_last_lock++;
  573. if (lpfc_debugfs_last_lock >= phba->cfg_hdw_queue)
  574. lpfc_debugfs_last_lock = 0;
  575. }
  576. return len;
  577. }
  578. #endif
  579. static int lpfc_debugfs_last_hba_slim_off;
  580. /**
  581. * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
  582. * @phba: The HBA to gather SLIM info from.
  583. * @buf: The buffer to dump log into.
  584. * @size: The maximum amount of data to process.
  585. *
  586. * Description:
  587. * This routine dumps the current contents of HBA SLIM for the HBA associated
  588. * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
  589. *
  590. * Notes:
  591. * This routine will only dump up to 1024 bytes of data each time called and
  592. * should be called multiple times to dump the entire HBA SLIM.
  593. *
  594. * Return Value:
  595. * This routine returns the amount of bytes that were dumped into @buf and will
  596. * not exceed @size.
  597. **/
  598. static int
  599. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  600. {
  601. int len = 0;
  602. int i, off;
  603. uint32_t *ptr;
  604. char *buffer;
  605. buffer = kmalloc(1024, GFP_KERNEL);
  606. if (!buffer)
  607. return 0;
  608. off = 0;
  609. spin_lock_irq(&phba->hbalock);
  610. len += scnprintf(buf+len, size-len, "HBA SLIM\n");
  611. lpfc_memcpy_from_slim(buffer,
  612. phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
  613. ptr = (uint32_t *)&buffer[0];
  614. off = lpfc_debugfs_last_hba_slim_off;
  615. /* Set it up for the next time */
  616. lpfc_debugfs_last_hba_slim_off += 1024;
  617. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  618. lpfc_debugfs_last_hba_slim_off = 0;
  619. i = 1024;
  620. while (i > 0) {
  621. len += scnprintf(buf+len, size-len,
  622. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  623. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  624. *(ptr+5), *(ptr+6), *(ptr+7));
  625. ptr += 8;
  626. i -= (8 * sizeof(uint32_t));
  627. off += (8 * sizeof(uint32_t));
  628. }
  629. spin_unlock_irq(&phba->hbalock);
  630. kfree(buffer);
  631. return len;
  632. }
  633. /**
  634. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
  635. * @phba: The HBA to gather Host SLIM info from.
  636. * @buf: The buffer to dump log into.
  637. * @size: The maximum amount of data to process.
  638. *
  639. * Description:
  640. * This routine dumps the current contents of host SLIM for the host associated
  641. * with @phba to @buf up to @size bytes of data. The dump will contain the
  642. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  643. *
  644. * Return Value:
  645. * This routine returns the amount of bytes that were dumped into @buf and will
  646. * not exceed @size.
  647. **/
  648. static int
  649. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  650. {
  651. int len = 0;
  652. int i, off;
  653. uint32_t word0, word1, word2, word3;
  654. uint32_t *ptr;
  655. struct lpfc_pgp *pgpp;
  656. struct lpfc_sli *psli = &phba->sli;
  657. struct lpfc_sli_ring *pring;
  658. off = 0;
  659. spin_lock_irq(&phba->hbalock);
  660. len += scnprintf(buf+len, size-len, "SLIM Mailbox\n");
  661. ptr = (uint32_t *)phba->slim2p.virt;
  662. i = sizeof(MAILBOX_t);
  663. while (i > 0) {
  664. len += scnprintf(buf+len, size-len,
  665. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  666. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  667. *(ptr+5), *(ptr+6), *(ptr+7));
  668. ptr += 8;
  669. i -= (8 * sizeof(uint32_t));
  670. off += (8 * sizeof(uint32_t));
  671. }
  672. len += scnprintf(buf+len, size-len, "SLIM PCB\n");
  673. ptr = (uint32_t *)phba->pcb;
  674. i = sizeof(PCB_t);
  675. while (i > 0) {
  676. len += scnprintf(buf+len, size-len,
  677. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  678. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  679. *(ptr+5), *(ptr+6), *(ptr+7));
  680. ptr += 8;
  681. i -= (8 * sizeof(uint32_t));
  682. off += (8 * sizeof(uint32_t));
  683. }
  684. if (phba->sli_rev <= LPFC_SLI_REV3) {
  685. for (i = 0; i < 4; i++) {
  686. pgpp = &phba->port_gp[i];
  687. pring = &psli->sli3_ring[i];
  688. len += scnprintf(buf+len, size-len,
  689. "Ring %d: CMD GetInx:%d "
  690. "(Max:%d Next:%d "
  691. "Local:%d flg:x%x) "
  692. "RSP PutInx:%d Max:%d\n",
  693. i, pgpp->cmdGetInx,
  694. pring->sli.sli3.numCiocb,
  695. pring->sli.sli3.next_cmdidx,
  696. pring->sli.sli3.local_getidx,
  697. pring->flag, pgpp->rspPutInx,
  698. pring->sli.sli3.numRiocb);
  699. }
  700. word0 = readl(phba->HAregaddr);
  701. word1 = readl(phba->CAregaddr);
  702. word2 = readl(phba->HSregaddr);
  703. word3 = readl(phba->HCregaddr);
  704. len += scnprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
  705. "HC:%08x\n", word0, word1, word2, word3);
  706. }
  707. spin_unlock_irq(&phba->hbalock);
  708. return len;
  709. }
  710. /**
  711. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
  712. * @vport: The vport to gather target node info from.
  713. * @buf: The buffer to dump log into.
  714. * @size: The maximum amount of data to process.
  715. *
  716. * Description:
  717. * This routine dumps the current target node list associated with @vport to
  718. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  719. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  720. *
  721. * Return Value:
  722. * This routine returns the amount of bytes that were dumped into @buf and will
  723. * not exceed @size.
  724. **/
  725. static int
  726. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  727. {
  728. int len = 0;
  729. int i, iocnt, outio, cnt;
  730. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  731. struct lpfc_hba *phba = vport->phba;
  732. struct lpfc_nodelist *ndlp;
  733. unsigned char *statep;
  734. struct nvme_fc_local_port *localport;
  735. struct nvme_fc_remote_port *nrport = NULL;
  736. struct lpfc_nvme_rport *rport;
  737. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  738. outio = 0;
  739. len += scnprintf(buf+len, size-len, "\nFCP Nodelist Entries ...\n");
  740. spin_lock_irq(shost->host_lock);
  741. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  742. iocnt = 0;
  743. if (!cnt) {
  744. len += scnprintf(buf+len, size-len,
  745. "Missing Nodelist Entries\n");
  746. break;
  747. }
  748. cnt--;
  749. switch (ndlp->nlp_state) {
  750. case NLP_STE_UNUSED_NODE:
  751. statep = "UNUSED";
  752. break;
  753. case NLP_STE_PLOGI_ISSUE:
  754. statep = "PLOGI ";
  755. break;
  756. case NLP_STE_ADISC_ISSUE:
  757. statep = "ADISC ";
  758. break;
  759. case NLP_STE_REG_LOGIN_ISSUE:
  760. statep = "REGLOG";
  761. break;
  762. case NLP_STE_PRLI_ISSUE:
  763. statep = "PRLI ";
  764. break;
  765. case NLP_STE_LOGO_ISSUE:
  766. statep = "LOGO ";
  767. break;
  768. case NLP_STE_UNMAPPED_NODE:
  769. statep = "UNMAP ";
  770. iocnt = 1;
  771. break;
  772. case NLP_STE_MAPPED_NODE:
  773. statep = "MAPPED";
  774. iocnt = 1;
  775. break;
  776. case NLP_STE_NPR_NODE:
  777. statep = "NPR ";
  778. break;
  779. default:
  780. statep = "UNKNOWN";
  781. }
  782. len += scnprintf(buf+len, size-len, "%s DID:x%06x ",
  783. statep, ndlp->nlp_DID);
  784. len += scnprintf(buf+len, size-len,
  785. "WWPN x%llx ",
  786. wwn_to_u64(ndlp->nlp_portname.u.wwn));
  787. len += scnprintf(buf+len, size-len,
  788. "WWNN x%llx ",
  789. wwn_to_u64(ndlp->nlp_nodename.u.wwn));
  790. if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
  791. len += scnprintf(buf+len, size-len, "RPI:%03d ",
  792. ndlp->nlp_rpi);
  793. else
  794. len += scnprintf(buf+len, size-len, "RPI:none ");
  795. len += scnprintf(buf+len, size-len, "flag:x%08x ",
  796. ndlp->nlp_flag);
  797. if (!ndlp->nlp_type)
  798. len += scnprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  799. if (ndlp->nlp_type & NLP_FC_NODE)
  800. len += scnprintf(buf+len, size-len, "FC_NODE ");
  801. if (ndlp->nlp_type & NLP_FABRIC) {
  802. len += scnprintf(buf+len, size-len, "FABRIC ");
  803. iocnt = 0;
  804. }
  805. if (ndlp->nlp_type & NLP_FCP_TARGET)
  806. len += scnprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  807. ndlp->nlp_sid);
  808. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  809. len += scnprintf(buf+len, size-len, "FCP_INITIATOR ");
  810. if (ndlp->nlp_type & NLP_NVME_TARGET)
  811. len += scnprintf(buf + len,
  812. size - len, "NVME_TGT sid:%d ",
  813. NLP_NO_SID);
  814. if (ndlp->nlp_type & NLP_NVME_INITIATOR)
  815. len += scnprintf(buf + len,
  816. size - len, "NVME_INITIATOR ");
  817. len += scnprintf(buf+len, size-len, "usgmap:%x ",
  818. ndlp->nlp_usg_map);
  819. len += scnprintf(buf+len, size-len, "refcnt:%x",
  820. kref_read(&ndlp->kref));
  821. if (iocnt) {
  822. i = atomic_read(&ndlp->cmd_pending);
  823. len += scnprintf(buf + len, size - len,
  824. " OutIO:x%x Qdepth x%x",
  825. i, ndlp->cmd_qdepth);
  826. outio += i;
  827. }
  828. len += scnprintf(buf + len, size - len, "defer:%x ",
  829. ndlp->nlp_defer_did);
  830. len += scnprintf(buf+len, size-len, "\n");
  831. }
  832. spin_unlock_irq(shost->host_lock);
  833. len += scnprintf(buf + len, size - len,
  834. "\nOutstanding IO x%x\n", outio);
  835. if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
  836. len += scnprintf(buf + len, size - len,
  837. "\nNVME Targetport Entry ...\n");
  838. /* Port state is only one of two values for now. */
  839. if (phba->targetport->port_id)
  840. statep = "REGISTERED";
  841. else
  842. statep = "INIT";
  843. len += scnprintf(buf + len, size - len,
  844. "TGT WWNN x%llx WWPN x%llx State %s\n",
  845. wwn_to_u64(vport->fc_nodename.u.wwn),
  846. wwn_to_u64(vport->fc_portname.u.wwn),
  847. statep);
  848. len += scnprintf(buf + len, size - len,
  849. " Targetport DID x%06x\n",
  850. phba->targetport->port_id);
  851. goto out_exit;
  852. }
  853. len += scnprintf(buf + len, size - len,
  854. "\nNVME Lport/Rport Entries ...\n");
  855. localport = vport->localport;
  856. if (!localport)
  857. goto out_exit;
  858. spin_lock_irq(shost->host_lock);
  859. /* Port state is only one of two values for now. */
  860. if (localport->port_id)
  861. statep = "ONLINE";
  862. else
  863. statep = "UNKNOWN ";
  864. len += scnprintf(buf + len, size - len,
  865. "Lport DID x%06x PortState %s\n",
  866. localport->port_id, statep);
  867. len += scnprintf(buf + len, size - len, "\tRport List:\n");
  868. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  869. /* local short-hand pointer. */
  870. spin_lock(&phba->hbalock);
  871. rport = lpfc_ndlp_get_nrport(ndlp);
  872. if (rport)
  873. nrport = rport->remoteport;
  874. else
  875. nrport = NULL;
  876. spin_unlock(&phba->hbalock);
  877. if (!nrport)
  878. continue;
  879. /* Port state is only one of two values for now. */
  880. switch (nrport->port_state) {
  881. case FC_OBJSTATE_ONLINE:
  882. statep = "ONLINE";
  883. break;
  884. case FC_OBJSTATE_UNKNOWN:
  885. statep = "UNKNOWN ";
  886. break;
  887. default:
  888. statep = "UNSUPPORTED";
  889. break;
  890. }
  891. /* Tab in to show lport ownership. */
  892. len += scnprintf(buf + len, size - len,
  893. "\t%s Port ID:x%06x ",
  894. statep, nrport->port_id);
  895. len += scnprintf(buf + len, size - len, "WWPN x%llx ",
  896. nrport->port_name);
  897. len += scnprintf(buf + len, size - len, "WWNN x%llx ",
  898. nrport->node_name);
  899. /* An NVME rport can have multiple roles. */
  900. if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
  901. len += scnprintf(buf + len, size - len,
  902. "INITIATOR ");
  903. if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
  904. len += scnprintf(buf + len, size - len,
  905. "TARGET ");
  906. if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
  907. len += scnprintf(buf + len, size - len,
  908. "DISCSRVC ");
  909. if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
  910. FC_PORT_ROLE_NVME_TARGET |
  911. FC_PORT_ROLE_NVME_DISCOVERY))
  912. len += scnprintf(buf + len, size - len,
  913. "UNKNOWN ROLE x%x",
  914. nrport->port_role);
  915. /* Terminate the string. */
  916. len += scnprintf(buf + len, size - len, "\n");
  917. }
  918. spin_unlock_irq(shost->host_lock);
  919. out_exit:
  920. return len;
  921. }
  922. /**
  923. * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
  924. * @vport: The vport to gather target node info from.
  925. * @buf: The buffer to dump log into.
  926. * @size: The maximum amount of data to process.
  927. *
  928. * Description:
  929. * This routine dumps the NVME statistics associated with @vport
  930. *
  931. * Return Value:
  932. * This routine returns the amount of bytes that were dumped into @buf and will
  933. * not exceed @size.
  934. **/
  935. static int
  936. lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
  937. {
  938. struct lpfc_hba *phba = vport->phba;
  939. struct lpfc_nvmet_tgtport *tgtp;
  940. struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp;
  941. struct nvme_fc_local_port *localport;
  942. struct lpfc_fc4_ctrl_stat *cstat;
  943. struct lpfc_nvme_lport *lport;
  944. uint64_t data1, data2, data3;
  945. uint64_t tot, totin, totout;
  946. int cnt, i;
  947. int len = 0;
  948. if (phba->nvmet_support) {
  949. if (!phba->targetport)
  950. return len;
  951. tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
  952. len += scnprintf(buf + len, size - len,
  953. "\nNVME Targetport Statistics\n");
  954. len += scnprintf(buf + len, size - len,
  955. "LS: Rcv %08x Drop %08x Abort %08x\n",
  956. atomic_read(&tgtp->rcv_ls_req_in),
  957. atomic_read(&tgtp->rcv_ls_req_drop),
  958. atomic_read(&tgtp->xmt_ls_abort));
  959. if (atomic_read(&tgtp->rcv_ls_req_in) !=
  960. atomic_read(&tgtp->rcv_ls_req_out)) {
  961. len += scnprintf(buf + len, size - len,
  962. "Rcv LS: in %08x != out %08x\n",
  963. atomic_read(&tgtp->rcv_ls_req_in),
  964. atomic_read(&tgtp->rcv_ls_req_out));
  965. }
  966. len += scnprintf(buf + len, size - len,
  967. "LS: Xmt %08x Drop %08x Cmpl %08x\n",
  968. atomic_read(&tgtp->xmt_ls_rsp),
  969. atomic_read(&tgtp->xmt_ls_drop),
  970. atomic_read(&tgtp->xmt_ls_rsp_cmpl));
  971. len += scnprintf(buf + len, size - len,
  972. "LS: RSP Abort %08x xb %08x Err %08x\n",
  973. atomic_read(&tgtp->xmt_ls_rsp_aborted),
  974. atomic_read(&tgtp->xmt_ls_rsp_xb_set),
  975. atomic_read(&tgtp->xmt_ls_rsp_error));
  976. len += scnprintf(buf + len, size - len,
  977. "FCP: Rcv %08x Defer %08x Release %08x "
  978. "Drop %08x\n",
  979. atomic_read(&tgtp->rcv_fcp_cmd_in),
  980. atomic_read(&tgtp->rcv_fcp_cmd_defer),
  981. atomic_read(&tgtp->xmt_fcp_release),
  982. atomic_read(&tgtp->rcv_fcp_cmd_drop));
  983. if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
  984. atomic_read(&tgtp->rcv_fcp_cmd_out)) {
  985. len += scnprintf(buf + len, size - len,
  986. "Rcv FCP: in %08x != out %08x\n",
  987. atomic_read(&tgtp->rcv_fcp_cmd_in),
  988. atomic_read(&tgtp->rcv_fcp_cmd_out));
  989. }
  990. len += scnprintf(buf + len, size - len,
  991. "FCP Rsp: read %08x readrsp %08x "
  992. "write %08x rsp %08x\n",
  993. atomic_read(&tgtp->xmt_fcp_read),
  994. atomic_read(&tgtp->xmt_fcp_read_rsp),
  995. atomic_read(&tgtp->xmt_fcp_write),
  996. atomic_read(&tgtp->xmt_fcp_rsp));
  997. len += scnprintf(buf + len, size - len,
  998. "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
  999. atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
  1000. atomic_read(&tgtp->xmt_fcp_rsp_error),
  1001. atomic_read(&tgtp->xmt_fcp_rsp_drop));
  1002. len += scnprintf(buf + len, size - len,
  1003. "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
  1004. atomic_read(&tgtp->xmt_fcp_rsp_aborted),
  1005. atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
  1006. atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
  1007. len += scnprintf(buf + len, size - len,
  1008. "ABORT: Xmt %08x Cmpl %08x\n",
  1009. atomic_read(&tgtp->xmt_fcp_abort),
  1010. atomic_read(&tgtp->xmt_fcp_abort_cmpl));
  1011. len += scnprintf(buf + len, size - len,
  1012. "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
  1013. atomic_read(&tgtp->xmt_abort_sol),
  1014. atomic_read(&tgtp->xmt_abort_unsol),
  1015. atomic_read(&tgtp->xmt_abort_rsp),
  1016. atomic_read(&tgtp->xmt_abort_rsp_error));
  1017. len += scnprintf(buf + len, size - len, "\n");
  1018. cnt = 0;
  1019. spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
  1020. list_for_each_entry_safe(ctxp, next_ctxp,
  1021. &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
  1022. list) {
  1023. cnt++;
  1024. }
  1025. spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
  1026. if (cnt) {
  1027. len += scnprintf(buf + len, size - len,
  1028. "ABORT: %d ctx entries\n", cnt);
  1029. spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
  1030. list_for_each_entry_safe(ctxp, next_ctxp,
  1031. &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
  1032. list) {
  1033. if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
  1034. break;
  1035. len += scnprintf(buf + len, size - len,
  1036. "Entry: oxid %x state %x "
  1037. "flag %x\n",
  1038. ctxp->oxid, ctxp->state,
  1039. ctxp->flag);
  1040. }
  1041. spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
  1042. }
  1043. /* Calculate outstanding IOs */
  1044. tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
  1045. tot += atomic_read(&tgtp->xmt_fcp_release);
  1046. tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
  1047. len += scnprintf(buf + len, size - len,
  1048. "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
  1049. "CTX Outstanding %08llx\n",
  1050. phba->sli4_hba.nvmet_xri_cnt,
  1051. phba->sli4_hba.nvmet_io_wait_cnt,
  1052. phba->sli4_hba.nvmet_io_wait_total,
  1053. tot);
  1054. } else {
  1055. if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
  1056. return len;
  1057. localport = vport->localport;
  1058. if (!localport)
  1059. return len;
  1060. lport = (struct lpfc_nvme_lport *)localport->private;
  1061. if (!lport)
  1062. return len;
  1063. len += scnprintf(buf + len, size - len,
  1064. "\nNVME HDWQ Statistics\n");
  1065. len += scnprintf(buf + len, size - len,
  1066. "LS: Xmt %016x Cmpl %016x\n",
  1067. atomic_read(&lport->fc4NvmeLsRequests),
  1068. atomic_read(&lport->fc4NvmeLsCmpls));
  1069. totin = 0;
  1070. totout = 0;
  1071. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  1072. cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
  1073. tot = cstat->io_cmpls;
  1074. totin += tot;
  1075. data1 = cstat->input_requests;
  1076. data2 = cstat->output_requests;
  1077. data3 = cstat->control_requests;
  1078. totout += (data1 + data2 + data3);
  1079. /* Limit to 32, debugfs display buffer limitation */
  1080. if (i >= 32)
  1081. continue;
  1082. len += scnprintf(buf + len, PAGE_SIZE - len,
  1083. "HDWQ (%d): Rd %016llx Wr %016llx "
  1084. "IO %016llx ",
  1085. i, data1, data2, data3);
  1086. len += scnprintf(buf + len, PAGE_SIZE - len,
  1087. "Cmpl %016llx OutIO %016llx\n",
  1088. tot, ((data1 + data2 + data3) - tot));
  1089. }
  1090. len += scnprintf(buf + len, PAGE_SIZE - len,
  1091. "Total FCP Cmpl %016llx Issue %016llx "
  1092. "OutIO %016llx\n",
  1093. totin, totout, totout - totin);
  1094. len += scnprintf(buf + len, size - len,
  1095. "LS Xmt Err: Abrt %08x Err %08x "
  1096. "Cmpl Err: xb %08x Err %08x\n",
  1097. atomic_read(&lport->xmt_ls_abort),
  1098. atomic_read(&lport->xmt_ls_err),
  1099. atomic_read(&lport->cmpl_ls_xb),
  1100. atomic_read(&lport->cmpl_ls_err));
  1101. len += scnprintf(buf + len, size - len,
  1102. "FCP Xmt Err: noxri %06x nondlp %06x "
  1103. "qdepth %06x wqerr %06x err %06x Abrt %06x\n",
  1104. atomic_read(&lport->xmt_fcp_noxri),
  1105. atomic_read(&lport->xmt_fcp_bad_ndlp),
  1106. atomic_read(&lport->xmt_fcp_qdepth),
  1107. atomic_read(&lport->xmt_fcp_wqerr),
  1108. atomic_read(&lport->xmt_fcp_err),
  1109. atomic_read(&lport->xmt_fcp_abort));
  1110. len += scnprintf(buf + len, size - len,
  1111. "FCP Cmpl Err: xb %08x Err %08x\n",
  1112. atomic_read(&lport->cmpl_fcp_xb),
  1113. atomic_read(&lport->cmpl_fcp_err));
  1114. }
  1115. return len;
  1116. }
  1117. /**
  1118. * lpfc_debugfs_scsistat_data - Dump target node list to a buffer
  1119. * @vport: The vport to gather target node info from.
  1120. * @buf: The buffer to dump log into.
  1121. * @size: The maximum amount of data to process.
  1122. *
  1123. * Description:
  1124. * This routine dumps the SCSI statistics associated with @vport
  1125. *
  1126. * Return Value:
  1127. * This routine returns the amount of bytes that were dumped into @buf and will
  1128. * not exceed @size.
  1129. **/
  1130. static int
  1131. lpfc_debugfs_scsistat_data(struct lpfc_vport *vport, char *buf, int size)
  1132. {
  1133. int len;
  1134. struct lpfc_hba *phba = vport->phba;
  1135. struct lpfc_fc4_ctrl_stat *cstat;
  1136. u64 data1, data2, data3;
  1137. u64 tot, totin, totout;
  1138. int i;
  1139. char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
  1140. if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
  1141. (phba->sli_rev != LPFC_SLI_REV4))
  1142. return 0;
  1143. scnprintf(buf, size, "SCSI HDWQ Statistics\n");
  1144. totin = 0;
  1145. totout = 0;
  1146. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  1147. cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
  1148. tot = cstat->io_cmpls;
  1149. totin += tot;
  1150. data1 = cstat->input_requests;
  1151. data2 = cstat->output_requests;
  1152. data3 = cstat->control_requests;
  1153. totout += (data1 + data2 + data3);
  1154. scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
  1155. "IO %016llx ", i, data1, data2, data3);
  1156. if (strlcat(buf, tmp, size) >= size)
  1157. goto buffer_done;
  1158. scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
  1159. tot, ((data1 + data2 + data3) - tot));
  1160. if (strlcat(buf, tmp, size) >= size)
  1161. goto buffer_done;
  1162. }
  1163. scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
  1164. "OutIO %016llx\n", totin, totout, totout - totin);
  1165. strlcat(buf, tmp, size);
  1166. buffer_done:
  1167. len = strnlen(buf, size);
  1168. return len;
  1169. }
  1170. void
  1171. lpfc_io_ktime(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
  1172. {
  1173. uint64_t seg1, seg2, seg3, seg4;
  1174. uint64_t segsum;
  1175. if (!lpfc_cmd->ts_last_cmd ||
  1176. !lpfc_cmd->ts_cmd_start ||
  1177. !lpfc_cmd->ts_cmd_wqput ||
  1178. !lpfc_cmd->ts_isr_cmpl ||
  1179. !lpfc_cmd->ts_data_io)
  1180. return;
  1181. if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_cmd_start)
  1182. return;
  1183. if (lpfc_cmd->ts_cmd_start < lpfc_cmd->ts_last_cmd)
  1184. return;
  1185. if (lpfc_cmd->ts_cmd_wqput < lpfc_cmd->ts_cmd_start)
  1186. return;
  1187. if (lpfc_cmd->ts_isr_cmpl < lpfc_cmd->ts_cmd_wqput)
  1188. return;
  1189. if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_isr_cmpl)
  1190. return;
  1191. /*
  1192. * Segment 1 - Time from Last FCP command cmpl is handed
  1193. * off to NVME Layer to start of next command.
  1194. * Segment 2 - Time from Driver receives a IO cmd start
  1195. * from NVME Layer to WQ put is done on IO cmd.
  1196. * Segment 3 - Time from Driver WQ put is done on IO cmd
  1197. * to MSI-X ISR for IO cmpl.
  1198. * Segment 4 - Time from MSI-X ISR for IO cmpl to when
  1199. * cmpl is handled off to the NVME Layer.
  1200. */
  1201. seg1 = lpfc_cmd->ts_cmd_start - lpfc_cmd->ts_last_cmd;
  1202. if (seg1 > 5000000) /* 5 ms - for sequential IOs only */
  1203. seg1 = 0;
  1204. /* Calculate times relative to start of IO */
  1205. seg2 = (lpfc_cmd->ts_cmd_wqput - lpfc_cmd->ts_cmd_start);
  1206. segsum = seg2;
  1207. seg3 = lpfc_cmd->ts_isr_cmpl - lpfc_cmd->ts_cmd_start;
  1208. if (segsum > seg3)
  1209. return;
  1210. seg3 -= segsum;
  1211. segsum += seg3;
  1212. seg4 = lpfc_cmd->ts_data_io - lpfc_cmd->ts_cmd_start;
  1213. if (segsum > seg4)
  1214. return;
  1215. seg4 -= segsum;
  1216. phba->ktime_data_samples++;
  1217. phba->ktime_seg1_total += seg1;
  1218. if (seg1 < phba->ktime_seg1_min)
  1219. phba->ktime_seg1_min = seg1;
  1220. else if (seg1 > phba->ktime_seg1_max)
  1221. phba->ktime_seg1_max = seg1;
  1222. phba->ktime_seg2_total += seg2;
  1223. if (seg2 < phba->ktime_seg2_min)
  1224. phba->ktime_seg2_min = seg2;
  1225. else if (seg2 > phba->ktime_seg2_max)
  1226. phba->ktime_seg2_max = seg2;
  1227. phba->ktime_seg3_total += seg3;
  1228. if (seg3 < phba->ktime_seg3_min)
  1229. phba->ktime_seg3_min = seg3;
  1230. else if (seg3 > phba->ktime_seg3_max)
  1231. phba->ktime_seg3_max = seg3;
  1232. phba->ktime_seg4_total += seg4;
  1233. if (seg4 < phba->ktime_seg4_min)
  1234. phba->ktime_seg4_min = seg4;
  1235. else if (seg4 > phba->ktime_seg4_max)
  1236. phba->ktime_seg4_max = seg4;
  1237. lpfc_cmd->ts_last_cmd = 0;
  1238. lpfc_cmd->ts_cmd_start = 0;
  1239. lpfc_cmd->ts_cmd_wqput = 0;
  1240. lpfc_cmd->ts_isr_cmpl = 0;
  1241. lpfc_cmd->ts_data_io = 0;
  1242. }
  1243. /**
  1244. * lpfc_debugfs_ioktime_data - Dump target node list to a buffer
  1245. * @vport: The vport to gather target node info from.
  1246. * @buf: The buffer to dump log into.
  1247. * @size: The maximum amount of data to process.
  1248. *
  1249. * Description:
  1250. * This routine dumps the NVME statistics associated with @vport
  1251. *
  1252. * Return Value:
  1253. * This routine returns the amount of bytes that were dumped into @buf and will
  1254. * not exceed @size.
  1255. **/
  1256. static int
  1257. lpfc_debugfs_ioktime_data(struct lpfc_vport *vport, char *buf, int size)
  1258. {
  1259. struct lpfc_hba *phba = vport->phba;
  1260. int len = 0;
  1261. if (phba->nvmet_support == 0) {
  1262. /* Initiator */
  1263. len += scnprintf(buf + len, PAGE_SIZE - len,
  1264. "ktime %s: Total Samples: %lld\n",
  1265. (phba->ktime_on ? "Enabled" : "Disabled"),
  1266. phba->ktime_data_samples);
  1267. if (phba->ktime_data_samples == 0)
  1268. return len;
  1269. len += scnprintf(
  1270. buf + len, PAGE_SIZE - len,
  1271. "Segment 1: Last Cmd cmpl "
  1272. "done -to- Start of next Cmd (in driver)\n");
  1273. len += scnprintf(
  1274. buf + len, PAGE_SIZE - len,
  1275. "avg:%08lld min:%08lld max %08lld\n",
  1276. div_u64(phba->ktime_seg1_total,
  1277. phba->ktime_data_samples),
  1278. phba->ktime_seg1_min,
  1279. phba->ktime_seg1_max);
  1280. len += scnprintf(
  1281. buf + len, PAGE_SIZE - len,
  1282. "Segment 2: Driver start of Cmd "
  1283. "-to- Firmware WQ doorbell\n");
  1284. len += scnprintf(
  1285. buf + len, PAGE_SIZE - len,
  1286. "avg:%08lld min:%08lld max %08lld\n",
  1287. div_u64(phba->ktime_seg2_total,
  1288. phba->ktime_data_samples),
  1289. phba->ktime_seg2_min,
  1290. phba->ktime_seg2_max);
  1291. len += scnprintf(
  1292. buf + len, PAGE_SIZE - len,
  1293. "Segment 3: Firmware WQ doorbell -to- "
  1294. "MSI-X ISR cmpl\n");
  1295. len += scnprintf(
  1296. buf + len, PAGE_SIZE - len,
  1297. "avg:%08lld min:%08lld max %08lld\n",
  1298. div_u64(phba->ktime_seg3_total,
  1299. phba->ktime_data_samples),
  1300. phba->ktime_seg3_min,
  1301. phba->ktime_seg3_max);
  1302. len += scnprintf(
  1303. buf + len, PAGE_SIZE - len,
  1304. "Segment 4: MSI-X ISR cmpl -to- "
  1305. "Cmd cmpl done\n");
  1306. len += scnprintf(
  1307. buf + len, PAGE_SIZE - len,
  1308. "avg:%08lld min:%08lld max %08lld\n",
  1309. div_u64(phba->ktime_seg4_total,
  1310. phba->ktime_data_samples),
  1311. phba->ktime_seg4_min,
  1312. phba->ktime_seg4_max);
  1313. len += scnprintf(
  1314. buf + len, PAGE_SIZE - len,
  1315. "Total IO avg time: %08lld\n",
  1316. div_u64(phba->ktime_seg1_total +
  1317. phba->ktime_seg2_total +
  1318. phba->ktime_seg3_total +
  1319. phba->ktime_seg4_total,
  1320. phba->ktime_data_samples));
  1321. return len;
  1322. }
  1323. /* NVME Target */
  1324. len += scnprintf(buf + len, PAGE_SIZE-len,
  1325. "ktime %s: Total Samples: %lld %lld\n",
  1326. (phba->ktime_on ? "Enabled" : "Disabled"),
  1327. phba->ktime_data_samples,
  1328. phba->ktime_status_samples);
  1329. if (phba->ktime_data_samples == 0)
  1330. return len;
  1331. len += scnprintf(buf + len, PAGE_SIZE-len,
  1332. "Segment 1: MSI-X ISR Rcv cmd -to- "
  1333. "cmd pass to NVME Layer\n");
  1334. len += scnprintf(buf + len, PAGE_SIZE-len,
  1335. "avg:%08lld min:%08lld max %08lld\n",
  1336. div_u64(phba->ktime_seg1_total,
  1337. phba->ktime_data_samples),
  1338. phba->ktime_seg1_min,
  1339. phba->ktime_seg1_max);
  1340. len += scnprintf(buf + len, PAGE_SIZE-len,
  1341. "Segment 2: cmd pass to NVME Layer- "
  1342. "-to- Driver rcv cmd OP (action)\n");
  1343. len += scnprintf(buf + len, PAGE_SIZE-len,
  1344. "avg:%08lld min:%08lld max %08lld\n",
  1345. div_u64(phba->ktime_seg2_total,
  1346. phba->ktime_data_samples),
  1347. phba->ktime_seg2_min,
  1348. phba->ktime_seg2_max);
  1349. len += scnprintf(buf + len, PAGE_SIZE-len,
  1350. "Segment 3: Driver rcv cmd OP -to- "
  1351. "Firmware WQ doorbell: cmd\n");
  1352. len += scnprintf(buf + len, PAGE_SIZE-len,
  1353. "avg:%08lld min:%08lld max %08lld\n",
  1354. div_u64(phba->ktime_seg3_total,
  1355. phba->ktime_data_samples),
  1356. phba->ktime_seg3_min,
  1357. phba->ktime_seg3_max);
  1358. len += scnprintf(buf + len, PAGE_SIZE-len,
  1359. "Segment 4: Firmware WQ doorbell: cmd "
  1360. "-to- MSI-X ISR for cmd cmpl\n");
  1361. len += scnprintf(buf + len, PAGE_SIZE-len,
  1362. "avg:%08lld min:%08lld max %08lld\n",
  1363. div_u64(phba->ktime_seg4_total,
  1364. phba->ktime_data_samples),
  1365. phba->ktime_seg4_min,
  1366. phba->ktime_seg4_max);
  1367. len += scnprintf(buf + len, PAGE_SIZE-len,
  1368. "Segment 5: MSI-X ISR for cmd cmpl "
  1369. "-to- NVME layer passed cmd done\n");
  1370. len += scnprintf(buf + len, PAGE_SIZE-len,
  1371. "avg:%08lld min:%08lld max %08lld\n",
  1372. div_u64(phba->ktime_seg5_total,
  1373. phba->ktime_data_samples),
  1374. phba->ktime_seg5_min,
  1375. phba->ktime_seg5_max);
  1376. if (phba->ktime_status_samples == 0) {
  1377. len += scnprintf(buf + len, PAGE_SIZE-len,
  1378. "Total: cmd received by MSI-X ISR "
  1379. "-to- cmd completed on wire\n");
  1380. len += scnprintf(buf + len, PAGE_SIZE-len,
  1381. "avg:%08lld min:%08lld "
  1382. "max %08lld\n",
  1383. div_u64(phba->ktime_seg10_total,
  1384. phba->ktime_data_samples),
  1385. phba->ktime_seg10_min,
  1386. phba->ktime_seg10_max);
  1387. return len;
  1388. }
  1389. len += scnprintf(buf + len, PAGE_SIZE-len,
  1390. "Segment 6: NVME layer passed cmd done "
  1391. "-to- Driver rcv rsp status OP\n");
  1392. len += scnprintf(buf + len, PAGE_SIZE-len,
  1393. "avg:%08lld min:%08lld max %08lld\n",
  1394. div_u64(phba->ktime_seg6_total,
  1395. phba->ktime_status_samples),
  1396. phba->ktime_seg6_min,
  1397. phba->ktime_seg6_max);
  1398. len += scnprintf(buf + len, PAGE_SIZE-len,
  1399. "Segment 7: Driver rcv rsp status OP "
  1400. "-to- Firmware WQ doorbell: status\n");
  1401. len += scnprintf(buf + len, PAGE_SIZE-len,
  1402. "avg:%08lld min:%08lld max %08lld\n",
  1403. div_u64(phba->ktime_seg7_total,
  1404. phba->ktime_status_samples),
  1405. phba->ktime_seg7_min,
  1406. phba->ktime_seg7_max);
  1407. len += scnprintf(buf + len, PAGE_SIZE-len,
  1408. "Segment 8: Firmware WQ doorbell: status"
  1409. " -to- MSI-X ISR for status cmpl\n");
  1410. len += scnprintf(buf + len, PAGE_SIZE-len,
  1411. "avg:%08lld min:%08lld max %08lld\n",
  1412. div_u64(phba->ktime_seg8_total,
  1413. phba->ktime_status_samples),
  1414. phba->ktime_seg8_min,
  1415. phba->ktime_seg8_max);
  1416. len += scnprintf(buf + len, PAGE_SIZE-len,
  1417. "Segment 9: MSI-X ISR for status cmpl "
  1418. "-to- NVME layer passed status done\n");
  1419. len += scnprintf(buf + len, PAGE_SIZE-len,
  1420. "avg:%08lld min:%08lld max %08lld\n",
  1421. div_u64(phba->ktime_seg9_total,
  1422. phba->ktime_status_samples),
  1423. phba->ktime_seg9_min,
  1424. phba->ktime_seg9_max);
  1425. len += scnprintf(buf + len, PAGE_SIZE-len,
  1426. "Total: cmd received by MSI-X ISR -to- "
  1427. "cmd completed on wire\n");
  1428. len += scnprintf(buf + len, PAGE_SIZE-len,
  1429. "avg:%08lld min:%08lld max %08lld\n",
  1430. div_u64(phba->ktime_seg10_total,
  1431. phba->ktime_status_samples),
  1432. phba->ktime_seg10_min,
  1433. phba->ktime_seg10_max);
  1434. return len;
  1435. }
  1436. /**
  1437. * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
  1438. * @phba: The phba to gather target node info from.
  1439. * @buf: The buffer to dump log into.
  1440. * @size: The maximum amount of data to process.
  1441. *
  1442. * Description:
  1443. * This routine dumps the NVME IO trace associated with @phba
  1444. *
  1445. * Return Value:
  1446. * This routine returns the amount of bytes that were dumped into @buf and will
  1447. * not exceed @size.
  1448. **/
  1449. static int
  1450. lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
  1451. {
  1452. struct lpfc_debugfs_nvmeio_trc *dtp;
  1453. int i, state, index, skip;
  1454. int len = 0;
  1455. state = phba->nvmeio_trc_on;
  1456. index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
  1457. (phba->nvmeio_trc_size - 1);
  1458. skip = phba->nvmeio_trc_output_idx;
  1459. len += scnprintf(buf + len, size - len,
  1460. "%s IO Trace %s: next_idx %d skip %d size %d\n",
  1461. (phba->nvmet_support ? "NVME" : "NVMET"),
  1462. (state ? "Enabled" : "Disabled"),
  1463. index, skip, phba->nvmeio_trc_size);
  1464. if (!phba->nvmeio_trc || state)
  1465. return len;
  1466. /* trace MUST bhe off to continue */
  1467. for (i = index; i < phba->nvmeio_trc_size; i++) {
  1468. if (skip) {
  1469. skip--;
  1470. continue;
  1471. }
  1472. dtp = phba->nvmeio_trc + i;
  1473. phba->nvmeio_trc_output_idx++;
  1474. if (!dtp->fmt)
  1475. continue;
  1476. len += scnprintf(buf + len, size - len, dtp->fmt,
  1477. dtp->data1, dtp->data2, dtp->data3);
  1478. if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
  1479. phba->nvmeio_trc_output_idx = 0;
  1480. len += scnprintf(buf + len, size - len,
  1481. "Trace Complete\n");
  1482. goto out;
  1483. }
  1484. if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
  1485. len += scnprintf(buf + len, size - len,
  1486. "Trace Continue (%d of %d)\n",
  1487. phba->nvmeio_trc_output_idx,
  1488. phba->nvmeio_trc_size);
  1489. goto out;
  1490. }
  1491. }
  1492. for (i = 0; i < index; i++) {
  1493. if (skip) {
  1494. skip--;
  1495. continue;
  1496. }
  1497. dtp = phba->nvmeio_trc + i;
  1498. phba->nvmeio_trc_output_idx++;
  1499. if (!dtp->fmt)
  1500. continue;
  1501. len += scnprintf(buf + len, size - len, dtp->fmt,
  1502. dtp->data1, dtp->data2, dtp->data3);
  1503. if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
  1504. phba->nvmeio_trc_output_idx = 0;
  1505. len += scnprintf(buf + len, size - len,
  1506. "Trace Complete\n");
  1507. goto out;
  1508. }
  1509. if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
  1510. len += scnprintf(buf + len, size - len,
  1511. "Trace Continue (%d of %d)\n",
  1512. phba->nvmeio_trc_output_idx,
  1513. phba->nvmeio_trc_size);
  1514. goto out;
  1515. }
  1516. }
  1517. len += scnprintf(buf + len, size - len,
  1518. "Trace Done\n");
  1519. out:
  1520. return len;
  1521. }
  1522. /**
  1523. * lpfc_debugfs_hdwqstat_data - Dump I/O stats to a buffer
  1524. * @vport: The vport to gather target node info from.
  1525. * @buf: The buffer to dump log into.
  1526. * @size: The maximum amount of data to process.
  1527. *
  1528. * Description:
  1529. * This routine dumps the NVME + SCSI statistics associated with @vport
  1530. *
  1531. * Return Value:
  1532. * This routine returns the amount of bytes that were dumped into @buf and will
  1533. * not exceed @size.
  1534. **/
  1535. static int
  1536. lpfc_debugfs_hdwqstat_data(struct lpfc_vport *vport, char *buf, int size)
  1537. {
  1538. struct lpfc_hba *phba = vport->phba;
  1539. struct lpfc_sli4_hdw_queue *qp;
  1540. struct lpfc_hdwq_stat *c_stat;
  1541. int i, j, len;
  1542. uint32_t tot_xmt;
  1543. uint32_t tot_rcv;
  1544. uint32_t tot_cmpl;
  1545. char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
  1546. scnprintf(tmp, sizeof(tmp), "HDWQ Stats:\n\n");
  1547. if (strlcat(buf, tmp, size) >= size)
  1548. goto buffer_done;
  1549. scnprintf(tmp, sizeof(tmp), "(NVME Accounting: %s) ",
  1550. (phba->hdwqstat_on &
  1551. (LPFC_CHECK_NVME_IO | LPFC_CHECK_NVMET_IO) ?
  1552. "Enabled" : "Disabled"));
  1553. if (strlcat(buf, tmp, size) >= size)
  1554. goto buffer_done;
  1555. scnprintf(tmp, sizeof(tmp), "(SCSI Accounting: %s) ",
  1556. (phba->hdwqstat_on & LPFC_CHECK_SCSI_IO ?
  1557. "Enabled" : "Disabled"));
  1558. if (strlcat(buf, tmp, size) >= size)
  1559. goto buffer_done;
  1560. scnprintf(tmp, sizeof(tmp), "\n\n");
  1561. if (strlcat(buf, tmp, size) >= size)
  1562. goto buffer_done;
  1563. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  1564. qp = &phba->sli4_hba.hdwq[i];
  1565. tot_rcv = 0;
  1566. tot_xmt = 0;
  1567. tot_cmpl = 0;
  1568. for_each_present_cpu(j) {
  1569. c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, j);
  1570. /* Only display for this HDWQ */
  1571. if (i != c_stat->hdwq_no)
  1572. continue;
  1573. /* Only display non-zero counters */
  1574. if (!c_stat->xmt_io && !c_stat->cmpl_io &&
  1575. !c_stat->rcv_io)
  1576. continue;
  1577. if (!tot_xmt && !tot_cmpl && !tot_rcv) {
  1578. /* Print HDWQ string only the first time */
  1579. scnprintf(tmp, sizeof(tmp), "[HDWQ %d]:\t", i);
  1580. if (strlcat(buf, tmp, size) >= size)
  1581. goto buffer_done;
  1582. }
  1583. tot_xmt += c_stat->xmt_io;
  1584. tot_cmpl += c_stat->cmpl_io;
  1585. if (phba->nvmet_support)
  1586. tot_rcv += c_stat->rcv_io;
  1587. scnprintf(tmp, sizeof(tmp), "| [CPU %d]: ", j);
  1588. if (strlcat(buf, tmp, size) >= size)
  1589. goto buffer_done;
  1590. if (phba->nvmet_support) {
  1591. scnprintf(tmp, sizeof(tmp),
  1592. "XMT 0x%x CMPL 0x%x RCV 0x%x |",
  1593. c_stat->xmt_io, c_stat->cmpl_io,
  1594. c_stat->rcv_io);
  1595. if (strlcat(buf, tmp, size) >= size)
  1596. goto buffer_done;
  1597. } else {
  1598. scnprintf(tmp, sizeof(tmp),
  1599. "XMT 0x%x CMPL 0x%x |",
  1600. c_stat->xmt_io, c_stat->cmpl_io);
  1601. if (strlcat(buf, tmp, size) >= size)
  1602. goto buffer_done;
  1603. }
  1604. }
  1605. /* Check if nothing to display */
  1606. if (!tot_xmt && !tot_cmpl && !tot_rcv)
  1607. continue;
  1608. scnprintf(tmp, sizeof(tmp), "\t->\t[HDWQ Total: ");
  1609. if (strlcat(buf, tmp, size) >= size)
  1610. goto buffer_done;
  1611. if (phba->nvmet_support) {
  1612. scnprintf(tmp, sizeof(tmp),
  1613. "XMT 0x%x CMPL 0x%x RCV 0x%x]\n\n",
  1614. tot_xmt, tot_cmpl, tot_rcv);
  1615. if (strlcat(buf, tmp, size) >= size)
  1616. goto buffer_done;
  1617. } else {
  1618. scnprintf(tmp, sizeof(tmp),
  1619. "XMT 0x%x CMPL 0x%x]\n\n",
  1620. tot_xmt, tot_cmpl);
  1621. if (strlcat(buf, tmp, size) >= size)
  1622. goto buffer_done;
  1623. }
  1624. }
  1625. buffer_done:
  1626. len = strnlen(buf, size);
  1627. return len;
  1628. }
  1629. #endif
  1630. /**
  1631. * lpfc_debugfs_disc_trc - Store discovery trace log
  1632. * @vport: The vport to associate this trace string with for retrieval.
  1633. * @mask: Log entry classification.
  1634. * @fmt: Format string to be displayed when dumping the log.
  1635. * @data1: 1st data parameter to be applied to @fmt.
  1636. * @data2: 2nd data parameter to be applied to @fmt.
  1637. * @data3: 3rd data parameter to be applied to @fmt.
  1638. *
  1639. * Description:
  1640. * This routine is used by the driver code to add a debugfs log entry to the
  1641. * discovery trace buffer associated with @vport. Only entries with a @mask that
  1642. * match the current debugfs discovery mask will be saved. Entries that do not
  1643. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  1644. * printf when displaying the log.
  1645. **/
  1646. inline void
  1647. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  1648. uint32_t data1, uint32_t data2, uint32_t data3)
  1649. {
  1650. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1651. struct lpfc_debugfs_trc *dtp;
  1652. int index;
  1653. if (!(lpfc_debugfs_mask_disc_trc & mask))
  1654. return;
  1655. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  1656. !vport || !vport->disc_trc)
  1657. return;
  1658. index = atomic_inc_return(&vport->disc_trc_cnt) &
  1659. (lpfc_debugfs_max_disc_trc - 1);
  1660. dtp = vport->disc_trc + index;
  1661. dtp->fmt = fmt;
  1662. dtp->data1 = data1;
  1663. dtp->data2 = data2;
  1664. dtp->data3 = data3;
  1665. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  1666. dtp->jif = jiffies;
  1667. #endif
  1668. return;
  1669. }
  1670. /**
  1671. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
  1672. * @phba: The phba to associate this trace string with for retrieval.
  1673. * @fmt: Format string to be displayed when dumping the log.
  1674. * @data1: 1st data parameter to be applied to @fmt.
  1675. * @data2: 2nd data parameter to be applied to @fmt.
  1676. * @data3: 3rd data parameter to be applied to @fmt.
  1677. *
  1678. * Description:
  1679. * This routine is used by the driver code to add a debugfs log entry to the
  1680. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  1681. * @data3 are used like printf when displaying the log.
  1682. **/
  1683. inline void
  1684. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  1685. uint32_t data1, uint32_t data2, uint32_t data3)
  1686. {
  1687. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1688. struct lpfc_debugfs_trc *dtp;
  1689. int index;
  1690. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  1691. !phba || !phba->slow_ring_trc)
  1692. return;
  1693. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  1694. (lpfc_debugfs_max_slow_ring_trc - 1);
  1695. dtp = phba->slow_ring_trc + index;
  1696. dtp->fmt = fmt;
  1697. dtp->data1 = data1;
  1698. dtp->data2 = data2;
  1699. dtp->data3 = data3;
  1700. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  1701. dtp->jif = jiffies;
  1702. #endif
  1703. return;
  1704. }
  1705. /**
  1706. * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
  1707. * @phba: The phba to associate this trace string with for retrieval.
  1708. * @fmt: Format string to be displayed when dumping the log.
  1709. * @data1: 1st data parameter to be applied to @fmt.
  1710. * @data2: 2nd data parameter to be applied to @fmt.
  1711. * @data3: 3rd data parameter to be applied to @fmt.
  1712. *
  1713. * Description:
  1714. * This routine is used by the driver code to add a debugfs log entry to the
  1715. * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
  1716. * @data3 are used like printf when displaying the log.
  1717. **/
  1718. inline void
  1719. lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
  1720. uint16_t data1, uint16_t data2, uint32_t data3)
  1721. {
  1722. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1723. struct lpfc_debugfs_nvmeio_trc *dtp;
  1724. int index;
  1725. if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
  1726. return;
  1727. index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
  1728. (phba->nvmeio_trc_size - 1);
  1729. dtp = phba->nvmeio_trc + index;
  1730. dtp->fmt = fmt;
  1731. dtp->data1 = data1;
  1732. dtp->data2 = data2;
  1733. dtp->data3 = data3;
  1734. #endif
  1735. }
  1736. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1737. /**
  1738. * lpfc_debugfs_disc_trc_open - Open the discovery trace log
  1739. * @inode: The inode pointer that contains a vport pointer.
  1740. * @file: The file pointer to attach the log output.
  1741. *
  1742. * Description:
  1743. * This routine is the entry point for the debugfs open file operation. It gets
  1744. * the vport from the i_private field in @inode, allocates the necessary buffer
  1745. * for the log, fills the buffer from the in-memory log for this vport, and then
  1746. * returns a pointer to that log in the private_data field in @file.
  1747. *
  1748. * Returns:
  1749. * This function returns zero if successful. On error it will return a negative
  1750. * error value.
  1751. **/
  1752. static int
  1753. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  1754. {
  1755. struct lpfc_vport *vport = inode->i_private;
  1756. struct lpfc_debug *debug;
  1757. int size;
  1758. int rc = -ENOMEM;
  1759. if (!lpfc_debugfs_max_disc_trc) {
  1760. rc = -ENOSPC;
  1761. goto out;
  1762. }
  1763. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1764. if (!debug)
  1765. goto out;
  1766. /* Round to page boundary */
  1767. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  1768. size = PAGE_ALIGN(size);
  1769. debug->buffer = kmalloc(size, GFP_KERNEL);
  1770. if (!debug->buffer) {
  1771. kfree(debug);
  1772. goto out;
  1773. }
  1774. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  1775. file->private_data = debug;
  1776. rc = 0;
  1777. out:
  1778. return rc;
  1779. }
  1780. /**
  1781. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
  1782. * @inode: The inode pointer that contains a vport pointer.
  1783. * @file: The file pointer to attach the log output.
  1784. *
  1785. * Description:
  1786. * This routine is the entry point for the debugfs open file operation. It gets
  1787. * the vport from the i_private field in @inode, allocates the necessary buffer
  1788. * for the log, fills the buffer from the in-memory log for this vport, and then
  1789. * returns a pointer to that log in the private_data field in @file.
  1790. *
  1791. * Returns:
  1792. * This function returns zero if successful. On error it will return a negative
  1793. * error value.
  1794. **/
  1795. static int
  1796. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  1797. {
  1798. struct lpfc_hba *phba = inode->i_private;
  1799. struct lpfc_debug *debug;
  1800. int size;
  1801. int rc = -ENOMEM;
  1802. if (!lpfc_debugfs_max_slow_ring_trc) {
  1803. rc = -ENOSPC;
  1804. goto out;
  1805. }
  1806. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1807. if (!debug)
  1808. goto out;
  1809. /* Round to page boundary */
  1810. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  1811. size = PAGE_ALIGN(size);
  1812. debug->buffer = kmalloc(size, GFP_KERNEL);
  1813. if (!debug->buffer) {
  1814. kfree(debug);
  1815. goto out;
  1816. }
  1817. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  1818. file->private_data = debug;
  1819. rc = 0;
  1820. out:
  1821. return rc;
  1822. }
  1823. /**
  1824. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
  1825. * @inode: The inode pointer that contains a vport pointer.
  1826. * @file: The file pointer to attach the log output.
  1827. *
  1828. * Description:
  1829. * This routine is the entry point for the debugfs open file operation. It gets
  1830. * the vport from the i_private field in @inode, allocates the necessary buffer
  1831. * for the log, fills the buffer from the in-memory log for this vport, and then
  1832. * returns a pointer to that log in the private_data field in @file.
  1833. *
  1834. * Returns:
  1835. * This function returns zero if successful. On error it will return a negative
  1836. * error value.
  1837. **/
  1838. static int
  1839. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  1840. {
  1841. struct lpfc_hba *phba = inode->i_private;
  1842. struct lpfc_debug *debug;
  1843. int rc = -ENOMEM;
  1844. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1845. if (!debug)
  1846. goto out;
  1847. /* Round to page boundary */
  1848. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  1849. if (!debug->buffer) {
  1850. kfree(debug);
  1851. goto out;
  1852. }
  1853. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  1854. LPFC_HBQINFO_SIZE);
  1855. file->private_data = debug;
  1856. rc = 0;
  1857. out:
  1858. return rc;
  1859. }
  1860. /**
  1861. * lpfc_debugfs_multixripools_open - Open the multixripool debugfs buffer
  1862. * @inode: The inode pointer that contains a hba pointer.
  1863. * @file: The file pointer to attach the log output.
  1864. *
  1865. * Description:
  1866. * This routine is the entry point for the debugfs open file operation. It gets
  1867. * the hba from the i_private field in @inode, allocates the necessary buffer
  1868. * for the log, fills the buffer from the in-memory log for this hba, and then
  1869. * returns a pointer to that log in the private_data field in @file.
  1870. *
  1871. * Returns:
  1872. * This function returns zero if successful. On error it will return a negative
  1873. * error value.
  1874. **/
  1875. static int
  1876. lpfc_debugfs_multixripools_open(struct inode *inode, struct file *file)
  1877. {
  1878. struct lpfc_hba *phba = inode->i_private;
  1879. struct lpfc_debug *debug;
  1880. int rc = -ENOMEM;
  1881. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1882. if (!debug)
  1883. goto out;
  1884. /* Round to page boundary */
  1885. debug->buffer = kzalloc(LPFC_DUMP_MULTIXRIPOOL_SIZE, GFP_KERNEL);
  1886. if (!debug->buffer) {
  1887. kfree(debug);
  1888. goto out;
  1889. }
  1890. debug->len = lpfc_debugfs_multixripools_data(
  1891. phba, debug->buffer, LPFC_DUMP_MULTIXRIPOOL_SIZE);
  1892. debug->i_private = inode->i_private;
  1893. file->private_data = debug;
  1894. rc = 0;
  1895. out:
  1896. return rc;
  1897. }
  1898. #ifdef LPFC_HDWQ_LOCK_STAT
  1899. /**
  1900. * lpfc_debugfs_lockstat_open - Open the lockstat debugfs buffer
  1901. * @inode: The inode pointer that contains a vport pointer.
  1902. * @file: The file pointer to attach the log output.
  1903. *
  1904. * Description:
  1905. * This routine is the entry point for the debugfs open file operation. It gets
  1906. * the vport from the i_private field in @inode, allocates the necessary buffer
  1907. * for the log, fills the buffer from the in-memory log for this vport, and then
  1908. * returns a pointer to that log in the private_data field in @file.
  1909. *
  1910. * Returns:
  1911. * This function returns zero if successful. On error it will return a negative
  1912. * error value.
  1913. **/
  1914. static int
  1915. lpfc_debugfs_lockstat_open(struct inode *inode, struct file *file)
  1916. {
  1917. struct lpfc_hba *phba = inode->i_private;
  1918. struct lpfc_debug *debug;
  1919. int rc = -ENOMEM;
  1920. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1921. if (!debug)
  1922. goto out;
  1923. /* Round to page boundary */
  1924. debug->buffer = kmalloc(LPFC_HDWQINFO_SIZE, GFP_KERNEL);
  1925. if (!debug->buffer) {
  1926. kfree(debug);
  1927. goto out;
  1928. }
  1929. debug->len = lpfc_debugfs_lockstat_data(phba, debug->buffer,
  1930. LPFC_HBQINFO_SIZE);
  1931. file->private_data = debug;
  1932. rc = 0;
  1933. out:
  1934. return rc;
  1935. }
  1936. static ssize_t
  1937. lpfc_debugfs_lockstat_write(struct file *file, const char __user *buf,
  1938. size_t nbytes, loff_t *ppos)
  1939. {
  1940. struct lpfc_debug *debug = file->private_data;
  1941. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1942. struct lpfc_sli4_hdw_queue *qp;
  1943. char mybuf[64];
  1944. char *pbuf;
  1945. int i;
  1946. /* Protect copy from user */
  1947. if (!access_ok(buf, nbytes))
  1948. return -EFAULT;
  1949. memset(mybuf, 0, sizeof(mybuf));
  1950. if (copy_from_user(mybuf, buf, nbytes))
  1951. return -EFAULT;
  1952. pbuf = &mybuf[0];
  1953. if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
  1954. (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
  1955. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  1956. qp = &phba->sli4_hba.hdwq[i];
  1957. qp->lock_conflict.alloc_xri_get = 0;
  1958. qp->lock_conflict.alloc_xri_put = 0;
  1959. qp->lock_conflict.free_xri = 0;
  1960. qp->lock_conflict.wq_access = 0;
  1961. qp->lock_conflict.alloc_pvt_pool = 0;
  1962. qp->lock_conflict.mv_from_pvt_pool = 0;
  1963. qp->lock_conflict.mv_to_pub_pool = 0;
  1964. qp->lock_conflict.mv_to_pvt_pool = 0;
  1965. qp->lock_conflict.free_pvt_pool = 0;
  1966. qp->lock_conflict.free_pub_pool = 0;
  1967. qp->lock_conflict.wq_access = 0;
  1968. }
  1969. }
  1970. return nbytes;
  1971. }
  1972. #endif
  1973. static int lpfc_debugfs_ras_log_data(struct lpfc_hba *phba,
  1974. char *buffer, int size)
  1975. {
  1976. int copied = 0;
  1977. struct lpfc_dmabuf *dmabuf, *next;
  1978. memset(buffer, 0, size);
  1979. spin_lock_irq(&phba->hbalock);
  1980. if (phba->ras_fwlog.state != ACTIVE) {
  1981. spin_unlock_irq(&phba->hbalock);
  1982. return -EINVAL;
  1983. }
  1984. spin_unlock_irq(&phba->hbalock);
  1985. list_for_each_entry_safe(dmabuf, next,
  1986. &phba->ras_fwlog.fwlog_buff_list, list) {
  1987. /* Check if copying will go over size and a '\0' char */
  1988. if ((copied + LPFC_RAS_MAX_ENTRY_SIZE) >= (size - 1)) {
  1989. memcpy(buffer + copied, dmabuf->virt,
  1990. size - copied - 1);
  1991. copied += size - copied - 1;
  1992. break;
  1993. }
  1994. memcpy(buffer + copied, dmabuf->virt, LPFC_RAS_MAX_ENTRY_SIZE);
  1995. copied += LPFC_RAS_MAX_ENTRY_SIZE;
  1996. }
  1997. return copied;
  1998. }
  1999. static int
  2000. lpfc_debugfs_ras_log_release(struct inode *inode, struct file *file)
  2001. {
  2002. struct lpfc_debug *debug = file->private_data;
  2003. vfree(debug->buffer);
  2004. kfree(debug);
  2005. return 0;
  2006. }
  2007. /**
  2008. * lpfc_debugfs_ras_log_open - Open the RAS log debugfs buffer
  2009. * @inode: The inode pointer that contains a vport pointer.
  2010. * @file: The file pointer to attach the log output.
  2011. *
  2012. * Description:
  2013. * This routine is the entry point for the debugfs open file operation. It gets
  2014. * the vport from the i_private field in @inode, allocates the necessary buffer
  2015. * for the log, fills the buffer from the in-memory log for this vport, and then
  2016. * returns a pointer to that log in the private_data field in @file.
  2017. *
  2018. * Returns:
  2019. * This function returns zero if successful. On error it will return a negative
  2020. * error value.
  2021. **/
  2022. static int
  2023. lpfc_debugfs_ras_log_open(struct inode *inode, struct file *file)
  2024. {
  2025. struct lpfc_hba *phba = inode->i_private;
  2026. struct lpfc_debug *debug;
  2027. int size;
  2028. int rc = -ENOMEM;
  2029. spin_lock_irq(&phba->hbalock);
  2030. if (phba->ras_fwlog.state != ACTIVE) {
  2031. spin_unlock_irq(&phba->hbalock);
  2032. rc = -EINVAL;
  2033. goto out;
  2034. }
  2035. spin_unlock_irq(&phba->hbalock);
  2036. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2037. if (!debug)
  2038. goto out;
  2039. size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;
  2040. debug->buffer = vmalloc(size);
  2041. if (!debug->buffer)
  2042. goto free_debug;
  2043. debug->len = lpfc_debugfs_ras_log_data(phba, debug->buffer, size);
  2044. if (debug->len < 0) {
  2045. rc = -EINVAL;
  2046. goto free_buffer;
  2047. }
  2048. file->private_data = debug;
  2049. return 0;
  2050. free_buffer:
  2051. vfree(debug->buffer);
  2052. free_debug:
  2053. kfree(debug);
  2054. out:
  2055. return rc;
  2056. }
  2057. /**
  2058. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
  2059. * @inode: The inode pointer that contains a vport pointer.
  2060. * @file: The file pointer to attach the log output.
  2061. *
  2062. * Description:
  2063. * This routine is the entry point for the debugfs open file operation. It gets
  2064. * the vport from the i_private field in @inode, allocates the necessary buffer
  2065. * for the log, fills the buffer from the in-memory log for this vport, and then
  2066. * returns a pointer to that log in the private_data field in @file.
  2067. *
  2068. * Returns:
  2069. * This function returns zero if successful. On error it will return a negative
  2070. * error value.
  2071. **/
  2072. static int
  2073. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  2074. {
  2075. struct lpfc_hba *phba = inode->i_private;
  2076. struct lpfc_debug *debug;
  2077. int rc = -ENOMEM;
  2078. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2079. if (!debug)
  2080. goto out;
  2081. /* Round to page boundary */
  2082. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  2083. if (!debug->buffer) {
  2084. kfree(debug);
  2085. goto out;
  2086. }
  2087. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  2088. LPFC_DUMPHBASLIM_SIZE);
  2089. file->private_data = debug;
  2090. rc = 0;
  2091. out:
  2092. return rc;
  2093. }
  2094. /**
  2095. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
  2096. * @inode: The inode pointer that contains a vport pointer.
  2097. * @file: The file pointer to attach the log output.
  2098. *
  2099. * Description:
  2100. * This routine is the entry point for the debugfs open file operation. It gets
  2101. * the vport from the i_private field in @inode, allocates the necessary buffer
  2102. * for the log, fills the buffer from the in-memory log for this vport, and then
  2103. * returns a pointer to that log in the private_data field in @file.
  2104. *
  2105. * Returns:
  2106. * This function returns zero if successful. On error it will return a negative
  2107. * error value.
  2108. **/
  2109. static int
  2110. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  2111. {
  2112. struct lpfc_hba *phba = inode->i_private;
  2113. struct lpfc_debug *debug;
  2114. int rc = -ENOMEM;
  2115. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2116. if (!debug)
  2117. goto out;
  2118. /* Round to page boundary */
  2119. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  2120. if (!debug->buffer) {
  2121. kfree(debug);
  2122. goto out;
  2123. }
  2124. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  2125. LPFC_DUMPHOSTSLIM_SIZE);
  2126. file->private_data = debug;
  2127. rc = 0;
  2128. out:
  2129. return rc;
  2130. }
  2131. static ssize_t
  2132. lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
  2133. size_t nbytes, loff_t *ppos)
  2134. {
  2135. struct dentry *dent = file->f_path.dentry;
  2136. struct lpfc_hba *phba = file->private_data;
  2137. char cbuf[32];
  2138. uint64_t tmp = 0;
  2139. int cnt = 0;
  2140. if (dent == phba->debug_writeGuard)
  2141. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
  2142. else if (dent == phba->debug_writeApp)
  2143. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
  2144. else if (dent == phba->debug_writeRef)
  2145. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
  2146. else if (dent == phba->debug_readGuard)
  2147. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
  2148. else if (dent == phba->debug_readApp)
  2149. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
  2150. else if (dent == phba->debug_readRef)
  2151. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
  2152. else if (dent == phba->debug_InjErrNPortID)
  2153. cnt = scnprintf(cbuf, 32, "0x%06x\n",
  2154. phba->lpfc_injerr_nportid);
  2155. else if (dent == phba->debug_InjErrWWPN) {
  2156. memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
  2157. tmp = cpu_to_be64(tmp);
  2158. cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
  2159. } else if (dent == phba->debug_InjErrLBA) {
  2160. if (phba->lpfc_injerr_lba == (sector_t)(-1))
  2161. cnt = scnprintf(cbuf, 32, "off\n");
  2162. else
  2163. cnt = scnprintf(cbuf, 32, "0x%llx\n",
  2164. (uint64_t) phba->lpfc_injerr_lba);
  2165. } else
  2166. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2167. "0547 Unknown debugfs error injection entry\n");
  2168. return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
  2169. }
  2170. static ssize_t
  2171. lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
  2172. size_t nbytes, loff_t *ppos)
  2173. {
  2174. struct dentry *dent = file->f_path.dentry;
  2175. struct lpfc_hba *phba = file->private_data;
  2176. char dstbuf[33];
  2177. uint64_t tmp = 0;
  2178. int size;
  2179. memset(dstbuf, 0, 33);
  2180. size = (nbytes < 32) ? nbytes : 32;
  2181. if (copy_from_user(dstbuf, buf, size))
  2182. return 0;
  2183. if (dent == phba->debug_InjErrLBA) {
  2184. if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
  2185. tmp = (uint64_t)(-1);
  2186. }
  2187. if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
  2188. return 0;
  2189. if (dent == phba->debug_writeGuard)
  2190. phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
  2191. else if (dent == phba->debug_writeApp)
  2192. phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
  2193. else if (dent == phba->debug_writeRef)
  2194. phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
  2195. else if (dent == phba->debug_readGuard)
  2196. phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
  2197. else if (dent == phba->debug_readApp)
  2198. phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
  2199. else if (dent == phba->debug_readRef)
  2200. phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
  2201. else if (dent == phba->debug_InjErrLBA)
  2202. phba->lpfc_injerr_lba = (sector_t)tmp;
  2203. else if (dent == phba->debug_InjErrNPortID)
  2204. phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
  2205. else if (dent == phba->debug_InjErrWWPN) {
  2206. tmp = cpu_to_be64(tmp);
  2207. memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
  2208. } else
  2209. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2210. "0548 Unknown debugfs error injection entry\n");
  2211. return nbytes;
  2212. }
  2213. static int
  2214. lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
  2215. {
  2216. return 0;
  2217. }
  2218. /**
  2219. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  2220. * @inode: The inode pointer that contains a vport pointer.
  2221. * @file: The file pointer to attach the log output.
  2222. *
  2223. * Description:
  2224. * This routine is the entry point for the debugfs open file operation. It gets
  2225. * the vport from the i_private field in @inode, allocates the necessary buffer
  2226. * for the log, fills the buffer from the in-memory log for this vport, and then
  2227. * returns a pointer to that log in the private_data field in @file.
  2228. *
  2229. * Returns:
  2230. * This function returns zero if successful. On error it will return a negative
  2231. * error value.
  2232. **/
  2233. static int
  2234. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  2235. {
  2236. struct lpfc_vport *vport = inode->i_private;
  2237. struct lpfc_debug *debug;
  2238. int rc = -ENOMEM;
  2239. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2240. if (!debug)
  2241. goto out;
  2242. /* Round to page boundary */
  2243. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  2244. if (!debug->buffer) {
  2245. kfree(debug);
  2246. goto out;
  2247. }
  2248. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  2249. LPFC_NODELIST_SIZE);
  2250. file->private_data = debug;
  2251. rc = 0;
  2252. out:
  2253. return rc;
  2254. }
  2255. /**
  2256. * lpfc_debugfs_lseek - Seek through a debugfs file
  2257. * @file: The file pointer to seek through.
  2258. * @off: The offset to seek to or the amount to seek by.
  2259. * @whence: Indicates how to seek.
  2260. *
  2261. * Description:
  2262. * This routine is the entry point for the debugfs lseek file operation. The
  2263. * @whence parameter indicates whether @off is the offset to directly seek to,
  2264. * or if it is a value to seek forward or reverse by. This function figures out
  2265. * what the new offset of the debugfs file will be and assigns that value to the
  2266. * f_pos field of @file.
  2267. *
  2268. * Returns:
  2269. * This function returns the new offset if successful and returns a negative
  2270. * error if unable to process the seek.
  2271. **/
  2272. static loff_t
  2273. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  2274. {
  2275. struct lpfc_debug *debug = file->private_data;
  2276. return fixed_size_llseek(file, off, whence, debug->len);
  2277. }
  2278. /**
  2279. * lpfc_debugfs_read - Read a debugfs file
  2280. * @file: The file pointer to read from.
  2281. * @buf: The buffer to copy the data to.
  2282. * @nbytes: The number of bytes to read.
  2283. * @ppos: The position in the file to start reading from.
  2284. *
  2285. * Description:
  2286. * This routine reads data from from the buffer indicated in the private_data
  2287. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  2288. * data to @buf.
  2289. *
  2290. * Returns:
  2291. * This function returns the amount of data that was read (this could be less
  2292. * than @nbytes if the end of the file was reached) or a negative error value.
  2293. **/
  2294. static ssize_t
  2295. lpfc_debugfs_read(struct file *file, char __user *buf,
  2296. size_t nbytes, loff_t *ppos)
  2297. {
  2298. struct lpfc_debug *debug = file->private_data;
  2299. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  2300. debug->len);
  2301. }
  2302. /**
  2303. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  2304. * @inode: The inode pointer that contains a vport pointer. (unused)
  2305. * @file: The file pointer that contains the buffer to release.
  2306. *
  2307. * Description:
  2308. * This routine frees the buffer that was allocated when the debugfs file was
  2309. * opened.
  2310. *
  2311. * Returns:
  2312. * This function returns zero.
  2313. **/
  2314. static int
  2315. lpfc_debugfs_release(struct inode *inode, struct file *file)
  2316. {
  2317. struct lpfc_debug *debug = file->private_data;
  2318. kfree(debug->buffer);
  2319. kfree(debug);
  2320. return 0;
  2321. }
  2322. /**
  2323. * lpfc_debugfs_multixripools_write - Clear multi-XRI pools statistics
  2324. * @file: The file pointer to read from.
  2325. * @buf: The buffer to copy the user data from.
  2326. * @nbytes: The number of bytes to get.
  2327. * @ppos: The position in the file to start reading from.
  2328. *
  2329. * Description:
  2330. * This routine clears multi-XRI pools statistics when buf contains "clear".
  2331. *
  2332. * Return Value:
  2333. * It returns the @nbytges passing in from debugfs user space when successful.
  2334. * In case of error conditions, it returns proper error code back to the user
  2335. * space.
  2336. **/
  2337. static ssize_t
  2338. lpfc_debugfs_multixripools_write(struct file *file, const char __user *buf,
  2339. size_t nbytes, loff_t *ppos)
  2340. {
  2341. struct lpfc_debug *debug = file->private_data;
  2342. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2343. char mybuf[64];
  2344. char *pbuf;
  2345. u32 i;
  2346. u32 hwq_count;
  2347. struct lpfc_sli4_hdw_queue *qp;
  2348. struct lpfc_multixri_pool *multixri_pool;
  2349. if (nbytes > 64)
  2350. nbytes = 64;
  2351. /* Protect copy from user */
  2352. if (!access_ok(buf, nbytes))
  2353. return -EFAULT;
  2354. memset(mybuf, 0, sizeof(mybuf));
  2355. if (copy_from_user(mybuf, buf, nbytes))
  2356. return -EFAULT;
  2357. pbuf = &mybuf[0];
  2358. if ((strncmp(pbuf, "clear", strlen("clear"))) == 0) {
  2359. hwq_count = phba->cfg_hdw_queue;
  2360. for (i = 0; i < hwq_count; i++) {
  2361. qp = &phba->sli4_hba.hdwq[i];
  2362. multixri_pool = qp->p_multixri_pool;
  2363. if (!multixri_pool)
  2364. continue;
  2365. qp->empty_io_bufs = 0;
  2366. multixri_pool->pbl_empty_count = 0;
  2367. #ifdef LPFC_MXP_STAT
  2368. multixri_pool->above_limit_count = 0;
  2369. multixri_pool->below_limit_count = 0;
  2370. multixri_pool->stat_max_hwm = 0;
  2371. multixri_pool->local_pbl_hit_count = 0;
  2372. multixri_pool->other_pbl_hit_count = 0;
  2373. multixri_pool->stat_pbl_count = 0;
  2374. multixri_pool->stat_pvt_count = 0;
  2375. multixri_pool->stat_busy_count = 0;
  2376. multixri_pool->stat_snapshot_taken = 0;
  2377. #endif
  2378. }
  2379. return strlen(pbuf);
  2380. }
  2381. return -EINVAL;
  2382. }
  2383. static int
  2384. lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
  2385. {
  2386. struct lpfc_vport *vport = inode->i_private;
  2387. struct lpfc_debug *debug;
  2388. int rc = -ENOMEM;
  2389. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2390. if (!debug)
  2391. goto out;
  2392. /* Round to page boundary */
  2393. debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
  2394. if (!debug->buffer) {
  2395. kfree(debug);
  2396. goto out;
  2397. }
  2398. debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
  2399. LPFC_NVMESTAT_SIZE);
  2400. debug->i_private = inode->i_private;
  2401. file->private_data = debug;
  2402. rc = 0;
  2403. out:
  2404. return rc;
  2405. }
  2406. static ssize_t
  2407. lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
  2408. size_t nbytes, loff_t *ppos)
  2409. {
  2410. struct lpfc_debug *debug = file->private_data;
  2411. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2412. struct lpfc_hba *phba = vport->phba;
  2413. struct lpfc_nvmet_tgtport *tgtp;
  2414. char mybuf[64];
  2415. char *pbuf;
  2416. if (!phba->targetport)
  2417. return -ENXIO;
  2418. if (nbytes > 64)
  2419. nbytes = 64;
  2420. memset(mybuf, 0, sizeof(mybuf));
  2421. if (copy_from_user(mybuf, buf, nbytes))
  2422. return -EFAULT;
  2423. pbuf = &mybuf[0];
  2424. tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
  2425. if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
  2426. (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
  2427. atomic_set(&tgtp->rcv_ls_req_in, 0);
  2428. atomic_set(&tgtp->rcv_ls_req_out, 0);
  2429. atomic_set(&tgtp->rcv_ls_req_drop, 0);
  2430. atomic_set(&tgtp->xmt_ls_abort, 0);
  2431. atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
  2432. atomic_set(&tgtp->xmt_ls_rsp, 0);
  2433. atomic_set(&tgtp->xmt_ls_drop, 0);
  2434. atomic_set(&tgtp->xmt_ls_rsp_error, 0);
  2435. atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
  2436. atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
  2437. atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
  2438. atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
  2439. atomic_set(&tgtp->xmt_fcp_drop, 0);
  2440. atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
  2441. atomic_set(&tgtp->xmt_fcp_read, 0);
  2442. atomic_set(&tgtp->xmt_fcp_write, 0);
  2443. atomic_set(&tgtp->xmt_fcp_rsp, 0);
  2444. atomic_set(&tgtp->xmt_fcp_release, 0);
  2445. atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
  2446. atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
  2447. atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
  2448. atomic_set(&tgtp->xmt_fcp_abort, 0);
  2449. atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
  2450. atomic_set(&tgtp->xmt_abort_sol, 0);
  2451. atomic_set(&tgtp->xmt_abort_unsol, 0);
  2452. atomic_set(&tgtp->xmt_abort_rsp, 0);
  2453. atomic_set(&tgtp->xmt_abort_rsp_error, 0);
  2454. }
  2455. return nbytes;
  2456. }
  2457. static int
  2458. lpfc_debugfs_scsistat_open(struct inode *inode, struct file *file)
  2459. {
  2460. struct lpfc_vport *vport = inode->i_private;
  2461. struct lpfc_debug *debug;
  2462. int rc = -ENOMEM;
  2463. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2464. if (!debug)
  2465. goto out;
  2466. /* Round to page boundary */
  2467. debug->buffer = kzalloc(LPFC_SCSISTAT_SIZE, GFP_KERNEL);
  2468. if (!debug->buffer) {
  2469. kfree(debug);
  2470. goto out;
  2471. }
  2472. debug->len = lpfc_debugfs_scsistat_data(vport, debug->buffer,
  2473. LPFC_SCSISTAT_SIZE);
  2474. debug->i_private = inode->i_private;
  2475. file->private_data = debug;
  2476. rc = 0;
  2477. out:
  2478. return rc;
  2479. }
  2480. static ssize_t
  2481. lpfc_debugfs_scsistat_write(struct file *file, const char __user *buf,
  2482. size_t nbytes, loff_t *ppos)
  2483. {
  2484. struct lpfc_debug *debug = file->private_data;
  2485. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2486. struct lpfc_hba *phba = vport->phba;
  2487. char mybuf[6] = {0};
  2488. int i;
  2489. /* Protect copy from user */
  2490. if (!access_ok(buf, nbytes))
  2491. return -EFAULT;
  2492. if (copy_from_user(mybuf, buf, (nbytes >= sizeof(mybuf)) ?
  2493. (sizeof(mybuf) - 1) : nbytes))
  2494. return -EFAULT;
  2495. if ((strncmp(&mybuf[0], "reset", strlen("reset")) == 0) ||
  2496. (strncmp(&mybuf[0], "zero", strlen("zero")) == 0)) {
  2497. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  2498. memset(&phba->sli4_hba.hdwq[i].scsi_cstat, 0,
  2499. sizeof(phba->sli4_hba.hdwq[i].scsi_cstat));
  2500. }
  2501. }
  2502. return nbytes;
  2503. }
  2504. static int
  2505. lpfc_debugfs_ioktime_open(struct inode *inode, struct file *file)
  2506. {
  2507. struct lpfc_vport *vport = inode->i_private;
  2508. struct lpfc_debug *debug;
  2509. int rc = -ENOMEM;
  2510. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2511. if (!debug)
  2512. goto out;
  2513. /* Round to page boundary */
  2514. debug->buffer = kmalloc(LPFC_IOKTIME_SIZE, GFP_KERNEL);
  2515. if (!debug->buffer) {
  2516. kfree(debug);
  2517. goto out;
  2518. }
  2519. debug->len = lpfc_debugfs_ioktime_data(vport, debug->buffer,
  2520. LPFC_IOKTIME_SIZE);
  2521. debug->i_private = inode->i_private;
  2522. file->private_data = debug;
  2523. rc = 0;
  2524. out:
  2525. return rc;
  2526. }
  2527. static ssize_t
  2528. lpfc_debugfs_ioktime_write(struct file *file, const char __user *buf,
  2529. size_t nbytes, loff_t *ppos)
  2530. {
  2531. struct lpfc_debug *debug = file->private_data;
  2532. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2533. struct lpfc_hba *phba = vport->phba;
  2534. char mybuf[64];
  2535. char *pbuf;
  2536. if (nbytes > 64)
  2537. nbytes = 64;
  2538. memset(mybuf, 0, sizeof(mybuf));
  2539. if (copy_from_user(mybuf, buf, nbytes))
  2540. return -EFAULT;
  2541. pbuf = &mybuf[0];
  2542. if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  2543. phba->ktime_data_samples = 0;
  2544. phba->ktime_status_samples = 0;
  2545. phba->ktime_seg1_total = 0;
  2546. phba->ktime_seg1_max = 0;
  2547. phba->ktime_seg1_min = 0xffffffff;
  2548. phba->ktime_seg2_total = 0;
  2549. phba->ktime_seg2_max = 0;
  2550. phba->ktime_seg2_min = 0xffffffff;
  2551. phba->ktime_seg3_total = 0;
  2552. phba->ktime_seg3_max = 0;
  2553. phba->ktime_seg3_min = 0xffffffff;
  2554. phba->ktime_seg4_total = 0;
  2555. phba->ktime_seg4_max = 0;
  2556. phba->ktime_seg4_min = 0xffffffff;
  2557. phba->ktime_seg5_total = 0;
  2558. phba->ktime_seg5_max = 0;
  2559. phba->ktime_seg5_min = 0xffffffff;
  2560. phba->ktime_seg6_total = 0;
  2561. phba->ktime_seg6_max = 0;
  2562. phba->ktime_seg6_min = 0xffffffff;
  2563. phba->ktime_seg7_total = 0;
  2564. phba->ktime_seg7_max = 0;
  2565. phba->ktime_seg7_min = 0xffffffff;
  2566. phba->ktime_seg8_total = 0;
  2567. phba->ktime_seg8_max = 0;
  2568. phba->ktime_seg8_min = 0xffffffff;
  2569. phba->ktime_seg9_total = 0;
  2570. phba->ktime_seg9_max = 0;
  2571. phba->ktime_seg9_min = 0xffffffff;
  2572. phba->ktime_seg10_total = 0;
  2573. phba->ktime_seg10_max = 0;
  2574. phba->ktime_seg10_min = 0xffffffff;
  2575. phba->ktime_on = 1;
  2576. return strlen(pbuf);
  2577. } else if ((strncmp(pbuf, "off",
  2578. sizeof("off") - 1) == 0)) {
  2579. phba->ktime_on = 0;
  2580. return strlen(pbuf);
  2581. } else if ((strncmp(pbuf, "zero",
  2582. sizeof("zero") - 1) == 0)) {
  2583. phba->ktime_data_samples = 0;
  2584. phba->ktime_status_samples = 0;
  2585. phba->ktime_seg1_total = 0;
  2586. phba->ktime_seg1_max = 0;
  2587. phba->ktime_seg1_min = 0xffffffff;
  2588. phba->ktime_seg2_total = 0;
  2589. phba->ktime_seg2_max = 0;
  2590. phba->ktime_seg2_min = 0xffffffff;
  2591. phba->ktime_seg3_total = 0;
  2592. phba->ktime_seg3_max = 0;
  2593. phba->ktime_seg3_min = 0xffffffff;
  2594. phba->ktime_seg4_total = 0;
  2595. phba->ktime_seg4_max = 0;
  2596. phba->ktime_seg4_min = 0xffffffff;
  2597. phba->ktime_seg5_total = 0;
  2598. phba->ktime_seg5_max = 0;
  2599. phba->ktime_seg5_min = 0xffffffff;
  2600. phba->ktime_seg6_total = 0;
  2601. phba->ktime_seg6_max = 0;
  2602. phba->ktime_seg6_min = 0xffffffff;
  2603. phba->ktime_seg7_total = 0;
  2604. phba->ktime_seg7_max = 0;
  2605. phba->ktime_seg7_min = 0xffffffff;
  2606. phba->ktime_seg8_total = 0;
  2607. phba->ktime_seg8_max = 0;
  2608. phba->ktime_seg8_min = 0xffffffff;
  2609. phba->ktime_seg9_total = 0;
  2610. phba->ktime_seg9_max = 0;
  2611. phba->ktime_seg9_min = 0xffffffff;
  2612. phba->ktime_seg10_total = 0;
  2613. phba->ktime_seg10_max = 0;
  2614. phba->ktime_seg10_min = 0xffffffff;
  2615. return strlen(pbuf);
  2616. }
  2617. return -EINVAL;
  2618. }
  2619. static int
  2620. lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
  2621. {
  2622. struct lpfc_hba *phba = inode->i_private;
  2623. struct lpfc_debug *debug;
  2624. int rc = -ENOMEM;
  2625. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2626. if (!debug)
  2627. goto out;
  2628. /* Round to page boundary */
  2629. debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
  2630. if (!debug->buffer) {
  2631. kfree(debug);
  2632. goto out;
  2633. }
  2634. debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
  2635. LPFC_NVMEIO_TRC_SIZE);
  2636. debug->i_private = inode->i_private;
  2637. file->private_data = debug;
  2638. rc = 0;
  2639. out:
  2640. return rc;
  2641. }
  2642. static ssize_t
  2643. lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
  2644. size_t nbytes, loff_t *ppos)
  2645. {
  2646. struct lpfc_debug *debug = file->private_data;
  2647. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2648. int i;
  2649. unsigned long sz;
  2650. char mybuf[64];
  2651. char *pbuf;
  2652. if (nbytes > 64)
  2653. nbytes = 64;
  2654. memset(mybuf, 0, sizeof(mybuf));
  2655. if (copy_from_user(mybuf, buf, nbytes))
  2656. return -EFAULT;
  2657. pbuf = &mybuf[0];
  2658. if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
  2659. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2660. "0570 nvmeio_trc_off\n");
  2661. phba->nvmeio_trc_output_idx = 0;
  2662. phba->nvmeio_trc_on = 0;
  2663. return strlen(pbuf);
  2664. } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  2665. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2666. "0571 nvmeio_trc_on\n");
  2667. phba->nvmeio_trc_output_idx = 0;
  2668. phba->nvmeio_trc_on = 1;
  2669. return strlen(pbuf);
  2670. }
  2671. /* We must be off to allocate the trace buffer */
  2672. if (phba->nvmeio_trc_on != 0)
  2673. return -EINVAL;
  2674. /* If not on or off, the parameter is the trace buffer size */
  2675. i = kstrtoul(pbuf, 0, &sz);
  2676. if (i)
  2677. return -EINVAL;
  2678. phba->nvmeio_trc_size = (uint32_t)sz;
  2679. /* It must be a power of 2 - round down */
  2680. i = 0;
  2681. while (sz > 1) {
  2682. sz = sz >> 1;
  2683. i++;
  2684. }
  2685. sz = (1 << i);
  2686. if (phba->nvmeio_trc_size != sz)
  2687. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2688. "0572 nvmeio_trc_size changed to %ld\n",
  2689. sz);
  2690. phba->nvmeio_trc_size = (uint32_t)sz;
  2691. /* If one previously exists, free it */
  2692. kfree(phba->nvmeio_trc);
  2693. /* Allocate new trace buffer and initialize */
  2694. phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
  2695. sz), GFP_KERNEL);
  2696. if (!phba->nvmeio_trc) {
  2697. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2698. "0573 Cannot create debugfs "
  2699. "nvmeio_trc buffer\n");
  2700. return -ENOMEM;
  2701. }
  2702. atomic_set(&phba->nvmeio_trc_cnt, 0);
  2703. phba->nvmeio_trc_on = 0;
  2704. phba->nvmeio_trc_output_idx = 0;
  2705. return strlen(pbuf);
  2706. }
  2707. static int
  2708. lpfc_debugfs_hdwqstat_open(struct inode *inode, struct file *file)
  2709. {
  2710. struct lpfc_vport *vport = inode->i_private;
  2711. struct lpfc_debug *debug;
  2712. int rc = -ENOMEM;
  2713. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2714. if (!debug)
  2715. goto out;
  2716. /* Round to page boundary */
  2717. debug->buffer = kcalloc(1, LPFC_SCSISTAT_SIZE, GFP_KERNEL);
  2718. if (!debug->buffer) {
  2719. kfree(debug);
  2720. goto out;
  2721. }
  2722. debug->len = lpfc_debugfs_hdwqstat_data(vport, debug->buffer,
  2723. LPFC_SCSISTAT_SIZE);
  2724. debug->i_private = inode->i_private;
  2725. file->private_data = debug;
  2726. rc = 0;
  2727. out:
  2728. return rc;
  2729. }
  2730. static ssize_t
  2731. lpfc_debugfs_hdwqstat_write(struct file *file, const char __user *buf,
  2732. size_t nbytes, loff_t *ppos)
  2733. {
  2734. struct lpfc_debug *debug = file->private_data;
  2735. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2736. struct lpfc_hba *phba = vport->phba;
  2737. struct lpfc_hdwq_stat *c_stat;
  2738. char mybuf[64];
  2739. char *pbuf;
  2740. int i;
  2741. if (nbytes > 64)
  2742. nbytes = 64;
  2743. memset(mybuf, 0, sizeof(mybuf));
  2744. if (copy_from_user(mybuf, buf, nbytes))
  2745. return -EFAULT;
  2746. pbuf = &mybuf[0];
  2747. if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  2748. if (phba->nvmet_support)
  2749. phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
  2750. else
  2751. phba->hdwqstat_on |= (LPFC_CHECK_NVME_IO |
  2752. LPFC_CHECK_SCSI_IO);
  2753. return strlen(pbuf);
  2754. } else if ((strncmp(pbuf, "nvme_on", sizeof("nvme_on") - 1) == 0)) {
  2755. if (phba->nvmet_support)
  2756. phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
  2757. else
  2758. phba->hdwqstat_on |= LPFC_CHECK_NVME_IO;
  2759. return strlen(pbuf);
  2760. } else if ((strncmp(pbuf, "scsi_on", sizeof("scsi_on") - 1) == 0)) {
  2761. if (!phba->nvmet_support)
  2762. phba->hdwqstat_on |= LPFC_CHECK_SCSI_IO;
  2763. return strlen(pbuf);
  2764. } else if ((strncmp(pbuf, "nvme_off", sizeof("nvme_off") - 1) == 0)) {
  2765. phba->hdwqstat_on &= ~(LPFC_CHECK_NVME_IO |
  2766. LPFC_CHECK_NVMET_IO);
  2767. return strlen(pbuf);
  2768. } else if ((strncmp(pbuf, "scsi_off", sizeof("scsi_off") - 1) == 0)) {
  2769. phba->hdwqstat_on &= ~LPFC_CHECK_SCSI_IO;
  2770. return strlen(pbuf);
  2771. } else if ((strncmp(pbuf, "off",
  2772. sizeof("off") - 1) == 0)) {
  2773. phba->hdwqstat_on = LPFC_CHECK_OFF;
  2774. return strlen(pbuf);
  2775. } else if ((strncmp(pbuf, "zero",
  2776. sizeof("zero") - 1) == 0)) {
  2777. for_each_present_cpu(i) {
  2778. c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, i);
  2779. c_stat->xmt_io = 0;
  2780. c_stat->cmpl_io = 0;
  2781. c_stat->rcv_io = 0;
  2782. }
  2783. return strlen(pbuf);
  2784. }
  2785. return -EINVAL;
  2786. }
  2787. /*
  2788. * ---------------------------------
  2789. * iDiag debugfs file access methods
  2790. * ---------------------------------
  2791. *
  2792. * All access methods are through the proper SLI4 PCI function's debugfs
  2793. * iDiag directory:
  2794. *
  2795. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  2796. */
  2797. /**
  2798. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  2799. * @buf: The pointer to the user space buffer.
  2800. * @nbytes: The number of bytes in the user space buffer.
  2801. * @idiag_cmd: pointer to the idiag command struct.
  2802. *
  2803. * This routine reads data from debugfs user space buffer and parses the
  2804. * buffer for getting the idiag command and arguments. The while space in
  2805. * between the set of data is used as the parsing separator.
  2806. *
  2807. * This routine returns 0 when successful, it returns proper error code
  2808. * back to the user space in error conditions.
  2809. */
  2810. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  2811. struct lpfc_idiag_cmd *idiag_cmd)
  2812. {
  2813. char mybuf[64];
  2814. char *pbuf, *step_str;
  2815. int i;
  2816. size_t bsize;
  2817. memset(mybuf, 0, sizeof(mybuf));
  2818. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  2819. bsize = min(nbytes, (sizeof(mybuf)-1));
  2820. if (copy_from_user(mybuf, buf, bsize))
  2821. return -EFAULT;
  2822. pbuf = &mybuf[0];
  2823. step_str = strsep(&pbuf, "\t ");
  2824. /* The opcode must present */
  2825. if (!step_str)
  2826. return -EINVAL;
  2827. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  2828. if (idiag_cmd->opcode == 0)
  2829. return -EINVAL;
  2830. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  2831. step_str = strsep(&pbuf, "\t ");
  2832. if (!step_str)
  2833. return i;
  2834. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  2835. }
  2836. return i;
  2837. }
  2838. /**
  2839. * lpfc_idiag_open - idiag open debugfs
  2840. * @inode: The inode pointer that contains a pointer to phba.
  2841. * @file: The file pointer to attach the file operation.
  2842. *
  2843. * Description:
  2844. * This routine is the entry point for the debugfs open file operation. It
  2845. * gets the reference to phba from the i_private field in @inode, it then
  2846. * allocates buffer for the file operation, performs the necessary PCI config
  2847. * space read into the allocated buffer according to the idiag user command
  2848. * setup, and then returns a pointer to buffer in the private_data field in
  2849. * @file.
  2850. *
  2851. * Returns:
  2852. * This function returns zero if successful. On error it will return an
  2853. * negative error value.
  2854. **/
  2855. static int
  2856. lpfc_idiag_open(struct inode *inode, struct file *file)
  2857. {
  2858. struct lpfc_debug *debug;
  2859. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2860. if (!debug)
  2861. return -ENOMEM;
  2862. debug->i_private = inode->i_private;
  2863. debug->buffer = NULL;
  2864. file->private_data = debug;
  2865. return 0;
  2866. }
  2867. /**
  2868. * lpfc_idiag_release - Release idiag access file operation
  2869. * @inode: The inode pointer that contains a vport pointer. (unused)
  2870. * @file: The file pointer that contains the buffer to release.
  2871. *
  2872. * Description:
  2873. * This routine is the generic release routine for the idiag access file
  2874. * operation, it frees the buffer that was allocated when the debugfs file
  2875. * was opened.
  2876. *
  2877. * Returns:
  2878. * This function returns zero.
  2879. **/
  2880. static int
  2881. lpfc_idiag_release(struct inode *inode, struct file *file)
  2882. {
  2883. struct lpfc_debug *debug = file->private_data;
  2884. /* Free the buffers to the file operation */
  2885. kfree(debug->buffer);
  2886. kfree(debug);
  2887. return 0;
  2888. }
  2889. /**
  2890. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  2891. * @inode: The inode pointer that contains a vport pointer. (unused)
  2892. * @file: The file pointer that contains the buffer to release.
  2893. *
  2894. * Description:
  2895. * This routine frees the buffer that was allocated when the debugfs file
  2896. * was opened. It also reset the fields in the idiag command struct in the
  2897. * case of command for write operation.
  2898. *
  2899. * Returns:
  2900. * This function returns zero.
  2901. **/
  2902. static int
  2903. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  2904. {
  2905. struct lpfc_debug *debug = file->private_data;
  2906. if (debug->op == LPFC_IDIAG_OP_WR) {
  2907. switch (idiag.cmd.opcode) {
  2908. case LPFC_IDIAG_CMD_PCICFG_WR:
  2909. case LPFC_IDIAG_CMD_PCICFG_ST:
  2910. case LPFC_IDIAG_CMD_PCICFG_CL:
  2911. case LPFC_IDIAG_CMD_QUEACC_WR:
  2912. case LPFC_IDIAG_CMD_QUEACC_ST:
  2913. case LPFC_IDIAG_CMD_QUEACC_CL:
  2914. memset(&idiag, 0, sizeof(idiag));
  2915. break;
  2916. default:
  2917. break;
  2918. }
  2919. }
  2920. /* Free the buffers to the file operation */
  2921. kfree(debug->buffer);
  2922. kfree(debug);
  2923. return 0;
  2924. }
  2925. /**
  2926. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  2927. * @file: The file pointer to read from.
  2928. * @buf: The buffer to copy the data to.
  2929. * @nbytes: The number of bytes to read.
  2930. * @ppos: The position in the file to start reading from.
  2931. *
  2932. * Description:
  2933. * This routine reads data from the @phba pci config space according to the
  2934. * idiag command, and copies to user @buf. Depending on the PCI config space
  2935. * read command setup, it does either a single register read of a byte
  2936. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  2937. * registers from the 4K extended PCI config space.
  2938. *
  2939. * Returns:
  2940. * This function returns the amount of data that was read (this could be less
  2941. * than @nbytes if the end of the file was reached) or a negative error value.
  2942. **/
  2943. static ssize_t
  2944. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  2945. loff_t *ppos)
  2946. {
  2947. struct lpfc_debug *debug = file->private_data;
  2948. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2949. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  2950. int where, count;
  2951. char *pbuffer;
  2952. struct pci_dev *pdev;
  2953. uint32_t u32val;
  2954. uint16_t u16val;
  2955. uint8_t u8val;
  2956. pdev = phba->pcidev;
  2957. if (!pdev)
  2958. return 0;
  2959. /* This is a user read operation */
  2960. debug->op = LPFC_IDIAG_OP_RD;
  2961. if (!debug->buffer)
  2962. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  2963. if (!debug->buffer)
  2964. return 0;
  2965. pbuffer = debug->buffer;
  2966. if (*ppos)
  2967. return 0;
  2968. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  2969. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  2970. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  2971. } else
  2972. return 0;
  2973. /* Read single PCI config space register */
  2974. switch (count) {
  2975. case SIZE_U8: /* byte (8 bits) */
  2976. pci_read_config_byte(pdev, where, &u8val);
  2977. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2978. "%03x: %02x\n", where, u8val);
  2979. break;
  2980. case SIZE_U16: /* word (16 bits) */
  2981. pci_read_config_word(pdev, where, &u16val);
  2982. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2983. "%03x: %04x\n", where, u16val);
  2984. break;
  2985. case SIZE_U32: /* double word (32 bits) */
  2986. pci_read_config_dword(pdev, where, &u32val);
  2987. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2988. "%03x: %08x\n", where, u32val);
  2989. break;
  2990. case LPFC_PCI_CFG_BROWSE: /* browse all */
  2991. goto pcicfg_browse;
  2992. break;
  2993. default:
  2994. /* illegal count */
  2995. len = 0;
  2996. break;
  2997. }
  2998. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2999. pcicfg_browse:
  3000. /* Browse all PCI config space registers */
  3001. offset_label = idiag.offset.last_rd;
  3002. offset = offset_label;
  3003. /* Read PCI config space */
  3004. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  3005. "%03x: ", offset_label);
  3006. while (index > 0) {
  3007. pci_read_config_dword(pdev, offset, &u32val);
  3008. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  3009. "%08x ", u32val);
  3010. offset += sizeof(uint32_t);
  3011. if (offset >= LPFC_PCI_CFG_SIZE) {
  3012. len += scnprintf(pbuffer+len,
  3013. LPFC_PCI_CFG_SIZE-len, "\n");
  3014. break;
  3015. }
  3016. index -= sizeof(uint32_t);
  3017. if (!index)
  3018. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  3019. "\n");
  3020. else if (!(index % (8 * sizeof(uint32_t)))) {
  3021. offset_label += (8 * sizeof(uint32_t));
  3022. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  3023. "\n%03x: ", offset_label);
  3024. }
  3025. }
  3026. /* Set up the offset for next portion of pci cfg read */
  3027. if (index == 0) {
  3028. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  3029. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  3030. idiag.offset.last_rd = 0;
  3031. } else
  3032. idiag.offset.last_rd = 0;
  3033. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3034. }
  3035. /**
  3036. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  3037. * @file: The file pointer to read from.
  3038. * @buf: The buffer to copy the user data from.
  3039. * @nbytes: The number of bytes to get.
  3040. * @ppos: The position in the file to start reading from.
  3041. *
  3042. * This routine get the debugfs idiag command struct from user space and
  3043. * then perform the syntax check for PCI config space read or write command
  3044. * accordingly. In the case of PCI config space read command, it sets up
  3045. * the command in the idiag command struct for the debugfs read operation.
  3046. * In the case of PCI config space write operation, it executes the write
  3047. * operation into the PCI config space accordingly.
  3048. *
  3049. * It returns the @nbytges passing in from debugfs user space when successful.
  3050. * In case of error conditions, it returns proper error code back to the user
  3051. * space.
  3052. */
  3053. static ssize_t
  3054. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  3055. size_t nbytes, loff_t *ppos)
  3056. {
  3057. struct lpfc_debug *debug = file->private_data;
  3058. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3059. uint32_t where, value, count;
  3060. uint32_t u32val;
  3061. uint16_t u16val;
  3062. uint8_t u8val;
  3063. struct pci_dev *pdev;
  3064. int rc;
  3065. pdev = phba->pcidev;
  3066. if (!pdev)
  3067. return -EFAULT;
  3068. /* This is a user write operation */
  3069. debug->op = LPFC_IDIAG_OP_WR;
  3070. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3071. if (rc < 0)
  3072. return rc;
  3073. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  3074. /* Sanity check on PCI config read command line arguments */
  3075. if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
  3076. goto error_out;
  3077. /* Read command from PCI config space, set up command fields */
  3078. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  3079. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  3080. if (count == LPFC_PCI_CFG_BROWSE) {
  3081. if (where % sizeof(uint32_t))
  3082. goto error_out;
  3083. /* Starting offset to browse */
  3084. idiag.offset.last_rd = where;
  3085. } else if ((count != sizeof(uint8_t)) &&
  3086. (count != sizeof(uint16_t)) &&
  3087. (count != sizeof(uint32_t)))
  3088. goto error_out;
  3089. if (count == sizeof(uint8_t)) {
  3090. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  3091. goto error_out;
  3092. if (where % sizeof(uint8_t))
  3093. goto error_out;
  3094. }
  3095. if (count == sizeof(uint16_t)) {
  3096. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  3097. goto error_out;
  3098. if (where % sizeof(uint16_t))
  3099. goto error_out;
  3100. }
  3101. if (count == sizeof(uint32_t)) {
  3102. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  3103. goto error_out;
  3104. if (where % sizeof(uint32_t))
  3105. goto error_out;
  3106. }
  3107. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  3108. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  3109. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  3110. /* Sanity check on PCI config write command line arguments */
  3111. if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
  3112. goto error_out;
  3113. /* Write command to PCI config space, read-modify-write */
  3114. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  3115. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  3116. value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
  3117. /* Sanity checks */
  3118. if ((count != sizeof(uint8_t)) &&
  3119. (count != sizeof(uint16_t)) &&
  3120. (count != sizeof(uint32_t)))
  3121. goto error_out;
  3122. if (count == sizeof(uint8_t)) {
  3123. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  3124. goto error_out;
  3125. if (where % sizeof(uint8_t))
  3126. goto error_out;
  3127. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  3128. pci_write_config_byte(pdev, where,
  3129. (uint8_t)value);
  3130. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  3131. rc = pci_read_config_byte(pdev, where, &u8val);
  3132. if (!rc) {
  3133. u8val |= (uint8_t)value;
  3134. pci_write_config_byte(pdev, where,
  3135. u8val);
  3136. }
  3137. }
  3138. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  3139. rc = pci_read_config_byte(pdev, where, &u8val);
  3140. if (!rc) {
  3141. u8val &= (uint8_t)(~value);
  3142. pci_write_config_byte(pdev, where,
  3143. u8val);
  3144. }
  3145. }
  3146. }
  3147. if (count == sizeof(uint16_t)) {
  3148. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  3149. goto error_out;
  3150. if (where % sizeof(uint16_t))
  3151. goto error_out;
  3152. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  3153. pci_write_config_word(pdev, where,
  3154. (uint16_t)value);
  3155. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  3156. rc = pci_read_config_word(pdev, where, &u16val);
  3157. if (!rc) {
  3158. u16val |= (uint16_t)value;
  3159. pci_write_config_word(pdev, where,
  3160. u16val);
  3161. }
  3162. }
  3163. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  3164. rc = pci_read_config_word(pdev, where, &u16val);
  3165. if (!rc) {
  3166. u16val &= (uint16_t)(~value);
  3167. pci_write_config_word(pdev, where,
  3168. u16val);
  3169. }
  3170. }
  3171. }
  3172. if (count == sizeof(uint32_t)) {
  3173. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  3174. goto error_out;
  3175. if (where % sizeof(uint32_t))
  3176. goto error_out;
  3177. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  3178. pci_write_config_dword(pdev, where, value);
  3179. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  3180. rc = pci_read_config_dword(pdev, where,
  3181. &u32val);
  3182. if (!rc) {
  3183. u32val |= value;
  3184. pci_write_config_dword(pdev, where,
  3185. u32val);
  3186. }
  3187. }
  3188. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  3189. rc = pci_read_config_dword(pdev, where,
  3190. &u32val);
  3191. if (!rc) {
  3192. u32val &= ~value;
  3193. pci_write_config_dword(pdev, where,
  3194. u32val);
  3195. }
  3196. }
  3197. }
  3198. } else
  3199. /* All other opecodes are illegal for now */
  3200. goto error_out;
  3201. return nbytes;
  3202. error_out:
  3203. memset(&idiag, 0, sizeof(idiag));
  3204. return -EINVAL;
  3205. }
  3206. /**
  3207. * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
  3208. * @file: The file pointer to read from.
  3209. * @buf: The buffer to copy the data to.
  3210. * @nbytes: The number of bytes to read.
  3211. * @ppos: The position in the file to start reading from.
  3212. *
  3213. * Description:
  3214. * This routine reads data from the @phba pci bar memory mapped space
  3215. * according to the idiag command, and copies to user @buf.
  3216. *
  3217. * Returns:
  3218. * This function returns the amount of data that was read (this could be less
  3219. * than @nbytes if the end of the file was reached) or a negative error value.
  3220. **/
  3221. static ssize_t
  3222. lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
  3223. loff_t *ppos)
  3224. {
  3225. struct lpfc_debug *debug = file->private_data;
  3226. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3227. int offset_label, offset, offset_run, len = 0, index;
  3228. int bar_num, acc_range, bar_size;
  3229. char *pbuffer;
  3230. void __iomem *mem_mapped_bar;
  3231. uint32_t if_type;
  3232. struct pci_dev *pdev;
  3233. uint32_t u32val;
  3234. pdev = phba->pcidev;
  3235. if (!pdev)
  3236. return 0;
  3237. /* This is a user read operation */
  3238. debug->op = LPFC_IDIAG_OP_RD;
  3239. if (!debug->buffer)
  3240. debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
  3241. if (!debug->buffer)
  3242. return 0;
  3243. pbuffer = debug->buffer;
  3244. if (*ppos)
  3245. return 0;
  3246. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  3247. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  3248. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  3249. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  3250. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  3251. } else
  3252. return 0;
  3253. if (acc_range == 0)
  3254. return 0;
  3255. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  3256. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  3257. if (bar_num == IDIAG_BARACC_BAR_0)
  3258. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  3259. else if (bar_num == IDIAG_BARACC_BAR_1)
  3260. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  3261. else if (bar_num == IDIAG_BARACC_BAR_2)
  3262. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  3263. else
  3264. return 0;
  3265. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  3266. if (bar_num == IDIAG_BARACC_BAR_0)
  3267. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  3268. else
  3269. return 0;
  3270. } else
  3271. return 0;
  3272. /* Read single PCI bar space register */
  3273. if (acc_range == SINGLE_WORD) {
  3274. offset_run = offset;
  3275. u32val = readl(mem_mapped_bar + offset_run);
  3276. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  3277. "%05x: %08x\n", offset_run, u32val);
  3278. } else
  3279. goto baracc_browse;
  3280. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3281. baracc_browse:
  3282. /* Browse all PCI bar space registers */
  3283. offset_label = idiag.offset.last_rd;
  3284. offset_run = offset_label;
  3285. /* Read PCI bar memory mapped space */
  3286. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  3287. "%05x: ", offset_label);
  3288. index = LPFC_PCI_BAR_RD_SIZE;
  3289. while (index > 0) {
  3290. u32val = readl(mem_mapped_bar + offset_run);
  3291. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  3292. "%08x ", u32val);
  3293. offset_run += sizeof(uint32_t);
  3294. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  3295. if (offset_run >= bar_size) {
  3296. len += scnprintf(pbuffer+len,
  3297. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  3298. break;
  3299. }
  3300. } else {
  3301. if (offset_run >= offset +
  3302. (acc_range * sizeof(uint32_t))) {
  3303. len += scnprintf(pbuffer+len,
  3304. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  3305. break;
  3306. }
  3307. }
  3308. index -= sizeof(uint32_t);
  3309. if (!index)
  3310. len += scnprintf(pbuffer+len,
  3311. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  3312. else if (!(index % (8 * sizeof(uint32_t)))) {
  3313. offset_label += (8 * sizeof(uint32_t));
  3314. len += scnprintf(pbuffer+len,
  3315. LPFC_PCI_BAR_RD_BUF_SIZE-len,
  3316. "\n%05x: ", offset_label);
  3317. }
  3318. }
  3319. /* Set up the offset for next portion of pci bar read */
  3320. if (index == 0) {
  3321. idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
  3322. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  3323. if (idiag.offset.last_rd >= bar_size)
  3324. idiag.offset.last_rd = 0;
  3325. } else {
  3326. if (offset_run >= offset +
  3327. (acc_range * sizeof(uint32_t)))
  3328. idiag.offset.last_rd = offset;
  3329. }
  3330. } else {
  3331. if (acc_range == LPFC_PCI_BAR_BROWSE)
  3332. idiag.offset.last_rd = 0;
  3333. else
  3334. idiag.offset.last_rd = offset;
  3335. }
  3336. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3337. }
  3338. /**
  3339. * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
  3340. * @file: The file pointer to read from.
  3341. * @buf: The buffer to copy the user data from.
  3342. * @nbytes: The number of bytes to get.
  3343. * @ppos: The position in the file to start reading from.
  3344. *
  3345. * This routine get the debugfs idiag command struct from user space and
  3346. * then perform the syntax check for PCI bar memory mapped space read or
  3347. * write command accordingly. In the case of PCI bar memory mapped space
  3348. * read command, it sets up the command in the idiag command struct for
  3349. * the debugfs read operation. In the case of PCI bar memorpy mapped space
  3350. * write operation, it executes the write operation into the PCI bar memory
  3351. * mapped space accordingly.
  3352. *
  3353. * It returns the @nbytges passing in from debugfs user space when successful.
  3354. * In case of error conditions, it returns proper error code back to the user
  3355. * space.
  3356. */
  3357. static ssize_t
  3358. lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
  3359. size_t nbytes, loff_t *ppos)
  3360. {
  3361. struct lpfc_debug *debug = file->private_data;
  3362. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3363. uint32_t bar_num, bar_size, offset, value, acc_range;
  3364. struct pci_dev *pdev;
  3365. void __iomem *mem_mapped_bar;
  3366. uint32_t if_type;
  3367. uint32_t u32val;
  3368. int rc;
  3369. pdev = phba->pcidev;
  3370. if (!pdev)
  3371. return -EFAULT;
  3372. /* This is a user write operation */
  3373. debug->op = LPFC_IDIAG_OP_WR;
  3374. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3375. if (rc < 0)
  3376. return rc;
  3377. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  3378. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  3379. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  3380. if ((bar_num != IDIAG_BARACC_BAR_0) &&
  3381. (bar_num != IDIAG_BARACC_BAR_1) &&
  3382. (bar_num != IDIAG_BARACC_BAR_2))
  3383. goto error_out;
  3384. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  3385. if (bar_num != IDIAG_BARACC_BAR_0)
  3386. goto error_out;
  3387. } else
  3388. goto error_out;
  3389. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  3390. if (bar_num == IDIAG_BARACC_BAR_0) {
  3391. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  3392. LPFC_PCI_IF0_BAR0_SIZE;
  3393. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  3394. } else if (bar_num == IDIAG_BARACC_BAR_1) {
  3395. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  3396. LPFC_PCI_IF0_BAR1_SIZE;
  3397. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  3398. } else if (bar_num == IDIAG_BARACC_BAR_2) {
  3399. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  3400. LPFC_PCI_IF0_BAR2_SIZE;
  3401. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  3402. } else
  3403. goto error_out;
  3404. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  3405. if (bar_num == IDIAG_BARACC_BAR_0) {
  3406. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  3407. LPFC_PCI_IF2_BAR0_SIZE;
  3408. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  3409. } else
  3410. goto error_out;
  3411. } else
  3412. goto error_out;
  3413. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  3414. if (offset % sizeof(uint32_t))
  3415. goto error_out;
  3416. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  3417. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  3418. /* Sanity check on PCI config read command line arguments */
  3419. if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
  3420. goto error_out;
  3421. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  3422. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  3423. if (offset > bar_size - sizeof(uint32_t))
  3424. goto error_out;
  3425. /* Starting offset to browse */
  3426. idiag.offset.last_rd = offset;
  3427. } else if (acc_range > SINGLE_WORD) {
  3428. if (offset + acc_range * sizeof(uint32_t) > bar_size)
  3429. goto error_out;
  3430. /* Starting offset to browse */
  3431. idiag.offset.last_rd = offset;
  3432. } else if (acc_range != SINGLE_WORD)
  3433. goto error_out;
  3434. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
  3435. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
  3436. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  3437. /* Sanity check on PCI bar write command line arguments */
  3438. if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
  3439. goto error_out;
  3440. /* Write command to PCI bar space, read-modify-write */
  3441. acc_range = SINGLE_WORD;
  3442. value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
  3443. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
  3444. writel(value, mem_mapped_bar + offset);
  3445. readl(mem_mapped_bar + offset);
  3446. }
  3447. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
  3448. u32val = readl(mem_mapped_bar + offset);
  3449. u32val |= value;
  3450. writel(u32val, mem_mapped_bar + offset);
  3451. readl(mem_mapped_bar + offset);
  3452. }
  3453. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  3454. u32val = readl(mem_mapped_bar + offset);
  3455. u32val &= ~value;
  3456. writel(u32val, mem_mapped_bar + offset);
  3457. readl(mem_mapped_bar + offset);
  3458. }
  3459. } else
  3460. /* All other opecodes are illegal for now */
  3461. goto error_out;
  3462. return nbytes;
  3463. error_out:
  3464. memset(&idiag, 0, sizeof(idiag));
  3465. return -EINVAL;
  3466. }
  3467. static int
  3468. __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
  3469. char *pbuffer, int len)
  3470. {
  3471. if (!qp)
  3472. return len;
  3473. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3474. "\t\t%s WQ info: ", wqtype);
  3475. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3476. "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
  3477. qp->assoc_qid, qp->q_cnt_1,
  3478. (unsigned long long)qp->q_cnt_4);
  3479. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3480. "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3481. "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]",
  3482. qp->queue_id, qp->entry_count,
  3483. qp->entry_size, qp->host_index,
  3484. qp->hba_index, qp->notify_interval);
  3485. len += scnprintf(pbuffer + len,
  3486. LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
  3487. return len;
  3488. }
  3489. static int
  3490. lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
  3491. int *len, int max_cnt, int cq_id)
  3492. {
  3493. struct lpfc_queue *qp;
  3494. int qidx;
  3495. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  3496. qp = phba->sli4_hba.hdwq[qidx].io_wq;
  3497. if (qp->assoc_qid != cq_id)
  3498. continue;
  3499. *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
  3500. if (*len >= max_cnt)
  3501. return 1;
  3502. }
  3503. return 0;
  3504. }
  3505. static int
  3506. __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
  3507. char *pbuffer, int len)
  3508. {
  3509. if (!qp)
  3510. return len;
  3511. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3512. "\t%s CQ info: ", cqtype);
  3513. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3514. "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
  3515. "xabt:x%x wq:x%llx]\n",
  3516. qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
  3517. qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
  3518. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3519. "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3520. "HST-IDX[%04d], NTFI[%03d], PLMT[%03d]",
  3521. qp->queue_id, qp->entry_count,
  3522. qp->entry_size, qp->host_index,
  3523. qp->notify_interval, qp->max_proc_limit);
  3524. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3525. "\n");
  3526. return len;
  3527. }
  3528. static int
  3529. __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
  3530. char *rqtype, char *pbuffer, int len)
  3531. {
  3532. if (!qp || !datqp)
  3533. return len;
  3534. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3535. "\t\t%s RQ info: ", rqtype);
  3536. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3537. "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
  3538. "posted:x%x rcv:x%llx]\n",
  3539. qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
  3540. qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
  3541. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3542. "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3543. "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
  3544. qp->queue_id, qp->entry_count, qp->entry_size,
  3545. qp->host_index, qp->hba_index, qp->notify_interval);
  3546. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3547. "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3548. "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
  3549. datqp->queue_id, datqp->entry_count,
  3550. datqp->entry_size, datqp->host_index,
  3551. datqp->hba_index, datqp->notify_interval);
  3552. return len;
  3553. }
  3554. static int
  3555. lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
  3556. int *len, int max_cnt, int eqidx, int eq_id)
  3557. {
  3558. struct lpfc_queue *qp;
  3559. int rc;
  3560. qp = phba->sli4_hba.hdwq[eqidx].io_cq;
  3561. *len = __lpfc_idiag_print_cq(qp, "IO", pbuffer, *len);
  3562. /* Reset max counter */
  3563. qp->CQ_max_cqe = 0;
  3564. if (*len >= max_cnt)
  3565. return 1;
  3566. rc = lpfc_idiag_wqs_for_cq(phba, "IO", pbuffer, len,
  3567. max_cnt, qp->queue_id);
  3568. if (rc)
  3569. return 1;
  3570. if ((eqidx < phba->cfg_nvmet_mrq) && phba->nvmet_support) {
  3571. /* NVMET CQset */
  3572. qp = phba->sli4_hba.nvmet_cqset[eqidx];
  3573. *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
  3574. /* Reset max counter */
  3575. qp->CQ_max_cqe = 0;
  3576. if (*len >= max_cnt)
  3577. return 1;
  3578. /* RQ header */
  3579. qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
  3580. *len = __lpfc_idiag_print_rqpair(qp,
  3581. phba->sli4_hba.nvmet_mrq_data[eqidx],
  3582. "NVMET MRQ", pbuffer, *len);
  3583. if (*len >= max_cnt)
  3584. return 1;
  3585. }
  3586. return 0;
  3587. }
  3588. static int
  3589. __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
  3590. char *pbuffer, int len)
  3591. {
  3592. if (!qp)
  3593. return len;
  3594. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3595. "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
  3596. "cqe_proc:x%x eqe_proc:x%llx eqd %d]\n",
  3597. eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
  3598. (unsigned long long)qp->q_cnt_4, qp->q_mode);
  3599. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3600. "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3601. "HST-IDX[%04d], NTFI[%03d], PLMT[%03d], AFFIN[%03d]",
  3602. qp->queue_id, qp->entry_count, qp->entry_size,
  3603. qp->host_index, qp->notify_interval,
  3604. qp->max_proc_limit, qp->chann);
  3605. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3606. "\n");
  3607. return len;
  3608. }
  3609. /**
  3610. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  3611. * @file: The file pointer to read from.
  3612. * @buf: The buffer to copy the data to.
  3613. * @nbytes: The number of bytes to read.
  3614. * @ppos: The position in the file to start reading from.
  3615. *
  3616. * Description:
  3617. * This routine reads data from the @phba SLI4 PCI function queue information,
  3618. * and copies to user @buf.
  3619. * This routine only returns 1 EQs worth of information. It remembers the last
  3620. * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
  3621. * retrieve all EQs allocated for the phba.
  3622. *
  3623. * Returns:
  3624. * This function returns the amount of data that was read (this could be less
  3625. * than @nbytes if the end of the file was reached) or a negative error value.
  3626. **/
  3627. static ssize_t
  3628. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  3629. loff_t *ppos)
  3630. {
  3631. struct lpfc_debug *debug = file->private_data;
  3632. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3633. char *pbuffer;
  3634. int max_cnt, rc, x, len = 0;
  3635. struct lpfc_queue *qp = NULL;
  3636. if (!debug->buffer)
  3637. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  3638. if (!debug->buffer)
  3639. return 0;
  3640. pbuffer = debug->buffer;
  3641. max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
  3642. if (*ppos)
  3643. return 0;
  3644. spin_lock_irq(&phba->hbalock);
  3645. /* Fast-path event queue */
  3646. if (phba->sli4_hba.hdwq && phba->cfg_hdw_queue) {
  3647. x = phba->lpfc_idiag_last_eq;
  3648. phba->lpfc_idiag_last_eq++;
  3649. if (phba->lpfc_idiag_last_eq >= phba->cfg_hdw_queue)
  3650. phba->lpfc_idiag_last_eq = 0;
  3651. len += scnprintf(pbuffer + len,
  3652. LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3653. "HDWQ %d out of %d HBA HDWQs\n",
  3654. x, phba->cfg_hdw_queue);
  3655. /* Fast-path EQ */
  3656. qp = phba->sli4_hba.hdwq[x].hba_eq;
  3657. if (!qp)
  3658. goto out;
  3659. len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
  3660. /* Reset max counter */
  3661. qp->EQ_max_eqe = 0;
  3662. if (len >= max_cnt)
  3663. goto too_big;
  3664. /* will dump both fcp and nvme cqs/wqs for the eq */
  3665. rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
  3666. max_cnt, x, qp->queue_id);
  3667. if (rc)
  3668. goto too_big;
  3669. /* Only EQ 0 has slow path CQs configured */
  3670. if (x)
  3671. goto out;
  3672. /* Slow-path mailbox CQ */
  3673. qp = phba->sli4_hba.mbx_cq;
  3674. len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
  3675. if (len >= max_cnt)
  3676. goto too_big;
  3677. /* Slow-path MBOX MQ */
  3678. qp = phba->sli4_hba.mbx_wq;
  3679. len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
  3680. if (len >= max_cnt)
  3681. goto too_big;
  3682. /* Slow-path ELS response CQ */
  3683. qp = phba->sli4_hba.els_cq;
  3684. len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
  3685. /* Reset max counter */
  3686. if (qp)
  3687. qp->CQ_max_cqe = 0;
  3688. if (len >= max_cnt)
  3689. goto too_big;
  3690. /* Slow-path ELS WQ */
  3691. qp = phba->sli4_hba.els_wq;
  3692. len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
  3693. if (len >= max_cnt)
  3694. goto too_big;
  3695. qp = phba->sli4_hba.hdr_rq;
  3696. len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
  3697. "ELS RQpair", pbuffer, len);
  3698. if (len >= max_cnt)
  3699. goto too_big;
  3700. /* Slow-path NVME LS response CQ */
  3701. qp = phba->sli4_hba.nvmels_cq;
  3702. len = __lpfc_idiag_print_cq(qp, "NVME LS",
  3703. pbuffer, len);
  3704. /* Reset max counter */
  3705. if (qp)
  3706. qp->CQ_max_cqe = 0;
  3707. if (len >= max_cnt)
  3708. goto too_big;
  3709. /* Slow-path NVME LS WQ */
  3710. qp = phba->sli4_hba.nvmels_wq;
  3711. len = __lpfc_idiag_print_wq(qp, "NVME LS",
  3712. pbuffer, len);
  3713. if (len >= max_cnt)
  3714. goto too_big;
  3715. goto out;
  3716. }
  3717. spin_unlock_irq(&phba->hbalock);
  3718. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3719. too_big:
  3720. len += scnprintf(pbuffer + len,
  3721. LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
  3722. out:
  3723. spin_unlock_irq(&phba->hbalock);
  3724. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3725. }
  3726. /**
  3727. * lpfc_idiag_que_param_check - queue access command parameter sanity check
  3728. * @q: The pointer to queue structure.
  3729. * @index: The index into a queue entry.
  3730. * @count: The number of queue entries to access.
  3731. *
  3732. * Description:
  3733. * The routine performs sanity check on device queue access method commands.
  3734. *
  3735. * Returns:
  3736. * This function returns -EINVAL when fails the sanity check, otherwise, it
  3737. * returns 0.
  3738. **/
  3739. static int
  3740. lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
  3741. {
  3742. /* Only support single entry read or browsing */
  3743. if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
  3744. return -EINVAL;
  3745. if (index > q->entry_count - 1)
  3746. return -EINVAL;
  3747. return 0;
  3748. }
  3749. /**
  3750. * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
  3751. * @pbuffer: The pointer to buffer to copy the read data into.
  3752. * @pque: The pointer to the queue to be read.
  3753. * @index: The index into the queue entry.
  3754. *
  3755. * Description:
  3756. * This routine reads out a single entry from the given queue's index location
  3757. * and copies it into the buffer provided.
  3758. *
  3759. * Returns:
  3760. * This function returns 0 when it fails, otherwise, it returns the length of
  3761. * the data read into the buffer provided.
  3762. **/
  3763. static int
  3764. lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
  3765. uint32_t index)
  3766. {
  3767. int offset, esize;
  3768. uint32_t *pentry;
  3769. if (!pbuffer || !pque)
  3770. return 0;
  3771. esize = pque->entry_size;
  3772. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  3773. "QE-INDEX[%04d]:\n", index);
  3774. offset = 0;
  3775. pentry = lpfc_sli4_qe(pque, index);
  3776. while (esize > 0) {
  3777. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  3778. "%08x ", *pentry);
  3779. pentry++;
  3780. offset += sizeof(uint32_t);
  3781. esize -= sizeof(uint32_t);
  3782. if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
  3783. len += scnprintf(pbuffer+len,
  3784. LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  3785. }
  3786. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  3787. return len;
  3788. }
  3789. /**
  3790. * lpfc_idiag_queacc_read - idiag debugfs read port queue
  3791. * @file: The file pointer to read from.
  3792. * @buf: The buffer to copy the data to.
  3793. * @nbytes: The number of bytes to read.
  3794. * @ppos: The position in the file to start reading from.
  3795. *
  3796. * Description:
  3797. * This routine reads data from the @phba device queue memory according to the
  3798. * idiag command, and copies to user @buf. Depending on the queue dump read
  3799. * command setup, it does either a single queue entry read or browing through
  3800. * all entries of the queue.
  3801. *
  3802. * Returns:
  3803. * This function returns the amount of data that was read (this could be less
  3804. * than @nbytes if the end of the file was reached) or a negative error value.
  3805. **/
  3806. static ssize_t
  3807. lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
  3808. loff_t *ppos)
  3809. {
  3810. struct lpfc_debug *debug = file->private_data;
  3811. uint32_t last_index, index, count;
  3812. struct lpfc_queue *pque = NULL;
  3813. char *pbuffer;
  3814. int len = 0;
  3815. /* This is a user read operation */
  3816. debug->op = LPFC_IDIAG_OP_RD;
  3817. if (!debug->buffer)
  3818. debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
  3819. if (!debug->buffer)
  3820. return 0;
  3821. pbuffer = debug->buffer;
  3822. if (*ppos)
  3823. return 0;
  3824. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  3825. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  3826. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  3827. pque = (struct lpfc_queue *)idiag.ptr_private;
  3828. } else
  3829. return 0;
  3830. /* Browse the queue starting from index */
  3831. if (count == LPFC_QUE_ACC_BROWSE)
  3832. goto que_browse;
  3833. /* Read a single entry from the queue */
  3834. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  3835. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3836. que_browse:
  3837. /* Browse all entries from the queue */
  3838. last_index = idiag.offset.last_rd;
  3839. index = last_index;
  3840. while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
  3841. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  3842. index++;
  3843. if (index > pque->entry_count - 1)
  3844. break;
  3845. }
  3846. /* Set up the offset for next portion of pci cfg read */
  3847. if (index > pque->entry_count - 1)
  3848. index = 0;
  3849. idiag.offset.last_rd = index;
  3850. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3851. }
  3852. /**
  3853. * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
  3854. * @file: The file pointer to read from.
  3855. * @buf: The buffer to copy the user data from.
  3856. * @nbytes: The number of bytes to get.
  3857. * @ppos: The position in the file to start reading from.
  3858. *
  3859. * This routine get the debugfs idiag command struct from user space and then
  3860. * perform the syntax check for port queue read (dump) or write (set) command
  3861. * accordingly. In the case of port queue read command, it sets up the command
  3862. * in the idiag command struct for the following debugfs read operation. In
  3863. * the case of port queue write operation, it executes the write operation
  3864. * into the port queue entry accordingly.
  3865. *
  3866. * It returns the @nbytges passing in from debugfs user space when successful.
  3867. * In case of error conditions, it returns proper error code back to the user
  3868. * space.
  3869. **/
  3870. static ssize_t
  3871. lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
  3872. size_t nbytes, loff_t *ppos)
  3873. {
  3874. struct lpfc_debug *debug = file->private_data;
  3875. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3876. uint32_t qidx, quetp, queid, index, count, offset, value;
  3877. uint32_t *pentry;
  3878. struct lpfc_queue *pque, *qp;
  3879. int rc;
  3880. /* This is a user write operation */
  3881. debug->op = LPFC_IDIAG_OP_WR;
  3882. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3883. if (rc < 0)
  3884. return rc;
  3885. /* Get and sanity check on command feilds */
  3886. quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
  3887. queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
  3888. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  3889. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  3890. offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
  3891. value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
  3892. /* Sanity check on command line arguments */
  3893. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  3894. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  3895. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  3896. if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
  3897. goto error_out;
  3898. if (count != 1)
  3899. goto error_out;
  3900. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  3901. if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
  3902. goto error_out;
  3903. } else
  3904. goto error_out;
  3905. switch (quetp) {
  3906. case LPFC_IDIAG_EQ:
  3907. /* HBA event queue */
  3908. if (phba->sli4_hba.hdwq) {
  3909. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  3910. qp = phba->sli4_hba.hdwq[qidx].hba_eq;
  3911. if (qp && qp->queue_id == queid) {
  3912. /* Sanity check */
  3913. rc = lpfc_idiag_que_param_check(qp,
  3914. index, count);
  3915. if (rc)
  3916. goto error_out;
  3917. idiag.ptr_private = qp;
  3918. goto pass_check;
  3919. }
  3920. }
  3921. }
  3922. goto error_out;
  3923. break;
  3924. case LPFC_IDIAG_CQ:
  3925. /* MBX complete queue */
  3926. if (phba->sli4_hba.mbx_cq &&
  3927. phba->sli4_hba.mbx_cq->queue_id == queid) {
  3928. /* Sanity check */
  3929. rc = lpfc_idiag_que_param_check(
  3930. phba->sli4_hba.mbx_cq, index, count);
  3931. if (rc)
  3932. goto error_out;
  3933. idiag.ptr_private = phba->sli4_hba.mbx_cq;
  3934. goto pass_check;
  3935. }
  3936. /* ELS complete queue */
  3937. if (phba->sli4_hba.els_cq &&
  3938. phba->sli4_hba.els_cq->queue_id == queid) {
  3939. /* Sanity check */
  3940. rc = lpfc_idiag_que_param_check(
  3941. phba->sli4_hba.els_cq, index, count);
  3942. if (rc)
  3943. goto error_out;
  3944. idiag.ptr_private = phba->sli4_hba.els_cq;
  3945. goto pass_check;
  3946. }
  3947. /* NVME LS complete queue */
  3948. if (phba->sli4_hba.nvmels_cq &&
  3949. phba->sli4_hba.nvmels_cq->queue_id == queid) {
  3950. /* Sanity check */
  3951. rc = lpfc_idiag_que_param_check(
  3952. phba->sli4_hba.nvmels_cq, index, count);
  3953. if (rc)
  3954. goto error_out;
  3955. idiag.ptr_private = phba->sli4_hba.nvmels_cq;
  3956. goto pass_check;
  3957. }
  3958. /* FCP complete queue */
  3959. if (phba->sli4_hba.hdwq) {
  3960. for (qidx = 0; qidx < phba->cfg_hdw_queue;
  3961. qidx++) {
  3962. qp = phba->sli4_hba.hdwq[qidx].io_cq;
  3963. if (qp && qp->queue_id == queid) {
  3964. /* Sanity check */
  3965. rc = lpfc_idiag_que_param_check(
  3966. qp, index, count);
  3967. if (rc)
  3968. goto error_out;
  3969. idiag.ptr_private = qp;
  3970. goto pass_check;
  3971. }
  3972. }
  3973. }
  3974. goto error_out;
  3975. break;
  3976. case LPFC_IDIAG_MQ:
  3977. /* MBX work queue */
  3978. if (phba->sli4_hba.mbx_wq &&
  3979. phba->sli4_hba.mbx_wq->queue_id == queid) {
  3980. /* Sanity check */
  3981. rc = lpfc_idiag_que_param_check(
  3982. phba->sli4_hba.mbx_wq, index, count);
  3983. if (rc)
  3984. goto error_out;
  3985. idiag.ptr_private = phba->sli4_hba.mbx_wq;
  3986. goto pass_check;
  3987. }
  3988. goto error_out;
  3989. break;
  3990. case LPFC_IDIAG_WQ:
  3991. /* ELS work queue */
  3992. if (phba->sli4_hba.els_wq &&
  3993. phba->sli4_hba.els_wq->queue_id == queid) {
  3994. /* Sanity check */
  3995. rc = lpfc_idiag_que_param_check(
  3996. phba->sli4_hba.els_wq, index, count);
  3997. if (rc)
  3998. goto error_out;
  3999. idiag.ptr_private = phba->sli4_hba.els_wq;
  4000. goto pass_check;
  4001. }
  4002. /* NVME LS work queue */
  4003. if (phba->sli4_hba.nvmels_wq &&
  4004. phba->sli4_hba.nvmels_wq->queue_id == queid) {
  4005. /* Sanity check */
  4006. rc = lpfc_idiag_que_param_check(
  4007. phba->sli4_hba.nvmels_wq, index, count);
  4008. if (rc)
  4009. goto error_out;
  4010. idiag.ptr_private = phba->sli4_hba.nvmels_wq;
  4011. goto pass_check;
  4012. }
  4013. if (phba->sli4_hba.hdwq) {
  4014. /* FCP/SCSI work queue */
  4015. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  4016. qp = phba->sli4_hba.hdwq[qidx].io_wq;
  4017. if (qp && qp->queue_id == queid) {
  4018. /* Sanity check */
  4019. rc = lpfc_idiag_que_param_check(
  4020. qp, index, count);
  4021. if (rc)
  4022. goto error_out;
  4023. idiag.ptr_private = qp;
  4024. goto pass_check;
  4025. }
  4026. }
  4027. }
  4028. goto error_out;
  4029. break;
  4030. case LPFC_IDIAG_RQ:
  4031. /* HDR queue */
  4032. if (phba->sli4_hba.hdr_rq &&
  4033. phba->sli4_hba.hdr_rq->queue_id == queid) {
  4034. /* Sanity check */
  4035. rc = lpfc_idiag_que_param_check(
  4036. phba->sli4_hba.hdr_rq, index, count);
  4037. if (rc)
  4038. goto error_out;
  4039. idiag.ptr_private = phba->sli4_hba.hdr_rq;
  4040. goto pass_check;
  4041. }
  4042. /* DAT queue */
  4043. if (phba->sli4_hba.dat_rq &&
  4044. phba->sli4_hba.dat_rq->queue_id == queid) {
  4045. /* Sanity check */
  4046. rc = lpfc_idiag_que_param_check(
  4047. phba->sli4_hba.dat_rq, index, count);
  4048. if (rc)
  4049. goto error_out;
  4050. idiag.ptr_private = phba->sli4_hba.dat_rq;
  4051. goto pass_check;
  4052. }
  4053. goto error_out;
  4054. break;
  4055. default:
  4056. goto error_out;
  4057. break;
  4058. }
  4059. pass_check:
  4060. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  4061. if (count == LPFC_QUE_ACC_BROWSE)
  4062. idiag.offset.last_rd = index;
  4063. }
  4064. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  4065. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  4066. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  4067. /* Additional sanity checks on write operation */
  4068. pque = (struct lpfc_queue *)idiag.ptr_private;
  4069. if (offset > pque->entry_size/sizeof(uint32_t) - 1)
  4070. goto error_out;
  4071. pentry = lpfc_sli4_qe(pque, index);
  4072. pentry += offset;
  4073. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
  4074. *pentry = value;
  4075. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
  4076. *pentry |= value;
  4077. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
  4078. *pentry &= ~value;
  4079. }
  4080. return nbytes;
  4081. error_out:
  4082. /* Clean out command structure on command error out */
  4083. memset(&idiag, 0, sizeof(idiag));
  4084. return -EINVAL;
  4085. }
  4086. /**
  4087. * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
  4088. * @phba: The pointer to hba structure.
  4089. * @pbuffer: The pointer to the buffer to copy the data to.
  4090. * @len: The length of bytes to copied.
  4091. * @drbregid: The id to doorbell registers.
  4092. *
  4093. * Description:
  4094. * This routine reads a doorbell register and copies its content to the
  4095. * user buffer pointed to by @pbuffer.
  4096. *
  4097. * Returns:
  4098. * This function returns the amount of data that was copied into @pbuffer.
  4099. **/
  4100. static int
  4101. lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  4102. int len, uint32_t drbregid)
  4103. {
  4104. if (!pbuffer)
  4105. return 0;
  4106. switch (drbregid) {
  4107. case LPFC_DRB_EQ:
  4108. len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE-len,
  4109. "EQ-DRB-REG: 0x%08x\n",
  4110. readl(phba->sli4_hba.EQDBregaddr));
  4111. break;
  4112. case LPFC_DRB_CQ:
  4113. len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE - len,
  4114. "CQ-DRB-REG: 0x%08x\n",
  4115. readl(phba->sli4_hba.CQDBregaddr));
  4116. break;
  4117. case LPFC_DRB_MQ:
  4118. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  4119. "MQ-DRB-REG: 0x%08x\n",
  4120. readl(phba->sli4_hba.MQDBregaddr));
  4121. break;
  4122. case LPFC_DRB_WQ:
  4123. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  4124. "WQ-DRB-REG: 0x%08x\n",
  4125. readl(phba->sli4_hba.WQDBregaddr));
  4126. break;
  4127. case LPFC_DRB_RQ:
  4128. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  4129. "RQ-DRB-REG: 0x%08x\n",
  4130. readl(phba->sli4_hba.RQDBregaddr));
  4131. break;
  4132. default:
  4133. break;
  4134. }
  4135. return len;
  4136. }
  4137. /**
  4138. * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
  4139. * @file: The file pointer to read from.
  4140. * @buf: The buffer to copy the data to.
  4141. * @nbytes: The number of bytes to read.
  4142. * @ppos: The position in the file to start reading from.
  4143. *
  4144. * Description:
  4145. * This routine reads data from the @phba device doorbell register according
  4146. * to the idiag command, and copies to user @buf. Depending on the doorbell
  4147. * register read command setup, it does either a single doorbell register
  4148. * read or dump all doorbell registers.
  4149. *
  4150. * Returns:
  4151. * This function returns the amount of data that was read (this could be less
  4152. * than @nbytes if the end of the file was reached) or a negative error value.
  4153. **/
  4154. static ssize_t
  4155. lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
  4156. loff_t *ppos)
  4157. {
  4158. struct lpfc_debug *debug = file->private_data;
  4159. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4160. uint32_t drb_reg_id, i;
  4161. char *pbuffer;
  4162. int len = 0;
  4163. /* This is a user read operation */
  4164. debug->op = LPFC_IDIAG_OP_RD;
  4165. if (!debug->buffer)
  4166. debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
  4167. if (!debug->buffer)
  4168. return 0;
  4169. pbuffer = debug->buffer;
  4170. if (*ppos)
  4171. return 0;
  4172. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
  4173. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  4174. else
  4175. return 0;
  4176. if (drb_reg_id == LPFC_DRB_ACC_ALL)
  4177. for (i = 1; i <= LPFC_DRB_MAX; i++)
  4178. len = lpfc_idiag_drbacc_read_reg(phba,
  4179. pbuffer, len, i);
  4180. else
  4181. len = lpfc_idiag_drbacc_read_reg(phba,
  4182. pbuffer, len, drb_reg_id);
  4183. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4184. }
  4185. /**
  4186. * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
  4187. * @file: The file pointer to read from.
  4188. * @buf: The buffer to copy the user data from.
  4189. * @nbytes: The number of bytes to get.
  4190. * @ppos: The position in the file to start reading from.
  4191. *
  4192. * This routine get the debugfs idiag command struct from user space and then
  4193. * perform the syntax check for port doorbell register read (dump) or write
  4194. * (set) command accordingly. In the case of port queue read command, it sets
  4195. * up the command in the idiag command struct for the following debugfs read
  4196. * operation. In the case of port doorbell register write operation, it
  4197. * executes the write operation into the port doorbell register accordingly.
  4198. *
  4199. * It returns the @nbytges passing in from debugfs user space when successful.
  4200. * In case of error conditions, it returns proper error code back to the user
  4201. * space.
  4202. **/
  4203. static ssize_t
  4204. lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
  4205. size_t nbytes, loff_t *ppos)
  4206. {
  4207. struct lpfc_debug *debug = file->private_data;
  4208. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4209. uint32_t drb_reg_id, value, reg_val = 0;
  4210. void __iomem *drb_reg;
  4211. int rc;
  4212. /* This is a user write operation */
  4213. debug->op = LPFC_IDIAG_OP_WR;
  4214. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4215. if (rc < 0)
  4216. return rc;
  4217. /* Sanity check on command line arguments */
  4218. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  4219. value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
  4220. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  4221. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  4222. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  4223. if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
  4224. goto error_out;
  4225. if (drb_reg_id > LPFC_DRB_MAX)
  4226. goto error_out;
  4227. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
  4228. if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
  4229. goto error_out;
  4230. if ((drb_reg_id > LPFC_DRB_MAX) &&
  4231. (drb_reg_id != LPFC_DRB_ACC_ALL))
  4232. goto error_out;
  4233. } else
  4234. goto error_out;
  4235. /* Perform the write access operation */
  4236. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  4237. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  4238. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  4239. switch (drb_reg_id) {
  4240. case LPFC_DRB_EQ:
  4241. drb_reg = phba->sli4_hba.EQDBregaddr;
  4242. break;
  4243. case LPFC_DRB_CQ:
  4244. drb_reg = phba->sli4_hba.CQDBregaddr;
  4245. break;
  4246. case LPFC_DRB_MQ:
  4247. drb_reg = phba->sli4_hba.MQDBregaddr;
  4248. break;
  4249. case LPFC_DRB_WQ:
  4250. drb_reg = phba->sli4_hba.WQDBregaddr;
  4251. break;
  4252. case LPFC_DRB_RQ:
  4253. drb_reg = phba->sli4_hba.RQDBregaddr;
  4254. break;
  4255. default:
  4256. goto error_out;
  4257. }
  4258. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
  4259. reg_val = value;
  4260. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
  4261. reg_val = readl(drb_reg);
  4262. reg_val |= value;
  4263. }
  4264. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  4265. reg_val = readl(drb_reg);
  4266. reg_val &= ~value;
  4267. }
  4268. writel(reg_val, drb_reg);
  4269. readl(drb_reg); /* flush */
  4270. }
  4271. return nbytes;
  4272. error_out:
  4273. /* Clean out command structure on command error out */
  4274. memset(&idiag, 0, sizeof(idiag));
  4275. return -EINVAL;
  4276. }
  4277. /**
  4278. * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
  4279. * @phba: The pointer to hba structure.
  4280. * @pbuffer: The pointer to the buffer to copy the data to.
  4281. * @len: The length of bytes to copied.
  4282. * @drbregid: The id to doorbell registers.
  4283. *
  4284. * Description:
  4285. * This routine reads a control register and copies its content to the
  4286. * user buffer pointed to by @pbuffer.
  4287. *
  4288. * Returns:
  4289. * This function returns the amount of data that was copied into @pbuffer.
  4290. **/
  4291. static int
  4292. lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  4293. int len, uint32_t ctlregid)
  4294. {
  4295. if (!pbuffer)
  4296. return 0;
  4297. switch (ctlregid) {
  4298. case LPFC_CTL_PORT_SEM:
  4299. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4300. "Port SemReg: 0x%08x\n",
  4301. readl(phba->sli4_hba.conf_regs_memmap_p +
  4302. LPFC_CTL_PORT_SEM_OFFSET));
  4303. break;
  4304. case LPFC_CTL_PORT_STA:
  4305. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4306. "Port StaReg: 0x%08x\n",
  4307. readl(phba->sli4_hba.conf_regs_memmap_p +
  4308. LPFC_CTL_PORT_STA_OFFSET));
  4309. break;
  4310. case LPFC_CTL_PORT_CTL:
  4311. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4312. "Port CtlReg: 0x%08x\n",
  4313. readl(phba->sli4_hba.conf_regs_memmap_p +
  4314. LPFC_CTL_PORT_CTL_OFFSET));
  4315. break;
  4316. case LPFC_CTL_PORT_ER1:
  4317. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4318. "Port Er1Reg: 0x%08x\n",
  4319. readl(phba->sli4_hba.conf_regs_memmap_p +
  4320. LPFC_CTL_PORT_ER1_OFFSET));
  4321. break;
  4322. case LPFC_CTL_PORT_ER2:
  4323. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4324. "Port Er2Reg: 0x%08x\n",
  4325. readl(phba->sli4_hba.conf_regs_memmap_p +
  4326. LPFC_CTL_PORT_ER2_OFFSET));
  4327. break;
  4328. case LPFC_CTL_PDEV_CTL:
  4329. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4330. "PDev CtlReg: 0x%08x\n",
  4331. readl(phba->sli4_hba.conf_regs_memmap_p +
  4332. LPFC_CTL_PDEV_CTL_OFFSET));
  4333. break;
  4334. default:
  4335. break;
  4336. }
  4337. return len;
  4338. }
  4339. /**
  4340. * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
  4341. * @file: The file pointer to read from.
  4342. * @buf: The buffer to copy the data to.
  4343. * @nbytes: The number of bytes to read.
  4344. * @ppos: The position in the file to start reading from.
  4345. *
  4346. * Description:
  4347. * This routine reads data from the @phba port and device registers according
  4348. * to the idiag command, and copies to user @buf.
  4349. *
  4350. * Returns:
  4351. * This function returns the amount of data that was read (this could be less
  4352. * than @nbytes if the end of the file was reached) or a negative error value.
  4353. **/
  4354. static ssize_t
  4355. lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
  4356. loff_t *ppos)
  4357. {
  4358. struct lpfc_debug *debug = file->private_data;
  4359. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4360. uint32_t ctl_reg_id, i;
  4361. char *pbuffer;
  4362. int len = 0;
  4363. /* This is a user read operation */
  4364. debug->op = LPFC_IDIAG_OP_RD;
  4365. if (!debug->buffer)
  4366. debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
  4367. if (!debug->buffer)
  4368. return 0;
  4369. pbuffer = debug->buffer;
  4370. if (*ppos)
  4371. return 0;
  4372. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
  4373. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  4374. else
  4375. return 0;
  4376. if (ctl_reg_id == LPFC_CTL_ACC_ALL)
  4377. for (i = 1; i <= LPFC_CTL_MAX; i++)
  4378. len = lpfc_idiag_ctlacc_read_reg(phba,
  4379. pbuffer, len, i);
  4380. else
  4381. len = lpfc_idiag_ctlacc_read_reg(phba,
  4382. pbuffer, len, ctl_reg_id);
  4383. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4384. }
  4385. /**
  4386. * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
  4387. * @file: The file pointer to read from.
  4388. * @buf: The buffer to copy the user data from.
  4389. * @nbytes: The number of bytes to get.
  4390. * @ppos: The position in the file to start reading from.
  4391. *
  4392. * This routine get the debugfs idiag command struct from user space and then
  4393. * perform the syntax check for port and device control register read (dump)
  4394. * or write (set) command accordingly.
  4395. *
  4396. * It returns the @nbytges passing in from debugfs user space when successful.
  4397. * In case of error conditions, it returns proper error code back to the user
  4398. * space.
  4399. **/
  4400. static ssize_t
  4401. lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
  4402. size_t nbytes, loff_t *ppos)
  4403. {
  4404. struct lpfc_debug *debug = file->private_data;
  4405. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4406. uint32_t ctl_reg_id, value, reg_val = 0;
  4407. void __iomem *ctl_reg;
  4408. int rc;
  4409. /* This is a user write operation */
  4410. debug->op = LPFC_IDIAG_OP_WR;
  4411. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4412. if (rc < 0)
  4413. return rc;
  4414. /* Sanity check on command line arguments */
  4415. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  4416. value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
  4417. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  4418. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  4419. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  4420. if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
  4421. goto error_out;
  4422. if (ctl_reg_id > LPFC_CTL_MAX)
  4423. goto error_out;
  4424. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
  4425. if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
  4426. goto error_out;
  4427. if ((ctl_reg_id > LPFC_CTL_MAX) &&
  4428. (ctl_reg_id != LPFC_CTL_ACC_ALL))
  4429. goto error_out;
  4430. } else
  4431. goto error_out;
  4432. /* Perform the write access operation */
  4433. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  4434. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  4435. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  4436. switch (ctl_reg_id) {
  4437. case LPFC_CTL_PORT_SEM:
  4438. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4439. LPFC_CTL_PORT_SEM_OFFSET;
  4440. break;
  4441. case LPFC_CTL_PORT_STA:
  4442. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4443. LPFC_CTL_PORT_STA_OFFSET;
  4444. break;
  4445. case LPFC_CTL_PORT_CTL:
  4446. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4447. LPFC_CTL_PORT_CTL_OFFSET;
  4448. break;
  4449. case LPFC_CTL_PORT_ER1:
  4450. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4451. LPFC_CTL_PORT_ER1_OFFSET;
  4452. break;
  4453. case LPFC_CTL_PORT_ER2:
  4454. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4455. LPFC_CTL_PORT_ER2_OFFSET;
  4456. break;
  4457. case LPFC_CTL_PDEV_CTL:
  4458. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4459. LPFC_CTL_PDEV_CTL_OFFSET;
  4460. break;
  4461. default:
  4462. goto error_out;
  4463. }
  4464. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
  4465. reg_val = value;
  4466. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
  4467. reg_val = readl(ctl_reg);
  4468. reg_val |= value;
  4469. }
  4470. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  4471. reg_val = readl(ctl_reg);
  4472. reg_val &= ~value;
  4473. }
  4474. writel(reg_val, ctl_reg);
  4475. readl(ctl_reg); /* flush */
  4476. }
  4477. return nbytes;
  4478. error_out:
  4479. /* Clean out command structure on command error out */
  4480. memset(&idiag, 0, sizeof(idiag));
  4481. return -EINVAL;
  4482. }
  4483. /**
  4484. * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
  4485. * @phba: Pointer to HBA context object.
  4486. * @pbuffer: Pointer to data buffer.
  4487. *
  4488. * Description:
  4489. * This routine gets the driver mailbox access debugfs setup information.
  4490. *
  4491. * Returns:
  4492. * This function returns the amount of data that was read (this could be less
  4493. * than @nbytes if the end of the file was reached) or a negative error value.
  4494. **/
  4495. static int
  4496. lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
  4497. {
  4498. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  4499. int len = 0;
  4500. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  4501. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  4502. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  4503. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  4504. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  4505. "mbx_dump_map: 0x%08x\n", mbx_dump_map);
  4506. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  4507. "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
  4508. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  4509. "mbx_word_cnt: %04d\n", mbx_word_cnt);
  4510. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  4511. "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
  4512. return len;
  4513. }
  4514. /**
  4515. * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
  4516. * @file: The file pointer to read from.
  4517. * @buf: The buffer to copy the data to.
  4518. * @nbytes: The number of bytes to read.
  4519. * @ppos: The position in the file to start reading from.
  4520. *
  4521. * Description:
  4522. * This routine reads data from the @phba driver mailbox access debugfs setup
  4523. * information.
  4524. *
  4525. * Returns:
  4526. * This function returns the amount of data that was read (this could be less
  4527. * than @nbytes if the end of the file was reached) or a negative error value.
  4528. **/
  4529. static ssize_t
  4530. lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
  4531. loff_t *ppos)
  4532. {
  4533. struct lpfc_debug *debug = file->private_data;
  4534. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4535. char *pbuffer;
  4536. int len = 0;
  4537. /* This is a user read operation */
  4538. debug->op = LPFC_IDIAG_OP_RD;
  4539. if (!debug->buffer)
  4540. debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
  4541. if (!debug->buffer)
  4542. return 0;
  4543. pbuffer = debug->buffer;
  4544. if (*ppos)
  4545. return 0;
  4546. if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
  4547. (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
  4548. return 0;
  4549. len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
  4550. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4551. }
  4552. /**
  4553. * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
  4554. * @file: The file pointer to read from.
  4555. * @buf: The buffer to copy the user data from.
  4556. * @nbytes: The number of bytes to get.
  4557. * @ppos: The position in the file to start reading from.
  4558. *
  4559. * This routine get the debugfs idiag command struct from user space and then
  4560. * perform the syntax check for driver mailbox command (dump) and sets up the
  4561. * necessary states in the idiag command struct accordingly.
  4562. *
  4563. * It returns the @nbytges passing in from debugfs user space when successful.
  4564. * In case of error conditions, it returns proper error code back to the user
  4565. * space.
  4566. **/
  4567. static ssize_t
  4568. lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
  4569. size_t nbytes, loff_t *ppos)
  4570. {
  4571. struct lpfc_debug *debug = file->private_data;
  4572. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  4573. int rc;
  4574. /* This is a user write operation */
  4575. debug->op = LPFC_IDIAG_OP_WR;
  4576. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4577. if (rc < 0)
  4578. return rc;
  4579. /* Sanity check on command line arguments */
  4580. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  4581. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  4582. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  4583. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  4584. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
  4585. if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
  4586. goto error_out;
  4587. if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
  4588. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  4589. goto error_out;
  4590. if (mbx_word_cnt > sizeof(MAILBOX_t))
  4591. goto error_out;
  4592. } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
  4593. if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
  4594. goto error_out;
  4595. if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
  4596. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  4597. goto error_out;
  4598. if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
  4599. goto error_out;
  4600. if (mbx_mbox_cmd != 0x9b)
  4601. goto error_out;
  4602. } else
  4603. goto error_out;
  4604. if (mbx_word_cnt == 0)
  4605. goto error_out;
  4606. if (rc != LPFC_MBX_DMP_ARG)
  4607. goto error_out;
  4608. if (mbx_mbox_cmd & ~0xff)
  4609. goto error_out;
  4610. /* condition for stop mailbox dump */
  4611. if (mbx_dump_cnt == 0)
  4612. goto reset_out;
  4613. return nbytes;
  4614. reset_out:
  4615. /* Clean out command structure on command error out */
  4616. memset(&idiag, 0, sizeof(idiag));
  4617. return nbytes;
  4618. error_out:
  4619. /* Clean out command structure on command error out */
  4620. memset(&idiag, 0, sizeof(idiag));
  4621. return -EINVAL;
  4622. }
  4623. /**
  4624. * lpfc_idiag_extacc_avail_get - get the available extents information
  4625. * @phba: pointer to lpfc hba data structure.
  4626. * @pbuffer: pointer to internal buffer.
  4627. * @len: length into the internal buffer data has been copied.
  4628. *
  4629. * Description:
  4630. * This routine is to get the available extent information.
  4631. *
  4632. * Returns:
  4633. * overall lenth of the data read into the internal buffer.
  4634. **/
  4635. static int
  4636. lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4637. {
  4638. uint16_t ext_cnt, ext_size;
  4639. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4640. "\nAvailable Extents Information:\n");
  4641. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4642. "\tPort Available VPI extents: ");
  4643. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
  4644. &ext_cnt, &ext_size);
  4645. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4646. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4647. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4648. "\tPort Available VFI extents: ");
  4649. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
  4650. &ext_cnt, &ext_size);
  4651. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4652. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4653. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4654. "\tPort Available RPI extents: ");
  4655. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
  4656. &ext_cnt, &ext_size);
  4657. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4658. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4659. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4660. "\tPort Available XRI extents: ");
  4661. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
  4662. &ext_cnt, &ext_size);
  4663. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4664. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4665. return len;
  4666. }
  4667. /**
  4668. * lpfc_idiag_extacc_alloc_get - get the allocated extents information
  4669. * @phba: pointer to lpfc hba data structure.
  4670. * @pbuffer: pointer to internal buffer.
  4671. * @len: length into the internal buffer data has been copied.
  4672. *
  4673. * Description:
  4674. * This routine is to get the allocated extent information.
  4675. *
  4676. * Returns:
  4677. * overall lenth of the data read into the internal buffer.
  4678. **/
  4679. static int
  4680. lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4681. {
  4682. uint16_t ext_cnt, ext_size;
  4683. int rc;
  4684. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4685. "\nAllocated Extents Information:\n");
  4686. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4687. "\tHost Allocated VPI extents: ");
  4688. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
  4689. &ext_cnt, &ext_size);
  4690. if (!rc)
  4691. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4692. "Port %d Extent %3d, Size %3d\n",
  4693. phba->brd_no, ext_cnt, ext_size);
  4694. else
  4695. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4696. "N/A\n");
  4697. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4698. "\tHost Allocated VFI extents: ");
  4699. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
  4700. &ext_cnt, &ext_size);
  4701. if (!rc)
  4702. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4703. "Port %d Extent %3d, Size %3d\n",
  4704. phba->brd_no, ext_cnt, ext_size);
  4705. else
  4706. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4707. "N/A\n");
  4708. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4709. "\tHost Allocated RPI extents: ");
  4710. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
  4711. &ext_cnt, &ext_size);
  4712. if (!rc)
  4713. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4714. "Port %d Extent %3d, Size %3d\n",
  4715. phba->brd_no, ext_cnt, ext_size);
  4716. else
  4717. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4718. "N/A\n");
  4719. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4720. "\tHost Allocated XRI extents: ");
  4721. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
  4722. &ext_cnt, &ext_size);
  4723. if (!rc)
  4724. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4725. "Port %d Extent %3d, Size %3d\n",
  4726. phba->brd_no, ext_cnt, ext_size);
  4727. else
  4728. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4729. "N/A\n");
  4730. return len;
  4731. }
  4732. /**
  4733. * lpfc_idiag_extacc_drivr_get - get driver extent information
  4734. * @phba: pointer to lpfc hba data structure.
  4735. * @pbuffer: pointer to internal buffer.
  4736. * @len: length into the internal buffer data has been copied.
  4737. *
  4738. * Description:
  4739. * This routine is to get the driver extent information.
  4740. *
  4741. * Returns:
  4742. * overall lenth of the data read into the internal buffer.
  4743. **/
  4744. static int
  4745. lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4746. {
  4747. struct lpfc_rsrc_blks *rsrc_blks;
  4748. int index;
  4749. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4750. "\nDriver Extents Information:\n");
  4751. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4752. "\tVPI extents:\n");
  4753. index = 0;
  4754. list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
  4755. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4756. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4757. index, rsrc_blks->rsrc_start,
  4758. rsrc_blks->rsrc_size);
  4759. index++;
  4760. }
  4761. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4762. "\tVFI extents:\n");
  4763. index = 0;
  4764. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
  4765. list) {
  4766. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4767. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4768. index, rsrc_blks->rsrc_start,
  4769. rsrc_blks->rsrc_size);
  4770. index++;
  4771. }
  4772. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4773. "\tRPI extents:\n");
  4774. index = 0;
  4775. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
  4776. list) {
  4777. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4778. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4779. index, rsrc_blks->rsrc_start,
  4780. rsrc_blks->rsrc_size);
  4781. index++;
  4782. }
  4783. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4784. "\tXRI extents:\n");
  4785. index = 0;
  4786. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
  4787. list) {
  4788. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4789. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4790. index, rsrc_blks->rsrc_start,
  4791. rsrc_blks->rsrc_size);
  4792. index++;
  4793. }
  4794. return len;
  4795. }
  4796. /**
  4797. * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
  4798. * @file: The file pointer to read from.
  4799. * @buf: The buffer to copy the user data from.
  4800. * @nbytes: The number of bytes to get.
  4801. * @ppos: The position in the file to start reading from.
  4802. *
  4803. * This routine get the debugfs idiag command struct from user space and then
  4804. * perform the syntax check for extent information access commands and sets
  4805. * up the necessary states in the idiag command struct accordingly.
  4806. *
  4807. * It returns the @nbytges passing in from debugfs user space when successful.
  4808. * In case of error conditions, it returns proper error code back to the user
  4809. * space.
  4810. **/
  4811. static ssize_t
  4812. lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
  4813. size_t nbytes, loff_t *ppos)
  4814. {
  4815. struct lpfc_debug *debug = file->private_data;
  4816. uint32_t ext_map;
  4817. int rc;
  4818. /* This is a user write operation */
  4819. debug->op = LPFC_IDIAG_OP_WR;
  4820. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4821. if (rc < 0)
  4822. return rc;
  4823. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  4824. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  4825. goto error_out;
  4826. if (rc != LPFC_EXT_ACC_CMD_ARG)
  4827. goto error_out;
  4828. if (!(ext_map & LPFC_EXT_ACC_ALL))
  4829. goto error_out;
  4830. return nbytes;
  4831. error_out:
  4832. /* Clean out command structure on command error out */
  4833. memset(&idiag, 0, sizeof(idiag));
  4834. return -EINVAL;
  4835. }
  4836. /**
  4837. * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
  4838. * @file: The file pointer to read from.
  4839. * @buf: The buffer to copy the data to.
  4840. * @nbytes: The number of bytes to read.
  4841. * @ppos: The position in the file to start reading from.
  4842. *
  4843. * Description:
  4844. * This routine reads data from the proper extent information according to
  4845. * the idiag command, and copies to user @buf.
  4846. *
  4847. * Returns:
  4848. * This function returns the amount of data that was read (this could be less
  4849. * than @nbytes if the end of the file was reached) or a negative error value.
  4850. **/
  4851. static ssize_t
  4852. lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
  4853. loff_t *ppos)
  4854. {
  4855. struct lpfc_debug *debug = file->private_data;
  4856. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4857. char *pbuffer;
  4858. uint32_t ext_map;
  4859. int len = 0;
  4860. /* This is a user read operation */
  4861. debug->op = LPFC_IDIAG_OP_RD;
  4862. if (!debug->buffer)
  4863. debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
  4864. if (!debug->buffer)
  4865. return 0;
  4866. pbuffer = debug->buffer;
  4867. if (*ppos)
  4868. return 0;
  4869. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  4870. return 0;
  4871. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  4872. if (ext_map & LPFC_EXT_ACC_AVAIL)
  4873. len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
  4874. if (ext_map & LPFC_EXT_ACC_ALLOC)
  4875. len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
  4876. if (ext_map & LPFC_EXT_ACC_DRIVR)
  4877. len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
  4878. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4879. }
  4880. #undef lpfc_debugfs_op_disc_trc
  4881. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  4882. .owner = THIS_MODULE,
  4883. .open = lpfc_debugfs_disc_trc_open,
  4884. .llseek = lpfc_debugfs_lseek,
  4885. .read = lpfc_debugfs_read,
  4886. .release = lpfc_debugfs_release,
  4887. };
  4888. #undef lpfc_debugfs_op_nodelist
  4889. static const struct file_operations lpfc_debugfs_op_nodelist = {
  4890. .owner = THIS_MODULE,
  4891. .open = lpfc_debugfs_nodelist_open,
  4892. .llseek = lpfc_debugfs_lseek,
  4893. .read = lpfc_debugfs_read,
  4894. .release = lpfc_debugfs_release,
  4895. };
  4896. #undef lpfc_debugfs_op_multixripools
  4897. static const struct file_operations lpfc_debugfs_op_multixripools = {
  4898. .owner = THIS_MODULE,
  4899. .open = lpfc_debugfs_multixripools_open,
  4900. .llseek = lpfc_debugfs_lseek,
  4901. .read = lpfc_debugfs_read,
  4902. .write = lpfc_debugfs_multixripools_write,
  4903. .release = lpfc_debugfs_release,
  4904. };
  4905. #undef lpfc_debugfs_op_hbqinfo
  4906. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  4907. .owner = THIS_MODULE,
  4908. .open = lpfc_debugfs_hbqinfo_open,
  4909. .llseek = lpfc_debugfs_lseek,
  4910. .read = lpfc_debugfs_read,
  4911. .release = lpfc_debugfs_release,
  4912. };
  4913. #ifdef LPFC_HDWQ_LOCK_STAT
  4914. #undef lpfc_debugfs_op_lockstat
  4915. static const struct file_operations lpfc_debugfs_op_lockstat = {
  4916. .owner = THIS_MODULE,
  4917. .open = lpfc_debugfs_lockstat_open,
  4918. .llseek = lpfc_debugfs_lseek,
  4919. .read = lpfc_debugfs_read,
  4920. .write = lpfc_debugfs_lockstat_write,
  4921. .release = lpfc_debugfs_release,
  4922. };
  4923. #endif
  4924. #undef lpfc_debugfs_ras_log
  4925. static const struct file_operations lpfc_debugfs_ras_log = {
  4926. .owner = THIS_MODULE,
  4927. .open = lpfc_debugfs_ras_log_open,
  4928. .llseek = lpfc_debugfs_lseek,
  4929. .read = lpfc_debugfs_read,
  4930. .release = lpfc_debugfs_ras_log_release,
  4931. };
  4932. #undef lpfc_debugfs_op_dumpHBASlim
  4933. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  4934. .owner = THIS_MODULE,
  4935. .open = lpfc_debugfs_dumpHBASlim_open,
  4936. .llseek = lpfc_debugfs_lseek,
  4937. .read = lpfc_debugfs_read,
  4938. .release = lpfc_debugfs_release,
  4939. };
  4940. #undef lpfc_debugfs_op_dumpHostSlim
  4941. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  4942. .owner = THIS_MODULE,
  4943. .open = lpfc_debugfs_dumpHostSlim_open,
  4944. .llseek = lpfc_debugfs_lseek,
  4945. .read = lpfc_debugfs_read,
  4946. .release = lpfc_debugfs_release,
  4947. };
  4948. #undef lpfc_debugfs_op_nvmestat
  4949. static const struct file_operations lpfc_debugfs_op_nvmestat = {
  4950. .owner = THIS_MODULE,
  4951. .open = lpfc_debugfs_nvmestat_open,
  4952. .llseek = lpfc_debugfs_lseek,
  4953. .read = lpfc_debugfs_read,
  4954. .write = lpfc_debugfs_nvmestat_write,
  4955. .release = lpfc_debugfs_release,
  4956. };
  4957. #undef lpfc_debugfs_op_scsistat
  4958. static const struct file_operations lpfc_debugfs_op_scsistat = {
  4959. .owner = THIS_MODULE,
  4960. .open = lpfc_debugfs_scsistat_open,
  4961. .llseek = lpfc_debugfs_lseek,
  4962. .read = lpfc_debugfs_read,
  4963. .write = lpfc_debugfs_scsistat_write,
  4964. .release = lpfc_debugfs_release,
  4965. };
  4966. #undef lpfc_debugfs_op_ioktime
  4967. static const struct file_operations lpfc_debugfs_op_ioktime = {
  4968. .owner = THIS_MODULE,
  4969. .open = lpfc_debugfs_ioktime_open,
  4970. .llseek = lpfc_debugfs_lseek,
  4971. .read = lpfc_debugfs_read,
  4972. .write = lpfc_debugfs_ioktime_write,
  4973. .release = lpfc_debugfs_release,
  4974. };
  4975. #undef lpfc_debugfs_op_nvmeio_trc
  4976. static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
  4977. .owner = THIS_MODULE,
  4978. .open = lpfc_debugfs_nvmeio_trc_open,
  4979. .llseek = lpfc_debugfs_lseek,
  4980. .read = lpfc_debugfs_read,
  4981. .write = lpfc_debugfs_nvmeio_trc_write,
  4982. .release = lpfc_debugfs_release,
  4983. };
  4984. #undef lpfc_debugfs_op_hdwqstat
  4985. static const struct file_operations lpfc_debugfs_op_hdwqstat = {
  4986. .owner = THIS_MODULE,
  4987. .open = lpfc_debugfs_hdwqstat_open,
  4988. .llseek = lpfc_debugfs_lseek,
  4989. .read = lpfc_debugfs_read,
  4990. .write = lpfc_debugfs_hdwqstat_write,
  4991. .release = lpfc_debugfs_release,
  4992. };
  4993. #undef lpfc_debugfs_op_dif_err
  4994. static const struct file_operations lpfc_debugfs_op_dif_err = {
  4995. .owner = THIS_MODULE,
  4996. .open = simple_open,
  4997. .llseek = lpfc_debugfs_lseek,
  4998. .read = lpfc_debugfs_dif_err_read,
  4999. .write = lpfc_debugfs_dif_err_write,
  5000. .release = lpfc_debugfs_dif_err_release,
  5001. };
  5002. #undef lpfc_debugfs_op_slow_ring_trc
  5003. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  5004. .owner = THIS_MODULE,
  5005. .open = lpfc_debugfs_slow_ring_trc_open,
  5006. .llseek = lpfc_debugfs_lseek,
  5007. .read = lpfc_debugfs_read,
  5008. .release = lpfc_debugfs_release,
  5009. };
  5010. static struct dentry *lpfc_debugfs_root = NULL;
  5011. static atomic_t lpfc_debugfs_hba_count;
  5012. /*
  5013. * File operations for the iDiag debugfs
  5014. */
  5015. #undef lpfc_idiag_op_pciCfg
  5016. static const struct file_operations lpfc_idiag_op_pciCfg = {
  5017. .owner = THIS_MODULE,
  5018. .open = lpfc_idiag_open,
  5019. .llseek = lpfc_debugfs_lseek,
  5020. .read = lpfc_idiag_pcicfg_read,
  5021. .write = lpfc_idiag_pcicfg_write,
  5022. .release = lpfc_idiag_cmd_release,
  5023. };
  5024. #undef lpfc_idiag_op_barAcc
  5025. static const struct file_operations lpfc_idiag_op_barAcc = {
  5026. .owner = THIS_MODULE,
  5027. .open = lpfc_idiag_open,
  5028. .llseek = lpfc_debugfs_lseek,
  5029. .read = lpfc_idiag_baracc_read,
  5030. .write = lpfc_idiag_baracc_write,
  5031. .release = lpfc_idiag_cmd_release,
  5032. };
  5033. #undef lpfc_idiag_op_queInfo
  5034. static const struct file_operations lpfc_idiag_op_queInfo = {
  5035. .owner = THIS_MODULE,
  5036. .open = lpfc_idiag_open,
  5037. .read = lpfc_idiag_queinfo_read,
  5038. .release = lpfc_idiag_release,
  5039. };
  5040. #undef lpfc_idiag_op_queAcc
  5041. static const struct file_operations lpfc_idiag_op_queAcc = {
  5042. .owner = THIS_MODULE,
  5043. .open = lpfc_idiag_open,
  5044. .llseek = lpfc_debugfs_lseek,
  5045. .read = lpfc_idiag_queacc_read,
  5046. .write = lpfc_idiag_queacc_write,
  5047. .release = lpfc_idiag_cmd_release,
  5048. };
  5049. #undef lpfc_idiag_op_drbAcc
  5050. static const struct file_operations lpfc_idiag_op_drbAcc = {
  5051. .owner = THIS_MODULE,
  5052. .open = lpfc_idiag_open,
  5053. .llseek = lpfc_debugfs_lseek,
  5054. .read = lpfc_idiag_drbacc_read,
  5055. .write = lpfc_idiag_drbacc_write,
  5056. .release = lpfc_idiag_cmd_release,
  5057. };
  5058. #undef lpfc_idiag_op_ctlAcc
  5059. static const struct file_operations lpfc_idiag_op_ctlAcc = {
  5060. .owner = THIS_MODULE,
  5061. .open = lpfc_idiag_open,
  5062. .llseek = lpfc_debugfs_lseek,
  5063. .read = lpfc_idiag_ctlacc_read,
  5064. .write = lpfc_idiag_ctlacc_write,
  5065. .release = lpfc_idiag_cmd_release,
  5066. };
  5067. #undef lpfc_idiag_op_mbxAcc
  5068. static const struct file_operations lpfc_idiag_op_mbxAcc = {
  5069. .owner = THIS_MODULE,
  5070. .open = lpfc_idiag_open,
  5071. .llseek = lpfc_debugfs_lseek,
  5072. .read = lpfc_idiag_mbxacc_read,
  5073. .write = lpfc_idiag_mbxacc_write,
  5074. .release = lpfc_idiag_cmd_release,
  5075. };
  5076. #undef lpfc_idiag_op_extAcc
  5077. static const struct file_operations lpfc_idiag_op_extAcc = {
  5078. .owner = THIS_MODULE,
  5079. .open = lpfc_idiag_open,
  5080. .llseek = lpfc_debugfs_lseek,
  5081. .read = lpfc_idiag_extacc_read,
  5082. .write = lpfc_idiag_extacc_write,
  5083. .release = lpfc_idiag_cmd_release,
  5084. };
  5085. #endif
  5086. /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
  5087. * @phba: Pointer to HBA context object.
  5088. * @dmabuf: Pointer to a DMA buffer descriptor.
  5089. *
  5090. * Description:
  5091. * This routine dump a bsg pass-through non-embedded mailbox command with
  5092. * external buffer.
  5093. **/
  5094. void
  5095. lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
  5096. enum mbox_type mbox_tp, enum dma_type dma_tp,
  5097. enum sta_type sta_tp,
  5098. struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
  5099. {
  5100. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5101. uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
  5102. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  5103. int len = 0;
  5104. uint32_t do_dump = 0;
  5105. uint32_t *pword;
  5106. uint32_t i;
  5107. if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
  5108. return;
  5109. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  5110. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  5111. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  5112. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  5113. if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
  5114. (*mbx_dump_cnt == 0) ||
  5115. (*mbx_word_cnt == 0))
  5116. return;
  5117. if (*mbx_mbox_cmd != 0x9B)
  5118. return;
  5119. if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
  5120. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
  5121. do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
  5122. pr_err("\nRead mbox command (x%x), "
  5123. "nemb:0x%x, extbuf_cnt:%d:\n",
  5124. sta_tp, nemb_tp, ext_buf);
  5125. }
  5126. }
  5127. if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
  5128. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
  5129. do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
  5130. pr_err("\nRead mbox buffer (x%x), "
  5131. "nemb:0x%x, extbuf_seq:%d:\n",
  5132. sta_tp, nemb_tp, ext_buf);
  5133. }
  5134. }
  5135. if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
  5136. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
  5137. do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
  5138. pr_err("\nWrite mbox command (x%x), "
  5139. "nemb:0x%x, extbuf_cnt:%d:\n",
  5140. sta_tp, nemb_tp, ext_buf);
  5141. }
  5142. }
  5143. if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
  5144. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
  5145. do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
  5146. pr_err("\nWrite mbox buffer (x%x), "
  5147. "nemb:0x%x, extbuf_seq:%d:\n",
  5148. sta_tp, nemb_tp, ext_buf);
  5149. }
  5150. }
  5151. /* dump buffer content */
  5152. if (do_dump) {
  5153. pword = (uint32_t *)dmabuf->virt;
  5154. for (i = 0; i < *mbx_word_cnt; i++) {
  5155. if (!(i % 8)) {
  5156. if (i != 0)
  5157. pr_err("%s\n", line_buf);
  5158. len = 0;
  5159. len += scnprintf(line_buf+len,
  5160. LPFC_MBX_ACC_LBUF_SZ-len,
  5161. "%03d: ", i);
  5162. }
  5163. len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  5164. "%08x ", (uint32_t)*pword);
  5165. pword++;
  5166. }
  5167. if ((i - 1) % 8)
  5168. pr_err("%s\n", line_buf);
  5169. (*mbx_dump_cnt)--;
  5170. }
  5171. /* Clean out command structure on reaching dump count */
  5172. if (*mbx_dump_cnt == 0)
  5173. memset(&idiag, 0, sizeof(idiag));
  5174. return;
  5175. #endif
  5176. }
  5177. /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
  5178. * @phba: Pointer to HBA context object.
  5179. * @dmabuf: Pointer to a DMA buffer descriptor.
  5180. *
  5181. * Description:
  5182. * This routine dump a pass-through non-embedded mailbox command from issue
  5183. * mailbox command.
  5184. **/
  5185. void
  5186. lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
  5187. {
  5188. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5189. uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
  5190. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  5191. int len = 0;
  5192. uint32_t *pword;
  5193. uint8_t *pbyte;
  5194. uint32_t i, j;
  5195. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
  5196. return;
  5197. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  5198. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  5199. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  5200. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  5201. if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
  5202. (*mbx_dump_cnt == 0) ||
  5203. (*mbx_word_cnt == 0))
  5204. return;
  5205. if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
  5206. (*mbx_mbox_cmd != pmbox->mbxCommand))
  5207. return;
  5208. /* dump buffer content */
  5209. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
  5210. pr_err("Mailbox command:0x%x dump by word:\n",
  5211. pmbox->mbxCommand);
  5212. pword = (uint32_t *)pmbox;
  5213. for (i = 0; i < *mbx_word_cnt; i++) {
  5214. if (!(i % 8)) {
  5215. if (i != 0)
  5216. pr_err("%s\n", line_buf);
  5217. len = 0;
  5218. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  5219. len += scnprintf(line_buf+len,
  5220. LPFC_MBX_ACC_LBUF_SZ-len,
  5221. "%03d: ", i);
  5222. }
  5223. len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  5224. "%08x ",
  5225. ((uint32_t)*pword) & 0xffffffff);
  5226. pword++;
  5227. }
  5228. if ((i - 1) % 8)
  5229. pr_err("%s\n", line_buf);
  5230. pr_err("\n");
  5231. }
  5232. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
  5233. pr_err("Mailbox command:0x%x dump by byte:\n",
  5234. pmbox->mbxCommand);
  5235. pbyte = (uint8_t *)pmbox;
  5236. for (i = 0; i < *mbx_word_cnt; i++) {
  5237. if (!(i % 8)) {
  5238. if (i != 0)
  5239. pr_err("%s\n", line_buf);
  5240. len = 0;
  5241. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  5242. len += scnprintf(line_buf+len,
  5243. LPFC_MBX_ACC_LBUF_SZ-len,
  5244. "%03d: ", i);
  5245. }
  5246. for (j = 0; j < 4; j++) {
  5247. len += scnprintf(line_buf+len,
  5248. LPFC_MBX_ACC_LBUF_SZ-len,
  5249. "%02x",
  5250. ((uint8_t)*pbyte) & 0xff);
  5251. pbyte++;
  5252. }
  5253. len += scnprintf(line_buf+len,
  5254. LPFC_MBX_ACC_LBUF_SZ-len, " ");
  5255. }
  5256. if ((i - 1) % 8)
  5257. pr_err("%s\n", line_buf);
  5258. pr_err("\n");
  5259. }
  5260. (*mbx_dump_cnt)--;
  5261. /* Clean out command structure on reaching dump count */
  5262. if (*mbx_dump_cnt == 0)
  5263. memset(&idiag, 0, sizeof(idiag));
  5264. return;
  5265. #endif
  5266. }
  5267. /**
  5268. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  5269. * @vport: The vport pointer to initialize.
  5270. *
  5271. * Description:
  5272. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  5273. * If not already created, this routine will create the lpfc directory, and
  5274. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  5275. * also create each file used to access lpfc specific debugfs information.
  5276. **/
  5277. inline void
  5278. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  5279. {
  5280. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5281. struct lpfc_hba *phba = vport->phba;
  5282. char name[64];
  5283. uint32_t num, i;
  5284. bool pport_setup = false;
  5285. if (!lpfc_debugfs_enable)
  5286. return;
  5287. /* Setup lpfc root directory */
  5288. if (!lpfc_debugfs_root) {
  5289. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  5290. atomic_set(&lpfc_debugfs_hba_count, 0);
  5291. }
  5292. if (!lpfc_debugfs_start_time)
  5293. lpfc_debugfs_start_time = jiffies;
  5294. /* Setup funcX directory for specific HBA PCI function */
  5295. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  5296. if (!phba->hba_debugfs_root) {
  5297. pport_setup = true;
  5298. phba->hba_debugfs_root =
  5299. debugfs_create_dir(name, lpfc_debugfs_root);
  5300. atomic_inc(&lpfc_debugfs_hba_count);
  5301. atomic_set(&phba->debugfs_vport_count, 0);
  5302. /* Multi-XRI pools */
  5303. snprintf(name, sizeof(name), "multixripools");
  5304. phba->debug_multixri_pools =
  5305. debugfs_create_file(name, S_IFREG | 0644,
  5306. phba->hba_debugfs_root,
  5307. phba,
  5308. &lpfc_debugfs_op_multixripools);
  5309. if (!phba->debug_multixri_pools) {
  5310. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5311. "0527 Cannot create debugfs multixripools\n");
  5312. goto debug_failed;
  5313. }
  5314. /* RAS log */
  5315. snprintf(name, sizeof(name), "ras_log");
  5316. phba->debug_ras_log =
  5317. debugfs_create_file(name, 0644,
  5318. phba->hba_debugfs_root,
  5319. phba, &lpfc_debugfs_ras_log);
  5320. if (!phba->debug_ras_log) {
  5321. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5322. "6148 Cannot create debugfs"
  5323. " ras_log\n");
  5324. goto debug_failed;
  5325. }
  5326. /* Setup hbqinfo */
  5327. snprintf(name, sizeof(name), "hbqinfo");
  5328. phba->debug_hbqinfo =
  5329. debugfs_create_file(name, S_IFREG | 0644,
  5330. phba->hba_debugfs_root,
  5331. phba, &lpfc_debugfs_op_hbqinfo);
  5332. #ifdef LPFC_HDWQ_LOCK_STAT
  5333. /* Setup lockstat */
  5334. snprintf(name, sizeof(name), "lockstat");
  5335. phba->debug_lockstat =
  5336. debugfs_create_file(name, S_IFREG | 0644,
  5337. phba->hba_debugfs_root,
  5338. phba, &lpfc_debugfs_op_lockstat);
  5339. if (!phba->debug_lockstat) {
  5340. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5341. "4610 Cant create debugfs lockstat\n");
  5342. goto debug_failed;
  5343. }
  5344. #endif
  5345. /* Setup dumpHBASlim */
  5346. if (phba->sli_rev < LPFC_SLI_REV4) {
  5347. snprintf(name, sizeof(name), "dumpHBASlim");
  5348. phba->debug_dumpHBASlim =
  5349. debugfs_create_file(name,
  5350. S_IFREG|S_IRUGO|S_IWUSR,
  5351. phba->hba_debugfs_root,
  5352. phba, &lpfc_debugfs_op_dumpHBASlim);
  5353. } else
  5354. phba->debug_dumpHBASlim = NULL;
  5355. /* Setup dumpHostSlim */
  5356. if (phba->sli_rev < LPFC_SLI_REV4) {
  5357. snprintf(name, sizeof(name), "dumpHostSlim");
  5358. phba->debug_dumpHostSlim =
  5359. debugfs_create_file(name,
  5360. S_IFREG|S_IRUGO|S_IWUSR,
  5361. phba->hba_debugfs_root,
  5362. phba, &lpfc_debugfs_op_dumpHostSlim);
  5363. } else
  5364. phba->debug_dumpHostSlim = NULL;
  5365. /* Setup DIF Error Injections */
  5366. snprintf(name, sizeof(name), "InjErrLBA");
  5367. phba->debug_InjErrLBA =
  5368. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5369. phba->hba_debugfs_root,
  5370. phba, &lpfc_debugfs_op_dif_err);
  5371. phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
  5372. snprintf(name, sizeof(name), "InjErrNPortID");
  5373. phba->debug_InjErrNPortID =
  5374. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5375. phba->hba_debugfs_root,
  5376. phba, &lpfc_debugfs_op_dif_err);
  5377. snprintf(name, sizeof(name), "InjErrWWPN");
  5378. phba->debug_InjErrWWPN =
  5379. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5380. phba->hba_debugfs_root,
  5381. phba, &lpfc_debugfs_op_dif_err);
  5382. snprintf(name, sizeof(name), "writeGuardInjErr");
  5383. phba->debug_writeGuard =
  5384. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5385. phba->hba_debugfs_root,
  5386. phba, &lpfc_debugfs_op_dif_err);
  5387. snprintf(name, sizeof(name), "writeAppInjErr");
  5388. phba->debug_writeApp =
  5389. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5390. phba->hba_debugfs_root,
  5391. phba, &lpfc_debugfs_op_dif_err);
  5392. snprintf(name, sizeof(name), "writeRefInjErr");
  5393. phba->debug_writeRef =
  5394. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5395. phba->hba_debugfs_root,
  5396. phba, &lpfc_debugfs_op_dif_err);
  5397. snprintf(name, sizeof(name), "readGuardInjErr");
  5398. phba->debug_readGuard =
  5399. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5400. phba->hba_debugfs_root,
  5401. phba, &lpfc_debugfs_op_dif_err);
  5402. snprintf(name, sizeof(name), "readAppInjErr");
  5403. phba->debug_readApp =
  5404. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5405. phba->hba_debugfs_root,
  5406. phba, &lpfc_debugfs_op_dif_err);
  5407. snprintf(name, sizeof(name), "readRefInjErr");
  5408. phba->debug_readRef =
  5409. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5410. phba->hba_debugfs_root,
  5411. phba, &lpfc_debugfs_op_dif_err);
  5412. /* Setup slow ring trace */
  5413. if (lpfc_debugfs_max_slow_ring_trc) {
  5414. num = lpfc_debugfs_max_slow_ring_trc - 1;
  5415. if (num & lpfc_debugfs_max_slow_ring_trc) {
  5416. /* Change to be a power of 2 */
  5417. num = lpfc_debugfs_max_slow_ring_trc;
  5418. i = 0;
  5419. while (num > 1) {
  5420. num = num >> 1;
  5421. i++;
  5422. }
  5423. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  5424. pr_err("lpfc_debugfs_max_disc_trc changed to "
  5425. "%d\n", lpfc_debugfs_max_disc_trc);
  5426. }
  5427. }
  5428. snprintf(name, sizeof(name), "slow_ring_trace");
  5429. phba->debug_slow_ring_trc =
  5430. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5431. phba->hba_debugfs_root,
  5432. phba, &lpfc_debugfs_op_slow_ring_trc);
  5433. if (!phba->slow_ring_trc) {
  5434. phba->slow_ring_trc = kmalloc(
  5435. (sizeof(struct lpfc_debugfs_trc) *
  5436. lpfc_debugfs_max_slow_ring_trc),
  5437. GFP_KERNEL);
  5438. if (!phba->slow_ring_trc) {
  5439. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5440. "0416 Cannot create debugfs "
  5441. "slow_ring buffer\n");
  5442. goto debug_failed;
  5443. }
  5444. atomic_set(&phba->slow_ring_trc_cnt, 0);
  5445. memset(phba->slow_ring_trc, 0,
  5446. (sizeof(struct lpfc_debugfs_trc) *
  5447. lpfc_debugfs_max_slow_ring_trc));
  5448. }
  5449. snprintf(name, sizeof(name), "nvmeio_trc");
  5450. phba->debug_nvmeio_trc =
  5451. debugfs_create_file(name, 0644,
  5452. phba->hba_debugfs_root,
  5453. phba, &lpfc_debugfs_op_nvmeio_trc);
  5454. atomic_set(&phba->nvmeio_trc_cnt, 0);
  5455. if (lpfc_debugfs_max_nvmeio_trc) {
  5456. num = lpfc_debugfs_max_nvmeio_trc - 1;
  5457. if (num & lpfc_debugfs_max_disc_trc) {
  5458. /* Change to be a power of 2 */
  5459. num = lpfc_debugfs_max_nvmeio_trc;
  5460. i = 0;
  5461. while (num > 1) {
  5462. num = num >> 1;
  5463. i++;
  5464. }
  5465. lpfc_debugfs_max_nvmeio_trc = (1 << i);
  5466. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5467. "0575 lpfc_debugfs_max_nvmeio_trc "
  5468. "changed to %d\n",
  5469. lpfc_debugfs_max_nvmeio_trc);
  5470. }
  5471. phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
  5472. /* Allocate trace buffer and initialize */
  5473. phba->nvmeio_trc = kzalloc(
  5474. (sizeof(struct lpfc_debugfs_nvmeio_trc) *
  5475. phba->nvmeio_trc_size), GFP_KERNEL);
  5476. if (!phba->nvmeio_trc) {
  5477. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5478. "0576 Cannot create debugfs "
  5479. "nvmeio_trc buffer\n");
  5480. goto nvmeio_off;
  5481. }
  5482. phba->nvmeio_trc_on = 1;
  5483. phba->nvmeio_trc_output_idx = 0;
  5484. phba->nvmeio_trc = NULL;
  5485. } else {
  5486. nvmeio_off:
  5487. phba->nvmeio_trc_size = 0;
  5488. phba->nvmeio_trc_on = 0;
  5489. phba->nvmeio_trc_output_idx = 0;
  5490. phba->nvmeio_trc = NULL;
  5491. }
  5492. }
  5493. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  5494. if (!vport->vport_debugfs_root) {
  5495. vport->vport_debugfs_root =
  5496. debugfs_create_dir(name, phba->hba_debugfs_root);
  5497. atomic_inc(&phba->debugfs_vport_count);
  5498. }
  5499. if (lpfc_debugfs_max_disc_trc) {
  5500. num = lpfc_debugfs_max_disc_trc - 1;
  5501. if (num & lpfc_debugfs_max_disc_trc) {
  5502. /* Change to be a power of 2 */
  5503. num = lpfc_debugfs_max_disc_trc;
  5504. i = 0;
  5505. while (num > 1) {
  5506. num = num >> 1;
  5507. i++;
  5508. }
  5509. lpfc_debugfs_max_disc_trc = (1 << i);
  5510. pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
  5511. lpfc_debugfs_max_disc_trc);
  5512. }
  5513. }
  5514. vport->disc_trc = kzalloc(
  5515. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  5516. GFP_KERNEL);
  5517. if (!vport->disc_trc) {
  5518. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5519. "0418 Cannot create debugfs disc trace "
  5520. "buffer\n");
  5521. goto debug_failed;
  5522. }
  5523. atomic_set(&vport->disc_trc_cnt, 0);
  5524. snprintf(name, sizeof(name), "discovery_trace");
  5525. vport->debug_disc_trc =
  5526. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5527. vport->vport_debugfs_root,
  5528. vport, &lpfc_debugfs_op_disc_trc);
  5529. snprintf(name, sizeof(name), "nodelist");
  5530. vport->debug_nodelist =
  5531. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5532. vport->vport_debugfs_root,
  5533. vport, &lpfc_debugfs_op_nodelist);
  5534. snprintf(name, sizeof(name), "nvmestat");
  5535. vport->debug_nvmestat =
  5536. debugfs_create_file(name, 0644,
  5537. vport->vport_debugfs_root,
  5538. vport, &lpfc_debugfs_op_nvmestat);
  5539. snprintf(name, sizeof(name), "scsistat");
  5540. vport->debug_scsistat =
  5541. debugfs_create_file(name, 0644,
  5542. vport->vport_debugfs_root,
  5543. vport, &lpfc_debugfs_op_scsistat);
  5544. if (!vport->debug_scsistat) {
  5545. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5546. "4611 Cannot create debugfs scsistat\n");
  5547. goto debug_failed;
  5548. }
  5549. snprintf(name, sizeof(name), "ioktime");
  5550. vport->debug_ioktime =
  5551. debugfs_create_file(name, 0644,
  5552. vport->vport_debugfs_root,
  5553. vport, &lpfc_debugfs_op_ioktime);
  5554. if (!vport->debug_ioktime) {
  5555. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5556. "0815 Cannot create debugfs ioktime\n");
  5557. goto debug_failed;
  5558. }
  5559. snprintf(name, sizeof(name), "hdwqstat");
  5560. vport->debug_hdwqstat =
  5561. debugfs_create_file(name, 0644,
  5562. vport->vport_debugfs_root,
  5563. vport, &lpfc_debugfs_op_hdwqstat);
  5564. /*
  5565. * The following section is for additional directories/files for the
  5566. * physical port.
  5567. */
  5568. if (!pport_setup)
  5569. goto debug_failed;
  5570. /*
  5571. * iDiag debugfs root entry points for SLI4 device only
  5572. */
  5573. if (phba->sli_rev < LPFC_SLI_REV4)
  5574. goto debug_failed;
  5575. snprintf(name, sizeof(name), "iDiag");
  5576. if (!phba->idiag_root) {
  5577. phba->idiag_root =
  5578. debugfs_create_dir(name, phba->hba_debugfs_root);
  5579. /* Initialize iDiag data structure */
  5580. memset(&idiag, 0, sizeof(idiag));
  5581. }
  5582. /* iDiag read PCI config space */
  5583. snprintf(name, sizeof(name), "pciCfg");
  5584. if (!phba->idiag_pci_cfg) {
  5585. phba->idiag_pci_cfg =
  5586. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5587. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  5588. idiag.offset.last_rd = 0;
  5589. }
  5590. /* iDiag PCI BAR access */
  5591. snprintf(name, sizeof(name), "barAcc");
  5592. if (!phba->idiag_bar_acc) {
  5593. phba->idiag_bar_acc =
  5594. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5595. phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
  5596. idiag.offset.last_rd = 0;
  5597. }
  5598. /* iDiag get PCI function queue information */
  5599. snprintf(name, sizeof(name), "queInfo");
  5600. if (!phba->idiag_que_info) {
  5601. phba->idiag_que_info =
  5602. debugfs_create_file(name, S_IFREG|S_IRUGO,
  5603. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  5604. }
  5605. /* iDiag access PCI function queue */
  5606. snprintf(name, sizeof(name), "queAcc");
  5607. if (!phba->idiag_que_acc) {
  5608. phba->idiag_que_acc =
  5609. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5610. phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
  5611. }
  5612. /* iDiag access PCI function doorbell registers */
  5613. snprintf(name, sizeof(name), "drbAcc");
  5614. if (!phba->idiag_drb_acc) {
  5615. phba->idiag_drb_acc =
  5616. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5617. phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
  5618. }
  5619. /* iDiag access PCI function control registers */
  5620. snprintf(name, sizeof(name), "ctlAcc");
  5621. if (!phba->idiag_ctl_acc) {
  5622. phba->idiag_ctl_acc =
  5623. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5624. phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
  5625. }
  5626. /* iDiag access mbox commands */
  5627. snprintf(name, sizeof(name), "mbxAcc");
  5628. if (!phba->idiag_mbx_acc) {
  5629. phba->idiag_mbx_acc =
  5630. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5631. phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
  5632. }
  5633. /* iDiag extents access commands */
  5634. if (phba->sli4_hba.extents_in_use) {
  5635. snprintf(name, sizeof(name), "extAcc");
  5636. if (!phba->idiag_ext_acc) {
  5637. phba->idiag_ext_acc =
  5638. debugfs_create_file(name,
  5639. S_IFREG|S_IRUGO|S_IWUSR,
  5640. phba->idiag_root, phba,
  5641. &lpfc_idiag_op_extAcc);
  5642. }
  5643. }
  5644. debug_failed:
  5645. return;
  5646. #endif
  5647. }
  5648. /**
  5649. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  5650. * @vport: The vport pointer to remove from debugfs.
  5651. *
  5652. * Description:
  5653. * When Debugfs is configured this routine removes debugfs file system elements
  5654. * that are specific to this vport. It also checks to see if there are any
  5655. * users left for the debugfs directories associated with the HBA and driver. If
  5656. * this is the last user of the HBA directory or driver directory then it will
  5657. * remove those from the debugfs infrastructure as well.
  5658. **/
  5659. inline void
  5660. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  5661. {
  5662. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5663. struct lpfc_hba *phba = vport->phba;
  5664. kfree(vport->disc_trc);
  5665. vport->disc_trc = NULL;
  5666. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  5667. vport->debug_disc_trc = NULL;
  5668. debugfs_remove(vport->debug_nodelist); /* nodelist */
  5669. vport->debug_nodelist = NULL;
  5670. debugfs_remove(vport->debug_nvmestat); /* nvmestat */
  5671. vport->debug_nvmestat = NULL;
  5672. debugfs_remove(vport->debug_scsistat); /* scsistat */
  5673. vport->debug_scsistat = NULL;
  5674. debugfs_remove(vport->debug_ioktime); /* ioktime */
  5675. vport->debug_ioktime = NULL;
  5676. debugfs_remove(vport->debug_hdwqstat); /* hdwqstat */
  5677. vport->debug_hdwqstat = NULL;
  5678. if (vport->vport_debugfs_root) {
  5679. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  5680. vport->vport_debugfs_root = NULL;
  5681. atomic_dec(&phba->debugfs_vport_count);
  5682. }
  5683. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  5684. debugfs_remove(phba->debug_multixri_pools); /* multixripools*/
  5685. phba->debug_multixri_pools = NULL;
  5686. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  5687. phba->debug_hbqinfo = NULL;
  5688. debugfs_remove(phba->debug_ras_log);
  5689. phba->debug_ras_log = NULL;
  5690. #ifdef LPFC_HDWQ_LOCK_STAT
  5691. debugfs_remove(phba->debug_lockstat); /* lockstat */
  5692. phba->debug_lockstat = NULL;
  5693. #endif
  5694. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  5695. phba->debug_dumpHBASlim = NULL;
  5696. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  5697. phba->debug_dumpHostSlim = NULL;
  5698. debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
  5699. phba->debug_InjErrLBA = NULL;
  5700. debugfs_remove(phba->debug_InjErrNPortID);
  5701. phba->debug_InjErrNPortID = NULL;
  5702. debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
  5703. phba->debug_InjErrWWPN = NULL;
  5704. debugfs_remove(phba->debug_writeGuard); /* writeGuard */
  5705. phba->debug_writeGuard = NULL;
  5706. debugfs_remove(phba->debug_writeApp); /* writeApp */
  5707. phba->debug_writeApp = NULL;
  5708. debugfs_remove(phba->debug_writeRef); /* writeRef */
  5709. phba->debug_writeRef = NULL;
  5710. debugfs_remove(phba->debug_readGuard); /* readGuard */
  5711. phba->debug_readGuard = NULL;
  5712. debugfs_remove(phba->debug_readApp); /* readApp */
  5713. phba->debug_readApp = NULL;
  5714. debugfs_remove(phba->debug_readRef); /* readRef */
  5715. phba->debug_readRef = NULL;
  5716. kfree(phba->slow_ring_trc);
  5717. phba->slow_ring_trc = NULL;
  5718. /* slow_ring_trace */
  5719. debugfs_remove(phba->debug_slow_ring_trc);
  5720. phba->debug_slow_ring_trc = NULL;
  5721. debugfs_remove(phba->debug_nvmeio_trc);
  5722. phba->debug_nvmeio_trc = NULL;
  5723. kfree(phba->nvmeio_trc);
  5724. phba->nvmeio_trc = NULL;
  5725. /*
  5726. * iDiag release
  5727. */
  5728. if (phba->sli_rev == LPFC_SLI_REV4) {
  5729. /* iDiag extAcc */
  5730. debugfs_remove(phba->idiag_ext_acc);
  5731. phba->idiag_ext_acc = NULL;
  5732. /* iDiag mbxAcc */
  5733. debugfs_remove(phba->idiag_mbx_acc);
  5734. phba->idiag_mbx_acc = NULL;
  5735. /* iDiag ctlAcc */
  5736. debugfs_remove(phba->idiag_ctl_acc);
  5737. phba->idiag_ctl_acc = NULL;
  5738. /* iDiag drbAcc */
  5739. debugfs_remove(phba->idiag_drb_acc);
  5740. phba->idiag_drb_acc = NULL;
  5741. /* iDiag queAcc */
  5742. debugfs_remove(phba->idiag_que_acc);
  5743. phba->idiag_que_acc = NULL;
  5744. /* iDiag queInfo */
  5745. debugfs_remove(phba->idiag_que_info);
  5746. phba->idiag_que_info = NULL;
  5747. /* iDiag barAcc */
  5748. debugfs_remove(phba->idiag_bar_acc);
  5749. phba->idiag_bar_acc = NULL;
  5750. /* iDiag pciCfg */
  5751. debugfs_remove(phba->idiag_pci_cfg);
  5752. phba->idiag_pci_cfg = NULL;
  5753. /* Finally remove the iDiag debugfs root */
  5754. debugfs_remove(phba->idiag_root);
  5755. phba->idiag_root = NULL;
  5756. }
  5757. if (phba->hba_debugfs_root) {
  5758. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  5759. phba->hba_debugfs_root = NULL;
  5760. atomic_dec(&lpfc_debugfs_hba_count);
  5761. }
  5762. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  5763. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  5764. lpfc_debugfs_root = NULL;
  5765. }
  5766. }
  5767. #endif
  5768. return;
  5769. }
  5770. /*
  5771. * Driver debug utility routines outside of debugfs. The debug utility
  5772. * routines implemented here is intended to be used in the instrumented
  5773. * debug driver for debugging host or port issues.
  5774. */
  5775. /**
  5776. * lpfc_debug_dump_all_queues - dump all the queues with a hba
  5777. * @phba: Pointer to HBA context object.
  5778. *
  5779. * This function dumps entries of all the queues asociated with the @phba.
  5780. **/
  5781. void
  5782. lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
  5783. {
  5784. int idx;
  5785. /*
  5786. * Dump Work Queues (WQs)
  5787. */
  5788. lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
  5789. lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
  5790. lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
  5791. for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
  5792. lpfc_debug_dump_wq(phba, DUMP_IO, idx);
  5793. lpfc_debug_dump_hdr_rq(phba);
  5794. lpfc_debug_dump_dat_rq(phba);
  5795. /*
  5796. * Dump Complete Queues (CQs)
  5797. */
  5798. lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
  5799. lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
  5800. lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
  5801. for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
  5802. lpfc_debug_dump_cq(phba, DUMP_IO, idx);
  5803. /*
  5804. * Dump Event Queues (EQs)
  5805. */
  5806. for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
  5807. lpfc_debug_dump_hba_eq(phba, idx);
  5808. }