1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2023 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_commonxripools_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 len += scnprintf(buf+len, size-len, "RPI:x%04x ",
873 len += scnprintf(buf+len, size-len, "flag:x%08x ",
876 len += scnprintf(buf+len, size-len, "UNKNOWN_TYPE ");
877 if (ndlp->nlp_type & NLP_FC_NODE)
878 len += scnprintf(buf+len, size-len, "FC_NODE ");
879 if (ndlp->nlp_type & NLP_FABRIC) {
880 len += scnprintf(buf+len, size-len, "FABRIC ");
883 if (ndlp->nlp_type & NLP_FCP_TARGET)
884 len += scnprintf(buf+len, size-len, "FCP_TGT sid:%d ",
886 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
887 len += scnprintf(buf+len, size-len, "FCP_INITIATOR ");
888 if (ndlp->nlp_type & NLP_NVME_TARGET)
889 len += scnprintf(buf + len,
890 size - len, "NVME_TGT sid:%d ",
892 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
893 len += scnprintf(buf + len,
894 size - len, "NVME_INITIATOR ");
895 len += scnprintf(buf+len, size-len, "refcnt:%d",
896 kref_read(&ndlp->kref));
898 i = atomic_read(&ndlp->cmd_pending);
899 len += scnprintf(buf + len, size - len,
900 " OutIO:x%x Qdepth x%x",
901 i, ndlp->cmd_qdepth);
904 len += scnprintf(buf+len, size-len, " xpt:x%x",
905 ndlp->fc4_xpt_flags);
906 if (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)
907 len += scnprintf(buf+len, size-len, " defer:%x",
908 ndlp->nlp_defer_did);
909 len += scnprintf(buf+len, size-len, "\n");
911 spin_unlock_irq(shost->host_lock);
913 len += scnprintf(buf + len, size - len,
914 "\nOutstanding IO x%x\n", outio);
916 if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
917 len += scnprintf(buf + len, size - len,
918 "\nNVME Targetport Entry ...\n");
920 /* Port state is only one of two values for now. */
921 if (phba->targetport->port_id)
922 statep = "REGISTERED";
925 len += scnprintf(buf + len, size - len,
926 "TGT WWNN x%llx WWPN x%llx State %s\n",
927 wwn_to_u64(vport->fc_nodename.u.wwn),
928 wwn_to_u64(vport->fc_portname.u.wwn),
930 len += scnprintf(buf + len, size - len,
931 " Targetport DID x%06x\n",
932 phba->targetport->port_id);
936 len += scnprintf(buf + len, size - len,
937 "\nNVME Lport/Rport Entries ...\n");
939 localport = vport->localport;
943 spin_lock_irq(shost->host_lock);
945 /* Port state is only one of two values for now. */
946 if (localport->port_id)
951 len += scnprintf(buf + len, size - len,
952 "Lport DID x%06x PortState %s\n",
953 localport->port_id, statep);
955 len += scnprintf(buf + len, size - len, "\tRport List:\n");
956 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
957 /* local short-hand pointer. */
958 spin_lock(&ndlp->lock);
959 rport = lpfc_ndlp_get_nrport(ndlp);
961 nrport = rport->remoteport;
964 spin_unlock(&ndlp->lock);
968 /* Port state is only one of two values for now. */
969 switch (nrport->port_state) {
970 case FC_OBJSTATE_ONLINE:
973 case FC_OBJSTATE_UNKNOWN:
977 statep = "UNSUPPORTED";
981 /* Tab in to show lport ownership. */
982 len += scnprintf(buf + len, size - len,
983 "\t%s Port ID:x%06x ",
984 statep, nrport->port_id);
985 len += scnprintf(buf + len, size - len, "WWPN x%llx ",
987 len += scnprintf(buf + len, size - len, "WWNN x%llx ",
990 /* An NVME rport can have multiple roles. */
991 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
992 len += scnprintf(buf + len, size - len,
994 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
995 len += scnprintf(buf + len, size - len,
997 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
998 len += scnprintf(buf + len, size - len,
1000 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
1001 FC_PORT_ROLE_NVME_TARGET |
1002 FC_PORT_ROLE_NVME_DISCOVERY))
1003 len += scnprintf(buf + len, size - len,
1006 /* Terminate the string. */
1007 len += scnprintf(buf + len, size - len, "\n");
1010 spin_unlock_irq(shost->host_lock);
1016 * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
1017 * @vport: The vport to gather target node info from.
1018 * @buf: The buffer to dump log into.
1019 * @size: The maximum amount of data to process.
1022 * This routine dumps the NVME statistics associated with @vport
1025 * This routine returns the amount of bytes that were dumped into @buf and will
1029 lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
1031 struct lpfc_hba *phba = vport->phba;
1032 struct lpfc_nvmet_tgtport *tgtp;
1033 struct lpfc_async_xchg_ctx *ctxp, *next_ctxp;
1034 struct nvme_fc_local_port *localport;
1035 struct lpfc_fc4_ctrl_stat *cstat;
1036 struct lpfc_nvme_lport *lport;
1037 uint64_t data1, data2, data3;
1038 uint64_t tot, totin, totout;
1042 if (phba->nvmet_support) {
1043 if (!phba->targetport)
1045 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1046 len += scnprintf(buf + len, size - len,
1047 "\nNVME Targetport Statistics\n");
1049 len += scnprintf(buf + len, size - len,
1050 "LS: Rcv %08x Drop %08x Abort %08x\n",
1051 atomic_read(&tgtp->rcv_ls_req_in),
1052 atomic_read(&tgtp->rcv_ls_req_drop),
1053 atomic_read(&tgtp->xmt_ls_abort));
1054 if (atomic_read(&tgtp->rcv_ls_req_in) !=
1055 atomic_read(&tgtp->rcv_ls_req_out)) {
1056 len += scnprintf(buf + len, size - len,
1057 "Rcv LS: in %08x != out %08x\n",
1058 atomic_read(&tgtp->rcv_ls_req_in),
1059 atomic_read(&tgtp->rcv_ls_req_out));
1062 len += scnprintf(buf + len, size - len,
1063 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
1064 atomic_read(&tgtp->xmt_ls_rsp),
1065 atomic_read(&tgtp->xmt_ls_drop),
1066 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
1068 len += scnprintf(buf + len, size - len,
1069 "LS: RSP Abort %08x xb %08x Err %08x\n",
1070 atomic_read(&tgtp->xmt_ls_rsp_aborted),
1071 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
1072 atomic_read(&tgtp->xmt_ls_rsp_error));
1074 len += scnprintf(buf + len, size - len,
1075 "FCP: Rcv %08x Defer %08x Release %08x "
1077 atomic_read(&tgtp->rcv_fcp_cmd_in),
1078 atomic_read(&tgtp->rcv_fcp_cmd_defer),
1079 atomic_read(&tgtp->xmt_fcp_release),
1080 atomic_read(&tgtp->rcv_fcp_cmd_drop));
1082 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
1083 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
1084 len += scnprintf(buf + len, size - len,
1085 "Rcv FCP: in %08x != out %08x\n",
1086 atomic_read(&tgtp->rcv_fcp_cmd_in),
1087 atomic_read(&tgtp->rcv_fcp_cmd_out));
1090 len += scnprintf(buf + len, size - len,
1091 "FCP Rsp: read %08x readrsp %08x "
1092 "write %08x rsp %08x\n",
1093 atomic_read(&tgtp->xmt_fcp_read),
1094 atomic_read(&tgtp->xmt_fcp_read_rsp),
1095 atomic_read(&tgtp->xmt_fcp_write),
1096 atomic_read(&tgtp->xmt_fcp_rsp));
1098 len += scnprintf(buf + len, size - len,
1099 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
1100 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
1101 atomic_read(&tgtp->xmt_fcp_rsp_error),
1102 atomic_read(&tgtp->xmt_fcp_rsp_drop));
1104 len += scnprintf(buf + len, size - len,
1105 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
1106 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
1107 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
1108 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
1110 len += scnprintf(buf + len, size - len,
1111 "ABORT: Xmt %08x Cmpl %08x\n",
1112 atomic_read(&tgtp->xmt_fcp_abort),
1113 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
1115 len += scnprintf(buf + len, size - len,
1116 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
1117 atomic_read(&tgtp->xmt_abort_sol),
1118 atomic_read(&tgtp->xmt_abort_unsol),
1119 atomic_read(&tgtp->xmt_abort_rsp),
1120 atomic_read(&tgtp->xmt_abort_rsp_error));
1122 len += scnprintf(buf + len, size - len, "\n");
1125 spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1126 list_for_each_entry_safe(ctxp, next_ctxp,
1127 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1131 spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1133 len += scnprintf(buf + len, size - len,
1134 "ABORT: %d ctx entries\n", cnt);
1135 spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1136 list_for_each_entry_safe(ctxp, next_ctxp,
1137 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1139 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
1141 len += scnprintf(buf + len, size - len,
1142 "Entry: oxid %x state %x "
1144 ctxp->oxid, ctxp->state,
1147 spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1150 /* Calculate outstanding IOs */
1151 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1152 tot += atomic_read(&tgtp->xmt_fcp_release);
1153 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
1155 len += scnprintf(buf + len, size - len,
1156 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
1157 "CTX Outstanding %08llx\n",
1158 phba->sli4_hba.nvmet_xri_cnt,
1159 phba->sli4_hba.nvmet_io_wait_cnt,
1160 phba->sli4_hba.nvmet_io_wait_total,
1163 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
1166 localport = vport->localport;
1169 lport = (struct lpfc_nvme_lport *)localport->private;
1173 len += scnprintf(buf + len, size - len,
1174 "\nNVME HDWQ Statistics\n");
1176 len += scnprintf(buf + len, size - len,
1177 "LS: Xmt %016x Cmpl %016x\n",
1178 atomic_read(&lport->fc4NvmeLsRequests),
1179 atomic_read(&lport->fc4NvmeLsCmpls));
1183 for (i = 0; i < phba->cfg_hdw_queue; i++) {
1184 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
1185 tot = cstat->io_cmpls;
1187 data1 = cstat->input_requests;
1188 data2 = cstat->output_requests;
1189 data3 = cstat->control_requests;
1190 totout += (data1 + data2 + data3);
1192 /* Limit to 32, debugfs display buffer limitation */
1196 len += scnprintf(buf + len, PAGE_SIZE - len,
1197 "HDWQ (%d): Rd %016llx Wr %016llx "
1199 i, data1, data2, data3);
1200 len += scnprintf(buf + len, PAGE_SIZE - len,
1201 "Cmpl %016llx OutIO %016llx\n",
1202 tot, ((data1 + data2 + data3) - tot));
1204 len += scnprintf(buf + len, PAGE_SIZE - len,
1205 "Total FCP Cmpl %016llx Issue %016llx "
1207 totin, totout, totout - totin);
1209 len += scnprintf(buf + len, size - len,
1210 "LS Xmt Err: Abrt %08x Err %08x "
1211 "Cmpl Err: xb %08x Err %08x\n",
1212 atomic_read(&lport->xmt_ls_abort),
1213 atomic_read(&lport->xmt_ls_err),
1214 atomic_read(&lport->cmpl_ls_xb),
1215 atomic_read(&lport->cmpl_ls_err));
1217 len += scnprintf(buf + len, size - len,
1218 "FCP Xmt Err: noxri %06x nondlp %06x "
1219 "qdepth %06x wqerr %06x err %06x Abrt %06x\n",
1220 atomic_read(&lport->xmt_fcp_noxri),
1221 atomic_read(&lport->xmt_fcp_bad_ndlp),
1222 atomic_read(&lport->xmt_fcp_qdepth),
1223 atomic_read(&lport->xmt_fcp_wqerr),
1224 atomic_read(&lport->xmt_fcp_err),
1225 atomic_read(&lport->xmt_fcp_abort));
1227 len += scnprintf(buf + len, size - len,
1228 "FCP Cmpl Err: xb %08x Err %08x\n",
1229 atomic_read(&lport->cmpl_fcp_xb),
1230 atomic_read(&lport->cmpl_fcp_err));
1238 * lpfc_debugfs_scsistat_data - Dump target node list to a buffer
1239 * @vport: The vport to gather target node info from.
1240 * @buf: The buffer to dump log into.
1241 * @size: The maximum amount of data to process.
1244 * This routine dumps the SCSI statistics associated with @vport
1247 * This routine returns the amount of bytes that were dumped into @buf and will
1251 lpfc_debugfs_scsistat_data(struct lpfc_vport *vport, char *buf, int size)
1254 struct lpfc_hba *phba = vport->phba;
1255 struct lpfc_fc4_ctrl_stat *cstat;
1256 u64 data1, data2, data3;
1257 u64 tot, totin, totout;
1259 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
1261 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
1262 (phba->sli_rev != LPFC_SLI_REV4))
1265 scnprintf(buf, size, "SCSI HDWQ Statistics\n");
1269 for (i = 0; i < phba->cfg_hdw_queue; i++) {
1270 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
1271 tot = cstat->io_cmpls;
1273 data1 = cstat->input_requests;
1274 data2 = cstat->output_requests;
1275 data3 = cstat->control_requests;
1276 totout += (data1 + data2 + data3);
1278 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
1279 "IO %016llx ", i, data1, data2, data3);
1280 if (strlcat(buf, tmp, size) >= size)
1283 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
1284 tot, ((data1 + data2 + data3) - tot));
1285 if (strlcat(buf, tmp, size) >= size)
1288 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
1289 "OutIO %016llx\n", totin, totout, totout - totin);
1290 strlcat(buf, tmp, size);
1293 len = strnlen(buf, size);
1299 lpfc_io_ktime(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
1301 uint64_t seg1, seg2, seg3, seg4;
1304 if (!lpfc_cmd->ts_last_cmd ||
1305 !lpfc_cmd->ts_cmd_start ||
1306 !lpfc_cmd->ts_cmd_wqput ||
1307 !lpfc_cmd->ts_isr_cmpl ||
1308 !lpfc_cmd->ts_data_io)
1311 if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_cmd_start)
1313 if (lpfc_cmd->ts_cmd_start < lpfc_cmd->ts_last_cmd)
1315 if (lpfc_cmd->ts_cmd_wqput < lpfc_cmd->ts_cmd_start)
1317 if (lpfc_cmd->ts_isr_cmpl < lpfc_cmd->ts_cmd_wqput)
1319 if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_isr_cmpl)
1322 * Segment 1 - Time from Last FCP command cmpl is handed
1323 * off to NVME Layer to start of next command.
1324 * Segment 2 - Time from Driver receives a IO cmd start
1325 * from NVME Layer to WQ put is done on IO cmd.
1326 * Segment 3 - Time from Driver WQ put is done on IO cmd
1327 * to MSI-X ISR for IO cmpl.
1328 * Segment 4 - Time from MSI-X ISR for IO cmpl to when
1329 * cmpl is handled off to the NVME Layer.
1331 seg1 = lpfc_cmd->ts_cmd_start - lpfc_cmd->ts_last_cmd;
1332 if (seg1 > 5000000) /* 5 ms - for sequential IOs only */
1335 /* Calculate times relative to start of IO */
1336 seg2 = (lpfc_cmd->ts_cmd_wqput - lpfc_cmd->ts_cmd_start);
1338 seg3 = lpfc_cmd->ts_isr_cmpl - lpfc_cmd->ts_cmd_start;
1344 seg4 = lpfc_cmd->ts_data_io - lpfc_cmd->ts_cmd_start;
1349 phba->ktime_data_samples++;
1350 phba->ktime_seg1_total += seg1;
1351 if (seg1 < phba->ktime_seg1_min)
1352 phba->ktime_seg1_min = seg1;
1353 else if (seg1 > phba->ktime_seg1_max)
1354 phba->ktime_seg1_max = seg1;
1355 phba->ktime_seg2_total += seg2;
1356 if (seg2 < phba->ktime_seg2_min)
1357 phba->ktime_seg2_min = seg2;
1358 else if (seg2 > phba->ktime_seg2_max)
1359 phba->ktime_seg2_max = seg2;
1360 phba->ktime_seg3_total += seg3;
1361 if (seg3 < phba->ktime_seg3_min)
1362 phba->ktime_seg3_min = seg3;
1363 else if (seg3 > phba->ktime_seg3_max)
1364 phba->ktime_seg3_max = seg3;
1365 phba->ktime_seg4_total += seg4;
1366 if (seg4 < phba->ktime_seg4_min)
1367 phba->ktime_seg4_min = seg4;
1368 else if (seg4 > phba->ktime_seg4_max)
1369 phba->ktime_seg4_max = seg4;
1371 lpfc_cmd->ts_last_cmd = 0;
1372 lpfc_cmd->ts_cmd_start = 0;
1373 lpfc_cmd->ts_cmd_wqput = 0;
1374 lpfc_cmd->ts_isr_cmpl = 0;
1375 lpfc_cmd->ts_data_io = 0;
1379 * lpfc_debugfs_ioktime_data - Dump target node list to a buffer
1380 * @vport: The vport to gather target node info from.
1381 * @buf: The buffer to dump log into.
1382 * @size: The maximum amount of data to process.
1385 * This routine dumps the NVME statistics associated with @vport
1388 * This routine returns the amount of bytes that were dumped into @buf and will
1392 lpfc_debugfs_ioktime_data(struct lpfc_vport *vport, char *buf, int size)
1394 struct lpfc_hba *phba = vport->phba;
1397 if (phba->nvmet_support == 0) {
1399 len += scnprintf(buf + len, PAGE_SIZE - len,
1400 "ktime %s: Total Samples: %lld\n",
1401 (phba->ktime_on ? "Enabled" : "Disabled"),
1402 phba->ktime_data_samples);
1403 if (phba->ktime_data_samples == 0)
1407 buf + len, PAGE_SIZE - len,
1408 "Segment 1: Last Cmd cmpl "
1409 "done -to- Start of next Cmd (in driver)\n");
1411 buf + len, PAGE_SIZE - len,
1412 "avg:%08lld min:%08lld max %08lld\n",
1413 div_u64(phba->ktime_seg1_total,
1414 phba->ktime_data_samples),
1415 phba->ktime_seg1_min,
1416 phba->ktime_seg1_max);
1418 buf + len, PAGE_SIZE - len,
1419 "Segment 2: Driver start of Cmd "
1420 "-to- Firmware WQ doorbell\n");
1422 buf + len, PAGE_SIZE - len,
1423 "avg:%08lld min:%08lld max %08lld\n",
1424 div_u64(phba->ktime_seg2_total,
1425 phba->ktime_data_samples),
1426 phba->ktime_seg2_min,
1427 phba->ktime_seg2_max);
1429 buf + len, PAGE_SIZE - len,
1430 "Segment 3: Firmware WQ doorbell -to- "
1431 "MSI-X ISR cmpl\n");
1433 buf + len, PAGE_SIZE - len,
1434 "avg:%08lld min:%08lld max %08lld\n",
1435 div_u64(phba->ktime_seg3_total,
1436 phba->ktime_data_samples),
1437 phba->ktime_seg3_min,
1438 phba->ktime_seg3_max);
1440 buf + len, PAGE_SIZE - len,
1441 "Segment 4: MSI-X ISR cmpl -to- "
1444 buf + len, PAGE_SIZE - len,
1445 "avg:%08lld min:%08lld max %08lld\n",
1446 div_u64(phba->ktime_seg4_total,
1447 phba->ktime_data_samples),
1448 phba->ktime_seg4_min,
1449 phba->ktime_seg4_max);
1451 buf + len, PAGE_SIZE - len,
1452 "Total IO avg time: %08lld\n",
1453 div_u64(phba->ktime_seg1_total +
1454 phba->ktime_seg2_total +
1455 phba->ktime_seg3_total +
1456 phba->ktime_seg4_total,
1457 phba->ktime_data_samples));
1462 len += scnprintf(buf + len, PAGE_SIZE-len,
1463 "ktime %s: Total Samples: %lld %lld\n",
1464 (phba->ktime_on ? "Enabled" : "Disabled"),
1465 phba->ktime_data_samples,
1466 phba->ktime_status_samples);
1467 if (phba->ktime_data_samples == 0)
1470 len += scnprintf(buf + len, PAGE_SIZE-len,
1471 "Segment 1: MSI-X ISR Rcv cmd -to- "
1472 "cmd pass to NVME Layer\n");
1473 len += scnprintf(buf + len, PAGE_SIZE-len,
1474 "avg:%08lld min:%08lld max %08lld\n",
1475 div_u64(phba->ktime_seg1_total,
1476 phba->ktime_data_samples),
1477 phba->ktime_seg1_min,
1478 phba->ktime_seg1_max);
1479 len += scnprintf(buf + len, PAGE_SIZE-len,
1480 "Segment 2: cmd pass to NVME Layer- "
1481 "-to- Driver rcv cmd OP (action)\n");
1482 len += scnprintf(buf + len, PAGE_SIZE-len,
1483 "avg:%08lld min:%08lld max %08lld\n",
1484 div_u64(phba->ktime_seg2_total,
1485 phba->ktime_data_samples),
1486 phba->ktime_seg2_min,
1487 phba->ktime_seg2_max);
1488 len += scnprintf(buf + len, PAGE_SIZE-len,
1489 "Segment 3: Driver rcv cmd OP -to- "
1490 "Firmware WQ doorbell: cmd\n");
1491 len += scnprintf(buf + len, PAGE_SIZE-len,
1492 "avg:%08lld min:%08lld max %08lld\n",
1493 div_u64(phba->ktime_seg3_total,
1494 phba->ktime_data_samples),
1495 phba->ktime_seg3_min,
1496 phba->ktime_seg3_max);
1497 len += scnprintf(buf + len, PAGE_SIZE-len,
1498 "Segment 4: Firmware WQ doorbell: cmd "
1499 "-to- MSI-X ISR for cmd cmpl\n");
1500 len += scnprintf(buf + len, PAGE_SIZE-len,
1501 "avg:%08lld min:%08lld max %08lld\n",
1502 div_u64(phba->ktime_seg4_total,
1503 phba->ktime_data_samples),
1504 phba->ktime_seg4_min,
1505 phba->ktime_seg4_max);
1506 len += scnprintf(buf + len, PAGE_SIZE-len,
1507 "Segment 5: MSI-X ISR for cmd cmpl "
1508 "-to- NVME layer passed cmd done\n");
1509 len += scnprintf(buf + len, PAGE_SIZE-len,
1510 "avg:%08lld min:%08lld max %08lld\n",
1511 div_u64(phba->ktime_seg5_total,
1512 phba->ktime_data_samples),
1513 phba->ktime_seg5_min,
1514 phba->ktime_seg5_max);
1516 if (phba->ktime_status_samples == 0) {
1517 len += scnprintf(buf + len, PAGE_SIZE-len,
1518 "Total: cmd received by MSI-X ISR "
1519 "-to- cmd completed on wire\n");
1520 len += scnprintf(buf + len, PAGE_SIZE-len,
1521 "avg:%08lld min:%08lld "
1523 div_u64(phba->ktime_seg10_total,
1524 phba->ktime_data_samples),
1525 phba->ktime_seg10_min,
1526 phba->ktime_seg10_max);
1530 len += scnprintf(buf + len, PAGE_SIZE-len,
1531 "Segment 6: NVME layer passed cmd done "
1532 "-to- Driver rcv rsp status OP\n");
1533 len += scnprintf(buf + len, PAGE_SIZE-len,
1534 "avg:%08lld min:%08lld max %08lld\n",
1535 div_u64(phba->ktime_seg6_total,
1536 phba->ktime_status_samples),
1537 phba->ktime_seg6_min,
1538 phba->ktime_seg6_max);
1539 len += scnprintf(buf + len, PAGE_SIZE-len,
1540 "Segment 7: Driver rcv rsp status OP "
1541 "-to- Firmware WQ doorbell: status\n");
1542 len += scnprintf(buf + len, PAGE_SIZE-len,
1543 "avg:%08lld min:%08lld max %08lld\n",
1544 div_u64(phba->ktime_seg7_total,
1545 phba->ktime_status_samples),
1546 phba->ktime_seg7_min,
1547 phba->ktime_seg7_max);
1548 len += scnprintf(buf + len, PAGE_SIZE-len,
1549 "Segment 8: Firmware WQ doorbell: status"
1550 " -to- MSI-X ISR for status cmpl\n");
1551 len += scnprintf(buf + len, PAGE_SIZE-len,
1552 "avg:%08lld min:%08lld max %08lld\n",
1553 div_u64(phba->ktime_seg8_total,
1554 phba->ktime_status_samples),
1555 phba->ktime_seg8_min,
1556 phba->ktime_seg8_max);
1557 len += scnprintf(buf + len, PAGE_SIZE-len,
1558 "Segment 9: MSI-X ISR for status cmpl "
1559 "-to- NVME layer passed status done\n");
1560 len += scnprintf(buf + len, PAGE_SIZE-len,
1561 "avg:%08lld min:%08lld max %08lld\n",
1562 div_u64(phba->ktime_seg9_total,
1563 phba->ktime_status_samples),
1564 phba->ktime_seg9_min,
1565 phba->ktime_seg9_max);
1566 len += scnprintf(buf + len, PAGE_SIZE-len,
1567 "Total: cmd received by MSI-X ISR -to- "
1568 "cmd completed on wire\n");
1569 len += scnprintf(buf + len, PAGE_SIZE-len,
1570 "avg:%08lld min:%08lld max %08lld\n",
1571 div_u64(phba->ktime_seg10_total,
1572 phba->ktime_status_samples),
1573 phba->ktime_seg10_min,
1574 phba->ktime_seg10_max);
1579 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1580 * @phba: The phba to gather target node info from.
1581 * @buf: The buffer to dump log into.
1582 * @size: The maximum amount of data to process.
1585 * This routine dumps the NVME IO trace associated with @phba
1588 * This routine returns the amount of bytes that were dumped into @buf and will
1592 lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1594 struct lpfc_debugfs_nvmeio_trc *dtp;
1595 int i, state, index, skip;
1598 state = phba->nvmeio_trc_on;
1600 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1601 (phba->nvmeio_trc_size - 1);
1602 skip = phba->nvmeio_trc_output_idx;
1604 len += scnprintf(buf + len, size - len,
1605 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1606 (phba->nvmet_support ? "NVME" : "NVMET"),
1607 (state ? "Enabled" : "Disabled"),
1608 index, skip, phba->nvmeio_trc_size);
1610 if (!phba->nvmeio_trc || state)
1613 /* trace MUST bhe off to continue */
1615 for (i = index; i < phba->nvmeio_trc_size; i++) {
1620 dtp = phba->nvmeio_trc + i;
1621 phba->nvmeio_trc_output_idx++;
1626 len += scnprintf(buf + len, size - len, dtp->fmt,
1627 dtp->data1, dtp->data2, dtp->data3);
1629 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1630 phba->nvmeio_trc_output_idx = 0;
1631 len += scnprintf(buf + len, size - len,
1632 "Trace Complete\n");
1636 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1637 len += scnprintf(buf + len, size - len,
1638 "Trace Continue (%d of %d)\n",
1639 phba->nvmeio_trc_output_idx,
1640 phba->nvmeio_trc_size);
1644 for (i = 0; i < index; i++) {
1649 dtp = phba->nvmeio_trc + i;
1650 phba->nvmeio_trc_output_idx++;
1655 len += scnprintf(buf + len, size - len, dtp->fmt,
1656 dtp->data1, dtp->data2, dtp->data3);
1658 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1659 phba->nvmeio_trc_output_idx = 0;
1660 len += scnprintf(buf + len, size - len,
1661 "Trace Complete\n");
1665 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1666 len += scnprintf(buf + len, size - len,
1667 "Trace Continue (%d of %d)\n",
1668 phba->nvmeio_trc_output_idx,
1669 phba->nvmeio_trc_size);
1674 len += scnprintf(buf + len, size - len,
1681 * lpfc_debugfs_hdwqstat_data - Dump I/O stats to a buffer
1682 * @vport: The vport to gather target node info from.
1683 * @buf: The buffer to dump log into.
1684 * @size: The maximum amount of data to process.
1687 * This routine dumps the NVME + SCSI statistics associated with @vport
1690 * This routine returns the amount of bytes that were dumped into @buf and will
1694 lpfc_debugfs_hdwqstat_data(struct lpfc_vport *vport, char *buf, int size)
1696 struct lpfc_hba *phba = vport->phba;
1697 struct lpfc_hdwq_stat *c_stat;
1702 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
1704 scnprintf(tmp, sizeof(tmp), "HDWQ Stats:\n\n");
1705 if (strlcat(buf, tmp, size) >= size)
1708 scnprintf(tmp, sizeof(tmp), "(NVME Accounting: %s) ",
1709 (phba->hdwqstat_on &
1710 (LPFC_CHECK_NVME_IO | LPFC_CHECK_NVMET_IO) ?
1711 "Enabled" : "Disabled"));
1712 if (strlcat(buf, tmp, size) >= size)
1715 scnprintf(tmp, sizeof(tmp), "(SCSI Accounting: %s) ",
1716 (phba->hdwqstat_on & LPFC_CHECK_SCSI_IO ?
1717 "Enabled" : "Disabled"));
1718 if (strlcat(buf, tmp, size) >= size)
1721 scnprintf(tmp, sizeof(tmp), "\n\n");
1722 if (strlcat(buf, tmp, size) >= size)
1725 for (i = 0; i < phba->cfg_hdw_queue; i++) {
1730 for_each_present_cpu(j) {
1731 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, j);
1733 /* Only display for this HDWQ */
1734 if (i != c_stat->hdwq_no)
1737 /* Only display non-zero counters */
1738 if (!c_stat->xmt_io && !c_stat->cmpl_io &&
1742 if (!tot_xmt && !tot_cmpl && !tot_rcv) {
1743 /* Print HDWQ string only the first time */
1744 scnprintf(tmp, sizeof(tmp), "[HDWQ %d]:\t", i);
1745 if (strlcat(buf, tmp, size) >= size)
1749 tot_xmt += c_stat->xmt_io;
1750 tot_cmpl += c_stat->cmpl_io;
1751 if (phba->nvmet_support)
1752 tot_rcv += c_stat->rcv_io;
1754 scnprintf(tmp, sizeof(tmp), "| [CPU %d]: ", j);
1755 if (strlcat(buf, tmp, size) >= size)
1758 if (phba->nvmet_support) {
1759 scnprintf(tmp, sizeof(tmp),
1760 "XMT 0x%x CMPL 0x%x RCV 0x%x |",
1761 c_stat->xmt_io, c_stat->cmpl_io,
1763 if (strlcat(buf, tmp, size) >= size)
1766 scnprintf(tmp, sizeof(tmp),
1767 "XMT 0x%x CMPL 0x%x |",
1768 c_stat->xmt_io, c_stat->cmpl_io);
1769 if (strlcat(buf, tmp, size) >= size)
1774 /* Check if nothing to display */
1775 if (!tot_xmt && !tot_cmpl && !tot_rcv)
1778 scnprintf(tmp, sizeof(tmp), "\t->\t[HDWQ Total: ");
1779 if (strlcat(buf, tmp, size) >= size)
1782 if (phba->nvmet_support) {
1783 scnprintf(tmp, sizeof(tmp),
1784 "XMT 0x%x CMPL 0x%x RCV 0x%x]\n\n",
1785 tot_xmt, tot_cmpl, tot_rcv);
1786 if (strlcat(buf, tmp, size) >= size)
1789 scnprintf(tmp, sizeof(tmp),
1790 "XMT 0x%x CMPL 0x%x]\n\n",
1792 if (strlcat(buf, tmp, size) >= size)
1798 len = strnlen(buf, size);
1805 * lpfc_debugfs_disc_trc - Store discovery trace log
1806 * @vport: The vport to associate this trace string with for retrieval.
1807 * @mask: Log entry classification.
1808 * @fmt: Format string to be displayed when dumping the log.
1809 * @data1: 1st data parameter to be applied to @fmt.
1810 * @data2: 2nd data parameter to be applied to @fmt.
1811 * @data3: 3rd data parameter to be applied to @fmt.
1814 * This routine is used by the driver code to add a debugfs log entry to the
1815 * discovery trace buffer associated with @vport. Only entries with a @mask that
1816 * match the current debugfs discovery mask will be saved. Entries that do not
1817 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1818 * printf when displaying the log.
1821 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1822 uint32_t data1, uint32_t data2, uint32_t data3)
1824 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1825 struct lpfc_debugfs_trc *dtp;
1828 if (!(lpfc_debugfs_mask_disc_trc & mask))
1831 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1832 !vport || !vport->disc_trc)
1835 index = atomic_inc_return(&vport->disc_trc_cnt) &
1836 (lpfc_debugfs_max_disc_trc - 1);
1837 dtp = vport->disc_trc + index;
1842 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1849 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
1850 * @phba: The phba to associate this trace string with for retrieval.
1851 * @fmt: Format string to be displayed when dumping the log.
1852 * @data1: 1st data parameter to be applied to @fmt.
1853 * @data2: 2nd data parameter to be applied to @fmt.
1854 * @data3: 3rd data parameter to be applied to @fmt.
1857 * This routine is used by the driver code to add a debugfs log entry to the
1858 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1859 * @data3 are used like printf when displaying the log.
1862 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1863 uint32_t data1, uint32_t data2, uint32_t data3)
1865 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1866 struct lpfc_debugfs_trc *dtp;
1869 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1870 !phba || !phba->slow_ring_trc)
1873 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1874 (lpfc_debugfs_max_slow_ring_trc - 1);
1875 dtp = phba->slow_ring_trc + index;
1880 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1887 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1888 * @phba: The phba to associate this trace string with for retrieval.
1889 * @fmt: Format string to be displayed when dumping the log.
1890 * @data1: 1st data parameter to be applied to @fmt.
1891 * @data2: 2nd data parameter to be applied to @fmt.
1892 * @data3: 3rd data parameter to be applied to @fmt.
1895 * This routine is used by the driver code to add a debugfs log entry to the
1896 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1897 * @data3 are used like printf when displaying the log.
1900 lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1901 uint16_t data1, uint16_t data2, uint32_t data3)
1903 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1904 struct lpfc_debugfs_nvmeio_trc *dtp;
1907 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1910 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1911 (phba->nvmeio_trc_size - 1);
1912 dtp = phba->nvmeio_trc + index;
1920 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1922 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
1923 * @inode: The inode pointer that contains a vport pointer.
1924 * @file: The file pointer to attach the log output.
1927 * This routine is the entry point for the debugfs open file operation. It gets
1928 * the vport from the i_private field in @inode, allocates the necessary buffer
1929 * for the log, fills the buffer from the in-memory log for this vport, and then
1930 * returns a pointer to that log in the private_data field in @file.
1933 * This function returns zero if successful. On error it will return a negative
1937 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1939 struct lpfc_vport *vport = inode->i_private;
1940 struct lpfc_debug *debug;
1944 if (!lpfc_debugfs_max_disc_trc) {
1949 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1953 /* Round to page boundary */
1954 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1955 size = PAGE_ALIGN(size);
1957 debug->buffer = kmalloc(size, GFP_KERNEL);
1958 if (!debug->buffer) {
1963 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1964 file->private_data = debug;
1972 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
1973 * @inode: The inode pointer that contains a vport pointer.
1974 * @file: The file pointer to attach the log output.
1977 * This routine is the entry point for the debugfs open file operation. It gets
1978 * the vport from the i_private field in @inode, allocates the necessary buffer
1979 * for the log, fills the buffer from the in-memory log for this vport, and then
1980 * returns a pointer to that log in the private_data field in @file.
1983 * This function returns zero if successful. On error it will return a negative
1987 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1989 struct lpfc_hba *phba = inode->i_private;
1990 struct lpfc_debug *debug;
1994 if (!lpfc_debugfs_max_slow_ring_trc) {
1999 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2003 /* Round to page boundary */
2004 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
2005 size = PAGE_ALIGN(size);
2007 debug->buffer = kmalloc(size, GFP_KERNEL);
2008 if (!debug->buffer) {
2013 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
2014 file->private_data = debug;
2022 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
2023 * @inode: The inode pointer that contains a vport pointer.
2024 * @file: The file pointer to attach the log output.
2027 * This routine is the entry point for the debugfs open file operation. It gets
2028 * the vport from the i_private field in @inode, allocates the necessary buffer
2029 * for the log, fills the buffer from the in-memory log for this vport, and then
2030 * returns a pointer to that log in the private_data field in @file.
2033 * This function returns zero if successful. On error it will return a negative
2037 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
2039 struct lpfc_hba *phba = inode->i_private;
2040 struct lpfc_debug *debug;
2043 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2047 /* Round to page boundary */
2048 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
2049 if (!debug->buffer) {
2054 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
2056 file->private_data = debug;
2064 * lpfc_debugfs_multixripools_open - Open the multixripool debugfs buffer
2065 * @inode: The inode pointer that contains a hba pointer.
2066 * @file: The file pointer to attach the log output.
2069 * This routine is the entry point for the debugfs open file operation. It gets
2070 * the hba from the i_private field in @inode, allocates the necessary buffer
2071 * for the log, fills the buffer from the in-memory log for this hba, and then
2072 * returns a pointer to that log in the private_data field in @file.
2075 * This function returns zero if successful. On error it will return a negative
2079 lpfc_debugfs_multixripools_open(struct inode *inode, struct file *file)
2081 struct lpfc_hba *phba = inode->i_private;
2082 struct lpfc_debug *debug;
2085 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2089 /* Round to page boundary */
2090 debug->buffer = kzalloc(LPFC_DUMP_MULTIXRIPOOL_SIZE, GFP_KERNEL);
2091 if (!debug->buffer) {
2096 debug->len = lpfc_debugfs_multixripools_data(
2097 phba, debug->buffer, LPFC_DUMP_MULTIXRIPOOL_SIZE);
2099 debug->i_private = inode->i_private;
2100 file->private_data = debug;
2107 #ifdef LPFC_HDWQ_LOCK_STAT
2109 * lpfc_debugfs_lockstat_open - Open the lockstat debugfs buffer
2110 * @inode: The inode pointer that contains a vport pointer.
2111 * @file: The file pointer to attach the log output.
2114 * This routine is the entry point for the debugfs open file operation. It gets
2115 * the vport from the i_private field in @inode, allocates the necessary buffer
2116 * for the log, fills the buffer from the in-memory log for this vport, and then
2117 * returns a pointer to that log in the private_data field in @file.
2120 * This function returns zero if successful. On error it will return a negative
2124 lpfc_debugfs_lockstat_open(struct inode *inode, struct file *file)
2126 struct lpfc_hba *phba = inode->i_private;
2127 struct lpfc_debug *debug;
2130 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2134 /* Round to page boundary */
2135 debug->buffer = kmalloc(LPFC_HDWQINFO_SIZE, GFP_KERNEL);
2136 if (!debug->buffer) {
2141 debug->len = lpfc_debugfs_lockstat_data(phba, debug->buffer,
2143 file->private_data = debug;
2151 lpfc_debugfs_lockstat_write(struct file *file, const char __user *buf,
2152 size_t nbytes, loff_t *ppos)
2154 struct lpfc_debug *debug = file->private_data;
2155 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2156 struct lpfc_sli4_hdw_queue *qp;
2162 memset(mybuf, 0, sizeof(mybuf));
2164 bsize = min(nbytes, (sizeof(mybuf) - 1));
2166 if (copy_from_user(mybuf, buf, bsize))
2170 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2171 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2172 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2173 qp = &phba->sli4_hba.hdwq[i];
2174 qp->lock_conflict.alloc_xri_get = 0;
2175 qp->lock_conflict.alloc_xri_put = 0;
2176 qp->lock_conflict.free_xri = 0;
2177 qp->lock_conflict.wq_access = 0;
2178 qp->lock_conflict.alloc_pvt_pool = 0;
2179 qp->lock_conflict.mv_from_pvt_pool = 0;
2180 qp->lock_conflict.mv_to_pub_pool = 0;
2181 qp->lock_conflict.mv_to_pvt_pool = 0;
2182 qp->lock_conflict.free_pvt_pool = 0;
2183 qp->lock_conflict.free_pub_pool = 0;
2184 qp->lock_conflict.wq_access = 0;
2191 static int lpfc_debugfs_ras_log_data(struct lpfc_hba *phba,
2192 char *buffer, int size)
2195 struct lpfc_dmabuf *dmabuf, *next;
2197 memset(buffer, 0, size);
2199 spin_lock_irq(&phba->hbalock);
2200 if (phba->ras_fwlog.state != ACTIVE) {
2201 spin_unlock_irq(&phba->hbalock);
2204 spin_unlock_irq(&phba->hbalock);
2206 list_for_each_entry_safe(dmabuf, next,
2207 &phba->ras_fwlog.fwlog_buff_list, list) {
2208 /* Check if copying will go over size and a '\0' char */
2209 if ((copied + LPFC_RAS_MAX_ENTRY_SIZE) >= (size - 1)) {
2210 memcpy(buffer + copied, dmabuf->virt,
2212 copied += size - copied - 1;
2215 memcpy(buffer + copied, dmabuf->virt, LPFC_RAS_MAX_ENTRY_SIZE);
2216 copied += LPFC_RAS_MAX_ENTRY_SIZE;
2222 lpfc_debugfs_ras_log_release(struct inode *inode, struct file *file)
2224 struct lpfc_debug *debug = file->private_data;
2226 vfree(debug->buffer);
2233 * lpfc_debugfs_ras_log_open - Open the RAS log debugfs buffer
2234 * @inode: The inode pointer that contains a vport pointer.
2235 * @file: The file pointer to attach the log output.
2238 * This routine is the entry point for the debugfs open file operation. It gets
2239 * the vport from the i_private field in @inode, allocates the necessary buffer
2240 * for the log, fills the buffer from the in-memory log for this vport, and then
2241 * returns a pointer to that log in the private_data field in @file.
2244 * This function returns zero if successful. On error it will return a negative
2248 lpfc_debugfs_ras_log_open(struct inode *inode, struct file *file)
2250 struct lpfc_hba *phba = inode->i_private;
2251 struct lpfc_debug *debug;
2255 spin_lock_irq(&phba->hbalock);
2256 if (phba->ras_fwlog.state != ACTIVE) {
2257 spin_unlock_irq(&phba->hbalock);
2261 spin_unlock_irq(&phba->hbalock);
2262 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2266 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;
2267 debug->buffer = vmalloc(size);
2271 debug->len = lpfc_debugfs_ras_log_data(phba, debug->buffer, size);
2272 if (debug->len < 0) {
2276 file->private_data = debug;
2281 vfree(debug->buffer);
2289 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
2290 * @inode: The inode pointer that contains a vport pointer.
2291 * @file: The file pointer to attach the log output.
2294 * This routine is the entry point for the debugfs open file operation. It gets
2295 * the vport from the i_private field in @inode, allocates the necessary buffer
2296 * for the log, fills the buffer from the in-memory log for this vport, and then
2297 * returns a pointer to that log in the private_data field in @file.
2300 * This function returns zero if successful. On error it will return a negative
2304 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
2306 struct lpfc_hba *phba = inode->i_private;
2307 struct lpfc_debug *debug;
2310 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2314 /* Round to page boundary */
2315 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
2316 if (!debug->buffer) {
2321 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
2322 LPFC_DUMPHBASLIM_SIZE);
2323 file->private_data = debug;
2331 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
2332 * @inode: The inode pointer that contains a vport pointer.
2333 * @file: The file pointer to attach the log output.
2336 * This routine is the entry point for the debugfs open file operation. It gets
2337 * the vport from the i_private field in @inode, allocates the necessary buffer
2338 * for the log, fills the buffer from the in-memory log for this vport, and then
2339 * returns a pointer to that log in the private_data field in @file.
2342 * This function returns zero if successful. On error it will return a negative
2346 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
2348 struct lpfc_hba *phba = inode->i_private;
2349 struct lpfc_debug *debug;
2352 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2356 /* Round to page boundary */
2357 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
2358 if (!debug->buffer) {
2363 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
2364 LPFC_DUMPHOSTSLIM_SIZE);
2365 file->private_data = debug;
2373 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
2374 size_t nbytes, loff_t *ppos)
2376 struct dentry *dent = file->f_path.dentry;
2377 struct lpfc_hba *phba = file->private_data;
2382 if (dent == phba->debug_writeGuard)
2383 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
2384 else if (dent == phba->debug_writeApp)
2385 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
2386 else if (dent == phba->debug_writeRef)
2387 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
2388 else if (dent == phba->debug_readGuard)
2389 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
2390 else if (dent == phba->debug_readApp)
2391 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
2392 else if (dent == phba->debug_readRef)
2393 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
2394 else if (dent == phba->debug_InjErrNPortID)
2395 cnt = scnprintf(cbuf, 32, "0x%06x\n",
2396 phba->lpfc_injerr_nportid);
2397 else if (dent == phba->debug_InjErrWWPN) {
2398 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
2399 tmp = cpu_to_be64(tmp);
2400 cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
2401 } else if (dent == phba->debug_InjErrLBA) {
2402 if (phba->lpfc_injerr_lba == (sector_t)(-1))
2403 cnt = scnprintf(cbuf, 32, "off\n");
2405 cnt = scnprintf(cbuf, 32, "0x%llx\n",
2406 (uint64_t) phba->lpfc_injerr_lba);
2408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2409 "0547 Unknown debugfs error injection entry\n");
2411 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
2415 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
2416 size_t nbytes, loff_t *ppos)
2418 struct dentry *dent = file->f_path.dentry;
2419 struct lpfc_hba *phba = file->private_data;
2424 memset(dstbuf, 0, 33);
2425 size = (nbytes < 32) ? nbytes : 32;
2426 if (copy_from_user(dstbuf, buf, size))
2429 if (dent == phba->debug_InjErrLBA) {
2430 if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
2432 tmp = (uint64_t)(-1);
2435 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
2438 if (dent == phba->debug_writeGuard)
2439 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
2440 else if (dent == phba->debug_writeApp)
2441 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
2442 else if (dent == phba->debug_writeRef)
2443 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
2444 else if (dent == phba->debug_readGuard)
2445 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
2446 else if (dent == phba->debug_readApp)
2447 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
2448 else if (dent == phba->debug_readRef)
2449 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
2450 else if (dent == phba->debug_InjErrLBA)
2451 phba->lpfc_injerr_lba = (sector_t)tmp;
2452 else if (dent == phba->debug_InjErrNPortID)
2453 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
2454 else if (dent == phba->debug_InjErrWWPN) {
2455 tmp = cpu_to_be64(tmp);
2456 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
2458 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2459 "0548 Unknown debugfs error injection entry\n");
2465 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
2471 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
2472 * @inode: The inode pointer that contains a vport pointer.
2473 * @file: The file pointer to attach the log output.
2476 * This routine is the entry point for the debugfs open file operation. It gets
2477 * the vport from the i_private field in @inode, allocates the necessary buffer
2478 * for the log, fills the buffer from the in-memory log for this vport, and then
2479 * returns a pointer to that log in the private_data field in @file.
2482 * This function returns zero if successful. On error it will return a negative
2486 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
2488 struct lpfc_vport *vport = inode->i_private;
2489 struct lpfc_debug *debug;
2492 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2496 /* Round to page boundary */
2497 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
2498 if (!debug->buffer) {
2503 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
2504 LPFC_NODELIST_SIZE);
2505 file->private_data = debug;
2513 * lpfc_debugfs_lseek - Seek through a debugfs file
2514 * @file: The file pointer to seek through.
2515 * @off: The offset to seek to or the amount to seek by.
2516 * @whence: Indicates how to seek.
2519 * This routine is the entry point for the debugfs lseek file operation. The
2520 * @whence parameter indicates whether @off is the offset to directly seek to,
2521 * or if it is a value to seek forward or reverse by. This function figures out
2522 * what the new offset of the debugfs file will be and assigns that value to the
2523 * f_pos field of @file.
2526 * This function returns the new offset if successful and returns a negative
2527 * error if unable to process the seek.
2530 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
2532 struct lpfc_debug *debug = file->private_data;
2533 return fixed_size_llseek(file, off, whence, debug->len);
2537 * lpfc_debugfs_read - Read a debugfs file
2538 * @file: The file pointer to read from.
2539 * @buf: The buffer to copy the data to.
2540 * @nbytes: The number of bytes to read.
2541 * @ppos: The position in the file to start reading from.
2544 * This routine reads data from from the buffer indicated in the private_data
2545 * field of @file. It will start reading at @ppos and copy up to @nbytes of
2549 * This function returns the amount of data that was read (this could be less
2550 * than @nbytes if the end of the file was reached) or a negative error value.
2553 lpfc_debugfs_read(struct file *file, char __user *buf,
2554 size_t nbytes, loff_t *ppos)
2556 struct lpfc_debug *debug = file->private_data;
2558 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
2563 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
2564 * @inode: The inode pointer that contains a vport pointer. (unused)
2565 * @file: The file pointer that contains the buffer to release.
2568 * This routine frees the buffer that was allocated when the debugfs file was
2572 * This function returns zero.
2575 lpfc_debugfs_release(struct inode *inode, struct file *file)
2577 struct lpfc_debug *debug = file->private_data;
2579 kfree(debug->buffer);
2586 * lpfc_debugfs_multixripools_write - Clear multi-XRI pools statistics
2587 * @file: The file pointer to read from.
2588 * @buf: The buffer to copy the user data from.
2589 * @nbytes: The number of bytes to get.
2590 * @ppos: The position in the file to start reading from.
2593 * This routine clears multi-XRI pools statistics when buf contains "clear".
2596 * It returns the @nbytges passing in from debugfs user space when successful.
2597 * In case of error conditions, it returns proper error code back to the user
2601 lpfc_debugfs_multixripools_write(struct file *file, const char __user *buf,
2602 size_t nbytes, loff_t *ppos)
2604 struct lpfc_debug *debug = file->private_data;
2605 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2610 struct lpfc_sli4_hdw_queue *qp;
2611 struct lpfc_multixri_pool *multixri_pool;
2613 if (nbytes > sizeof(mybuf) - 1)
2614 nbytes = sizeof(mybuf) - 1;
2616 memset(mybuf, 0, sizeof(mybuf));
2618 if (copy_from_user(mybuf, buf, nbytes))
2622 if ((strncmp(pbuf, "clear", strlen("clear"))) == 0) {
2623 hwq_count = phba->cfg_hdw_queue;
2624 for (i = 0; i < hwq_count; i++) {
2625 qp = &phba->sli4_hba.hdwq[i];
2626 multixri_pool = qp->p_multixri_pool;
2630 qp->empty_io_bufs = 0;
2631 multixri_pool->pbl_empty_count = 0;
2632 #ifdef LPFC_MXP_STAT
2633 multixri_pool->above_limit_count = 0;
2634 multixri_pool->below_limit_count = 0;
2635 multixri_pool->stat_max_hwm = 0;
2636 multixri_pool->local_pbl_hit_count = 0;
2637 multixri_pool->other_pbl_hit_count = 0;
2639 multixri_pool->stat_pbl_count = 0;
2640 multixri_pool->stat_pvt_count = 0;
2641 multixri_pool->stat_busy_count = 0;
2642 multixri_pool->stat_snapshot_taken = 0;
2645 return strlen(pbuf);
2652 lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
2654 struct lpfc_vport *vport = inode->i_private;
2655 struct lpfc_debug *debug;
2658 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2662 /* Round to page boundary */
2663 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
2664 if (!debug->buffer) {
2669 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
2670 LPFC_NVMESTAT_SIZE);
2672 debug->i_private = inode->i_private;
2673 file->private_data = debug;
2681 lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
2682 size_t nbytes, loff_t *ppos)
2684 struct lpfc_debug *debug = file->private_data;
2685 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2686 struct lpfc_hba *phba = vport->phba;
2687 struct lpfc_nvmet_tgtport *tgtp;
2691 if (!phba->targetport)
2694 if (nbytes > sizeof(mybuf) - 1)
2695 nbytes = sizeof(mybuf) - 1;
2697 memset(mybuf, 0, sizeof(mybuf));
2699 if (copy_from_user(mybuf, buf, nbytes))
2703 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2704 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2705 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2706 atomic_set(&tgtp->rcv_ls_req_in, 0);
2707 atomic_set(&tgtp->rcv_ls_req_out, 0);
2708 atomic_set(&tgtp->rcv_ls_req_drop, 0);
2709 atomic_set(&tgtp->xmt_ls_abort, 0);
2710 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
2711 atomic_set(&tgtp->xmt_ls_rsp, 0);
2712 atomic_set(&tgtp->xmt_ls_drop, 0);
2713 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
2714 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
2716 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
2717 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
2718 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
2719 atomic_set(&tgtp->xmt_fcp_drop, 0);
2720 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
2721 atomic_set(&tgtp->xmt_fcp_read, 0);
2722 atomic_set(&tgtp->xmt_fcp_write, 0);
2723 atomic_set(&tgtp->xmt_fcp_rsp, 0);
2724 atomic_set(&tgtp->xmt_fcp_release, 0);
2725 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
2726 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
2727 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
2729 atomic_set(&tgtp->xmt_fcp_abort, 0);
2730 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
2731 atomic_set(&tgtp->xmt_abort_sol, 0);
2732 atomic_set(&tgtp->xmt_abort_unsol, 0);
2733 atomic_set(&tgtp->xmt_abort_rsp, 0);
2734 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
2740 lpfc_debugfs_scsistat_open(struct inode *inode, struct file *file)
2742 struct lpfc_vport *vport = inode->i_private;
2743 struct lpfc_debug *debug;
2746 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2750 /* Round to page boundary */
2751 debug->buffer = kzalloc(LPFC_SCSISTAT_SIZE, GFP_KERNEL);
2752 if (!debug->buffer) {
2757 debug->len = lpfc_debugfs_scsistat_data(vport, debug->buffer,
2758 LPFC_SCSISTAT_SIZE);
2760 debug->i_private = inode->i_private;
2761 file->private_data = debug;
2769 lpfc_debugfs_scsistat_write(struct file *file, const char __user *buf,
2770 size_t nbytes, loff_t *ppos)
2772 struct lpfc_debug *debug = file->private_data;
2773 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2774 struct lpfc_hba *phba = vport->phba;
2775 char mybuf[6] = {0};
2778 if (copy_from_user(mybuf, buf, (nbytes >= sizeof(mybuf)) ?
2779 (sizeof(mybuf) - 1) : nbytes))
2782 if ((strncmp(&mybuf[0], "reset", strlen("reset")) == 0) ||
2783 (strncmp(&mybuf[0], "zero", strlen("zero")) == 0)) {
2784 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2785 memset(&phba->sli4_hba.hdwq[i].scsi_cstat, 0,
2786 sizeof(phba->sli4_hba.hdwq[i].scsi_cstat));
2794 lpfc_debugfs_ioktime_open(struct inode *inode, struct file *file)
2796 struct lpfc_vport *vport = inode->i_private;
2797 struct lpfc_debug *debug;
2800 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2804 /* Round to page boundary */
2805 debug->buffer = kmalloc(LPFC_IOKTIME_SIZE, GFP_KERNEL);
2806 if (!debug->buffer) {
2811 debug->len = lpfc_debugfs_ioktime_data(vport, debug->buffer,
2814 debug->i_private = inode->i_private;
2815 file->private_data = debug;
2823 lpfc_debugfs_ioktime_write(struct file *file, const char __user *buf,
2824 size_t nbytes, loff_t *ppos)
2826 struct lpfc_debug *debug = file->private_data;
2827 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2828 struct lpfc_hba *phba = vport->phba;
2832 if (nbytes > sizeof(mybuf) - 1)
2833 nbytes = sizeof(mybuf) - 1;
2835 memset(mybuf, 0, sizeof(mybuf));
2837 if (copy_from_user(mybuf, buf, nbytes))
2841 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2842 phba->ktime_data_samples = 0;
2843 phba->ktime_status_samples = 0;
2844 phba->ktime_seg1_total = 0;
2845 phba->ktime_seg1_max = 0;
2846 phba->ktime_seg1_min = 0xffffffff;
2847 phba->ktime_seg2_total = 0;
2848 phba->ktime_seg2_max = 0;
2849 phba->ktime_seg2_min = 0xffffffff;
2850 phba->ktime_seg3_total = 0;
2851 phba->ktime_seg3_max = 0;
2852 phba->ktime_seg3_min = 0xffffffff;
2853 phba->ktime_seg4_total = 0;
2854 phba->ktime_seg4_max = 0;
2855 phba->ktime_seg4_min = 0xffffffff;
2856 phba->ktime_seg5_total = 0;
2857 phba->ktime_seg5_max = 0;
2858 phba->ktime_seg5_min = 0xffffffff;
2859 phba->ktime_seg6_total = 0;
2860 phba->ktime_seg6_max = 0;
2861 phba->ktime_seg6_min = 0xffffffff;
2862 phba->ktime_seg7_total = 0;
2863 phba->ktime_seg7_max = 0;
2864 phba->ktime_seg7_min = 0xffffffff;
2865 phba->ktime_seg8_total = 0;
2866 phba->ktime_seg8_max = 0;
2867 phba->ktime_seg8_min = 0xffffffff;
2868 phba->ktime_seg9_total = 0;
2869 phba->ktime_seg9_max = 0;
2870 phba->ktime_seg9_min = 0xffffffff;
2871 phba->ktime_seg10_total = 0;
2872 phba->ktime_seg10_max = 0;
2873 phba->ktime_seg10_min = 0xffffffff;
2876 return strlen(pbuf);
2877 } else if ((strncmp(pbuf, "off",
2878 sizeof("off") - 1) == 0)) {
2880 return strlen(pbuf);
2881 } else if ((strncmp(pbuf, "zero",
2882 sizeof("zero") - 1) == 0)) {
2883 phba->ktime_data_samples = 0;
2884 phba->ktime_status_samples = 0;
2885 phba->ktime_seg1_total = 0;
2886 phba->ktime_seg1_max = 0;
2887 phba->ktime_seg1_min = 0xffffffff;
2888 phba->ktime_seg2_total = 0;
2889 phba->ktime_seg2_max = 0;
2890 phba->ktime_seg2_min = 0xffffffff;
2891 phba->ktime_seg3_total = 0;
2892 phba->ktime_seg3_max = 0;
2893 phba->ktime_seg3_min = 0xffffffff;
2894 phba->ktime_seg4_total = 0;
2895 phba->ktime_seg4_max = 0;
2896 phba->ktime_seg4_min = 0xffffffff;
2897 phba->ktime_seg5_total = 0;
2898 phba->ktime_seg5_max = 0;
2899 phba->ktime_seg5_min = 0xffffffff;
2900 phba->ktime_seg6_total = 0;
2901 phba->ktime_seg6_max = 0;
2902 phba->ktime_seg6_min = 0xffffffff;
2903 phba->ktime_seg7_total = 0;
2904 phba->ktime_seg7_max = 0;
2905 phba->ktime_seg7_min = 0xffffffff;
2906 phba->ktime_seg8_total = 0;
2907 phba->ktime_seg8_max = 0;
2908 phba->ktime_seg8_min = 0xffffffff;
2909 phba->ktime_seg9_total = 0;
2910 phba->ktime_seg9_max = 0;
2911 phba->ktime_seg9_min = 0xffffffff;
2912 phba->ktime_seg10_total = 0;
2913 phba->ktime_seg10_max = 0;
2914 phba->ktime_seg10_min = 0xffffffff;
2915 return strlen(pbuf);
2921 lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2923 struct lpfc_hba *phba = inode->i_private;
2924 struct lpfc_debug *debug;
2927 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2931 /* Round to page boundary */
2932 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2933 if (!debug->buffer) {
2938 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2939 LPFC_NVMEIO_TRC_SIZE);
2941 debug->i_private = inode->i_private;
2942 file->private_data = debug;
2950 lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2951 size_t nbytes, loff_t *ppos)
2953 struct lpfc_debug *debug = file->private_data;
2954 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2960 if (nbytes > sizeof(mybuf) - 1)
2961 nbytes = sizeof(mybuf) - 1;
2963 memset(mybuf, 0, sizeof(mybuf));
2965 if (copy_from_user(mybuf, buf, nbytes))
2969 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2970 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2971 "0570 nvmeio_trc_off\n");
2972 phba->nvmeio_trc_output_idx = 0;
2973 phba->nvmeio_trc_on = 0;
2974 return strlen(pbuf);
2975 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2976 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2977 "0571 nvmeio_trc_on\n");
2978 phba->nvmeio_trc_output_idx = 0;
2979 phba->nvmeio_trc_on = 1;
2980 return strlen(pbuf);
2983 /* We must be off to allocate the trace buffer */
2984 if (phba->nvmeio_trc_on != 0)
2987 /* If not on or off, the parameter is the trace buffer size */
2988 i = kstrtoul(pbuf, 0, &sz);
2991 phba->nvmeio_trc_size = (uint32_t)sz;
2993 /* It must be a power of 2 - round down */
3000 if (phba->nvmeio_trc_size != sz)
3001 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3002 "0572 nvmeio_trc_size changed to %ld\n",
3004 phba->nvmeio_trc_size = (uint32_t)sz;
3006 /* If one previously exists, free it */
3007 kfree(phba->nvmeio_trc);
3009 /* Allocate new trace buffer and initialize */
3010 phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
3012 if (!phba->nvmeio_trc) {
3013 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3014 "0573 Cannot create debugfs "
3015 "nvmeio_trc buffer\n");
3018 atomic_set(&phba->nvmeio_trc_cnt, 0);
3019 phba->nvmeio_trc_on = 0;
3020 phba->nvmeio_trc_output_idx = 0;
3022 return strlen(pbuf);
3026 lpfc_debugfs_hdwqstat_open(struct inode *inode, struct file *file)
3028 struct lpfc_vport *vport = inode->i_private;
3029 struct lpfc_debug *debug;
3032 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
3036 /* Round to page boundary */
3037 debug->buffer = kcalloc(1, LPFC_SCSISTAT_SIZE, GFP_KERNEL);
3038 if (!debug->buffer) {
3043 debug->len = lpfc_debugfs_hdwqstat_data(vport, debug->buffer,
3044 LPFC_SCSISTAT_SIZE);
3046 debug->i_private = inode->i_private;
3047 file->private_data = debug;
3055 lpfc_debugfs_hdwqstat_write(struct file *file, const char __user *buf,
3056 size_t nbytes, loff_t *ppos)
3058 struct lpfc_debug *debug = file->private_data;
3059 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
3060 struct lpfc_hba *phba = vport->phba;
3061 struct lpfc_hdwq_stat *c_stat;
3066 if (nbytes > sizeof(mybuf) - 1)
3067 nbytes = sizeof(mybuf) - 1;
3069 memset(mybuf, 0, sizeof(mybuf));
3071 if (copy_from_user(mybuf, buf, nbytes))
3075 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
3076 if (phba->nvmet_support)
3077 phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
3079 phba->hdwqstat_on |= (LPFC_CHECK_NVME_IO |
3080 LPFC_CHECK_SCSI_IO);
3081 return strlen(pbuf);
3082 } else if ((strncmp(pbuf, "nvme_on", sizeof("nvme_on") - 1) == 0)) {
3083 if (phba->nvmet_support)
3084 phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
3086 phba->hdwqstat_on |= LPFC_CHECK_NVME_IO;
3087 return strlen(pbuf);
3088 } else if ((strncmp(pbuf, "scsi_on", sizeof("scsi_on") - 1) == 0)) {
3089 if (!phba->nvmet_support)
3090 phba->hdwqstat_on |= LPFC_CHECK_SCSI_IO;
3091 return strlen(pbuf);
3092 } else if ((strncmp(pbuf, "nvme_off", sizeof("nvme_off") - 1) == 0)) {
3093 phba->hdwqstat_on &= ~(LPFC_CHECK_NVME_IO |
3094 LPFC_CHECK_NVMET_IO);
3095 return strlen(pbuf);
3096 } else if ((strncmp(pbuf, "scsi_off", sizeof("scsi_off") - 1) == 0)) {
3097 phba->hdwqstat_on &= ~LPFC_CHECK_SCSI_IO;
3098 return strlen(pbuf);
3099 } else if ((strncmp(pbuf, "off",
3100 sizeof("off") - 1) == 0)) {
3101 phba->hdwqstat_on = LPFC_CHECK_OFF;
3102 return strlen(pbuf);
3103 } else if ((strncmp(pbuf, "zero",
3104 sizeof("zero") - 1) == 0)) {
3105 for_each_present_cpu(i) {
3106 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, i);
3108 c_stat->cmpl_io = 0;
3111 return strlen(pbuf);
3117 * ---------------------------------
3118 * iDiag debugfs file access methods
3119 * ---------------------------------
3121 * All access methods are through the proper SLI4 PCI function's debugfs
3124 * /sys/kernel/debug/lpfc/fn<#>/iDiag
3128 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
3129 * @buf: The pointer to the user space buffer.
3130 * @nbytes: The number of bytes in the user space buffer.
3131 * @idiag_cmd: pointer to the idiag command struct.
3133 * This routine reads data from debugfs user space buffer and parses the
3134 * buffer for getting the idiag command and arguments. The while space in
3135 * between the set of data is used as the parsing separator.
3137 * This routine returns 0 when successful, it returns proper error code
3138 * back to the user space in error conditions.
3140 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
3141 struct lpfc_idiag_cmd *idiag_cmd)
3144 char *pbuf, *step_str;
3148 memset(mybuf, 0, sizeof(mybuf));
3149 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
3150 bsize = min(nbytes, (sizeof(mybuf)-1));
3152 if (copy_from_user(mybuf, buf, bsize))
3155 step_str = strsep(&pbuf, "\t ");
3157 /* The opcode must present */
3161 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
3162 if (idiag_cmd->opcode == 0)
3165 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
3166 step_str = strsep(&pbuf, "\t ");
3169 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
3175 * lpfc_idiag_open - idiag open debugfs
3176 * @inode: The inode pointer that contains a pointer to phba.
3177 * @file: The file pointer to attach the file operation.
3180 * This routine is the entry point for the debugfs open file operation. It
3181 * gets the reference to phba from the i_private field in @inode, it then
3182 * allocates buffer for the file operation, performs the necessary PCI config
3183 * space read into the allocated buffer according to the idiag user command
3184 * setup, and then returns a pointer to buffer in the private_data field in
3188 * This function returns zero if successful. On error it will return an
3189 * negative error value.
3192 lpfc_idiag_open(struct inode *inode, struct file *file)
3194 struct lpfc_debug *debug;
3196 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
3200 debug->i_private = inode->i_private;
3201 debug->buffer = NULL;
3202 file->private_data = debug;
3208 * lpfc_idiag_release - Release idiag access file operation
3209 * @inode: The inode pointer that contains a vport pointer. (unused)
3210 * @file: The file pointer that contains the buffer to release.
3213 * This routine is the generic release routine for the idiag access file
3214 * operation, it frees the buffer that was allocated when the debugfs file
3218 * This function returns zero.
3221 lpfc_idiag_release(struct inode *inode, struct file *file)
3223 struct lpfc_debug *debug = file->private_data;
3225 /* Free the buffers to the file operation */
3226 kfree(debug->buffer);
3233 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
3234 * @inode: The inode pointer that contains a vport pointer. (unused)
3235 * @file: The file pointer that contains the buffer to release.
3238 * This routine frees the buffer that was allocated when the debugfs file
3239 * was opened. It also reset the fields in the idiag command struct in the
3240 * case of command for write operation.
3243 * This function returns zero.
3246 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
3248 struct lpfc_debug *debug = file->private_data;
3250 if (debug->op == LPFC_IDIAG_OP_WR) {
3251 switch (idiag.cmd.opcode) {
3252 case LPFC_IDIAG_CMD_PCICFG_WR:
3253 case LPFC_IDIAG_CMD_PCICFG_ST:
3254 case LPFC_IDIAG_CMD_PCICFG_CL:
3255 case LPFC_IDIAG_CMD_QUEACC_WR:
3256 case LPFC_IDIAG_CMD_QUEACC_ST:
3257 case LPFC_IDIAG_CMD_QUEACC_CL:
3258 memset(&idiag, 0, sizeof(idiag));
3265 /* Free the buffers to the file operation */
3266 kfree(debug->buffer);
3273 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
3274 * @file: The file pointer to read from.
3275 * @buf: The buffer to copy the data to.
3276 * @nbytes: The number of bytes to read.
3277 * @ppos: The position in the file to start reading from.
3280 * This routine reads data from the @phba pci config space according to the
3281 * idiag command, and copies to user @buf. Depending on the PCI config space
3282 * read command setup, it does either a single register read of a byte
3283 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
3284 * registers from the 4K extended PCI config space.
3287 * This function returns the amount of data that was read (this could be less
3288 * than @nbytes if the end of the file was reached) or a negative error value.
3291 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
3294 struct lpfc_debug *debug = file->private_data;
3295 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3296 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
3299 struct pci_dev *pdev;
3304 pdev = phba->pcidev;
3308 /* This is a user read operation */
3309 debug->op = LPFC_IDIAG_OP_RD;
3312 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
3315 pbuffer = debug->buffer;
3320 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
3321 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3322 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
3326 /* Read single PCI config space register */
3328 case SIZE_U8: /* byte (8 bits) */
3329 pci_read_config_byte(pdev, where, &u8val);
3330 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3331 "%03x: %02x\n", where, u8val);
3333 case SIZE_U16: /* word (16 bits) */
3334 pci_read_config_word(pdev, where, &u16val);
3335 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3336 "%03x: %04x\n", where, u16val);
3338 case SIZE_U32: /* double word (32 bits) */
3339 pci_read_config_dword(pdev, where, &u32val);
3340 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3341 "%03x: %08x\n", where, u32val);
3343 case LPFC_PCI_CFG_BROWSE: /* browse all */
3350 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3354 /* Browse all PCI config space registers */
3355 offset_label = idiag.offset.last_rd;
3356 offset = offset_label;
3358 /* Read PCI config space */
3359 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3360 "%03x: ", offset_label);
3362 pci_read_config_dword(pdev, offset, &u32val);
3363 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3365 offset += sizeof(uint32_t);
3366 if (offset >= LPFC_PCI_CFG_SIZE) {
3367 len += scnprintf(pbuffer+len,
3368 LPFC_PCI_CFG_SIZE-len, "\n");
3371 index -= sizeof(uint32_t);
3373 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3375 else if (!(index % (8 * sizeof(uint32_t)))) {
3376 offset_label += (8 * sizeof(uint32_t));
3377 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
3378 "\n%03x: ", offset_label);
3382 /* Set up the offset for next portion of pci cfg read */
3384 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
3385 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
3386 idiag.offset.last_rd = 0;
3388 idiag.offset.last_rd = 0;
3390 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3394 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
3395 * @file: The file pointer to read from.
3396 * @buf: The buffer to copy the user data from.
3397 * @nbytes: The number of bytes to get.
3398 * @ppos: The position in the file to start reading from.
3400 * This routine get the debugfs idiag command struct from user space and
3401 * then perform the syntax check for PCI config space read or write command
3402 * accordingly. In the case of PCI config space read command, it sets up
3403 * the command in the idiag command struct for the debugfs read operation.
3404 * In the case of PCI config space write operation, it executes the write
3405 * operation into the PCI config space accordingly.
3407 * It returns the @nbytges passing in from debugfs user space when successful.
3408 * In case of error conditions, it returns proper error code back to the user
3412 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
3413 size_t nbytes, loff_t *ppos)
3415 struct lpfc_debug *debug = file->private_data;
3416 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3417 uint32_t where, value, count;
3421 struct pci_dev *pdev;
3424 pdev = phba->pcidev;
3428 /* This is a user write operation */
3429 debug->op = LPFC_IDIAG_OP_WR;
3431 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3435 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
3436 /* Sanity check on PCI config read command line arguments */
3437 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
3439 /* Read command from PCI config space, set up command fields */
3440 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3441 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
3442 if (count == LPFC_PCI_CFG_BROWSE) {
3443 if (where % sizeof(uint32_t))
3445 /* Starting offset to browse */
3446 idiag.offset.last_rd = where;
3447 } else if ((count != sizeof(uint8_t)) &&
3448 (count != sizeof(uint16_t)) &&
3449 (count != sizeof(uint32_t)))
3451 if (count == sizeof(uint8_t)) {
3452 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
3454 if (where % sizeof(uint8_t))
3457 if (count == sizeof(uint16_t)) {
3458 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
3460 if (where % sizeof(uint16_t))
3463 if (count == sizeof(uint32_t)) {
3464 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
3466 if (where % sizeof(uint32_t))
3469 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
3470 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
3471 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3472 /* Sanity check on PCI config write command line arguments */
3473 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
3475 /* Write command to PCI config space, read-modify-write */
3476 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3477 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
3478 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
3480 if ((count != sizeof(uint8_t)) &&
3481 (count != sizeof(uint16_t)) &&
3482 (count != sizeof(uint32_t)))
3484 if (count == sizeof(uint8_t)) {
3485 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
3487 if (where % sizeof(uint8_t))
3489 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3490 pci_write_config_byte(pdev, where,
3492 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3493 rc = pci_read_config_byte(pdev, where, &u8val);
3495 u8val |= (uint8_t)value;
3496 pci_write_config_byte(pdev, where,
3500 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3501 rc = pci_read_config_byte(pdev, where, &u8val);
3503 u8val &= (uint8_t)(~value);
3504 pci_write_config_byte(pdev, where,
3509 if (count == sizeof(uint16_t)) {
3510 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
3512 if (where % sizeof(uint16_t))
3514 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3515 pci_write_config_word(pdev, where,
3517 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3518 rc = pci_read_config_word(pdev, where, &u16val);
3520 u16val |= (uint16_t)value;
3521 pci_write_config_word(pdev, where,
3525 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3526 rc = pci_read_config_word(pdev, where, &u16val);
3528 u16val &= (uint16_t)(~value);
3529 pci_write_config_word(pdev, where,
3534 if (count == sizeof(uint32_t)) {
3535 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
3537 if (where % sizeof(uint32_t))
3539 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3540 pci_write_config_dword(pdev, where, value);
3541 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3542 rc = pci_read_config_dword(pdev, where,
3546 pci_write_config_dword(pdev, where,
3550 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3551 rc = pci_read_config_dword(pdev, where,
3555 pci_write_config_dword(pdev, where,
3561 /* All other opecodes are illegal for now */
3566 memset(&idiag, 0, sizeof(idiag));
3571 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
3572 * @file: The file pointer to read from.
3573 * @buf: The buffer to copy the data to.
3574 * @nbytes: The number of bytes to read.
3575 * @ppos: The position in the file to start reading from.
3578 * This routine reads data from the @phba pci bar memory mapped space
3579 * according to the idiag command, and copies to user @buf.
3582 * This function returns the amount of data that was read (this could be less
3583 * than @nbytes if the end of the file was reached) or a negative error value.
3586 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
3589 struct lpfc_debug *debug = file->private_data;
3590 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3591 int offset_label, offset, offset_run, len = 0, index;
3592 int bar_num, acc_range, bar_size;
3594 void __iomem *mem_mapped_bar;
3596 struct pci_dev *pdev;
3599 pdev = phba->pcidev;
3603 /* This is a user read operation */
3604 debug->op = LPFC_IDIAG_OP_RD;
3607 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
3610 pbuffer = debug->buffer;
3615 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3616 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3617 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3618 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3619 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3626 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3627 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3628 if (bar_num == IDIAG_BARACC_BAR_0)
3629 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3630 else if (bar_num == IDIAG_BARACC_BAR_1)
3631 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3632 else if (bar_num == IDIAG_BARACC_BAR_2)
3633 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3636 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3637 if (bar_num == IDIAG_BARACC_BAR_0)
3638 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3644 /* Read single PCI bar space register */
3645 if (acc_range == SINGLE_WORD) {
3646 offset_run = offset;
3647 u32val = readl(mem_mapped_bar + offset_run);
3648 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
3649 "%05x: %08x\n", offset_run, u32val);
3653 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3657 /* Browse all PCI bar space registers */
3658 offset_label = idiag.offset.last_rd;
3659 offset_run = offset_label;
3661 /* Read PCI bar memory mapped space */
3662 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
3663 "%05x: ", offset_label);
3664 index = LPFC_PCI_BAR_RD_SIZE;
3666 u32val = readl(mem_mapped_bar + offset_run);
3667 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
3669 offset_run += sizeof(uint32_t);
3670 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3671 if (offset_run >= bar_size) {
3672 len += scnprintf(pbuffer+len,
3673 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3677 if (offset_run >= offset +
3678 (acc_range * sizeof(uint32_t))) {
3679 len += scnprintf(pbuffer+len,
3680 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3684 index -= sizeof(uint32_t);
3686 len += scnprintf(pbuffer+len,
3687 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3688 else if (!(index % (8 * sizeof(uint32_t)))) {
3689 offset_label += (8 * sizeof(uint32_t));
3690 len += scnprintf(pbuffer+len,
3691 LPFC_PCI_BAR_RD_BUF_SIZE-len,
3692 "\n%05x: ", offset_label);
3696 /* Set up the offset for next portion of pci bar read */
3698 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
3699 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3700 if (idiag.offset.last_rd >= bar_size)
3701 idiag.offset.last_rd = 0;
3703 if (offset_run >= offset +
3704 (acc_range * sizeof(uint32_t)))
3705 idiag.offset.last_rd = offset;
3708 if (acc_range == LPFC_PCI_BAR_BROWSE)
3709 idiag.offset.last_rd = 0;
3711 idiag.offset.last_rd = offset;
3714 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3718 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
3719 * @file: The file pointer to read from.
3720 * @buf: The buffer to copy the user data from.
3721 * @nbytes: The number of bytes to get.
3722 * @ppos: The position in the file to start reading from.
3724 * This routine get the debugfs idiag command struct from user space and
3725 * then perform the syntax check for PCI bar memory mapped space read or
3726 * write command accordingly. In the case of PCI bar memory mapped space
3727 * read command, it sets up the command in the idiag command struct for
3728 * the debugfs read operation. In the case of PCI bar memorpy mapped space
3729 * write operation, it executes the write operation into the PCI bar memory
3730 * mapped space accordingly.
3732 * It returns the @nbytges passing in from debugfs user space when successful.
3733 * In case of error conditions, it returns proper error code back to the user
3737 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
3738 size_t nbytes, loff_t *ppos)
3740 struct lpfc_debug *debug = file->private_data;
3741 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3742 uint32_t bar_num, bar_size, offset, value, acc_range;
3743 struct pci_dev *pdev;
3744 void __iomem *mem_mapped_bar;
3749 pdev = phba->pcidev;
3753 /* This is a user write operation */
3754 debug->op = LPFC_IDIAG_OP_WR;
3756 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3760 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3761 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3763 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3764 if ((bar_num != IDIAG_BARACC_BAR_0) &&
3765 (bar_num != IDIAG_BARACC_BAR_1) &&
3766 (bar_num != IDIAG_BARACC_BAR_2))
3768 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3769 if (bar_num != IDIAG_BARACC_BAR_0)
3774 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3775 if (bar_num == IDIAG_BARACC_BAR_0) {
3776 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3777 LPFC_PCI_IF0_BAR0_SIZE;
3778 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3779 } else if (bar_num == IDIAG_BARACC_BAR_1) {
3780 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3781 LPFC_PCI_IF0_BAR1_SIZE;
3782 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3783 } else if (bar_num == IDIAG_BARACC_BAR_2) {
3784 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3785 LPFC_PCI_IF0_BAR2_SIZE;
3786 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3789 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3790 if (bar_num == IDIAG_BARACC_BAR_0) {
3791 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3792 LPFC_PCI_IF2_BAR0_SIZE;
3793 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3799 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3800 if (offset % sizeof(uint32_t))
3803 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3804 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3805 /* Sanity check on PCI config read command line arguments */
3806 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3808 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3809 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3810 if (offset > bar_size - sizeof(uint32_t))
3812 /* Starting offset to browse */
3813 idiag.offset.last_rd = offset;
3814 } else if (acc_range > SINGLE_WORD) {
3815 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3817 /* Starting offset to browse */
3818 idiag.offset.last_rd = offset;
3819 } else if (acc_range != SINGLE_WORD)
3821 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3822 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3823 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3824 /* Sanity check on PCI bar write command line arguments */
3825 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3827 /* Write command to PCI bar space, read-modify-write */
3828 acc_range = SINGLE_WORD;
3829 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3830 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3831 writel(value, mem_mapped_bar + offset);
3832 readl(mem_mapped_bar + offset);
3834 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3835 u32val = readl(mem_mapped_bar + offset);
3837 writel(u32val, mem_mapped_bar + offset);
3838 readl(mem_mapped_bar + offset);
3840 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3841 u32val = readl(mem_mapped_bar + offset);
3843 writel(u32val, mem_mapped_bar + offset);
3844 readl(mem_mapped_bar + offset);
3847 /* All other opecodes are illegal for now */
3852 memset(&idiag, 0, sizeof(idiag));
3857 __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3858 char *pbuffer, int len)
3863 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3864 "\t\t%s WQ info: ", wqtype);
3865 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3866 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3867 qp->assoc_qid, qp->q_cnt_1,
3868 (unsigned long long)qp->q_cnt_4);
3869 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3870 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3871 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]",
3872 qp->queue_id, qp->entry_count,
3873 qp->entry_size, qp->host_index,
3874 qp->hba_index, qp->notify_interval);
3875 len += scnprintf(pbuffer + len,
3876 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3881 lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3882 int *len, int max_cnt, int cq_id)
3884 struct lpfc_queue *qp;
3887 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
3888 qp = phba->sli4_hba.hdwq[qidx].io_wq;
3889 if (qp->assoc_qid != cq_id)
3891 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3892 if (*len >= max_cnt)
3899 __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3900 char *pbuffer, int len)
3905 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3906 "\t%s CQ info: ", cqtype);
3907 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3908 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3909 "xabt:x%x wq:x%llx]\n",
3910 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3911 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3912 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3913 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3914 "HST-IDX[%04d], NTFI[%03d], PLMT[%03d]",
3915 qp->queue_id, qp->entry_count,
3916 qp->entry_size, qp->host_index,
3917 qp->notify_interval, qp->max_proc_limit);
3919 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3926 __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3927 char *rqtype, char *pbuffer, int len)
3932 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3933 "\t\t%s RQ info: ", rqtype);
3934 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3935 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
3936 "posted:x%x rcv:x%llx]\n",
3937 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3938 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3939 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3940 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3941 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
3942 qp->queue_id, qp->entry_count, qp->entry_size,
3943 qp->host_index, qp->hba_index, qp->notify_interval);
3944 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3945 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3946 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
3947 datqp->queue_id, datqp->entry_count,
3948 datqp->entry_size, datqp->host_index,
3949 datqp->hba_index, datqp->notify_interval);
3954 lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
3955 int *len, int max_cnt, int eqidx, int eq_id)
3957 struct lpfc_queue *qp;
3960 qp = phba->sli4_hba.hdwq[eqidx].io_cq;
3962 *len = __lpfc_idiag_print_cq(qp, "IO", pbuffer, *len);
3964 /* Reset max counter */
3967 if (*len >= max_cnt)
3970 rc = lpfc_idiag_wqs_for_cq(phba, "IO", pbuffer, len,
3971 max_cnt, qp->queue_id);
3975 if ((eqidx < phba->cfg_nvmet_mrq) && phba->nvmet_support) {
3977 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3978 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3980 /* Reset max counter */
3983 if (*len >= max_cnt)
3987 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3988 *len = __lpfc_idiag_print_rqpair(qp,
3989 phba->sli4_hba.nvmet_mrq_data[eqidx],
3990 "NVMET MRQ", pbuffer, *len);
3992 if (*len >= max_cnt)
4000 __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
4001 char *pbuffer, int len)
4006 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
4007 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
4008 "cqe_proc:x%x eqe_proc:x%llx eqd %d]\n",
4009 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
4010 (unsigned long long)qp->q_cnt_4, qp->q_mode);
4011 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
4012 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
4013 "HST-IDX[%04d], NTFI[%03d], PLMT[%03d], AFFIN[%03d]",
4014 qp->queue_id, qp->entry_count, qp->entry_size,
4015 qp->host_index, qp->notify_interval,
4016 qp->max_proc_limit, qp->chann);
4017 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
4024 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
4025 * @file: The file pointer to read from.
4026 * @buf: The buffer to copy the data to.
4027 * @nbytes: The number of bytes to read.
4028 * @ppos: The position in the file to start reading from.
4031 * This routine reads data from the @phba SLI4 PCI function queue information,
4032 * and copies to user @buf.
4033 * This routine only returns 1 EQs worth of information. It remembers the last
4034 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
4035 * retrieve all EQs allocated for the phba.
4038 * This function returns the amount of data that was read (this could be less
4039 * than @nbytes if the end of the file was reached) or a negative error value.
4042 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
4045 struct lpfc_debug *debug = file->private_data;
4046 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4048 int max_cnt, rc, x, len = 0;
4049 struct lpfc_queue *qp = NULL;
4052 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
4055 pbuffer = debug->buffer;
4056 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
4061 spin_lock_irq(&phba->hbalock);
4063 /* Fast-path event queue */
4064 if (phba->sli4_hba.hdwq && phba->cfg_hdw_queue) {
4066 x = phba->lpfc_idiag_last_eq;
4067 phba->lpfc_idiag_last_eq++;
4068 if (phba->lpfc_idiag_last_eq >= phba->cfg_hdw_queue)
4069 phba->lpfc_idiag_last_eq = 0;
4071 len += scnprintf(pbuffer + len,
4072 LPFC_QUE_INFO_GET_BUF_SIZE - len,
4073 "HDWQ %d out of %d HBA HDWQs\n",
4074 x, phba->cfg_hdw_queue);
4077 qp = phba->sli4_hba.hdwq[x].hba_eq;
4081 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
4083 /* Reset max counter */
4089 /* will dump both fcp and nvme cqs/wqs for the eq */
4090 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
4091 max_cnt, x, qp->queue_id);
4095 /* Only EQ 0 has slow path CQs configured */
4099 /* Slow-path mailbox CQ */
4100 qp = phba->sli4_hba.mbx_cq;
4101 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
4105 /* Slow-path MBOX MQ */
4106 qp = phba->sli4_hba.mbx_wq;
4107 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
4111 /* Slow-path ELS response CQ */
4112 qp = phba->sli4_hba.els_cq;
4113 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
4114 /* Reset max counter */
4120 /* Slow-path ELS WQ */
4121 qp = phba->sli4_hba.els_wq;
4122 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
4126 qp = phba->sli4_hba.hdr_rq;
4127 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
4128 "ELS RQpair", pbuffer, len);
4132 /* Slow-path NVME LS response CQ */
4133 qp = phba->sli4_hba.nvmels_cq;
4134 len = __lpfc_idiag_print_cq(qp, "NVME LS",
4136 /* Reset max counter */
4142 /* Slow-path NVME LS WQ */
4143 qp = phba->sli4_hba.nvmels_wq;
4144 len = __lpfc_idiag_print_wq(qp, "NVME LS",
4152 spin_unlock_irq(&phba->hbalock);
4153 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4156 len += scnprintf(pbuffer + len,
4157 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
4159 spin_unlock_irq(&phba->hbalock);
4160 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4164 * lpfc_idiag_que_param_check - queue access command parameter sanity check
4165 * @q: The pointer to queue structure.
4166 * @index: The index into a queue entry.
4167 * @count: The number of queue entries to access.
4170 * The routine performs sanity check on device queue access method commands.
4173 * This function returns -EINVAL when fails the sanity check, otherwise, it
4177 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
4179 /* Only support single entry read or browsing */
4180 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
4182 if (index > q->entry_count - 1)
4188 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
4189 * @pbuffer: The pointer to buffer to copy the read data into.
4190 * @len: Length of the buffer.
4191 * @pque: The pointer to the queue to be read.
4192 * @index: The index into the queue entry.
4195 * This routine reads out a single entry from the given queue's index location
4196 * and copies it into the buffer provided.
4199 * This function returns 0 when it fails, otherwise, it returns the length of
4200 * the data read into the buffer provided.
4203 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
4209 if (!pbuffer || !pque)
4212 esize = pque->entry_size;
4213 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
4214 "QE-INDEX[%04d]:\n", index);
4217 pentry = lpfc_sli4_qe(pque, index);
4219 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
4222 offset += sizeof(uint32_t);
4223 esize -= sizeof(uint32_t);
4224 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
4225 len += scnprintf(pbuffer+len,
4226 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
4228 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
4234 * lpfc_idiag_queacc_read - idiag debugfs read port queue
4235 * @file: The file pointer to read from.
4236 * @buf: The buffer to copy the data to.
4237 * @nbytes: The number of bytes to read.
4238 * @ppos: The position in the file to start reading from.
4241 * This routine reads data from the @phba device queue memory according to the
4242 * idiag command, and copies to user @buf. Depending on the queue dump read
4243 * command setup, it does either a single queue entry read or browing through
4244 * all entries of the queue.
4247 * This function returns the amount of data that was read (this could be less
4248 * than @nbytes if the end of the file was reached) or a negative error value.
4251 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
4254 struct lpfc_debug *debug = file->private_data;
4255 uint32_t last_index, index, count;
4256 struct lpfc_queue *pque = NULL;
4260 /* This is a user read operation */
4261 debug->op = LPFC_IDIAG_OP_RD;
4264 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
4267 pbuffer = debug->buffer;
4272 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4273 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
4274 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
4275 pque = (struct lpfc_queue *)idiag.ptr_private;
4279 /* Browse the queue starting from index */
4280 if (count == LPFC_QUE_ACC_BROWSE)
4283 /* Read a single entry from the queue */
4284 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
4286 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4290 /* Browse all entries from the queue */
4291 last_index = idiag.offset.last_rd;
4294 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
4295 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
4297 if (index > pque->entry_count - 1)
4301 /* Set up the offset for next portion of pci cfg read */
4302 if (index > pque->entry_count - 1)
4304 idiag.offset.last_rd = index;
4306 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4310 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
4311 * @file: The file pointer to read from.
4312 * @buf: The buffer to copy the user data from.
4313 * @nbytes: The number of bytes to get.
4314 * @ppos: The position in the file to start reading from.
4316 * This routine get the debugfs idiag command struct from user space and then
4317 * perform the syntax check for port queue read (dump) or write (set) command
4318 * accordingly. In the case of port queue read command, it sets up the command
4319 * in the idiag command struct for the following debugfs read operation. In
4320 * the case of port queue write operation, it executes the write operation
4321 * into the port queue entry accordingly.
4323 * It returns the @nbytges passing in from debugfs user space when successful.
4324 * In case of error conditions, it returns proper error code back to the user
4328 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
4329 size_t nbytes, loff_t *ppos)
4331 struct lpfc_debug *debug = file->private_data;
4332 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4333 uint32_t qidx, quetp, queid, index, count, offset, value;
4335 struct lpfc_queue *pque, *qp;
4338 /* This is a user write operation */
4339 debug->op = LPFC_IDIAG_OP_WR;
4341 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4345 /* Get and sanity check on command feilds */
4346 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
4347 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
4348 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
4349 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
4350 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
4351 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
4353 /* Sanity check on command line arguments */
4354 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
4355 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
4356 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
4357 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
4361 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4362 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
4369 /* HBA event queue */
4370 if (phba->sli4_hba.hdwq) {
4371 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
4372 qp = phba->sli4_hba.hdwq[qidx].hba_eq;
4373 if (qp && qp->queue_id == queid) {
4375 rc = lpfc_idiag_que_param_check(qp,
4379 idiag.ptr_private = qp;
4387 /* MBX complete queue */
4388 if (phba->sli4_hba.mbx_cq &&
4389 phba->sli4_hba.mbx_cq->queue_id == queid) {
4391 rc = lpfc_idiag_que_param_check(
4392 phba->sli4_hba.mbx_cq, index, count);
4395 idiag.ptr_private = phba->sli4_hba.mbx_cq;
4398 /* ELS complete queue */
4399 if (phba->sli4_hba.els_cq &&
4400 phba->sli4_hba.els_cq->queue_id == queid) {
4402 rc = lpfc_idiag_que_param_check(
4403 phba->sli4_hba.els_cq, index, count);
4406 idiag.ptr_private = phba->sli4_hba.els_cq;
4409 /* NVME LS complete queue */
4410 if (phba->sli4_hba.nvmels_cq &&
4411 phba->sli4_hba.nvmels_cq->queue_id == queid) {
4413 rc = lpfc_idiag_que_param_check(
4414 phba->sli4_hba.nvmels_cq, index, count);
4417 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
4420 /* FCP complete queue */
4421 if (phba->sli4_hba.hdwq) {
4422 for (qidx = 0; qidx < phba->cfg_hdw_queue;
4424 qp = phba->sli4_hba.hdwq[qidx].io_cq;
4425 if (qp && qp->queue_id == queid) {
4427 rc = lpfc_idiag_que_param_check(
4431 idiag.ptr_private = qp;
4439 /* MBX work queue */
4440 if (phba->sli4_hba.mbx_wq &&
4441 phba->sli4_hba.mbx_wq->queue_id == queid) {
4443 rc = lpfc_idiag_que_param_check(
4444 phba->sli4_hba.mbx_wq, index, count);
4447 idiag.ptr_private = phba->sli4_hba.mbx_wq;
4453 /* ELS work queue */
4454 if (phba->sli4_hba.els_wq &&
4455 phba->sli4_hba.els_wq->queue_id == queid) {
4457 rc = lpfc_idiag_que_param_check(
4458 phba->sli4_hba.els_wq, index, count);
4461 idiag.ptr_private = phba->sli4_hba.els_wq;
4464 /* NVME LS work queue */
4465 if (phba->sli4_hba.nvmels_wq &&
4466 phba->sli4_hba.nvmels_wq->queue_id == queid) {
4468 rc = lpfc_idiag_que_param_check(
4469 phba->sli4_hba.nvmels_wq, index, count);
4472 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
4476 if (phba->sli4_hba.hdwq) {
4477 /* FCP/SCSI work queue */
4478 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
4479 qp = phba->sli4_hba.hdwq[qidx].io_wq;
4480 if (qp && qp->queue_id == queid) {
4482 rc = lpfc_idiag_que_param_check(
4486 idiag.ptr_private = qp;
4495 if (phba->sli4_hba.hdr_rq &&
4496 phba->sli4_hba.hdr_rq->queue_id == queid) {
4498 rc = lpfc_idiag_que_param_check(
4499 phba->sli4_hba.hdr_rq, index, count);
4502 idiag.ptr_private = phba->sli4_hba.hdr_rq;
4506 if (phba->sli4_hba.dat_rq &&
4507 phba->sli4_hba.dat_rq->queue_id == queid) {
4509 rc = lpfc_idiag_que_param_check(
4510 phba->sli4_hba.dat_rq, index, count);
4513 idiag.ptr_private = phba->sli4_hba.dat_rq;
4523 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4524 if (count == LPFC_QUE_ACC_BROWSE)
4525 idiag.offset.last_rd = index;
4528 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
4529 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
4530 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
4531 /* Additional sanity checks on write operation */
4532 pque = (struct lpfc_queue *)idiag.ptr_private;
4533 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
4535 pentry = lpfc_sli4_qe(pque, index);
4537 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
4539 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
4541 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
4547 /* Clean out command structure on command error out */
4548 memset(&idiag, 0, sizeof(idiag));
4553 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
4554 * @phba: The pointer to hba structure.
4555 * @pbuffer: The pointer to the buffer to copy the data to.
4556 * @len: The length of bytes to copied.
4557 * @drbregid: The id to doorbell registers.
4560 * This routine reads a doorbell register and copies its content to the
4561 * user buffer pointed to by @pbuffer.
4564 * This function returns the amount of data that was copied into @pbuffer.
4567 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4568 int len, uint32_t drbregid)
4576 len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE-len,
4577 "EQ-DRB-REG: 0x%08x\n",
4578 readl(phba->sli4_hba.EQDBregaddr));
4581 len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE - len,
4582 "CQ-DRB-REG: 0x%08x\n",
4583 readl(phba->sli4_hba.CQDBregaddr));
4586 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
4587 "MQ-DRB-REG: 0x%08x\n",
4588 readl(phba->sli4_hba.MQDBregaddr));
4591 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
4592 "WQ-DRB-REG: 0x%08x\n",
4593 readl(phba->sli4_hba.WQDBregaddr));
4596 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
4597 "RQ-DRB-REG: 0x%08x\n",
4598 readl(phba->sli4_hba.RQDBregaddr));
4608 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
4609 * @file: The file pointer to read from.
4610 * @buf: The buffer to copy the data to.
4611 * @nbytes: The number of bytes to read.
4612 * @ppos: The position in the file to start reading from.
4615 * This routine reads data from the @phba device doorbell register according
4616 * to the idiag command, and copies to user @buf. Depending on the doorbell
4617 * register read command setup, it does either a single doorbell register
4618 * read or dump all doorbell registers.
4621 * This function returns the amount of data that was read (this could be less
4622 * than @nbytes if the end of the file was reached) or a negative error value.
4625 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
4628 struct lpfc_debug *debug = file->private_data;
4629 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4630 uint32_t drb_reg_id, i;
4634 /* This is a user read operation */
4635 debug->op = LPFC_IDIAG_OP_RD;
4638 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
4641 pbuffer = debug->buffer;
4646 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
4647 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4651 if (drb_reg_id == LPFC_DRB_ACC_ALL)
4652 for (i = 1; i <= LPFC_DRB_MAX; i++)
4653 len = lpfc_idiag_drbacc_read_reg(phba,
4656 len = lpfc_idiag_drbacc_read_reg(phba,
4657 pbuffer, len, drb_reg_id);
4659 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4663 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
4664 * @file: The file pointer to read from.
4665 * @buf: The buffer to copy the user data from.
4666 * @nbytes: The number of bytes to get.
4667 * @ppos: The position in the file to start reading from.
4669 * This routine get the debugfs idiag command struct from user space and then
4670 * perform the syntax check for port doorbell register read (dump) or write
4671 * (set) command accordingly. In the case of port queue read command, it sets
4672 * up the command in the idiag command struct for the following debugfs read
4673 * operation. In the case of port doorbell register write operation, it
4674 * executes the write operation into the port doorbell register accordingly.
4676 * It returns the @nbytges passing in from debugfs user space when successful.
4677 * In case of error conditions, it returns proper error code back to the user
4681 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4682 size_t nbytes, loff_t *ppos)
4684 struct lpfc_debug *debug = file->private_data;
4685 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4686 uint32_t drb_reg_id, value, reg_val = 0;
4687 void __iomem *drb_reg;
4690 /* This is a user write operation */
4691 debug->op = LPFC_IDIAG_OP_WR;
4693 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4697 /* Sanity check on command line arguments */
4698 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4699 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
4701 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4702 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4703 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4704 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4706 if (drb_reg_id > LPFC_DRB_MAX)
4708 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4709 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4711 if ((drb_reg_id > LPFC_DRB_MAX) &&
4712 (drb_reg_id != LPFC_DRB_ACC_ALL))
4717 /* Perform the write access operation */
4718 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4719 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4720 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4721 switch (drb_reg_id) {
4723 drb_reg = phba->sli4_hba.EQDBregaddr;
4726 drb_reg = phba->sli4_hba.CQDBregaddr;
4729 drb_reg = phba->sli4_hba.MQDBregaddr;
4732 drb_reg = phba->sli4_hba.WQDBregaddr;
4735 drb_reg = phba->sli4_hba.RQDBregaddr;
4741 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4743 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4744 reg_val = readl(drb_reg);
4747 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4748 reg_val = readl(drb_reg);
4751 writel(reg_val, drb_reg);
4752 readl(drb_reg); /* flush */
4757 /* Clean out command structure on command error out */
4758 memset(&idiag, 0, sizeof(idiag));
4763 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4764 * @phba: The pointer to hba structure.
4765 * @pbuffer: The pointer to the buffer to copy the data to.
4766 * @len: The length of bytes to copied.
4767 * @ctlregid: The id to doorbell registers.
4770 * This routine reads a control register and copies its content to the
4771 * user buffer pointed to by @pbuffer.
4774 * This function returns the amount of data that was copied into @pbuffer.
4777 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4778 int len, uint32_t ctlregid)
4785 case LPFC_CTL_PORT_SEM:
4786 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4787 "Port SemReg: 0x%08x\n",
4788 readl(phba->sli4_hba.conf_regs_memmap_p +
4789 LPFC_CTL_PORT_SEM_OFFSET));
4791 case LPFC_CTL_PORT_STA:
4792 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4793 "Port StaReg: 0x%08x\n",
4794 readl(phba->sli4_hba.conf_regs_memmap_p +
4795 LPFC_CTL_PORT_STA_OFFSET));
4797 case LPFC_CTL_PORT_CTL:
4798 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4799 "Port CtlReg: 0x%08x\n",
4800 readl(phba->sli4_hba.conf_regs_memmap_p +
4801 LPFC_CTL_PORT_CTL_OFFSET));
4803 case LPFC_CTL_PORT_ER1:
4804 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4805 "Port Er1Reg: 0x%08x\n",
4806 readl(phba->sli4_hba.conf_regs_memmap_p +
4807 LPFC_CTL_PORT_ER1_OFFSET));
4809 case LPFC_CTL_PORT_ER2:
4810 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4811 "Port Er2Reg: 0x%08x\n",
4812 readl(phba->sli4_hba.conf_regs_memmap_p +
4813 LPFC_CTL_PORT_ER2_OFFSET));
4815 case LPFC_CTL_PDEV_CTL:
4816 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4817 "PDev CtlReg: 0x%08x\n",
4818 readl(phba->sli4_hba.conf_regs_memmap_p +
4819 LPFC_CTL_PDEV_CTL_OFFSET));
4828 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4829 * @file: The file pointer to read from.
4830 * @buf: The buffer to copy the data to.
4831 * @nbytes: The number of bytes to read.
4832 * @ppos: The position in the file to start reading from.
4835 * This routine reads data from the @phba port and device registers according
4836 * to the idiag command, and copies to user @buf.
4839 * This function returns the amount of data that was read (this could be less
4840 * than @nbytes if the end of the file was reached) or a negative error value.
4843 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4846 struct lpfc_debug *debug = file->private_data;
4847 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4848 uint32_t ctl_reg_id, i;
4852 /* This is a user read operation */
4853 debug->op = LPFC_IDIAG_OP_RD;
4856 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4859 pbuffer = debug->buffer;
4864 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4865 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4869 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4870 for (i = 1; i <= LPFC_CTL_MAX; i++)
4871 len = lpfc_idiag_ctlacc_read_reg(phba,
4874 len = lpfc_idiag_ctlacc_read_reg(phba,
4875 pbuffer, len, ctl_reg_id);
4877 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4881 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4882 * @file: The file pointer to read from.
4883 * @buf: The buffer to copy the user data from.
4884 * @nbytes: The number of bytes to get.
4885 * @ppos: The position in the file to start reading from.
4887 * This routine get the debugfs idiag command struct from user space and then
4888 * perform the syntax check for port and device control register read (dump)
4889 * or write (set) command accordingly.
4891 * It returns the @nbytges passing in from debugfs user space when successful.
4892 * In case of error conditions, it returns proper error code back to the user
4896 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4897 size_t nbytes, loff_t *ppos)
4899 struct lpfc_debug *debug = file->private_data;
4900 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4901 uint32_t ctl_reg_id, value, reg_val = 0;
4902 void __iomem *ctl_reg;
4905 /* This is a user write operation */
4906 debug->op = LPFC_IDIAG_OP_WR;
4908 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4912 /* Sanity check on command line arguments */
4913 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4914 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4916 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4917 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4918 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4919 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4921 if (ctl_reg_id > LPFC_CTL_MAX)
4923 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4924 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4926 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4927 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4932 /* Perform the write access operation */
4933 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4934 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4935 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4936 switch (ctl_reg_id) {
4937 case LPFC_CTL_PORT_SEM:
4938 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4939 LPFC_CTL_PORT_SEM_OFFSET;
4941 case LPFC_CTL_PORT_STA:
4942 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4943 LPFC_CTL_PORT_STA_OFFSET;
4945 case LPFC_CTL_PORT_CTL:
4946 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4947 LPFC_CTL_PORT_CTL_OFFSET;
4949 case LPFC_CTL_PORT_ER1:
4950 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4951 LPFC_CTL_PORT_ER1_OFFSET;
4953 case LPFC_CTL_PORT_ER2:
4954 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4955 LPFC_CTL_PORT_ER2_OFFSET;
4957 case LPFC_CTL_PDEV_CTL:
4958 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4959 LPFC_CTL_PDEV_CTL_OFFSET;
4965 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4967 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4968 reg_val = readl(ctl_reg);
4971 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4972 reg_val = readl(ctl_reg);
4975 writel(reg_val, ctl_reg);
4976 readl(ctl_reg); /* flush */
4981 /* Clean out command structure on command error out */
4982 memset(&idiag, 0, sizeof(idiag));
4987 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4988 * @phba: Pointer to HBA context object.
4989 * @pbuffer: Pointer to data buffer.
4992 * This routine gets the driver mailbox access debugfs setup information.
4995 * This function returns the amount of data that was read (this could be less
4996 * than @nbytes if the end of the file was reached) or a negative error value.
4999 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
5001 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
5004 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5005 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5006 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5007 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5009 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
5010 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
5011 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
5012 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
5013 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
5014 "mbx_word_cnt: %04d\n", mbx_word_cnt);
5015 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
5016 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
5022 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
5023 * @file: The file pointer to read from.
5024 * @buf: The buffer to copy the data to.
5025 * @nbytes: The number of bytes to read.
5026 * @ppos: The position in the file to start reading from.
5029 * This routine reads data from the @phba driver mailbox access debugfs setup
5033 * This function returns the amount of data that was read (this could be less
5034 * than @nbytes if the end of the file was reached) or a negative error value.
5037 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
5040 struct lpfc_debug *debug = file->private_data;
5041 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5045 /* This is a user read operation */
5046 debug->op = LPFC_IDIAG_OP_RD;
5049 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
5052 pbuffer = debug->buffer;
5057 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
5058 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
5061 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
5063 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
5067 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
5068 * @file: The file pointer to read from.
5069 * @buf: The buffer to copy the user data from.
5070 * @nbytes: The number of bytes to get.
5071 * @ppos: The position in the file to start reading from.
5073 * This routine get the debugfs idiag command struct from user space and then
5074 * perform the syntax check for driver mailbox command (dump) and sets up the
5075 * necessary states in the idiag command struct accordingly.
5077 * It returns the @nbytges passing in from debugfs user space when successful.
5078 * In case of error conditions, it returns proper error code back to the user
5082 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
5083 size_t nbytes, loff_t *ppos)
5085 struct lpfc_debug *debug = file->private_data;
5086 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
5089 /* This is a user write operation */
5090 debug->op = LPFC_IDIAG_OP_WR;
5092 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
5096 /* Sanity check on command line arguments */
5097 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5098 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5099 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5100 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5102 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
5103 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
5105 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
5106 (mbx_dump_map != LPFC_MBX_DMP_ALL))
5108 if (mbx_word_cnt > sizeof(MAILBOX_t))
5110 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
5111 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
5113 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
5114 (mbx_dump_map != LPFC_MBX_DMP_ALL))
5116 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
5118 if (mbx_mbox_cmd != 0x9b)
5123 if (mbx_word_cnt == 0)
5125 if (rc != LPFC_MBX_DMP_ARG)
5127 if (mbx_mbox_cmd & ~0xff)
5130 /* condition for stop mailbox dump */
5131 if (mbx_dump_cnt == 0)
5137 /* Clean out command structure on command error out */
5138 memset(&idiag, 0, sizeof(idiag));
5142 /* Clean out command structure on command error out */
5143 memset(&idiag, 0, sizeof(idiag));
5148 * lpfc_idiag_extacc_avail_get - get the available extents information
5149 * @phba: pointer to lpfc hba data structure.
5150 * @pbuffer: pointer to internal buffer.
5151 * @len: length into the internal buffer data has been copied.
5154 * This routine is to get the available extent information.
5157 * overall length of the data read into the internal buffer.
5160 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
5162 uint16_t ext_cnt = 0, ext_size = 0;
5164 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5165 "\nAvailable Extents Information:\n");
5167 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5168 "\tPort Available VPI extents: ");
5169 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
5170 &ext_cnt, &ext_size);
5171 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5172 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5174 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5175 "\tPort Available VFI extents: ");
5176 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
5177 &ext_cnt, &ext_size);
5178 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5179 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5181 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5182 "\tPort Available RPI extents: ");
5183 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
5184 &ext_cnt, &ext_size);
5185 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5186 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5188 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5189 "\tPort Available XRI extents: ");
5190 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
5191 &ext_cnt, &ext_size);
5192 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5193 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5199 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
5200 * @phba: pointer to lpfc hba data structure.
5201 * @pbuffer: pointer to internal buffer.
5202 * @len: length into the internal buffer data has been copied.
5205 * This routine is to get the allocated extent information.
5208 * overall length of the data read into the internal buffer.
5211 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
5213 uint16_t ext_cnt, ext_size;
5216 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5217 "\nAllocated Extents Information:\n");
5219 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5220 "\tHost Allocated VPI extents: ");
5221 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
5222 &ext_cnt, &ext_size);
5224 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5225 "Port %d Extent %3d, Size %3d\n",
5226 phba->brd_no, ext_cnt, ext_size);
5228 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5231 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5232 "\tHost Allocated VFI extents: ");
5233 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
5234 &ext_cnt, &ext_size);
5236 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5237 "Port %d Extent %3d, Size %3d\n",
5238 phba->brd_no, ext_cnt, ext_size);
5240 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5243 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5244 "\tHost Allocated RPI extents: ");
5245 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
5246 &ext_cnt, &ext_size);
5248 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5249 "Port %d Extent %3d, Size %3d\n",
5250 phba->brd_no, ext_cnt, ext_size);
5252 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5255 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5256 "\tHost Allocated XRI extents: ");
5257 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
5258 &ext_cnt, &ext_size);
5260 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5261 "Port %d Extent %3d, Size %3d\n",
5262 phba->brd_no, ext_cnt, ext_size);
5264 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5271 * lpfc_idiag_extacc_drivr_get - get driver extent information
5272 * @phba: pointer to lpfc hba data structure.
5273 * @pbuffer: pointer to internal buffer.
5274 * @len: length into the internal buffer data has been copied.
5277 * This routine is to get the driver extent information.
5280 * overall length of the data read into the internal buffer.
5283 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
5285 struct lpfc_rsrc_blks *rsrc_blks;
5288 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5289 "\nDriver Extents Information:\n");
5291 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5292 "\tVPI extents:\n");
5294 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
5295 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5296 "\t\tBlock %3d: Start %4d, Count %4d\n",
5297 index, rsrc_blks->rsrc_start,
5298 rsrc_blks->rsrc_size);
5301 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5302 "\tVFI extents:\n");
5304 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
5306 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5307 "\t\tBlock %3d: Start %4d, Count %4d\n",
5308 index, rsrc_blks->rsrc_start,
5309 rsrc_blks->rsrc_size);
5313 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5314 "\tRPI extents:\n");
5316 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
5318 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5319 "\t\tBlock %3d: Start %4d, Count %4d\n",
5320 index, rsrc_blks->rsrc_start,
5321 rsrc_blks->rsrc_size);
5325 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5326 "\tXRI extents:\n");
5328 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
5330 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
5331 "\t\tBlock %3d: Start %4d, Count %4d\n",
5332 index, rsrc_blks->rsrc_start,
5333 rsrc_blks->rsrc_size);
5341 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
5342 * @file: The file pointer to read from.
5343 * @buf: The buffer to copy the user data from.
5344 * @nbytes: The number of bytes to get.
5345 * @ppos: The position in the file to start reading from.
5347 * This routine get the debugfs idiag command struct from user space and then
5348 * perform the syntax check for extent information access commands and sets
5349 * up the necessary states in the idiag command struct accordingly.
5351 * It returns the @nbytges passing in from debugfs user space when successful.
5352 * In case of error conditions, it returns proper error code back to the user
5356 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
5357 size_t nbytes, loff_t *ppos)
5359 struct lpfc_debug *debug = file->private_data;
5363 /* This is a user write operation */
5364 debug->op = LPFC_IDIAG_OP_WR;
5366 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
5370 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
5372 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
5374 if (rc != LPFC_EXT_ACC_CMD_ARG)
5376 if (!(ext_map & LPFC_EXT_ACC_ALL))
5381 /* Clean out command structure on command error out */
5382 memset(&idiag, 0, sizeof(idiag));
5387 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
5388 * @file: The file pointer to read from.
5389 * @buf: The buffer to copy the data to.
5390 * @nbytes: The number of bytes to read.
5391 * @ppos: The position in the file to start reading from.
5394 * This routine reads data from the proper extent information according to
5395 * the idiag command, and copies to user @buf.
5398 * This function returns the amount of data that was read (this could be less
5399 * than @nbytes if the end of the file was reached) or a negative error value.
5402 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
5405 struct lpfc_debug *debug = file->private_data;
5406 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5411 /* This is a user read operation */
5412 debug->op = LPFC_IDIAG_OP_RD;
5415 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
5418 pbuffer = debug->buffer;
5421 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
5424 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
5425 if (ext_map & LPFC_EXT_ACC_AVAIL)
5426 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
5427 if (ext_map & LPFC_EXT_ACC_ALLOC)
5428 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
5429 if (ext_map & LPFC_EXT_ACC_DRIVR)
5430 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
5432 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
5436 lpfc_cgn_buffer_open(struct inode *inode, struct file *file)
5438 struct lpfc_debug *debug;
5441 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
5445 debug->buffer = vmalloc(LPFC_CGN_BUF_SIZE);
5446 if (!debug->buffer) {
5451 debug->i_private = inode->i_private;
5452 file->private_data = debug;
5460 lpfc_cgn_buffer_read(struct file *file, char __user *buf, size_t nbytes,
5463 struct lpfc_debug *debug = file->private_data;
5464 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5465 char *buffer = debug->buffer;
5469 if (!phba->sli4_hba.pc_sli4_params.mi_ver || !phba->cgn_i) {
5470 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5471 "Congestion Mgmt is not supported\n");
5474 ptr = (uint32_t *)phba->cgn_i->virt;
5475 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5476 "Congestion Buffer Header\n");
5477 /* Dump the first 32 bytes */
5479 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5480 "000: %08x %08x %08x %08x %08x %08x %08x %08x\n",
5481 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
5482 *(ptr + 4), *(ptr + 5), *(ptr + 6), *(ptr + 7));
5484 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5485 "Congestion Buffer Data\n");
5486 while (cnt < sizeof(struct lpfc_cgn_info)) {
5487 if (len > (LPFC_CGN_BUF_SIZE - LPFC_DEBUG_OUT_LINE_SZ)) {
5488 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5489 "Truncated . . .\n");
5492 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5493 "%03x: %08x %08x %08x %08x "
5494 "%08x %08x %08x %08x\n",
5495 cnt, *ptr, *(ptr + 1), *(ptr + 2),
5496 *(ptr + 3), *(ptr + 4), *(ptr + 5),
5497 *(ptr + 6), *(ptr + 7));
5501 if (len > (LPFC_CGN_BUF_SIZE - LPFC_DEBUG_OUT_LINE_SZ)) {
5502 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5503 "Truncated . . .\n");
5506 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5507 "Parameter Data\n");
5508 ptr = (uint32_t *)&phba->cgn_p;
5509 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5510 "%08x %08x %08x %08x\n",
5511 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3));
5513 return simple_read_from_buffer(buf, nbytes, ppos, buffer, len);
5517 lpfc_cgn_buffer_release(struct inode *inode, struct file *file)
5519 struct lpfc_debug *debug = file->private_data;
5521 vfree(debug->buffer);
5528 lpfc_rx_monitor_open(struct inode *inode, struct file *file)
5530 struct lpfc_rx_monitor_debug *debug;
5533 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
5537 debug->buffer = vmalloc(MAX_DEBUGFS_RX_INFO_SIZE);
5538 if (!debug->buffer) {
5543 debug->i_private = inode->i_private;
5544 file->private_data = debug;
5552 lpfc_rx_monitor_read(struct file *file, char __user *buf, size_t nbytes,
5555 struct lpfc_rx_monitor_debug *debug = file->private_data;
5556 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5557 char *buffer = debug->buffer;
5559 if (!phba->rx_monitor) {
5560 scnprintf(buffer, MAX_DEBUGFS_RX_INFO_SIZE,
5561 "Rx Monitor Info is empty.\n");
5563 lpfc_rx_monitor_report(phba, phba->rx_monitor, buffer,
5564 MAX_DEBUGFS_RX_INFO_SIZE,
5565 LPFC_MAX_RXMONITOR_ENTRY);
5568 return simple_read_from_buffer(buf, nbytes, ppos, buffer,
5573 lpfc_rx_monitor_release(struct inode *inode, struct file *file)
5575 struct lpfc_rx_monitor_debug *debug = file->private_data;
5577 vfree(debug->buffer);
5583 #undef lpfc_debugfs_op_disc_trc
5584 static const struct file_operations lpfc_debugfs_op_disc_trc = {
5585 .owner = THIS_MODULE,
5586 .open = lpfc_debugfs_disc_trc_open,
5587 .llseek = lpfc_debugfs_lseek,
5588 .read = lpfc_debugfs_read,
5589 .release = lpfc_debugfs_release,
5592 #undef lpfc_debugfs_op_nodelist
5593 static const struct file_operations lpfc_debugfs_op_nodelist = {
5594 .owner = THIS_MODULE,
5595 .open = lpfc_debugfs_nodelist_open,
5596 .llseek = lpfc_debugfs_lseek,
5597 .read = lpfc_debugfs_read,
5598 .release = lpfc_debugfs_release,
5601 #undef lpfc_debugfs_op_multixripools
5602 static const struct file_operations lpfc_debugfs_op_multixripools = {
5603 .owner = THIS_MODULE,
5604 .open = lpfc_debugfs_multixripools_open,
5605 .llseek = lpfc_debugfs_lseek,
5606 .read = lpfc_debugfs_read,
5607 .write = lpfc_debugfs_multixripools_write,
5608 .release = lpfc_debugfs_release,
5611 #undef lpfc_debugfs_op_hbqinfo
5612 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
5613 .owner = THIS_MODULE,
5614 .open = lpfc_debugfs_hbqinfo_open,
5615 .llseek = lpfc_debugfs_lseek,
5616 .read = lpfc_debugfs_read,
5617 .release = lpfc_debugfs_release,
5620 #ifdef LPFC_HDWQ_LOCK_STAT
5621 #undef lpfc_debugfs_op_lockstat
5622 static const struct file_operations lpfc_debugfs_op_lockstat = {
5623 .owner = THIS_MODULE,
5624 .open = lpfc_debugfs_lockstat_open,
5625 .llseek = lpfc_debugfs_lseek,
5626 .read = lpfc_debugfs_read,
5627 .write = lpfc_debugfs_lockstat_write,
5628 .release = lpfc_debugfs_release,
5632 #undef lpfc_debugfs_ras_log
5633 static const struct file_operations lpfc_debugfs_ras_log = {
5634 .owner = THIS_MODULE,
5635 .open = lpfc_debugfs_ras_log_open,
5636 .llseek = lpfc_debugfs_lseek,
5637 .read = lpfc_debugfs_read,
5638 .release = lpfc_debugfs_ras_log_release,
5641 #undef lpfc_debugfs_op_dumpHBASlim
5642 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
5643 .owner = THIS_MODULE,
5644 .open = lpfc_debugfs_dumpHBASlim_open,
5645 .llseek = lpfc_debugfs_lseek,
5646 .read = lpfc_debugfs_read,
5647 .release = lpfc_debugfs_release,
5650 #undef lpfc_debugfs_op_dumpHostSlim
5651 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
5652 .owner = THIS_MODULE,
5653 .open = lpfc_debugfs_dumpHostSlim_open,
5654 .llseek = lpfc_debugfs_lseek,
5655 .read = lpfc_debugfs_read,
5656 .release = lpfc_debugfs_release,
5659 #undef lpfc_debugfs_op_nvmestat
5660 static const struct file_operations lpfc_debugfs_op_nvmestat = {
5661 .owner = THIS_MODULE,
5662 .open = lpfc_debugfs_nvmestat_open,
5663 .llseek = lpfc_debugfs_lseek,
5664 .read = lpfc_debugfs_read,
5665 .write = lpfc_debugfs_nvmestat_write,
5666 .release = lpfc_debugfs_release,
5669 #undef lpfc_debugfs_op_scsistat
5670 static const struct file_operations lpfc_debugfs_op_scsistat = {
5671 .owner = THIS_MODULE,
5672 .open = lpfc_debugfs_scsistat_open,
5673 .llseek = lpfc_debugfs_lseek,
5674 .read = lpfc_debugfs_read,
5675 .write = lpfc_debugfs_scsistat_write,
5676 .release = lpfc_debugfs_release,
5679 #undef lpfc_debugfs_op_ioktime
5680 static const struct file_operations lpfc_debugfs_op_ioktime = {
5681 .owner = THIS_MODULE,
5682 .open = lpfc_debugfs_ioktime_open,
5683 .llseek = lpfc_debugfs_lseek,
5684 .read = lpfc_debugfs_read,
5685 .write = lpfc_debugfs_ioktime_write,
5686 .release = lpfc_debugfs_release,
5689 #undef lpfc_debugfs_op_nvmeio_trc
5690 static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
5691 .owner = THIS_MODULE,
5692 .open = lpfc_debugfs_nvmeio_trc_open,
5693 .llseek = lpfc_debugfs_lseek,
5694 .read = lpfc_debugfs_read,
5695 .write = lpfc_debugfs_nvmeio_trc_write,
5696 .release = lpfc_debugfs_release,
5699 #undef lpfc_debugfs_op_hdwqstat
5700 static const struct file_operations lpfc_debugfs_op_hdwqstat = {
5701 .owner = THIS_MODULE,
5702 .open = lpfc_debugfs_hdwqstat_open,
5703 .llseek = lpfc_debugfs_lseek,
5704 .read = lpfc_debugfs_read,
5705 .write = lpfc_debugfs_hdwqstat_write,
5706 .release = lpfc_debugfs_release,
5709 #undef lpfc_debugfs_op_dif_err
5710 static const struct file_operations lpfc_debugfs_op_dif_err = {
5711 .owner = THIS_MODULE,
5712 .open = simple_open,
5713 .llseek = lpfc_debugfs_lseek,
5714 .read = lpfc_debugfs_dif_err_read,
5715 .write = lpfc_debugfs_dif_err_write,
5716 .release = lpfc_debugfs_dif_err_release,
5719 #undef lpfc_debugfs_op_slow_ring_trc
5720 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
5721 .owner = THIS_MODULE,
5722 .open = lpfc_debugfs_slow_ring_trc_open,
5723 .llseek = lpfc_debugfs_lseek,
5724 .read = lpfc_debugfs_read,
5725 .release = lpfc_debugfs_release,
5728 static struct dentry *lpfc_debugfs_root = NULL;
5729 static atomic_t lpfc_debugfs_hba_count;
5732 * File operations for the iDiag debugfs
5734 #undef lpfc_idiag_op_pciCfg
5735 static const struct file_operations lpfc_idiag_op_pciCfg = {
5736 .owner = THIS_MODULE,
5737 .open = lpfc_idiag_open,
5738 .llseek = lpfc_debugfs_lseek,
5739 .read = lpfc_idiag_pcicfg_read,
5740 .write = lpfc_idiag_pcicfg_write,
5741 .release = lpfc_idiag_cmd_release,
5744 #undef lpfc_idiag_op_barAcc
5745 static const struct file_operations lpfc_idiag_op_barAcc = {
5746 .owner = THIS_MODULE,
5747 .open = lpfc_idiag_open,
5748 .llseek = lpfc_debugfs_lseek,
5749 .read = lpfc_idiag_baracc_read,
5750 .write = lpfc_idiag_baracc_write,
5751 .release = lpfc_idiag_cmd_release,
5754 #undef lpfc_idiag_op_queInfo
5755 static const struct file_operations lpfc_idiag_op_queInfo = {
5756 .owner = THIS_MODULE,
5757 .open = lpfc_idiag_open,
5758 .read = lpfc_idiag_queinfo_read,
5759 .release = lpfc_idiag_release,
5762 #undef lpfc_idiag_op_queAcc
5763 static const struct file_operations lpfc_idiag_op_queAcc = {
5764 .owner = THIS_MODULE,
5765 .open = lpfc_idiag_open,
5766 .llseek = lpfc_debugfs_lseek,
5767 .read = lpfc_idiag_queacc_read,
5768 .write = lpfc_idiag_queacc_write,
5769 .release = lpfc_idiag_cmd_release,
5772 #undef lpfc_idiag_op_drbAcc
5773 static const struct file_operations lpfc_idiag_op_drbAcc = {
5774 .owner = THIS_MODULE,
5775 .open = lpfc_idiag_open,
5776 .llseek = lpfc_debugfs_lseek,
5777 .read = lpfc_idiag_drbacc_read,
5778 .write = lpfc_idiag_drbacc_write,
5779 .release = lpfc_idiag_cmd_release,
5782 #undef lpfc_idiag_op_ctlAcc
5783 static const struct file_operations lpfc_idiag_op_ctlAcc = {
5784 .owner = THIS_MODULE,
5785 .open = lpfc_idiag_open,
5786 .llseek = lpfc_debugfs_lseek,
5787 .read = lpfc_idiag_ctlacc_read,
5788 .write = lpfc_idiag_ctlacc_write,
5789 .release = lpfc_idiag_cmd_release,
5792 #undef lpfc_idiag_op_mbxAcc
5793 static const struct file_operations lpfc_idiag_op_mbxAcc = {
5794 .owner = THIS_MODULE,
5795 .open = lpfc_idiag_open,
5796 .llseek = lpfc_debugfs_lseek,
5797 .read = lpfc_idiag_mbxacc_read,
5798 .write = lpfc_idiag_mbxacc_write,
5799 .release = lpfc_idiag_cmd_release,
5802 #undef lpfc_idiag_op_extAcc
5803 static const struct file_operations lpfc_idiag_op_extAcc = {
5804 .owner = THIS_MODULE,
5805 .open = lpfc_idiag_open,
5806 .llseek = lpfc_debugfs_lseek,
5807 .read = lpfc_idiag_extacc_read,
5808 .write = lpfc_idiag_extacc_write,
5809 .release = lpfc_idiag_cmd_release,
5811 #undef lpfc_cgn_buffer_op
5812 static const struct file_operations lpfc_cgn_buffer_op = {
5813 .owner = THIS_MODULE,
5814 .open = lpfc_cgn_buffer_open,
5815 .llseek = lpfc_debugfs_lseek,
5816 .read = lpfc_cgn_buffer_read,
5817 .release = lpfc_cgn_buffer_release,
5820 #undef lpfc_rx_monitor_op
5821 static const struct file_operations lpfc_rx_monitor_op = {
5822 .owner = THIS_MODULE,
5823 .open = lpfc_rx_monitor_open,
5824 .llseek = lpfc_debugfs_lseek,
5825 .read = lpfc_rx_monitor_read,
5826 .release = lpfc_rx_monitor_release,
5830 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
5831 * @phba: Pointer to HBA context object.
5832 * @dmabuf: Pointer to a DMA buffer descriptor.
5835 * This routine dump a bsg pass-through non-embedded mailbox command with
5839 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
5840 enum mbox_type mbox_tp, enum dma_type dma_tp,
5841 enum sta_type sta_tp,
5842 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
5844 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5845 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
5846 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5848 uint32_t do_dump = 0;
5852 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
5855 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5856 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5857 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5858 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5860 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
5861 (*mbx_dump_cnt == 0) ||
5862 (*mbx_word_cnt == 0))
5865 if (*mbx_mbox_cmd != 0x9B)
5868 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5869 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5870 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
5871 pr_err("\nRead mbox command (x%x), "
5872 "nemb:0x%x, extbuf_cnt:%d:\n",
5873 sta_tp, nemb_tp, ext_buf);
5876 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5877 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5878 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
5879 pr_err("\nRead mbox buffer (x%x), "
5880 "nemb:0x%x, extbuf_seq:%d:\n",
5881 sta_tp, nemb_tp, ext_buf);
5884 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5885 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5886 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
5887 pr_err("\nWrite mbox command (x%x), "
5888 "nemb:0x%x, extbuf_cnt:%d:\n",
5889 sta_tp, nemb_tp, ext_buf);
5892 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5893 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5894 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
5895 pr_err("\nWrite mbox buffer (x%x), "
5896 "nemb:0x%x, extbuf_seq:%d:\n",
5897 sta_tp, nemb_tp, ext_buf);
5901 /* dump buffer content */
5903 pword = (uint32_t *)dmabuf->virt;
5904 for (i = 0; i < *mbx_word_cnt; i++) {
5907 pr_err("%s\n", line_buf);
5909 len += scnprintf(line_buf+len,
5910 LPFC_MBX_ACC_LBUF_SZ-len,
5913 len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5914 "%08x ", (uint32_t)*pword);
5918 pr_err("%s\n", line_buf);
5922 /* Clean out command structure on reaching dump count */
5923 if (*mbx_dump_cnt == 0)
5924 memset(&idiag, 0, sizeof(idiag));
5929 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5930 * @phba: Pointer to HBA context object.
5931 * @dmabuf: Pointer to a DMA buffer descriptor.
5934 * This routine dump a pass-through non-embedded mailbox command from issue
5938 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5940 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5941 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5942 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5948 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5951 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5952 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5953 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5954 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5956 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5957 (*mbx_dump_cnt == 0) ||
5958 (*mbx_word_cnt == 0))
5961 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5962 (*mbx_mbox_cmd != pmbox->mbxCommand))
5965 /* dump buffer content */
5966 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
5967 pr_err("Mailbox command:0x%x dump by word:\n",
5969 pword = (uint32_t *)pmbox;
5970 for (i = 0; i < *mbx_word_cnt; i++) {
5973 pr_err("%s\n", line_buf);
5975 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5976 len += scnprintf(line_buf+len,
5977 LPFC_MBX_ACC_LBUF_SZ-len,
5980 len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5982 ((uint32_t)*pword) & 0xffffffff);
5986 pr_err("%s\n", line_buf);
5989 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
5990 pr_err("Mailbox command:0x%x dump by byte:\n",
5992 pbyte = (uint8_t *)pmbox;
5993 for (i = 0; i < *mbx_word_cnt; i++) {
5996 pr_err("%s\n", line_buf);
5998 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5999 len += scnprintf(line_buf+len,
6000 LPFC_MBX_ACC_LBUF_SZ-len,
6003 for (j = 0; j < 4; j++) {
6004 len += scnprintf(line_buf+len,
6005 LPFC_MBX_ACC_LBUF_SZ-len,
6007 ((uint8_t)*pbyte) & 0xff);
6010 len += scnprintf(line_buf+len,
6011 LPFC_MBX_ACC_LBUF_SZ-len, " ");
6014 pr_err("%s\n", line_buf);
6019 /* Clean out command structure on reaching dump count */
6020 if (*mbx_dump_cnt == 0)
6021 memset(&idiag, 0, sizeof(idiag));
6027 * lpfc_debugfs_initialize - Initialize debugfs for a vport
6028 * @vport: The vport pointer to initialize.
6031 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
6032 * If not already created, this routine will create the lpfc directory, and
6033 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
6034 * also create each file used to access lpfc specific debugfs information.
6037 lpfc_debugfs_initialize(struct lpfc_vport *vport)
6039 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
6040 struct lpfc_hba *phba = vport->phba;
6043 bool pport_setup = false;
6045 if (!lpfc_debugfs_enable)
6048 /* Setup lpfc root directory */
6049 if (!lpfc_debugfs_root) {
6050 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
6051 atomic_set(&lpfc_debugfs_hba_count, 0);
6053 if (!lpfc_debugfs_start_time)
6054 lpfc_debugfs_start_time = jiffies;
6056 /* Setup funcX directory for specific HBA PCI function */
6057 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
6058 if (!phba->hba_debugfs_root) {
6060 phba->hba_debugfs_root =
6061 debugfs_create_dir(name, lpfc_debugfs_root);
6062 atomic_inc(&lpfc_debugfs_hba_count);
6063 atomic_set(&phba->debugfs_vport_count, 0);
6065 /* Multi-XRI pools */
6066 snprintf(name, sizeof(name), "multixripools");
6067 phba->debug_multixri_pools =
6068 debugfs_create_file(name, S_IFREG | 0644,
6069 phba->hba_debugfs_root,
6071 &lpfc_debugfs_op_multixripools);
6072 if (!phba->debug_multixri_pools) {
6073 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6074 "0527 Cannot create debugfs multixripools\n");
6078 /* Congestion Info Buffer */
6079 scnprintf(name, sizeof(name), "cgn_buffer");
6080 phba->debug_cgn_buffer =
6081 debugfs_create_file(name, S_IFREG | 0644,
6082 phba->hba_debugfs_root,
6083 phba, &lpfc_cgn_buffer_op);
6084 if (!phba->debug_cgn_buffer) {
6085 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6086 "6527 Cannot create debugfs "
6092 scnprintf(name, sizeof(name), "rx_monitor");
6093 phba->debug_rx_monitor =
6094 debugfs_create_file(name, S_IFREG | 0644,
6095 phba->hba_debugfs_root,
6096 phba, &lpfc_rx_monitor_op);
6097 if (!phba->debug_rx_monitor) {
6098 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6099 "6528 Cannot create debugfs "
6105 snprintf(name, sizeof(name), "ras_log");
6106 phba->debug_ras_log =
6107 debugfs_create_file(name, 0644,
6108 phba->hba_debugfs_root,
6109 phba, &lpfc_debugfs_ras_log);
6110 if (!phba->debug_ras_log) {
6111 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6112 "6148 Cannot create debugfs"
6118 snprintf(name, sizeof(name), "hbqinfo");
6119 phba->debug_hbqinfo =
6120 debugfs_create_file(name, S_IFREG | 0644,
6121 phba->hba_debugfs_root,
6122 phba, &lpfc_debugfs_op_hbqinfo);
6124 #ifdef LPFC_HDWQ_LOCK_STAT
6125 /* Setup lockstat */
6126 snprintf(name, sizeof(name), "lockstat");
6127 phba->debug_lockstat =
6128 debugfs_create_file(name, S_IFREG | 0644,
6129 phba->hba_debugfs_root,
6130 phba, &lpfc_debugfs_op_lockstat);
6131 if (!phba->debug_lockstat) {
6132 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6133 "4610 Can't create debugfs lockstat\n");
6138 /* Setup dumpHBASlim */
6139 if (phba->sli_rev < LPFC_SLI_REV4) {
6140 snprintf(name, sizeof(name), "dumpHBASlim");
6141 phba->debug_dumpHBASlim =
6142 debugfs_create_file(name,
6143 S_IFREG|S_IRUGO|S_IWUSR,
6144 phba->hba_debugfs_root,
6145 phba, &lpfc_debugfs_op_dumpHBASlim);
6147 phba->debug_dumpHBASlim = NULL;
6149 /* Setup dumpHostSlim */
6150 if (phba->sli_rev < LPFC_SLI_REV4) {
6151 snprintf(name, sizeof(name), "dumpHostSlim");
6152 phba->debug_dumpHostSlim =
6153 debugfs_create_file(name,
6154 S_IFREG|S_IRUGO|S_IWUSR,
6155 phba->hba_debugfs_root,
6156 phba, &lpfc_debugfs_op_dumpHostSlim);
6158 phba->debug_dumpHostSlim = NULL;
6160 /* Setup DIF Error Injections */
6161 snprintf(name, sizeof(name), "InjErrLBA");
6162 phba->debug_InjErrLBA =
6163 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6164 phba->hba_debugfs_root,
6165 phba, &lpfc_debugfs_op_dif_err);
6166 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
6168 snprintf(name, sizeof(name), "InjErrNPortID");
6169 phba->debug_InjErrNPortID =
6170 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6171 phba->hba_debugfs_root,
6172 phba, &lpfc_debugfs_op_dif_err);
6174 snprintf(name, sizeof(name), "InjErrWWPN");
6175 phba->debug_InjErrWWPN =
6176 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6177 phba->hba_debugfs_root,
6178 phba, &lpfc_debugfs_op_dif_err);
6180 snprintf(name, sizeof(name), "writeGuardInjErr");
6181 phba->debug_writeGuard =
6182 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6183 phba->hba_debugfs_root,
6184 phba, &lpfc_debugfs_op_dif_err);
6186 snprintf(name, sizeof(name), "writeAppInjErr");
6187 phba->debug_writeApp =
6188 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6189 phba->hba_debugfs_root,
6190 phba, &lpfc_debugfs_op_dif_err);
6192 snprintf(name, sizeof(name), "writeRefInjErr");
6193 phba->debug_writeRef =
6194 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6195 phba->hba_debugfs_root,
6196 phba, &lpfc_debugfs_op_dif_err);
6198 snprintf(name, sizeof(name), "readGuardInjErr");
6199 phba->debug_readGuard =
6200 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6201 phba->hba_debugfs_root,
6202 phba, &lpfc_debugfs_op_dif_err);
6204 snprintf(name, sizeof(name), "readAppInjErr");
6205 phba->debug_readApp =
6206 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6207 phba->hba_debugfs_root,
6208 phba, &lpfc_debugfs_op_dif_err);
6210 snprintf(name, sizeof(name), "readRefInjErr");
6211 phba->debug_readRef =
6212 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6213 phba->hba_debugfs_root,
6214 phba, &lpfc_debugfs_op_dif_err);
6216 /* Setup slow ring trace */
6217 if (lpfc_debugfs_max_slow_ring_trc) {
6218 num = lpfc_debugfs_max_slow_ring_trc - 1;
6219 if (num & lpfc_debugfs_max_slow_ring_trc) {
6220 /* Change to be a power of 2 */
6221 num = lpfc_debugfs_max_slow_ring_trc;
6227 lpfc_debugfs_max_slow_ring_trc = (1 << i);
6228 pr_err("lpfc_debugfs_max_disc_trc changed to "
6229 "%d\n", lpfc_debugfs_max_disc_trc);
6233 snprintf(name, sizeof(name), "slow_ring_trace");
6234 phba->debug_slow_ring_trc =
6235 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6236 phba->hba_debugfs_root,
6237 phba, &lpfc_debugfs_op_slow_ring_trc);
6238 if (!phba->slow_ring_trc) {
6239 phba->slow_ring_trc = kcalloc(
6240 lpfc_debugfs_max_slow_ring_trc,
6241 sizeof(struct lpfc_debugfs_trc),
6243 if (!phba->slow_ring_trc) {
6244 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6245 "0416 Cannot create debugfs "
6246 "slow_ring buffer\n");
6249 atomic_set(&phba->slow_ring_trc_cnt, 0);
6252 snprintf(name, sizeof(name), "nvmeio_trc");
6253 phba->debug_nvmeio_trc =
6254 debugfs_create_file(name, 0644,
6255 phba->hba_debugfs_root,
6256 phba, &lpfc_debugfs_op_nvmeio_trc);
6258 atomic_set(&phba->nvmeio_trc_cnt, 0);
6259 if (lpfc_debugfs_max_nvmeio_trc) {
6260 num = lpfc_debugfs_max_nvmeio_trc - 1;
6261 if (num & lpfc_debugfs_max_disc_trc) {
6262 /* Change to be a power of 2 */
6263 num = lpfc_debugfs_max_nvmeio_trc;
6269 lpfc_debugfs_max_nvmeio_trc = (1 << i);
6270 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6271 "0575 lpfc_debugfs_max_nvmeio_trc "
6273 lpfc_debugfs_max_nvmeio_trc);
6275 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
6277 /* Allocate trace buffer and initialize */
6278 phba->nvmeio_trc = kzalloc(
6279 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
6280 phba->nvmeio_trc_size), GFP_KERNEL);
6282 if (!phba->nvmeio_trc) {
6283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6284 "0576 Cannot create debugfs "
6285 "nvmeio_trc buffer\n");
6288 phba->nvmeio_trc_on = 1;
6289 phba->nvmeio_trc_output_idx = 0;
6290 phba->nvmeio_trc = NULL;
6293 phba->nvmeio_trc_size = 0;
6294 phba->nvmeio_trc_on = 0;
6295 phba->nvmeio_trc_output_idx = 0;
6296 phba->nvmeio_trc = NULL;
6300 snprintf(name, sizeof(name), "vport%d", vport->vpi);
6301 if (!vport->vport_debugfs_root) {
6302 vport->vport_debugfs_root =
6303 debugfs_create_dir(name, phba->hba_debugfs_root);
6304 atomic_inc(&phba->debugfs_vport_count);
6307 if (lpfc_debugfs_max_disc_trc) {
6308 num = lpfc_debugfs_max_disc_trc - 1;
6309 if (num & lpfc_debugfs_max_disc_trc) {
6310 /* Change to be a power of 2 */
6311 num = lpfc_debugfs_max_disc_trc;
6317 lpfc_debugfs_max_disc_trc = (1 << i);
6318 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
6319 lpfc_debugfs_max_disc_trc);
6323 vport->disc_trc = kzalloc(
6324 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
6327 if (!vport->disc_trc) {
6328 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6329 "0418 Cannot create debugfs disc trace "
6333 atomic_set(&vport->disc_trc_cnt, 0);
6335 snprintf(name, sizeof(name), "discovery_trace");
6336 vport->debug_disc_trc =
6337 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6338 vport->vport_debugfs_root,
6339 vport, &lpfc_debugfs_op_disc_trc);
6340 snprintf(name, sizeof(name), "nodelist");
6341 vport->debug_nodelist =
6342 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6343 vport->vport_debugfs_root,
6344 vport, &lpfc_debugfs_op_nodelist);
6346 snprintf(name, sizeof(name), "nvmestat");
6347 vport->debug_nvmestat =
6348 debugfs_create_file(name, 0644,
6349 vport->vport_debugfs_root,
6350 vport, &lpfc_debugfs_op_nvmestat);
6352 snprintf(name, sizeof(name), "scsistat");
6353 vport->debug_scsistat =
6354 debugfs_create_file(name, 0644,
6355 vport->vport_debugfs_root,
6356 vport, &lpfc_debugfs_op_scsistat);
6357 if (!vport->debug_scsistat) {
6358 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6359 "4611 Cannot create debugfs scsistat\n");
6363 snprintf(name, sizeof(name), "ioktime");
6364 vport->debug_ioktime =
6365 debugfs_create_file(name, 0644,
6366 vport->vport_debugfs_root,
6367 vport, &lpfc_debugfs_op_ioktime);
6368 if (!vport->debug_ioktime) {
6369 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6370 "0815 Cannot create debugfs ioktime\n");
6374 snprintf(name, sizeof(name), "hdwqstat");
6375 vport->debug_hdwqstat =
6376 debugfs_create_file(name, 0644,
6377 vport->vport_debugfs_root,
6378 vport, &lpfc_debugfs_op_hdwqstat);
6381 * The following section is for additional directories/files for the
6389 * iDiag debugfs root entry points for SLI4 device only
6391 if (phba->sli_rev < LPFC_SLI_REV4)
6394 snprintf(name, sizeof(name), "iDiag");
6395 if (!phba->idiag_root) {
6397 debugfs_create_dir(name, phba->hba_debugfs_root);
6398 /* Initialize iDiag data structure */
6399 memset(&idiag, 0, sizeof(idiag));
6402 /* iDiag read PCI config space */
6403 snprintf(name, sizeof(name), "pciCfg");
6404 if (!phba->idiag_pci_cfg) {
6405 phba->idiag_pci_cfg =
6406 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6407 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
6408 idiag.offset.last_rd = 0;
6411 /* iDiag PCI BAR access */
6412 snprintf(name, sizeof(name), "barAcc");
6413 if (!phba->idiag_bar_acc) {
6414 phba->idiag_bar_acc =
6415 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6416 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
6417 idiag.offset.last_rd = 0;
6420 /* iDiag get PCI function queue information */
6421 snprintf(name, sizeof(name), "queInfo");
6422 if (!phba->idiag_que_info) {
6423 phba->idiag_que_info =
6424 debugfs_create_file(name, S_IFREG|S_IRUGO,
6425 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
6428 /* iDiag access PCI function queue */
6429 snprintf(name, sizeof(name), "queAcc");
6430 if (!phba->idiag_que_acc) {
6431 phba->idiag_que_acc =
6432 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6433 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
6436 /* iDiag access PCI function doorbell registers */
6437 snprintf(name, sizeof(name), "drbAcc");
6438 if (!phba->idiag_drb_acc) {
6439 phba->idiag_drb_acc =
6440 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6441 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
6444 /* iDiag access PCI function control registers */
6445 snprintf(name, sizeof(name), "ctlAcc");
6446 if (!phba->idiag_ctl_acc) {
6447 phba->idiag_ctl_acc =
6448 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6449 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
6452 /* iDiag access mbox commands */
6453 snprintf(name, sizeof(name), "mbxAcc");
6454 if (!phba->idiag_mbx_acc) {
6455 phba->idiag_mbx_acc =
6456 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6457 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
6460 /* iDiag extents access commands */
6461 if (phba->sli4_hba.extents_in_use) {
6462 snprintf(name, sizeof(name), "extAcc");
6463 if (!phba->idiag_ext_acc) {
6464 phba->idiag_ext_acc =
6465 debugfs_create_file(name,
6466 S_IFREG|S_IRUGO|S_IWUSR,
6467 phba->idiag_root, phba,
6468 &lpfc_idiag_op_extAcc);
6478 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
6479 * @vport: The vport pointer to remove from debugfs.
6482 * When Debugfs is configured this routine removes debugfs file system elements
6483 * that are specific to this vport. It also checks to see if there are any
6484 * users left for the debugfs directories associated with the HBA and driver. If
6485 * this is the last user of the HBA directory or driver directory then it will
6486 * remove those from the debugfs infrastructure as well.
6489 lpfc_debugfs_terminate(struct lpfc_vport *vport)
6491 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
6492 struct lpfc_hba *phba = vport->phba;
6494 kfree(vport->disc_trc);
6495 vport->disc_trc = NULL;
6497 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
6498 vport->debug_disc_trc = NULL;
6500 debugfs_remove(vport->debug_nodelist); /* nodelist */
6501 vport->debug_nodelist = NULL;
6503 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
6504 vport->debug_nvmestat = NULL;
6506 debugfs_remove(vport->debug_scsistat); /* scsistat */
6507 vport->debug_scsistat = NULL;
6509 debugfs_remove(vport->debug_ioktime); /* ioktime */
6510 vport->debug_ioktime = NULL;
6512 debugfs_remove(vport->debug_hdwqstat); /* hdwqstat */
6513 vport->debug_hdwqstat = NULL;
6515 if (vport->vport_debugfs_root) {
6516 debugfs_remove(vport->vport_debugfs_root); /* vportX */
6517 vport->vport_debugfs_root = NULL;
6518 atomic_dec(&phba->debugfs_vport_count);
6521 if (atomic_read(&phba->debugfs_vport_count) == 0) {
6523 debugfs_remove(phba->debug_multixri_pools); /* multixripools*/
6524 phba->debug_multixri_pools = NULL;
6526 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
6527 phba->debug_hbqinfo = NULL;
6529 debugfs_remove(phba->debug_cgn_buffer);
6530 phba->debug_cgn_buffer = NULL;
6532 debugfs_remove(phba->debug_rx_monitor);
6533 phba->debug_rx_monitor = NULL;
6535 debugfs_remove(phba->debug_ras_log);
6536 phba->debug_ras_log = NULL;
6538 #ifdef LPFC_HDWQ_LOCK_STAT
6539 debugfs_remove(phba->debug_lockstat); /* lockstat */
6540 phba->debug_lockstat = NULL;
6542 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
6543 phba->debug_dumpHBASlim = NULL;
6545 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
6546 phba->debug_dumpHostSlim = NULL;
6548 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
6549 phba->debug_InjErrLBA = NULL;
6551 debugfs_remove(phba->debug_InjErrNPortID);
6552 phba->debug_InjErrNPortID = NULL;
6554 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
6555 phba->debug_InjErrWWPN = NULL;
6557 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
6558 phba->debug_writeGuard = NULL;
6560 debugfs_remove(phba->debug_writeApp); /* writeApp */
6561 phba->debug_writeApp = NULL;
6563 debugfs_remove(phba->debug_writeRef); /* writeRef */
6564 phba->debug_writeRef = NULL;
6566 debugfs_remove(phba->debug_readGuard); /* readGuard */
6567 phba->debug_readGuard = NULL;
6569 debugfs_remove(phba->debug_readApp); /* readApp */
6570 phba->debug_readApp = NULL;
6572 debugfs_remove(phba->debug_readRef); /* readRef */
6573 phba->debug_readRef = NULL;
6575 kfree(phba->slow_ring_trc);
6576 phba->slow_ring_trc = NULL;
6578 /* slow_ring_trace */
6579 debugfs_remove(phba->debug_slow_ring_trc);
6580 phba->debug_slow_ring_trc = NULL;
6582 debugfs_remove(phba->debug_nvmeio_trc);
6583 phba->debug_nvmeio_trc = NULL;
6585 kfree(phba->nvmeio_trc);
6586 phba->nvmeio_trc = NULL;
6591 if (phba->sli_rev == LPFC_SLI_REV4) {
6593 debugfs_remove(phba->idiag_ext_acc);
6594 phba->idiag_ext_acc = NULL;
6597 debugfs_remove(phba->idiag_mbx_acc);
6598 phba->idiag_mbx_acc = NULL;
6601 debugfs_remove(phba->idiag_ctl_acc);
6602 phba->idiag_ctl_acc = NULL;
6605 debugfs_remove(phba->idiag_drb_acc);
6606 phba->idiag_drb_acc = NULL;
6609 debugfs_remove(phba->idiag_que_acc);
6610 phba->idiag_que_acc = NULL;
6613 debugfs_remove(phba->idiag_que_info);
6614 phba->idiag_que_info = NULL;
6617 debugfs_remove(phba->idiag_bar_acc);
6618 phba->idiag_bar_acc = NULL;
6621 debugfs_remove(phba->idiag_pci_cfg);
6622 phba->idiag_pci_cfg = NULL;
6624 /* Finally remove the iDiag debugfs root */
6625 debugfs_remove(phba->idiag_root);
6626 phba->idiag_root = NULL;
6629 if (phba->hba_debugfs_root) {
6630 debugfs_remove(phba->hba_debugfs_root); /* fnX */
6631 phba->hba_debugfs_root = NULL;
6632 atomic_dec(&lpfc_debugfs_hba_count);
6635 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
6636 debugfs_remove(lpfc_debugfs_root); /* lpfc */
6637 lpfc_debugfs_root = NULL;
6645 * Driver debug utility routines outside of debugfs. The debug utility
6646 * routines implemented here is intended to be used in the instrumented
6647 * debug driver for debugging host or port issues.
6651 * lpfc_debug_dump_all_queues - dump all the queues with a hba
6652 * @phba: Pointer to HBA context object.
6654 * This function dumps entries of all the queues asociated with the @phba.
6657 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
6662 * Dump Work Queues (WQs)
6664 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
6665 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
6666 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
6668 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
6669 lpfc_debug_dump_wq(phba, DUMP_IO, idx);
6671 lpfc_debug_dump_hdr_rq(phba);
6672 lpfc_debug_dump_dat_rq(phba);
6674 * Dump Complete Queues (CQs)
6676 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
6677 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
6678 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
6680 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
6681 lpfc_debug_dump_cq(phba, DUMP_IO, idx);
6684 * Dump Event Queues (EQs)
6686 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
6687 lpfc_debug_dump_hba_eq(phba, idx);