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. *
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 *******************************************************************/
23 #include <linux/blkdev.h>
24 #include <linux/delay.h>
25 #include <linux/module.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/idr.h>
28 #include <linux/interrupt.h>
29 #include <linux/kthread.h>
30 #include <linux/slab.h>
31 #include <linux/pci.h>
32 #include <linux/spinlock.h>
33 #include <linux/ctype.h>
34 #include <linux/vmalloc.h>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_device.h>
38 #include <scsi/scsi_host.h>
39 #include <scsi/scsi_transport_fc.h>
40 #include <scsi/fc/fc_fs.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_logmsg.h"
52 #include "lpfc_crtn.h"
53 #include "lpfc_vport.h"
54 #include "lpfc_version.h"
55 #include "lpfc_compat.h"
56 #include "lpfc_debugfs.h"
59 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
63 * To access this interface the user should:
64 * # mount -t debugfs none /sys/kernel/debug
66 * The lpfc debugfs directory hierarchy is:
67 * /sys/kernel/debug/lpfc/fnX/vportY
68 * where X is the lpfc hba function unique_id
69 * where Y is the vport VPI on that hba
71 * Debugging services available per vport:
73 * This is an ACSII readable file that contains a trace of the last
74 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
75 * See lpfc_debugfs.h for different categories of discovery events.
76 * To enable the discovery trace, the following module parameters must be set:
77 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
78 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
79 * EACH vport. X MUST also be a power of 2.
80 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
84 * This is an ACSII readable file that contains a trace of the last
85 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
86 * To enable the slow ring trace, the following module parameters must be set:
87 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
88 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
89 * the HBA. X MUST also be a power of 2.
91 static int lpfc_debugfs_enable = 1;
92 module_param(lpfc_debugfs_enable, int, S_IRUGO);
93 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
95 /* This MUST be a power of 2 */
96 static int lpfc_debugfs_max_disc_trc;
97 module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
98 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
99 "Set debugfs discovery trace depth");
101 /* This MUST be a power of 2 */
102 static int lpfc_debugfs_max_slow_ring_trc;
103 module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
104 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
105 "Set debugfs slow ring trace depth");
107 /* This MUST be a power of 2 */
108 static int lpfc_debugfs_max_nvmeio_trc;
109 module_param(lpfc_debugfs_max_nvmeio_trc, int, 0444);
110 MODULE_PARM_DESC(lpfc_debugfs_max_nvmeio_trc,
111 "Set debugfs NVME IO trace depth");
113 static int lpfc_debugfs_mask_disc_trc;
114 module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
115 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
116 "Set debugfs discovery trace mask");
118 #include <linux/debugfs.h>
120 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
121 static unsigned long lpfc_debugfs_start_time = 0L;
124 static struct lpfc_idiag idiag;
127 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
128 * @vport: The vport to gather the log info from.
129 * @buf: The buffer to dump log into.
130 * @size: The maximum amount of data to process.
133 * This routine gathers the lpfc discovery debugfs data from the @vport and
134 * dumps it to @buf up to @size number of bytes. It will start at the next entry
135 * in the log and process the log until the end of the buffer. Then it will
136 * gather from the beginning of the log and process until the current entry.
139 * Discovery logging will be disabled while while this routine dumps the log.
142 * This routine returns the amount of bytes that were dumped into @buf and will
146 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
148 int i, index, len, enable;
150 struct lpfc_debugfs_trc *dtp;
153 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
157 enable = lpfc_debugfs_enable;
158 lpfc_debugfs_enable = 0;
161 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
162 (lpfc_debugfs_max_disc_trc - 1);
163 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
164 dtp = vport->disc_trc + i;
167 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
169 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
170 dtp->seq_cnt, ms, dtp->fmt);
171 len += scnprintf(buf+len, size-len, buffer,
172 dtp->data1, dtp->data2, dtp->data3);
174 for (i = 0; i < index; i++) {
175 dtp = vport->disc_trc + i;
178 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
180 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
181 dtp->seq_cnt, ms, dtp->fmt);
182 len += scnprintf(buf+len, size-len, buffer,
183 dtp->data1, dtp->data2, dtp->data3);
186 lpfc_debugfs_enable = enable;
193 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
194 * @phba: The HBA to gather the log info from.
195 * @buf: The buffer to dump log into.
196 * @size: The maximum amount of data to process.
199 * This routine gathers the lpfc slow ring debugfs data from the @phba and
200 * dumps it to @buf up to @size number of bytes. It will start at the next entry
201 * in the log and process the log until the end of the buffer. Then it will
202 * gather from the beginning of the log and process until the current entry.
205 * Slow ring logging will be disabled while while this routine dumps the log.
208 * This routine returns the amount of bytes that were dumped into @buf and will
212 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
214 int i, index, len, enable;
216 struct lpfc_debugfs_trc *dtp;
219 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
223 enable = lpfc_debugfs_enable;
224 lpfc_debugfs_enable = 0;
227 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
228 (lpfc_debugfs_max_slow_ring_trc - 1);
229 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
230 dtp = phba->slow_ring_trc + i;
233 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
235 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
236 dtp->seq_cnt, ms, dtp->fmt);
237 len += scnprintf(buf+len, size-len, buffer,
238 dtp->data1, dtp->data2, dtp->data3);
240 for (i = 0; i < index; i++) {
241 dtp = phba->slow_ring_trc + i;
244 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
246 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
247 dtp->seq_cnt, ms, dtp->fmt);
248 len += scnprintf(buf+len, size-len, buffer,
249 dtp->data1, dtp->data2, dtp->data3);
252 lpfc_debugfs_enable = enable;
258 static int lpfc_debugfs_last_hbq = -1;
261 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
262 * @phba: The HBA to gather host buffer info from.
263 * @buf: The buffer to dump log into.
264 * @size: The maximum amount of data to process.
267 * This routine dumps the host buffer queue info from the @phba to @buf up to
268 * @size number of bytes. A header that describes the current hbq state will be
269 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
270 * until @size bytes have been dumped or all the hbq info has been dumped.
273 * This routine will rotate through each configured HBQ each time called.
276 * This routine returns the amount of bytes that were dumped into @buf and will
280 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
283 int i, j, found, posted, low;
284 uint32_t phys, raw_index, getidx;
285 struct lpfc_hbq_init *hip;
287 struct lpfc_hbq_entry *hbqe;
288 struct lpfc_dmabuf *d_buf;
289 struct hbq_dmabuf *hbq_buf;
291 if (phba->sli_rev != 3)
294 spin_lock_irq(&phba->hbalock);
296 /* toggle between multiple hbqs, if any */
297 i = lpfc_sli_hbq_count();
299 lpfc_debugfs_last_hbq++;
300 if (lpfc_debugfs_last_hbq >= i)
301 lpfc_debugfs_last_hbq = 0;
304 lpfc_debugfs_last_hbq = 0;
306 i = lpfc_debugfs_last_hbq;
308 len += scnprintf(buf+len, size-len, "HBQ %d Info\n", i);
310 hbqs = &phba->hbqs[i];
312 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
315 hip = lpfc_hbq_defs[i];
316 len += scnprintf(buf+len, size-len,
317 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
318 hip->hbq_index, hip->profile, hip->rn,
319 hip->buffer_count, hip->init_count, hip->add_count, posted);
321 raw_index = phba->hbq_get[i];
322 getidx = le32_to_cpu(raw_index);
323 len += scnprintf(buf+len, size-len,
324 "entries:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
325 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
326 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
328 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
329 for (j=0; j<hbqs->entry_count; j++) {
330 len += scnprintf(buf+len, size-len,
331 "%03d: %08x %04x %05x ", j,
332 le32_to_cpu(hbqe->bde.addrLow),
333 le32_to_cpu(hbqe->bde.tus.w),
334 le32_to_cpu(hbqe->buffer_tag));
338 /* First calculate if slot has an associated posted buffer */
339 low = hbqs->hbqPutIdx - posted;
341 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
342 len += scnprintf(buf + len, size - len,
348 if ((j >= hbqs->hbqPutIdx) &&
349 (j < (hbqs->entry_count+low))) {
350 len += scnprintf(buf + len, size - len,
356 /* Get the Buffer info for the posted buffer */
357 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
358 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
359 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
360 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
361 len += scnprintf(buf+len, size-len,
362 "Buf%d: x%px %06x\n", i,
363 hbq_buf->dbuf.virt, hbq_buf->tag);
370 len += scnprintf(buf+len, size-len, "No DMAinfo?\n");
374 if (len > LPFC_HBQINFO_SIZE - 54)
377 spin_unlock_irq(&phba->hbalock);
381 static int lpfc_debugfs_last_xripool;
384 * lpfc_debugfs_common_xri_data - Dump Hardware Queue info to a buffer
385 * @phba: The HBA to gather host buffer info from.
386 * @buf: The buffer to dump log into.
387 * @size: The maximum amount of data to process.
390 * This routine dumps the Hardware Queue info from the @phba to @buf up to
391 * @size number of bytes. A header that describes the current hdwq state will be
392 * dumped to @buf first and then info on each hdwq entry will be dumped to @buf
393 * until @size bytes have been dumped or all the hdwq info has been dumped.
396 * This routine will rotate through each configured Hardware Queue each
400 * This routine returns the amount of bytes that were dumped into @buf and will
404 lpfc_debugfs_commonxripools_data(struct lpfc_hba *phba, char *buf, int size)
406 struct lpfc_sli4_hdw_queue *qp;
411 for (i = 0; i < phba->cfg_hdw_queue; i++) {
412 if (len > (LPFC_DUMP_MULTIXRIPOOL_SIZE - 80))
414 qp = &phba->sli4_hba.hdwq[lpfc_debugfs_last_xripool];
416 len += scnprintf(buf + len, size - len, "HdwQ %d Info ", i);
417 spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag);
418 spin_lock(&qp->io_buf_list_get_lock);
419 spin_lock(&qp->io_buf_list_put_lock);
420 out = qp->total_io_bufs - (qp->get_io_bufs + qp->put_io_bufs +
421 qp->abts_scsi_io_bufs + qp->abts_nvme_io_bufs);
422 len += scnprintf(buf + len, size - len,
423 "tot:%d get:%d put:%d mt:%d "
424 "ABTS scsi:%d nvme:%d Out:%d\n",
425 qp->total_io_bufs, qp->get_io_bufs, qp->put_io_bufs,
426 qp->empty_io_bufs, qp->abts_scsi_io_bufs,
427 qp->abts_nvme_io_bufs, out);
428 spin_unlock(&qp->io_buf_list_put_lock);
429 spin_unlock(&qp->io_buf_list_get_lock);
430 spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag);
432 lpfc_debugfs_last_xripool++;
433 if (lpfc_debugfs_last_xripool >= phba->cfg_hdw_queue)
434 lpfc_debugfs_last_xripool = 0;
441 * lpfc_debugfs_multixripools_data - Display multi-XRI pools information
442 * @phba: The HBA to gather host buffer info from.
443 * @buf: The buffer to dump log into.
444 * @size: The maximum amount of data to process.
447 * This routine displays current multi-XRI pools information including XRI
448 * count in public, private and txcmplq. It also displays current high and
452 * This routine returns the amount of bytes that were dumped into @buf and will
456 lpfc_debugfs_multixripools_data(struct lpfc_hba *phba, char *buf, int size)
460 struct lpfc_sli4_hdw_queue *qp;
461 struct lpfc_multixri_pool *multixri_pool;
462 struct lpfc_pvt_pool *pvt_pool;
463 struct lpfc_pbl_pool *pbl_pool;
465 char tmp[LPFC_DEBUG_OUT_LINE_SZ] = {0};
467 if (phba->sli_rev != LPFC_SLI_REV4)
470 if (!phba->sli4_hba.hdwq)
473 if (!phba->cfg_xri_rebalancing) {
474 i = lpfc_debugfs_commonxripools_data(phba, buf, size);
479 * Pbl: Current number of free XRIs in public pool
480 * Pvt: Current number of free XRIs in private pool
481 * Busy: Current number of outstanding XRIs
482 * HWM: Current high watermark
483 * pvt_empty: Incremented by 1 when IO submission fails (no xri)
484 * pbl_empty: Incremented by 1 when all pbl_pool are empty during
487 scnprintf(tmp, sizeof(tmp),
488 "HWQ: Pbl Pvt Busy HWM | pvt_empty pbl_empty ");
489 if (strlcat(buf, tmp, size) >= size)
490 return strnlen(buf, size);
494 * MAXH: Max high watermark seen so far
495 * above_lmt: Incremented by 1 if xri_owned > xri_limit during
497 * below_lmt: Incremented by 1 if xri_owned <= xri_limit during
499 * locPbl_hit: Incremented by 1 if successfully get a batch of XRI from
501 * othPbl_hit: Incremented by 1 if successfully get a batch of XRI from
504 scnprintf(tmp, sizeof(tmp),
505 "MAXH above_lmt below_lmt locPbl_hit othPbl_hit");
506 if (strlcat(buf, tmp, size) >= size)
507 return strnlen(buf, size);
510 * sPbl: snapshot of Pbl 15 sec after stat gets cleared
511 * sPvt: snapshot of Pvt 15 sec after stat gets cleared
512 * sBusy: snapshot of Busy 15 sec after stat gets cleared
514 scnprintf(tmp, sizeof(tmp),
515 " | sPbl sPvt sBusy");
516 if (strlcat(buf, tmp, size) >= size)
517 return strnlen(buf, size);
520 scnprintf(tmp, sizeof(tmp), "\n");
521 if (strlcat(buf, tmp, size) >= size)
522 return strnlen(buf, size);
524 hwq_count = phba->cfg_hdw_queue;
525 for (i = 0; i < hwq_count; i++) {
526 qp = &phba->sli4_hba.hdwq[i];
527 multixri_pool = qp->p_multixri_pool;
530 pbl_pool = &multixri_pool->pbl_pool;
531 pvt_pool = &multixri_pool->pvt_pool;
532 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
534 scnprintf(tmp, sizeof(tmp),
535 "%03d: %4d %4d %4d %4d | %10d %10d ",
536 i, pbl_pool->count, pvt_pool->count,
537 txcmplq_cnt, pvt_pool->high_watermark,
538 qp->empty_io_bufs, multixri_pool->pbl_empty_count);
539 if (strlcat(buf, tmp, size) >= size)
543 scnprintf(tmp, sizeof(tmp),
544 "%4d %10d %10d %10d %10d",
545 multixri_pool->stat_max_hwm,
546 multixri_pool->above_limit_count,
547 multixri_pool->below_limit_count,
548 multixri_pool->local_pbl_hit_count,
549 multixri_pool->other_pbl_hit_count);
550 if (strlcat(buf, tmp, size) >= size)
553 scnprintf(tmp, sizeof(tmp),
555 multixri_pool->stat_pbl_count,
556 multixri_pool->stat_pvt_count,
557 multixri_pool->stat_busy_count);
558 if (strlcat(buf, tmp, size) >= size)
562 scnprintf(tmp, sizeof(tmp), "\n");
563 if (strlcat(buf, tmp, size) >= size)
566 return strnlen(buf, size);
570 #ifdef LPFC_HDWQ_LOCK_STAT
571 static int lpfc_debugfs_last_lock;
574 * lpfc_debugfs_lockstat_data - Dump Hardware Queue info to a buffer
575 * @phba: The HBA to gather host buffer info from.
576 * @buf: The buffer to dump log into.
577 * @size: The maximum amount of data to process.
580 * This routine dumps the Hardware Queue info from the @phba to @buf up to
581 * @size number of bytes. A header that describes the current hdwq state will be
582 * dumped to @buf first and then info on each hdwq entry will be dumped to @buf
583 * until @size bytes have been dumped or all the hdwq info has been dumped.
586 * This routine will rotate through each configured Hardware Queue each
590 * This routine returns the amount of bytes that were dumped into @buf and will
594 lpfc_debugfs_lockstat_data(struct lpfc_hba *phba, char *buf, int size)
596 struct lpfc_sli4_hdw_queue *qp;
600 if (phba->sli_rev != LPFC_SLI_REV4)
603 if (!phba->sli4_hba.hdwq)
606 for (i = 0; i < phba->cfg_hdw_queue; i++) {
607 if (len > (LPFC_HDWQINFO_SIZE - 100))
609 qp = &phba->sli4_hba.hdwq[lpfc_debugfs_last_lock];
611 len += scnprintf(buf + len, size - len, "HdwQ %03d Lock ", i);
612 if (phba->cfg_xri_rebalancing) {
613 len += scnprintf(buf + len, size - len,
614 "get_pvt:%d mv_pvt:%d "
615 "mv2pub:%d mv2pvt:%d "
616 "put_pvt:%d put_pub:%d wq:%d\n",
617 qp->lock_conflict.alloc_pvt_pool,
618 qp->lock_conflict.mv_from_pvt_pool,
619 qp->lock_conflict.mv_to_pub_pool,
620 qp->lock_conflict.mv_to_pvt_pool,
621 qp->lock_conflict.free_pvt_pool,
622 qp->lock_conflict.free_pub_pool,
623 qp->lock_conflict.wq_access);
625 len += scnprintf(buf + len, size - len,
626 "get:%d put:%d free:%d wq:%d\n",
627 qp->lock_conflict.alloc_xri_get,
628 qp->lock_conflict.alloc_xri_put,
629 qp->lock_conflict.free_xri,
630 qp->lock_conflict.wq_access);
633 lpfc_debugfs_last_lock++;
634 if (lpfc_debugfs_last_lock >= phba->cfg_hdw_queue)
635 lpfc_debugfs_last_lock = 0;
642 static int lpfc_debugfs_last_hba_slim_off;
645 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
646 * @phba: The HBA to gather SLIM info from.
647 * @buf: The buffer to dump log into.
648 * @size: The maximum amount of data to process.
651 * This routine dumps the current contents of HBA SLIM for the HBA associated
652 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
655 * This routine will only dump up to 1024 bytes of data each time called and
656 * should be called multiple times to dump the entire HBA SLIM.
659 * This routine returns the amount of bytes that were dumped into @buf and will
663 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
670 buffer = kmalloc(1024, GFP_KERNEL);
675 spin_lock_irq(&phba->hbalock);
677 len += scnprintf(buf+len, size-len, "HBA SLIM\n");
678 lpfc_memcpy_from_slim(buffer,
679 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
681 ptr = (uint32_t *)&buffer[0];
682 off = lpfc_debugfs_last_hba_slim_off;
684 /* Set it up for the next time */
685 lpfc_debugfs_last_hba_slim_off += 1024;
686 if (lpfc_debugfs_last_hba_slim_off >= 4096)
687 lpfc_debugfs_last_hba_slim_off = 0;
691 len += scnprintf(buf+len, size-len,
692 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
693 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
694 *(ptr+5), *(ptr+6), *(ptr+7));
696 i -= (8 * sizeof(uint32_t));
697 off += (8 * sizeof(uint32_t));
700 spin_unlock_irq(&phba->hbalock);
707 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
708 * @phba: The HBA to gather Host SLIM info from.
709 * @buf: The buffer to dump log into.
710 * @size: The maximum amount of data to process.
713 * This routine dumps the current contents of host SLIM for the host associated
714 * with @phba to @buf up to @size bytes of data. The dump will contain the
715 * Mailbox, PCB, Rings, and Registers that are located in host memory.
718 * This routine returns the amount of bytes that were dumped into @buf and will
722 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
726 uint32_t word0, word1, word2, word3;
728 struct lpfc_pgp *pgpp;
729 struct lpfc_sli *psli = &phba->sli;
730 struct lpfc_sli_ring *pring;
733 spin_lock_irq(&phba->hbalock);
735 len += scnprintf(buf+len, size-len, "SLIM Mailbox\n");
736 ptr = (uint32_t *)phba->slim2p.virt;
737 i = sizeof(MAILBOX_t);
739 len += scnprintf(buf+len, size-len,
740 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
741 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
742 *(ptr+5), *(ptr+6), *(ptr+7));
744 i -= (8 * sizeof(uint32_t));
745 off += (8 * sizeof(uint32_t));
748 len += scnprintf(buf+len, size-len, "SLIM PCB\n");
749 ptr = (uint32_t *)phba->pcb;
752 len += scnprintf(buf+len, size-len,
753 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
754 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
755 *(ptr+5), *(ptr+6), *(ptr+7));
757 i -= (8 * sizeof(uint32_t));
758 off += (8 * sizeof(uint32_t));
761 if (phba->sli_rev <= LPFC_SLI_REV3) {
762 for (i = 0; i < 4; i++) {
763 pgpp = &phba->port_gp[i];
764 pring = &psli->sli3_ring[i];
765 len += scnprintf(buf+len, size-len,
766 "Ring %d: CMD GetInx:%d "
769 "RSP PutInx:%d Max:%d\n",
771 pring->sli.sli3.numCiocb,
772 pring->sli.sli3.next_cmdidx,
773 pring->sli.sli3.local_getidx,
774 pring->flag, pgpp->rspPutInx,
775 pring->sli.sli3.numRiocb);
778 word0 = readl(phba->HAregaddr);
779 word1 = readl(phba->CAregaddr);
780 word2 = readl(phba->HSregaddr);
781 word3 = readl(phba->HCregaddr);
782 len += scnprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
783 "HC:%08x\n", word0, word1, word2, word3);
785 spin_unlock_irq(&phba->hbalock);
790 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
791 * @vport: The vport to gather target node info from.
792 * @buf: The buffer to dump log into.
793 * @size: The maximum amount of data to process.
796 * This routine dumps the current target node list associated with @vport to
797 * @buf up to @size bytes of data. Each node entry in the dump will contain a
798 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
801 * This routine returns the amount of bytes that were dumped into @buf and will
805 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
808 int i, iocnt, outio, cnt;
809 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
810 struct lpfc_hba *phba = vport->phba;
811 struct lpfc_nodelist *ndlp;
812 unsigned char *statep;
813 struct nvme_fc_local_port *localport;
814 struct nvme_fc_remote_port *nrport = NULL;
815 struct lpfc_nvme_rport *rport;
817 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
820 len += scnprintf(buf+len, size-len, "\nFCP Nodelist Entries ...\n");
821 spin_lock_irq(shost->host_lock);
822 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
825 len += scnprintf(buf+len, size-len,
826 "Missing Nodelist Entries\n");
830 switch (ndlp->nlp_state) {
831 case NLP_STE_UNUSED_NODE:
834 case NLP_STE_PLOGI_ISSUE:
837 case NLP_STE_ADISC_ISSUE:
840 case NLP_STE_REG_LOGIN_ISSUE:
843 case NLP_STE_PRLI_ISSUE:
846 case NLP_STE_LOGO_ISSUE:
849 case NLP_STE_UNMAPPED_NODE:
853 case NLP_STE_MAPPED_NODE:
857 case NLP_STE_NPR_NODE:
863 len += scnprintf(buf+len, size-len, "%s DID:x%06x ",
864 statep, ndlp->nlp_DID);
865 len += scnprintf(buf+len, size-len,
867 wwn_to_u64(ndlp->nlp_portname.u.wwn));
868 len += scnprintf(buf+len, size-len,
870 wwn_to_u64(ndlp->nlp_nodename.u.wwn));
871 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
872 len += scnprintf(buf+len, size-len, "RPI:%03d ",
875 len += scnprintf(buf+len, size-len, "RPI:none ");
876 len += scnprintf(buf+len, size-len, "flag:x%08x ",
879 len += scnprintf(buf+len, size-len, "UNKNOWN_TYPE ");
880 if (ndlp->nlp_type & NLP_FC_NODE)
881 len += scnprintf(buf+len, size-len, "FC_NODE ");
882 if (ndlp->nlp_type & NLP_FABRIC) {
883 len += scnprintf(buf+len, size-len, "FABRIC ");
886 if (ndlp->nlp_type & NLP_FCP_TARGET)
887 len += scnprintf(buf+len, size-len, "FCP_TGT sid:%d ",
889 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
890 len += scnprintf(buf+len, size-len, "FCP_INITIATOR ");
891 if (ndlp->nlp_type & NLP_NVME_TARGET)
892 len += scnprintf(buf + len,
893 size - len, "NVME_TGT sid:%d ",
895 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
896 len += scnprintf(buf + len,
897 size - len, "NVME_INITIATOR ");
898 len += scnprintf(buf+len, size-len, "usgmap:%x ",
900 len += scnprintf(buf+len, size-len, "refcnt:%x",
901 kref_read(&ndlp->kref));
903 i = atomic_read(&ndlp->cmd_pending);
904 len += scnprintf(buf + len, size - len,
905 " OutIO:x%x Qdepth x%x",
906 i, ndlp->cmd_qdepth);
909 len += scnprintf(buf + len, size - len, "defer:%x ",
910 ndlp->nlp_defer_did);
911 len += scnprintf(buf+len, size-len, "\n");
913 spin_unlock_irq(shost->host_lock);
915 len += scnprintf(buf + len, size - len,
916 "\nOutstanding IO x%x\n", outio);
918 if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
919 len += scnprintf(buf + len, size - len,
920 "\nNVME Targetport Entry ...\n");
922 /* Port state is only one of two values for now. */
923 if (phba->targetport->port_id)
924 statep = "REGISTERED";
927 len += scnprintf(buf + len, size - len,
928 "TGT WWNN x%llx WWPN x%llx State %s\n",
929 wwn_to_u64(vport->fc_nodename.u.wwn),
930 wwn_to_u64(vport->fc_portname.u.wwn),
932 len += scnprintf(buf + len, size - len,
933 " Targetport DID x%06x\n",
934 phba->targetport->port_id);
938 len += scnprintf(buf + len, size - len,
939 "\nNVME Lport/Rport Entries ...\n");
941 localport = vport->localport;
945 spin_lock_irq(shost->host_lock);
947 /* Port state is only one of two values for now. */
948 if (localport->port_id)
953 len += scnprintf(buf + len, size - len,
954 "Lport DID x%06x PortState %s\n",
955 localport->port_id, statep);
957 len += scnprintf(buf + len, size - len, "\tRport List:\n");
958 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
959 /* local short-hand pointer. */
960 spin_lock(&phba->hbalock);
961 rport = lpfc_ndlp_get_nrport(ndlp);
963 nrport = rport->remoteport;
966 spin_unlock(&phba->hbalock);
970 /* Port state is only one of two values for now. */
971 switch (nrport->port_state) {
972 case FC_OBJSTATE_ONLINE:
975 case FC_OBJSTATE_UNKNOWN:
979 statep = "UNSUPPORTED";
983 /* Tab in to show lport ownership. */
984 len += scnprintf(buf + len, size - len,
985 "\t%s Port ID:x%06x ",
986 statep, nrport->port_id);
987 len += scnprintf(buf + len, size - len, "WWPN x%llx ",
989 len += scnprintf(buf + len, size - len, "WWNN x%llx ",
992 /* An NVME rport can have multiple roles. */
993 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
994 len += scnprintf(buf + len, size - len,
996 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
997 len += scnprintf(buf + len, size - len,
999 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
1000 len += scnprintf(buf + len, size - len,
1002 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
1003 FC_PORT_ROLE_NVME_TARGET |
1004 FC_PORT_ROLE_NVME_DISCOVERY))
1005 len += scnprintf(buf + len, size - len,
1008 /* Terminate the string. */
1009 len += scnprintf(buf + len, size - len, "\n");
1012 spin_unlock_irq(shost->host_lock);
1018 * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
1019 * @vport: The vport to gather target node info from.
1020 * @buf: The buffer to dump log into.
1021 * @size: The maximum amount of data to process.
1024 * This routine dumps the NVME statistics associated with @vport
1027 * This routine returns the amount of bytes that were dumped into @buf and will
1031 lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
1033 struct lpfc_hba *phba = vport->phba;
1034 struct lpfc_nvmet_tgtport *tgtp;
1035 struct lpfc_async_xchg_ctx *ctxp, *next_ctxp;
1036 struct nvme_fc_local_port *localport;
1037 struct lpfc_fc4_ctrl_stat *cstat;
1038 struct lpfc_nvme_lport *lport;
1039 uint64_t data1, data2, data3;
1040 uint64_t tot, totin, totout;
1044 if (phba->nvmet_support) {
1045 if (!phba->targetport)
1047 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1048 len += scnprintf(buf + len, size - len,
1049 "\nNVME Targetport Statistics\n");
1051 len += scnprintf(buf + len, size - len,
1052 "LS: Rcv %08x Drop %08x Abort %08x\n",
1053 atomic_read(&tgtp->rcv_ls_req_in),
1054 atomic_read(&tgtp->rcv_ls_req_drop),
1055 atomic_read(&tgtp->xmt_ls_abort));
1056 if (atomic_read(&tgtp->rcv_ls_req_in) !=
1057 atomic_read(&tgtp->rcv_ls_req_out)) {
1058 len += scnprintf(buf + len, size - len,
1059 "Rcv LS: in %08x != out %08x\n",
1060 atomic_read(&tgtp->rcv_ls_req_in),
1061 atomic_read(&tgtp->rcv_ls_req_out));
1064 len += scnprintf(buf + len, size - len,
1065 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
1066 atomic_read(&tgtp->xmt_ls_rsp),
1067 atomic_read(&tgtp->xmt_ls_drop),
1068 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
1070 len += scnprintf(buf + len, size - len,
1071 "LS: RSP Abort %08x xb %08x Err %08x\n",
1072 atomic_read(&tgtp->xmt_ls_rsp_aborted),
1073 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
1074 atomic_read(&tgtp->xmt_ls_rsp_error));
1076 len += scnprintf(buf + len, size - len,
1077 "FCP: Rcv %08x Defer %08x Release %08x "
1079 atomic_read(&tgtp->rcv_fcp_cmd_in),
1080 atomic_read(&tgtp->rcv_fcp_cmd_defer),
1081 atomic_read(&tgtp->xmt_fcp_release),
1082 atomic_read(&tgtp->rcv_fcp_cmd_drop));
1084 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
1085 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
1086 len += scnprintf(buf + len, size - len,
1087 "Rcv FCP: in %08x != out %08x\n",
1088 atomic_read(&tgtp->rcv_fcp_cmd_in),
1089 atomic_read(&tgtp->rcv_fcp_cmd_out));
1092 len += scnprintf(buf + len, size - len,
1093 "FCP Rsp: read %08x readrsp %08x "
1094 "write %08x rsp %08x\n",
1095 atomic_read(&tgtp->xmt_fcp_read),
1096 atomic_read(&tgtp->xmt_fcp_read_rsp),
1097 atomic_read(&tgtp->xmt_fcp_write),
1098 atomic_read(&tgtp->xmt_fcp_rsp));
1100 len += scnprintf(buf + len, size - len,
1101 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
1102 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
1103 atomic_read(&tgtp->xmt_fcp_rsp_error),
1104 atomic_read(&tgtp->xmt_fcp_rsp_drop));
1106 len += scnprintf(buf + len, size - len,
1107 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
1108 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
1109 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
1110 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
1112 len += scnprintf(buf + len, size - len,
1113 "ABORT: Xmt %08x Cmpl %08x\n",
1114 atomic_read(&tgtp->xmt_fcp_abort),
1115 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
1117 len += scnprintf(buf + len, size - len,
1118 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
1119 atomic_read(&tgtp->xmt_abort_sol),
1120 atomic_read(&tgtp->xmt_abort_unsol),
1121 atomic_read(&tgtp->xmt_abort_rsp),
1122 atomic_read(&tgtp->xmt_abort_rsp_error));
1124 len += scnprintf(buf + len, size - len, "\n");
1127 spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1128 list_for_each_entry_safe(ctxp, next_ctxp,
1129 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1133 spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1135 len += scnprintf(buf + len, size - len,
1136 "ABORT: %d ctx entries\n", cnt);
1137 spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1138 list_for_each_entry_safe(ctxp, next_ctxp,
1139 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1141 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
1143 len += scnprintf(buf + len, size - len,
1144 "Entry: oxid %x state %x "
1146 ctxp->oxid, ctxp->state,
1149 spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1152 /* Calculate outstanding IOs */
1153 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1154 tot += atomic_read(&tgtp->xmt_fcp_release);
1155 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
1157 len += scnprintf(buf + len, size - len,
1158 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
1159 "CTX Outstanding %08llx\n",
1160 phba->sli4_hba.nvmet_xri_cnt,
1161 phba->sli4_hba.nvmet_io_wait_cnt,
1162 phba->sli4_hba.nvmet_io_wait_total,
1165 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
1168 localport = vport->localport;
1171 lport = (struct lpfc_nvme_lport *)localport->private;
1175 len += scnprintf(buf + len, size - len,
1176 "\nNVME HDWQ Statistics\n");
1178 len += scnprintf(buf + len, size - len,
1179 "LS: Xmt %016x Cmpl %016x\n",
1180 atomic_read(&lport->fc4NvmeLsRequests),
1181 atomic_read(&lport->fc4NvmeLsCmpls));
1185 for (i = 0; i < phba->cfg_hdw_queue; i++) {
1186 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
1187 tot = cstat->io_cmpls;
1189 data1 = cstat->input_requests;
1190 data2 = cstat->output_requests;
1191 data3 = cstat->control_requests;
1192 totout += (data1 + data2 + data3);
1194 /* Limit to 32, debugfs display buffer limitation */
1198 len += scnprintf(buf + len, PAGE_SIZE - len,
1199 "HDWQ (%d): Rd %016llx Wr %016llx "
1201 i, data1, data2, data3);
1202 len += scnprintf(buf + len, PAGE_SIZE - len,
1203 "Cmpl %016llx OutIO %016llx\n",
1204 tot, ((data1 + data2 + data3) - tot));
1206 len += scnprintf(buf + len, PAGE_SIZE - len,
1207 "Total FCP Cmpl %016llx Issue %016llx "
1209 totin, totout, totout - totin);
1211 len += scnprintf(buf + len, size - len,
1212 "LS Xmt Err: Abrt %08x Err %08x "
1213 "Cmpl Err: xb %08x Err %08x\n",
1214 atomic_read(&lport->xmt_ls_abort),
1215 atomic_read(&lport->xmt_ls_err),
1216 atomic_read(&lport->cmpl_ls_xb),
1217 atomic_read(&lport->cmpl_ls_err));
1219 len += scnprintf(buf + len, size - len,
1220 "FCP Xmt Err: noxri %06x nondlp %06x "
1221 "qdepth %06x wqerr %06x err %06x Abrt %06x\n",
1222 atomic_read(&lport->xmt_fcp_noxri),
1223 atomic_read(&lport->xmt_fcp_bad_ndlp),
1224 atomic_read(&lport->xmt_fcp_qdepth),
1225 atomic_read(&lport->xmt_fcp_wqerr),
1226 atomic_read(&lport->xmt_fcp_err),
1227 atomic_read(&lport->xmt_fcp_abort));
1229 len += scnprintf(buf + len, size - len,
1230 "FCP Cmpl Err: xb %08x Err %08x\n",
1231 atomic_read(&lport->cmpl_fcp_xb),
1232 atomic_read(&lport->cmpl_fcp_err));
1240 * lpfc_debugfs_scsistat_data - Dump target node list to a buffer
1241 * @vport: The vport to gather target node info from.
1242 * @buf: The buffer to dump log into.
1243 * @size: The maximum amount of data to process.
1246 * This routine dumps the SCSI statistics associated with @vport
1249 * This routine returns the amount of bytes that were dumped into @buf and will
1253 lpfc_debugfs_scsistat_data(struct lpfc_vport *vport, char *buf, int size)
1256 struct lpfc_hba *phba = vport->phba;
1257 struct lpfc_fc4_ctrl_stat *cstat;
1258 u64 data1, data2, data3;
1259 u64 tot, totin, totout;
1261 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
1263 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
1264 (phba->sli_rev != LPFC_SLI_REV4))
1267 scnprintf(buf, size, "SCSI HDWQ Statistics\n");
1271 for (i = 0; i < phba->cfg_hdw_queue; i++) {
1272 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
1273 tot = cstat->io_cmpls;
1275 data1 = cstat->input_requests;
1276 data2 = cstat->output_requests;
1277 data3 = cstat->control_requests;
1278 totout += (data1 + data2 + data3);
1280 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
1281 "IO %016llx ", i, data1, data2, data3);
1282 if (strlcat(buf, tmp, size) >= size)
1285 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
1286 tot, ((data1 + data2 + data3) - tot));
1287 if (strlcat(buf, tmp, size) >= size)
1290 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
1291 "OutIO %016llx\n", totin, totout, totout - totin);
1292 strlcat(buf, tmp, size);
1295 len = strnlen(buf, size);
1301 lpfc_io_ktime(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
1303 uint64_t seg1, seg2, seg3, seg4;
1306 if (!lpfc_cmd->ts_last_cmd ||
1307 !lpfc_cmd->ts_cmd_start ||
1308 !lpfc_cmd->ts_cmd_wqput ||
1309 !lpfc_cmd->ts_isr_cmpl ||
1310 !lpfc_cmd->ts_data_io)
1313 if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_cmd_start)
1315 if (lpfc_cmd->ts_cmd_start < lpfc_cmd->ts_last_cmd)
1317 if (lpfc_cmd->ts_cmd_wqput < lpfc_cmd->ts_cmd_start)
1319 if (lpfc_cmd->ts_isr_cmpl < lpfc_cmd->ts_cmd_wqput)
1321 if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_isr_cmpl)
1324 * Segment 1 - Time from Last FCP command cmpl is handed
1325 * off to NVME Layer to start of next command.
1326 * Segment 2 - Time from Driver receives a IO cmd start
1327 * from NVME Layer to WQ put is done on IO cmd.
1328 * Segment 3 - Time from Driver WQ put is done on IO cmd
1329 * to MSI-X ISR for IO cmpl.
1330 * Segment 4 - Time from MSI-X ISR for IO cmpl to when
1331 * cmpl is handled off to the NVME Layer.
1333 seg1 = lpfc_cmd->ts_cmd_start - lpfc_cmd->ts_last_cmd;
1334 if (seg1 > 5000000) /* 5 ms - for sequential IOs only */
1337 /* Calculate times relative to start of IO */
1338 seg2 = (lpfc_cmd->ts_cmd_wqput - lpfc_cmd->ts_cmd_start);
1340 seg3 = lpfc_cmd->ts_isr_cmpl - lpfc_cmd->ts_cmd_start;
1346 seg4 = lpfc_cmd->ts_data_io - lpfc_cmd->ts_cmd_start;
1351 phba->ktime_data_samples++;
1352 phba->ktime_seg1_total += seg1;
1353 if (seg1 < phba->ktime_seg1_min)
1354 phba->ktime_seg1_min = seg1;
1355 else if (seg1 > phba->ktime_seg1_max)
1356 phba->ktime_seg1_max = seg1;
1357 phba->ktime_seg2_total += seg2;
1358 if (seg2 < phba->ktime_seg2_min)
1359 phba->ktime_seg2_min = seg2;
1360 else if (seg2 > phba->ktime_seg2_max)
1361 phba->ktime_seg2_max = seg2;
1362 phba->ktime_seg3_total += seg3;
1363 if (seg3 < phba->ktime_seg3_min)
1364 phba->ktime_seg3_min = seg3;
1365 else if (seg3 > phba->ktime_seg3_max)
1366 phba->ktime_seg3_max = seg3;
1367 phba->ktime_seg4_total += seg4;
1368 if (seg4 < phba->ktime_seg4_min)
1369 phba->ktime_seg4_min = seg4;
1370 else if (seg4 > phba->ktime_seg4_max)
1371 phba->ktime_seg4_max = seg4;
1373 lpfc_cmd->ts_last_cmd = 0;
1374 lpfc_cmd->ts_cmd_start = 0;
1375 lpfc_cmd->ts_cmd_wqput = 0;
1376 lpfc_cmd->ts_isr_cmpl = 0;
1377 lpfc_cmd->ts_data_io = 0;
1381 * lpfc_debugfs_ioktime_data - Dump target node list to a buffer
1382 * @vport: The vport to gather target node info from.
1383 * @buf: The buffer to dump log into.
1384 * @size: The maximum amount of data to process.
1387 * This routine dumps the NVME statistics associated with @vport
1390 * This routine returns the amount of bytes that were dumped into @buf and will
1394 lpfc_debugfs_ioktime_data(struct lpfc_vport *vport, char *buf, int size)
1396 struct lpfc_hba *phba = vport->phba;
1399 if (phba->nvmet_support == 0) {
1401 len += scnprintf(buf + len, PAGE_SIZE - len,
1402 "ktime %s: Total Samples: %lld\n",
1403 (phba->ktime_on ? "Enabled" : "Disabled"),
1404 phba->ktime_data_samples);
1405 if (phba->ktime_data_samples == 0)
1409 buf + len, PAGE_SIZE - len,
1410 "Segment 1: Last Cmd cmpl "
1411 "done -to- Start of next Cmd (in driver)\n");
1413 buf + len, PAGE_SIZE - len,
1414 "avg:%08lld min:%08lld max %08lld\n",
1415 div_u64(phba->ktime_seg1_total,
1416 phba->ktime_data_samples),
1417 phba->ktime_seg1_min,
1418 phba->ktime_seg1_max);
1420 buf + len, PAGE_SIZE - len,
1421 "Segment 2: Driver start of Cmd "
1422 "-to- Firmware WQ doorbell\n");
1424 buf + len, PAGE_SIZE - len,
1425 "avg:%08lld min:%08lld max %08lld\n",
1426 div_u64(phba->ktime_seg2_total,
1427 phba->ktime_data_samples),
1428 phba->ktime_seg2_min,
1429 phba->ktime_seg2_max);
1431 buf + len, PAGE_SIZE - len,
1432 "Segment 3: Firmware WQ doorbell -to- "
1433 "MSI-X ISR cmpl\n");
1435 buf + len, PAGE_SIZE - len,
1436 "avg:%08lld min:%08lld max %08lld\n",
1437 div_u64(phba->ktime_seg3_total,
1438 phba->ktime_data_samples),
1439 phba->ktime_seg3_min,
1440 phba->ktime_seg3_max);
1442 buf + len, PAGE_SIZE - len,
1443 "Segment 4: MSI-X ISR cmpl -to- "
1446 buf + len, PAGE_SIZE - len,
1447 "avg:%08lld min:%08lld max %08lld\n",
1448 div_u64(phba->ktime_seg4_total,
1449 phba->ktime_data_samples),
1450 phba->ktime_seg4_min,
1451 phba->ktime_seg4_max);
1453 buf + len, PAGE_SIZE - len,
1454 "Total IO avg time: %08lld\n",
1455 div_u64(phba->ktime_seg1_total +
1456 phba->ktime_seg2_total +
1457 phba->ktime_seg3_total +
1458 phba->ktime_seg4_total,
1459 phba->ktime_data_samples));
1464 len += scnprintf(buf + len, PAGE_SIZE-len,
1465 "ktime %s: Total Samples: %lld %lld\n",
1466 (phba->ktime_on ? "Enabled" : "Disabled"),
1467 phba->ktime_data_samples,
1468 phba->ktime_status_samples);
1469 if (phba->ktime_data_samples == 0)
1472 len += scnprintf(buf + len, PAGE_SIZE-len,
1473 "Segment 1: MSI-X ISR Rcv cmd -to- "
1474 "cmd pass to NVME Layer\n");
1475 len += scnprintf(buf + len, PAGE_SIZE-len,
1476 "avg:%08lld min:%08lld max %08lld\n",
1477 div_u64(phba->ktime_seg1_total,
1478 phba->ktime_data_samples),
1479 phba->ktime_seg1_min,
1480 phba->ktime_seg1_max);
1481 len += scnprintf(buf + len, PAGE_SIZE-len,
1482 "Segment 2: cmd pass to NVME Layer- "
1483 "-to- Driver rcv cmd OP (action)\n");
1484 len += scnprintf(buf + len, PAGE_SIZE-len,
1485 "avg:%08lld min:%08lld max %08lld\n",
1486 div_u64(phba->ktime_seg2_total,
1487 phba->ktime_data_samples),
1488 phba->ktime_seg2_min,
1489 phba->ktime_seg2_max);
1490 len += scnprintf(buf + len, PAGE_SIZE-len,
1491 "Segment 3: Driver rcv cmd OP -to- "
1492 "Firmware WQ doorbell: cmd\n");
1493 len += scnprintf(buf + len, PAGE_SIZE-len,
1494 "avg:%08lld min:%08lld max %08lld\n",
1495 div_u64(phba->ktime_seg3_total,
1496 phba->ktime_data_samples),
1497 phba->ktime_seg3_min,
1498 phba->ktime_seg3_max);
1499 len += scnprintf(buf + len, PAGE_SIZE-len,
1500 "Segment 4: Firmware WQ doorbell: cmd "
1501 "-to- MSI-X ISR for cmd cmpl\n");
1502 len += scnprintf(buf + len, PAGE_SIZE-len,
1503 "avg:%08lld min:%08lld max %08lld\n",
1504 div_u64(phba->ktime_seg4_total,
1505 phba->ktime_data_samples),
1506 phba->ktime_seg4_min,
1507 phba->ktime_seg4_max);
1508 len += scnprintf(buf + len, PAGE_SIZE-len,
1509 "Segment 5: MSI-X ISR for cmd cmpl "
1510 "-to- NVME layer passed cmd done\n");
1511 len += scnprintf(buf + len, PAGE_SIZE-len,
1512 "avg:%08lld min:%08lld max %08lld\n",
1513 div_u64(phba->ktime_seg5_total,
1514 phba->ktime_data_samples),
1515 phba->ktime_seg5_min,
1516 phba->ktime_seg5_max);
1518 if (phba->ktime_status_samples == 0) {
1519 len += scnprintf(buf + len, PAGE_SIZE-len,
1520 "Total: cmd received by MSI-X ISR "
1521 "-to- cmd completed on wire\n");
1522 len += scnprintf(buf + len, PAGE_SIZE-len,
1523 "avg:%08lld min:%08lld "
1525 div_u64(phba->ktime_seg10_total,
1526 phba->ktime_data_samples),
1527 phba->ktime_seg10_min,
1528 phba->ktime_seg10_max);
1532 len += scnprintf(buf + len, PAGE_SIZE-len,
1533 "Segment 6: NVME layer passed cmd done "
1534 "-to- Driver rcv rsp status OP\n");
1535 len += scnprintf(buf + len, PAGE_SIZE-len,
1536 "avg:%08lld min:%08lld max %08lld\n",
1537 div_u64(phba->ktime_seg6_total,
1538 phba->ktime_status_samples),
1539 phba->ktime_seg6_min,
1540 phba->ktime_seg6_max);
1541 len += scnprintf(buf + len, PAGE_SIZE-len,
1542 "Segment 7: Driver rcv rsp status OP "
1543 "-to- Firmware WQ doorbell: status\n");
1544 len += scnprintf(buf + len, PAGE_SIZE-len,
1545 "avg:%08lld min:%08lld max %08lld\n",
1546 div_u64(phba->ktime_seg7_total,
1547 phba->ktime_status_samples),
1548 phba->ktime_seg7_min,
1549 phba->ktime_seg7_max);
1550 len += scnprintf(buf + len, PAGE_SIZE-len,
1551 "Segment 8: Firmware WQ doorbell: status"
1552 " -to- MSI-X ISR for status cmpl\n");
1553 len += scnprintf(buf + len, PAGE_SIZE-len,
1554 "avg:%08lld min:%08lld max %08lld\n",
1555 div_u64(phba->ktime_seg8_total,
1556 phba->ktime_status_samples),
1557 phba->ktime_seg8_min,
1558 phba->ktime_seg8_max);
1559 len += scnprintf(buf + len, PAGE_SIZE-len,
1560 "Segment 9: MSI-X ISR for status cmpl "
1561 "-to- NVME layer passed status done\n");
1562 len += scnprintf(buf + len, PAGE_SIZE-len,
1563 "avg:%08lld min:%08lld max %08lld\n",
1564 div_u64(phba->ktime_seg9_total,
1565 phba->ktime_status_samples),
1566 phba->ktime_seg9_min,
1567 phba->ktime_seg9_max);
1568 len += scnprintf(buf + len, PAGE_SIZE-len,
1569 "Total: cmd received by MSI-X ISR -to- "
1570 "cmd completed on wire\n");
1571 len += scnprintf(buf + len, PAGE_SIZE-len,
1572 "avg:%08lld min:%08lld max %08lld\n",
1573 div_u64(phba->ktime_seg10_total,
1574 phba->ktime_status_samples),
1575 phba->ktime_seg10_min,
1576 phba->ktime_seg10_max);
1581 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1582 * @phba: The phba to gather target node info from.
1583 * @buf: The buffer to dump log into.
1584 * @size: The maximum amount of data to process.
1587 * This routine dumps the NVME IO trace associated with @phba
1590 * This routine returns the amount of bytes that were dumped into @buf and will
1594 lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1596 struct lpfc_debugfs_nvmeio_trc *dtp;
1597 int i, state, index, skip;
1600 state = phba->nvmeio_trc_on;
1602 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1603 (phba->nvmeio_trc_size - 1);
1604 skip = phba->nvmeio_trc_output_idx;
1606 len += scnprintf(buf + len, size - len,
1607 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1608 (phba->nvmet_support ? "NVME" : "NVMET"),
1609 (state ? "Enabled" : "Disabled"),
1610 index, skip, phba->nvmeio_trc_size);
1612 if (!phba->nvmeio_trc || state)
1615 /* trace MUST bhe off to continue */
1617 for (i = index; i < phba->nvmeio_trc_size; i++) {
1622 dtp = phba->nvmeio_trc + i;
1623 phba->nvmeio_trc_output_idx++;
1628 len += scnprintf(buf + len, size - len, dtp->fmt,
1629 dtp->data1, dtp->data2, dtp->data3);
1631 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1632 phba->nvmeio_trc_output_idx = 0;
1633 len += scnprintf(buf + len, size - len,
1634 "Trace Complete\n");
1638 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1639 len += scnprintf(buf + len, size - len,
1640 "Trace Continue (%d of %d)\n",
1641 phba->nvmeio_trc_output_idx,
1642 phba->nvmeio_trc_size);
1646 for (i = 0; i < index; i++) {
1651 dtp = phba->nvmeio_trc + i;
1652 phba->nvmeio_trc_output_idx++;
1657 len += scnprintf(buf + len, size - len, dtp->fmt,
1658 dtp->data1, dtp->data2, dtp->data3);
1660 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1661 phba->nvmeio_trc_output_idx = 0;
1662 len += scnprintf(buf + len, size - len,
1663 "Trace Complete\n");
1667 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1668 len += scnprintf(buf + len, size - len,
1669 "Trace Continue (%d of %d)\n",
1670 phba->nvmeio_trc_output_idx,
1671 phba->nvmeio_trc_size);
1676 len += scnprintf(buf + len, size - len,
1683 * lpfc_debugfs_hdwqstat_data - Dump I/O stats to a buffer
1684 * @vport: The vport to gather target node info from.
1685 * @buf: The buffer to dump log into.
1686 * @size: The maximum amount of data to process.
1689 * This routine dumps the NVME + SCSI statistics associated with @vport
1692 * This routine returns the amount of bytes that were dumped into @buf and will
1696 lpfc_debugfs_hdwqstat_data(struct lpfc_vport *vport, char *buf, int size)
1698 struct lpfc_hba *phba = vport->phba;
1699 struct lpfc_sli4_hdw_queue *qp;
1700 struct lpfc_hdwq_stat *c_stat;
1705 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
1707 scnprintf(tmp, sizeof(tmp), "HDWQ Stats:\n\n");
1708 if (strlcat(buf, tmp, size) >= size)
1711 scnprintf(tmp, sizeof(tmp), "(NVME Accounting: %s) ",
1712 (phba->hdwqstat_on &
1713 (LPFC_CHECK_NVME_IO | LPFC_CHECK_NVMET_IO) ?
1714 "Enabled" : "Disabled"));
1715 if (strlcat(buf, tmp, size) >= size)
1718 scnprintf(tmp, sizeof(tmp), "(SCSI Accounting: %s) ",
1719 (phba->hdwqstat_on & LPFC_CHECK_SCSI_IO ?
1720 "Enabled" : "Disabled"));
1721 if (strlcat(buf, tmp, size) >= size)
1724 scnprintf(tmp, sizeof(tmp), "\n\n");
1725 if (strlcat(buf, tmp, size) >= size)
1728 for (i = 0; i < phba->cfg_hdw_queue; i++) {
1729 qp = &phba->sli4_hba.hdwq[i];
1735 for_each_present_cpu(j) {
1736 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, j);
1738 /* Only display for this HDWQ */
1739 if (i != c_stat->hdwq_no)
1742 /* Only display non-zero counters */
1743 if (!c_stat->xmt_io && !c_stat->cmpl_io &&
1747 if (!tot_xmt && !tot_cmpl && !tot_rcv) {
1748 /* Print HDWQ string only the first time */
1749 scnprintf(tmp, sizeof(tmp), "[HDWQ %d]:\t", i);
1750 if (strlcat(buf, tmp, size) >= size)
1754 tot_xmt += c_stat->xmt_io;
1755 tot_cmpl += c_stat->cmpl_io;
1756 if (phba->nvmet_support)
1757 tot_rcv += c_stat->rcv_io;
1759 scnprintf(tmp, sizeof(tmp), "| [CPU %d]: ", j);
1760 if (strlcat(buf, tmp, size) >= size)
1763 if (phba->nvmet_support) {
1764 scnprintf(tmp, sizeof(tmp),
1765 "XMT 0x%x CMPL 0x%x RCV 0x%x |",
1766 c_stat->xmt_io, c_stat->cmpl_io,
1768 if (strlcat(buf, tmp, size) >= size)
1771 scnprintf(tmp, sizeof(tmp),
1772 "XMT 0x%x CMPL 0x%x |",
1773 c_stat->xmt_io, c_stat->cmpl_io);
1774 if (strlcat(buf, tmp, size) >= size)
1779 /* Check if nothing to display */
1780 if (!tot_xmt && !tot_cmpl && !tot_rcv)
1783 scnprintf(tmp, sizeof(tmp), "\t->\t[HDWQ Total: ");
1784 if (strlcat(buf, tmp, size) >= size)
1787 if (phba->nvmet_support) {
1788 scnprintf(tmp, sizeof(tmp),
1789 "XMT 0x%x CMPL 0x%x RCV 0x%x]\n\n",
1790 tot_xmt, tot_cmpl, tot_rcv);
1791 if (strlcat(buf, tmp, size) >= size)
1794 scnprintf(tmp, sizeof(tmp),
1795 "XMT 0x%x CMPL 0x%x]\n\n",
1797 if (strlcat(buf, tmp, size) >= size)
1803 len = strnlen(buf, size);
1810 * lpfc_debugfs_disc_trc - Store discovery trace log
1811 * @vport: The vport to associate this trace string with for retrieval.
1812 * @mask: Log entry classification.
1813 * @fmt: Format string to be displayed when dumping the log.
1814 * @data1: 1st data parameter to be applied to @fmt.
1815 * @data2: 2nd data parameter to be applied to @fmt.
1816 * @data3: 3rd data parameter to be applied to @fmt.
1819 * This routine is used by the driver code to add a debugfs log entry to the
1820 * discovery trace buffer associated with @vport. Only entries with a @mask that
1821 * match the current debugfs discovery mask will be saved. Entries that do not
1822 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1823 * printf when displaying the log.
1826 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1827 uint32_t data1, uint32_t data2, uint32_t data3)
1829 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1830 struct lpfc_debugfs_trc *dtp;
1833 if (!(lpfc_debugfs_mask_disc_trc & mask))
1836 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1837 !vport || !vport->disc_trc)
1840 index = atomic_inc_return(&vport->disc_trc_cnt) &
1841 (lpfc_debugfs_max_disc_trc - 1);
1842 dtp = vport->disc_trc + index;
1847 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1854 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
1855 * @phba: The phba to associate this trace string with for retrieval.
1856 * @fmt: Format string to be displayed when dumping the log.
1857 * @data1: 1st data parameter to be applied to @fmt.
1858 * @data2: 2nd data parameter to be applied to @fmt.
1859 * @data3: 3rd data parameter to be applied to @fmt.
1862 * This routine is used by the driver code to add a debugfs log entry to the
1863 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1864 * @data3 are used like printf when displaying the log.
1867 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1868 uint32_t data1, uint32_t data2, uint32_t data3)
1870 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1871 struct lpfc_debugfs_trc *dtp;
1874 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1875 !phba || !phba->slow_ring_trc)
1878 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1879 (lpfc_debugfs_max_slow_ring_trc - 1);
1880 dtp = phba->slow_ring_trc + index;
1885 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1892 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1893 * @phba: The phba to associate this trace string with for retrieval.
1894 * @fmt: Format string to be displayed when dumping the log.
1895 * @data1: 1st data parameter to be applied to @fmt.
1896 * @data2: 2nd data parameter to be applied to @fmt.
1897 * @data3: 3rd data parameter to be applied to @fmt.
1900 * This routine is used by the driver code to add a debugfs log entry to the
1901 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1902 * @data3 are used like printf when displaying the log.
1905 lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1906 uint16_t data1, uint16_t data2, uint32_t data3)
1908 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1909 struct lpfc_debugfs_nvmeio_trc *dtp;
1912 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1915 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1916 (phba->nvmeio_trc_size - 1);
1917 dtp = phba->nvmeio_trc + index;
1925 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1927 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
1928 * @inode: The inode pointer that contains a vport pointer.
1929 * @file: The file pointer to attach the log output.
1932 * This routine is the entry point for the debugfs open file operation. It gets
1933 * the vport from the i_private field in @inode, allocates the necessary buffer
1934 * for the log, fills the buffer from the in-memory log for this vport, and then
1935 * returns a pointer to that log in the private_data field in @file.
1938 * This function returns zero if successful. On error it will return a negative
1942 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1944 struct lpfc_vport *vport = inode->i_private;
1945 struct lpfc_debug *debug;
1949 if (!lpfc_debugfs_max_disc_trc) {
1954 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1958 /* Round to page boundary */
1959 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1960 size = PAGE_ALIGN(size);
1962 debug->buffer = kmalloc(size, GFP_KERNEL);
1963 if (!debug->buffer) {
1968 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1969 file->private_data = debug;
1977 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
1978 * @inode: The inode pointer that contains a vport pointer.
1979 * @file: The file pointer to attach the log output.
1982 * This routine is the entry point for the debugfs open file operation. It gets
1983 * the vport from the i_private field in @inode, allocates the necessary buffer
1984 * for the log, fills the buffer from the in-memory log for this vport, and then
1985 * returns a pointer to that log in the private_data field in @file.
1988 * This function returns zero if successful. On error it will return a negative
1992 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1994 struct lpfc_hba *phba = inode->i_private;
1995 struct lpfc_debug *debug;
1999 if (!lpfc_debugfs_max_slow_ring_trc) {
2004 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2008 /* Round to page boundary */
2009 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
2010 size = PAGE_ALIGN(size);
2012 debug->buffer = kmalloc(size, GFP_KERNEL);
2013 if (!debug->buffer) {
2018 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
2019 file->private_data = debug;
2027 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
2028 * @inode: The inode pointer that contains a vport pointer.
2029 * @file: The file pointer to attach the log output.
2032 * This routine is the entry point for the debugfs open file operation. It gets
2033 * the vport from the i_private field in @inode, allocates the necessary buffer
2034 * for the log, fills the buffer from the in-memory log for this vport, and then
2035 * returns a pointer to that log in the private_data field in @file.
2038 * This function returns zero if successful. On error it will return a negative
2042 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
2044 struct lpfc_hba *phba = inode->i_private;
2045 struct lpfc_debug *debug;
2048 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2052 /* Round to page boundary */
2053 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
2054 if (!debug->buffer) {
2059 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
2061 file->private_data = debug;
2069 * lpfc_debugfs_multixripools_open - Open the multixripool debugfs buffer
2070 * @inode: The inode pointer that contains a hba pointer.
2071 * @file: The file pointer to attach the log output.
2074 * This routine is the entry point for the debugfs open file operation. It gets
2075 * the hba from the i_private field in @inode, allocates the necessary buffer
2076 * for the log, fills the buffer from the in-memory log for this hba, and then
2077 * returns a pointer to that log in the private_data field in @file.
2080 * This function returns zero if successful. On error it will return a negative
2084 lpfc_debugfs_multixripools_open(struct inode *inode, struct file *file)
2086 struct lpfc_hba *phba = inode->i_private;
2087 struct lpfc_debug *debug;
2090 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2094 /* Round to page boundary */
2095 debug->buffer = kzalloc(LPFC_DUMP_MULTIXRIPOOL_SIZE, GFP_KERNEL);
2096 if (!debug->buffer) {
2101 debug->len = lpfc_debugfs_multixripools_data(
2102 phba, debug->buffer, LPFC_DUMP_MULTIXRIPOOL_SIZE);
2104 debug->i_private = inode->i_private;
2105 file->private_data = debug;
2112 #ifdef LPFC_HDWQ_LOCK_STAT
2114 * lpfc_debugfs_lockstat_open - Open the lockstat debugfs buffer
2115 * @inode: The inode pointer that contains a vport pointer.
2116 * @file: The file pointer to attach the log output.
2119 * This routine is the entry point for the debugfs open file operation. It gets
2120 * the vport from the i_private field in @inode, allocates the necessary buffer
2121 * for the log, fills the buffer from the in-memory log for this vport, and then
2122 * returns a pointer to that log in the private_data field in @file.
2125 * This function returns zero if successful. On error it will return a negative
2129 lpfc_debugfs_lockstat_open(struct inode *inode, struct file *file)
2131 struct lpfc_hba *phba = inode->i_private;
2132 struct lpfc_debug *debug;
2135 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2139 /* Round to page boundary */
2140 debug->buffer = kmalloc(LPFC_HDWQINFO_SIZE, GFP_KERNEL);
2141 if (!debug->buffer) {
2146 debug->len = lpfc_debugfs_lockstat_data(phba, debug->buffer,
2148 file->private_data = debug;
2156 lpfc_debugfs_lockstat_write(struct file *file, const char __user *buf,
2157 size_t nbytes, loff_t *ppos)
2159 struct lpfc_debug *debug = file->private_data;
2160 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2161 struct lpfc_sli4_hdw_queue *qp;
2166 memset(mybuf, 0, sizeof(mybuf));
2168 if (copy_from_user(mybuf, buf, nbytes))
2172 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2173 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2174 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2175 qp = &phba->sli4_hba.hdwq[i];
2176 qp->lock_conflict.alloc_xri_get = 0;
2177 qp->lock_conflict.alloc_xri_put = 0;
2178 qp->lock_conflict.free_xri = 0;
2179 qp->lock_conflict.wq_access = 0;
2180 qp->lock_conflict.alloc_pvt_pool = 0;
2181 qp->lock_conflict.mv_from_pvt_pool = 0;
2182 qp->lock_conflict.mv_to_pub_pool = 0;
2183 qp->lock_conflict.mv_to_pvt_pool = 0;
2184 qp->lock_conflict.free_pvt_pool = 0;
2185 qp->lock_conflict.free_pub_pool = 0;
2186 qp->lock_conflict.wq_access = 0;
2193 static int lpfc_debugfs_ras_log_data(struct lpfc_hba *phba,
2194 char *buffer, int size)
2197 struct lpfc_dmabuf *dmabuf, *next;
2199 memset(buffer, 0, size);
2201 spin_lock_irq(&phba->hbalock);
2202 if (phba->ras_fwlog.state != ACTIVE) {
2203 spin_unlock_irq(&phba->hbalock);
2206 spin_unlock_irq(&phba->hbalock);
2208 list_for_each_entry_safe(dmabuf, next,
2209 &phba->ras_fwlog.fwlog_buff_list, list) {
2210 /* Check if copying will go over size and a '\0' char */
2211 if ((copied + LPFC_RAS_MAX_ENTRY_SIZE) >= (size - 1)) {
2212 memcpy(buffer + copied, dmabuf->virt,
2214 copied += size - copied - 1;
2217 memcpy(buffer + copied, dmabuf->virt, LPFC_RAS_MAX_ENTRY_SIZE);
2218 copied += LPFC_RAS_MAX_ENTRY_SIZE;
2224 lpfc_debugfs_ras_log_release(struct inode *inode, struct file *file)
2226 struct lpfc_debug *debug = file->private_data;
2228 vfree(debug->buffer);
2235 * lpfc_debugfs_ras_log_open - Open the RAS log debugfs buffer
2236 * @inode: The inode pointer that contains a vport pointer.
2237 * @file: The file pointer to attach the log output.
2240 * This routine is the entry point for the debugfs open file operation. It gets
2241 * the vport from the i_private field in @inode, allocates the necessary buffer
2242 * for the log, fills the buffer from the in-memory log for this vport, and then
2243 * returns a pointer to that log in the private_data field in @file.
2246 * This function returns zero if successful. On error it will return a negative
2250 lpfc_debugfs_ras_log_open(struct inode *inode, struct file *file)
2252 struct lpfc_hba *phba = inode->i_private;
2253 struct lpfc_debug *debug;
2257 spin_lock_irq(&phba->hbalock);
2258 if (phba->ras_fwlog.state != ACTIVE) {
2259 spin_unlock_irq(&phba->hbalock);
2263 spin_unlock_irq(&phba->hbalock);
2264 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2268 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;
2269 debug->buffer = vmalloc(size);
2273 debug->len = lpfc_debugfs_ras_log_data(phba, debug->buffer, size);
2274 if (debug->len < 0) {
2278 file->private_data = debug;
2283 vfree(debug->buffer);
2291 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
2292 * @inode: The inode pointer that contains a vport pointer.
2293 * @file: The file pointer to attach the log output.
2296 * This routine is the entry point for the debugfs open file operation. It gets
2297 * the vport from the i_private field in @inode, allocates the necessary buffer
2298 * for the log, fills the buffer from the in-memory log for this vport, and then
2299 * returns a pointer to that log in the private_data field in @file.
2302 * This function returns zero if successful. On error it will return a negative
2306 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
2308 struct lpfc_hba *phba = inode->i_private;
2309 struct lpfc_debug *debug;
2312 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2316 /* Round to page boundary */
2317 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
2318 if (!debug->buffer) {
2323 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
2324 LPFC_DUMPHBASLIM_SIZE);
2325 file->private_data = debug;
2333 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
2334 * @inode: The inode pointer that contains a vport pointer.
2335 * @file: The file pointer to attach the log output.
2338 * This routine is the entry point for the debugfs open file operation. It gets
2339 * the vport from the i_private field in @inode, allocates the necessary buffer
2340 * for the log, fills the buffer from the in-memory log for this vport, and then
2341 * returns a pointer to that log in the private_data field in @file.
2344 * This function returns zero if successful. On error it will return a negative
2348 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
2350 struct lpfc_hba *phba = inode->i_private;
2351 struct lpfc_debug *debug;
2354 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2358 /* Round to page boundary */
2359 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
2360 if (!debug->buffer) {
2365 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
2366 LPFC_DUMPHOSTSLIM_SIZE);
2367 file->private_data = debug;
2375 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
2376 size_t nbytes, loff_t *ppos)
2378 struct dentry *dent = file->f_path.dentry;
2379 struct lpfc_hba *phba = file->private_data;
2384 if (dent == phba->debug_writeGuard)
2385 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
2386 else if (dent == phba->debug_writeApp)
2387 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
2388 else if (dent == phba->debug_writeRef)
2389 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
2390 else if (dent == phba->debug_readGuard)
2391 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
2392 else if (dent == phba->debug_readApp)
2393 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
2394 else if (dent == phba->debug_readRef)
2395 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
2396 else if (dent == phba->debug_InjErrNPortID)
2397 cnt = scnprintf(cbuf, 32, "0x%06x\n",
2398 phba->lpfc_injerr_nportid);
2399 else if (dent == phba->debug_InjErrWWPN) {
2400 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
2401 tmp = cpu_to_be64(tmp);
2402 cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
2403 } else if (dent == phba->debug_InjErrLBA) {
2404 if (phba->lpfc_injerr_lba == (sector_t)(-1))
2405 cnt = scnprintf(cbuf, 32, "off\n");
2407 cnt = scnprintf(cbuf, 32, "0x%llx\n",
2408 (uint64_t) phba->lpfc_injerr_lba);
2410 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2411 "0547 Unknown debugfs error injection entry\n");
2413 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
2417 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
2418 size_t nbytes, loff_t *ppos)
2420 struct dentry *dent = file->f_path.dentry;
2421 struct lpfc_hba *phba = file->private_data;
2426 memset(dstbuf, 0, 33);
2427 size = (nbytes < 32) ? nbytes : 32;
2428 if (copy_from_user(dstbuf, buf, size))
2431 if (dent == phba->debug_InjErrLBA) {
2432 if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
2434 tmp = (uint64_t)(-1);
2437 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
2440 if (dent == phba->debug_writeGuard)
2441 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
2442 else if (dent == phba->debug_writeApp)
2443 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
2444 else if (dent == phba->debug_writeRef)
2445 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
2446 else if (dent == phba->debug_readGuard)
2447 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
2448 else if (dent == phba->debug_readApp)
2449 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
2450 else if (dent == phba->debug_readRef)
2451 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
2452 else if (dent == phba->debug_InjErrLBA)
2453 phba->lpfc_injerr_lba = (sector_t)tmp;
2454 else if (dent == phba->debug_InjErrNPortID)
2455 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
2456 else if (dent == phba->debug_InjErrWWPN) {
2457 tmp = cpu_to_be64(tmp);
2458 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
2460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2461 "0548 Unknown debugfs error injection entry\n");
2467 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
2473 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
2474 * @inode: The inode pointer that contains a vport pointer.
2475 * @file: The file pointer to attach the log output.
2478 * This routine is the entry point for the debugfs open file operation. It gets
2479 * the vport from the i_private field in @inode, allocates the necessary buffer
2480 * for the log, fills the buffer from the in-memory log for this vport, and then
2481 * returns a pointer to that log in the private_data field in @file.
2484 * This function returns zero if successful. On error it will return a negative
2488 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
2490 struct lpfc_vport *vport = inode->i_private;
2491 struct lpfc_debug *debug;
2494 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2498 /* Round to page boundary */
2499 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
2500 if (!debug->buffer) {
2505 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
2506 LPFC_NODELIST_SIZE);
2507 file->private_data = debug;
2515 * lpfc_debugfs_lseek - Seek through a debugfs file
2516 * @file: The file pointer to seek through.
2517 * @off: The offset to seek to or the amount to seek by.
2518 * @whence: Indicates how to seek.
2521 * This routine is the entry point for the debugfs lseek file operation. The
2522 * @whence parameter indicates whether @off is the offset to directly seek to,
2523 * or if it is a value to seek forward or reverse by. This function figures out
2524 * what the new offset of the debugfs file will be and assigns that value to the
2525 * f_pos field of @file.
2528 * This function returns the new offset if successful and returns a negative
2529 * error if unable to process the seek.
2532 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
2534 struct lpfc_debug *debug = file->private_data;
2535 return fixed_size_llseek(file, off, whence, debug->len);
2539 * lpfc_debugfs_read - Read a debugfs file
2540 * @file: The file pointer to read from.
2541 * @buf: The buffer to copy the data to.
2542 * @nbytes: The number of bytes to read.
2543 * @ppos: The position in the file to start reading from.
2546 * This routine reads data from from the buffer indicated in the private_data
2547 * field of @file. It will start reading at @ppos and copy up to @nbytes of
2551 * This function returns the amount of data that was read (this could be less
2552 * than @nbytes if the end of the file was reached) or a negative error value.
2555 lpfc_debugfs_read(struct file *file, char __user *buf,
2556 size_t nbytes, loff_t *ppos)
2558 struct lpfc_debug *debug = file->private_data;
2560 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
2565 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
2566 * @inode: The inode pointer that contains a vport pointer. (unused)
2567 * @file: The file pointer that contains the buffer to release.
2570 * This routine frees the buffer that was allocated when the debugfs file was
2574 * This function returns zero.
2577 lpfc_debugfs_release(struct inode *inode, struct file *file)
2579 struct lpfc_debug *debug = file->private_data;
2581 kfree(debug->buffer);
2588 * lpfc_debugfs_multixripools_write - Clear multi-XRI pools statistics
2589 * @file: The file pointer to read from.
2590 * @buf: The buffer to copy the user data from.
2591 * @nbytes: The number of bytes to get.
2592 * @ppos: The position in the file to start reading from.
2595 * This routine clears multi-XRI pools statistics when buf contains "clear".
2598 * It returns the @nbytges passing in from debugfs user space when successful.
2599 * In case of error conditions, it returns proper error code back to the user
2603 lpfc_debugfs_multixripools_write(struct file *file, const char __user *buf,
2604 size_t nbytes, loff_t *ppos)
2606 struct lpfc_debug *debug = file->private_data;
2607 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2612 struct lpfc_sli4_hdw_queue *qp;
2613 struct lpfc_multixri_pool *multixri_pool;
2618 memset(mybuf, 0, sizeof(mybuf));
2620 if (copy_from_user(mybuf, buf, nbytes))
2624 if ((strncmp(pbuf, "clear", strlen("clear"))) == 0) {
2625 hwq_count = phba->cfg_hdw_queue;
2626 for (i = 0; i < hwq_count; i++) {
2627 qp = &phba->sli4_hba.hdwq[i];
2628 multixri_pool = qp->p_multixri_pool;
2632 qp->empty_io_bufs = 0;
2633 multixri_pool->pbl_empty_count = 0;
2634 #ifdef LPFC_MXP_STAT
2635 multixri_pool->above_limit_count = 0;
2636 multixri_pool->below_limit_count = 0;
2637 multixri_pool->stat_max_hwm = 0;
2638 multixri_pool->local_pbl_hit_count = 0;
2639 multixri_pool->other_pbl_hit_count = 0;
2641 multixri_pool->stat_pbl_count = 0;
2642 multixri_pool->stat_pvt_count = 0;
2643 multixri_pool->stat_busy_count = 0;
2644 multixri_pool->stat_snapshot_taken = 0;
2647 return strlen(pbuf);
2654 lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
2656 struct lpfc_vport *vport = inode->i_private;
2657 struct lpfc_debug *debug;
2660 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2664 /* Round to page boundary */
2665 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
2666 if (!debug->buffer) {
2671 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
2672 LPFC_NVMESTAT_SIZE);
2674 debug->i_private = inode->i_private;
2675 file->private_data = debug;
2683 lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
2684 size_t nbytes, loff_t *ppos)
2686 struct lpfc_debug *debug = file->private_data;
2687 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2688 struct lpfc_hba *phba = vport->phba;
2689 struct lpfc_nvmet_tgtport *tgtp;
2693 if (!phba->targetport)
2699 memset(mybuf, 0, sizeof(mybuf));
2701 if (copy_from_user(mybuf, buf, nbytes))
2705 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2706 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2707 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2708 atomic_set(&tgtp->rcv_ls_req_in, 0);
2709 atomic_set(&tgtp->rcv_ls_req_out, 0);
2710 atomic_set(&tgtp->rcv_ls_req_drop, 0);
2711 atomic_set(&tgtp->xmt_ls_abort, 0);
2712 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
2713 atomic_set(&tgtp->xmt_ls_rsp, 0);
2714 atomic_set(&tgtp->xmt_ls_drop, 0);
2715 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
2716 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
2718 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
2719 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
2720 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
2721 atomic_set(&tgtp->xmt_fcp_drop, 0);
2722 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
2723 atomic_set(&tgtp->xmt_fcp_read, 0);
2724 atomic_set(&tgtp->xmt_fcp_write, 0);
2725 atomic_set(&tgtp->xmt_fcp_rsp, 0);
2726 atomic_set(&tgtp->xmt_fcp_release, 0);
2727 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
2728 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
2729 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
2731 atomic_set(&tgtp->xmt_fcp_abort, 0);
2732 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
2733 atomic_set(&tgtp->xmt_abort_sol, 0);
2734 atomic_set(&tgtp->xmt_abort_unsol, 0);
2735 atomic_set(&tgtp->xmt_abort_rsp, 0);
2736 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
2742 lpfc_debugfs_scsistat_open(struct inode *inode, struct file *file)
2744 struct lpfc_vport *vport = inode->i_private;
2745 struct lpfc_debug *debug;
2748 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2752 /* Round to page boundary */
2753 debug->buffer = kzalloc(LPFC_SCSISTAT_SIZE, GFP_KERNEL);
2754 if (!debug->buffer) {
2759 debug->len = lpfc_debugfs_scsistat_data(vport, debug->buffer,
2760 LPFC_SCSISTAT_SIZE);
2762 debug->i_private = inode->i_private;
2763 file->private_data = debug;
2771 lpfc_debugfs_scsistat_write(struct file *file, const char __user *buf,
2772 size_t nbytes, loff_t *ppos)
2774 struct lpfc_debug *debug = file->private_data;
2775 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2776 struct lpfc_hba *phba = vport->phba;
2777 char mybuf[6] = {0};
2780 if (copy_from_user(mybuf, buf, (nbytes >= sizeof(mybuf)) ?
2781 (sizeof(mybuf) - 1) : nbytes))
2784 if ((strncmp(&mybuf[0], "reset", strlen("reset")) == 0) ||
2785 (strncmp(&mybuf[0], "zero", strlen("zero")) == 0)) {
2786 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2787 memset(&phba->sli4_hba.hdwq[i].scsi_cstat, 0,
2788 sizeof(phba->sli4_hba.hdwq[i].scsi_cstat));
2796 lpfc_debugfs_ioktime_open(struct inode *inode, struct file *file)
2798 struct lpfc_vport *vport = inode->i_private;
2799 struct lpfc_debug *debug;
2802 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2806 /* Round to page boundary */
2807 debug->buffer = kmalloc(LPFC_IOKTIME_SIZE, GFP_KERNEL);
2808 if (!debug->buffer) {
2813 debug->len = lpfc_debugfs_ioktime_data(vport, debug->buffer,
2816 debug->i_private = inode->i_private;
2817 file->private_data = debug;
2825 lpfc_debugfs_ioktime_write(struct file *file, const char __user *buf,
2826 size_t nbytes, loff_t *ppos)
2828 struct lpfc_debug *debug = file->private_data;
2829 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2830 struct lpfc_hba *phba = vport->phba;
2837 memset(mybuf, 0, sizeof(mybuf));
2839 if (copy_from_user(mybuf, buf, nbytes))
2843 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2844 phba->ktime_data_samples = 0;
2845 phba->ktime_status_samples = 0;
2846 phba->ktime_seg1_total = 0;
2847 phba->ktime_seg1_max = 0;
2848 phba->ktime_seg1_min = 0xffffffff;
2849 phba->ktime_seg2_total = 0;
2850 phba->ktime_seg2_max = 0;
2851 phba->ktime_seg2_min = 0xffffffff;
2852 phba->ktime_seg3_total = 0;
2853 phba->ktime_seg3_max = 0;
2854 phba->ktime_seg3_min = 0xffffffff;
2855 phba->ktime_seg4_total = 0;
2856 phba->ktime_seg4_max = 0;
2857 phba->ktime_seg4_min = 0xffffffff;
2858 phba->ktime_seg5_total = 0;
2859 phba->ktime_seg5_max = 0;
2860 phba->ktime_seg5_min = 0xffffffff;
2861 phba->ktime_seg6_total = 0;
2862 phba->ktime_seg6_max = 0;
2863 phba->ktime_seg6_min = 0xffffffff;
2864 phba->ktime_seg7_total = 0;
2865 phba->ktime_seg7_max = 0;
2866 phba->ktime_seg7_min = 0xffffffff;
2867 phba->ktime_seg8_total = 0;
2868 phba->ktime_seg8_max = 0;
2869 phba->ktime_seg8_min = 0xffffffff;
2870 phba->ktime_seg9_total = 0;
2871 phba->ktime_seg9_max = 0;
2872 phba->ktime_seg9_min = 0xffffffff;
2873 phba->ktime_seg10_total = 0;
2874 phba->ktime_seg10_max = 0;
2875 phba->ktime_seg10_min = 0xffffffff;
2878 return strlen(pbuf);
2879 } else if ((strncmp(pbuf, "off",
2880 sizeof("off") - 1) == 0)) {
2882 return strlen(pbuf);
2883 } else if ((strncmp(pbuf, "zero",
2884 sizeof("zero") - 1) == 0)) {
2885 phba->ktime_data_samples = 0;
2886 phba->ktime_status_samples = 0;
2887 phba->ktime_seg1_total = 0;
2888 phba->ktime_seg1_max = 0;
2889 phba->ktime_seg1_min = 0xffffffff;
2890 phba->ktime_seg2_total = 0;
2891 phba->ktime_seg2_max = 0;
2892 phba->ktime_seg2_min = 0xffffffff;
2893 phba->ktime_seg3_total = 0;
2894 phba->ktime_seg3_max = 0;
2895 phba->ktime_seg3_min = 0xffffffff;
2896 phba->ktime_seg4_total = 0;
2897 phba->ktime_seg4_max = 0;
2898 phba->ktime_seg4_min = 0xffffffff;
2899 phba->ktime_seg5_total = 0;
2900 phba->ktime_seg5_max = 0;
2901 phba->ktime_seg5_min = 0xffffffff;
2902 phba->ktime_seg6_total = 0;
2903 phba->ktime_seg6_max = 0;
2904 phba->ktime_seg6_min = 0xffffffff;
2905 phba->ktime_seg7_total = 0;
2906 phba->ktime_seg7_max = 0;
2907 phba->ktime_seg7_min = 0xffffffff;
2908 phba->ktime_seg8_total = 0;
2909 phba->ktime_seg8_max = 0;
2910 phba->ktime_seg8_min = 0xffffffff;
2911 phba->ktime_seg9_total = 0;
2912 phba->ktime_seg9_max = 0;
2913 phba->ktime_seg9_min = 0xffffffff;
2914 phba->ktime_seg10_total = 0;
2915 phba->ktime_seg10_max = 0;
2916 phba->ktime_seg10_min = 0xffffffff;
2917 return strlen(pbuf);
2923 lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2925 struct lpfc_hba *phba = inode->i_private;
2926 struct lpfc_debug *debug;
2929 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2933 /* Round to page boundary */
2934 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2935 if (!debug->buffer) {
2940 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2941 LPFC_NVMEIO_TRC_SIZE);
2943 debug->i_private = inode->i_private;
2944 file->private_data = debug;
2952 lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2953 size_t nbytes, loff_t *ppos)
2955 struct lpfc_debug *debug = file->private_data;
2956 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2965 memset(mybuf, 0, sizeof(mybuf));
2967 if (copy_from_user(mybuf, buf, nbytes))
2971 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2972 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2973 "0570 nvmeio_trc_off\n");
2974 phba->nvmeio_trc_output_idx = 0;
2975 phba->nvmeio_trc_on = 0;
2976 return strlen(pbuf);
2977 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2978 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2979 "0571 nvmeio_trc_on\n");
2980 phba->nvmeio_trc_output_idx = 0;
2981 phba->nvmeio_trc_on = 1;
2982 return strlen(pbuf);
2985 /* We must be off to allocate the trace buffer */
2986 if (phba->nvmeio_trc_on != 0)
2989 /* If not on or off, the parameter is the trace buffer size */
2990 i = kstrtoul(pbuf, 0, &sz);
2993 phba->nvmeio_trc_size = (uint32_t)sz;
2995 /* It must be a power of 2 - round down */
3002 if (phba->nvmeio_trc_size != sz)
3003 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3004 "0572 nvmeio_trc_size changed to %ld\n",
3006 phba->nvmeio_trc_size = (uint32_t)sz;
3008 /* If one previously exists, free it */
3009 kfree(phba->nvmeio_trc);
3011 /* Allocate new trace buffer and initialize */
3012 phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
3014 if (!phba->nvmeio_trc) {
3015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3016 "0573 Cannot create debugfs "
3017 "nvmeio_trc buffer\n");
3020 atomic_set(&phba->nvmeio_trc_cnt, 0);
3021 phba->nvmeio_trc_on = 0;
3022 phba->nvmeio_trc_output_idx = 0;
3024 return strlen(pbuf);
3028 lpfc_debugfs_hdwqstat_open(struct inode *inode, struct file *file)
3030 struct lpfc_vport *vport = inode->i_private;
3031 struct lpfc_debug *debug;
3034 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
3038 /* Round to page boundary */
3039 debug->buffer = kcalloc(1, LPFC_SCSISTAT_SIZE, GFP_KERNEL);
3040 if (!debug->buffer) {
3045 debug->len = lpfc_debugfs_hdwqstat_data(vport, debug->buffer,
3046 LPFC_SCSISTAT_SIZE);
3048 debug->i_private = inode->i_private;
3049 file->private_data = debug;
3057 lpfc_debugfs_hdwqstat_write(struct file *file, const char __user *buf,
3058 size_t nbytes, loff_t *ppos)
3060 struct lpfc_debug *debug = file->private_data;
3061 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
3062 struct lpfc_hba *phba = vport->phba;
3063 struct lpfc_hdwq_stat *c_stat;
3071 memset(mybuf, 0, sizeof(mybuf));
3073 if (copy_from_user(mybuf, buf, nbytes))
3077 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
3078 if (phba->nvmet_support)
3079 phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
3081 phba->hdwqstat_on |= (LPFC_CHECK_NVME_IO |
3082 LPFC_CHECK_SCSI_IO);
3083 return strlen(pbuf);
3084 } else if ((strncmp(pbuf, "nvme_on", sizeof("nvme_on") - 1) == 0)) {
3085 if (phba->nvmet_support)
3086 phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
3088 phba->hdwqstat_on |= LPFC_CHECK_NVME_IO;
3089 return strlen(pbuf);
3090 } else if ((strncmp(pbuf, "scsi_on", sizeof("scsi_on") - 1) == 0)) {
3091 if (!phba->nvmet_support)
3092 phba->hdwqstat_on |= LPFC_CHECK_SCSI_IO;
3093 return strlen(pbuf);
3094 } else if ((strncmp(pbuf, "nvme_off", sizeof("nvme_off") - 1) == 0)) {
3095 phba->hdwqstat_on &= ~(LPFC_CHECK_NVME_IO |
3096 LPFC_CHECK_NVMET_IO);
3097 return strlen(pbuf);
3098 } else if ((strncmp(pbuf, "scsi_off", sizeof("scsi_off") - 1) == 0)) {
3099 phba->hdwqstat_on &= ~LPFC_CHECK_SCSI_IO;
3100 return strlen(pbuf);
3101 } else if ((strncmp(pbuf, "off",
3102 sizeof("off") - 1) == 0)) {
3103 phba->hdwqstat_on = LPFC_CHECK_OFF;
3104 return strlen(pbuf);
3105 } else if ((strncmp(pbuf, "zero",
3106 sizeof("zero") - 1) == 0)) {
3107 for_each_present_cpu(i) {
3108 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, i);
3110 c_stat->cmpl_io = 0;
3113 return strlen(pbuf);
3119 * ---------------------------------
3120 * iDiag debugfs file access methods
3121 * ---------------------------------
3123 * All access methods are through the proper SLI4 PCI function's debugfs
3126 * /sys/kernel/debug/lpfc/fn<#>/iDiag
3130 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
3131 * @buf: The pointer to the user space buffer.
3132 * @nbytes: The number of bytes in the user space buffer.
3133 * @idiag_cmd: pointer to the idiag command struct.
3135 * This routine reads data from debugfs user space buffer and parses the
3136 * buffer for getting the idiag command and arguments. The while space in
3137 * between the set of data is used as the parsing separator.
3139 * This routine returns 0 when successful, it returns proper error code
3140 * back to the user space in error conditions.
3142 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
3143 struct lpfc_idiag_cmd *idiag_cmd)
3146 char *pbuf, *step_str;
3150 memset(mybuf, 0, sizeof(mybuf));
3151 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
3152 bsize = min(nbytes, (sizeof(mybuf)-1));
3154 if (copy_from_user(mybuf, buf, bsize))
3157 step_str = strsep(&pbuf, "\t ");
3159 /* The opcode must present */
3163 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
3164 if (idiag_cmd->opcode == 0)
3167 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
3168 step_str = strsep(&pbuf, "\t ");
3171 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
3177 * lpfc_idiag_open - idiag open debugfs
3178 * @inode: The inode pointer that contains a pointer to phba.
3179 * @file: The file pointer to attach the file operation.
3182 * This routine is the entry point for the debugfs open file operation. It
3183 * gets the reference to phba from the i_private field in @inode, it then
3184 * allocates buffer for the file operation, performs the necessary PCI config
3185 * space read into the allocated buffer according to the idiag user command
3186 * setup, and then returns a pointer to buffer in the private_data field in
3190 * This function returns zero if successful. On error it will return an
3191 * negative error value.
3194 lpfc_idiag_open(struct inode *inode, struct file *file)
3196 struct lpfc_debug *debug;
3198 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
3202 debug->i_private = inode->i_private;
3203 debug->buffer = NULL;
3204 file->private_data = debug;
3210 * lpfc_idiag_release - Release idiag access file operation
3211 * @inode: The inode pointer that contains a vport pointer. (unused)
3212 * @file: The file pointer that contains the buffer to release.
3215 * This routine is the generic release routine for the idiag access file
3216 * operation, it frees the buffer that was allocated when the debugfs file
3220 * This function returns zero.
3223 lpfc_idiag_release(struct inode *inode, struct file *file)
3225 struct lpfc_debug *debug = file->private_data;
3227 /* Free the buffers to the file operation */
3228 kfree(debug->buffer);
3235 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
3236 * @inode: The inode pointer that contains a vport pointer. (unused)
3237 * @file: The file pointer that contains the buffer to release.
3240 * This routine frees the buffer that was allocated when the debugfs file
3241 * was opened. It also reset the fields in the idiag command struct in the
3242 * case of command for write operation.
3245 * This function returns zero.
3248 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
3250 struct lpfc_debug *debug = file->private_data;
3252 if (debug->op == LPFC_IDIAG_OP_WR) {
3253 switch (idiag.cmd.opcode) {
3254 case LPFC_IDIAG_CMD_PCICFG_WR:
3255 case LPFC_IDIAG_CMD_PCICFG_ST:
3256 case LPFC_IDIAG_CMD_PCICFG_CL:
3257 case LPFC_IDIAG_CMD_QUEACC_WR:
3258 case LPFC_IDIAG_CMD_QUEACC_ST:
3259 case LPFC_IDIAG_CMD_QUEACC_CL:
3260 memset(&idiag, 0, sizeof(idiag));
3267 /* Free the buffers to the file operation */
3268 kfree(debug->buffer);
3275 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
3276 * @file: The file pointer to read from.
3277 * @buf: The buffer to copy the data to.
3278 * @nbytes: The number of bytes to read.
3279 * @ppos: The position in the file to start reading from.
3282 * This routine reads data from the @phba pci config space according to the
3283 * idiag command, and copies to user @buf. Depending on the PCI config space
3284 * read command setup, it does either a single register read of a byte
3285 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
3286 * registers from the 4K extended PCI config space.
3289 * This function returns the amount of data that was read (this could be less
3290 * than @nbytes if the end of the file was reached) or a negative error value.
3293 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
3296 struct lpfc_debug *debug = file->private_data;
3297 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3298 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
3301 struct pci_dev *pdev;
3306 pdev = phba->pcidev;
3310 /* This is a user read operation */
3311 debug->op = LPFC_IDIAG_OP_RD;
3314 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
3317 pbuffer = debug->buffer;
3322 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
3323 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3324 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
3328 /* Read single PCI config space register */
3330 case SIZE_U8: /* byte (8 bits) */
3331 pci_read_config_byte(pdev, where, &u8val);
3332 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3333 "%03x: %02x\n", where, u8val);
3335 case SIZE_U16: /* word (16 bits) */
3336 pci_read_config_word(pdev, where, &u16val);
3337 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3338 "%03x: %04x\n", where, u16val);
3340 case SIZE_U32: /* double word (32 bits) */
3341 pci_read_config_dword(pdev, where, &u32val);
3342 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3343 "%03x: %08x\n", where, u32val);
3345 case LPFC_PCI_CFG_BROWSE: /* browse all */
3353 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3357 /* Browse all PCI config space registers */
3358 offset_label = idiag.offset.last_rd;
3359 offset = offset_label;
3361 /* Read PCI config space */
3362 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3363 "%03x: ", offset_label);
3365 pci_read_config_dword(pdev, offset, &u32val);
3366 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3368 offset += sizeof(uint32_t);
3369 if (offset >= LPFC_PCI_CFG_SIZE) {
3370 len += scnprintf(pbuffer+len,
3371 LPFC_PCI_CFG_SIZE-len, "\n");
3374 index -= sizeof(uint32_t);
3376 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3378 else if (!(index % (8 * sizeof(uint32_t)))) {
3379 offset_label += (8 * sizeof(uint32_t));
3380 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3381 "\n%03x: ", offset_label);
3385 /* Set up the offset for next portion of pci cfg read */
3387 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
3388 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
3389 idiag.offset.last_rd = 0;
3391 idiag.offset.last_rd = 0;
3393 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3397 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
3398 * @file: The file pointer to read from.
3399 * @buf: The buffer to copy the user data from.
3400 * @nbytes: The number of bytes to get.
3401 * @ppos: The position in the file to start reading from.
3403 * This routine get the debugfs idiag command struct from user space and
3404 * then perform the syntax check for PCI config space read or write command
3405 * accordingly. In the case of PCI config space read command, it sets up
3406 * the command in the idiag command struct for the debugfs read operation.
3407 * In the case of PCI config space write operation, it executes the write
3408 * operation into the PCI config space accordingly.
3410 * It returns the @nbytges passing in from debugfs user space when successful.
3411 * In case of error conditions, it returns proper error code back to the user
3415 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
3416 size_t nbytes, loff_t *ppos)
3418 struct lpfc_debug *debug = file->private_data;
3419 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3420 uint32_t where, value, count;
3424 struct pci_dev *pdev;
3427 pdev = phba->pcidev;
3431 /* This is a user write operation */
3432 debug->op = LPFC_IDIAG_OP_WR;
3434 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3438 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
3439 /* Sanity check on PCI config read command line arguments */
3440 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
3442 /* Read command from PCI config space, set up command fields */
3443 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3444 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
3445 if (count == LPFC_PCI_CFG_BROWSE) {
3446 if (where % sizeof(uint32_t))
3448 /* Starting offset to browse */
3449 idiag.offset.last_rd = where;
3450 } else if ((count != sizeof(uint8_t)) &&
3451 (count != sizeof(uint16_t)) &&
3452 (count != sizeof(uint32_t)))
3454 if (count == sizeof(uint8_t)) {
3455 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
3457 if (where % sizeof(uint8_t))
3460 if (count == sizeof(uint16_t)) {
3461 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
3463 if (where % sizeof(uint16_t))
3466 if (count == sizeof(uint32_t)) {
3467 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
3469 if (where % sizeof(uint32_t))
3472 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
3473 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
3474 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3475 /* Sanity check on PCI config write command line arguments */
3476 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
3478 /* Write command to PCI config space, read-modify-write */
3479 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3480 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
3481 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
3483 if ((count != sizeof(uint8_t)) &&
3484 (count != sizeof(uint16_t)) &&
3485 (count != sizeof(uint32_t)))
3487 if (count == sizeof(uint8_t)) {
3488 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
3490 if (where % sizeof(uint8_t))
3492 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3493 pci_write_config_byte(pdev, where,
3495 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3496 rc = pci_read_config_byte(pdev, where, &u8val);
3498 u8val |= (uint8_t)value;
3499 pci_write_config_byte(pdev, where,
3503 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3504 rc = pci_read_config_byte(pdev, where, &u8val);
3506 u8val &= (uint8_t)(~value);
3507 pci_write_config_byte(pdev, where,
3512 if (count == sizeof(uint16_t)) {
3513 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
3515 if (where % sizeof(uint16_t))
3517 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3518 pci_write_config_word(pdev, where,
3520 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3521 rc = pci_read_config_word(pdev, where, &u16val);
3523 u16val |= (uint16_t)value;
3524 pci_write_config_word(pdev, where,
3528 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3529 rc = pci_read_config_word(pdev, where, &u16val);
3531 u16val &= (uint16_t)(~value);
3532 pci_write_config_word(pdev, where,
3537 if (count == sizeof(uint32_t)) {
3538 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
3540 if (where % sizeof(uint32_t))
3542 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3543 pci_write_config_dword(pdev, where, value);
3544 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3545 rc = pci_read_config_dword(pdev, where,
3549 pci_write_config_dword(pdev, where,
3553 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3554 rc = pci_read_config_dword(pdev, where,
3558 pci_write_config_dword(pdev, where,
3564 /* All other opecodes are illegal for now */
3569 memset(&idiag, 0, sizeof(idiag));
3574 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
3575 * @file: The file pointer to read from.
3576 * @buf: The buffer to copy the data to.
3577 * @nbytes: The number of bytes to read.
3578 * @ppos: The position in the file to start reading from.
3581 * This routine reads data from the @phba pci bar memory mapped space
3582 * according to the idiag command, and copies to user @buf.
3585 * This function returns the amount of data that was read (this could be less
3586 * than @nbytes if the end of the file was reached) or a negative error value.
3589 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
3592 struct lpfc_debug *debug = file->private_data;
3593 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3594 int offset_label, offset, offset_run, len = 0, index;
3595 int bar_num, acc_range, bar_size;
3597 void __iomem *mem_mapped_bar;
3599 struct pci_dev *pdev;
3602 pdev = phba->pcidev;
3606 /* This is a user read operation */
3607 debug->op = LPFC_IDIAG_OP_RD;
3610 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
3613 pbuffer = debug->buffer;
3618 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3619 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3620 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3621 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3622 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3629 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3630 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3631 if (bar_num == IDIAG_BARACC_BAR_0)
3632 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3633 else if (bar_num == IDIAG_BARACC_BAR_1)
3634 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3635 else if (bar_num == IDIAG_BARACC_BAR_2)
3636 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3639 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3640 if (bar_num == IDIAG_BARACC_BAR_0)
3641 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3647 /* Read single PCI bar space register */
3648 if (acc_range == SINGLE_WORD) {
3649 offset_run = offset;
3650 u32val = readl(mem_mapped_bar + offset_run);
3651 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
3652 "%05x: %08x\n", offset_run, u32val);
3656 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3660 /* Browse all PCI bar space registers */
3661 offset_label = idiag.offset.last_rd;
3662 offset_run = offset_label;
3664 /* Read PCI bar memory mapped space */
3665 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
3666 "%05x: ", offset_label);
3667 index = LPFC_PCI_BAR_RD_SIZE;
3669 u32val = readl(mem_mapped_bar + offset_run);
3670 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
3672 offset_run += sizeof(uint32_t);
3673 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3674 if (offset_run >= bar_size) {
3675 len += scnprintf(pbuffer+len,
3676 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3680 if (offset_run >= offset +
3681 (acc_range * sizeof(uint32_t))) {
3682 len += scnprintf(pbuffer+len,
3683 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3687 index -= sizeof(uint32_t);
3689 len += scnprintf(pbuffer+len,
3690 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3691 else if (!(index % (8 * sizeof(uint32_t)))) {
3692 offset_label += (8 * sizeof(uint32_t));
3693 len += scnprintf(pbuffer+len,
3694 LPFC_PCI_BAR_RD_BUF_SIZE-len,
3695 "\n%05x: ", offset_label);
3699 /* Set up the offset for next portion of pci bar read */
3701 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
3702 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3703 if (idiag.offset.last_rd >= bar_size)
3704 idiag.offset.last_rd = 0;
3706 if (offset_run >= offset +
3707 (acc_range * sizeof(uint32_t)))
3708 idiag.offset.last_rd = offset;
3711 if (acc_range == LPFC_PCI_BAR_BROWSE)
3712 idiag.offset.last_rd = 0;
3714 idiag.offset.last_rd = offset;
3717 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3721 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
3722 * @file: The file pointer to read from.
3723 * @buf: The buffer to copy the user data from.
3724 * @nbytes: The number of bytes to get.
3725 * @ppos: The position in the file to start reading from.
3727 * This routine get the debugfs idiag command struct from user space and
3728 * then perform the syntax check for PCI bar memory mapped space read or
3729 * write command accordingly. In the case of PCI bar memory mapped space
3730 * read command, it sets up the command in the idiag command struct for
3731 * the debugfs read operation. In the case of PCI bar memorpy mapped space
3732 * write operation, it executes the write operation into the PCI bar memory
3733 * mapped space accordingly.
3735 * It returns the @nbytges passing in from debugfs user space when successful.
3736 * In case of error conditions, it returns proper error code back to the user
3740 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
3741 size_t nbytes, loff_t *ppos)
3743 struct lpfc_debug *debug = file->private_data;
3744 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3745 uint32_t bar_num, bar_size, offset, value, acc_range;
3746 struct pci_dev *pdev;
3747 void __iomem *mem_mapped_bar;
3752 pdev = phba->pcidev;
3756 /* This is a user write operation */
3757 debug->op = LPFC_IDIAG_OP_WR;
3759 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3763 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3764 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3766 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3767 if ((bar_num != IDIAG_BARACC_BAR_0) &&
3768 (bar_num != IDIAG_BARACC_BAR_1) &&
3769 (bar_num != IDIAG_BARACC_BAR_2))
3771 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3772 if (bar_num != IDIAG_BARACC_BAR_0)
3777 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3778 if (bar_num == IDIAG_BARACC_BAR_0) {
3779 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3780 LPFC_PCI_IF0_BAR0_SIZE;
3781 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3782 } else if (bar_num == IDIAG_BARACC_BAR_1) {
3783 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3784 LPFC_PCI_IF0_BAR1_SIZE;
3785 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3786 } else if (bar_num == IDIAG_BARACC_BAR_2) {
3787 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3788 LPFC_PCI_IF0_BAR2_SIZE;
3789 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3792 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3793 if (bar_num == IDIAG_BARACC_BAR_0) {
3794 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3795 LPFC_PCI_IF2_BAR0_SIZE;
3796 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3802 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3803 if (offset % sizeof(uint32_t))
3806 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3807 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3808 /* Sanity check on PCI config read command line arguments */
3809 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3811 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3812 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3813 if (offset > bar_size - sizeof(uint32_t))
3815 /* Starting offset to browse */
3816 idiag.offset.last_rd = offset;
3817 } else if (acc_range > SINGLE_WORD) {
3818 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3820 /* Starting offset to browse */
3821 idiag.offset.last_rd = offset;
3822 } else if (acc_range != SINGLE_WORD)
3824 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3825 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3826 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3827 /* Sanity check on PCI bar write command line arguments */
3828 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3830 /* Write command to PCI bar space, read-modify-write */
3831 acc_range = SINGLE_WORD;
3832 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3833 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3834 writel(value, mem_mapped_bar + offset);
3835 readl(mem_mapped_bar + offset);
3837 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3838 u32val = readl(mem_mapped_bar + offset);
3840 writel(u32val, mem_mapped_bar + offset);
3841 readl(mem_mapped_bar + offset);
3843 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3844 u32val = readl(mem_mapped_bar + offset);
3846 writel(u32val, mem_mapped_bar + offset);
3847 readl(mem_mapped_bar + offset);
3850 /* All other opecodes are illegal for now */
3855 memset(&idiag, 0, sizeof(idiag));
3860 __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3861 char *pbuffer, int len)
3866 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3867 "\t\t%s WQ info: ", wqtype);
3868 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3869 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3870 qp->assoc_qid, qp->q_cnt_1,
3871 (unsigned long long)qp->q_cnt_4);
3872 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3873 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3874 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]",
3875 qp->queue_id, qp->entry_count,
3876 qp->entry_size, qp->host_index,
3877 qp->hba_index, qp->notify_interval);
3878 len += scnprintf(pbuffer + len,
3879 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3884 lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3885 int *len, int max_cnt, int cq_id)
3887 struct lpfc_queue *qp;
3890 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
3891 qp = phba->sli4_hba.hdwq[qidx].io_wq;
3892 if (qp->assoc_qid != cq_id)
3894 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3895 if (*len >= max_cnt)
3902 __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3903 char *pbuffer, int len)
3908 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3909 "\t%s CQ info: ", cqtype);
3910 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3911 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3912 "xabt:x%x wq:x%llx]\n",
3913 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3914 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3915 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3916 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3917 "HST-IDX[%04d], NTFI[%03d], PLMT[%03d]",
3918 qp->queue_id, qp->entry_count,
3919 qp->entry_size, qp->host_index,
3920 qp->notify_interval, qp->max_proc_limit);
3922 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3929 __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3930 char *rqtype, char *pbuffer, int len)
3935 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3936 "\t\t%s RQ info: ", rqtype);
3937 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3938 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
3939 "posted:x%x rcv:x%llx]\n",
3940 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3941 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3942 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3943 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3944 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
3945 qp->queue_id, qp->entry_count, qp->entry_size,
3946 qp->host_index, qp->hba_index, qp->notify_interval);
3947 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3948 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3949 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
3950 datqp->queue_id, datqp->entry_count,
3951 datqp->entry_size, datqp->host_index,
3952 datqp->hba_index, datqp->notify_interval);
3957 lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
3958 int *len, int max_cnt, int eqidx, int eq_id)
3960 struct lpfc_queue *qp;
3963 qp = phba->sli4_hba.hdwq[eqidx].io_cq;
3965 *len = __lpfc_idiag_print_cq(qp, "IO", pbuffer, *len);
3967 /* Reset max counter */
3970 if (*len >= max_cnt)
3973 rc = lpfc_idiag_wqs_for_cq(phba, "IO", pbuffer, len,
3974 max_cnt, qp->queue_id);
3978 if ((eqidx < phba->cfg_nvmet_mrq) && phba->nvmet_support) {
3980 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3981 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3983 /* Reset max counter */
3986 if (*len >= max_cnt)
3990 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3991 *len = __lpfc_idiag_print_rqpair(qp,
3992 phba->sli4_hba.nvmet_mrq_data[eqidx],
3993 "NVMET MRQ", pbuffer, *len);
3995 if (*len >= max_cnt)
4003 __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
4004 char *pbuffer, int len)
4009 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
4010 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
4011 "cqe_proc:x%x eqe_proc:x%llx eqd %d]\n",
4012 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
4013 (unsigned long long)qp->q_cnt_4, qp->q_mode);
4014 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
4015 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
4016 "HST-IDX[%04d], NTFI[%03d], PLMT[%03d], AFFIN[%03d]",
4017 qp->queue_id, qp->entry_count, qp->entry_size,
4018 qp->host_index, qp->notify_interval,
4019 qp->max_proc_limit, qp->chann);
4020 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
4027 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
4028 * @file: The file pointer to read from.
4029 * @buf: The buffer to copy the data to.
4030 * @nbytes: The number of bytes to read.
4031 * @ppos: The position in the file to start reading from.
4034 * This routine reads data from the @phba SLI4 PCI function queue information,
4035 * and copies to user @buf.
4036 * This routine only returns 1 EQs worth of information. It remembers the last
4037 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
4038 * retrieve all EQs allocated for the phba.
4041 * This function returns the amount of data that was read (this could be less
4042 * than @nbytes if the end of the file was reached) or a negative error value.
4045 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
4048 struct lpfc_debug *debug = file->private_data;
4049 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4051 int max_cnt, rc, x, len = 0;
4052 struct lpfc_queue *qp = NULL;
4055 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
4058 pbuffer = debug->buffer;
4059 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
4064 spin_lock_irq(&phba->hbalock);
4066 /* Fast-path event queue */
4067 if (phba->sli4_hba.hdwq && phba->cfg_hdw_queue) {
4069 x = phba->lpfc_idiag_last_eq;
4070 phba->lpfc_idiag_last_eq++;
4071 if (phba->lpfc_idiag_last_eq >= phba->cfg_hdw_queue)
4072 phba->lpfc_idiag_last_eq = 0;
4074 len += scnprintf(pbuffer + len,
4075 LPFC_QUE_INFO_GET_BUF_SIZE - len,
4076 "HDWQ %d out of %d HBA HDWQs\n",
4077 x, phba->cfg_hdw_queue);
4080 qp = phba->sli4_hba.hdwq[x].hba_eq;
4084 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
4086 /* Reset max counter */
4092 /* will dump both fcp and nvme cqs/wqs for the eq */
4093 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
4094 max_cnt, x, qp->queue_id);
4098 /* Only EQ 0 has slow path CQs configured */
4102 /* Slow-path mailbox CQ */
4103 qp = phba->sli4_hba.mbx_cq;
4104 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
4108 /* Slow-path MBOX MQ */
4109 qp = phba->sli4_hba.mbx_wq;
4110 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
4114 /* Slow-path ELS response CQ */
4115 qp = phba->sli4_hba.els_cq;
4116 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
4117 /* Reset max counter */
4123 /* Slow-path ELS WQ */
4124 qp = phba->sli4_hba.els_wq;
4125 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
4129 qp = phba->sli4_hba.hdr_rq;
4130 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
4131 "ELS RQpair", pbuffer, len);
4135 /* Slow-path NVME LS response CQ */
4136 qp = phba->sli4_hba.nvmels_cq;
4137 len = __lpfc_idiag_print_cq(qp, "NVME LS",
4139 /* Reset max counter */
4145 /* Slow-path NVME LS WQ */
4146 qp = phba->sli4_hba.nvmels_wq;
4147 len = __lpfc_idiag_print_wq(qp, "NVME LS",
4155 spin_unlock_irq(&phba->hbalock);
4156 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4159 len += scnprintf(pbuffer + len,
4160 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
4162 spin_unlock_irq(&phba->hbalock);
4163 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4167 * lpfc_idiag_que_param_check - queue access command parameter sanity check
4168 * @q: The pointer to queue structure.
4169 * @index: The index into a queue entry.
4170 * @count: The number of queue entries to access.
4173 * The routine performs sanity check on device queue access method commands.
4176 * This function returns -EINVAL when fails the sanity check, otherwise, it
4180 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
4182 /* Only support single entry read or browsing */
4183 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
4185 if (index > q->entry_count - 1)
4191 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
4192 * @pbuffer: The pointer to buffer to copy the read data into.
4193 * @pque: The pointer to the queue to be read.
4194 * @index: The index into the queue entry.
4197 * This routine reads out a single entry from the given queue's index location
4198 * and copies it into the buffer provided.
4201 * This function returns 0 when it fails, otherwise, it returns the length of
4202 * the data read into the buffer provided.
4205 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
4211 if (!pbuffer || !pque)
4214 esize = pque->entry_size;
4215 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
4216 "QE-INDEX[%04d]:\n", index);
4219 pentry = lpfc_sli4_qe(pque, index);
4221 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
4224 offset += sizeof(uint32_t);
4225 esize -= sizeof(uint32_t);
4226 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
4227 len += scnprintf(pbuffer+len,
4228 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
4230 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
4236 * lpfc_idiag_queacc_read - idiag debugfs read port queue
4237 * @file: The file pointer to read from.
4238 * @buf: The buffer to copy the data to.
4239 * @nbytes: The number of bytes to read.
4240 * @ppos: The position in the file to start reading from.
4243 * This routine reads data from the @phba device queue memory according to the
4244 * idiag command, and copies to user @buf. Depending on the queue dump read
4245 * command setup, it does either a single queue entry read or browing through
4246 * all entries of the queue.
4249 * This function returns the amount of data that was read (this could be less
4250 * than @nbytes if the end of the file was reached) or a negative error value.
4253 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
4256 struct lpfc_debug *debug = file->private_data;
4257 uint32_t last_index, index, count;
4258 struct lpfc_queue *pque = NULL;
4262 /* This is a user read operation */
4263 debug->op = LPFC_IDIAG_OP_RD;
4266 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
4269 pbuffer = debug->buffer;
4274 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4275 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
4276 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
4277 pque = (struct lpfc_queue *)idiag.ptr_private;
4281 /* Browse the queue starting from index */
4282 if (count == LPFC_QUE_ACC_BROWSE)
4285 /* Read a single entry from the queue */
4286 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
4288 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4292 /* Browse all entries from the queue */
4293 last_index = idiag.offset.last_rd;
4296 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
4297 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
4299 if (index > pque->entry_count - 1)
4303 /* Set up the offset for next portion of pci cfg read */
4304 if (index > pque->entry_count - 1)
4306 idiag.offset.last_rd = index;
4308 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4312 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
4313 * @file: The file pointer to read from.
4314 * @buf: The buffer to copy the user data from.
4315 * @nbytes: The number of bytes to get.
4316 * @ppos: The position in the file to start reading from.
4318 * This routine get the debugfs idiag command struct from user space and then
4319 * perform the syntax check for port queue read (dump) or write (set) command
4320 * accordingly. In the case of port queue read command, it sets up the command
4321 * in the idiag command struct for the following debugfs read operation. In
4322 * the case of port queue write operation, it executes the write operation
4323 * into the port queue entry accordingly.
4325 * It returns the @nbytges passing in from debugfs user space when successful.
4326 * In case of error conditions, it returns proper error code back to the user
4330 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
4331 size_t nbytes, loff_t *ppos)
4333 struct lpfc_debug *debug = file->private_data;
4334 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4335 uint32_t qidx, quetp, queid, index, count, offset, value;
4337 struct lpfc_queue *pque, *qp;
4340 /* This is a user write operation */
4341 debug->op = LPFC_IDIAG_OP_WR;
4343 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4347 /* Get and sanity check on command feilds */
4348 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
4349 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
4350 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
4351 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
4352 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
4353 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
4355 /* Sanity check on command line arguments */
4356 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
4357 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
4358 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
4359 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
4363 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4364 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
4371 /* HBA event queue */
4372 if (phba->sli4_hba.hdwq) {
4373 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
4374 qp = phba->sli4_hba.hdwq[qidx].hba_eq;
4375 if (qp && qp->queue_id == queid) {
4377 rc = lpfc_idiag_que_param_check(qp,
4381 idiag.ptr_private = qp;
4389 /* MBX complete queue */
4390 if (phba->sli4_hba.mbx_cq &&
4391 phba->sli4_hba.mbx_cq->queue_id == queid) {
4393 rc = lpfc_idiag_que_param_check(
4394 phba->sli4_hba.mbx_cq, index, count);
4397 idiag.ptr_private = phba->sli4_hba.mbx_cq;
4400 /* ELS complete queue */
4401 if (phba->sli4_hba.els_cq &&
4402 phba->sli4_hba.els_cq->queue_id == queid) {
4404 rc = lpfc_idiag_que_param_check(
4405 phba->sli4_hba.els_cq, index, count);
4408 idiag.ptr_private = phba->sli4_hba.els_cq;
4411 /* NVME LS complete queue */
4412 if (phba->sli4_hba.nvmels_cq &&
4413 phba->sli4_hba.nvmels_cq->queue_id == queid) {
4415 rc = lpfc_idiag_que_param_check(
4416 phba->sli4_hba.nvmels_cq, index, count);
4419 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
4422 /* FCP complete queue */
4423 if (phba->sli4_hba.hdwq) {
4424 for (qidx = 0; qidx < phba->cfg_hdw_queue;
4426 qp = phba->sli4_hba.hdwq[qidx].io_cq;
4427 if (qp && qp->queue_id == queid) {
4429 rc = lpfc_idiag_que_param_check(
4433 idiag.ptr_private = qp;
4441 /* MBX work queue */
4442 if (phba->sli4_hba.mbx_wq &&
4443 phba->sli4_hba.mbx_wq->queue_id == queid) {
4445 rc = lpfc_idiag_que_param_check(
4446 phba->sli4_hba.mbx_wq, index, count);
4449 idiag.ptr_private = phba->sli4_hba.mbx_wq;
4455 /* ELS work queue */
4456 if (phba->sli4_hba.els_wq &&
4457 phba->sli4_hba.els_wq->queue_id == queid) {
4459 rc = lpfc_idiag_que_param_check(
4460 phba->sli4_hba.els_wq, index, count);
4463 idiag.ptr_private = phba->sli4_hba.els_wq;
4466 /* NVME LS work queue */
4467 if (phba->sli4_hba.nvmels_wq &&
4468 phba->sli4_hba.nvmels_wq->queue_id == queid) {
4470 rc = lpfc_idiag_que_param_check(
4471 phba->sli4_hba.nvmels_wq, index, count);
4474 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
4478 if (phba->sli4_hba.hdwq) {
4479 /* FCP/SCSI work queue */
4480 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
4481 qp = phba->sli4_hba.hdwq[qidx].io_wq;
4482 if (qp && qp->queue_id == queid) {
4484 rc = lpfc_idiag_que_param_check(
4488 idiag.ptr_private = qp;
4498 if (phba->sli4_hba.hdr_rq &&
4499 phba->sli4_hba.hdr_rq->queue_id == queid) {
4501 rc = lpfc_idiag_que_param_check(
4502 phba->sli4_hba.hdr_rq, index, count);
4505 idiag.ptr_private = phba->sli4_hba.hdr_rq;
4509 if (phba->sli4_hba.dat_rq &&
4510 phba->sli4_hba.dat_rq->queue_id == queid) {
4512 rc = lpfc_idiag_que_param_check(
4513 phba->sli4_hba.dat_rq, index, count);
4516 idiag.ptr_private = phba->sli4_hba.dat_rq;
4528 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4529 if (count == LPFC_QUE_ACC_BROWSE)
4530 idiag.offset.last_rd = index;
4533 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
4534 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
4535 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
4536 /* Additional sanity checks on write operation */
4537 pque = (struct lpfc_queue *)idiag.ptr_private;
4538 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
4540 pentry = lpfc_sli4_qe(pque, index);
4542 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
4544 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
4546 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
4552 /* Clean out command structure on command error out */
4553 memset(&idiag, 0, sizeof(idiag));
4558 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
4559 * @phba: The pointer to hba structure.
4560 * @pbuffer: The pointer to the buffer to copy the data to.
4561 * @len: The length of bytes to copied.
4562 * @drbregid: The id to doorbell registers.
4565 * This routine reads a doorbell register and copies its content to the
4566 * user buffer pointed to by @pbuffer.
4569 * This function returns the amount of data that was copied into @pbuffer.
4572 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4573 int len, uint32_t drbregid)
4581 len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE-len,
4582 "EQ-DRB-REG: 0x%08x\n",
4583 readl(phba->sli4_hba.EQDBregaddr));
4586 len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE - len,
4587 "CQ-DRB-REG: 0x%08x\n",
4588 readl(phba->sli4_hba.CQDBregaddr));
4591 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
4592 "MQ-DRB-REG: 0x%08x\n",
4593 readl(phba->sli4_hba.MQDBregaddr));
4596 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
4597 "WQ-DRB-REG: 0x%08x\n",
4598 readl(phba->sli4_hba.WQDBregaddr));
4601 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
4602 "RQ-DRB-REG: 0x%08x\n",
4603 readl(phba->sli4_hba.RQDBregaddr));
4613 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
4614 * @file: The file pointer to read from.
4615 * @buf: The buffer to copy the data to.
4616 * @nbytes: The number of bytes to read.
4617 * @ppos: The position in the file to start reading from.
4620 * This routine reads data from the @phba device doorbell register according
4621 * to the idiag command, and copies to user @buf. Depending on the doorbell
4622 * register read command setup, it does either a single doorbell register
4623 * read or dump all doorbell registers.
4626 * This function returns the amount of data that was read (this could be less
4627 * than @nbytes if the end of the file was reached) or a negative error value.
4630 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
4633 struct lpfc_debug *debug = file->private_data;
4634 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4635 uint32_t drb_reg_id, i;
4639 /* This is a user read operation */
4640 debug->op = LPFC_IDIAG_OP_RD;
4643 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
4646 pbuffer = debug->buffer;
4651 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
4652 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4656 if (drb_reg_id == LPFC_DRB_ACC_ALL)
4657 for (i = 1; i <= LPFC_DRB_MAX; i++)
4658 len = lpfc_idiag_drbacc_read_reg(phba,
4661 len = lpfc_idiag_drbacc_read_reg(phba,
4662 pbuffer, len, drb_reg_id);
4664 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4668 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
4669 * @file: The file pointer to read from.
4670 * @buf: The buffer to copy the user data from.
4671 * @nbytes: The number of bytes to get.
4672 * @ppos: The position in the file to start reading from.
4674 * This routine get the debugfs idiag command struct from user space and then
4675 * perform the syntax check for port doorbell register read (dump) or write
4676 * (set) command accordingly. In the case of port queue read command, it sets
4677 * up the command in the idiag command struct for the following debugfs read
4678 * operation. In the case of port doorbell register write operation, it
4679 * executes the write operation into the port doorbell register accordingly.
4681 * It returns the @nbytges passing in from debugfs user space when successful.
4682 * In case of error conditions, it returns proper error code back to the user
4686 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4687 size_t nbytes, loff_t *ppos)
4689 struct lpfc_debug *debug = file->private_data;
4690 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4691 uint32_t drb_reg_id, value, reg_val = 0;
4692 void __iomem *drb_reg;
4695 /* This is a user write operation */
4696 debug->op = LPFC_IDIAG_OP_WR;
4698 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4702 /* Sanity check on command line arguments */
4703 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4704 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
4706 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4707 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4708 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4709 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4711 if (drb_reg_id > LPFC_DRB_MAX)
4713 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4714 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4716 if ((drb_reg_id > LPFC_DRB_MAX) &&
4717 (drb_reg_id != LPFC_DRB_ACC_ALL))
4722 /* Perform the write access operation */
4723 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4724 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4725 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4726 switch (drb_reg_id) {
4728 drb_reg = phba->sli4_hba.EQDBregaddr;
4731 drb_reg = phba->sli4_hba.CQDBregaddr;
4734 drb_reg = phba->sli4_hba.MQDBregaddr;
4737 drb_reg = phba->sli4_hba.WQDBregaddr;
4740 drb_reg = phba->sli4_hba.RQDBregaddr;
4746 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4748 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4749 reg_val = readl(drb_reg);
4752 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4753 reg_val = readl(drb_reg);
4756 writel(reg_val, drb_reg);
4757 readl(drb_reg); /* flush */
4762 /* Clean out command structure on command error out */
4763 memset(&idiag, 0, sizeof(idiag));
4768 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4769 * @phba: The pointer to hba structure.
4770 * @pbuffer: The pointer to the buffer to copy the data to.
4771 * @len: The length of bytes to copied.
4772 * @drbregid: The id to doorbell registers.
4775 * This routine reads a control register and copies its content to the
4776 * user buffer pointed to by @pbuffer.
4779 * This function returns the amount of data that was copied into @pbuffer.
4782 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4783 int len, uint32_t ctlregid)
4790 case LPFC_CTL_PORT_SEM:
4791 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4792 "Port SemReg: 0x%08x\n",
4793 readl(phba->sli4_hba.conf_regs_memmap_p +
4794 LPFC_CTL_PORT_SEM_OFFSET));
4796 case LPFC_CTL_PORT_STA:
4797 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4798 "Port StaReg: 0x%08x\n",
4799 readl(phba->sli4_hba.conf_regs_memmap_p +
4800 LPFC_CTL_PORT_STA_OFFSET));
4802 case LPFC_CTL_PORT_CTL:
4803 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4804 "Port CtlReg: 0x%08x\n",
4805 readl(phba->sli4_hba.conf_regs_memmap_p +
4806 LPFC_CTL_PORT_CTL_OFFSET));
4808 case LPFC_CTL_PORT_ER1:
4809 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4810 "Port Er1Reg: 0x%08x\n",
4811 readl(phba->sli4_hba.conf_regs_memmap_p +
4812 LPFC_CTL_PORT_ER1_OFFSET));
4814 case LPFC_CTL_PORT_ER2:
4815 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4816 "Port Er2Reg: 0x%08x\n",
4817 readl(phba->sli4_hba.conf_regs_memmap_p +
4818 LPFC_CTL_PORT_ER2_OFFSET));
4820 case LPFC_CTL_PDEV_CTL:
4821 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4822 "PDev CtlReg: 0x%08x\n",
4823 readl(phba->sli4_hba.conf_regs_memmap_p +
4824 LPFC_CTL_PDEV_CTL_OFFSET));
4833 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4834 * @file: The file pointer to read from.
4835 * @buf: The buffer to copy the data to.
4836 * @nbytes: The number of bytes to read.
4837 * @ppos: The position in the file to start reading from.
4840 * This routine reads data from the @phba port and device registers according
4841 * to the idiag command, and copies to user @buf.
4844 * This function returns the amount of data that was read (this could be less
4845 * than @nbytes if the end of the file was reached) or a negative error value.
4848 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4851 struct lpfc_debug *debug = file->private_data;
4852 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4853 uint32_t ctl_reg_id, i;
4857 /* This is a user read operation */
4858 debug->op = LPFC_IDIAG_OP_RD;
4861 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4864 pbuffer = debug->buffer;
4869 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4870 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4874 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4875 for (i = 1; i <= LPFC_CTL_MAX; i++)
4876 len = lpfc_idiag_ctlacc_read_reg(phba,
4879 len = lpfc_idiag_ctlacc_read_reg(phba,
4880 pbuffer, len, ctl_reg_id);
4882 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4886 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4887 * @file: The file pointer to read from.
4888 * @buf: The buffer to copy the user data from.
4889 * @nbytes: The number of bytes to get.
4890 * @ppos: The position in the file to start reading from.
4892 * This routine get the debugfs idiag command struct from user space and then
4893 * perform the syntax check for port and device control register read (dump)
4894 * or write (set) command accordingly.
4896 * It returns the @nbytges passing in from debugfs user space when successful.
4897 * In case of error conditions, it returns proper error code back to the user
4901 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4902 size_t nbytes, loff_t *ppos)
4904 struct lpfc_debug *debug = file->private_data;
4905 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4906 uint32_t ctl_reg_id, value, reg_val = 0;
4907 void __iomem *ctl_reg;
4910 /* This is a user write operation */
4911 debug->op = LPFC_IDIAG_OP_WR;
4913 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4917 /* Sanity check on command line arguments */
4918 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4919 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4921 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4922 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4923 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4924 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4926 if (ctl_reg_id > LPFC_CTL_MAX)
4928 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4929 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4931 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4932 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4937 /* Perform the write access operation */
4938 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4939 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4940 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4941 switch (ctl_reg_id) {
4942 case LPFC_CTL_PORT_SEM:
4943 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4944 LPFC_CTL_PORT_SEM_OFFSET;
4946 case LPFC_CTL_PORT_STA:
4947 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4948 LPFC_CTL_PORT_STA_OFFSET;
4950 case LPFC_CTL_PORT_CTL:
4951 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4952 LPFC_CTL_PORT_CTL_OFFSET;
4954 case LPFC_CTL_PORT_ER1:
4955 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4956 LPFC_CTL_PORT_ER1_OFFSET;
4958 case LPFC_CTL_PORT_ER2:
4959 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4960 LPFC_CTL_PORT_ER2_OFFSET;
4962 case LPFC_CTL_PDEV_CTL:
4963 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4964 LPFC_CTL_PDEV_CTL_OFFSET;
4970 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4972 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4973 reg_val = readl(ctl_reg);
4976 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4977 reg_val = readl(ctl_reg);
4980 writel(reg_val, ctl_reg);
4981 readl(ctl_reg); /* flush */
4986 /* Clean out command structure on command error out */
4987 memset(&idiag, 0, sizeof(idiag));
4992 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4993 * @phba: Pointer to HBA context object.
4994 * @pbuffer: Pointer to data buffer.
4997 * This routine gets the driver mailbox access debugfs setup information.
5000 * This function returns the amount of data that was read (this could be less
5001 * than @nbytes if the end of the file was reached) or a negative error value.
5004 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
5006 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
5009 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5010 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5011 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5012 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5014 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
5015 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
5016 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
5017 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
5018 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
5019 "mbx_word_cnt: %04d\n", mbx_word_cnt);
5020 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
5021 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
5027 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
5028 * @file: The file pointer to read from.
5029 * @buf: The buffer to copy the data to.
5030 * @nbytes: The number of bytes to read.
5031 * @ppos: The position in the file to start reading from.
5034 * This routine reads data from the @phba driver mailbox access debugfs setup
5038 * This function returns the amount of data that was read (this could be less
5039 * than @nbytes if the end of the file was reached) or a negative error value.
5042 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
5045 struct lpfc_debug *debug = file->private_data;
5046 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5050 /* This is a user read operation */
5051 debug->op = LPFC_IDIAG_OP_RD;
5054 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
5057 pbuffer = debug->buffer;
5062 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
5063 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
5066 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
5068 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
5072 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
5073 * @file: The file pointer to read from.
5074 * @buf: The buffer to copy the user data from.
5075 * @nbytes: The number of bytes to get.
5076 * @ppos: The position in the file to start reading from.
5078 * This routine get the debugfs idiag command struct from user space and then
5079 * perform the syntax check for driver mailbox command (dump) and sets up the
5080 * necessary states in the idiag command struct accordingly.
5082 * It returns the @nbytges passing in from debugfs user space when successful.
5083 * In case of error conditions, it returns proper error code back to the user
5087 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
5088 size_t nbytes, loff_t *ppos)
5090 struct lpfc_debug *debug = file->private_data;
5091 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
5094 /* This is a user write operation */
5095 debug->op = LPFC_IDIAG_OP_WR;
5097 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
5101 /* Sanity check on command line arguments */
5102 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5103 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5104 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5105 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5107 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
5108 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
5110 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
5111 (mbx_dump_map != LPFC_MBX_DMP_ALL))
5113 if (mbx_word_cnt > sizeof(MAILBOX_t))
5115 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
5116 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
5118 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
5119 (mbx_dump_map != LPFC_MBX_DMP_ALL))
5121 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
5123 if (mbx_mbox_cmd != 0x9b)
5128 if (mbx_word_cnt == 0)
5130 if (rc != LPFC_MBX_DMP_ARG)
5132 if (mbx_mbox_cmd & ~0xff)
5135 /* condition for stop mailbox dump */
5136 if (mbx_dump_cnt == 0)
5142 /* Clean out command structure on command error out */
5143 memset(&idiag, 0, sizeof(idiag));
5147 /* Clean out command structure on command error out */
5148 memset(&idiag, 0, sizeof(idiag));
5153 * lpfc_idiag_extacc_avail_get - get the available extents information
5154 * @phba: pointer to lpfc hba data structure.
5155 * @pbuffer: pointer to internal buffer.
5156 * @len: length into the internal buffer data has been copied.
5159 * This routine is to get the available extent information.
5162 * overall lenth of the data read into the internal buffer.
5165 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
5167 uint16_t ext_cnt, ext_size;
5169 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5170 "\nAvailable Extents Information:\n");
5172 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5173 "\tPort Available VPI extents: ");
5174 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
5175 &ext_cnt, &ext_size);
5176 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5177 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5179 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5180 "\tPort Available VFI extents: ");
5181 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
5182 &ext_cnt, &ext_size);
5183 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5184 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5186 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5187 "\tPort Available RPI extents: ");
5188 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
5189 &ext_cnt, &ext_size);
5190 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5191 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5193 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5194 "\tPort Available XRI extents: ");
5195 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
5196 &ext_cnt, &ext_size);
5197 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5198 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5204 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
5205 * @phba: pointer to lpfc hba data structure.
5206 * @pbuffer: pointer to internal buffer.
5207 * @len: length into the internal buffer data has been copied.
5210 * This routine is to get the allocated extent information.
5213 * overall lenth of the data read into the internal buffer.
5216 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
5218 uint16_t ext_cnt, ext_size;
5221 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5222 "\nAllocated Extents Information:\n");
5224 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5225 "\tHost Allocated VPI extents: ");
5226 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
5227 &ext_cnt, &ext_size);
5229 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5230 "Port %d Extent %3d, Size %3d\n",
5231 phba->brd_no, ext_cnt, ext_size);
5233 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5236 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5237 "\tHost Allocated VFI extents: ");
5238 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
5239 &ext_cnt, &ext_size);
5241 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5242 "Port %d Extent %3d, Size %3d\n",
5243 phba->brd_no, ext_cnt, ext_size);
5245 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5248 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5249 "\tHost Allocated RPI extents: ");
5250 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
5251 &ext_cnt, &ext_size);
5253 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5254 "Port %d Extent %3d, Size %3d\n",
5255 phba->brd_no, ext_cnt, ext_size);
5257 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5260 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5261 "\tHost Allocated XRI extents: ");
5262 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
5263 &ext_cnt, &ext_size);
5265 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5266 "Port %d Extent %3d, Size %3d\n",
5267 phba->brd_no, ext_cnt, ext_size);
5269 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5276 * lpfc_idiag_extacc_drivr_get - get driver extent information
5277 * @phba: pointer to lpfc hba data structure.
5278 * @pbuffer: pointer to internal buffer.
5279 * @len: length into the internal buffer data has been copied.
5282 * This routine is to get the driver extent information.
5285 * overall lenth of the data read into the internal buffer.
5288 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
5290 struct lpfc_rsrc_blks *rsrc_blks;
5293 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5294 "\nDriver Extents Information:\n");
5296 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5297 "\tVPI extents:\n");
5299 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
5300 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5301 "\t\tBlock %3d: Start %4d, Count %4d\n",
5302 index, rsrc_blks->rsrc_start,
5303 rsrc_blks->rsrc_size);
5306 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5307 "\tVFI extents:\n");
5309 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
5311 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5312 "\t\tBlock %3d: Start %4d, Count %4d\n",
5313 index, rsrc_blks->rsrc_start,
5314 rsrc_blks->rsrc_size);
5318 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5319 "\tRPI extents:\n");
5321 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
5323 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5324 "\t\tBlock %3d: Start %4d, Count %4d\n",
5325 index, rsrc_blks->rsrc_start,
5326 rsrc_blks->rsrc_size);
5330 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5331 "\tXRI extents:\n");
5333 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
5335 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5336 "\t\tBlock %3d: Start %4d, Count %4d\n",
5337 index, rsrc_blks->rsrc_start,
5338 rsrc_blks->rsrc_size);
5346 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
5347 * @file: The file pointer to read from.
5348 * @buf: The buffer to copy the user data from.
5349 * @nbytes: The number of bytes to get.
5350 * @ppos: The position in the file to start reading from.
5352 * This routine get the debugfs idiag command struct from user space and then
5353 * perform the syntax check for extent information access commands and sets
5354 * up the necessary states in the idiag command struct accordingly.
5356 * It returns the @nbytges passing in from debugfs user space when successful.
5357 * In case of error conditions, it returns proper error code back to the user
5361 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
5362 size_t nbytes, loff_t *ppos)
5364 struct lpfc_debug *debug = file->private_data;
5368 /* This is a user write operation */
5369 debug->op = LPFC_IDIAG_OP_WR;
5371 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
5375 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
5377 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
5379 if (rc != LPFC_EXT_ACC_CMD_ARG)
5381 if (!(ext_map & LPFC_EXT_ACC_ALL))
5386 /* Clean out command structure on command error out */
5387 memset(&idiag, 0, sizeof(idiag));
5392 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
5393 * @file: The file pointer to read from.
5394 * @buf: The buffer to copy the data to.
5395 * @nbytes: The number of bytes to read.
5396 * @ppos: The position in the file to start reading from.
5399 * This routine reads data from the proper extent information according to
5400 * the idiag command, and copies to user @buf.
5403 * This function returns the amount of data that was read (this could be less
5404 * than @nbytes if the end of the file was reached) or a negative error value.
5407 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
5410 struct lpfc_debug *debug = file->private_data;
5411 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5416 /* This is a user read operation */
5417 debug->op = LPFC_IDIAG_OP_RD;
5420 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
5423 pbuffer = debug->buffer;
5426 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
5429 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
5430 if (ext_map & LPFC_EXT_ACC_AVAIL)
5431 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
5432 if (ext_map & LPFC_EXT_ACC_ALLOC)
5433 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
5434 if (ext_map & LPFC_EXT_ACC_DRIVR)
5435 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
5437 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
5440 #undef lpfc_debugfs_op_disc_trc
5441 static const struct file_operations lpfc_debugfs_op_disc_trc = {
5442 .owner = THIS_MODULE,
5443 .open = lpfc_debugfs_disc_trc_open,
5444 .llseek = lpfc_debugfs_lseek,
5445 .read = lpfc_debugfs_read,
5446 .release = lpfc_debugfs_release,
5449 #undef lpfc_debugfs_op_nodelist
5450 static const struct file_operations lpfc_debugfs_op_nodelist = {
5451 .owner = THIS_MODULE,
5452 .open = lpfc_debugfs_nodelist_open,
5453 .llseek = lpfc_debugfs_lseek,
5454 .read = lpfc_debugfs_read,
5455 .release = lpfc_debugfs_release,
5458 #undef lpfc_debugfs_op_multixripools
5459 static const struct file_operations lpfc_debugfs_op_multixripools = {
5460 .owner = THIS_MODULE,
5461 .open = lpfc_debugfs_multixripools_open,
5462 .llseek = lpfc_debugfs_lseek,
5463 .read = lpfc_debugfs_read,
5464 .write = lpfc_debugfs_multixripools_write,
5465 .release = lpfc_debugfs_release,
5468 #undef lpfc_debugfs_op_hbqinfo
5469 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
5470 .owner = THIS_MODULE,
5471 .open = lpfc_debugfs_hbqinfo_open,
5472 .llseek = lpfc_debugfs_lseek,
5473 .read = lpfc_debugfs_read,
5474 .release = lpfc_debugfs_release,
5477 #ifdef LPFC_HDWQ_LOCK_STAT
5478 #undef lpfc_debugfs_op_lockstat
5479 static const struct file_operations lpfc_debugfs_op_lockstat = {
5480 .owner = THIS_MODULE,
5481 .open = lpfc_debugfs_lockstat_open,
5482 .llseek = lpfc_debugfs_lseek,
5483 .read = lpfc_debugfs_read,
5484 .write = lpfc_debugfs_lockstat_write,
5485 .release = lpfc_debugfs_release,
5489 #undef lpfc_debugfs_ras_log
5490 static const struct file_operations lpfc_debugfs_ras_log = {
5491 .owner = THIS_MODULE,
5492 .open = lpfc_debugfs_ras_log_open,
5493 .llseek = lpfc_debugfs_lseek,
5494 .read = lpfc_debugfs_read,
5495 .release = lpfc_debugfs_ras_log_release,
5498 #undef lpfc_debugfs_op_dumpHBASlim
5499 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
5500 .owner = THIS_MODULE,
5501 .open = lpfc_debugfs_dumpHBASlim_open,
5502 .llseek = lpfc_debugfs_lseek,
5503 .read = lpfc_debugfs_read,
5504 .release = lpfc_debugfs_release,
5507 #undef lpfc_debugfs_op_dumpHostSlim
5508 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
5509 .owner = THIS_MODULE,
5510 .open = lpfc_debugfs_dumpHostSlim_open,
5511 .llseek = lpfc_debugfs_lseek,
5512 .read = lpfc_debugfs_read,
5513 .release = lpfc_debugfs_release,
5516 #undef lpfc_debugfs_op_nvmestat
5517 static const struct file_operations lpfc_debugfs_op_nvmestat = {
5518 .owner = THIS_MODULE,
5519 .open = lpfc_debugfs_nvmestat_open,
5520 .llseek = lpfc_debugfs_lseek,
5521 .read = lpfc_debugfs_read,
5522 .write = lpfc_debugfs_nvmestat_write,
5523 .release = lpfc_debugfs_release,
5526 #undef lpfc_debugfs_op_scsistat
5527 static const struct file_operations lpfc_debugfs_op_scsistat = {
5528 .owner = THIS_MODULE,
5529 .open = lpfc_debugfs_scsistat_open,
5530 .llseek = lpfc_debugfs_lseek,
5531 .read = lpfc_debugfs_read,
5532 .write = lpfc_debugfs_scsistat_write,
5533 .release = lpfc_debugfs_release,
5536 #undef lpfc_debugfs_op_ioktime
5537 static const struct file_operations lpfc_debugfs_op_ioktime = {
5538 .owner = THIS_MODULE,
5539 .open = lpfc_debugfs_ioktime_open,
5540 .llseek = lpfc_debugfs_lseek,
5541 .read = lpfc_debugfs_read,
5542 .write = lpfc_debugfs_ioktime_write,
5543 .release = lpfc_debugfs_release,
5546 #undef lpfc_debugfs_op_nvmeio_trc
5547 static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
5548 .owner = THIS_MODULE,
5549 .open = lpfc_debugfs_nvmeio_trc_open,
5550 .llseek = lpfc_debugfs_lseek,
5551 .read = lpfc_debugfs_read,
5552 .write = lpfc_debugfs_nvmeio_trc_write,
5553 .release = lpfc_debugfs_release,
5556 #undef lpfc_debugfs_op_hdwqstat
5557 static const struct file_operations lpfc_debugfs_op_hdwqstat = {
5558 .owner = THIS_MODULE,
5559 .open = lpfc_debugfs_hdwqstat_open,
5560 .llseek = lpfc_debugfs_lseek,
5561 .read = lpfc_debugfs_read,
5562 .write = lpfc_debugfs_hdwqstat_write,
5563 .release = lpfc_debugfs_release,
5566 #undef lpfc_debugfs_op_dif_err
5567 static const struct file_operations lpfc_debugfs_op_dif_err = {
5568 .owner = THIS_MODULE,
5569 .open = simple_open,
5570 .llseek = lpfc_debugfs_lseek,
5571 .read = lpfc_debugfs_dif_err_read,
5572 .write = lpfc_debugfs_dif_err_write,
5573 .release = lpfc_debugfs_dif_err_release,
5576 #undef lpfc_debugfs_op_slow_ring_trc
5577 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
5578 .owner = THIS_MODULE,
5579 .open = lpfc_debugfs_slow_ring_trc_open,
5580 .llseek = lpfc_debugfs_lseek,
5581 .read = lpfc_debugfs_read,
5582 .release = lpfc_debugfs_release,
5585 static struct dentry *lpfc_debugfs_root = NULL;
5586 static atomic_t lpfc_debugfs_hba_count;
5589 * File operations for the iDiag debugfs
5591 #undef lpfc_idiag_op_pciCfg
5592 static const struct file_operations lpfc_idiag_op_pciCfg = {
5593 .owner = THIS_MODULE,
5594 .open = lpfc_idiag_open,
5595 .llseek = lpfc_debugfs_lseek,
5596 .read = lpfc_idiag_pcicfg_read,
5597 .write = lpfc_idiag_pcicfg_write,
5598 .release = lpfc_idiag_cmd_release,
5601 #undef lpfc_idiag_op_barAcc
5602 static const struct file_operations lpfc_idiag_op_barAcc = {
5603 .owner = THIS_MODULE,
5604 .open = lpfc_idiag_open,
5605 .llseek = lpfc_debugfs_lseek,
5606 .read = lpfc_idiag_baracc_read,
5607 .write = lpfc_idiag_baracc_write,
5608 .release = lpfc_idiag_cmd_release,
5611 #undef lpfc_idiag_op_queInfo
5612 static const struct file_operations lpfc_idiag_op_queInfo = {
5613 .owner = THIS_MODULE,
5614 .open = lpfc_idiag_open,
5615 .read = lpfc_idiag_queinfo_read,
5616 .release = lpfc_idiag_release,
5619 #undef lpfc_idiag_op_queAcc
5620 static const struct file_operations lpfc_idiag_op_queAcc = {
5621 .owner = THIS_MODULE,
5622 .open = lpfc_idiag_open,
5623 .llseek = lpfc_debugfs_lseek,
5624 .read = lpfc_idiag_queacc_read,
5625 .write = lpfc_idiag_queacc_write,
5626 .release = lpfc_idiag_cmd_release,
5629 #undef lpfc_idiag_op_drbAcc
5630 static const struct file_operations lpfc_idiag_op_drbAcc = {
5631 .owner = THIS_MODULE,
5632 .open = lpfc_idiag_open,
5633 .llseek = lpfc_debugfs_lseek,
5634 .read = lpfc_idiag_drbacc_read,
5635 .write = lpfc_idiag_drbacc_write,
5636 .release = lpfc_idiag_cmd_release,
5639 #undef lpfc_idiag_op_ctlAcc
5640 static const struct file_operations lpfc_idiag_op_ctlAcc = {
5641 .owner = THIS_MODULE,
5642 .open = lpfc_idiag_open,
5643 .llseek = lpfc_debugfs_lseek,
5644 .read = lpfc_idiag_ctlacc_read,
5645 .write = lpfc_idiag_ctlacc_write,
5646 .release = lpfc_idiag_cmd_release,
5649 #undef lpfc_idiag_op_mbxAcc
5650 static const struct file_operations lpfc_idiag_op_mbxAcc = {
5651 .owner = THIS_MODULE,
5652 .open = lpfc_idiag_open,
5653 .llseek = lpfc_debugfs_lseek,
5654 .read = lpfc_idiag_mbxacc_read,
5655 .write = lpfc_idiag_mbxacc_write,
5656 .release = lpfc_idiag_cmd_release,
5659 #undef lpfc_idiag_op_extAcc
5660 static const struct file_operations lpfc_idiag_op_extAcc = {
5661 .owner = THIS_MODULE,
5662 .open = lpfc_idiag_open,
5663 .llseek = lpfc_debugfs_lseek,
5664 .read = lpfc_idiag_extacc_read,
5665 .write = lpfc_idiag_extacc_write,
5666 .release = lpfc_idiag_cmd_release,
5670 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
5671 * @phba: Pointer to HBA context object.
5672 * @dmabuf: Pointer to a DMA buffer descriptor.
5675 * This routine dump a bsg pass-through non-embedded mailbox command with
5679 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
5680 enum mbox_type mbox_tp, enum dma_type dma_tp,
5681 enum sta_type sta_tp,
5682 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
5684 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5685 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
5686 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5688 uint32_t do_dump = 0;
5692 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
5695 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5696 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5697 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5698 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5700 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
5701 (*mbx_dump_cnt == 0) ||
5702 (*mbx_word_cnt == 0))
5705 if (*mbx_mbox_cmd != 0x9B)
5708 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5709 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5710 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
5711 pr_err("\nRead mbox command (x%x), "
5712 "nemb:0x%x, extbuf_cnt:%d:\n",
5713 sta_tp, nemb_tp, ext_buf);
5716 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5717 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5718 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
5719 pr_err("\nRead mbox buffer (x%x), "
5720 "nemb:0x%x, extbuf_seq:%d:\n",
5721 sta_tp, nemb_tp, ext_buf);
5724 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5725 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5726 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
5727 pr_err("\nWrite mbox command (x%x), "
5728 "nemb:0x%x, extbuf_cnt:%d:\n",
5729 sta_tp, nemb_tp, ext_buf);
5732 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5733 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5734 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
5735 pr_err("\nWrite mbox buffer (x%x), "
5736 "nemb:0x%x, extbuf_seq:%d:\n",
5737 sta_tp, nemb_tp, ext_buf);
5741 /* dump buffer content */
5743 pword = (uint32_t *)dmabuf->virt;
5744 for (i = 0; i < *mbx_word_cnt; i++) {
5747 pr_err("%s\n", line_buf);
5749 len += scnprintf(line_buf+len,
5750 LPFC_MBX_ACC_LBUF_SZ-len,
5753 len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5754 "%08x ", (uint32_t)*pword);
5758 pr_err("%s\n", line_buf);
5762 /* Clean out command structure on reaching dump count */
5763 if (*mbx_dump_cnt == 0)
5764 memset(&idiag, 0, sizeof(idiag));
5769 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5770 * @phba: Pointer to HBA context object.
5771 * @dmabuf: Pointer to a DMA buffer descriptor.
5774 * This routine dump a pass-through non-embedded mailbox command from issue
5778 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5780 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5781 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5782 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5788 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5791 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5792 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5793 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5794 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5796 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5797 (*mbx_dump_cnt == 0) ||
5798 (*mbx_word_cnt == 0))
5801 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5802 (*mbx_mbox_cmd != pmbox->mbxCommand))
5805 /* dump buffer content */
5806 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
5807 pr_err("Mailbox command:0x%x dump by word:\n",
5809 pword = (uint32_t *)pmbox;
5810 for (i = 0; i < *mbx_word_cnt; i++) {
5813 pr_err("%s\n", line_buf);
5815 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5816 len += scnprintf(line_buf+len,
5817 LPFC_MBX_ACC_LBUF_SZ-len,
5820 len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5822 ((uint32_t)*pword) & 0xffffffff);
5826 pr_err("%s\n", line_buf);
5829 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
5830 pr_err("Mailbox command:0x%x dump by byte:\n",
5832 pbyte = (uint8_t *)pmbox;
5833 for (i = 0; i < *mbx_word_cnt; i++) {
5836 pr_err("%s\n", line_buf);
5838 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5839 len += scnprintf(line_buf+len,
5840 LPFC_MBX_ACC_LBUF_SZ-len,
5843 for (j = 0; j < 4; j++) {
5844 len += scnprintf(line_buf+len,
5845 LPFC_MBX_ACC_LBUF_SZ-len,
5847 ((uint8_t)*pbyte) & 0xff);
5850 len += scnprintf(line_buf+len,
5851 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5854 pr_err("%s\n", line_buf);
5859 /* Clean out command structure on reaching dump count */
5860 if (*mbx_dump_cnt == 0)
5861 memset(&idiag, 0, sizeof(idiag));
5867 * lpfc_debugfs_initialize - Initialize debugfs for a vport
5868 * @vport: The vport pointer to initialize.
5871 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5872 * If not already created, this routine will create the lpfc directory, and
5873 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5874 * also create each file used to access lpfc specific debugfs information.
5877 lpfc_debugfs_initialize(struct lpfc_vport *vport)
5879 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5880 struct lpfc_hba *phba = vport->phba;
5883 bool pport_setup = false;
5885 if (!lpfc_debugfs_enable)
5888 /* Setup lpfc root directory */
5889 if (!lpfc_debugfs_root) {
5890 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5891 atomic_set(&lpfc_debugfs_hba_count, 0);
5893 if (!lpfc_debugfs_start_time)
5894 lpfc_debugfs_start_time = jiffies;
5896 /* Setup funcX directory for specific HBA PCI function */
5897 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
5898 if (!phba->hba_debugfs_root) {
5900 phba->hba_debugfs_root =
5901 debugfs_create_dir(name, lpfc_debugfs_root);
5902 atomic_inc(&lpfc_debugfs_hba_count);
5903 atomic_set(&phba->debugfs_vport_count, 0);
5905 /* Multi-XRI pools */
5906 snprintf(name, sizeof(name), "multixripools");
5907 phba->debug_multixri_pools =
5908 debugfs_create_file(name, S_IFREG | 0644,
5909 phba->hba_debugfs_root,
5911 &lpfc_debugfs_op_multixripools);
5912 if (!phba->debug_multixri_pools) {
5913 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5914 "0527 Cannot create debugfs multixripools\n");
5919 snprintf(name, sizeof(name), "ras_log");
5920 phba->debug_ras_log =
5921 debugfs_create_file(name, 0644,
5922 phba->hba_debugfs_root,
5923 phba, &lpfc_debugfs_ras_log);
5924 if (!phba->debug_ras_log) {
5925 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5926 "6148 Cannot create debugfs"
5932 snprintf(name, sizeof(name), "hbqinfo");
5933 phba->debug_hbqinfo =
5934 debugfs_create_file(name, S_IFREG | 0644,
5935 phba->hba_debugfs_root,
5936 phba, &lpfc_debugfs_op_hbqinfo);
5938 #ifdef LPFC_HDWQ_LOCK_STAT
5939 /* Setup lockstat */
5940 snprintf(name, sizeof(name), "lockstat");
5941 phba->debug_lockstat =
5942 debugfs_create_file(name, S_IFREG | 0644,
5943 phba->hba_debugfs_root,
5944 phba, &lpfc_debugfs_op_lockstat);
5945 if (!phba->debug_lockstat) {
5946 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5947 "4610 Cant create debugfs lockstat\n");
5952 /* Setup dumpHBASlim */
5953 if (phba->sli_rev < LPFC_SLI_REV4) {
5954 snprintf(name, sizeof(name), "dumpHBASlim");
5955 phba->debug_dumpHBASlim =
5956 debugfs_create_file(name,
5957 S_IFREG|S_IRUGO|S_IWUSR,
5958 phba->hba_debugfs_root,
5959 phba, &lpfc_debugfs_op_dumpHBASlim);
5961 phba->debug_dumpHBASlim = NULL;
5963 /* Setup dumpHostSlim */
5964 if (phba->sli_rev < LPFC_SLI_REV4) {
5965 snprintf(name, sizeof(name), "dumpHostSlim");
5966 phba->debug_dumpHostSlim =
5967 debugfs_create_file(name,
5968 S_IFREG|S_IRUGO|S_IWUSR,
5969 phba->hba_debugfs_root,
5970 phba, &lpfc_debugfs_op_dumpHostSlim);
5972 phba->debug_dumpHostSlim = NULL;
5974 /* Setup DIF Error Injections */
5975 snprintf(name, sizeof(name), "InjErrLBA");
5976 phba->debug_InjErrLBA =
5977 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5978 phba->hba_debugfs_root,
5979 phba, &lpfc_debugfs_op_dif_err);
5980 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5982 snprintf(name, sizeof(name), "InjErrNPortID");
5983 phba->debug_InjErrNPortID =
5984 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5985 phba->hba_debugfs_root,
5986 phba, &lpfc_debugfs_op_dif_err);
5988 snprintf(name, sizeof(name), "InjErrWWPN");
5989 phba->debug_InjErrWWPN =
5990 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5991 phba->hba_debugfs_root,
5992 phba, &lpfc_debugfs_op_dif_err);
5994 snprintf(name, sizeof(name), "writeGuardInjErr");
5995 phba->debug_writeGuard =
5996 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5997 phba->hba_debugfs_root,
5998 phba, &lpfc_debugfs_op_dif_err);
6000 snprintf(name, sizeof(name), "writeAppInjErr");
6001 phba->debug_writeApp =
6002 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6003 phba->hba_debugfs_root,
6004 phba, &lpfc_debugfs_op_dif_err);
6006 snprintf(name, sizeof(name), "writeRefInjErr");
6007 phba->debug_writeRef =
6008 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6009 phba->hba_debugfs_root,
6010 phba, &lpfc_debugfs_op_dif_err);
6012 snprintf(name, sizeof(name), "readGuardInjErr");
6013 phba->debug_readGuard =
6014 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6015 phba->hba_debugfs_root,
6016 phba, &lpfc_debugfs_op_dif_err);
6018 snprintf(name, sizeof(name), "readAppInjErr");
6019 phba->debug_readApp =
6020 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6021 phba->hba_debugfs_root,
6022 phba, &lpfc_debugfs_op_dif_err);
6024 snprintf(name, sizeof(name), "readRefInjErr");
6025 phba->debug_readRef =
6026 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6027 phba->hba_debugfs_root,
6028 phba, &lpfc_debugfs_op_dif_err);
6030 /* Setup slow ring trace */
6031 if (lpfc_debugfs_max_slow_ring_trc) {
6032 num = lpfc_debugfs_max_slow_ring_trc - 1;
6033 if (num & lpfc_debugfs_max_slow_ring_trc) {
6034 /* Change to be a power of 2 */
6035 num = lpfc_debugfs_max_slow_ring_trc;
6041 lpfc_debugfs_max_slow_ring_trc = (1 << i);
6042 pr_err("lpfc_debugfs_max_disc_trc changed to "
6043 "%d\n", lpfc_debugfs_max_disc_trc);
6047 snprintf(name, sizeof(name), "slow_ring_trace");
6048 phba->debug_slow_ring_trc =
6049 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6050 phba->hba_debugfs_root,
6051 phba, &lpfc_debugfs_op_slow_ring_trc);
6052 if (!phba->slow_ring_trc) {
6053 phba->slow_ring_trc = kmalloc(
6054 (sizeof(struct lpfc_debugfs_trc) *
6055 lpfc_debugfs_max_slow_ring_trc),
6057 if (!phba->slow_ring_trc) {
6058 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6059 "0416 Cannot create debugfs "
6060 "slow_ring buffer\n");
6063 atomic_set(&phba->slow_ring_trc_cnt, 0);
6064 memset(phba->slow_ring_trc, 0,
6065 (sizeof(struct lpfc_debugfs_trc) *
6066 lpfc_debugfs_max_slow_ring_trc));
6069 snprintf(name, sizeof(name), "nvmeio_trc");
6070 phba->debug_nvmeio_trc =
6071 debugfs_create_file(name, 0644,
6072 phba->hba_debugfs_root,
6073 phba, &lpfc_debugfs_op_nvmeio_trc);
6075 atomic_set(&phba->nvmeio_trc_cnt, 0);
6076 if (lpfc_debugfs_max_nvmeio_trc) {
6077 num = lpfc_debugfs_max_nvmeio_trc - 1;
6078 if (num & lpfc_debugfs_max_disc_trc) {
6079 /* Change to be a power of 2 */
6080 num = lpfc_debugfs_max_nvmeio_trc;
6086 lpfc_debugfs_max_nvmeio_trc = (1 << i);
6087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6088 "0575 lpfc_debugfs_max_nvmeio_trc "
6090 lpfc_debugfs_max_nvmeio_trc);
6092 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
6094 /* Allocate trace buffer and initialize */
6095 phba->nvmeio_trc = kzalloc(
6096 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
6097 phba->nvmeio_trc_size), GFP_KERNEL);
6099 if (!phba->nvmeio_trc) {
6100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6101 "0576 Cannot create debugfs "
6102 "nvmeio_trc buffer\n");
6105 phba->nvmeio_trc_on = 1;
6106 phba->nvmeio_trc_output_idx = 0;
6107 phba->nvmeio_trc = NULL;
6110 phba->nvmeio_trc_size = 0;
6111 phba->nvmeio_trc_on = 0;
6112 phba->nvmeio_trc_output_idx = 0;
6113 phba->nvmeio_trc = NULL;
6117 snprintf(name, sizeof(name), "vport%d", vport->vpi);
6118 if (!vport->vport_debugfs_root) {
6119 vport->vport_debugfs_root =
6120 debugfs_create_dir(name, phba->hba_debugfs_root);
6121 atomic_inc(&phba->debugfs_vport_count);
6124 if (lpfc_debugfs_max_disc_trc) {
6125 num = lpfc_debugfs_max_disc_trc - 1;
6126 if (num & lpfc_debugfs_max_disc_trc) {
6127 /* Change to be a power of 2 */
6128 num = lpfc_debugfs_max_disc_trc;
6134 lpfc_debugfs_max_disc_trc = (1 << i);
6135 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
6136 lpfc_debugfs_max_disc_trc);
6140 vport->disc_trc = kzalloc(
6141 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
6144 if (!vport->disc_trc) {
6145 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6146 "0418 Cannot create debugfs disc trace "
6150 atomic_set(&vport->disc_trc_cnt, 0);
6152 snprintf(name, sizeof(name), "discovery_trace");
6153 vport->debug_disc_trc =
6154 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6155 vport->vport_debugfs_root,
6156 vport, &lpfc_debugfs_op_disc_trc);
6157 snprintf(name, sizeof(name), "nodelist");
6158 vport->debug_nodelist =
6159 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6160 vport->vport_debugfs_root,
6161 vport, &lpfc_debugfs_op_nodelist);
6163 snprintf(name, sizeof(name), "nvmestat");
6164 vport->debug_nvmestat =
6165 debugfs_create_file(name, 0644,
6166 vport->vport_debugfs_root,
6167 vport, &lpfc_debugfs_op_nvmestat);
6169 snprintf(name, sizeof(name), "scsistat");
6170 vport->debug_scsistat =
6171 debugfs_create_file(name, 0644,
6172 vport->vport_debugfs_root,
6173 vport, &lpfc_debugfs_op_scsistat);
6174 if (!vport->debug_scsistat) {
6175 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6176 "4611 Cannot create debugfs scsistat\n");
6180 snprintf(name, sizeof(name), "ioktime");
6181 vport->debug_ioktime =
6182 debugfs_create_file(name, 0644,
6183 vport->vport_debugfs_root,
6184 vport, &lpfc_debugfs_op_ioktime);
6185 if (!vport->debug_ioktime) {
6186 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6187 "0815 Cannot create debugfs ioktime\n");
6191 snprintf(name, sizeof(name), "hdwqstat");
6192 vport->debug_hdwqstat =
6193 debugfs_create_file(name, 0644,
6194 vport->vport_debugfs_root,
6195 vport, &lpfc_debugfs_op_hdwqstat);
6198 * The following section is for additional directories/files for the
6206 * iDiag debugfs root entry points for SLI4 device only
6208 if (phba->sli_rev < LPFC_SLI_REV4)
6211 snprintf(name, sizeof(name), "iDiag");
6212 if (!phba->idiag_root) {
6214 debugfs_create_dir(name, phba->hba_debugfs_root);
6215 /* Initialize iDiag data structure */
6216 memset(&idiag, 0, sizeof(idiag));
6219 /* iDiag read PCI config space */
6220 snprintf(name, sizeof(name), "pciCfg");
6221 if (!phba->idiag_pci_cfg) {
6222 phba->idiag_pci_cfg =
6223 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6224 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
6225 idiag.offset.last_rd = 0;
6228 /* iDiag PCI BAR access */
6229 snprintf(name, sizeof(name), "barAcc");
6230 if (!phba->idiag_bar_acc) {
6231 phba->idiag_bar_acc =
6232 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6233 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
6234 idiag.offset.last_rd = 0;
6237 /* iDiag get PCI function queue information */
6238 snprintf(name, sizeof(name), "queInfo");
6239 if (!phba->idiag_que_info) {
6240 phba->idiag_que_info =
6241 debugfs_create_file(name, S_IFREG|S_IRUGO,
6242 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
6245 /* iDiag access PCI function queue */
6246 snprintf(name, sizeof(name), "queAcc");
6247 if (!phba->idiag_que_acc) {
6248 phba->idiag_que_acc =
6249 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6250 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
6253 /* iDiag access PCI function doorbell registers */
6254 snprintf(name, sizeof(name), "drbAcc");
6255 if (!phba->idiag_drb_acc) {
6256 phba->idiag_drb_acc =
6257 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6258 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
6261 /* iDiag access PCI function control registers */
6262 snprintf(name, sizeof(name), "ctlAcc");
6263 if (!phba->idiag_ctl_acc) {
6264 phba->idiag_ctl_acc =
6265 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6266 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
6269 /* iDiag access mbox commands */
6270 snprintf(name, sizeof(name), "mbxAcc");
6271 if (!phba->idiag_mbx_acc) {
6272 phba->idiag_mbx_acc =
6273 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6274 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
6277 /* iDiag extents access commands */
6278 if (phba->sli4_hba.extents_in_use) {
6279 snprintf(name, sizeof(name), "extAcc");
6280 if (!phba->idiag_ext_acc) {
6281 phba->idiag_ext_acc =
6282 debugfs_create_file(name,
6283 S_IFREG|S_IRUGO|S_IWUSR,
6284 phba->idiag_root, phba,
6285 &lpfc_idiag_op_extAcc);
6295 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
6296 * @vport: The vport pointer to remove from debugfs.
6299 * When Debugfs is configured this routine removes debugfs file system elements
6300 * that are specific to this vport. It also checks to see if there are any
6301 * users left for the debugfs directories associated with the HBA and driver. If
6302 * this is the last user of the HBA directory or driver directory then it will
6303 * remove those from the debugfs infrastructure as well.
6306 lpfc_debugfs_terminate(struct lpfc_vport *vport)
6308 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
6309 struct lpfc_hba *phba = vport->phba;
6311 kfree(vport->disc_trc);
6312 vport->disc_trc = NULL;
6314 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
6315 vport->debug_disc_trc = NULL;
6317 debugfs_remove(vport->debug_nodelist); /* nodelist */
6318 vport->debug_nodelist = NULL;
6320 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
6321 vport->debug_nvmestat = NULL;
6323 debugfs_remove(vport->debug_scsistat); /* scsistat */
6324 vport->debug_scsistat = NULL;
6326 debugfs_remove(vport->debug_ioktime); /* ioktime */
6327 vport->debug_ioktime = NULL;
6329 debugfs_remove(vport->debug_hdwqstat); /* hdwqstat */
6330 vport->debug_hdwqstat = NULL;
6332 if (vport->vport_debugfs_root) {
6333 debugfs_remove(vport->vport_debugfs_root); /* vportX */
6334 vport->vport_debugfs_root = NULL;
6335 atomic_dec(&phba->debugfs_vport_count);
6338 if (atomic_read(&phba->debugfs_vport_count) == 0) {
6340 debugfs_remove(phba->debug_multixri_pools); /* multixripools*/
6341 phba->debug_multixri_pools = NULL;
6343 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
6344 phba->debug_hbqinfo = NULL;
6346 debugfs_remove(phba->debug_ras_log);
6347 phba->debug_ras_log = NULL;
6349 #ifdef LPFC_HDWQ_LOCK_STAT
6350 debugfs_remove(phba->debug_lockstat); /* lockstat */
6351 phba->debug_lockstat = NULL;
6353 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
6354 phba->debug_dumpHBASlim = NULL;
6356 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
6357 phba->debug_dumpHostSlim = NULL;
6359 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
6360 phba->debug_InjErrLBA = NULL;
6362 debugfs_remove(phba->debug_InjErrNPortID);
6363 phba->debug_InjErrNPortID = NULL;
6365 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
6366 phba->debug_InjErrWWPN = NULL;
6368 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
6369 phba->debug_writeGuard = NULL;
6371 debugfs_remove(phba->debug_writeApp); /* writeApp */
6372 phba->debug_writeApp = NULL;
6374 debugfs_remove(phba->debug_writeRef); /* writeRef */
6375 phba->debug_writeRef = NULL;
6377 debugfs_remove(phba->debug_readGuard); /* readGuard */
6378 phba->debug_readGuard = NULL;
6380 debugfs_remove(phba->debug_readApp); /* readApp */
6381 phba->debug_readApp = NULL;
6383 debugfs_remove(phba->debug_readRef); /* readRef */
6384 phba->debug_readRef = NULL;
6386 kfree(phba->slow_ring_trc);
6387 phba->slow_ring_trc = NULL;
6389 /* slow_ring_trace */
6390 debugfs_remove(phba->debug_slow_ring_trc);
6391 phba->debug_slow_ring_trc = NULL;
6393 debugfs_remove(phba->debug_nvmeio_trc);
6394 phba->debug_nvmeio_trc = NULL;
6396 kfree(phba->nvmeio_trc);
6397 phba->nvmeio_trc = NULL;
6402 if (phba->sli_rev == LPFC_SLI_REV4) {
6404 debugfs_remove(phba->idiag_ext_acc);
6405 phba->idiag_ext_acc = NULL;
6408 debugfs_remove(phba->idiag_mbx_acc);
6409 phba->idiag_mbx_acc = NULL;
6412 debugfs_remove(phba->idiag_ctl_acc);
6413 phba->idiag_ctl_acc = NULL;
6416 debugfs_remove(phba->idiag_drb_acc);
6417 phba->idiag_drb_acc = NULL;
6420 debugfs_remove(phba->idiag_que_acc);
6421 phba->idiag_que_acc = NULL;
6424 debugfs_remove(phba->idiag_que_info);
6425 phba->idiag_que_info = NULL;
6428 debugfs_remove(phba->idiag_bar_acc);
6429 phba->idiag_bar_acc = NULL;
6432 debugfs_remove(phba->idiag_pci_cfg);
6433 phba->idiag_pci_cfg = NULL;
6435 /* Finally remove the iDiag debugfs root */
6436 debugfs_remove(phba->idiag_root);
6437 phba->idiag_root = NULL;
6440 if (phba->hba_debugfs_root) {
6441 debugfs_remove(phba->hba_debugfs_root); /* fnX */
6442 phba->hba_debugfs_root = NULL;
6443 atomic_dec(&lpfc_debugfs_hba_count);
6446 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
6447 debugfs_remove(lpfc_debugfs_root); /* lpfc */
6448 lpfc_debugfs_root = NULL;
6456 * Driver debug utility routines outside of debugfs. The debug utility
6457 * routines implemented here is intended to be used in the instrumented
6458 * debug driver for debugging host or port issues.
6462 * lpfc_debug_dump_all_queues - dump all the queues with a hba
6463 * @phba: Pointer to HBA context object.
6465 * This function dumps entries of all the queues asociated with the @phba.
6468 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
6473 * Dump Work Queues (WQs)
6475 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
6476 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
6477 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
6479 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
6480 lpfc_debug_dump_wq(phba, DUMP_IO, idx);
6482 lpfc_debug_dump_hdr_rq(phba);
6483 lpfc_debug_dump_dat_rq(phba);
6485 * Dump Complete Queues (CQs)
6487 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
6488 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
6489 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
6491 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
6492 lpfc_debug_dump_cq(phba, DUMP_IO, idx);
6495 * Dump Event Queues (EQs)
6497 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
6498 lpfc_debug_dump_hba_eq(phba, idx);