1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 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>
35 #include <scsi/scsi.h>
36 #include <scsi/scsi_device.h>
37 #include <scsi/scsi_host.h>
38 #include <scsi/scsi_transport_fc.h>
39 #include <scsi/fc/fc_fs.h>
41 #include <linux/nvme-fc-driver.h>
46 #include "lpfc_sli4.h"
48 #include "lpfc_disc.h"
50 #include "lpfc_scsi.h"
51 #include "lpfc_nvme.h"
52 #include "lpfc_nvmet.h"
53 #include "lpfc_logmsg.h"
54 #include "lpfc_crtn.h"
55 #include "lpfc_vport.h"
56 #include "lpfc_version.h"
57 #include "lpfc_compat.h"
58 #include "lpfc_debugfs.h"
61 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
65 * To access this interface the user should:
66 * # mount -t debugfs none /sys/kernel/debug
68 * The lpfc debugfs directory hierarchy is:
69 * /sys/kernel/debug/lpfc/fnX/vportY
70 * where X is the lpfc hba function unique_id
71 * where Y is the vport VPI on that hba
73 * Debugging services available per vport:
75 * This is an ACSII readable file that contains a trace of the last
76 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
77 * See lpfc_debugfs.h for different categories of discovery events.
78 * To enable the discovery trace, the following module parameters must be set:
79 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
80 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
81 * EACH vport. X MUST also be a power of 2.
82 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
86 * This is an ACSII readable file that contains a trace of the last
87 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
88 * To enable the slow ring trace, the following module parameters must be set:
89 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
90 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
91 * the HBA. X MUST also be a power of 2.
93 static int lpfc_debugfs_enable = 1;
94 module_param(lpfc_debugfs_enable, int, S_IRUGO);
95 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
97 /* This MUST be a power of 2 */
98 static int lpfc_debugfs_max_disc_trc;
99 module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
100 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
101 "Set debugfs discovery trace depth");
103 /* This MUST be a power of 2 */
104 static int lpfc_debugfs_max_slow_ring_trc;
105 module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
106 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
107 "Set debugfs slow ring trace depth");
109 /* This MUST be a power of 2 */
110 static int lpfc_debugfs_max_nvmeio_trc;
111 module_param(lpfc_debugfs_max_nvmeio_trc, int, 0444);
112 MODULE_PARM_DESC(lpfc_debugfs_max_nvmeio_trc,
113 "Set debugfs NVME IO trace depth");
115 static int lpfc_debugfs_mask_disc_trc;
116 module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
117 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
118 "Set debugfs discovery trace mask");
120 #include <linux/debugfs.h>
122 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
123 static unsigned long lpfc_debugfs_start_time = 0L;
126 static struct lpfc_idiag idiag;
129 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
130 * @vport: The vport to gather the log info from.
131 * @buf: The buffer to dump log into.
132 * @size: The maximum amount of data to process.
135 * This routine gathers the lpfc discovery debugfs data from the @vport and
136 * dumps it to @buf up to @size number of bytes. It will start at the next entry
137 * in the log and process the log until the end of the buffer. Then it will
138 * gather from the beginning of the log and process until the current entry.
141 * Discovery logging will be disabled while while this routine dumps the log.
144 * This routine returns the amount of bytes that were dumped into @buf and will
148 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
150 int i, index, len, enable;
152 struct lpfc_debugfs_trc *dtp;
155 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
159 enable = lpfc_debugfs_enable;
160 lpfc_debugfs_enable = 0;
163 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
164 (lpfc_debugfs_max_disc_trc - 1);
165 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
166 dtp = vport->disc_trc + i;
169 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
171 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
172 dtp->seq_cnt, ms, dtp->fmt);
173 len += snprintf(buf+len, size-len, buffer,
174 dtp->data1, dtp->data2, dtp->data3);
176 for (i = 0; i < index; i++) {
177 dtp = vport->disc_trc + i;
180 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
182 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
183 dtp->seq_cnt, ms, dtp->fmt);
184 len += snprintf(buf+len, size-len, buffer,
185 dtp->data1, dtp->data2, dtp->data3);
188 lpfc_debugfs_enable = enable;
195 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
196 * @phba: The HBA to gather the log info from.
197 * @buf: The buffer to dump log into.
198 * @size: The maximum amount of data to process.
201 * This routine gathers the lpfc slow ring debugfs data from the @phba and
202 * dumps it to @buf up to @size number of bytes. It will start at the next entry
203 * in the log and process the log until the end of the buffer. Then it will
204 * gather from the beginning of the log and process until the current entry.
207 * Slow ring logging will be disabled while while this routine dumps the log.
210 * This routine returns the amount of bytes that were dumped into @buf and will
214 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
216 int i, index, len, enable;
218 struct lpfc_debugfs_trc *dtp;
221 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
225 enable = lpfc_debugfs_enable;
226 lpfc_debugfs_enable = 0;
229 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
230 (lpfc_debugfs_max_slow_ring_trc - 1);
231 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
232 dtp = phba->slow_ring_trc + i;
235 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
237 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
238 dtp->seq_cnt, ms, dtp->fmt);
239 len += snprintf(buf+len, size-len, buffer,
240 dtp->data1, dtp->data2, dtp->data3);
242 for (i = 0; i < index; i++) {
243 dtp = phba->slow_ring_trc + i;
246 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
248 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
249 dtp->seq_cnt, ms, dtp->fmt);
250 len += snprintf(buf+len, size-len, buffer,
251 dtp->data1, dtp->data2, dtp->data3);
254 lpfc_debugfs_enable = enable;
260 static int lpfc_debugfs_last_hbq = -1;
263 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
264 * @phba: The HBA to gather host buffer info from.
265 * @buf: The buffer to dump log into.
266 * @size: The maximum amount of data to process.
269 * This routine dumps the host buffer queue info from the @phba to @buf up to
270 * @size number of bytes. A header that describes the current hbq state will be
271 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
272 * until @size bytes have been dumped or all the hbq info has been dumped.
275 * This routine will rotate through each configured HBQ each time called.
278 * This routine returns the amount of bytes that were dumped into @buf and will
282 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
285 int i, j, found, posted, low;
286 uint32_t phys, raw_index, getidx;
287 struct lpfc_hbq_init *hip;
289 struct lpfc_hbq_entry *hbqe;
290 struct lpfc_dmabuf *d_buf;
291 struct hbq_dmabuf *hbq_buf;
293 if (phba->sli_rev != 3)
296 spin_lock_irq(&phba->hbalock);
298 /* toggle between multiple hbqs, if any */
299 i = lpfc_sli_hbq_count();
301 lpfc_debugfs_last_hbq++;
302 if (lpfc_debugfs_last_hbq >= i)
303 lpfc_debugfs_last_hbq = 0;
306 lpfc_debugfs_last_hbq = 0;
308 i = lpfc_debugfs_last_hbq;
310 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
312 hbqs = &phba->hbqs[i];
314 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
317 hip = lpfc_hbq_defs[i];
318 len += snprintf(buf+len, size-len,
319 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
320 hip->hbq_index, hip->profile, hip->rn,
321 hip->buffer_count, hip->init_count, hip->add_count, posted);
323 raw_index = phba->hbq_get[i];
324 getidx = le32_to_cpu(raw_index);
325 len += snprintf(buf+len, size-len,
326 "entries:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
327 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
328 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
330 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
331 for (j=0; j<hbqs->entry_count; j++) {
332 len += snprintf(buf+len, size-len,
333 "%03d: %08x %04x %05x ", j,
334 le32_to_cpu(hbqe->bde.addrLow),
335 le32_to_cpu(hbqe->bde.tus.w),
336 le32_to_cpu(hbqe->buffer_tag));
340 /* First calculate if slot has an associated posted buffer */
341 low = hbqs->hbqPutIdx - posted;
343 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
344 len += snprintf(buf+len, size-len, "Unused\n");
349 if ((j >= hbqs->hbqPutIdx) &&
350 (j < (hbqs->entry_count+low))) {
351 len += snprintf(buf+len, size-len, "Unused\n");
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 += snprintf(buf+len, size-len,
362 "Buf%d: %p %06x\n", i,
363 hbq_buf->dbuf.virt, hbq_buf->tag);
370 len += snprintf(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_hba_slim_off;
384 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
385 * @phba: The HBA to gather SLIM info from.
386 * @buf: The buffer to dump log into.
387 * @size: The maximum amount of data to process.
390 * This routine dumps the current contents of HBA SLIM for the HBA associated
391 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
394 * This routine will only dump up to 1024 bytes of data each time called and
395 * should be called multiple times to dump the entire HBA SLIM.
398 * This routine returns the amount of bytes that were dumped into @buf and will
402 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
409 buffer = kmalloc(1024, GFP_KERNEL);
414 spin_lock_irq(&phba->hbalock);
416 len += snprintf(buf+len, size-len, "HBA SLIM\n");
417 lpfc_memcpy_from_slim(buffer,
418 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
420 ptr = (uint32_t *)&buffer[0];
421 off = lpfc_debugfs_last_hba_slim_off;
423 /* Set it up for the next time */
424 lpfc_debugfs_last_hba_slim_off += 1024;
425 if (lpfc_debugfs_last_hba_slim_off >= 4096)
426 lpfc_debugfs_last_hba_slim_off = 0;
430 len += snprintf(buf+len, size-len,
431 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
432 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
433 *(ptr+5), *(ptr+6), *(ptr+7));
435 i -= (8 * sizeof(uint32_t));
436 off += (8 * sizeof(uint32_t));
439 spin_unlock_irq(&phba->hbalock);
446 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
447 * @phba: The HBA to gather Host SLIM info from.
448 * @buf: The buffer to dump log into.
449 * @size: The maximum amount of data to process.
452 * This routine dumps the current contents of host SLIM for the host associated
453 * with @phba to @buf up to @size bytes of data. The dump will contain the
454 * Mailbox, PCB, Rings, and Registers that are located in host memory.
457 * This routine returns the amount of bytes that were dumped into @buf and will
461 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
465 uint32_t word0, word1, word2, word3;
467 struct lpfc_pgp *pgpp;
468 struct lpfc_sli *psli = &phba->sli;
469 struct lpfc_sli_ring *pring;
472 spin_lock_irq(&phba->hbalock);
474 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
475 ptr = (uint32_t *)phba->slim2p.virt;
476 i = sizeof(MAILBOX_t);
478 len += snprintf(buf+len, size-len,
479 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
480 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
481 *(ptr+5), *(ptr+6), *(ptr+7));
483 i -= (8 * sizeof(uint32_t));
484 off += (8 * sizeof(uint32_t));
487 len += snprintf(buf+len, size-len, "SLIM PCB\n");
488 ptr = (uint32_t *)phba->pcb;
491 len += snprintf(buf+len, size-len,
492 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
493 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
494 *(ptr+5), *(ptr+6), *(ptr+7));
496 i -= (8 * sizeof(uint32_t));
497 off += (8 * sizeof(uint32_t));
500 if (phba->sli_rev <= LPFC_SLI_REV3) {
501 for (i = 0; i < 4; i++) {
502 pgpp = &phba->port_gp[i];
503 pring = &psli->sli3_ring[i];
504 len += snprintf(buf+len, size-len,
505 "Ring %d: CMD GetInx:%d "
508 "RSP PutInx:%d Max:%d\n",
510 pring->sli.sli3.numCiocb,
511 pring->sli.sli3.next_cmdidx,
512 pring->sli.sli3.local_getidx,
513 pring->flag, pgpp->rspPutInx,
514 pring->sli.sli3.numRiocb);
517 word0 = readl(phba->HAregaddr);
518 word1 = readl(phba->CAregaddr);
519 word2 = readl(phba->HSregaddr);
520 word3 = readl(phba->HCregaddr);
521 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
522 "HC:%08x\n", word0, word1, word2, word3);
524 spin_unlock_irq(&phba->hbalock);
529 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
530 * @vport: The vport to gather target node info from.
531 * @buf: The buffer to dump log into.
532 * @size: The maximum amount of data to process.
535 * This routine dumps the current target node list associated with @vport to
536 * @buf up to @size bytes of data. Each node entry in the dump will contain a
537 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
540 * This routine returns the amount of bytes that were dumped into @buf and will
544 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
547 int i, iocnt, outio, cnt;
548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
549 struct lpfc_hba *phba = vport->phba;
550 struct lpfc_nodelist *ndlp;
551 unsigned char *statep;
552 struct nvme_fc_local_port *localport;
553 struct nvme_fc_remote_port *nrport = NULL;
554 struct lpfc_nvme_rport *rport;
556 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
559 len += snprintf(buf+len, size-len, "\nFCP Nodelist Entries ...\n");
560 spin_lock_irq(shost->host_lock);
561 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
564 len += snprintf(buf+len, size-len,
565 "Missing Nodelist Entries\n");
569 switch (ndlp->nlp_state) {
570 case NLP_STE_UNUSED_NODE:
573 case NLP_STE_PLOGI_ISSUE:
576 case NLP_STE_ADISC_ISSUE:
579 case NLP_STE_REG_LOGIN_ISSUE:
582 case NLP_STE_PRLI_ISSUE:
585 case NLP_STE_LOGO_ISSUE:
588 case NLP_STE_UNMAPPED_NODE:
592 case NLP_STE_MAPPED_NODE:
596 case NLP_STE_NPR_NODE:
602 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
603 statep, ndlp->nlp_DID);
604 len += snprintf(buf+len, size-len,
606 wwn_to_u64(ndlp->nlp_portname.u.wwn));
607 len += snprintf(buf+len, size-len,
609 wwn_to_u64(ndlp->nlp_nodename.u.wwn));
610 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
611 len += snprintf(buf+len, size-len, "RPI:%03d ",
614 len += snprintf(buf+len, size-len, "RPI:none ");
615 len += snprintf(buf+len, size-len, "flag:x%08x ",
618 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
619 if (ndlp->nlp_type & NLP_FC_NODE)
620 len += snprintf(buf+len, size-len, "FC_NODE ");
621 if (ndlp->nlp_type & NLP_FABRIC) {
622 len += snprintf(buf+len, size-len, "FABRIC ");
625 if (ndlp->nlp_type & NLP_FCP_TARGET)
626 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
628 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
629 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
630 if (ndlp->nlp_type & NLP_NVME_TARGET)
631 len += snprintf(buf + len,
632 size - len, "NVME_TGT sid:%d ",
634 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
635 len += snprintf(buf + len,
636 size - len, "NVME_INITIATOR ");
637 len += snprintf(buf+len, size-len, "usgmap:%x ",
639 len += snprintf(buf+len, size-len, "refcnt:%x",
640 kref_read(&ndlp->kref));
642 i = atomic_read(&ndlp->cmd_pending);
643 len += snprintf(buf + len, size - len,
644 " OutIO:x%x Qdepth x%x",
645 i, ndlp->cmd_qdepth);
648 len += snprintf(buf+len, size-len, "\n");
650 spin_unlock_irq(shost->host_lock);
652 len += snprintf(buf + len, size - len,
653 "\nOutstanding IO x%x\n", outio);
655 if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
656 len += snprintf(buf + len, size - len,
657 "\nNVME Targetport Entry ...\n");
659 /* Port state is only one of two values for now. */
660 if (phba->targetport->port_id)
661 statep = "REGISTERED";
664 len += snprintf(buf + len, size - len,
665 "TGT WWNN x%llx WWPN x%llx State %s\n",
666 wwn_to_u64(vport->fc_nodename.u.wwn),
667 wwn_to_u64(vport->fc_portname.u.wwn),
669 len += snprintf(buf + len, size - len,
670 " Targetport DID x%06x\n",
671 phba->targetport->port_id);
675 len += snprintf(buf + len, size - len,
676 "\nNVME Lport/Rport Entries ...\n");
678 localport = vport->localport;
682 spin_lock_irq(shost->host_lock);
684 /* Port state is only one of two values for now. */
685 if (localport->port_id)
690 len += snprintf(buf + len, size - len,
691 "Lport DID x%06x PortState %s\n",
692 localport->port_id, statep);
694 len += snprintf(buf + len, size - len, "\tRport List:\n");
695 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
696 /* local short-hand pointer. */
697 spin_lock(&phba->hbalock);
698 rport = lpfc_ndlp_get_nrport(ndlp);
700 nrport = rport->remoteport;
701 spin_unlock(&phba->hbalock);
705 /* Port state is only one of two values for now. */
706 switch (nrport->port_state) {
707 case FC_OBJSTATE_ONLINE:
710 case FC_OBJSTATE_UNKNOWN:
714 statep = "UNSUPPORTED";
718 /* Tab in to show lport ownership. */
719 len += snprintf(buf + len, size - len,
720 "\t%s Port ID:x%06x ",
721 statep, nrport->port_id);
722 len += snprintf(buf + len, size - len, "WWPN x%llx ",
724 len += snprintf(buf + len, size - len, "WWNN x%llx ",
727 /* An NVME rport can have multiple roles. */
728 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
729 len += snprintf(buf + len, size - len,
731 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
732 len += snprintf(buf + len, size - len,
734 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
735 len += snprintf(buf + len, size - len,
737 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
738 FC_PORT_ROLE_NVME_TARGET |
739 FC_PORT_ROLE_NVME_DISCOVERY))
740 len += snprintf(buf + len, size - len,
743 /* Terminate the string. */
744 len += snprintf(buf + len, size - len, "\n");
747 spin_unlock_irq(shost->host_lock);
753 * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
754 * @vport: The vport to gather target node info from.
755 * @buf: The buffer to dump log into.
756 * @size: The maximum amount of data to process.
759 * This routine dumps the NVME statistics associated with @vport
762 * This routine returns the amount of bytes that were dumped into @buf and will
766 lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
768 struct lpfc_hba *phba = vport->phba;
769 struct lpfc_nvmet_tgtport *tgtp;
770 struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp;
771 struct nvme_fc_local_port *localport;
772 struct lpfc_nvme_ctrl_stat *cstat;
773 struct lpfc_nvme_lport *lport;
774 uint64_t data1, data2, data3;
775 uint64_t tot, totin, totout;
779 if (phba->nvmet_support) {
780 if (!phba->targetport)
782 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
783 len += snprintf(buf + len, size - len,
784 "\nNVME Targetport Statistics\n");
786 len += snprintf(buf + len, size - len,
787 "LS: Rcv %08x Drop %08x Abort %08x\n",
788 atomic_read(&tgtp->rcv_ls_req_in),
789 atomic_read(&tgtp->rcv_ls_req_drop),
790 atomic_read(&tgtp->xmt_ls_abort));
791 if (atomic_read(&tgtp->rcv_ls_req_in) !=
792 atomic_read(&tgtp->rcv_ls_req_out)) {
793 len += snprintf(buf + len, size - len,
794 "Rcv LS: in %08x != out %08x\n",
795 atomic_read(&tgtp->rcv_ls_req_in),
796 atomic_read(&tgtp->rcv_ls_req_out));
799 len += snprintf(buf + len, size - len,
800 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
801 atomic_read(&tgtp->xmt_ls_rsp),
802 atomic_read(&tgtp->xmt_ls_drop),
803 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
805 len += snprintf(buf + len, size - len,
806 "LS: RSP Abort %08x xb %08x Err %08x\n",
807 atomic_read(&tgtp->xmt_ls_rsp_aborted),
808 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
809 atomic_read(&tgtp->xmt_ls_rsp_error));
811 len += snprintf(buf + len, size - len,
812 "FCP: Rcv %08x Defer %08x Release %08x "
814 atomic_read(&tgtp->rcv_fcp_cmd_in),
815 atomic_read(&tgtp->rcv_fcp_cmd_defer),
816 atomic_read(&tgtp->xmt_fcp_release),
817 atomic_read(&tgtp->rcv_fcp_cmd_drop));
819 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
820 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
821 len += snprintf(buf + len, size - len,
822 "Rcv FCP: in %08x != out %08x\n",
823 atomic_read(&tgtp->rcv_fcp_cmd_in),
824 atomic_read(&tgtp->rcv_fcp_cmd_out));
827 len += snprintf(buf + len, size - len,
828 "FCP Rsp: read %08x readrsp %08x "
829 "write %08x rsp %08x\n",
830 atomic_read(&tgtp->xmt_fcp_read),
831 atomic_read(&tgtp->xmt_fcp_read_rsp),
832 atomic_read(&tgtp->xmt_fcp_write),
833 atomic_read(&tgtp->xmt_fcp_rsp));
835 len += snprintf(buf + len, size - len,
836 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
837 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
838 atomic_read(&tgtp->xmt_fcp_rsp_error),
839 atomic_read(&tgtp->xmt_fcp_rsp_drop));
841 len += snprintf(buf + len, size - len,
842 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
843 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
844 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
845 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
847 len += snprintf(buf + len, size - len,
848 "ABORT: Xmt %08x Cmpl %08x\n",
849 atomic_read(&tgtp->xmt_fcp_abort),
850 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
852 len += snprintf(buf + len, size - len,
853 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
854 atomic_read(&tgtp->xmt_abort_sol),
855 atomic_read(&tgtp->xmt_abort_unsol),
856 atomic_read(&tgtp->xmt_abort_rsp),
857 atomic_read(&tgtp->xmt_abort_rsp_error));
859 len += snprintf(buf + len, size - len, "\n");
862 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
863 list_for_each_entry_safe(ctxp, next_ctxp,
864 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
868 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
870 len += snprintf(buf + len, size - len,
871 "ABORT: %d ctx entries\n", cnt);
872 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
873 list_for_each_entry_safe(ctxp, next_ctxp,
874 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
876 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
878 len += snprintf(buf + len, size - len,
879 "Entry: oxid %x state %x "
881 ctxp->oxid, ctxp->state,
884 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
887 /* Calculate outstanding IOs */
888 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
889 tot += atomic_read(&tgtp->xmt_fcp_release);
890 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
892 len += snprintf(buf + len, size - len,
893 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
894 "CTX Outstanding %08llx\n",
895 phba->sli4_hba.nvmet_xri_cnt,
896 phba->sli4_hba.nvmet_io_wait_cnt,
897 phba->sli4_hba.nvmet_io_wait_total,
900 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
903 localport = vport->localport;
906 lport = (struct lpfc_nvme_lport *)localport->private;
910 len += snprintf(buf + len, size - len,
911 "\nNVME Lport Statistics\n");
913 len += snprintf(buf + len, size - len,
914 "LS: Xmt %016x Cmpl %016x\n",
915 atomic_read(&lport->fc4NvmeLsRequests),
916 atomic_read(&lport->fc4NvmeLsCmpls));
918 if (phba->cfg_nvme_io_channel < 32)
919 maxch = phba->cfg_nvme_io_channel;
924 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
925 cstat = &lport->cstat[i];
926 tot = atomic_read(&cstat->fc4NvmeIoCmpls);
928 data1 = atomic_read(&cstat->fc4NvmeInputRequests);
929 data2 = atomic_read(&cstat->fc4NvmeOutputRequests);
930 data3 = atomic_read(&cstat->fc4NvmeControlRequests);
931 totout += (data1 + data2 + data3);
933 /* Limit to 32, debugfs display buffer limitation */
937 len += snprintf(buf + len, PAGE_SIZE - len,
938 "FCP (%d): Rd %016llx Wr %016llx "
940 i, data1, data2, data3);
941 len += snprintf(buf + len, PAGE_SIZE - len,
942 "Cmpl %016llx OutIO %016llx\n",
943 tot, ((data1 + data2 + data3) - tot));
945 len += snprintf(buf + len, PAGE_SIZE - len,
946 "Total FCP Cmpl %016llx Issue %016llx "
948 totin, totout, totout - totin);
950 len += snprintf(buf + len, size - len,
951 "LS Xmt Err: Abrt %08x Err %08x "
952 "Cmpl Err: xb %08x Err %08x\n",
953 atomic_read(&lport->xmt_ls_abort),
954 atomic_read(&lport->xmt_ls_err),
955 atomic_read(&lport->cmpl_ls_xb),
956 atomic_read(&lport->cmpl_ls_err));
958 len += snprintf(buf + len, size - len,
959 "FCP Xmt Err: noxri %06x nondlp %06x "
960 "qdepth %06x wqerr %06x err %06x Abrt %06x\n",
961 atomic_read(&lport->xmt_fcp_noxri),
962 atomic_read(&lport->xmt_fcp_bad_ndlp),
963 atomic_read(&lport->xmt_fcp_qdepth),
964 atomic_read(&lport->xmt_fcp_wqerr),
965 atomic_read(&lport->xmt_fcp_err),
966 atomic_read(&lport->xmt_fcp_abort));
968 len += snprintf(buf + len, size - len,
969 "FCP Cmpl Err: xb %08x Err %08x\n",
970 atomic_read(&lport->cmpl_fcp_xb),
971 atomic_read(&lport->cmpl_fcp_err));
980 * lpfc_debugfs_nvmektime_data - Dump target node list to a buffer
981 * @vport: The vport to gather target node info from.
982 * @buf: The buffer to dump log into.
983 * @size: The maximum amount of data to process.
986 * This routine dumps the NVME statistics associated with @vport
989 * This routine returns the amount of bytes that were dumped into @buf and will
993 lpfc_debugfs_nvmektime_data(struct lpfc_vport *vport, char *buf, int size)
995 struct lpfc_hba *phba = vport->phba;
998 if (phba->nvmet_support == 0) {
1000 len += snprintf(buf + len, PAGE_SIZE - len,
1001 "ktime %s: Total Samples: %lld\n",
1002 (phba->ktime_on ? "Enabled" : "Disabled"),
1003 phba->ktime_data_samples);
1004 if (phba->ktime_data_samples == 0)
1008 buf + len, PAGE_SIZE - len,
1009 "Segment 1: Last NVME Cmd cmpl "
1010 "done -to- Start of next NVME cnd (in driver)\n");
1012 buf + len, PAGE_SIZE - len,
1013 "avg:%08lld min:%08lld max %08lld\n",
1014 div_u64(phba->ktime_seg1_total,
1015 phba->ktime_data_samples),
1016 phba->ktime_seg1_min,
1017 phba->ktime_seg1_max);
1019 buf + len, PAGE_SIZE - len,
1020 "Segment 2: Driver start of NVME cmd "
1021 "-to- Firmware WQ doorbell\n");
1023 buf + len, PAGE_SIZE - len,
1024 "avg:%08lld min:%08lld max %08lld\n",
1025 div_u64(phba->ktime_seg2_total,
1026 phba->ktime_data_samples),
1027 phba->ktime_seg2_min,
1028 phba->ktime_seg2_max);
1030 buf + len, PAGE_SIZE - len,
1031 "Segment 3: Firmware WQ doorbell -to- "
1032 "MSI-X ISR cmpl\n");
1034 buf + len, PAGE_SIZE - len,
1035 "avg:%08lld min:%08lld max %08lld\n",
1036 div_u64(phba->ktime_seg3_total,
1037 phba->ktime_data_samples),
1038 phba->ktime_seg3_min,
1039 phba->ktime_seg3_max);
1041 buf + len, PAGE_SIZE - len,
1042 "Segment 4: MSI-X ISR cmpl -to- "
1043 "NVME cmpl done\n");
1045 buf + len, PAGE_SIZE - len,
1046 "avg:%08lld min:%08lld max %08lld\n",
1047 div_u64(phba->ktime_seg4_total,
1048 phba->ktime_data_samples),
1049 phba->ktime_seg4_min,
1050 phba->ktime_seg4_max);
1052 buf + len, PAGE_SIZE - len,
1053 "Total IO avg time: %08lld\n",
1054 div_u64(phba->ktime_seg1_total +
1055 phba->ktime_seg2_total +
1056 phba->ktime_seg3_total +
1057 phba->ktime_seg4_total,
1058 phba->ktime_data_samples));
1063 len += snprintf(buf + len, PAGE_SIZE-len,
1064 "ktime %s: Total Samples: %lld %lld\n",
1065 (phba->ktime_on ? "Enabled" : "Disabled"),
1066 phba->ktime_data_samples,
1067 phba->ktime_status_samples);
1068 if (phba->ktime_data_samples == 0)
1071 len += snprintf(buf + len, PAGE_SIZE-len,
1072 "Segment 1: MSI-X ISR Rcv cmd -to- "
1073 "cmd pass to NVME Layer\n");
1074 len += snprintf(buf + len, PAGE_SIZE-len,
1075 "avg:%08lld min:%08lld max %08lld\n",
1076 div_u64(phba->ktime_seg1_total,
1077 phba->ktime_data_samples),
1078 phba->ktime_seg1_min,
1079 phba->ktime_seg1_max);
1080 len += snprintf(buf + len, PAGE_SIZE-len,
1081 "Segment 2: cmd pass to NVME Layer- "
1082 "-to- Driver rcv cmd OP (action)\n");
1083 len += snprintf(buf + len, PAGE_SIZE-len,
1084 "avg:%08lld min:%08lld max %08lld\n",
1085 div_u64(phba->ktime_seg2_total,
1086 phba->ktime_data_samples),
1087 phba->ktime_seg2_min,
1088 phba->ktime_seg2_max);
1089 len += snprintf(buf + len, PAGE_SIZE-len,
1090 "Segment 3: Driver rcv cmd OP -to- "
1091 "Firmware WQ doorbell: cmd\n");
1092 len += snprintf(buf + len, PAGE_SIZE-len,
1093 "avg:%08lld min:%08lld max %08lld\n",
1094 div_u64(phba->ktime_seg3_total,
1095 phba->ktime_data_samples),
1096 phba->ktime_seg3_min,
1097 phba->ktime_seg3_max);
1098 len += snprintf(buf + len, PAGE_SIZE-len,
1099 "Segment 4: Firmware WQ doorbell: cmd "
1100 "-to- MSI-X ISR for cmd cmpl\n");
1101 len += snprintf(buf + len, PAGE_SIZE-len,
1102 "avg:%08lld min:%08lld max %08lld\n",
1103 div_u64(phba->ktime_seg4_total,
1104 phba->ktime_data_samples),
1105 phba->ktime_seg4_min,
1106 phba->ktime_seg4_max);
1107 len += snprintf(buf + len, PAGE_SIZE-len,
1108 "Segment 5: MSI-X ISR for cmd cmpl "
1109 "-to- NVME layer passed cmd done\n");
1110 len += snprintf(buf + len, PAGE_SIZE-len,
1111 "avg:%08lld min:%08lld max %08lld\n",
1112 div_u64(phba->ktime_seg5_total,
1113 phba->ktime_data_samples),
1114 phba->ktime_seg5_min,
1115 phba->ktime_seg5_max);
1117 if (phba->ktime_status_samples == 0) {
1118 len += snprintf(buf + len, PAGE_SIZE-len,
1119 "Total: cmd received by MSI-X ISR "
1120 "-to- cmd completed on wire\n");
1121 len += snprintf(buf + len, PAGE_SIZE-len,
1122 "avg:%08lld min:%08lld "
1124 div_u64(phba->ktime_seg10_total,
1125 phba->ktime_data_samples),
1126 phba->ktime_seg10_min,
1127 phba->ktime_seg10_max);
1131 len += snprintf(buf + len, PAGE_SIZE-len,
1132 "Segment 6: NVME layer passed cmd done "
1133 "-to- Driver rcv rsp status OP\n");
1134 len += snprintf(buf + len, PAGE_SIZE-len,
1135 "avg:%08lld min:%08lld max %08lld\n",
1136 div_u64(phba->ktime_seg6_total,
1137 phba->ktime_status_samples),
1138 phba->ktime_seg6_min,
1139 phba->ktime_seg6_max);
1140 len += snprintf(buf + len, PAGE_SIZE-len,
1141 "Segment 7: Driver rcv rsp status OP "
1142 "-to- Firmware WQ doorbell: status\n");
1143 len += snprintf(buf + len, PAGE_SIZE-len,
1144 "avg:%08lld min:%08lld max %08lld\n",
1145 div_u64(phba->ktime_seg7_total,
1146 phba->ktime_status_samples),
1147 phba->ktime_seg7_min,
1148 phba->ktime_seg7_max);
1149 len += snprintf(buf + len, PAGE_SIZE-len,
1150 "Segment 8: Firmware WQ doorbell: status"
1151 " -to- MSI-X ISR for status cmpl\n");
1152 len += snprintf(buf + len, PAGE_SIZE-len,
1153 "avg:%08lld min:%08lld max %08lld\n",
1154 div_u64(phba->ktime_seg8_total,
1155 phba->ktime_status_samples),
1156 phba->ktime_seg8_min,
1157 phba->ktime_seg8_max);
1158 len += snprintf(buf + len, PAGE_SIZE-len,
1159 "Segment 9: MSI-X ISR for status cmpl "
1160 "-to- NVME layer passed status done\n");
1161 len += snprintf(buf + len, PAGE_SIZE-len,
1162 "avg:%08lld min:%08lld max %08lld\n",
1163 div_u64(phba->ktime_seg9_total,
1164 phba->ktime_status_samples),
1165 phba->ktime_seg9_min,
1166 phba->ktime_seg9_max);
1167 len += snprintf(buf + len, PAGE_SIZE-len,
1168 "Total: cmd received by MSI-X ISR -to- "
1169 "cmd completed on wire\n");
1170 len += snprintf(buf + len, PAGE_SIZE-len,
1171 "avg:%08lld min:%08lld max %08lld\n",
1172 div_u64(phba->ktime_seg10_total,
1173 phba->ktime_status_samples),
1174 phba->ktime_seg10_min,
1175 phba->ktime_seg10_max);
1180 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1181 * @phba: The phba to gather target node info from.
1182 * @buf: The buffer to dump log into.
1183 * @size: The maximum amount of data to process.
1186 * This routine dumps the NVME IO trace associated with @phba
1189 * This routine returns the amount of bytes that were dumped into @buf and will
1193 lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1195 struct lpfc_debugfs_nvmeio_trc *dtp;
1196 int i, state, index, skip;
1199 state = phba->nvmeio_trc_on;
1201 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1202 (phba->nvmeio_trc_size - 1);
1203 skip = phba->nvmeio_trc_output_idx;
1205 len += snprintf(buf + len, size - len,
1206 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1207 (phba->nvmet_support ? "NVME" : "NVMET"),
1208 (state ? "Enabled" : "Disabled"),
1209 index, skip, phba->nvmeio_trc_size);
1211 if (!phba->nvmeio_trc || state)
1214 /* trace MUST bhe off to continue */
1216 for (i = index; i < phba->nvmeio_trc_size; i++) {
1221 dtp = phba->nvmeio_trc + i;
1222 phba->nvmeio_trc_output_idx++;
1227 len += snprintf(buf + len, size - len, dtp->fmt,
1228 dtp->data1, dtp->data2, dtp->data3);
1230 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1231 phba->nvmeio_trc_output_idx = 0;
1232 len += snprintf(buf + len, size - len,
1233 "Trace Complete\n");
1237 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1238 len += snprintf(buf + len, size - len,
1239 "Trace Continue (%d of %d)\n",
1240 phba->nvmeio_trc_output_idx,
1241 phba->nvmeio_trc_size);
1245 for (i = 0; i < index; i++) {
1250 dtp = phba->nvmeio_trc + i;
1251 phba->nvmeio_trc_output_idx++;
1256 len += snprintf(buf + len, size - len, dtp->fmt,
1257 dtp->data1, dtp->data2, dtp->data3);
1259 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1260 phba->nvmeio_trc_output_idx = 0;
1261 len += snprintf(buf + len, size - len,
1262 "Trace Complete\n");
1266 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1267 len += snprintf(buf + len, size - len,
1268 "Trace Continue (%d of %d)\n",
1269 phba->nvmeio_trc_output_idx,
1270 phba->nvmeio_trc_size);
1275 len += snprintf(buf + len, size - len,
1282 * lpfc_debugfs_cpucheck_data - Dump target node list to a buffer
1283 * @vport: The vport to gather target node info from.
1284 * @buf: The buffer to dump log into.
1285 * @size: The maximum amount of data to process.
1288 * This routine dumps the NVME statistics associated with @vport
1291 * This routine returns the amount of bytes that were dumped into @buf and will
1295 lpfc_debugfs_cpucheck_data(struct lpfc_vport *vport, char *buf, int size)
1297 struct lpfc_hba *phba = vport->phba;
1300 uint32_t tot_xmt = 0;
1301 uint32_t tot_rcv = 0;
1302 uint32_t tot_cmpl = 0;
1303 uint32_t tot_ccmpl = 0;
1305 if (phba->nvmet_support == 0) {
1306 /* NVME Initiator */
1307 len += snprintf(buf + len, PAGE_SIZE - len,
1309 (phba->cpucheck_on & LPFC_CHECK_NVME_IO ?
1310 "Enabled" : "Disabled"));
1311 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1312 if (i >= LPFC_CHECK_CPU_CNT)
1314 len += snprintf(buf + len, PAGE_SIZE - len,
1315 "%02d: xmit x%08x cmpl x%08x\n",
1316 i, phba->cpucheck_xmt_io[i],
1317 phba->cpucheck_cmpl_io[i]);
1318 tot_xmt += phba->cpucheck_xmt_io[i];
1319 tot_cmpl += phba->cpucheck_cmpl_io[i];
1321 len += snprintf(buf + len, PAGE_SIZE - len,
1322 "tot:xmit x%08x cmpl x%08x\n",
1328 len += snprintf(buf + len, PAGE_SIZE - len,
1330 (phba->cpucheck_on & LPFC_CHECK_NVMET_IO ?
1331 "IO Enabled - " : "IO Disabled - "));
1332 len += snprintf(buf + len, PAGE_SIZE - len,
1334 (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV ?
1335 "Rcv Enabled\n" : "Rcv Disabled\n"));
1336 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1337 if (i >= LPFC_CHECK_CPU_CNT)
1339 len += snprintf(buf + len, PAGE_SIZE - len,
1340 "%02d: xmit x%08x ccmpl x%08x "
1341 "cmpl x%08x rcv x%08x\n",
1342 i, phba->cpucheck_xmt_io[i],
1343 phba->cpucheck_ccmpl_io[i],
1344 phba->cpucheck_cmpl_io[i],
1345 phba->cpucheck_rcv_io[i]);
1346 tot_xmt += phba->cpucheck_xmt_io[i];
1347 tot_rcv += phba->cpucheck_rcv_io[i];
1348 tot_cmpl += phba->cpucheck_cmpl_io[i];
1349 tot_ccmpl += phba->cpucheck_ccmpl_io[i];
1351 len += snprintf(buf + len, PAGE_SIZE - len,
1352 "tot:xmit x%08x ccmpl x%08x cmpl x%08x rcv x%08x\n",
1353 tot_xmt, tot_ccmpl, tot_cmpl, tot_rcv);
1360 * lpfc_debugfs_disc_trc - Store discovery trace log
1361 * @vport: The vport to associate this trace string with for retrieval.
1362 * @mask: Log entry classification.
1363 * @fmt: Format string to be displayed when dumping the log.
1364 * @data1: 1st data parameter to be applied to @fmt.
1365 * @data2: 2nd data parameter to be applied to @fmt.
1366 * @data3: 3rd data parameter to be applied to @fmt.
1369 * This routine is used by the driver code to add a debugfs log entry to the
1370 * discovery trace buffer associated with @vport. Only entries with a @mask that
1371 * match the current debugfs discovery mask will be saved. Entries that do not
1372 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1373 * printf when displaying the log.
1376 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1377 uint32_t data1, uint32_t data2, uint32_t data3)
1379 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1380 struct lpfc_debugfs_trc *dtp;
1383 if (!(lpfc_debugfs_mask_disc_trc & mask))
1386 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1387 !vport || !vport->disc_trc)
1390 index = atomic_inc_return(&vport->disc_trc_cnt) &
1391 (lpfc_debugfs_max_disc_trc - 1);
1392 dtp = vport->disc_trc + index;
1397 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1404 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
1405 * @phba: The phba to associate this trace string with for retrieval.
1406 * @fmt: Format string to be displayed when dumping the log.
1407 * @data1: 1st data parameter to be applied to @fmt.
1408 * @data2: 2nd data parameter to be applied to @fmt.
1409 * @data3: 3rd data parameter to be applied to @fmt.
1412 * This routine is used by the driver code to add a debugfs log entry to the
1413 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1414 * @data3 are used like printf when displaying the log.
1417 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1418 uint32_t data1, uint32_t data2, uint32_t data3)
1420 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1421 struct lpfc_debugfs_trc *dtp;
1424 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1425 !phba || !phba->slow_ring_trc)
1428 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1429 (lpfc_debugfs_max_slow_ring_trc - 1);
1430 dtp = phba->slow_ring_trc + index;
1435 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1442 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1443 * @phba: The phba to associate this trace string with for retrieval.
1444 * @fmt: Format string to be displayed when dumping the log.
1445 * @data1: 1st data parameter to be applied to @fmt.
1446 * @data2: 2nd data parameter to be applied to @fmt.
1447 * @data3: 3rd data parameter to be applied to @fmt.
1450 * This routine is used by the driver code to add a debugfs log entry to the
1451 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1452 * @data3 are used like printf when displaying the log.
1455 lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1456 uint16_t data1, uint16_t data2, uint32_t data3)
1458 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1459 struct lpfc_debugfs_nvmeio_trc *dtp;
1462 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1465 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1466 (phba->nvmeio_trc_size - 1);
1467 dtp = phba->nvmeio_trc + index;
1475 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1477 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
1478 * @inode: The inode pointer that contains a vport pointer.
1479 * @file: The file pointer to attach the log output.
1482 * This routine is the entry point for the debugfs open file operation. It gets
1483 * the vport from the i_private field in @inode, allocates the necessary buffer
1484 * for the log, fills the buffer from the in-memory log for this vport, and then
1485 * returns a pointer to that log in the private_data field in @file.
1488 * This function returns zero if successful. On error it will return a negative
1492 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1494 struct lpfc_vport *vport = inode->i_private;
1495 struct lpfc_debug *debug;
1499 if (!lpfc_debugfs_max_disc_trc) {
1504 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1508 /* Round to page boundary */
1509 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1510 size = PAGE_ALIGN(size);
1512 debug->buffer = kmalloc(size, GFP_KERNEL);
1513 if (!debug->buffer) {
1518 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1519 file->private_data = debug;
1527 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
1528 * @inode: The inode pointer that contains a vport pointer.
1529 * @file: The file pointer to attach the log output.
1532 * This routine is the entry point for the debugfs open file operation. It gets
1533 * the vport from the i_private field in @inode, allocates the necessary buffer
1534 * for the log, fills the buffer from the in-memory log for this vport, and then
1535 * returns a pointer to that log in the private_data field in @file.
1538 * This function returns zero if successful. On error it will return a negative
1542 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1544 struct lpfc_hba *phba = inode->i_private;
1545 struct lpfc_debug *debug;
1549 if (!lpfc_debugfs_max_slow_ring_trc) {
1554 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1558 /* Round to page boundary */
1559 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1560 size = PAGE_ALIGN(size);
1562 debug->buffer = kmalloc(size, GFP_KERNEL);
1563 if (!debug->buffer) {
1568 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
1569 file->private_data = debug;
1577 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
1578 * @inode: The inode pointer that contains a vport pointer.
1579 * @file: The file pointer to attach the log output.
1582 * This routine is the entry point for the debugfs open file operation. It gets
1583 * the vport from the i_private field in @inode, allocates the necessary buffer
1584 * for the log, fills the buffer from the in-memory log for this vport, and then
1585 * returns a pointer to that log in the private_data field in @file.
1588 * This function returns zero if successful. On error it will return a negative
1592 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
1594 struct lpfc_hba *phba = inode->i_private;
1595 struct lpfc_debug *debug;
1598 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1602 /* Round to page boundary */
1603 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
1604 if (!debug->buffer) {
1609 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
1611 file->private_data = debug;
1619 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
1620 * @inode: The inode pointer that contains a vport pointer.
1621 * @file: The file pointer to attach the log output.
1624 * This routine is the entry point for the debugfs open file operation. It gets
1625 * the vport from the i_private field in @inode, allocates the necessary buffer
1626 * for the log, fills the buffer from the in-memory log for this vport, and then
1627 * returns a pointer to that log in the private_data field in @file.
1630 * This function returns zero if successful. On error it will return a negative
1634 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
1636 struct lpfc_hba *phba = inode->i_private;
1637 struct lpfc_debug *debug;
1640 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1644 /* Round to page boundary */
1645 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
1646 if (!debug->buffer) {
1651 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
1652 LPFC_DUMPHBASLIM_SIZE);
1653 file->private_data = debug;
1661 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
1662 * @inode: The inode pointer that contains a vport pointer.
1663 * @file: The file pointer to attach the log output.
1666 * This routine is the entry point for the debugfs open file operation. It gets
1667 * the vport from the i_private field in @inode, allocates the necessary buffer
1668 * for the log, fills the buffer from the in-memory log for this vport, and then
1669 * returns a pointer to that log in the private_data field in @file.
1672 * This function returns zero if successful. On error it will return a negative
1676 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
1678 struct lpfc_hba *phba = inode->i_private;
1679 struct lpfc_debug *debug;
1682 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1686 /* Round to page boundary */
1687 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
1688 if (!debug->buffer) {
1693 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
1694 LPFC_DUMPHOSTSLIM_SIZE);
1695 file->private_data = debug;
1703 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
1705 struct lpfc_debug *debug;
1708 if (!_dump_buf_data)
1711 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1715 /* Round to page boundary */
1716 pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
1717 __func__, _dump_buf_data);
1718 debug->buffer = _dump_buf_data;
1719 if (!debug->buffer) {
1724 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
1725 file->private_data = debug;
1733 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
1735 struct lpfc_debug *debug;
1741 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1745 /* Round to page boundary */
1746 pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n",
1747 __func__, _dump_buf_dif, file);
1748 debug->buffer = _dump_buf_dif;
1749 if (!debug->buffer) {
1754 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
1755 file->private_data = debug;
1763 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
1764 size_t nbytes, loff_t *ppos)
1767 * The Data/DIF buffers only save one failing IO
1768 * The write op is used as a reset mechanism after an IO has
1769 * already been saved to the next one can be saved
1771 spin_lock(&_dump_buf_lock);
1773 memset((void *)_dump_buf_data, 0,
1774 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
1775 memset((void *)_dump_buf_dif, 0,
1776 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
1780 spin_unlock(&_dump_buf_lock);
1786 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1787 size_t nbytes, loff_t *ppos)
1789 struct dentry *dent = file->f_path.dentry;
1790 struct lpfc_hba *phba = file->private_data;
1795 if (dent == phba->debug_writeGuard)
1796 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1797 else if (dent == phba->debug_writeApp)
1798 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
1799 else if (dent == phba->debug_writeRef)
1800 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
1801 else if (dent == phba->debug_readGuard)
1802 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1803 else if (dent == phba->debug_readApp)
1804 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
1805 else if (dent == phba->debug_readRef)
1806 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1807 else if (dent == phba->debug_InjErrNPortID)
1808 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1809 else if (dent == phba->debug_InjErrWWPN) {
1810 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1811 tmp = cpu_to_be64(tmp);
1812 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1813 } else if (dent == phba->debug_InjErrLBA) {
1814 if (phba->lpfc_injerr_lba == (sector_t)(-1))
1815 cnt = snprintf(cbuf, 32, "off\n");
1817 cnt = snprintf(cbuf, 32, "0x%llx\n",
1818 (uint64_t) phba->lpfc_injerr_lba);
1820 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1821 "0547 Unknown debugfs error injection entry\n");
1823 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1827 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1828 size_t nbytes, loff_t *ppos)
1830 struct dentry *dent = file->f_path.dentry;
1831 struct lpfc_hba *phba = file->private_data;
1836 memset(dstbuf, 0, 33);
1837 size = (nbytes < 32) ? nbytes : 32;
1838 if (copy_from_user(dstbuf, buf, size))
1841 if (dent == phba->debug_InjErrLBA) {
1842 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1843 tmp = (uint64_t)(-1);
1846 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
1849 if (dent == phba->debug_writeGuard)
1850 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1851 else if (dent == phba->debug_writeApp)
1852 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1853 else if (dent == phba->debug_writeRef)
1854 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1855 else if (dent == phba->debug_readGuard)
1856 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
1857 else if (dent == phba->debug_readApp)
1858 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1859 else if (dent == phba->debug_readRef)
1860 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1861 else if (dent == phba->debug_InjErrLBA)
1862 phba->lpfc_injerr_lba = (sector_t)tmp;
1863 else if (dent == phba->debug_InjErrNPortID)
1864 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1865 else if (dent == phba->debug_InjErrWWPN) {
1866 tmp = cpu_to_be64(tmp);
1867 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1870 "0548 Unknown debugfs error injection entry\n");
1876 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1882 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1883 * @inode: The inode pointer that contains a vport pointer.
1884 * @file: The file pointer to attach the log output.
1887 * This routine is the entry point for the debugfs open file operation. It gets
1888 * the vport from the i_private field in @inode, allocates the necessary buffer
1889 * for the log, fills the buffer from the in-memory log for this vport, and then
1890 * returns a pointer to that log in the private_data field in @file.
1893 * This function returns zero if successful. On error it will return a negative
1897 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1899 struct lpfc_vport *vport = inode->i_private;
1900 struct lpfc_debug *debug;
1903 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1907 /* Round to page boundary */
1908 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1909 if (!debug->buffer) {
1914 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1915 LPFC_NODELIST_SIZE);
1916 file->private_data = debug;
1924 * lpfc_debugfs_lseek - Seek through a debugfs file
1925 * @file: The file pointer to seek through.
1926 * @off: The offset to seek to or the amount to seek by.
1927 * @whence: Indicates how to seek.
1930 * This routine is the entry point for the debugfs lseek file operation. The
1931 * @whence parameter indicates whether @off is the offset to directly seek to,
1932 * or if it is a value to seek forward or reverse by. This function figures out
1933 * what the new offset of the debugfs file will be and assigns that value to the
1934 * f_pos field of @file.
1937 * This function returns the new offset if successful and returns a negative
1938 * error if unable to process the seek.
1941 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1943 struct lpfc_debug *debug = file->private_data;
1944 return fixed_size_llseek(file, off, whence, debug->len);
1948 * lpfc_debugfs_read - Read a debugfs file
1949 * @file: The file pointer to read from.
1950 * @buf: The buffer to copy the data to.
1951 * @nbytes: The number of bytes to read.
1952 * @ppos: The position in the file to start reading from.
1955 * This routine reads data from from the buffer indicated in the private_data
1956 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1960 * This function returns the amount of data that was read (this could be less
1961 * than @nbytes if the end of the file was reached) or a negative error value.
1964 lpfc_debugfs_read(struct file *file, char __user *buf,
1965 size_t nbytes, loff_t *ppos)
1967 struct lpfc_debug *debug = file->private_data;
1969 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1974 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1975 * @inode: The inode pointer that contains a vport pointer. (unused)
1976 * @file: The file pointer that contains the buffer to release.
1979 * This routine frees the buffer that was allocated when the debugfs file was
1983 * This function returns zero.
1986 lpfc_debugfs_release(struct inode *inode, struct file *file)
1988 struct lpfc_debug *debug = file->private_data;
1990 kfree(debug->buffer);
1997 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1999 struct lpfc_debug *debug = file->private_data;
2001 debug->buffer = NULL;
2009 lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
2011 struct lpfc_vport *vport = inode->i_private;
2012 struct lpfc_debug *debug;
2015 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2019 /* Round to page boundary */
2020 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
2021 if (!debug->buffer) {
2026 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
2027 LPFC_NVMESTAT_SIZE);
2029 debug->i_private = inode->i_private;
2030 file->private_data = debug;
2038 lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
2039 size_t nbytes, loff_t *ppos)
2041 struct lpfc_debug *debug = file->private_data;
2042 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2043 struct lpfc_hba *phba = vport->phba;
2044 struct lpfc_nvmet_tgtport *tgtp;
2048 if (!phba->targetport)
2054 memset(mybuf, 0, sizeof(mybuf));
2056 if (copy_from_user(mybuf, buf, nbytes))
2060 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2061 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2062 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2063 atomic_set(&tgtp->rcv_ls_req_in, 0);
2064 atomic_set(&tgtp->rcv_ls_req_out, 0);
2065 atomic_set(&tgtp->rcv_ls_req_drop, 0);
2066 atomic_set(&tgtp->xmt_ls_abort, 0);
2067 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
2068 atomic_set(&tgtp->xmt_ls_rsp, 0);
2069 atomic_set(&tgtp->xmt_ls_drop, 0);
2070 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
2071 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
2073 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
2074 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
2075 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
2076 atomic_set(&tgtp->xmt_fcp_drop, 0);
2077 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
2078 atomic_set(&tgtp->xmt_fcp_read, 0);
2079 atomic_set(&tgtp->xmt_fcp_write, 0);
2080 atomic_set(&tgtp->xmt_fcp_rsp, 0);
2081 atomic_set(&tgtp->xmt_fcp_release, 0);
2082 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
2083 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
2084 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
2086 atomic_set(&tgtp->xmt_fcp_abort, 0);
2087 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
2088 atomic_set(&tgtp->xmt_abort_sol, 0);
2089 atomic_set(&tgtp->xmt_abort_unsol, 0);
2090 atomic_set(&tgtp->xmt_abort_rsp, 0);
2091 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
2097 lpfc_debugfs_nvmektime_open(struct inode *inode, struct file *file)
2099 struct lpfc_vport *vport = inode->i_private;
2100 struct lpfc_debug *debug;
2103 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2107 /* Round to page boundary */
2108 debug->buffer = kmalloc(LPFC_NVMEKTIME_SIZE, GFP_KERNEL);
2109 if (!debug->buffer) {
2114 debug->len = lpfc_debugfs_nvmektime_data(vport, debug->buffer,
2115 LPFC_NVMEKTIME_SIZE);
2117 debug->i_private = inode->i_private;
2118 file->private_data = debug;
2126 lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf,
2127 size_t nbytes, loff_t *ppos)
2129 struct lpfc_debug *debug = file->private_data;
2130 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2131 struct lpfc_hba *phba = vport->phba;
2138 memset(mybuf, 0, sizeof(mybuf));
2140 if (copy_from_user(mybuf, buf, nbytes))
2144 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2145 phba->ktime_data_samples = 0;
2146 phba->ktime_status_samples = 0;
2147 phba->ktime_seg1_total = 0;
2148 phba->ktime_seg1_max = 0;
2149 phba->ktime_seg1_min = 0xffffffff;
2150 phba->ktime_seg2_total = 0;
2151 phba->ktime_seg2_max = 0;
2152 phba->ktime_seg2_min = 0xffffffff;
2153 phba->ktime_seg3_total = 0;
2154 phba->ktime_seg3_max = 0;
2155 phba->ktime_seg3_min = 0xffffffff;
2156 phba->ktime_seg4_total = 0;
2157 phba->ktime_seg4_max = 0;
2158 phba->ktime_seg4_min = 0xffffffff;
2159 phba->ktime_seg5_total = 0;
2160 phba->ktime_seg5_max = 0;
2161 phba->ktime_seg5_min = 0xffffffff;
2162 phba->ktime_seg6_total = 0;
2163 phba->ktime_seg6_max = 0;
2164 phba->ktime_seg6_min = 0xffffffff;
2165 phba->ktime_seg7_total = 0;
2166 phba->ktime_seg7_max = 0;
2167 phba->ktime_seg7_min = 0xffffffff;
2168 phba->ktime_seg8_total = 0;
2169 phba->ktime_seg8_max = 0;
2170 phba->ktime_seg8_min = 0xffffffff;
2171 phba->ktime_seg9_total = 0;
2172 phba->ktime_seg9_max = 0;
2173 phba->ktime_seg9_min = 0xffffffff;
2174 phba->ktime_seg10_total = 0;
2175 phba->ktime_seg10_max = 0;
2176 phba->ktime_seg10_min = 0xffffffff;
2179 return strlen(pbuf);
2180 } else if ((strncmp(pbuf, "off",
2181 sizeof("off") - 1) == 0)) {
2183 return strlen(pbuf);
2184 } else if ((strncmp(pbuf, "zero",
2185 sizeof("zero") - 1) == 0)) {
2186 phba->ktime_data_samples = 0;
2187 phba->ktime_status_samples = 0;
2188 phba->ktime_seg1_total = 0;
2189 phba->ktime_seg1_max = 0;
2190 phba->ktime_seg1_min = 0xffffffff;
2191 phba->ktime_seg2_total = 0;
2192 phba->ktime_seg2_max = 0;
2193 phba->ktime_seg2_min = 0xffffffff;
2194 phba->ktime_seg3_total = 0;
2195 phba->ktime_seg3_max = 0;
2196 phba->ktime_seg3_min = 0xffffffff;
2197 phba->ktime_seg4_total = 0;
2198 phba->ktime_seg4_max = 0;
2199 phba->ktime_seg4_min = 0xffffffff;
2200 phba->ktime_seg5_total = 0;
2201 phba->ktime_seg5_max = 0;
2202 phba->ktime_seg5_min = 0xffffffff;
2203 phba->ktime_seg6_total = 0;
2204 phba->ktime_seg6_max = 0;
2205 phba->ktime_seg6_min = 0xffffffff;
2206 phba->ktime_seg7_total = 0;
2207 phba->ktime_seg7_max = 0;
2208 phba->ktime_seg7_min = 0xffffffff;
2209 phba->ktime_seg8_total = 0;
2210 phba->ktime_seg8_max = 0;
2211 phba->ktime_seg8_min = 0xffffffff;
2212 phba->ktime_seg9_total = 0;
2213 phba->ktime_seg9_max = 0;
2214 phba->ktime_seg9_min = 0xffffffff;
2215 phba->ktime_seg10_total = 0;
2216 phba->ktime_seg10_max = 0;
2217 phba->ktime_seg10_min = 0xffffffff;
2218 return strlen(pbuf);
2224 lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2226 struct lpfc_hba *phba = inode->i_private;
2227 struct lpfc_debug *debug;
2230 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2234 /* Round to page boundary */
2235 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2236 if (!debug->buffer) {
2241 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2242 LPFC_NVMEIO_TRC_SIZE);
2244 debug->i_private = inode->i_private;
2245 file->private_data = debug;
2253 lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2254 size_t nbytes, loff_t *ppos)
2256 struct lpfc_debug *debug = file->private_data;
2257 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2266 memset(mybuf, 0, sizeof(mybuf));
2268 if (copy_from_user(mybuf, buf, nbytes))
2272 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2274 "0570 nvmeio_trc_off\n");
2275 phba->nvmeio_trc_output_idx = 0;
2276 phba->nvmeio_trc_on = 0;
2277 return strlen(pbuf);
2278 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2279 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2280 "0571 nvmeio_trc_on\n");
2281 phba->nvmeio_trc_output_idx = 0;
2282 phba->nvmeio_trc_on = 1;
2283 return strlen(pbuf);
2286 /* We must be off to allocate the trace buffer */
2287 if (phba->nvmeio_trc_on != 0)
2290 /* If not on or off, the parameter is the trace buffer size */
2291 i = kstrtoul(pbuf, 0, &sz);
2294 phba->nvmeio_trc_size = (uint32_t)sz;
2296 /* It must be a power of 2 - round down */
2303 if (phba->nvmeio_trc_size != sz)
2304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2305 "0572 nvmeio_trc_size changed to %ld\n",
2307 phba->nvmeio_trc_size = (uint32_t)sz;
2309 /* If one previously exists, free it */
2310 kfree(phba->nvmeio_trc);
2312 /* Allocate new trace buffer and initialize */
2313 phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
2315 if (!phba->nvmeio_trc) {
2316 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2317 "0573 Cannot create debugfs "
2318 "nvmeio_trc buffer\n");
2321 atomic_set(&phba->nvmeio_trc_cnt, 0);
2322 phba->nvmeio_trc_on = 0;
2323 phba->nvmeio_trc_output_idx = 0;
2325 return strlen(pbuf);
2329 lpfc_debugfs_cpucheck_open(struct inode *inode, struct file *file)
2331 struct lpfc_vport *vport = inode->i_private;
2332 struct lpfc_debug *debug;
2335 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2339 /* Round to page boundary */
2340 debug->buffer = kmalloc(LPFC_CPUCHECK_SIZE, GFP_KERNEL);
2341 if (!debug->buffer) {
2346 debug->len = lpfc_debugfs_cpucheck_data(vport, debug->buffer,
2347 LPFC_NVMEKTIME_SIZE);
2349 debug->i_private = inode->i_private;
2350 file->private_data = debug;
2358 lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
2359 size_t nbytes, loff_t *ppos)
2361 struct lpfc_debug *debug = file->private_data;
2362 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2363 struct lpfc_hba *phba = vport->phba;
2371 memset(mybuf, 0, sizeof(mybuf));
2373 if (copy_from_user(mybuf, buf, nbytes))
2377 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2378 if (phba->nvmet_support)
2379 phba->cpucheck_on |= LPFC_CHECK_NVMET_IO;
2381 phba->cpucheck_on |= LPFC_CHECK_NVME_IO;
2382 return strlen(pbuf);
2383 } else if ((strncmp(pbuf, "rcv",
2384 sizeof("rcv") - 1) == 0)) {
2385 if (phba->nvmet_support)
2386 phba->cpucheck_on |= LPFC_CHECK_NVMET_RCV;
2389 return strlen(pbuf);
2390 } else if ((strncmp(pbuf, "off",
2391 sizeof("off") - 1) == 0)) {
2392 phba->cpucheck_on = LPFC_CHECK_OFF;
2393 return strlen(pbuf);
2394 } else if ((strncmp(pbuf, "zero",
2395 sizeof("zero") - 1) == 0)) {
2396 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
2397 if (i >= LPFC_CHECK_CPU_CNT)
2399 phba->cpucheck_rcv_io[i] = 0;
2400 phba->cpucheck_xmt_io[i] = 0;
2401 phba->cpucheck_cmpl_io[i] = 0;
2402 phba->cpucheck_ccmpl_io[i] = 0;
2404 return strlen(pbuf);
2410 * ---------------------------------
2411 * iDiag debugfs file access methods
2412 * ---------------------------------
2414 * All access methods are through the proper SLI4 PCI function's debugfs
2417 * /sys/kernel/debug/lpfc/fn<#>/iDiag
2421 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
2422 * @buf: The pointer to the user space buffer.
2423 * @nbytes: The number of bytes in the user space buffer.
2424 * @idiag_cmd: pointer to the idiag command struct.
2426 * This routine reads data from debugfs user space buffer and parses the
2427 * buffer for getting the idiag command and arguments. The while space in
2428 * between the set of data is used as the parsing separator.
2430 * This routine returns 0 when successful, it returns proper error code
2431 * back to the user space in error conditions.
2433 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
2434 struct lpfc_idiag_cmd *idiag_cmd)
2437 char *pbuf, *step_str;
2441 memset(mybuf, 0, sizeof(mybuf));
2442 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
2443 bsize = min(nbytes, (sizeof(mybuf)-1));
2445 if (copy_from_user(mybuf, buf, bsize))
2448 step_str = strsep(&pbuf, "\t ");
2450 /* The opcode must present */
2454 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
2455 if (idiag_cmd->opcode == 0)
2458 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
2459 step_str = strsep(&pbuf, "\t ");
2462 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
2468 * lpfc_idiag_open - idiag open debugfs
2469 * @inode: The inode pointer that contains a pointer to phba.
2470 * @file: The file pointer to attach the file operation.
2473 * This routine is the entry point for the debugfs open file operation. It
2474 * gets the reference to phba from the i_private field in @inode, it then
2475 * allocates buffer for the file operation, performs the necessary PCI config
2476 * space read into the allocated buffer according to the idiag user command
2477 * setup, and then returns a pointer to buffer in the private_data field in
2481 * This function returns zero if successful. On error it will return an
2482 * negative error value.
2485 lpfc_idiag_open(struct inode *inode, struct file *file)
2487 struct lpfc_debug *debug;
2489 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2493 debug->i_private = inode->i_private;
2494 debug->buffer = NULL;
2495 file->private_data = debug;
2501 * lpfc_idiag_release - Release idiag access file operation
2502 * @inode: The inode pointer that contains a vport pointer. (unused)
2503 * @file: The file pointer that contains the buffer to release.
2506 * This routine is the generic release routine for the idiag access file
2507 * operation, it frees the buffer that was allocated when the debugfs file
2511 * This function returns zero.
2514 lpfc_idiag_release(struct inode *inode, struct file *file)
2516 struct lpfc_debug *debug = file->private_data;
2518 /* Free the buffers to the file operation */
2519 kfree(debug->buffer);
2526 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
2527 * @inode: The inode pointer that contains a vport pointer. (unused)
2528 * @file: The file pointer that contains the buffer to release.
2531 * This routine frees the buffer that was allocated when the debugfs file
2532 * was opened. It also reset the fields in the idiag command struct in the
2533 * case of command for write operation.
2536 * This function returns zero.
2539 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
2541 struct lpfc_debug *debug = file->private_data;
2543 if (debug->op == LPFC_IDIAG_OP_WR) {
2544 switch (idiag.cmd.opcode) {
2545 case LPFC_IDIAG_CMD_PCICFG_WR:
2546 case LPFC_IDIAG_CMD_PCICFG_ST:
2547 case LPFC_IDIAG_CMD_PCICFG_CL:
2548 case LPFC_IDIAG_CMD_QUEACC_WR:
2549 case LPFC_IDIAG_CMD_QUEACC_ST:
2550 case LPFC_IDIAG_CMD_QUEACC_CL:
2551 memset(&idiag, 0, sizeof(idiag));
2558 /* Free the buffers to the file operation */
2559 kfree(debug->buffer);
2566 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
2567 * @file: The file pointer to read from.
2568 * @buf: The buffer to copy the data to.
2569 * @nbytes: The number of bytes to read.
2570 * @ppos: The position in the file to start reading from.
2573 * This routine reads data from the @phba pci config space according to the
2574 * idiag command, and copies to user @buf. Depending on the PCI config space
2575 * read command setup, it does either a single register read of a byte
2576 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
2577 * registers from the 4K extended PCI config space.
2580 * This function returns the amount of data that was read (this could be less
2581 * than @nbytes if the end of the file was reached) or a negative error value.
2584 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
2587 struct lpfc_debug *debug = file->private_data;
2588 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2589 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
2592 struct pci_dev *pdev;
2597 pdev = phba->pcidev;
2601 /* This is a user read operation */
2602 debug->op = LPFC_IDIAG_OP_RD;
2605 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
2608 pbuffer = debug->buffer;
2613 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2614 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2615 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2619 /* Read single PCI config space register */
2621 case SIZE_U8: /* byte (8 bits) */
2622 pci_read_config_byte(pdev, where, &u8val);
2623 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2624 "%03x: %02x\n", where, u8val);
2626 case SIZE_U16: /* word (16 bits) */
2627 pci_read_config_word(pdev, where, &u16val);
2628 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2629 "%03x: %04x\n", where, u16val);
2631 case SIZE_U32: /* double word (32 bits) */
2632 pci_read_config_dword(pdev, where, &u32val);
2633 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2634 "%03x: %08x\n", where, u32val);
2636 case LPFC_PCI_CFG_BROWSE: /* browse all */
2644 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2648 /* Browse all PCI config space registers */
2649 offset_label = idiag.offset.last_rd;
2650 offset = offset_label;
2652 /* Read PCI config space */
2653 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2654 "%03x: ", offset_label);
2656 pci_read_config_dword(pdev, offset, &u32val);
2657 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2659 offset += sizeof(uint32_t);
2660 if (offset >= LPFC_PCI_CFG_SIZE) {
2661 len += snprintf(pbuffer+len,
2662 LPFC_PCI_CFG_SIZE-len, "\n");
2665 index -= sizeof(uint32_t);
2667 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2669 else if (!(index % (8 * sizeof(uint32_t)))) {
2670 offset_label += (8 * sizeof(uint32_t));
2671 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2672 "\n%03x: ", offset_label);
2676 /* Set up the offset for next portion of pci cfg read */
2678 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
2679 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
2680 idiag.offset.last_rd = 0;
2682 idiag.offset.last_rd = 0;
2684 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2688 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
2689 * @file: The file pointer to read from.
2690 * @buf: The buffer to copy the user data from.
2691 * @nbytes: The number of bytes to get.
2692 * @ppos: The position in the file to start reading from.
2694 * This routine get the debugfs idiag command struct from user space and
2695 * then perform the syntax check for PCI config space read or write command
2696 * accordingly. In the case of PCI config space read command, it sets up
2697 * the command in the idiag command struct for the debugfs read operation.
2698 * In the case of PCI config space write operation, it executes the write
2699 * operation into the PCI config space accordingly.
2701 * It returns the @nbytges passing in from debugfs user space when successful.
2702 * In case of error conditions, it returns proper error code back to the user
2706 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
2707 size_t nbytes, loff_t *ppos)
2709 struct lpfc_debug *debug = file->private_data;
2710 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2711 uint32_t where, value, count;
2715 struct pci_dev *pdev;
2718 pdev = phba->pcidev;
2722 /* This is a user write operation */
2723 debug->op = LPFC_IDIAG_OP_WR;
2725 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2729 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2730 /* Sanity check on PCI config read command line arguments */
2731 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
2733 /* Read command from PCI config space, set up command fields */
2734 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2735 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2736 if (count == LPFC_PCI_CFG_BROWSE) {
2737 if (where % sizeof(uint32_t))
2739 /* Starting offset to browse */
2740 idiag.offset.last_rd = where;
2741 } else if ((count != sizeof(uint8_t)) &&
2742 (count != sizeof(uint16_t)) &&
2743 (count != sizeof(uint32_t)))
2745 if (count == sizeof(uint8_t)) {
2746 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2748 if (where % sizeof(uint8_t))
2751 if (count == sizeof(uint16_t)) {
2752 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2754 if (where % sizeof(uint16_t))
2757 if (count == sizeof(uint32_t)) {
2758 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2760 if (where % sizeof(uint32_t))
2763 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
2764 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
2765 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2766 /* Sanity check on PCI config write command line arguments */
2767 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
2769 /* Write command to PCI config space, read-modify-write */
2770 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2771 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2772 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
2774 if ((count != sizeof(uint8_t)) &&
2775 (count != sizeof(uint16_t)) &&
2776 (count != sizeof(uint32_t)))
2778 if (count == sizeof(uint8_t)) {
2779 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2781 if (where % sizeof(uint8_t))
2783 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2784 pci_write_config_byte(pdev, where,
2786 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2787 rc = pci_read_config_byte(pdev, where, &u8val);
2789 u8val |= (uint8_t)value;
2790 pci_write_config_byte(pdev, where,
2794 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2795 rc = pci_read_config_byte(pdev, where, &u8val);
2797 u8val &= (uint8_t)(~value);
2798 pci_write_config_byte(pdev, where,
2803 if (count == sizeof(uint16_t)) {
2804 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2806 if (where % sizeof(uint16_t))
2808 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2809 pci_write_config_word(pdev, where,
2811 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2812 rc = pci_read_config_word(pdev, where, &u16val);
2814 u16val |= (uint16_t)value;
2815 pci_write_config_word(pdev, where,
2819 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2820 rc = pci_read_config_word(pdev, where, &u16val);
2822 u16val &= (uint16_t)(~value);
2823 pci_write_config_word(pdev, where,
2828 if (count == sizeof(uint32_t)) {
2829 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2831 if (where % sizeof(uint32_t))
2833 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2834 pci_write_config_dword(pdev, where, value);
2835 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2836 rc = pci_read_config_dword(pdev, where,
2840 pci_write_config_dword(pdev, where,
2844 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2845 rc = pci_read_config_dword(pdev, where,
2849 pci_write_config_dword(pdev, where,
2855 /* All other opecodes are illegal for now */
2860 memset(&idiag, 0, sizeof(idiag));
2865 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
2866 * @file: The file pointer to read from.
2867 * @buf: The buffer to copy the data to.
2868 * @nbytes: The number of bytes to read.
2869 * @ppos: The position in the file to start reading from.
2872 * This routine reads data from the @phba pci bar memory mapped space
2873 * according to the idiag command, and copies to user @buf.
2876 * This function returns the amount of data that was read (this could be less
2877 * than @nbytes if the end of the file was reached) or a negative error value.
2880 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
2883 struct lpfc_debug *debug = file->private_data;
2884 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2885 int offset_label, offset, offset_run, len = 0, index;
2886 int bar_num, acc_range, bar_size;
2888 void __iomem *mem_mapped_bar;
2890 struct pci_dev *pdev;
2893 pdev = phba->pcidev;
2897 /* This is a user read operation */
2898 debug->op = LPFC_IDIAG_OP_RD;
2901 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
2904 pbuffer = debug->buffer;
2909 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
2910 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2911 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
2912 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
2913 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
2920 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2921 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2922 if (bar_num == IDIAG_BARACC_BAR_0)
2923 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2924 else if (bar_num == IDIAG_BARACC_BAR_1)
2925 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2926 else if (bar_num == IDIAG_BARACC_BAR_2)
2927 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2930 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2931 if (bar_num == IDIAG_BARACC_BAR_0)
2932 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2938 /* Read single PCI bar space register */
2939 if (acc_range == SINGLE_WORD) {
2940 offset_run = offset;
2941 u32val = readl(mem_mapped_bar + offset_run);
2942 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2943 "%05x: %08x\n", offset_run, u32val);
2947 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2951 /* Browse all PCI bar space registers */
2952 offset_label = idiag.offset.last_rd;
2953 offset_run = offset_label;
2955 /* Read PCI bar memory mapped space */
2956 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2957 "%05x: ", offset_label);
2958 index = LPFC_PCI_BAR_RD_SIZE;
2960 u32val = readl(mem_mapped_bar + offset_run);
2961 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2963 offset_run += sizeof(uint32_t);
2964 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2965 if (offset_run >= bar_size) {
2966 len += snprintf(pbuffer+len,
2967 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2971 if (offset_run >= offset +
2972 (acc_range * sizeof(uint32_t))) {
2973 len += snprintf(pbuffer+len,
2974 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2978 index -= sizeof(uint32_t);
2980 len += snprintf(pbuffer+len,
2981 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2982 else if (!(index % (8 * sizeof(uint32_t)))) {
2983 offset_label += (8 * sizeof(uint32_t));
2984 len += snprintf(pbuffer+len,
2985 LPFC_PCI_BAR_RD_BUF_SIZE-len,
2986 "\n%05x: ", offset_label);
2990 /* Set up the offset for next portion of pci bar read */
2992 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
2993 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2994 if (idiag.offset.last_rd >= bar_size)
2995 idiag.offset.last_rd = 0;
2997 if (offset_run >= offset +
2998 (acc_range * sizeof(uint32_t)))
2999 idiag.offset.last_rd = offset;
3002 if (acc_range == LPFC_PCI_BAR_BROWSE)
3003 idiag.offset.last_rd = 0;
3005 idiag.offset.last_rd = offset;
3008 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3012 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
3013 * @file: The file pointer to read from.
3014 * @buf: The buffer to copy the user data from.
3015 * @nbytes: The number of bytes to get.
3016 * @ppos: The position in the file to start reading from.
3018 * This routine get the debugfs idiag command struct from user space and
3019 * then perform the syntax check for PCI bar memory mapped space read or
3020 * write command accordingly. In the case of PCI bar memory mapped space
3021 * read command, it sets up the command in the idiag command struct for
3022 * the debugfs read operation. In the case of PCI bar memorpy mapped space
3023 * write operation, it executes the write operation into the PCI bar memory
3024 * mapped space accordingly.
3026 * It returns the @nbytges passing in from debugfs user space when successful.
3027 * In case of error conditions, it returns proper error code back to the user
3031 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
3032 size_t nbytes, loff_t *ppos)
3034 struct lpfc_debug *debug = file->private_data;
3035 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3036 uint32_t bar_num, bar_size, offset, value, acc_range;
3037 struct pci_dev *pdev;
3038 void __iomem *mem_mapped_bar;
3043 pdev = phba->pcidev;
3047 /* This is a user write operation */
3048 debug->op = LPFC_IDIAG_OP_WR;
3050 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3054 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3055 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3057 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3058 if ((bar_num != IDIAG_BARACC_BAR_0) &&
3059 (bar_num != IDIAG_BARACC_BAR_1) &&
3060 (bar_num != IDIAG_BARACC_BAR_2))
3062 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3063 if (bar_num != IDIAG_BARACC_BAR_0)
3068 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3069 if (bar_num == IDIAG_BARACC_BAR_0) {
3070 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3071 LPFC_PCI_IF0_BAR0_SIZE;
3072 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3073 } else if (bar_num == IDIAG_BARACC_BAR_1) {
3074 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3075 LPFC_PCI_IF0_BAR1_SIZE;
3076 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3077 } else if (bar_num == IDIAG_BARACC_BAR_2) {
3078 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3079 LPFC_PCI_IF0_BAR2_SIZE;
3080 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3083 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3084 if (bar_num == IDIAG_BARACC_BAR_0) {
3085 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3086 LPFC_PCI_IF2_BAR0_SIZE;
3087 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3093 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3094 if (offset % sizeof(uint32_t))
3097 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3098 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3099 /* Sanity check on PCI config read command line arguments */
3100 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3102 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3103 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3104 if (offset > bar_size - sizeof(uint32_t))
3106 /* Starting offset to browse */
3107 idiag.offset.last_rd = offset;
3108 } else if (acc_range > SINGLE_WORD) {
3109 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3111 /* Starting offset to browse */
3112 idiag.offset.last_rd = offset;
3113 } else if (acc_range != SINGLE_WORD)
3115 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3116 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3117 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3118 /* Sanity check on PCI bar write command line arguments */
3119 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3121 /* Write command to PCI bar space, read-modify-write */
3122 acc_range = SINGLE_WORD;
3123 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3124 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3125 writel(value, mem_mapped_bar + offset);
3126 readl(mem_mapped_bar + offset);
3128 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3129 u32val = readl(mem_mapped_bar + offset);
3131 writel(u32val, mem_mapped_bar + offset);
3132 readl(mem_mapped_bar + offset);
3134 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3135 u32val = readl(mem_mapped_bar + offset);
3137 writel(u32val, mem_mapped_bar + offset);
3138 readl(mem_mapped_bar + offset);
3141 /* All other opecodes are illegal for now */
3146 memset(&idiag, 0, sizeof(idiag));
3151 __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3152 char *pbuffer, int len)
3157 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3158 "\t\t%s WQ info: ", wqtype);
3159 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3160 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3161 qp->assoc_qid, qp->q_cnt_1,
3162 (unsigned long long)qp->q_cnt_4);
3163 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3164 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3165 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3166 qp->queue_id, qp->entry_count,
3167 qp->entry_size, qp->host_index,
3168 qp->hba_index, qp->entry_repost);
3169 len += snprintf(pbuffer + len,
3170 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3175 lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3176 int *len, int max_cnt, int cq_id)
3178 struct lpfc_queue *qp;
3181 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3182 qp = phba->sli4_hba.fcp_wq[qidx];
3183 if (qp->assoc_qid != cq_id)
3185 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3186 if (*len >= max_cnt)
3189 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3190 qp = phba->sli4_hba.nvme_wq[qidx];
3191 if (qp->assoc_qid != cq_id)
3193 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3194 if (*len >= max_cnt)
3201 __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3202 char *pbuffer, int len)
3207 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3208 "\t%s CQ info: ", cqtype);
3209 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3210 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3211 "xabt:x%x wq:x%llx]\n",
3212 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3213 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3214 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3215 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3216 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3217 qp->queue_id, qp->entry_count,
3218 qp->entry_size, qp->host_index,
3219 qp->hba_index, qp->entry_repost);
3221 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3227 __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3228 char *rqtype, char *pbuffer, int len)
3233 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3234 "\t\t%s RQ info: ", rqtype);
3235 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3236 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
3237 "posted:x%x rcv:x%llx]\n",
3238 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3239 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3240 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3241 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3242 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
3243 qp->queue_id, qp->entry_count, qp->entry_size,
3244 qp->host_index, qp->hba_index, qp->entry_repost);
3245 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3246 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3247 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
3248 datqp->queue_id, datqp->entry_count,
3249 datqp->entry_size, datqp->host_index,
3250 datqp->hba_index, datqp->entry_repost);
3255 lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
3256 int *len, int max_cnt, int eqidx, int eq_id)
3258 struct lpfc_queue *qp;
3261 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3262 qp = phba->sli4_hba.fcp_cq[qidx];
3263 if (qp->assoc_qid != eq_id)
3266 *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
3268 /* Reset max counter */
3271 if (*len >= max_cnt)
3274 rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
3275 max_cnt, qp->queue_id);
3280 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3281 qp = phba->sli4_hba.nvme_cq[qidx];
3282 if (qp->assoc_qid != eq_id)
3285 *len = __lpfc_idiag_print_cq(qp, "NVME", pbuffer, *len);
3287 /* Reset max counter */
3290 if (*len >= max_cnt)
3293 rc = lpfc_idiag_wqs_for_cq(phba, "NVME", pbuffer, len,
3294 max_cnt, qp->queue_id);
3299 if ((eqidx < phba->cfg_nvmet_mrq) && phba->nvmet_support) {
3301 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3302 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3304 /* Reset max counter */
3307 if (*len >= max_cnt)
3311 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3312 *len = __lpfc_idiag_print_rqpair(qp,
3313 phba->sli4_hba.nvmet_mrq_data[eqidx],
3314 "NVMET MRQ", pbuffer, *len);
3316 if (*len >= max_cnt)
3324 __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
3325 char *pbuffer, int len)
3330 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3331 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
3332 "cqe_proc:x%x eqe_proc:x%llx eqd %d]\n",
3333 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
3334 (unsigned long long)qp->q_cnt_4, qp->q_mode);
3335 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3336 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3337 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3338 qp->queue_id, qp->entry_count, qp->entry_size,
3339 qp->host_index, qp->hba_index, qp->entry_repost);
3340 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3346 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
3347 * @file: The file pointer to read from.
3348 * @buf: The buffer to copy the data to.
3349 * @nbytes: The number of bytes to read.
3350 * @ppos: The position in the file to start reading from.
3353 * This routine reads data from the @phba SLI4 PCI function queue information,
3354 * and copies to user @buf.
3355 * This routine only returns 1 EQs worth of information. It remembers the last
3356 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
3357 * retrieve all EQs allocated for the phba.
3360 * This function returns the amount of data that was read (this could be less
3361 * than @nbytes if the end of the file was reached) or a negative error value.
3364 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
3367 struct lpfc_debug *debug = file->private_data;
3368 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3370 int max_cnt, rc, x, len = 0;
3371 struct lpfc_queue *qp = NULL;
3374 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
3377 pbuffer = debug->buffer;
3378 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
3383 spin_lock_irq(&phba->hbalock);
3385 /* Fast-path event queue */
3386 if (phba->sli4_hba.hba_eq && phba->io_channel_irqs) {
3388 x = phba->lpfc_idiag_last_eq;
3389 if (phba->cfg_fof && (x >= phba->io_channel_irqs)) {
3390 phba->lpfc_idiag_last_eq = 0;
3393 phba->lpfc_idiag_last_eq++;
3394 if (phba->lpfc_idiag_last_eq >= phba->io_channel_irqs)
3395 if (phba->cfg_fof == 0)
3396 phba->lpfc_idiag_last_eq = 0;
3398 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3399 "EQ %d out of %d HBA EQs\n",
3400 x, phba->io_channel_irqs);
3403 qp = phba->sli4_hba.hba_eq[x];
3407 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
3409 /* Reset max counter */
3415 /* will dump both fcp and nvme cqs/wqs for the eq */
3416 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
3417 max_cnt, x, qp->queue_id);
3421 /* Only EQ 0 has slow path CQs configured */
3425 /* Slow-path mailbox CQ */
3426 qp = phba->sli4_hba.mbx_cq;
3427 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
3431 /* Slow-path MBOX MQ */
3432 qp = phba->sli4_hba.mbx_wq;
3433 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
3437 /* Slow-path ELS response CQ */
3438 qp = phba->sli4_hba.els_cq;
3439 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
3440 /* Reset max counter */
3446 /* Slow-path ELS WQ */
3447 qp = phba->sli4_hba.els_wq;
3448 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
3452 qp = phba->sli4_hba.hdr_rq;
3453 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
3454 "ELS RQpair", pbuffer, len);
3458 /* Slow-path NVME LS response CQ */
3459 qp = phba->sli4_hba.nvmels_cq;
3460 len = __lpfc_idiag_print_cq(qp, "NVME LS",
3462 /* Reset max counter */
3468 /* Slow-path NVME LS WQ */
3469 qp = phba->sli4_hba.nvmels_wq;
3470 len = __lpfc_idiag_print_wq(qp, "NVME LS",
3479 if (phba->cfg_fof) {
3481 qp = phba->sli4_hba.fof_eq;
3482 len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
3484 /* Reset max counter */
3492 qp = phba->sli4_hba.oas_cq;
3493 len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
3494 /* Reset max counter */
3501 qp = phba->sli4_hba.oas_wq;
3502 len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
3507 spin_unlock_irq(&phba->hbalock);
3508 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3511 len += snprintf(pbuffer + len,
3512 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
3514 spin_unlock_irq(&phba->hbalock);
3515 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3519 * lpfc_idiag_que_param_check - queue access command parameter sanity check
3520 * @q: The pointer to queue structure.
3521 * @index: The index into a queue entry.
3522 * @count: The number of queue entries to access.
3525 * The routine performs sanity check on device queue access method commands.
3528 * This function returns -EINVAL when fails the sanity check, otherwise, it
3532 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
3534 /* Only support single entry read or browsing */
3535 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
3537 if (index > q->entry_count - 1)
3543 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
3544 * @pbuffer: The pointer to buffer to copy the read data into.
3545 * @pque: The pointer to the queue to be read.
3546 * @index: The index into the queue entry.
3549 * This routine reads out a single entry from the given queue's index location
3550 * and copies it into the buffer provided.
3553 * This function returns 0 when it fails, otherwise, it returns the length of
3554 * the data read into the buffer provided.
3557 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
3563 if (!pbuffer || !pque)
3566 esize = pque->entry_size;
3567 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3568 "QE-INDEX[%04d]:\n", index);
3571 pentry = pque->qe[index].address;
3573 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3576 offset += sizeof(uint32_t);
3577 esize -= sizeof(uint32_t);
3578 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
3579 len += snprintf(pbuffer+len,
3580 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3582 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3588 * lpfc_idiag_queacc_read - idiag debugfs read port queue
3589 * @file: The file pointer to read from.
3590 * @buf: The buffer to copy the data to.
3591 * @nbytes: The number of bytes to read.
3592 * @ppos: The position in the file to start reading from.
3595 * This routine reads data from the @phba device queue memory according to the
3596 * idiag command, and copies to user @buf. Depending on the queue dump read
3597 * command setup, it does either a single queue entry read or browing through
3598 * all entries of the queue.
3601 * This function returns the amount of data that was read (this could be less
3602 * than @nbytes if the end of the file was reached) or a negative error value.
3605 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
3608 struct lpfc_debug *debug = file->private_data;
3609 uint32_t last_index, index, count;
3610 struct lpfc_queue *pque = NULL;
3614 /* This is a user read operation */
3615 debug->op = LPFC_IDIAG_OP_RD;
3618 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
3621 pbuffer = debug->buffer;
3626 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3627 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3628 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3629 pque = (struct lpfc_queue *)idiag.ptr_private;
3633 /* Browse the queue starting from index */
3634 if (count == LPFC_QUE_ACC_BROWSE)
3637 /* Read a single entry from the queue */
3638 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3640 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3644 /* Browse all entries from the queue */
3645 last_index = idiag.offset.last_rd;
3648 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
3649 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3651 if (index > pque->entry_count - 1)
3655 /* Set up the offset for next portion of pci cfg read */
3656 if (index > pque->entry_count - 1)
3658 idiag.offset.last_rd = index;
3660 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3664 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
3665 * @file: The file pointer to read from.
3666 * @buf: The buffer to copy the user data from.
3667 * @nbytes: The number of bytes to get.
3668 * @ppos: The position in the file to start reading from.
3670 * This routine get the debugfs idiag command struct from user space and then
3671 * perform the syntax check for port queue read (dump) or write (set) command
3672 * accordingly. In the case of port queue read command, it sets up the command
3673 * in the idiag command struct for the following debugfs read operation. In
3674 * the case of port queue write operation, it executes the write operation
3675 * into the port queue entry accordingly.
3677 * It returns the @nbytges passing in from debugfs user space when successful.
3678 * In case of error conditions, it returns proper error code back to the user
3682 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3683 size_t nbytes, loff_t *ppos)
3685 struct lpfc_debug *debug = file->private_data;
3686 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3687 uint32_t qidx, quetp, queid, index, count, offset, value;
3689 struct lpfc_queue *pque, *qp;
3692 /* This is a user write operation */
3693 debug->op = LPFC_IDIAG_OP_WR;
3695 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3699 /* Get and sanity check on command feilds */
3700 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
3701 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
3702 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3703 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3704 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
3705 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
3707 /* Sanity check on command line arguments */
3708 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3709 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3710 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3711 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
3715 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3716 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
3723 /* HBA event queue */
3724 if (phba->sli4_hba.hba_eq) {
3725 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
3726 qp = phba->sli4_hba.hba_eq[qidx];
3727 if (qp && qp->queue_id == queid) {
3729 rc = lpfc_idiag_que_param_check(qp,
3733 idiag.ptr_private = qp;
3741 /* MBX complete queue */
3742 if (phba->sli4_hba.mbx_cq &&
3743 phba->sli4_hba.mbx_cq->queue_id == queid) {
3745 rc = lpfc_idiag_que_param_check(
3746 phba->sli4_hba.mbx_cq, index, count);
3749 idiag.ptr_private = phba->sli4_hba.mbx_cq;
3752 /* ELS complete queue */
3753 if (phba->sli4_hba.els_cq &&
3754 phba->sli4_hba.els_cq->queue_id == queid) {
3756 rc = lpfc_idiag_que_param_check(
3757 phba->sli4_hba.els_cq, index, count);
3760 idiag.ptr_private = phba->sli4_hba.els_cq;
3763 /* NVME LS complete queue */
3764 if (phba->sli4_hba.nvmels_cq &&
3765 phba->sli4_hba.nvmels_cq->queue_id == queid) {
3767 rc = lpfc_idiag_que_param_check(
3768 phba->sli4_hba.nvmels_cq, index, count);
3771 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3774 /* FCP complete queue */
3775 if (phba->sli4_hba.fcp_cq) {
3776 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3778 qp = phba->sli4_hba.fcp_cq[qidx];
3779 if (qp && qp->queue_id == queid) {
3781 rc = lpfc_idiag_que_param_check(
3785 idiag.ptr_private = qp;
3790 /* NVME complete queue */
3791 if (phba->sli4_hba.nvme_cq) {
3794 if (phba->sli4_hba.nvme_cq[qidx] &&
3795 phba->sli4_hba.nvme_cq[qidx]->queue_id ==
3798 rc = lpfc_idiag_que_param_check(
3799 phba->sli4_hba.nvme_cq[qidx],
3804 phba->sli4_hba.nvme_cq[qidx];
3807 } while (++qidx < phba->cfg_nvme_io_channel);
3812 /* MBX work queue */
3813 if (phba->sli4_hba.mbx_wq &&
3814 phba->sli4_hba.mbx_wq->queue_id == queid) {
3816 rc = lpfc_idiag_que_param_check(
3817 phba->sli4_hba.mbx_wq, index, count);
3820 idiag.ptr_private = phba->sli4_hba.mbx_wq;
3826 /* ELS work queue */
3827 if (phba->sli4_hba.els_wq &&
3828 phba->sli4_hba.els_wq->queue_id == queid) {
3830 rc = lpfc_idiag_que_param_check(
3831 phba->sli4_hba.els_wq, index, count);
3834 idiag.ptr_private = phba->sli4_hba.els_wq;
3837 /* NVME LS work queue */
3838 if (phba->sli4_hba.nvmels_wq &&
3839 phba->sli4_hba.nvmels_wq->queue_id == queid) {
3841 rc = lpfc_idiag_que_param_check(
3842 phba->sli4_hba.nvmels_wq, index, count);
3845 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3848 /* FCP work queue */
3849 if (phba->sli4_hba.fcp_wq) {
3850 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3852 qp = phba->sli4_hba.fcp_wq[qidx];
3853 if (qp && qp->queue_id == queid) {
3855 rc = lpfc_idiag_que_param_check(
3859 idiag.ptr_private = qp;
3864 /* NVME work queue */
3865 if (phba->sli4_hba.nvme_wq) {
3866 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3868 qp = phba->sli4_hba.nvme_wq[qidx];
3869 if (qp && qp->queue_id == queid) {
3871 rc = lpfc_idiag_que_param_check(
3875 idiag.ptr_private = qp;
3881 /* NVME work queues */
3882 if (phba->sli4_hba.nvme_wq) {
3883 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3885 if (!phba->sli4_hba.nvme_wq[qidx])
3887 if (phba->sli4_hba.nvme_wq[qidx]->queue_id ==
3890 rc = lpfc_idiag_que_param_check(
3891 phba->sli4_hba.nvme_wq[qidx],
3896 phba->sli4_hba.nvme_wq[qidx];
3905 if (phba->sli4_hba.hdr_rq &&
3906 phba->sli4_hba.hdr_rq->queue_id == queid) {
3908 rc = lpfc_idiag_que_param_check(
3909 phba->sli4_hba.hdr_rq, index, count);
3912 idiag.ptr_private = phba->sli4_hba.hdr_rq;
3916 if (phba->sli4_hba.dat_rq &&
3917 phba->sli4_hba.dat_rq->queue_id == queid) {
3919 rc = lpfc_idiag_que_param_check(
3920 phba->sli4_hba.dat_rq, index, count);
3923 idiag.ptr_private = phba->sli4_hba.dat_rq;
3935 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3936 if (count == LPFC_QUE_ACC_BROWSE)
3937 idiag.offset.last_rd = index;
3940 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3941 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3942 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3943 /* Additional sanity checks on write operation */
3944 pque = (struct lpfc_queue *)idiag.ptr_private;
3945 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
3947 pentry = pque->qe[index].address;
3949 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
3951 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
3953 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
3959 /* Clean out command structure on command error out */
3960 memset(&idiag, 0, sizeof(idiag));
3965 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
3966 * @phba: The pointer to hba structure.
3967 * @pbuffer: The pointer to the buffer to copy the data to.
3968 * @len: The lenght of bytes to copied.
3969 * @drbregid: The id to doorbell registers.
3972 * This routine reads a doorbell register and copies its content to the
3973 * user buffer pointed to by @pbuffer.
3976 * This function returns the amount of data that was copied into @pbuffer.
3979 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
3980 int len, uint32_t drbregid)
3988 len += snprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE-len,
3989 "EQ-DRB-REG: 0x%08x\n",
3990 readl(phba->sli4_hba.EQDBregaddr));
3993 len += snprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE - len,
3994 "CQ-DRB-REG: 0x%08x\n",
3995 readl(phba->sli4_hba.CQDBregaddr));
3998 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3999 "MQ-DRB-REG: 0x%08x\n",
4000 readl(phba->sli4_hba.MQDBregaddr));
4003 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
4004 "WQ-DRB-REG: 0x%08x\n",
4005 readl(phba->sli4_hba.WQDBregaddr));
4008 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
4009 "RQ-DRB-REG: 0x%08x\n",
4010 readl(phba->sli4_hba.RQDBregaddr));
4020 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
4021 * @file: The file pointer to read from.
4022 * @buf: The buffer to copy the data to.
4023 * @nbytes: The number of bytes to read.
4024 * @ppos: The position in the file to start reading from.
4027 * This routine reads data from the @phba device doorbell register according
4028 * to the idiag command, and copies to user @buf. Depending on the doorbell
4029 * register read command setup, it does either a single doorbell register
4030 * read or dump all doorbell registers.
4033 * This function returns the amount of data that was read (this could be less
4034 * than @nbytes if the end of the file was reached) or a negative error value.
4037 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
4040 struct lpfc_debug *debug = file->private_data;
4041 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4042 uint32_t drb_reg_id, i;
4046 /* This is a user read operation */
4047 debug->op = LPFC_IDIAG_OP_RD;
4050 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
4053 pbuffer = debug->buffer;
4058 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
4059 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4063 if (drb_reg_id == LPFC_DRB_ACC_ALL)
4064 for (i = 1; i <= LPFC_DRB_MAX; i++)
4065 len = lpfc_idiag_drbacc_read_reg(phba,
4068 len = lpfc_idiag_drbacc_read_reg(phba,
4069 pbuffer, len, drb_reg_id);
4071 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4075 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
4076 * @file: The file pointer to read from.
4077 * @buf: The buffer to copy the user data from.
4078 * @nbytes: The number of bytes to get.
4079 * @ppos: The position in the file to start reading from.
4081 * This routine get the debugfs idiag command struct from user space and then
4082 * perform the syntax check for port doorbell register read (dump) or write
4083 * (set) command accordingly. In the case of port queue read command, it sets
4084 * up the command in the idiag command struct for the following debugfs read
4085 * operation. In the case of port doorbell register write operation, it
4086 * executes the write operation into the port doorbell register accordingly.
4088 * It returns the @nbytges passing in from debugfs user space when successful.
4089 * In case of error conditions, it returns proper error code back to the user
4093 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4094 size_t nbytes, loff_t *ppos)
4096 struct lpfc_debug *debug = file->private_data;
4097 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4098 uint32_t drb_reg_id, value, reg_val = 0;
4099 void __iomem *drb_reg;
4102 /* This is a user write operation */
4103 debug->op = LPFC_IDIAG_OP_WR;
4105 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4109 /* Sanity check on command line arguments */
4110 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4111 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
4113 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4114 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4115 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4116 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4118 if (drb_reg_id > LPFC_DRB_MAX)
4120 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4121 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4123 if ((drb_reg_id > LPFC_DRB_MAX) &&
4124 (drb_reg_id != LPFC_DRB_ACC_ALL))
4129 /* Perform the write access operation */
4130 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4131 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4132 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4133 switch (drb_reg_id) {
4135 drb_reg = phba->sli4_hba.EQDBregaddr;
4138 drb_reg = phba->sli4_hba.CQDBregaddr;
4141 drb_reg = phba->sli4_hba.MQDBregaddr;
4144 drb_reg = phba->sli4_hba.WQDBregaddr;
4147 drb_reg = phba->sli4_hba.RQDBregaddr;
4153 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4155 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4156 reg_val = readl(drb_reg);
4159 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4160 reg_val = readl(drb_reg);
4163 writel(reg_val, drb_reg);
4164 readl(drb_reg); /* flush */
4169 /* Clean out command structure on command error out */
4170 memset(&idiag, 0, sizeof(idiag));
4175 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4176 * @phba: The pointer to hba structure.
4177 * @pbuffer: The pointer to the buffer to copy the data to.
4178 * @len: The lenght of bytes to copied.
4179 * @drbregid: The id to doorbell registers.
4182 * This routine reads a control register and copies its content to the
4183 * user buffer pointed to by @pbuffer.
4186 * This function returns the amount of data that was copied into @pbuffer.
4189 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4190 int len, uint32_t ctlregid)
4197 case LPFC_CTL_PORT_SEM:
4198 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4199 "Port SemReg: 0x%08x\n",
4200 readl(phba->sli4_hba.conf_regs_memmap_p +
4201 LPFC_CTL_PORT_SEM_OFFSET));
4203 case LPFC_CTL_PORT_STA:
4204 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4205 "Port StaReg: 0x%08x\n",
4206 readl(phba->sli4_hba.conf_regs_memmap_p +
4207 LPFC_CTL_PORT_STA_OFFSET));
4209 case LPFC_CTL_PORT_CTL:
4210 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4211 "Port CtlReg: 0x%08x\n",
4212 readl(phba->sli4_hba.conf_regs_memmap_p +
4213 LPFC_CTL_PORT_CTL_OFFSET));
4215 case LPFC_CTL_PORT_ER1:
4216 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4217 "Port Er1Reg: 0x%08x\n",
4218 readl(phba->sli4_hba.conf_regs_memmap_p +
4219 LPFC_CTL_PORT_ER1_OFFSET));
4221 case LPFC_CTL_PORT_ER2:
4222 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4223 "Port Er2Reg: 0x%08x\n",
4224 readl(phba->sli4_hba.conf_regs_memmap_p +
4225 LPFC_CTL_PORT_ER2_OFFSET));
4227 case LPFC_CTL_PDEV_CTL:
4228 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4229 "PDev CtlReg: 0x%08x\n",
4230 readl(phba->sli4_hba.conf_regs_memmap_p +
4231 LPFC_CTL_PDEV_CTL_OFFSET));
4240 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4241 * @file: The file pointer to read from.
4242 * @buf: The buffer to copy the data to.
4243 * @nbytes: The number of bytes to read.
4244 * @ppos: The position in the file to start reading from.
4247 * This routine reads data from the @phba port and device registers according
4248 * to the idiag command, and copies to user @buf.
4251 * This function returns the amount of data that was read (this could be less
4252 * than @nbytes if the end of the file was reached) or a negative error value.
4255 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4258 struct lpfc_debug *debug = file->private_data;
4259 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4260 uint32_t ctl_reg_id, i;
4264 /* This is a user read operation */
4265 debug->op = LPFC_IDIAG_OP_RD;
4268 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4271 pbuffer = debug->buffer;
4276 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4277 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4281 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4282 for (i = 1; i <= LPFC_CTL_MAX; i++)
4283 len = lpfc_idiag_ctlacc_read_reg(phba,
4286 len = lpfc_idiag_ctlacc_read_reg(phba,
4287 pbuffer, len, ctl_reg_id);
4289 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4293 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4294 * @file: The file pointer to read from.
4295 * @buf: The buffer to copy the user data from.
4296 * @nbytes: The number of bytes to get.
4297 * @ppos: The position in the file to start reading from.
4299 * This routine get the debugfs idiag command struct from user space and then
4300 * perform the syntax check for port and device control register read (dump)
4301 * or write (set) command accordingly.
4303 * It returns the @nbytges passing in from debugfs user space when successful.
4304 * In case of error conditions, it returns proper error code back to the user
4308 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4309 size_t nbytes, loff_t *ppos)
4311 struct lpfc_debug *debug = file->private_data;
4312 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4313 uint32_t ctl_reg_id, value, reg_val = 0;
4314 void __iomem *ctl_reg;
4317 /* This is a user write operation */
4318 debug->op = LPFC_IDIAG_OP_WR;
4320 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4324 /* Sanity check on command line arguments */
4325 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4326 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4328 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4329 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4330 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4331 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4333 if (ctl_reg_id > LPFC_CTL_MAX)
4335 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4336 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4338 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4339 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4344 /* Perform the write access operation */
4345 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4346 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4347 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4348 switch (ctl_reg_id) {
4349 case LPFC_CTL_PORT_SEM:
4350 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4351 LPFC_CTL_PORT_SEM_OFFSET;
4353 case LPFC_CTL_PORT_STA:
4354 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4355 LPFC_CTL_PORT_STA_OFFSET;
4357 case LPFC_CTL_PORT_CTL:
4358 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4359 LPFC_CTL_PORT_CTL_OFFSET;
4361 case LPFC_CTL_PORT_ER1:
4362 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4363 LPFC_CTL_PORT_ER1_OFFSET;
4365 case LPFC_CTL_PORT_ER2:
4366 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4367 LPFC_CTL_PORT_ER2_OFFSET;
4369 case LPFC_CTL_PDEV_CTL:
4370 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4371 LPFC_CTL_PDEV_CTL_OFFSET;
4377 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4379 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4380 reg_val = readl(ctl_reg);
4383 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4384 reg_val = readl(ctl_reg);
4387 writel(reg_val, ctl_reg);
4388 readl(ctl_reg); /* flush */
4393 /* Clean out command structure on command error out */
4394 memset(&idiag, 0, sizeof(idiag));
4399 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4400 * @phba: Pointer to HBA context object.
4401 * @pbuffer: Pointer to data buffer.
4404 * This routine gets the driver mailbox access debugfs setup information.
4407 * This function returns the amount of data that was read (this could be less
4408 * than @nbytes if the end of the file was reached) or a negative error value.
4411 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
4413 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4416 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4417 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4418 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4419 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4421 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4422 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
4423 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4424 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
4425 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4426 "mbx_word_cnt: %04d\n", mbx_word_cnt);
4427 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4428 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
4434 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
4435 * @file: The file pointer to read from.
4436 * @buf: The buffer to copy the data to.
4437 * @nbytes: The number of bytes to read.
4438 * @ppos: The position in the file to start reading from.
4441 * This routine reads data from the @phba driver mailbox access debugfs setup
4445 * This function returns the amount of data that was read (this could be less
4446 * than @nbytes if the end of the file was reached) or a negative error value.
4449 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
4452 struct lpfc_debug *debug = file->private_data;
4453 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4457 /* This is a user read operation */
4458 debug->op = LPFC_IDIAG_OP_RD;
4461 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
4464 pbuffer = debug->buffer;
4469 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
4470 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
4473 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
4475 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4479 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
4480 * @file: The file pointer to read from.
4481 * @buf: The buffer to copy the user data from.
4482 * @nbytes: The number of bytes to get.
4483 * @ppos: The position in the file to start reading from.
4485 * This routine get the debugfs idiag command struct from user space and then
4486 * perform the syntax check for driver mailbox command (dump) and sets up the
4487 * necessary states in the idiag command struct accordingly.
4489 * It returns the @nbytges passing in from debugfs user space when successful.
4490 * In case of error conditions, it returns proper error code back to the user
4494 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
4495 size_t nbytes, loff_t *ppos)
4497 struct lpfc_debug *debug = file->private_data;
4498 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4501 /* This is a user write operation */
4502 debug->op = LPFC_IDIAG_OP_WR;
4504 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4508 /* Sanity check on command line arguments */
4509 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4510 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4511 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4512 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4514 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
4515 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
4517 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
4518 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4520 if (mbx_word_cnt > sizeof(MAILBOX_t))
4522 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
4523 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
4525 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
4526 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4528 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
4530 if (mbx_mbox_cmd != 0x9b)
4535 if (mbx_word_cnt == 0)
4537 if (rc != LPFC_MBX_DMP_ARG)
4539 if (mbx_mbox_cmd & ~0xff)
4542 /* condition for stop mailbox dump */
4543 if (mbx_dump_cnt == 0)
4549 /* Clean out command structure on command error out */
4550 memset(&idiag, 0, sizeof(idiag));
4554 /* Clean out command structure on command error out */
4555 memset(&idiag, 0, sizeof(idiag));
4560 * lpfc_idiag_extacc_avail_get - get the available extents information
4561 * @phba: pointer to lpfc hba data structure.
4562 * @pbuffer: pointer to internal buffer.
4563 * @len: length into the internal buffer data has been copied.
4566 * This routine is to get the available extent information.
4569 * overall lenth of the data read into the internal buffer.
4572 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
4574 uint16_t ext_cnt, ext_size;
4576 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4577 "\nAvailable Extents Information:\n");
4579 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4580 "\tPort Available VPI extents: ");
4581 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
4582 &ext_cnt, &ext_size);
4583 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4584 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4586 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4587 "\tPort Available VFI extents: ");
4588 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
4589 &ext_cnt, &ext_size);
4590 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4591 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4593 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4594 "\tPort Available RPI extents: ");
4595 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
4596 &ext_cnt, &ext_size);
4597 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4598 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4600 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4601 "\tPort Available XRI extents: ");
4602 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
4603 &ext_cnt, &ext_size);
4604 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4605 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4611 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
4612 * @phba: pointer to lpfc hba data structure.
4613 * @pbuffer: pointer to internal buffer.
4614 * @len: length into the internal buffer data has been copied.
4617 * This routine is to get the allocated extent information.
4620 * overall lenth of the data read into the internal buffer.
4623 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
4625 uint16_t ext_cnt, ext_size;
4628 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4629 "\nAllocated Extents Information:\n");
4631 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4632 "\tHost Allocated VPI extents: ");
4633 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
4634 &ext_cnt, &ext_size);
4636 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4637 "Port %d Extent %3d, Size %3d\n",
4638 phba->brd_no, ext_cnt, ext_size);
4640 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4643 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4644 "\tHost Allocated VFI extents: ");
4645 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
4646 &ext_cnt, &ext_size);
4648 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4649 "Port %d Extent %3d, Size %3d\n",
4650 phba->brd_no, ext_cnt, ext_size);
4652 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4655 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4656 "\tHost Allocated RPI extents: ");
4657 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
4658 &ext_cnt, &ext_size);
4660 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4661 "Port %d Extent %3d, Size %3d\n",
4662 phba->brd_no, ext_cnt, ext_size);
4664 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4667 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4668 "\tHost Allocated XRI extents: ");
4669 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
4670 &ext_cnt, &ext_size);
4672 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4673 "Port %d Extent %3d, Size %3d\n",
4674 phba->brd_no, ext_cnt, ext_size);
4676 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4683 * lpfc_idiag_extacc_drivr_get - get driver extent information
4684 * @phba: pointer to lpfc hba data structure.
4685 * @pbuffer: pointer to internal buffer.
4686 * @len: length into the internal buffer data has been copied.
4689 * This routine is to get the driver extent information.
4692 * overall lenth of the data read into the internal buffer.
4695 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
4697 struct lpfc_rsrc_blks *rsrc_blks;
4700 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4701 "\nDriver Extents Information:\n");
4703 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4704 "\tVPI extents:\n");
4706 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
4707 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4708 "\t\tBlock %3d: Start %4d, Count %4d\n",
4709 index, rsrc_blks->rsrc_start,
4710 rsrc_blks->rsrc_size);
4713 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4714 "\tVFI extents:\n");
4716 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
4718 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4719 "\t\tBlock %3d: Start %4d, Count %4d\n",
4720 index, rsrc_blks->rsrc_start,
4721 rsrc_blks->rsrc_size);
4725 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4726 "\tRPI extents:\n");
4728 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
4730 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4731 "\t\tBlock %3d: Start %4d, Count %4d\n",
4732 index, rsrc_blks->rsrc_start,
4733 rsrc_blks->rsrc_size);
4737 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4738 "\tXRI extents:\n");
4740 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
4742 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4743 "\t\tBlock %3d: Start %4d, Count %4d\n",
4744 index, rsrc_blks->rsrc_start,
4745 rsrc_blks->rsrc_size);
4753 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
4754 * @file: The file pointer to read from.
4755 * @buf: The buffer to copy the user data from.
4756 * @nbytes: The number of bytes to get.
4757 * @ppos: The position in the file to start reading from.
4759 * This routine get the debugfs idiag command struct from user space and then
4760 * perform the syntax check for extent information access commands and sets
4761 * up the necessary states in the idiag command struct accordingly.
4763 * It returns the @nbytges passing in from debugfs user space when successful.
4764 * In case of error conditions, it returns proper error code back to the user
4768 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
4769 size_t nbytes, loff_t *ppos)
4771 struct lpfc_debug *debug = file->private_data;
4775 /* This is a user write operation */
4776 debug->op = LPFC_IDIAG_OP_WR;
4778 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4782 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4784 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4786 if (rc != LPFC_EXT_ACC_CMD_ARG)
4788 if (!(ext_map & LPFC_EXT_ACC_ALL))
4793 /* Clean out command structure on command error out */
4794 memset(&idiag, 0, sizeof(idiag));
4799 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
4800 * @file: The file pointer to read from.
4801 * @buf: The buffer to copy the data to.
4802 * @nbytes: The number of bytes to read.
4803 * @ppos: The position in the file to start reading from.
4806 * This routine reads data from the proper extent information according to
4807 * the idiag command, and copies to user @buf.
4810 * This function returns the amount of data that was read (this could be less
4811 * than @nbytes if the end of the file was reached) or a negative error value.
4814 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
4817 struct lpfc_debug *debug = file->private_data;
4818 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4823 /* This is a user read operation */
4824 debug->op = LPFC_IDIAG_OP_RD;
4827 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
4830 pbuffer = debug->buffer;
4833 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4836 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4837 if (ext_map & LPFC_EXT_ACC_AVAIL)
4838 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
4839 if (ext_map & LPFC_EXT_ACC_ALLOC)
4840 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
4841 if (ext_map & LPFC_EXT_ACC_DRIVR)
4842 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
4844 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4847 #undef lpfc_debugfs_op_disc_trc
4848 static const struct file_operations lpfc_debugfs_op_disc_trc = {
4849 .owner = THIS_MODULE,
4850 .open = lpfc_debugfs_disc_trc_open,
4851 .llseek = lpfc_debugfs_lseek,
4852 .read = lpfc_debugfs_read,
4853 .release = lpfc_debugfs_release,
4856 #undef lpfc_debugfs_op_nodelist
4857 static const struct file_operations lpfc_debugfs_op_nodelist = {
4858 .owner = THIS_MODULE,
4859 .open = lpfc_debugfs_nodelist_open,
4860 .llseek = lpfc_debugfs_lseek,
4861 .read = lpfc_debugfs_read,
4862 .release = lpfc_debugfs_release,
4865 #undef lpfc_debugfs_op_hbqinfo
4866 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
4867 .owner = THIS_MODULE,
4868 .open = lpfc_debugfs_hbqinfo_open,
4869 .llseek = lpfc_debugfs_lseek,
4870 .read = lpfc_debugfs_read,
4871 .release = lpfc_debugfs_release,
4874 #undef lpfc_debugfs_op_dumpHBASlim
4875 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
4876 .owner = THIS_MODULE,
4877 .open = lpfc_debugfs_dumpHBASlim_open,
4878 .llseek = lpfc_debugfs_lseek,
4879 .read = lpfc_debugfs_read,
4880 .release = lpfc_debugfs_release,
4883 #undef lpfc_debugfs_op_dumpHostSlim
4884 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
4885 .owner = THIS_MODULE,
4886 .open = lpfc_debugfs_dumpHostSlim_open,
4887 .llseek = lpfc_debugfs_lseek,
4888 .read = lpfc_debugfs_read,
4889 .release = lpfc_debugfs_release,
4892 #undef lpfc_debugfs_op_nvmestat
4893 static const struct file_operations lpfc_debugfs_op_nvmestat = {
4894 .owner = THIS_MODULE,
4895 .open = lpfc_debugfs_nvmestat_open,
4896 .llseek = lpfc_debugfs_lseek,
4897 .read = lpfc_debugfs_read,
4898 .write = lpfc_debugfs_nvmestat_write,
4899 .release = lpfc_debugfs_release,
4902 #undef lpfc_debugfs_op_nvmektime
4903 static const struct file_operations lpfc_debugfs_op_nvmektime = {
4904 .owner = THIS_MODULE,
4905 .open = lpfc_debugfs_nvmektime_open,
4906 .llseek = lpfc_debugfs_lseek,
4907 .read = lpfc_debugfs_read,
4908 .write = lpfc_debugfs_nvmektime_write,
4909 .release = lpfc_debugfs_release,
4912 #undef lpfc_debugfs_op_nvmeio_trc
4913 static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
4914 .owner = THIS_MODULE,
4915 .open = lpfc_debugfs_nvmeio_trc_open,
4916 .llseek = lpfc_debugfs_lseek,
4917 .read = lpfc_debugfs_read,
4918 .write = lpfc_debugfs_nvmeio_trc_write,
4919 .release = lpfc_debugfs_release,
4922 #undef lpfc_debugfs_op_cpucheck
4923 static const struct file_operations lpfc_debugfs_op_cpucheck = {
4924 .owner = THIS_MODULE,
4925 .open = lpfc_debugfs_cpucheck_open,
4926 .llseek = lpfc_debugfs_lseek,
4927 .read = lpfc_debugfs_read,
4928 .write = lpfc_debugfs_cpucheck_write,
4929 .release = lpfc_debugfs_release,
4932 #undef lpfc_debugfs_op_dumpData
4933 static const struct file_operations lpfc_debugfs_op_dumpData = {
4934 .owner = THIS_MODULE,
4935 .open = lpfc_debugfs_dumpData_open,
4936 .llseek = lpfc_debugfs_lseek,
4937 .read = lpfc_debugfs_read,
4938 .write = lpfc_debugfs_dumpDataDif_write,
4939 .release = lpfc_debugfs_dumpDataDif_release,
4942 #undef lpfc_debugfs_op_dumpDif
4943 static const struct file_operations lpfc_debugfs_op_dumpDif = {
4944 .owner = THIS_MODULE,
4945 .open = lpfc_debugfs_dumpDif_open,
4946 .llseek = lpfc_debugfs_lseek,
4947 .read = lpfc_debugfs_read,
4948 .write = lpfc_debugfs_dumpDataDif_write,
4949 .release = lpfc_debugfs_dumpDataDif_release,
4952 #undef lpfc_debugfs_op_dif_err
4953 static const struct file_operations lpfc_debugfs_op_dif_err = {
4954 .owner = THIS_MODULE,
4955 .open = simple_open,
4956 .llseek = lpfc_debugfs_lseek,
4957 .read = lpfc_debugfs_dif_err_read,
4958 .write = lpfc_debugfs_dif_err_write,
4959 .release = lpfc_debugfs_dif_err_release,
4962 #undef lpfc_debugfs_op_slow_ring_trc
4963 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
4964 .owner = THIS_MODULE,
4965 .open = lpfc_debugfs_slow_ring_trc_open,
4966 .llseek = lpfc_debugfs_lseek,
4967 .read = lpfc_debugfs_read,
4968 .release = lpfc_debugfs_release,
4971 static struct dentry *lpfc_debugfs_root = NULL;
4972 static atomic_t lpfc_debugfs_hba_count;
4975 * File operations for the iDiag debugfs
4977 #undef lpfc_idiag_op_pciCfg
4978 static const struct file_operations lpfc_idiag_op_pciCfg = {
4979 .owner = THIS_MODULE,
4980 .open = lpfc_idiag_open,
4981 .llseek = lpfc_debugfs_lseek,
4982 .read = lpfc_idiag_pcicfg_read,
4983 .write = lpfc_idiag_pcicfg_write,
4984 .release = lpfc_idiag_cmd_release,
4987 #undef lpfc_idiag_op_barAcc
4988 static const struct file_operations lpfc_idiag_op_barAcc = {
4989 .owner = THIS_MODULE,
4990 .open = lpfc_idiag_open,
4991 .llseek = lpfc_debugfs_lseek,
4992 .read = lpfc_idiag_baracc_read,
4993 .write = lpfc_idiag_baracc_write,
4994 .release = lpfc_idiag_cmd_release,
4997 #undef lpfc_idiag_op_queInfo
4998 static const struct file_operations lpfc_idiag_op_queInfo = {
4999 .owner = THIS_MODULE,
5000 .open = lpfc_idiag_open,
5001 .read = lpfc_idiag_queinfo_read,
5002 .release = lpfc_idiag_release,
5005 #undef lpfc_idiag_op_queAcc
5006 static const struct file_operations lpfc_idiag_op_queAcc = {
5007 .owner = THIS_MODULE,
5008 .open = lpfc_idiag_open,
5009 .llseek = lpfc_debugfs_lseek,
5010 .read = lpfc_idiag_queacc_read,
5011 .write = lpfc_idiag_queacc_write,
5012 .release = lpfc_idiag_cmd_release,
5015 #undef lpfc_idiag_op_drbAcc
5016 static const struct file_operations lpfc_idiag_op_drbAcc = {
5017 .owner = THIS_MODULE,
5018 .open = lpfc_idiag_open,
5019 .llseek = lpfc_debugfs_lseek,
5020 .read = lpfc_idiag_drbacc_read,
5021 .write = lpfc_idiag_drbacc_write,
5022 .release = lpfc_idiag_cmd_release,
5025 #undef lpfc_idiag_op_ctlAcc
5026 static const struct file_operations lpfc_idiag_op_ctlAcc = {
5027 .owner = THIS_MODULE,
5028 .open = lpfc_idiag_open,
5029 .llseek = lpfc_debugfs_lseek,
5030 .read = lpfc_idiag_ctlacc_read,
5031 .write = lpfc_idiag_ctlacc_write,
5032 .release = lpfc_idiag_cmd_release,
5035 #undef lpfc_idiag_op_mbxAcc
5036 static const struct file_operations lpfc_idiag_op_mbxAcc = {
5037 .owner = THIS_MODULE,
5038 .open = lpfc_idiag_open,
5039 .llseek = lpfc_debugfs_lseek,
5040 .read = lpfc_idiag_mbxacc_read,
5041 .write = lpfc_idiag_mbxacc_write,
5042 .release = lpfc_idiag_cmd_release,
5045 #undef lpfc_idiag_op_extAcc
5046 static const struct file_operations lpfc_idiag_op_extAcc = {
5047 .owner = THIS_MODULE,
5048 .open = lpfc_idiag_open,
5049 .llseek = lpfc_debugfs_lseek,
5050 .read = lpfc_idiag_extacc_read,
5051 .write = lpfc_idiag_extacc_write,
5052 .release = lpfc_idiag_cmd_release,
5057 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
5058 * @phba: Pointer to HBA context object.
5059 * @dmabuf: Pointer to a DMA buffer descriptor.
5062 * This routine dump a bsg pass-through non-embedded mailbox command with
5066 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
5067 enum mbox_type mbox_tp, enum dma_type dma_tp,
5068 enum sta_type sta_tp,
5069 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
5071 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5072 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
5073 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5075 uint32_t do_dump = 0;
5079 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
5082 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5083 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5084 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5085 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5087 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
5088 (*mbx_dump_cnt == 0) ||
5089 (*mbx_word_cnt == 0))
5092 if (*mbx_mbox_cmd != 0x9B)
5095 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5096 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5097 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
5098 pr_err("\nRead mbox command (x%x), "
5099 "nemb:0x%x, extbuf_cnt:%d:\n",
5100 sta_tp, nemb_tp, ext_buf);
5103 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5104 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5105 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
5106 pr_err("\nRead mbox buffer (x%x), "
5107 "nemb:0x%x, extbuf_seq:%d:\n",
5108 sta_tp, nemb_tp, ext_buf);
5111 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5112 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5113 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
5114 pr_err("\nWrite mbox command (x%x), "
5115 "nemb:0x%x, extbuf_cnt:%d:\n",
5116 sta_tp, nemb_tp, ext_buf);
5119 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5120 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5121 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
5122 pr_err("\nWrite mbox buffer (x%x), "
5123 "nemb:0x%x, extbuf_seq:%d:\n",
5124 sta_tp, nemb_tp, ext_buf);
5128 /* dump buffer content */
5130 pword = (uint32_t *)dmabuf->virt;
5131 for (i = 0; i < *mbx_word_cnt; i++) {
5134 pr_err("%s\n", line_buf);
5136 len += snprintf(line_buf+len,
5137 LPFC_MBX_ACC_LBUF_SZ-len,
5140 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5141 "%08x ", (uint32_t)*pword);
5145 pr_err("%s\n", line_buf);
5149 /* Clean out command structure on reaching dump count */
5150 if (*mbx_dump_cnt == 0)
5151 memset(&idiag, 0, sizeof(idiag));
5156 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5157 * @phba: Pointer to HBA context object.
5158 * @dmabuf: Pointer to a DMA buffer descriptor.
5161 * This routine dump a pass-through non-embedded mailbox command from issue
5165 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5167 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5168 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5169 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5175 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5178 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5179 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5180 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5181 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5183 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5184 (*mbx_dump_cnt == 0) ||
5185 (*mbx_word_cnt == 0))
5188 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5189 (*mbx_mbox_cmd != pmbox->mbxCommand))
5192 /* dump buffer content */
5193 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
5194 pr_err("Mailbox command:0x%x dump by word:\n",
5196 pword = (uint32_t *)pmbox;
5197 for (i = 0; i < *mbx_word_cnt; i++) {
5200 pr_err("%s\n", line_buf);
5202 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5203 len += snprintf(line_buf+len,
5204 LPFC_MBX_ACC_LBUF_SZ-len,
5207 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5209 ((uint32_t)*pword) & 0xffffffff);
5213 pr_err("%s\n", line_buf);
5216 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
5217 pr_err("Mailbox command:0x%x dump by byte:\n",
5219 pbyte = (uint8_t *)pmbox;
5220 for (i = 0; i < *mbx_word_cnt; i++) {
5223 pr_err("%s\n", line_buf);
5225 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5226 len += snprintf(line_buf+len,
5227 LPFC_MBX_ACC_LBUF_SZ-len,
5230 for (j = 0; j < 4; j++) {
5231 len += snprintf(line_buf+len,
5232 LPFC_MBX_ACC_LBUF_SZ-len,
5234 ((uint8_t)*pbyte) & 0xff);
5237 len += snprintf(line_buf+len,
5238 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5241 pr_err("%s\n", line_buf);
5246 /* Clean out command structure on reaching dump count */
5247 if (*mbx_dump_cnt == 0)
5248 memset(&idiag, 0, sizeof(idiag));
5254 * lpfc_debugfs_initialize - Initialize debugfs for a vport
5255 * @vport: The vport pointer to initialize.
5258 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5259 * If not already created, this routine will create the lpfc directory, and
5260 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5261 * also create each file used to access lpfc specific debugfs information.
5264 lpfc_debugfs_initialize(struct lpfc_vport *vport)
5266 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5267 struct lpfc_hba *phba = vport->phba;
5270 bool pport_setup = false;
5272 if (!lpfc_debugfs_enable)
5275 /* Setup lpfc root directory */
5276 if (!lpfc_debugfs_root) {
5277 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5278 atomic_set(&lpfc_debugfs_hba_count, 0);
5279 if (!lpfc_debugfs_root) {
5280 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5281 "0408 Cannot create debugfs root\n");
5285 if (!lpfc_debugfs_start_time)
5286 lpfc_debugfs_start_time = jiffies;
5288 /* Setup funcX directory for specific HBA PCI function */
5289 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
5290 if (!phba->hba_debugfs_root) {
5292 phba->hba_debugfs_root =
5293 debugfs_create_dir(name, lpfc_debugfs_root);
5294 if (!phba->hba_debugfs_root) {
5295 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5296 "0412 Cannot create debugfs hba\n");
5299 atomic_inc(&lpfc_debugfs_hba_count);
5300 atomic_set(&phba->debugfs_vport_count, 0);
5303 snprintf(name, sizeof(name), "hbqinfo");
5304 phba->debug_hbqinfo =
5305 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5306 phba->hba_debugfs_root,
5307 phba, &lpfc_debugfs_op_hbqinfo);
5308 if (!phba->debug_hbqinfo) {
5309 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5310 "0411 Cannot create debugfs hbqinfo\n");
5314 /* Setup dumpHBASlim */
5315 if (phba->sli_rev < LPFC_SLI_REV4) {
5316 snprintf(name, sizeof(name), "dumpHBASlim");
5317 phba->debug_dumpHBASlim =
5318 debugfs_create_file(name,
5319 S_IFREG|S_IRUGO|S_IWUSR,
5320 phba->hba_debugfs_root,
5321 phba, &lpfc_debugfs_op_dumpHBASlim);
5322 if (!phba->debug_dumpHBASlim) {
5323 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5324 "0413 Cannot create debugfs "
5329 phba->debug_dumpHBASlim = NULL;
5331 /* Setup dumpHostSlim */
5332 if (phba->sli_rev < LPFC_SLI_REV4) {
5333 snprintf(name, sizeof(name), "dumpHostSlim");
5334 phba->debug_dumpHostSlim =
5335 debugfs_create_file(name,
5336 S_IFREG|S_IRUGO|S_IWUSR,
5337 phba->hba_debugfs_root,
5338 phba, &lpfc_debugfs_op_dumpHostSlim);
5339 if (!phba->debug_dumpHostSlim) {
5340 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5341 "0414 Cannot create debugfs "
5346 phba->debug_dumpHostSlim = NULL;
5348 /* Setup dumpData */
5349 snprintf(name, sizeof(name), "dumpData");
5350 phba->debug_dumpData =
5351 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5352 phba->hba_debugfs_root,
5353 phba, &lpfc_debugfs_op_dumpData);
5354 if (!phba->debug_dumpData) {
5355 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5356 "0800 Cannot create debugfs dumpData\n");
5361 snprintf(name, sizeof(name), "dumpDif");
5362 phba->debug_dumpDif =
5363 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5364 phba->hba_debugfs_root,
5365 phba, &lpfc_debugfs_op_dumpDif);
5366 if (!phba->debug_dumpDif) {
5367 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5368 "0801 Cannot create debugfs dumpDif\n");
5372 /* Setup DIF Error Injections */
5373 snprintf(name, sizeof(name), "InjErrLBA");
5374 phba->debug_InjErrLBA =
5375 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5376 phba->hba_debugfs_root,
5377 phba, &lpfc_debugfs_op_dif_err);
5378 if (!phba->debug_InjErrLBA) {
5379 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5380 "0807 Cannot create debugfs InjErrLBA\n");
5383 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5385 snprintf(name, sizeof(name), "InjErrNPortID");
5386 phba->debug_InjErrNPortID =
5387 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5388 phba->hba_debugfs_root,
5389 phba, &lpfc_debugfs_op_dif_err);
5390 if (!phba->debug_InjErrNPortID) {
5391 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5392 "0809 Cannot create debugfs InjErrNPortID\n");
5396 snprintf(name, sizeof(name), "InjErrWWPN");
5397 phba->debug_InjErrWWPN =
5398 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5399 phba->hba_debugfs_root,
5400 phba, &lpfc_debugfs_op_dif_err);
5401 if (!phba->debug_InjErrWWPN) {
5402 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5403 "0810 Cannot create debugfs InjErrWWPN\n");
5407 snprintf(name, sizeof(name), "writeGuardInjErr");
5408 phba->debug_writeGuard =
5409 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5410 phba->hba_debugfs_root,
5411 phba, &lpfc_debugfs_op_dif_err);
5412 if (!phba->debug_writeGuard) {
5413 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5414 "0802 Cannot create debugfs writeGuard\n");
5418 snprintf(name, sizeof(name), "writeAppInjErr");
5419 phba->debug_writeApp =
5420 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5421 phba->hba_debugfs_root,
5422 phba, &lpfc_debugfs_op_dif_err);
5423 if (!phba->debug_writeApp) {
5424 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5425 "0803 Cannot create debugfs writeApp\n");
5429 snprintf(name, sizeof(name), "writeRefInjErr");
5430 phba->debug_writeRef =
5431 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5432 phba->hba_debugfs_root,
5433 phba, &lpfc_debugfs_op_dif_err);
5434 if (!phba->debug_writeRef) {
5435 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5436 "0804 Cannot create debugfs writeRef\n");
5440 snprintf(name, sizeof(name), "readGuardInjErr");
5441 phba->debug_readGuard =
5442 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5443 phba->hba_debugfs_root,
5444 phba, &lpfc_debugfs_op_dif_err);
5445 if (!phba->debug_readGuard) {
5446 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5447 "0808 Cannot create debugfs readGuard\n");
5451 snprintf(name, sizeof(name), "readAppInjErr");
5452 phba->debug_readApp =
5453 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5454 phba->hba_debugfs_root,
5455 phba, &lpfc_debugfs_op_dif_err);
5456 if (!phba->debug_readApp) {
5457 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5458 "0805 Cannot create debugfs readApp\n");
5462 snprintf(name, sizeof(name), "readRefInjErr");
5463 phba->debug_readRef =
5464 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5465 phba->hba_debugfs_root,
5466 phba, &lpfc_debugfs_op_dif_err);
5467 if (!phba->debug_readRef) {
5468 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5469 "0806 Cannot create debugfs readApp\n");
5473 /* Setup slow ring trace */
5474 if (lpfc_debugfs_max_slow_ring_trc) {
5475 num = lpfc_debugfs_max_slow_ring_trc - 1;
5476 if (num & lpfc_debugfs_max_slow_ring_trc) {
5477 /* Change to be a power of 2 */
5478 num = lpfc_debugfs_max_slow_ring_trc;
5484 lpfc_debugfs_max_slow_ring_trc = (1 << i);
5485 pr_err("lpfc_debugfs_max_disc_trc changed to "
5486 "%d\n", lpfc_debugfs_max_disc_trc);
5490 snprintf(name, sizeof(name), "slow_ring_trace");
5491 phba->debug_slow_ring_trc =
5492 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5493 phba->hba_debugfs_root,
5494 phba, &lpfc_debugfs_op_slow_ring_trc);
5495 if (!phba->debug_slow_ring_trc) {
5496 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5497 "0415 Cannot create debugfs "
5498 "slow_ring_trace\n");
5501 if (!phba->slow_ring_trc) {
5502 phba->slow_ring_trc = kmalloc(
5503 (sizeof(struct lpfc_debugfs_trc) *
5504 lpfc_debugfs_max_slow_ring_trc),
5506 if (!phba->slow_ring_trc) {
5507 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5508 "0416 Cannot create debugfs "
5509 "slow_ring buffer\n");
5512 atomic_set(&phba->slow_ring_trc_cnt, 0);
5513 memset(phba->slow_ring_trc, 0,
5514 (sizeof(struct lpfc_debugfs_trc) *
5515 lpfc_debugfs_max_slow_ring_trc));
5518 snprintf(name, sizeof(name), "nvmeio_trc");
5519 phba->debug_nvmeio_trc =
5520 debugfs_create_file(name, 0644,
5521 phba->hba_debugfs_root,
5522 phba, &lpfc_debugfs_op_nvmeio_trc);
5523 if (!phba->debug_nvmeio_trc) {
5524 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5525 "0574 No create debugfs nvmeio_trc\n");
5529 atomic_set(&phba->nvmeio_trc_cnt, 0);
5530 if (lpfc_debugfs_max_nvmeio_trc) {
5531 num = lpfc_debugfs_max_nvmeio_trc - 1;
5532 if (num & lpfc_debugfs_max_disc_trc) {
5533 /* Change to be a power of 2 */
5534 num = lpfc_debugfs_max_nvmeio_trc;
5540 lpfc_debugfs_max_nvmeio_trc = (1 << i);
5541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5542 "0575 lpfc_debugfs_max_nvmeio_trc "
5544 lpfc_debugfs_max_nvmeio_trc);
5546 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
5548 /* Allocate trace buffer and initialize */
5549 phba->nvmeio_trc = kzalloc(
5550 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5551 phba->nvmeio_trc_size), GFP_KERNEL);
5553 if (!phba->nvmeio_trc) {
5554 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5555 "0576 Cannot create debugfs "
5556 "nvmeio_trc buffer\n");
5559 phba->nvmeio_trc_on = 1;
5560 phba->nvmeio_trc_output_idx = 0;
5561 phba->nvmeio_trc = NULL;
5564 phba->nvmeio_trc_size = 0;
5565 phba->nvmeio_trc_on = 0;
5566 phba->nvmeio_trc_output_idx = 0;
5567 phba->nvmeio_trc = NULL;
5571 snprintf(name, sizeof(name), "vport%d", vport->vpi);
5572 if (!vport->vport_debugfs_root) {
5573 vport->vport_debugfs_root =
5574 debugfs_create_dir(name, phba->hba_debugfs_root);
5575 if (!vport->vport_debugfs_root) {
5576 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5577 "0417 Can't create debugfs\n");
5580 atomic_inc(&phba->debugfs_vport_count);
5583 if (lpfc_debugfs_max_disc_trc) {
5584 num = lpfc_debugfs_max_disc_trc - 1;
5585 if (num & lpfc_debugfs_max_disc_trc) {
5586 /* Change to be a power of 2 */
5587 num = lpfc_debugfs_max_disc_trc;
5593 lpfc_debugfs_max_disc_trc = (1 << i);
5594 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
5595 lpfc_debugfs_max_disc_trc);
5599 vport->disc_trc = kzalloc(
5600 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
5603 if (!vport->disc_trc) {
5604 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5605 "0418 Cannot create debugfs disc trace "
5609 atomic_set(&vport->disc_trc_cnt, 0);
5611 snprintf(name, sizeof(name), "discovery_trace");
5612 vport->debug_disc_trc =
5613 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5614 vport->vport_debugfs_root,
5615 vport, &lpfc_debugfs_op_disc_trc);
5616 if (!vport->debug_disc_trc) {
5617 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5618 "0419 Cannot create debugfs "
5619 "discovery_trace\n");
5622 snprintf(name, sizeof(name), "nodelist");
5623 vport->debug_nodelist =
5624 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5625 vport->vport_debugfs_root,
5626 vport, &lpfc_debugfs_op_nodelist);
5627 if (!vport->debug_nodelist) {
5628 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5629 "2985 Can't create debugfs nodelist\n");
5633 snprintf(name, sizeof(name), "nvmestat");
5634 vport->debug_nvmestat =
5635 debugfs_create_file(name, 0644,
5636 vport->vport_debugfs_root,
5637 vport, &lpfc_debugfs_op_nvmestat);
5638 if (!vport->debug_nvmestat) {
5639 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5640 "0811 Cannot create debugfs nvmestat\n");
5644 snprintf(name, sizeof(name), "nvmektime");
5645 vport->debug_nvmektime =
5646 debugfs_create_file(name, 0644,
5647 vport->vport_debugfs_root,
5648 vport, &lpfc_debugfs_op_nvmektime);
5649 if (!vport->debug_nvmektime) {
5650 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5651 "0815 Cannot create debugfs nvmektime\n");
5655 snprintf(name, sizeof(name), "cpucheck");
5656 vport->debug_cpucheck =
5657 debugfs_create_file(name, 0644,
5658 vport->vport_debugfs_root,
5659 vport, &lpfc_debugfs_op_cpucheck);
5660 if (!vport->debug_cpucheck) {
5661 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5662 "0819 Cannot create debugfs cpucheck\n");
5667 * The following section is for additional directories/files for the
5675 * iDiag debugfs root entry points for SLI4 device only
5677 if (phba->sli_rev < LPFC_SLI_REV4)
5680 snprintf(name, sizeof(name), "iDiag");
5681 if (!phba->idiag_root) {
5683 debugfs_create_dir(name, phba->hba_debugfs_root);
5684 if (!phba->idiag_root) {
5685 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5686 "2922 Can't create idiag debugfs\n");
5689 /* Initialize iDiag data structure */
5690 memset(&idiag, 0, sizeof(idiag));
5693 /* iDiag read PCI config space */
5694 snprintf(name, sizeof(name), "pciCfg");
5695 if (!phba->idiag_pci_cfg) {
5696 phba->idiag_pci_cfg =
5697 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5698 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
5699 if (!phba->idiag_pci_cfg) {
5700 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5701 "2923 Can't create idiag debugfs\n");
5704 idiag.offset.last_rd = 0;
5707 /* iDiag PCI BAR access */
5708 snprintf(name, sizeof(name), "barAcc");
5709 if (!phba->idiag_bar_acc) {
5710 phba->idiag_bar_acc =
5711 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5712 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
5713 if (!phba->idiag_bar_acc) {
5714 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5715 "3056 Can't create idiag debugfs\n");
5718 idiag.offset.last_rd = 0;
5721 /* iDiag get PCI function queue information */
5722 snprintf(name, sizeof(name), "queInfo");
5723 if (!phba->idiag_que_info) {
5724 phba->idiag_que_info =
5725 debugfs_create_file(name, S_IFREG|S_IRUGO,
5726 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
5727 if (!phba->idiag_que_info) {
5728 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5729 "2924 Can't create idiag debugfs\n");
5734 /* iDiag access PCI function queue */
5735 snprintf(name, sizeof(name), "queAcc");
5736 if (!phba->idiag_que_acc) {
5737 phba->idiag_que_acc =
5738 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5739 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
5740 if (!phba->idiag_que_acc) {
5741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5742 "2926 Can't create idiag debugfs\n");
5747 /* iDiag access PCI function doorbell registers */
5748 snprintf(name, sizeof(name), "drbAcc");
5749 if (!phba->idiag_drb_acc) {
5750 phba->idiag_drb_acc =
5751 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5752 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
5753 if (!phba->idiag_drb_acc) {
5754 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5755 "2927 Can't create idiag debugfs\n");
5760 /* iDiag access PCI function control registers */
5761 snprintf(name, sizeof(name), "ctlAcc");
5762 if (!phba->idiag_ctl_acc) {
5763 phba->idiag_ctl_acc =
5764 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5765 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
5766 if (!phba->idiag_ctl_acc) {
5767 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5768 "2981 Can't create idiag debugfs\n");
5773 /* iDiag access mbox commands */
5774 snprintf(name, sizeof(name), "mbxAcc");
5775 if (!phba->idiag_mbx_acc) {
5776 phba->idiag_mbx_acc =
5777 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5778 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
5779 if (!phba->idiag_mbx_acc) {
5780 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5781 "2980 Can't create idiag debugfs\n");
5786 /* iDiag extents access commands */
5787 if (phba->sli4_hba.extents_in_use) {
5788 snprintf(name, sizeof(name), "extAcc");
5789 if (!phba->idiag_ext_acc) {
5790 phba->idiag_ext_acc =
5791 debugfs_create_file(name,
5792 S_IFREG|S_IRUGO|S_IWUSR,
5793 phba->idiag_root, phba,
5794 &lpfc_idiag_op_extAcc);
5795 if (!phba->idiag_ext_acc) {
5796 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5810 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
5811 * @vport: The vport pointer to remove from debugfs.
5814 * When Debugfs is configured this routine removes debugfs file system elements
5815 * that are specific to this vport. It also checks to see if there are any
5816 * users left for the debugfs directories associated with the HBA and driver. If
5817 * this is the last user of the HBA directory or driver directory then it will
5818 * remove those from the debugfs infrastructure as well.
5821 lpfc_debugfs_terminate(struct lpfc_vport *vport)
5823 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5824 struct lpfc_hba *phba = vport->phba;
5826 kfree(vport->disc_trc);
5827 vport->disc_trc = NULL;
5829 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
5830 vport->debug_disc_trc = NULL;
5832 debugfs_remove(vport->debug_nodelist); /* nodelist */
5833 vport->debug_nodelist = NULL;
5835 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
5836 vport->debug_nvmestat = NULL;
5838 debugfs_remove(vport->debug_nvmektime); /* nvmektime */
5839 vport->debug_nvmektime = NULL;
5841 debugfs_remove(vport->debug_cpucheck); /* cpucheck */
5842 vport->debug_cpucheck = NULL;
5844 if (vport->vport_debugfs_root) {
5845 debugfs_remove(vport->vport_debugfs_root); /* vportX */
5846 vport->vport_debugfs_root = NULL;
5847 atomic_dec(&phba->debugfs_vport_count);
5850 if (atomic_read(&phba->debugfs_vport_count) == 0) {
5852 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
5853 phba->debug_hbqinfo = NULL;
5855 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
5856 phba->debug_dumpHBASlim = NULL;
5858 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
5859 phba->debug_dumpHostSlim = NULL;
5861 debugfs_remove(phba->debug_dumpData); /* dumpData */
5862 phba->debug_dumpData = NULL;
5864 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
5865 phba->debug_dumpDif = NULL;
5867 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
5868 phba->debug_InjErrLBA = NULL;
5870 debugfs_remove(phba->debug_InjErrNPortID);
5871 phba->debug_InjErrNPortID = NULL;
5873 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
5874 phba->debug_InjErrWWPN = NULL;
5876 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
5877 phba->debug_writeGuard = NULL;
5879 debugfs_remove(phba->debug_writeApp); /* writeApp */
5880 phba->debug_writeApp = NULL;
5882 debugfs_remove(phba->debug_writeRef); /* writeRef */
5883 phba->debug_writeRef = NULL;
5885 debugfs_remove(phba->debug_readGuard); /* readGuard */
5886 phba->debug_readGuard = NULL;
5888 debugfs_remove(phba->debug_readApp); /* readApp */
5889 phba->debug_readApp = NULL;
5891 debugfs_remove(phba->debug_readRef); /* readRef */
5892 phba->debug_readRef = NULL;
5894 kfree(phba->slow_ring_trc);
5895 phba->slow_ring_trc = NULL;
5897 /* slow_ring_trace */
5898 debugfs_remove(phba->debug_slow_ring_trc);
5899 phba->debug_slow_ring_trc = NULL;
5901 debugfs_remove(phba->debug_nvmeio_trc);
5902 phba->debug_nvmeio_trc = NULL;
5904 kfree(phba->nvmeio_trc);
5905 phba->nvmeio_trc = NULL;
5910 if (phba->sli_rev == LPFC_SLI_REV4) {
5912 debugfs_remove(phba->idiag_ext_acc);
5913 phba->idiag_ext_acc = NULL;
5916 debugfs_remove(phba->idiag_mbx_acc);
5917 phba->idiag_mbx_acc = NULL;
5920 debugfs_remove(phba->idiag_ctl_acc);
5921 phba->idiag_ctl_acc = NULL;
5924 debugfs_remove(phba->idiag_drb_acc);
5925 phba->idiag_drb_acc = NULL;
5928 debugfs_remove(phba->idiag_que_acc);
5929 phba->idiag_que_acc = NULL;
5932 debugfs_remove(phba->idiag_que_info);
5933 phba->idiag_que_info = NULL;
5936 debugfs_remove(phba->idiag_bar_acc);
5937 phba->idiag_bar_acc = NULL;
5940 debugfs_remove(phba->idiag_pci_cfg);
5941 phba->idiag_pci_cfg = NULL;
5943 /* Finally remove the iDiag debugfs root */
5944 debugfs_remove(phba->idiag_root);
5945 phba->idiag_root = NULL;
5948 if (phba->hba_debugfs_root) {
5949 debugfs_remove(phba->hba_debugfs_root); /* fnX */
5950 phba->hba_debugfs_root = NULL;
5951 atomic_dec(&lpfc_debugfs_hba_count);
5954 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
5955 debugfs_remove(lpfc_debugfs_root); /* lpfc */
5956 lpfc_debugfs_root = NULL;
5964 * Driver debug utility routines outside of debugfs. The debug utility
5965 * routines implemented here is intended to be used in the instrumented
5966 * debug driver for debugging host or port issues.
5970 * lpfc_debug_dump_all_queues - dump all the queues with a hba
5971 * @phba: Pointer to HBA context object.
5973 * This function dumps entries of all the queues asociated with the @phba.
5976 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
5981 * Dump Work Queues (WQs)
5983 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
5984 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
5985 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
5987 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5988 lpfc_debug_dump_wq(phba, DUMP_FCP, idx);
5990 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5991 lpfc_debug_dump_wq(phba, DUMP_NVME, idx);
5993 lpfc_debug_dump_hdr_rq(phba);
5994 lpfc_debug_dump_dat_rq(phba);
5996 * Dump Complete Queues (CQs)
5998 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
5999 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
6000 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
6002 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
6003 lpfc_debug_dump_cq(phba, DUMP_FCP, idx);
6005 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
6006 lpfc_debug_dump_cq(phba, DUMP_NVME, idx);
6009 * Dump Event Queues (EQs)
6011 for (idx = 0; idx < phba->io_channel_irqs; idx++)
6012 lpfc_debug_dump_hba_eq(phba, idx);