1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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)
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 lpfc_nvmet_tgtport *tgtp;
554 struct nvme_fc_remote_port *nrport;
556 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
558 len += snprintf(buf+len, size-len, "\nFCP Nodelist Entries ...\n");
559 spin_lock_irq(shost->host_lock);
560 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
562 len += snprintf(buf+len, size-len,
563 "Missing Nodelist Entries\n");
567 switch (ndlp->nlp_state) {
568 case NLP_STE_UNUSED_NODE:
571 case NLP_STE_PLOGI_ISSUE:
574 case NLP_STE_ADISC_ISSUE:
577 case NLP_STE_REG_LOGIN_ISSUE:
580 case NLP_STE_PRLI_ISSUE:
583 case NLP_STE_LOGO_ISSUE:
586 case NLP_STE_UNMAPPED_NODE:
589 case NLP_STE_MAPPED_NODE:
592 case NLP_STE_NPR_NODE:
598 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
599 statep, ndlp->nlp_DID);
600 len += snprintf(buf+len, size-len,
602 wwn_to_u64(ndlp->nlp_portname.u.wwn));
603 len += snprintf(buf+len, size-len,
605 wwn_to_u64(ndlp->nlp_nodename.u.wwn));
606 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
607 len += snprintf(buf+len, size-len, "RPI:%03d ",
610 len += snprintf(buf+len, size-len, "RPI:none ");
611 len += snprintf(buf+len, size-len, "flag:x%08x ",
614 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
615 if (ndlp->nlp_type & NLP_FC_NODE)
616 len += snprintf(buf+len, size-len, "FC_NODE ");
617 if (ndlp->nlp_type & NLP_FABRIC)
618 len += snprintf(buf+len, size-len, "FABRIC ");
619 if (ndlp->nlp_type & NLP_FCP_TARGET)
620 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
622 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
623 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
624 if (ndlp->nlp_type & NLP_NVME_TARGET)
625 len += snprintf(buf + len,
626 size - len, "NVME_TGT sid:%d ",
628 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
629 len += snprintf(buf + len,
630 size - len, "NVME_INITIATOR ");
631 len += snprintf(buf+len, size-len, "usgmap:%x ",
633 len += snprintf(buf+len, size-len, "refcnt:%x",
634 kref_read(&ndlp->kref));
635 len += snprintf(buf+len, size-len, "\n");
637 spin_unlock_irq(shost->host_lock);
639 if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
640 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
641 len += snprintf(buf + len, size - len,
642 "\nNVME Targetport Entry ...\n");
644 /* Port state is only one of two values for now. */
645 if (phba->targetport->port_id)
646 statep = "REGISTERED";
649 len += snprintf(buf + len, size - len,
650 "TGT WWNN x%llx WWPN x%llx State %s\n",
651 wwn_to_u64(vport->fc_nodename.u.wwn),
652 wwn_to_u64(vport->fc_portname.u.wwn),
654 len += snprintf(buf + len, size - len,
655 " Targetport DID x%06x\n",
656 phba->targetport->port_id);
660 len += snprintf(buf + len, size - len,
661 "\nNVME Lport/Rport Entries ...\n");
663 localport = vport->localport;
667 spin_lock_irq(shost->host_lock);
669 /* Port state is only one of two values for now. */
670 if (localport->port_id)
675 len += snprintf(buf + len, size - len,
676 "Lport DID x%06x PortState %s\n",
677 localport->port_id, statep);
679 len += snprintf(buf + len, size - len, "\tRport List:\n");
680 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
681 /* local short-hand pointer. */
685 nrport = ndlp->nrport->remoteport;
687 /* Port state is only one of two values for now. */
688 switch (nrport->port_state) {
689 case FC_OBJSTATE_ONLINE:
692 case FC_OBJSTATE_UNKNOWN:
696 statep = "UNSUPPORTED";
700 /* Tab in to show lport ownership. */
701 len += snprintf(buf + len, size - len,
702 "\t%s Port ID:x%06x ",
703 statep, nrport->port_id);
704 len += snprintf(buf + len, size - len, "WWPN x%llx ",
706 len += snprintf(buf + len, size - len, "WWNN x%llx ",
709 /* An NVME rport can have multiple roles. */
710 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
711 len += snprintf(buf + len, size - len,
713 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
714 len += snprintf(buf + len, size - len,
716 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
717 len += snprintf(buf + len, size - len,
719 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
720 FC_PORT_ROLE_NVME_TARGET |
721 FC_PORT_ROLE_NVME_DISCOVERY))
722 len += snprintf(buf + len, size - len,
725 /* Terminate the string. */
726 len += snprintf(buf + len, size - len, "\n");
729 spin_unlock_irq(shost->host_lock);
735 * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
736 * @vport: The vport to gather target node info from.
737 * @buf: The buffer to dump log into.
738 * @size: The maximum amount of data to process.
741 * This routine dumps the NVME statistics associated with @vport
744 * This routine returns the amount of bytes that were dumped into @buf and will
748 lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
750 struct lpfc_hba *phba = vport->phba;
751 struct lpfc_nvmet_tgtport *tgtp;
752 struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp;
753 uint64_t tot, data1, data2, data3;
757 if (phba->nvmet_support) {
758 if (!phba->targetport)
760 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
761 len += snprintf(buf + len, size - len,
762 "\nNVME Targetport Statistics\n");
764 len += snprintf(buf + len, size - len,
765 "LS: Rcv %08x Drop %08x Abort %08x\n",
766 atomic_read(&tgtp->rcv_ls_req_in),
767 atomic_read(&tgtp->rcv_ls_req_drop),
768 atomic_read(&tgtp->xmt_ls_abort));
769 if (atomic_read(&tgtp->rcv_ls_req_in) !=
770 atomic_read(&tgtp->rcv_ls_req_out)) {
771 len += snprintf(buf + len, size - len,
772 "Rcv LS: in %08x != out %08x\n",
773 atomic_read(&tgtp->rcv_ls_req_in),
774 atomic_read(&tgtp->rcv_ls_req_out));
777 len += snprintf(buf + len, size - len,
778 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
779 atomic_read(&tgtp->xmt_ls_rsp),
780 atomic_read(&tgtp->xmt_ls_drop),
781 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
782 atomic_read(&tgtp->xmt_ls_rsp_error));
784 len += snprintf(buf + len, size - len,
785 "FCP: Rcv %08x Defer %08x Release %08x "
787 atomic_read(&tgtp->rcv_fcp_cmd_in),
788 atomic_read(&tgtp->rcv_fcp_cmd_defer),
789 atomic_read(&tgtp->xmt_fcp_release),
790 atomic_read(&tgtp->rcv_fcp_cmd_drop));
792 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
793 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
794 len += snprintf(buf + len, size - len,
795 "Rcv FCP: in %08x != out %08x\n",
796 atomic_read(&tgtp->rcv_fcp_cmd_in),
797 atomic_read(&tgtp->rcv_fcp_cmd_out));
800 len += snprintf(buf + len, size - len,
801 "FCP Rsp: read %08x readrsp %08x "
802 "write %08x rsp %08x\n",
803 atomic_read(&tgtp->xmt_fcp_read),
804 atomic_read(&tgtp->xmt_fcp_read_rsp),
805 atomic_read(&tgtp->xmt_fcp_write),
806 atomic_read(&tgtp->xmt_fcp_rsp));
808 len += snprintf(buf + len, size - len,
809 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
810 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
811 atomic_read(&tgtp->xmt_fcp_rsp_error),
812 atomic_read(&tgtp->xmt_fcp_rsp_drop));
814 len += snprintf(buf + len, size - len,
815 "ABORT: Xmt %08x Cmpl %08x\n",
816 atomic_read(&tgtp->xmt_fcp_abort),
817 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
819 len += snprintf(buf + len, size - len,
820 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
821 atomic_read(&tgtp->xmt_abort_sol),
822 atomic_read(&tgtp->xmt_abort_unsol),
823 atomic_read(&tgtp->xmt_abort_rsp),
824 atomic_read(&tgtp->xmt_abort_rsp_error));
826 len += snprintf(buf + len, size - len, "\n");
829 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
830 list_for_each_entry_safe(ctxp, next_ctxp,
831 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
835 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
837 len += snprintf(buf + len, size - len,
838 "ABORT: %d ctx entries\n", cnt);
839 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
840 list_for_each_entry_safe(ctxp, next_ctxp,
841 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
843 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
845 len += snprintf(buf + len, size - len,
846 "Entry: oxid %x state %x "
848 ctxp->oxid, ctxp->state,
851 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
854 spin_lock(&phba->sli4_hba.nvmet_ctx_get_lock);
855 spin_lock(&phba->sli4_hba.nvmet_ctx_put_lock);
856 tot = phba->sli4_hba.nvmet_xri_cnt -
857 (phba->sli4_hba.nvmet_ctx_get_cnt +
858 phba->sli4_hba.nvmet_ctx_put_cnt);
859 spin_unlock(&phba->sli4_hba.nvmet_ctx_put_lock);
860 spin_unlock(&phba->sli4_hba.nvmet_ctx_get_lock);
862 len += snprintf(buf + len, size - len,
863 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
864 "CTX Outstanding %08llx\n",
865 phba->sli4_hba.nvmet_xri_cnt,
866 phba->sli4_hba.nvmet_io_wait_cnt,
867 phba->sli4_hba.nvmet_io_wait_total,
870 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
873 len += snprintf(buf + len, size - len,
874 "\nNVME Lport Statistics\n");
876 len += snprintf(buf + len, size - len,
877 "LS: Xmt %016x Cmpl %016x\n",
878 atomic_read(&phba->fc4NvmeLsRequests),
879 atomic_read(&phba->fc4NvmeLsCmpls));
881 tot = atomic_read(&phba->fc4NvmeIoCmpls);
882 data1 = atomic_read(&phba->fc4NvmeInputRequests);
883 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
884 data3 = atomic_read(&phba->fc4NvmeControlRequests);
886 len += snprintf(buf + len, size - len,
887 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
888 data1, data2, data3);
890 len += snprintf(buf + len, size - len,
891 " Cmpl %016llx Outstanding %016llx\n",
892 tot, (data1 + data2 + data3) - tot);
900 * lpfc_debugfs_nvmektime_data - Dump target node list to a buffer
901 * @vport: The vport to gather target node info from.
902 * @buf: The buffer to dump log into.
903 * @size: The maximum amount of data to process.
906 * This routine dumps the NVME statistics associated with @vport
909 * This routine returns the amount of bytes that were dumped into @buf and will
913 lpfc_debugfs_nvmektime_data(struct lpfc_vport *vport, char *buf, int size)
915 struct lpfc_hba *phba = vport->phba;
918 if (phba->nvmet_support == 0) {
920 len += snprintf(buf + len, PAGE_SIZE - len,
921 "ktime %s: Total Samples: %lld\n",
922 (phba->ktime_on ? "Enabled" : "Disabled"),
923 phba->ktime_data_samples);
924 if (phba->ktime_data_samples == 0)
928 buf + len, PAGE_SIZE - len,
929 "Segment 1: Last NVME Cmd cmpl "
930 "done -to- Start of next NVME cnd (in driver)\n");
932 buf + len, PAGE_SIZE - len,
933 "avg:%08lld min:%08lld max %08lld\n",
934 div_u64(phba->ktime_seg1_total,
935 phba->ktime_data_samples),
936 phba->ktime_seg1_min,
937 phba->ktime_seg1_max);
939 buf + len, PAGE_SIZE - len,
940 "Segment 2: Driver start of NVME cmd "
941 "-to- Firmware WQ doorbell\n");
943 buf + len, PAGE_SIZE - len,
944 "avg:%08lld min:%08lld max %08lld\n",
945 div_u64(phba->ktime_seg2_total,
946 phba->ktime_data_samples),
947 phba->ktime_seg2_min,
948 phba->ktime_seg2_max);
950 buf + len, PAGE_SIZE - len,
951 "Segment 3: Firmware WQ doorbell -to- "
954 buf + len, PAGE_SIZE - len,
955 "avg:%08lld min:%08lld max %08lld\n",
956 div_u64(phba->ktime_seg3_total,
957 phba->ktime_data_samples),
958 phba->ktime_seg3_min,
959 phba->ktime_seg3_max);
961 buf + len, PAGE_SIZE - len,
962 "Segment 4: MSI-X ISR cmpl -to- "
965 buf + len, PAGE_SIZE - len,
966 "avg:%08lld min:%08lld max %08lld\n",
967 div_u64(phba->ktime_seg4_total,
968 phba->ktime_data_samples),
969 phba->ktime_seg4_min,
970 phba->ktime_seg4_max);
972 buf + len, PAGE_SIZE - len,
973 "Total IO avg time: %08lld\n",
974 div_u64(phba->ktime_seg1_total +
975 phba->ktime_seg2_total +
976 phba->ktime_seg3_total +
977 phba->ktime_seg4_total,
978 phba->ktime_data_samples));
983 len += snprintf(buf + len, PAGE_SIZE-len,
984 "ktime %s: Total Samples: %lld %lld\n",
985 (phba->ktime_on ? "Enabled" : "Disabled"),
986 phba->ktime_data_samples,
987 phba->ktime_status_samples);
988 if (phba->ktime_data_samples == 0)
991 len += snprintf(buf + len, PAGE_SIZE-len,
992 "Segment 1: MSI-X ISR Rcv cmd -to- "
993 "cmd pass to NVME Layer\n");
994 len += snprintf(buf + len, PAGE_SIZE-len,
995 "avg:%08lld min:%08lld max %08lld\n",
996 div_u64(phba->ktime_seg1_total,
997 phba->ktime_data_samples),
998 phba->ktime_seg1_min,
999 phba->ktime_seg1_max);
1000 len += snprintf(buf + len, PAGE_SIZE-len,
1001 "Segment 2: cmd pass to NVME Layer- "
1002 "-to- Driver rcv cmd OP (action)\n");
1003 len += snprintf(buf + len, PAGE_SIZE-len,
1004 "avg:%08lld min:%08lld max %08lld\n",
1005 div_u64(phba->ktime_seg2_total,
1006 phba->ktime_data_samples),
1007 phba->ktime_seg2_min,
1008 phba->ktime_seg2_max);
1009 len += snprintf(buf + len, PAGE_SIZE-len,
1010 "Segment 3: Driver rcv cmd OP -to- "
1011 "Firmware WQ doorbell: cmd\n");
1012 len += snprintf(buf + len, PAGE_SIZE-len,
1013 "avg:%08lld min:%08lld max %08lld\n",
1014 div_u64(phba->ktime_seg3_total,
1015 phba->ktime_data_samples),
1016 phba->ktime_seg3_min,
1017 phba->ktime_seg3_max);
1018 len += snprintf(buf + len, PAGE_SIZE-len,
1019 "Segment 4: Firmware WQ doorbell: cmd "
1020 "-to- MSI-X ISR for cmd cmpl\n");
1021 len += snprintf(buf + len, PAGE_SIZE-len,
1022 "avg:%08lld min:%08lld max %08lld\n",
1023 div_u64(phba->ktime_seg4_total,
1024 phba->ktime_data_samples),
1025 phba->ktime_seg4_min,
1026 phba->ktime_seg4_max);
1027 len += snprintf(buf + len, PAGE_SIZE-len,
1028 "Segment 5: MSI-X ISR for cmd cmpl "
1029 "-to- NVME layer passed cmd done\n");
1030 len += snprintf(buf + len, PAGE_SIZE-len,
1031 "avg:%08lld min:%08lld max %08lld\n",
1032 div_u64(phba->ktime_seg5_total,
1033 phba->ktime_data_samples),
1034 phba->ktime_seg5_min,
1035 phba->ktime_seg5_max);
1037 if (phba->ktime_status_samples == 0) {
1038 len += snprintf(buf + len, PAGE_SIZE-len,
1039 "Total: cmd received by MSI-X ISR "
1040 "-to- cmd completed on wire\n");
1041 len += snprintf(buf + len, PAGE_SIZE-len,
1042 "avg:%08lld min:%08lld "
1044 div_u64(phba->ktime_seg10_total,
1045 phba->ktime_data_samples),
1046 phba->ktime_seg10_min,
1047 phba->ktime_seg10_max);
1051 len += snprintf(buf + len, PAGE_SIZE-len,
1052 "Segment 6: NVME layer passed cmd done "
1053 "-to- Driver rcv rsp status OP\n");
1054 len += snprintf(buf + len, PAGE_SIZE-len,
1055 "avg:%08lld min:%08lld max %08lld\n",
1056 div_u64(phba->ktime_seg6_total,
1057 phba->ktime_status_samples),
1058 phba->ktime_seg6_min,
1059 phba->ktime_seg6_max);
1060 len += snprintf(buf + len, PAGE_SIZE-len,
1061 "Segment 7: Driver rcv rsp status OP "
1062 "-to- Firmware WQ doorbell: status\n");
1063 len += snprintf(buf + len, PAGE_SIZE-len,
1064 "avg:%08lld min:%08lld max %08lld\n",
1065 div_u64(phba->ktime_seg7_total,
1066 phba->ktime_status_samples),
1067 phba->ktime_seg7_min,
1068 phba->ktime_seg7_max);
1069 len += snprintf(buf + len, PAGE_SIZE-len,
1070 "Segment 8: Firmware WQ doorbell: status"
1071 " -to- MSI-X ISR for status cmpl\n");
1072 len += snprintf(buf + len, PAGE_SIZE-len,
1073 "avg:%08lld min:%08lld max %08lld\n",
1074 div_u64(phba->ktime_seg8_total,
1075 phba->ktime_status_samples),
1076 phba->ktime_seg8_min,
1077 phba->ktime_seg8_max);
1078 len += snprintf(buf + len, PAGE_SIZE-len,
1079 "Segment 9: MSI-X ISR for status cmpl "
1080 "-to- NVME layer passed status done\n");
1081 len += snprintf(buf + len, PAGE_SIZE-len,
1082 "avg:%08lld min:%08lld max %08lld\n",
1083 div_u64(phba->ktime_seg9_total,
1084 phba->ktime_status_samples),
1085 phba->ktime_seg9_min,
1086 phba->ktime_seg9_max);
1087 len += snprintf(buf + len, PAGE_SIZE-len,
1088 "Total: cmd received by MSI-X ISR -to- "
1089 "cmd completed on wire\n");
1090 len += snprintf(buf + len, PAGE_SIZE-len,
1091 "avg:%08lld min:%08lld max %08lld\n",
1092 div_u64(phba->ktime_seg10_total,
1093 phba->ktime_status_samples),
1094 phba->ktime_seg10_min,
1095 phba->ktime_seg10_max);
1100 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1101 * @phba: The phba to gather target node info from.
1102 * @buf: The buffer to dump log into.
1103 * @size: The maximum amount of data to process.
1106 * This routine dumps the NVME IO trace associated with @phba
1109 * This routine returns the amount of bytes that were dumped into @buf and will
1113 lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1115 struct lpfc_debugfs_nvmeio_trc *dtp;
1116 int i, state, index, skip;
1119 state = phba->nvmeio_trc_on;
1121 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1122 (phba->nvmeio_trc_size - 1);
1123 skip = phba->nvmeio_trc_output_idx;
1125 len += snprintf(buf + len, size - len,
1126 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1127 (phba->nvmet_support ? "NVME" : "NVMET"),
1128 (state ? "Enabled" : "Disabled"),
1129 index, skip, phba->nvmeio_trc_size);
1131 if (!phba->nvmeio_trc || state)
1134 /* trace MUST bhe off to continue */
1136 for (i = index; i < phba->nvmeio_trc_size; i++) {
1141 dtp = phba->nvmeio_trc + i;
1142 phba->nvmeio_trc_output_idx++;
1147 len += snprintf(buf + len, size - len, dtp->fmt,
1148 dtp->data1, dtp->data2, dtp->data3);
1150 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1151 phba->nvmeio_trc_output_idx = 0;
1152 len += snprintf(buf + len, size - len,
1153 "Trace Complete\n");
1157 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1158 len += snprintf(buf + len, size - len,
1159 "Trace Continue (%d of %d)\n",
1160 phba->nvmeio_trc_output_idx,
1161 phba->nvmeio_trc_size);
1165 for (i = 0; i < index; i++) {
1170 dtp = phba->nvmeio_trc + i;
1171 phba->nvmeio_trc_output_idx++;
1176 len += snprintf(buf + len, size - len, dtp->fmt,
1177 dtp->data1, dtp->data2, dtp->data3);
1179 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1180 phba->nvmeio_trc_output_idx = 0;
1181 len += snprintf(buf + len, size - len,
1182 "Trace Complete\n");
1186 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1187 len += snprintf(buf + len, size - len,
1188 "Trace Continue (%d of %d)\n",
1189 phba->nvmeio_trc_output_idx,
1190 phba->nvmeio_trc_size);
1195 len += snprintf(buf + len, size - len,
1202 * lpfc_debugfs_cpucheck_data - Dump target node list to a buffer
1203 * @vport: The vport to gather target node info from.
1204 * @buf: The buffer to dump log into.
1205 * @size: The maximum amount of data to process.
1208 * This routine dumps the NVME statistics associated with @vport
1211 * This routine returns the amount of bytes that were dumped into @buf and will
1215 lpfc_debugfs_cpucheck_data(struct lpfc_vport *vport, char *buf, int size)
1217 struct lpfc_hba *phba = vport->phba;
1220 uint32_t tot_xmt = 0;
1221 uint32_t tot_rcv = 0;
1222 uint32_t tot_cmpl = 0;
1223 uint32_t tot_ccmpl = 0;
1225 if (phba->nvmet_support == 0) {
1226 /* NVME Initiator */
1227 len += snprintf(buf + len, PAGE_SIZE - len,
1229 (phba->cpucheck_on & LPFC_CHECK_NVME_IO ?
1230 "Enabled" : "Disabled"));
1231 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1232 if (i >= LPFC_CHECK_CPU_CNT)
1234 len += snprintf(buf + len, PAGE_SIZE - len,
1235 "%02d: xmit x%08x cmpl x%08x\n",
1236 i, phba->cpucheck_xmt_io[i],
1237 phba->cpucheck_cmpl_io[i]);
1238 tot_xmt += phba->cpucheck_xmt_io[i];
1239 tot_cmpl += phba->cpucheck_cmpl_io[i];
1241 len += snprintf(buf + len, PAGE_SIZE - len,
1242 "tot:xmit x%08x cmpl x%08x\n",
1248 len += snprintf(buf + len, PAGE_SIZE - len,
1250 (phba->cpucheck_on & LPFC_CHECK_NVMET_IO ?
1251 "IO Enabled - " : "IO Disabled - "));
1252 len += snprintf(buf + len, PAGE_SIZE - len,
1254 (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV ?
1255 "Rcv Enabled\n" : "Rcv Disabled\n"));
1256 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1257 if (i >= LPFC_CHECK_CPU_CNT)
1259 len += snprintf(buf + len, PAGE_SIZE - len,
1260 "%02d: xmit x%08x ccmpl x%08x "
1261 "cmpl x%08x rcv x%08x\n",
1262 i, phba->cpucheck_xmt_io[i],
1263 phba->cpucheck_ccmpl_io[i],
1264 phba->cpucheck_cmpl_io[i],
1265 phba->cpucheck_rcv_io[i]);
1266 tot_xmt += phba->cpucheck_xmt_io[i];
1267 tot_rcv += phba->cpucheck_rcv_io[i];
1268 tot_cmpl += phba->cpucheck_cmpl_io[i];
1269 tot_ccmpl += phba->cpucheck_ccmpl_io[i];
1271 len += snprintf(buf + len, PAGE_SIZE - len,
1272 "tot:xmit x%08x ccmpl x%08x cmpl x%08x rcv x%08x\n",
1273 tot_xmt, tot_ccmpl, tot_cmpl, tot_rcv);
1280 * lpfc_debugfs_disc_trc - Store discovery trace log
1281 * @vport: The vport to associate this trace string with for retrieval.
1282 * @mask: Log entry classification.
1283 * @fmt: Format string to be displayed when dumping the log.
1284 * @data1: 1st data parameter to be applied to @fmt.
1285 * @data2: 2nd data parameter to be applied to @fmt.
1286 * @data3: 3rd data parameter to be applied to @fmt.
1289 * This routine is used by the driver code to add a debugfs log entry to the
1290 * discovery trace buffer associated with @vport. Only entries with a @mask that
1291 * match the current debugfs discovery mask will be saved. Entries that do not
1292 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1293 * printf when displaying the log.
1296 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1297 uint32_t data1, uint32_t data2, uint32_t data3)
1299 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1300 struct lpfc_debugfs_trc *dtp;
1303 if (!(lpfc_debugfs_mask_disc_trc & mask))
1306 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1307 !vport || !vport->disc_trc)
1310 index = atomic_inc_return(&vport->disc_trc_cnt) &
1311 (lpfc_debugfs_max_disc_trc - 1);
1312 dtp = vport->disc_trc + index;
1317 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1324 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
1325 * @phba: The phba to associate this trace string with for retrieval.
1326 * @fmt: Format string to be displayed when dumping the log.
1327 * @data1: 1st data parameter to be applied to @fmt.
1328 * @data2: 2nd data parameter to be applied to @fmt.
1329 * @data3: 3rd data parameter to be applied to @fmt.
1332 * This routine is used by the driver code to add a debugfs log entry to the
1333 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1334 * @data3 are used like printf when displaying the log.
1337 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1338 uint32_t data1, uint32_t data2, uint32_t data3)
1340 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1341 struct lpfc_debugfs_trc *dtp;
1344 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1345 !phba || !phba->slow_ring_trc)
1348 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1349 (lpfc_debugfs_max_slow_ring_trc - 1);
1350 dtp = phba->slow_ring_trc + index;
1355 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1362 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1363 * @phba: The phba to associate this trace string with for retrieval.
1364 * @fmt: Format string to be displayed when dumping the log.
1365 * @data1: 1st data parameter to be applied to @fmt.
1366 * @data2: 2nd data parameter to be applied to @fmt.
1367 * @data3: 3rd data parameter to be applied to @fmt.
1370 * This routine is used by the driver code to add a debugfs log entry to the
1371 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1372 * @data3 are used like printf when displaying the log.
1375 lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1376 uint16_t data1, uint16_t data2, uint32_t data3)
1378 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1379 struct lpfc_debugfs_nvmeio_trc *dtp;
1382 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1385 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1386 (phba->nvmeio_trc_size - 1);
1387 dtp = phba->nvmeio_trc + index;
1395 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1397 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
1398 * @inode: The inode pointer that contains a vport pointer.
1399 * @file: The file pointer to attach the log output.
1402 * This routine is the entry point for the debugfs open file operation. It gets
1403 * the vport from the i_private field in @inode, allocates the necessary buffer
1404 * for the log, fills the buffer from the in-memory log for this vport, and then
1405 * returns a pointer to that log in the private_data field in @file.
1408 * This function returns zero if successful. On error it will return a negative
1412 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1414 struct lpfc_vport *vport = inode->i_private;
1415 struct lpfc_debug *debug;
1419 if (!lpfc_debugfs_max_disc_trc) {
1424 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1428 /* Round to page boundary */
1429 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1430 size = PAGE_ALIGN(size);
1432 debug->buffer = kmalloc(size, GFP_KERNEL);
1433 if (!debug->buffer) {
1438 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1439 file->private_data = debug;
1447 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
1448 * @inode: The inode pointer that contains a vport pointer.
1449 * @file: The file pointer to attach the log output.
1452 * This routine is the entry point for the debugfs open file operation. It gets
1453 * the vport from the i_private field in @inode, allocates the necessary buffer
1454 * for the log, fills the buffer from the in-memory log for this vport, and then
1455 * returns a pointer to that log in the private_data field in @file.
1458 * This function returns zero if successful. On error it will return a negative
1462 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1464 struct lpfc_hba *phba = inode->i_private;
1465 struct lpfc_debug *debug;
1469 if (!lpfc_debugfs_max_slow_ring_trc) {
1474 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1478 /* Round to page boundary */
1479 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1480 size = PAGE_ALIGN(size);
1482 debug->buffer = kmalloc(size, GFP_KERNEL);
1483 if (!debug->buffer) {
1488 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
1489 file->private_data = debug;
1497 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
1498 * @inode: The inode pointer that contains a vport pointer.
1499 * @file: The file pointer to attach the log output.
1502 * This routine is the entry point for the debugfs open file operation. It gets
1503 * the vport from the i_private field in @inode, allocates the necessary buffer
1504 * for the log, fills the buffer from the in-memory log for this vport, and then
1505 * returns a pointer to that log in the private_data field in @file.
1508 * This function returns zero if successful. On error it will return a negative
1512 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
1514 struct lpfc_hba *phba = inode->i_private;
1515 struct lpfc_debug *debug;
1518 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1522 /* Round to page boundary */
1523 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
1524 if (!debug->buffer) {
1529 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
1531 file->private_data = debug;
1539 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
1540 * @inode: The inode pointer that contains a vport pointer.
1541 * @file: The file pointer to attach the log output.
1544 * This routine is the entry point for the debugfs open file operation. It gets
1545 * the vport from the i_private field in @inode, allocates the necessary buffer
1546 * for the log, fills the buffer from the in-memory log for this vport, and then
1547 * returns a pointer to that log in the private_data field in @file.
1550 * This function returns zero if successful. On error it will return a negative
1554 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
1556 struct lpfc_hba *phba = inode->i_private;
1557 struct lpfc_debug *debug;
1560 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1564 /* Round to page boundary */
1565 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
1566 if (!debug->buffer) {
1571 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
1572 LPFC_DUMPHBASLIM_SIZE);
1573 file->private_data = debug;
1581 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
1582 * @inode: The inode pointer that contains a vport pointer.
1583 * @file: The file pointer to attach the log output.
1586 * This routine is the entry point for the debugfs open file operation. It gets
1587 * the vport from the i_private field in @inode, allocates the necessary buffer
1588 * for the log, fills the buffer from the in-memory log for this vport, and then
1589 * returns a pointer to that log in the private_data field in @file.
1592 * This function returns zero if successful. On error it will return a negative
1596 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
1598 struct lpfc_hba *phba = inode->i_private;
1599 struct lpfc_debug *debug;
1602 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1606 /* Round to page boundary */
1607 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
1608 if (!debug->buffer) {
1613 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
1614 LPFC_DUMPHOSTSLIM_SIZE);
1615 file->private_data = debug;
1623 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
1625 struct lpfc_debug *debug;
1628 if (!_dump_buf_data)
1631 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1635 /* Round to page boundary */
1636 pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
1637 __func__, _dump_buf_data);
1638 debug->buffer = _dump_buf_data;
1639 if (!debug->buffer) {
1644 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
1645 file->private_data = debug;
1653 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
1655 struct lpfc_debug *debug;
1661 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1665 /* Round to page boundary */
1666 pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n",
1667 __func__, _dump_buf_dif, file);
1668 debug->buffer = _dump_buf_dif;
1669 if (!debug->buffer) {
1674 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
1675 file->private_data = debug;
1683 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
1684 size_t nbytes, loff_t *ppos)
1687 * The Data/DIF buffers only save one failing IO
1688 * The write op is used as a reset mechanism after an IO has
1689 * already been saved to the next one can be saved
1691 spin_lock(&_dump_buf_lock);
1693 memset((void *)_dump_buf_data, 0,
1694 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
1695 memset((void *)_dump_buf_dif, 0,
1696 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
1700 spin_unlock(&_dump_buf_lock);
1706 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1707 size_t nbytes, loff_t *ppos)
1709 struct dentry *dent = file->f_path.dentry;
1710 struct lpfc_hba *phba = file->private_data;
1715 if (dent == phba->debug_writeGuard)
1716 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1717 else if (dent == phba->debug_writeApp)
1718 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
1719 else if (dent == phba->debug_writeRef)
1720 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
1721 else if (dent == phba->debug_readGuard)
1722 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1723 else if (dent == phba->debug_readApp)
1724 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
1725 else if (dent == phba->debug_readRef)
1726 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1727 else if (dent == phba->debug_InjErrNPortID)
1728 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1729 else if (dent == phba->debug_InjErrWWPN) {
1730 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1731 tmp = cpu_to_be64(tmp);
1732 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1733 } else if (dent == phba->debug_InjErrLBA) {
1734 if (phba->lpfc_injerr_lba == (sector_t)(-1))
1735 cnt = snprintf(cbuf, 32, "off\n");
1737 cnt = snprintf(cbuf, 32, "0x%llx\n",
1738 (uint64_t) phba->lpfc_injerr_lba);
1740 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1741 "0547 Unknown debugfs error injection entry\n");
1743 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1747 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1748 size_t nbytes, loff_t *ppos)
1750 struct dentry *dent = file->f_path.dentry;
1751 struct lpfc_hba *phba = file->private_data;
1756 memset(dstbuf, 0, 33);
1757 size = (nbytes < 32) ? nbytes : 32;
1758 if (copy_from_user(dstbuf, buf, size))
1761 if (dent == phba->debug_InjErrLBA) {
1762 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1763 tmp = (uint64_t)(-1);
1766 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
1769 if (dent == phba->debug_writeGuard)
1770 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1771 else if (dent == phba->debug_writeApp)
1772 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1773 else if (dent == phba->debug_writeRef)
1774 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1775 else if (dent == phba->debug_readGuard)
1776 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
1777 else if (dent == phba->debug_readApp)
1778 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1779 else if (dent == phba->debug_readRef)
1780 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1781 else if (dent == phba->debug_InjErrLBA)
1782 phba->lpfc_injerr_lba = (sector_t)tmp;
1783 else if (dent == phba->debug_InjErrNPortID)
1784 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1785 else if (dent == phba->debug_InjErrWWPN) {
1786 tmp = cpu_to_be64(tmp);
1787 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1789 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1790 "0548 Unknown debugfs error injection entry\n");
1796 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1802 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1803 * @inode: The inode pointer that contains a vport pointer.
1804 * @file: The file pointer to attach the log output.
1807 * This routine is the entry point for the debugfs open file operation. It gets
1808 * the vport from the i_private field in @inode, allocates the necessary buffer
1809 * for the log, fills the buffer from the in-memory log for this vport, and then
1810 * returns a pointer to that log in the private_data field in @file.
1813 * This function returns zero if successful. On error it will return a negative
1817 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1819 struct lpfc_vport *vport = inode->i_private;
1820 struct lpfc_debug *debug;
1823 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1827 /* Round to page boundary */
1828 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1829 if (!debug->buffer) {
1834 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1835 LPFC_NODELIST_SIZE);
1836 file->private_data = debug;
1844 * lpfc_debugfs_lseek - Seek through a debugfs file
1845 * @file: The file pointer to seek through.
1846 * @off: The offset to seek to or the amount to seek by.
1847 * @whence: Indicates how to seek.
1850 * This routine is the entry point for the debugfs lseek file operation. The
1851 * @whence parameter indicates whether @off is the offset to directly seek to,
1852 * or if it is a value to seek forward or reverse by. This function figures out
1853 * what the new offset of the debugfs file will be and assigns that value to the
1854 * f_pos field of @file.
1857 * This function returns the new offset if successful and returns a negative
1858 * error if unable to process the seek.
1861 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1863 struct lpfc_debug *debug = file->private_data;
1864 return fixed_size_llseek(file, off, whence, debug->len);
1868 * lpfc_debugfs_read - Read a debugfs file
1869 * @file: The file pointer to read from.
1870 * @buf: The buffer to copy the data to.
1871 * @nbytes: The number of bytes to read.
1872 * @ppos: The position in the file to start reading from.
1875 * This routine reads data from from the buffer indicated in the private_data
1876 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1880 * This function returns the amount of data that was read (this could be less
1881 * than @nbytes if the end of the file was reached) or a negative error value.
1884 lpfc_debugfs_read(struct file *file, char __user *buf,
1885 size_t nbytes, loff_t *ppos)
1887 struct lpfc_debug *debug = file->private_data;
1889 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1894 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1895 * @inode: The inode pointer that contains a vport pointer. (unused)
1896 * @file: The file pointer that contains the buffer to release.
1899 * This routine frees the buffer that was allocated when the debugfs file was
1903 * This function returns zero.
1906 lpfc_debugfs_release(struct inode *inode, struct file *file)
1908 struct lpfc_debug *debug = file->private_data;
1910 kfree(debug->buffer);
1917 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1919 struct lpfc_debug *debug = file->private_data;
1921 debug->buffer = NULL;
1929 lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
1931 struct lpfc_vport *vport = inode->i_private;
1932 struct lpfc_debug *debug;
1935 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1939 /* Round to page boundary */
1940 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
1941 if (!debug->buffer) {
1946 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
1947 LPFC_NVMESTAT_SIZE);
1949 debug->i_private = inode->i_private;
1950 file->private_data = debug;
1958 lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
1959 size_t nbytes, loff_t *ppos)
1961 struct lpfc_debug *debug = file->private_data;
1962 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
1963 struct lpfc_hba *phba = vport->phba;
1964 struct lpfc_nvmet_tgtport *tgtp;
1968 if (!phba->targetport)
1974 memset(mybuf, 0, sizeof(mybuf));
1976 if (copy_from_user(mybuf, buf, nbytes))
1980 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1981 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
1982 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
1983 atomic_set(&tgtp->rcv_ls_req_in, 0);
1984 atomic_set(&tgtp->rcv_ls_req_out, 0);
1985 atomic_set(&tgtp->rcv_ls_req_drop, 0);
1986 atomic_set(&tgtp->xmt_ls_abort, 0);
1987 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
1988 atomic_set(&tgtp->xmt_ls_rsp, 0);
1989 atomic_set(&tgtp->xmt_ls_drop, 0);
1990 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
1991 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
1993 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
1994 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
1995 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
1996 atomic_set(&tgtp->xmt_fcp_drop, 0);
1997 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
1998 atomic_set(&tgtp->xmt_fcp_read, 0);
1999 atomic_set(&tgtp->xmt_fcp_write, 0);
2000 atomic_set(&tgtp->xmt_fcp_rsp, 0);
2001 atomic_set(&tgtp->xmt_fcp_release, 0);
2002 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
2003 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
2004 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
2006 atomic_set(&tgtp->xmt_fcp_abort, 0);
2007 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
2008 atomic_set(&tgtp->xmt_abort_sol, 0);
2009 atomic_set(&tgtp->xmt_abort_unsol, 0);
2010 atomic_set(&tgtp->xmt_abort_rsp, 0);
2011 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
2017 lpfc_debugfs_nvmektime_open(struct inode *inode, struct file *file)
2019 struct lpfc_vport *vport = inode->i_private;
2020 struct lpfc_debug *debug;
2023 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2027 /* Round to page boundary */
2028 debug->buffer = kmalloc(LPFC_NVMEKTIME_SIZE, GFP_KERNEL);
2029 if (!debug->buffer) {
2034 debug->len = lpfc_debugfs_nvmektime_data(vport, debug->buffer,
2035 LPFC_NVMEKTIME_SIZE);
2037 debug->i_private = inode->i_private;
2038 file->private_data = debug;
2046 lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf,
2047 size_t nbytes, loff_t *ppos)
2049 struct lpfc_debug *debug = file->private_data;
2050 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2051 struct lpfc_hba *phba = vport->phba;
2058 memset(mybuf, 0, sizeof(mybuf));
2060 if (copy_from_user(mybuf, buf, nbytes))
2064 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2065 phba->ktime_data_samples = 0;
2066 phba->ktime_status_samples = 0;
2067 phba->ktime_seg1_total = 0;
2068 phba->ktime_seg1_max = 0;
2069 phba->ktime_seg1_min = 0xffffffff;
2070 phba->ktime_seg2_total = 0;
2071 phba->ktime_seg2_max = 0;
2072 phba->ktime_seg2_min = 0xffffffff;
2073 phba->ktime_seg3_total = 0;
2074 phba->ktime_seg3_max = 0;
2075 phba->ktime_seg3_min = 0xffffffff;
2076 phba->ktime_seg4_total = 0;
2077 phba->ktime_seg4_max = 0;
2078 phba->ktime_seg4_min = 0xffffffff;
2079 phba->ktime_seg5_total = 0;
2080 phba->ktime_seg5_max = 0;
2081 phba->ktime_seg5_min = 0xffffffff;
2082 phba->ktime_seg6_total = 0;
2083 phba->ktime_seg6_max = 0;
2084 phba->ktime_seg6_min = 0xffffffff;
2085 phba->ktime_seg7_total = 0;
2086 phba->ktime_seg7_max = 0;
2087 phba->ktime_seg7_min = 0xffffffff;
2088 phba->ktime_seg8_total = 0;
2089 phba->ktime_seg8_max = 0;
2090 phba->ktime_seg8_min = 0xffffffff;
2091 phba->ktime_seg9_total = 0;
2092 phba->ktime_seg9_max = 0;
2093 phba->ktime_seg9_min = 0xffffffff;
2094 phba->ktime_seg10_total = 0;
2095 phba->ktime_seg10_max = 0;
2096 phba->ktime_seg10_min = 0xffffffff;
2099 return strlen(pbuf);
2100 } else if ((strncmp(pbuf, "off",
2101 sizeof("off") - 1) == 0)) {
2103 return strlen(pbuf);
2104 } else if ((strncmp(pbuf, "zero",
2105 sizeof("zero") - 1) == 0)) {
2106 phba->ktime_data_samples = 0;
2107 phba->ktime_status_samples = 0;
2108 phba->ktime_seg1_total = 0;
2109 phba->ktime_seg1_max = 0;
2110 phba->ktime_seg1_min = 0xffffffff;
2111 phba->ktime_seg2_total = 0;
2112 phba->ktime_seg2_max = 0;
2113 phba->ktime_seg2_min = 0xffffffff;
2114 phba->ktime_seg3_total = 0;
2115 phba->ktime_seg3_max = 0;
2116 phba->ktime_seg3_min = 0xffffffff;
2117 phba->ktime_seg4_total = 0;
2118 phba->ktime_seg4_max = 0;
2119 phba->ktime_seg4_min = 0xffffffff;
2120 phba->ktime_seg5_total = 0;
2121 phba->ktime_seg5_max = 0;
2122 phba->ktime_seg5_min = 0xffffffff;
2123 phba->ktime_seg6_total = 0;
2124 phba->ktime_seg6_max = 0;
2125 phba->ktime_seg6_min = 0xffffffff;
2126 phba->ktime_seg7_total = 0;
2127 phba->ktime_seg7_max = 0;
2128 phba->ktime_seg7_min = 0xffffffff;
2129 phba->ktime_seg8_total = 0;
2130 phba->ktime_seg8_max = 0;
2131 phba->ktime_seg8_min = 0xffffffff;
2132 phba->ktime_seg9_total = 0;
2133 phba->ktime_seg9_max = 0;
2134 phba->ktime_seg9_min = 0xffffffff;
2135 phba->ktime_seg10_total = 0;
2136 phba->ktime_seg10_max = 0;
2137 phba->ktime_seg10_min = 0xffffffff;
2138 return strlen(pbuf);
2144 lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2146 struct lpfc_hba *phba = inode->i_private;
2147 struct lpfc_debug *debug;
2150 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2154 /* Round to page boundary */
2155 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2156 if (!debug->buffer) {
2161 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2162 LPFC_NVMEIO_TRC_SIZE);
2164 debug->i_private = inode->i_private;
2165 file->private_data = debug;
2173 lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2174 size_t nbytes, loff_t *ppos)
2176 struct lpfc_debug *debug = file->private_data;
2177 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2186 memset(mybuf, 0, sizeof(mybuf));
2188 if (copy_from_user(mybuf, buf, nbytes))
2192 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2193 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2194 "0570 nvmeio_trc_off\n");
2195 phba->nvmeio_trc_output_idx = 0;
2196 phba->nvmeio_trc_on = 0;
2197 return strlen(pbuf);
2198 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2199 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2200 "0571 nvmeio_trc_on\n");
2201 phba->nvmeio_trc_output_idx = 0;
2202 phba->nvmeio_trc_on = 1;
2203 return strlen(pbuf);
2206 /* We must be off to allocate the trace buffer */
2207 if (phba->nvmeio_trc_on != 0)
2210 /* If not on or off, the parameter is the trace buffer size */
2211 i = kstrtoul(pbuf, 0, &sz);
2214 phba->nvmeio_trc_size = (uint32_t)sz;
2216 /* It must be a power of 2 - round down */
2223 if (phba->nvmeio_trc_size != sz)
2224 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2225 "0572 nvmeio_trc_size changed to %ld\n",
2227 phba->nvmeio_trc_size = (uint32_t)sz;
2229 /* If one previously exists, free it */
2230 kfree(phba->nvmeio_trc);
2232 /* Allocate new trace buffer and initialize */
2233 phba->nvmeio_trc = kmalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
2235 if (!phba->nvmeio_trc) {
2236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2237 "0573 Cannot create debugfs "
2238 "nvmeio_trc buffer\n");
2241 memset(phba->nvmeio_trc, 0,
2242 (sizeof(struct lpfc_debugfs_nvmeio_trc) * sz));
2243 atomic_set(&phba->nvmeio_trc_cnt, 0);
2244 phba->nvmeio_trc_on = 0;
2245 phba->nvmeio_trc_output_idx = 0;
2247 return strlen(pbuf);
2251 lpfc_debugfs_cpucheck_open(struct inode *inode, struct file *file)
2253 struct lpfc_vport *vport = inode->i_private;
2254 struct lpfc_debug *debug;
2257 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2261 /* Round to page boundary */
2262 debug->buffer = kmalloc(LPFC_CPUCHECK_SIZE, GFP_KERNEL);
2263 if (!debug->buffer) {
2268 debug->len = lpfc_debugfs_cpucheck_data(vport, debug->buffer,
2269 LPFC_NVMEKTIME_SIZE);
2271 debug->i_private = inode->i_private;
2272 file->private_data = debug;
2280 lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
2281 size_t nbytes, loff_t *ppos)
2283 struct lpfc_debug *debug = file->private_data;
2284 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2285 struct lpfc_hba *phba = vport->phba;
2293 memset(mybuf, 0, sizeof(mybuf));
2295 if (copy_from_user(mybuf, buf, nbytes))
2299 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2300 if (phba->nvmet_support)
2301 phba->cpucheck_on |= LPFC_CHECK_NVMET_IO;
2303 phba->cpucheck_on |= LPFC_CHECK_NVME_IO;
2304 return strlen(pbuf);
2305 } else if ((strncmp(pbuf, "rcv",
2306 sizeof("rcv") - 1) == 0)) {
2307 if (phba->nvmet_support)
2308 phba->cpucheck_on |= LPFC_CHECK_NVMET_RCV;
2311 return strlen(pbuf);
2312 } else if ((strncmp(pbuf, "off",
2313 sizeof("off") - 1) == 0)) {
2314 phba->cpucheck_on = LPFC_CHECK_OFF;
2315 return strlen(pbuf);
2316 } else if ((strncmp(pbuf, "zero",
2317 sizeof("zero") - 1) == 0)) {
2318 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
2319 if (i >= LPFC_CHECK_CPU_CNT)
2321 phba->cpucheck_rcv_io[i] = 0;
2322 phba->cpucheck_xmt_io[i] = 0;
2323 phba->cpucheck_cmpl_io[i] = 0;
2324 phba->cpucheck_ccmpl_io[i] = 0;
2326 return strlen(pbuf);
2332 * ---------------------------------
2333 * iDiag debugfs file access methods
2334 * ---------------------------------
2336 * All access methods are through the proper SLI4 PCI function's debugfs
2339 * /sys/kernel/debug/lpfc/fn<#>/iDiag
2343 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
2344 * @buf: The pointer to the user space buffer.
2345 * @nbytes: The number of bytes in the user space buffer.
2346 * @idiag_cmd: pointer to the idiag command struct.
2348 * This routine reads data from debugfs user space buffer and parses the
2349 * buffer for getting the idiag command and arguments. The while space in
2350 * between the set of data is used as the parsing separator.
2352 * This routine returns 0 when successful, it returns proper error code
2353 * back to the user space in error conditions.
2355 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
2356 struct lpfc_idiag_cmd *idiag_cmd)
2359 char *pbuf, *step_str;
2363 memset(mybuf, 0, sizeof(mybuf));
2364 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
2365 bsize = min(nbytes, (sizeof(mybuf)-1));
2367 if (copy_from_user(mybuf, buf, bsize))
2370 step_str = strsep(&pbuf, "\t ");
2372 /* The opcode must present */
2376 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
2377 if (idiag_cmd->opcode == 0)
2380 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
2381 step_str = strsep(&pbuf, "\t ");
2384 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
2390 * lpfc_idiag_open - idiag open debugfs
2391 * @inode: The inode pointer that contains a pointer to phba.
2392 * @file: The file pointer to attach the file operation.
2395 * This routine is the entry point for the debugfs open file operation. It
2396 * gets the reference to phba from the i_private field in @inode, it then
2397 * allocates buffer for the file operation, performs the necessary PCI config
2398 * space read into the allocated buffer according to the idiag user command
2399 * setup, and then returns a pointer to buffer in the private_data field in
2403 * This function returns zero if successful. On error it will return an
2404 * negative error value.
2407 lpfc_idiag_open(struct inode *inode, struct file *file)
2409 struct lpfc_debug *debug;
2411 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2415 debug->i_private = inode->i_private;
2416 debug->buffer = NULL;
2417 file->private_data = debug;
2423 * lpfc_idiag_release - Release idiag access file operation
2424 * @inode: The inode pointer that contains a vport pointer. (unused)
2425 * @file: The file pointer that contains the buffer to release.
2428 * This routine is the generic release routine for the idiag access file
2429 * operation, it frees the buffer that was allocated when the debugfs file
2433 * This function returns zero.
2436 lpfc_idiag_release(struct inode *inode, struct file *file)
2438 struct lpfc_debug *debug = file->private_data;
2440 /* Free the buffers to the file operation */
2441 kfree(debug->buffer);
2448 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
2449 * @inode: The inode pointer that contains a vport pointer. (unused)
2450 * @file: The file pointer that contains the buffer to release.
2453 * This routine frees the buffer that was allocated when the debugfs file
2454 * was opened. It also reset the fields in the idiag command struct in the
2455 * case of command for write operation.
2458 * This function returns zero.
2461 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
2463 struct lpfc_debug *debug = file->private_data;
2465 if (debug->op == LPFC_IDIAG_OP_WR) {
2466 switch (idiag.cmd.opcode) {
2467 case LPFC_IDIAG_CMD_PCICFG_WR:
2468 case LPFC_IDIAG_CMD_PCICFG_ST:
2469 case LPFC_IDIAG_CMD_PCICFG_CL:
2470 case LPFC_IDIAG_CMD_QUEACC_WR:
2471 case LPFC_IDIAG_CMD_QUEACC_ST:
2472 case LPFC_IDIAG_CMD_QUEACC_CL:
2473 memset(&idiag, 0, sizeof(idiag));
2480 /* Free the buffers to the file operation */
2481 kfree(debug->buffer);
2488 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
2489 * @file: The file pointer to read from.
2490 * @buf: The buffer to copy the data to.
2491 * @nbytes: The number of bytes to read.
2492 * @ppos: The position in the file to start reading from.
2495 * This routine reads data from the @phba pci config space according to the
2496 * idiag command, and copies to user @buf. Depending on the PCI config space
2497 * read command setup, it does either a single register read of a byte
2498 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
2499 * registers from the 4K extended PCI config space.
2502 * This function returns the amount of data that was read (this could be less
2503 * than @nbytes if the end of the file was reached) or a negative error value.
2506 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
2509 struct lpfc_debug *debug = file->private_data;
2510 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2511 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
2514 struct pci_dev *pdev;
2519 pdev = phba->pcidev;
2523 /* This is a user read operation */
2524 debug->op = LPFC_IDIAG_OP_RD;
2527 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
2530 pbuffer = debug->buffer;
2535 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2536 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2537 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2541 /* Read single PCI config space register */
2543 case SIZE_U8: /* byte (8 bits) */
2544 pci_read_config_byte(pdev, where, &u8val);
2545 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2546 "%03x: %02x\n", where, u8val);
2548 case SIZE_U16: /* word (16 bits) */
2549 pci_read_config_word(pdev, where, &u16val);
2550 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2551 "%03x: %04x\n", where, u16val);
2553 case SIZE_U32: /* double word (32 bits) */
2554 pci_read_config_dword(pdev, where, &u32val);
2555 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2556 "%03x: %08x\n", where, u32val);
2558 case LPFC_PCI_CFG_BROWSE: /* browse all */
2566 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2570 /* Browse all PCI config space registers */
2571 offset_label = idiag.offset.last_rd;
2572 offset = offset_label;
2574 /* Read PCI config space */
2575 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2576 "%03x: ", offset_label);
2578 pci_read_config_dword(pdev, offset, &u32val);
2579 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2581 offset += sizeof(uint32_t);
2582 if (offset >= LPFC_PCI_CFG_SIZE) {
2583 len += snprintf(pbuffer+len,
2584 LPFC_PCI_CFG_SIZE-len, "\n");
2587 index -= sizeof(uint32_t);
2589 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2591 else if (!(index % (8 * sizeof(uint32_t)))) {
2592 offset_label += (8 * sizeof(uint32_t));
2593 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2594 "\n%03x: ", offset_label);
2598 /* Set up the offset for next portion of pci cfg read */
2600 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
2601 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
2602 idiag.offset.last_rd = 0;
2604 idiag.offset.last_rd = 0;
2606 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2610 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
2611 * @file: The file pointer to read from.
2612 * @buf: The buffer to copy the user data from.
2613 * @nbytes: The number of bytes to get.
2614 * @ppos: The position in the file to start reading from.
2616 * This routine get the debugfs idiag command struct from user space and
2617 * then perform the syntax check for PCI config space read or write command
2618 * accordingly. In the case of PCI config space read command, it sets up
2619 * the command in the idiag command struct for the debugfs read operation.
2620 * In the case of PCI config space write operation, it executes the write
2621 * operation into the PCI config space accordingly.
2623 * It returns the @nbytges passing in from debugfs user space when successful.
2624 * In case of error conditions, it returns proper error code back to the user
2628 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
2629 size_t nbytes, loff_t *ppos)
2631 struct lpfc_debug *debug = file->private_data;
2632 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2633 uint32_t where, value, count;
2637 struct pci_dev *pdev;
2640 pdev = phba->pcidev;
2644 /* This is a user write operation */
2645 debug->op = LPFC_IDIAG_OP_WR;
2647 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2651 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2652 /* Sanity check on PCI config read command line arguments */
2653 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
2655 /* Read command from PCI config space, set up command fields */
2656 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2657 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2658 if (count == LPFC_PCI_CFG_BROWSE) {
2659 if (where % sizeof(uint32_t))
2661 /* Starting offset to browse */
2662 idiag.offset.last_rd = where;
2663 } else if ((count != sizeof(uint8_t)) &&
2664 (count != sizeof(uint16_t)) &&
2665 (count != sizeof(uint32_t)))
2667 if (count == sizeof(uint8_t)) {
2668 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2670 if (where % sizeof(uint8_t))
2673 if (count == sizeof(uint16_t)) {
2674 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2676 if (where % sizeof(uint16_t))
2679 if (count == sizeof(uint32_t)) {
2680 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2682 if (where % sizeof(uint32_t))
2685 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
2686 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
2687 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2688 /* Sanity check on PCI config write command line arguments */
2689 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
2691 /* Write command to PCI config space, read-modify-write */
2692 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2693 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2694 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
2696 if ((count != sizeof(uint8_t)) &&
2697 (count != sizeof(uint16_t)) &&
2698 (count != sizeof(uint32_t)))
2700 if (count == sizeof(uint8_t)) {
2701 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2703 if (where % sizeof(uint8_t))
2705 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2706 pci_write_config_byte(pdev, where,
2708 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2709 rc = pci_read_config_byte(pdev, where, &u8val);
2711 u8val |= (uint8_t)value;
2712 pci_write_config_byte(pdev, where,
2716 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2717 rc = pci_read_config_byte(pdev, where, &u8val);
2719 u8val &= (uint8_t)(~value);
2720 pci_write_config_byte(pdev, where,
2725 if (count == sizeof(uint16_t)) {
2726 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2728 if (where % sizeof(uint16_t))
2730 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2731 pci_write_config_word(pdev, where,
2733 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2734 rc = pci_read_config_word(pdev, where, &u16val);
2736 u16val |= (uint16_t)value;
2737 pci_write_config_word(pdev, where,
2741 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2742 rc = pci_read_config_word(pdev, where, &u16val);
2744 u16val &= (uint16_t)(~value);
2745 pci_write_config_word(pdev, where,
2750 if (count == sizeof(uint32_t)) {
2751 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2753 if (where % sizeof(uint32_t))
2755 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2756 pci_write_config_dword(pdev, where, value);
2757 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2758 rc = pci_read_config_dword(pdev, where,
2762 pci_write_config_dword(pdev, where,
2766 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2767 rc = pci_read_config_dword(pdev, where,
2771 pci_write_config_dword(pdev, where,
2777 /* All other opecodes are illegal for now */
2782 memset(&idiag, 0, sizeof(idiag));
2787 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
2788 * @file: The file pointer to read from.
2789 * @buf: The buffer to copy the data to.
2790 * @nbytes: The number of bytes to read.
2791 * @ppos: The position in the file to start reading from.
2794 * This routine reads data from the @phba pci bar memory mapped space
2795 * according to the idiag command, and copies to user @buf.
2798 * This function returns the amount of data that was read (this could be less
2799 * than @nbytes if the end of the file was reached) or a negative error value.
2802 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
2805 struct lpfc_debug *debug = file->private_data;
2806 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2807 int offset_label, offset, offset_run, len = 0, index;
2808 int bar_num, acc_range, bar_size;
2810 void __iomem *mem_mapped_bar;
2812 struct pci_dev *pdev;
2815 pdev = phba->pcidev;
2819 /* This is a user read operation */
2820 debug->op = LPFC_IDIAG_OP_RD;
2823 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
2826 pbuffer = debug->buffer;
2831 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
2832 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2833 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
2834 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
2835 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
2842 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2843 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2844 if (bar_num == IDIAG_BARACC_BAR_0)
2845 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2846 else if (bar_num == IDIAG_BARACC_BAR_1)
2847 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2848 else if (bar_num == IDIAG_BARACC_BAR_2)
2849 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2852 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2853 if (bar_num == IDIAG_BARACC_BAR_0)
2854 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2860 /* Read single PCI bar space register */
2861 if (acc_range == SINGLE_WORD) {
2862 offset_run = offset;
2863 u32val = readl(mem_mapped_bar + offset_run);
2864 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2865 "%05x: %08x\n", offset_run, u32val);
2869 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2873 /* Browse all PCI bar space registers */
2874 offset_label = idiag.offset.last_rd;
2875 offset_run = offset_label;
2877 /* Read PCI bar memory mapped space */
2878 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2879 "%05x: ", offset_label);
2880 index = LPFC_PCI_BAR_RD_SIZE;
2882 u32val = readl(mem_mapped_bar + offset_run);
2883 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2885 offset_run += sizeof(uint32_t);
2886 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2887 if (offset_run >= bar_size) {
2888 len += snprintf(pbuffer+len,
2889 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2893 if (offset_run >= offset +
2894 (acc_range * sizeof(uint32_t))) {
2895 len += snprintf(pbuffer+len,
2896 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2900 index -= sizeof(uint32_t);
2902 len += snprintf(pbuffer+len,
2903 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2904 else if (!(index % (8 * sizeof(uint32_t)))) {
2905 offset_label += (8 * sizeof(uint32_t));
2906 len += snprintf(pbuffer+len,
2907 LPFC_PCI_BAR_RD_BUF_SIZE-len,
2908 "\n%05x: ", offset_label);
2912 /* Set up the offset for next portion of pci bar read */
2914 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
2915 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2916 if (idiag.offset.last_rd >= bar_size)
2917 idiag.offset.last_rd = 0;
2919 if (offset_run >= offset +
2920 (acc_range * sizeof(uint32_t)))
2921 idiag.offset.last_rd = offset;
2924 if (acc_range == LPFC_PCI_BAR_BROWSE)
2925 idiag.offset.last_rd = 0;
2927 idiag.offset.last_rd = offset;
2930 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2934 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
2935 * @file: The file pointer to read from.
2936 * @buf: The buffer to copy the user data from.
2937 * @nbytes: The number of bytes to get.
2938 * @ppos: The position in the file to start reading from.
2940 * This routine get the debugfs idiag command struct from user space and
2941 * then perform the syntax check for PCI bar memory mapped space read or
2942 * write command accordingly. In the case of PCI bar memory mapped space
2943 * read command, it sets up the command in the idiag command struct for
2944 * the debugfs read operation. In the case of PCI bar memorpy mapped space
2945 * write operation, it executes the write operation into the PCI bar memory
2946 * mapped space accordingly.
2948 * It returns the @nbytges passing in from debugfs user space when successful.
2949 * In case of error conditions, it returns proper error code back to the user
2953 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
2954 size_t nbytes, loff_t *ppos)
2956 struct lpfc_debug *debug = file->private_data;
2957 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2958 uint32_t bar_num, bar_size, offset, value, acc_range;
2959 struct pci_dev *pdev;
2960 void __iomem *mem_mapped_bar;
2965 pdev = phba->pcidev;
2969 /* This is a user write operation */
2970 debug->op = LPFC_IDIAG_OP_WR;
2972 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2976 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2977 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2979 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2980 if ((bar_num != IDIAG_BARACC_BAR_0) &&
2981 (bar_num != IDIAG_BARACC_BAR_1) &&
2982 (bar_num != IDIAG_BARACC_BAR_2))
2984 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2985 if (bar_num != IDIAG_BARACC_BAR_0)
2990 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2991 if (bar_num == IDIAG_BARACC_BAR_0) {
2992 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2993 LPFC_PCI_IF0_BAR0_SIZE;
2994 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2995 } else if (bar_num == IDIAG_BARACC_BAR_1) {
2996 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2997 LPFC_PCI_IF0_BAR1_SIZE;
2998 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2999 } else if (bar_num == IDIAG_BARACC_BAR_2) {
3000 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3001 LPFC_PCI_IF0_BAR2_SIZE;
3002 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3005 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3006 if (bar_num == IDIAG_BARACC_BAR_0) {
3007 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3008 LPFC_PCI_IF2_BAR0_SIZE;
3009 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3015 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3016 if (offset % sizeof(uint32_t))
3019 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3020 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3021 /* Sanity check on PCI config read command line arguments */
3022 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3024 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3025 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3026 if (offset > bar_size - sizeof(uint32_t))
3028 /* Starting offset to browse */
3029 idiag.offset.last_rd = offset;
3030 } else if (acc_range > SINGLE_WORD) {
3031 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3033 /* Starting offset to browse */
3034 idiag.offset.last_rd = offset;
3035 } else if (acc_range != SINGLE_WORD)
3037 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3038 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3039 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3040 /* Sanity check on PCI bar write command line arguments */
3041 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3043 /* Write command to PCI bar space, read-modify-write */
3044 acc_range = SINGLE_WORD;
3045 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3046 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3047 writel(value, mem_mapped_bar + offset);
3048 readl(mem_mapped_bar + offset);
3050 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3051 u32val = readl(mem_mapped_bar + offset);
3053 writel(u32val, mem_mapped_bar + offset);
3054 readl(mem_mapped_bar + offset);
3056 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3057 u32val = readl(mem_mapped_bar + offset);
3059 writel(u32val, mem_mapped_bar + offset);
3060 readl(mem_mapped_bar + offset);
3063 /* All other opecodes are illegal for now */
3068 memset(&idiag, 0, sizeof(idiag));
3073 __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3074 char *pbuffer, int len)
3079 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3080 "\t\t%s WQ info: ", wqtype);
3081 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3082 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3083 qp->assoc_qid, qp->q_cnt_1,
3084 (unsigned long long)qp->q_cnt_4);
3085 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3086 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3087 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3088 qp->queue_id, qp->entry_count,
3089 qp->entry_size, qp->host_index,
3090 qp->hba_index, qp->entry_repost);
3091 len += snprintf(pbuffer + len,
3092 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3097 lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3098 int *len, int max_cnt, int cq_id)
3100 struct lpfc_queue *qp;
3103 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3104 qp = phba->sli4_hba.fcp_wq[qidx];
3105 if (qp->assoc_qid != cq_id)
3107 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3108 if (*len >= max_cnt)
3111 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3112 qp = phba->sli4_hba.nvme_wq[qidx];
3113 if (qp->assoc_qid != cq_id)
3115 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3116 if (*len >= max_cnt)
3123 __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3124 char *pbuffer, int len)
3129 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3130 "\t%s CQ info: ", cqtype);
3131 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3132 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3133 "xabt:x%x wq:x%llx]\n",
3134 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3135 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3136 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3137 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3138 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3139 qp->queue_id, qp->entry_count,
3140 qp->entry_size, qp->host_index,
3141 qp->hba_index, qp->entry_repost);
3143 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3149 __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3150 char *rqtype, char *pbuffer, int len)
3155 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3156 "\t\t%s RQ info: ", rqtype);
3157 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3158 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
3159 "posted:x%x rcv:x%llx]\n",
3160 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3161 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3162 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3163 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3164 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
3165 qp->queue_id, qp->entry_count, qp->entry_size,
3166 qp->host_index, qp->hba_index, qp->entry_repost);
3167 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3168 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3169 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
3170 datqp->queue_id, datqp->entry_count,
3171 datqp->entry_size, datqp->host_index,
3172 datqp->hba_index, datqp->entry_repost);
3177 lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
3178 int *len, int max_cnt, int eqidx, int eq_id)
3180 struct lpfc_queue *qp;
3183 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3184 qp = phba->sli4_hba.fcp_cq[qidx];
3185 if (qp->assoc_qid != eq_id)
3188 *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
3190 /* Reset max counter */
3193 if (*len >= max_cnt)
3196 rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
3197 max_cnt, qp->queue_id);
3202 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3203 qp = phba->sli4_hba.nvme_cq[qidx];
3204 if (qp->assoc_qid != eq_id)
3207 *len = __lpfc_idiag_print_cq(qp, "NVME", pbuffer, *len);
3209 /* Reset max counter */
3212 if (*len >= max_cnt)
3215 rc = lpfc_idiag_wqs_for_cq(phba, "NVME", pbuffer, len,
3216 max_cnt, qp->queue_id);
3221 if (eqidx < phba->cfg_nvmet_mrq) {
3223 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3224 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3226 /* Reset max counter */
3229 if (*len >= max_cnt)
3233 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3234 *len = __lpfc_idiag_print_rqpair(qp,
3235 phba->sli4_hba.nvmet_mrq_data[eqidx],
3236 "NVMET MRQ", pbuffer, *len);
3238 if (*len >= max_cnt)
3246 __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
3247 char *pbuffer, int len)
3252 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3253 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
3254 "bs:x%x proc:x%llx eqd %d]\n",
3255 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
3256 (unsigned long long)qp->q_cnt_4, qp->q_mode);
3257 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3258 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3259 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3260 qp->queue_id, qp->entry_count, qp->entry_size,
3261 qp->host_index, qp->hba_index, qp->entry_repost);
3262 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3268 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
3269 * @file: The file pointer to read from.
3270 * @buf: The buffer to copy the data to.
3271 * @nbytes: The number of bytes to read.
3272 * @ppos: The position in the file to start reading from.
3275 * This routine reads data from the @phba SLI4 PCI function queue information,
3276 * and copies to user @buf.
3277 * This routine only returns 1 EQs worth of information. It remembers the last
3278 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
3279 * retrieve all EQs allocated for the phba.
3282 * This function returns the amount of data that was read (this could be less
3283 * than @nbytes if the end of the file was reached) or a negative error value.
3286 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
3289 struct lpfc_debug *debug = file->private_data;
3290 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3292 int max_cnt, rc, x, len = 0;
3293 struct lpfc_queue *qp = NULL;
3296 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
3299 pbuffer = debug->buffer;
3300 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
3305 spin_lock_irq(&phba->hbalock);
3307 /* Fast-path event queue */
3308 if (phba->sli4_hba.hba_eq && phba->io_channel_irqs) {
3310 x = phba->lpfc_idiag_last_eq;
3311 if (phba->cfg_fof && (x >= phba->io_channel_irqs)) {
3312 phba->lpfc_idiag_last_eq = 0;
3315 phba->lpfc_idiag_last_eq++;
3316 if (phba->lpfc_idiag_last_eq >= phba->io_channel_irqs)
3317 if (phba->cfg_fof == 0)
3318 phba->lpfc_idiag_last_eq = 0;
3320 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3321 "EQ %d out of %d HBA EQs\n",
3322 x, phba->io_channel_irqs);
3325 qp = phba->sli4_hba.hba_eq[x];
3329 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
3331 /* Reset max counter */
3337 /* will dump both fcp and nvme cqs/wqs for the eq */
3338 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
3339 max_cnt, x, qp->queue_id);
3343 /* Only EQ 0 has slow path CQs configured */
3347 /* Slow-path mailbox CQ */
3348 qp = phba->sli4_hba.mbx_cq;
3349 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
3353 /* Slow-path MBOX MQ */
3354 qp = phba->sli4_hba.mbx_wq;
3355 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
3359 /* Slow-path ELS response CQ */
3360 qp = phba->sli4_hba.els_cq;
3361 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
3362 /* Reset max counter */
3368 /* Slow-path ELS WQ */
3369 qp = phba->sli4_hba.els_wq;
3370 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
3374 /* Slow-path NVME LS response CQ */
3375 qp = phba->sli4_hba.nvmels_cq;
3376 len = __lpfc_idiag_print_cq(qp, "NVME LS",
3378 /* Reset max counter */
3384 /* Slow-path NVME LS WQ */
3385 qp = phba->sli4_hba.nvmels_wq;
3386 len = __lpfc_idiag_print_wq(qp, "NVME LS",
3391 qp = phba->sli4_hba.hdr_rq;
3392 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
3393 "RQpair", pbuffer, len);
3401 if (phba->cfg_fof) {
3403 qp = phba->sli4_hba.fof_eq;
3404 len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
3406 /* Reset max counter */
3414 qp = phba->sli4_hba.oas_cq;
3415 len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
3416 /* Reset max counter */
3423 qp = phba->sli4_hba.oas_wq;
3424 len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
3429 spin_unlock_irq(&phba->hbalock);
3430 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3433 len += snprintf(pbuffer + len,
3434 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
3436 spin_unlock_irq(&phba->hbalock);
3437 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3441 * lpfc_idiag_que_param_check - queue access command parameter sanity check
3442 * @q: The pointer to queue structure.
3443 * @index: The index into a queue entry.
3444 * @count: The number of queue entries to access.
3447 * The routine performs sanity check on device queue access method commands.
3450 * This function returns -EINVAL when fails the sanity check, otherwise, it
3454 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
3456 /* Only support single entry read or browsing */
3457 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
3459 if (index > q->entry_count - 1)
3465 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
3466 * @pbuffer: The pointer to buffer to copy the read data into.
3467 * @pque: The pointer to the queue to be read.
3468 * @index: The index into the queue entry.
3471 * This routine reads out a single entry from the given queue's index location
3472 * and copies it into the buffer provided.
3475 * This function returns 0 when it fails, otherwise, it returns the length of
3476 * the data read into the buffer provided.
3479 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
3485 if (!pbuffer || !pque)
3488 esize = pque->entry_size;
3489 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3490 "QE-INDEX[%04d]:\n", index);
3493 pentry = pque->qe[index].address;
3495 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3498 offset += sizeof(uint32_t);
3499 esize -= sizeof(uint32_t);
3500 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
3501 len += snprintf(pbuffer+len,
3502 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3504 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3510 * lpfc_idiag_queacc_read - idiag debugfs read port queue
3511 * @file: The file pointer to read from.
3512 * @buf: The buffer to copy the data to.
3513 * @nbytes: The number of bytes to read.
3514 * @ppos: The position in the file to start reading from.
3517 * This routine reads data from the @phba device queue memory according to the
3518 * idiag command, and copies to user @buf. Depending on the queue dump read
3519 * command setup, it does either a single queue entry read or browing through
3520 * all entries of the queue.
3523 * This function returns the amount of data that was read (this could be less
3524 * than @nbytes if the end of the file was reached) or a negative error value.
3527 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
3530 struct lpfc_debug *debug = file->private_data;
3531 uint32_t last_index, index, count;
3532 struct lpfc_queue *pque = NULL;
3536 /* This is a user read operation */
3537 debug->op = LPFC_IDIAG_OP_RD;
3540 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
3543 pbuffer = debug->buffer;
3548 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3549 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3550 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3551 pque = (struct lpfc_queue *)idiag.ptr_private;
3555 /* Browse the queue starting from index */
3556 if (count == LPFC_QUE_ACC_BROWSE)
3559 /* Read a single entry from the queue */
3560 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3562 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3566 /* Browse all entries from the queue */
3567 last_index = idiag.offset.last_rd;
3570 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
3571 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3573 if (index > pque->entry_count - 1)
3577 /* Set up the offset for next portion of pci cfg read */
3578 if (index > pque->entry_count - 1)
3580 idiag.offset.last_rd = index;
3582 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3586 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
3587 * @file: The file pointer to read from.
3588 * @buf: The buffer to copy the user data from.
3589 * @nbytes: The number of bytes to get.
3590 * @ppos: The position in the file to start reading from.
3592 * This routine get the debugfs idiag command struct from user space and then
3593 * perform the syntax check for port queue read (dump) or write (set) command
3594 * accordingly. In the case of port queue read command, it sets up the command
3595 * in the idiag command struct for the following debugfs read operation. In
3596 * the case of port queue write operation, it executes the write operation
3597 * into the port queue entry accordingly.
3599 * It returns the @nbytges passing in from debugfs user space when successful.
3600 * In case of error conditions, it returns proper error code back to the user
3604 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3605 size_t nbytes, loff_t *ppos)
3607 struct lpfc_debug *debug = file->private_data;
3608 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3609 uint32_t qidx, quetp, queid, index, count, offset, value;
3611 struct lpfc_queue *pque, *qp;
3614 /* This is a user write operation */
3615 debug->op = LPFC_IDIAG_OP_WR;
3617 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3621 /* Get and sanity check on command feilds */
3622 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
3623 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
3624 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3625 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3626 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
3627 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
3629 /* Sanity check on command line arguments */
3630 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3631 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3632 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3633 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
3637 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3638 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
3645 /* HBA event queue */
3646 if (phba->sli4_hba.hba_eq) {
3647 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
3648 qp = phba->sli4_hba.hba_eq[qidx];
3649 if (qp && qp->queue_id == queid) {
3651 rc = lpfc_idiag_que_param_check(qp,
3655 idiag.ptr_private = qp;
3663 /* MBX complete queue */
3664 if (phba->sli4_hba.mbx_cq &&
3665 phba->sli4_hba.mbx_cq->queue_id == queid) {
3667 rc = lpfc_idiag_que_param_check(
3668 phba->sli4_hba.mbx_cq, index, count);
3671 idiag.ptr_private = phba->sli4_hba.mbx_cq;
3674 /* ELS complete queue */
3675 if (phba->sli4_hba.els_cq &&
3676 phba->sli4_hba.els_cq->queue_id == queid) {
3678 rc = lpfc_idiag_que_param_check(
3679 phba->sli4_hba.els_cq, index, count);
3682 idiag.ptr_private = phba->sli4_hba.els_cq;
3685 /* NVME LS complete queue */
3686 if (phba->sli4_hba.nvmels_cq &&
3687 phba->sli4_hba.nvmels_cq->queue_id == queid) {
3689 rc = lpfc_idiag_que_param_check(
3690 phba->sli4_hba.nvmels_cq, index, count);
3693 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3696 /* FCP complete queue */
3697 if (phba->sli4_hba.fcp_cq) {
3698 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3700 qp = phba->sli4_hba.fcp_cq[qidx];
3701 if (qp && qp->queue_id == queid) {
3703 rc = lpfc_idiag_que_param_check(
3707 idiag.ptr_private = qp;
3712 /* NVME complete queue */
3713 if (phba->sli4_hba.nvme_cq) {
3716 if (phba->sli4_hba.nvme_cq[qidx] &&
3717 phba->sli4_hba.nvme_cq[qidx]->queue_id ==
3720 rc = lpfc_idiag_que_param_check(
3721 phba->sli4_hba.nvme_cq[qidx],
3726 phba->sli4_hba.nvme_cq[qidx];
3729 } while (++qidx < phba->cfg_nvme_io_channel);
3734 /* MBX work queue */
3735 if (phba->sli4_hba.mbx_wq &&
3736 phba->sli4_hba.mbx_wq->queue_id == queid) {
3738 rc = lpfc_idiag_que_param_check(
3739 phba->sli4_hba.mbx_wq, index, count);
3742 idiag.ptr_private = phba->sli4_hba.mbx_wq;
3748 /* ELS work queue */
3749 if (phba->sli4_hba.els_wq &&
3750 phba->sli4_hba.els_wq->queue_id == queid) {
3752 rc = lpfc_idiag_que_param_check(
3753 phba->sli4_hba.els_wq, index, count);
3756 idiag.ptr_private = phba->sli4_hba.els_wq;
3759 /* NVME LS work queue */
3760 if (phba->sli4_hba.nvmels_wq &&
3761 phba->sli4_hba.nvmels_wq->queue_id == queid) {
3763 rc = lpfc_idiag_que_param_check(
3764 phba->sli4_hba.nvmels_wq, index, count);
3767 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3770 /* FCP work queue */
3771 if (phba->sli4_hba.fcp_wq) {
3772 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3774 qp = phba->sli4_hba.fcp_wq[qidx];
3775 if (qp && qp->queue_id == queid) {
3777 rc = lpfc_idiag_que_param_check(
3781 idiag.ptr_private = qp;
3786 /* NVME work queue */
3787 if (phba->sli4_hba.nvme_wq) {
3788 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3790 qp = phba->sli4_hba.nvme_wq[qidx];
3791 if (qp && qp->queue_id == queid) {
3793 rc = lpfc_idiag_que_param_check(
3797 idiag.ptr_private = qp;
3803 /* NVME work queues */
3804 if (phba->sli4_hba.nvme_wq) {
3805 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3807 if (!phba->sli4_hba.nvme_wq[qidx])
3809 if (phba->sli4_hba.nvme_wq[qidx]->queue_id ==
3812 rc = lpfc_idiag_que_param_check(
3813 phba->sli4_hba.nvme_wq[qidx],
3818 phba->sli4_hba.nvme_wq[qidx];
3827 if (phba->sli4_hba.hdr_rq &&
3828 phba->sli4_hba.hdr_rq->queue_id == queid) {
3830 rc = lpfc_idiag_que_param_check(
3831 phba->sli4_hba.hdr_rq, index, count);
3834 idiag.ptr_private = phba->sli4_hba.hdr_rq;
3838 if (phba->sli4_hba.dat_rq &&
3839 phba->sli4_hba.dat_rq->queue_id == queid) {
3841 rc = lpfc_idiag_que_param_check(
3842 phba->sli4_hba.dat_rq, index, count);
3845 idiag.ptr_private = phba->sli4_hba.dat_rq;
3857 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3858 if (count == LPFC_QUE_ACC_BROWSE)
3859 idiag.offset.last_rd = index;
3862 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3863 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3864 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3865 /* Additional sanity checks on write operation */
3866 pque = (struct lpfc_queue *)idiag.ptr_private;
3867 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
3869 pentry = pque->qe[index].address;
3871 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
3873 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
3875 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
3881 /* Clean out command structure on command error out */
3882 memset(&idiag, 0, sizeof(idiag));
3887 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
3888 * @phba: The pointer to hba structure.
3889 * @pbuffer: The pointer to the buffer to copy the data to.
3890 * @len: The lenght of bytes to copied.
3891 * @drbregid: The id to doorbell registers.
3894 * This routine reads a doorbell register and copies its content to the
3895 * user buffer pointed to by @pbuffer.
3898 * This function returns the amount of data that was copied into @pbuffer.
3901 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
3902 int len, uint32_t drbregid)
3910 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3911 "EQCQ-DRB-REG: 0x%08x\n",
3912 readl(phba->sli4_hba.EQCQDBregaddr));
3915 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3916 "MQ-DRB-REG: 0x%08x\n",
3917 readl(phba->sli4_hba.MQDBregaddr));
3920 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3921 "WQ-DRB-REG: 0x%08x\n",
3922 readl(phba->sli4_hba.WQDBregaddr));
3925 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3926 "RQ-DRB-REG: 0x%08x\n",
3927 readl(phba->sli4_hba.RQDBregaddr));
3937 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
3938 * @file: The file pointer to read from.
3939 * @buf: The buffer to copy the data to.
3940 * @nbytes: The number of bytes to read.
3941 * @ppos: The position in the file to start reading from.
3944 * This routine reads data from the @phba device doorbell register according
3945 * to the idiag command, and copies to user @buf. Depending on the doorbell
3946 * register read command setup, it does either a single doorbell register
3947 * read or dump all doorbell registers.
3950 * This function returns the amount of data that was read (this could be less
3951 * than @nbytes if the end of the file was reached) or a negative error value.
3954 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
3957 struct lpfc_debug *debug = file->private_data;
3958 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3959 uint32_t drb_reg_id, i;
3963 /* This is a user read operation */
3964 debug->op = LPFC_IDIAG_OP_RD;
3967 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
3970 pbuffer = debug->buffer;
3975 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
3976 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
3980 if (drb_reg_id == LPFC_DRB_ACC_ALL)
3981 for (i = 1; i <= LPFC_DRB_MAX; i++)
3982 len = lpfc_idiag_drbacc_read_reg(phba,
3985 len = lpfc_idiag_drbacc_read_reg(phba,
3986 pbuffer, len, drb_reg_id);
3988 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3992 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
3993 * @file: The file pointer to read from.
3994 * @buf: The buffer to copy the user data from.
3995 * @nbytes: The number of bytes to get.
3996 * @ppos: The position in the file to start reading from.
3998 * This routine get the debugfs idiag command struct from user space and then
3999 * perform the syntax check for port doorbell register read (dump) or write
4000 * (set) command accordingly. In the case of port queue read command, it sets
4001 * up the command in the idiag command struct for the following debugfs read
4002 * operation. In the case of port doorbell register write operation, it
4003 * executes the write operation into the port doorbell register accordingly.
4005 * It returns the @nbytges passing in from debugfs user space when successful.
4006 * In case of error conditions, it returns proper error code back to the user
4010 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4011 size_t nbytes, loff_t *ppos)
4013 struct lpfc_debug *debug = file->private_data;
4014 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4015 uint32_t drb_reg_id, value, reg_val = 0;
4016 void __iomem *drb_reg;
4019 /* This is a user write operation */
4020 debug->op = LPFC_IDIAG_OP_WR;
4022 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4026 /* Sanity check on command line arguments */
4027 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4028 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
4030 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4031 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4032 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4033 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4035 if (drb_reg_id > LPFC_DRB_MAX)
4037 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4038 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4040 if ((drb_reg_id > LPFC_DRB_MAX) &&
4041 (drb_reg_id != LPFC_DRB_ACC_ALL))
4046 /* Perform the write access operation */
4047 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4048 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4049 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4050 switch (drb_reg_id) {
4052 drb_reg = phba->sli4_hba.EQCQDBregaddr;
4055 drb_reg = phba->sli4_hba.MQDBregaddr;
4058 drb_reg = phba->sli4_hba.WQDBregaddr;
4061 drb_reg = phba->sli4_hba.RQDBregaddr;
4067 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4069 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4070 reg_val = readl(drb_reg);
4073 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4074 reg_val = readl(drb_reg);
4077 writel(reg_val, drb_reg);
4078 readl(drb_reg); /* flush */
4083 /* Clean out command structure on command error out */
4084 memset(&idiag, 0, sizeof(idiag));
4089 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4090 * @phba: The pointer to hba structure.
4091 * @pbuffer: The pointer to the buffer to copy the data to.
4092 * @len: The lenght of bytes to copied.
4093 * @drbregid: The id to doorbell registers.
4096 * This routine reads a control register and copies its content to the
4097 * user buffer pointed to by @pbuffer.
4100 * This function returns the amount of data that was copied into @pbuffer.
4103 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4104 int len, uint32_t ctlregid)
4111 case LPFC_CTL_PORT_SEM:
4112 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4113 "Port SemReg: 0x%08x\n",
4114 readl(phba->sli4_hba.conf_regs_memmap_p +
4115 LPFC_CTL_PORT_SEM_OFFSET));
4117 case LPFC_CTL_PORT_STA:
4118 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4119 "Port StaReg: 0x%08x\n",
4120 readl(phba->sli4_hba.conf_regs_memmap_p +
4121 LPFC_CTL_PORT_STA_OFFSET));
4123 case LPFC_CTL_PORT_CTL:
4124 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4125 "Port CtlReg: 0x%08x\n",
4126 readl(phba->sli4_hba.conf_regs_memmap_p +
4127 LPFC_CTL_PORT_CTL_OFFSET));
4129 case LPFC_CTL_PORT_ER1:
4130 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4131 "Port Er1Reg: 0x%08x\n",
4132 readl(phba->sli4_hba.conf_regs_memmap_p +
4133 LPFC_CTL_PORT_ER1_OFFSET));
4135 case LPFC_CTL_PORT_ER2:
4136 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4137 "Port Er2Reg: 0x%08x\n",
4138 readl(phba->sli4_hba.conf_regs_memmap_p +
4139 LPFC_CTL_PORT_ER2_OFFSET));
4141 case LPFC_CTL_PDEV_CTL:
4142 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4143 "PDev CtlReg: 0x%08x\n",
4144 readl(phba->sli4_hba.conf_regs_memmap_p +
4145 LPFC_CTL_PDEV_CTL_OFFSET));
4154 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4155 * @file: The file pointer to read from.
4156 * @buf: The buffer to copy the data to.
4157 * @nbytes: The number of bytes to read.
4158 * @ppos: The position in the file to start reading from.
4161 * This routine reads data from the @phba port and device registers according
4162 * to the idiag command, and copies to user @buf.
4165 * This function returns the amount of data that was read (this could be less
4166 * than @nbytes if the end of the file was reached) or a negative error value.
4169 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4172 struct lpfc_debug *debug = file->private_data;
4173 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4174 uint32_t ctl_reg_id, i;
4178 /* This is a user read operation */
4179 debug->op = LPFC_IDIAG_OP_RD;
4182 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4185 pbuffer = debug->buffer;
4190 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4191 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4195 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4196 for (i = 1; i <= LPFC_CTL_MAX; i++)
4197 len = lpfc_idiag_ctlacc_read_reg(phba,
4200 len = lpfc_idiag_ctlacc_read_reg(phba,
4201 pbuffer, len, ctl_reg_id);
4203 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4207 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4208 * @file: The file pointer to read from.
4209 * @buf: The buffer to copy the user data from.
4210 * @nbytes: The number of bytes to get.
4211 * @ppos: The position in the file to start reading from.
4213 * This routine get the debugfs idiag command struct from user space and then
4214 * perform the syntax check for port and device control register read (dump)
4215 * or write (set) command accordingly.
4217 * It returns the @nbytges passing in from debugfs user space when successful.
4218 * In case of error conditions, it returns proper error code back to the user
4222 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4223 size_t nbytes, loff_t *ppos)
4225 struct lpfc_debug *debug = file->private_data;
4226 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4227 uint32_t ctl_reg_id, value, reg_val = 0;
4228 void __iomem *ctl_reg;
4231 /* This is a user write operation */
4232 debug->op = LPFC_IDIAG_OP_WR;
4234 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4238 /* Sanity check on command line arguments */
4239 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4240 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4242 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4243 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4244 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4245 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4247 if (ctl_reg_id > LPFC_CTL_MAX)
4249 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4250 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4252 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4253 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4258 /* Perform the write access operation */
4259 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4260 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4261 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4262 switch (ctl_reg_id) {
4263 case LPFC_CTL_PORT_SEM:
4264 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4265 LPFC_CTL_PORT_SEM_OFFSET;
4267 case LPFC_CTL_PORT_STA:
4268 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4269 LPFC_CTL_PORT_STA_OFFSET;
4271 case LPFC_CTL_PORT_CTL:
4272 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4273 LPFC_CTL_PORT_CTL_OFFSET;
4275 case LPFC_CTL_PORT_ER1:
4276 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4277 LPFC_CTL_PORT_ER1_OFFSET;
4279 case LPFC_CTL_PORT_ER2:
4280 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4281 LPFC_CTL_PORT_ER2_OFFSET;
4283 case LPFC_CTL_PDEV_CTL:
4284 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4285 LPFC_CTL_PDEV_CTL_OFFSET;
4291 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4293 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4294 reg_val = readl(ctl_reg);
4297 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4298 reg_val = readl(ctl_reg);
4301 writel(reg_val, ctl_reg);
4302 readl(ctl_reg); /* flush */
4307 /* Clean out command structure on command error out */
4308 memset(&idiag, 0, sizeof(idiag));
4313 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4314 * @phba: Pointer to HBA context object.
4315 * @pbuffer: Pointer to data buffer.
4318 * This routine gets the driver mailbox access debugfs setup information.
4321 * This function returns the amount of data that was read (this could be less
4322 * than @nbytes if the end of the file was reached) or a negative error value.
4325 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
4327 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4330 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4331 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4332 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4333 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4335 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4336 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
4337 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4338 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
4339 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4340 "mbx_word_cnt: %04d\n", mbx_word_cnt);
4341 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4342 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
4348 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
4349 * @file: The file pointer to read from.
4350 * @buf: The buffer to copy the data to.
4351 * @nbytes: The number of bytes to read.
4352 * @ppos: The position in the file to start reading from.
4355 * This routine reads data from the @phba driver mailbox access debugfs setup
4359 * This function returns the amount of data that was read (this could be less
4360 * than @nbytes if the end of the file was reached) or a negative error value.
4363 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
4366 struct lpfc_debug *debug = file->private_data;
4367 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4371 /* This is a user read operation */
4372 debug->op = LPFC_IDIAG_OP_RD;
4375 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
4378 pbuffer = debug->buffer;
4383 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
4384 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
4387 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
4389 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4393 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
4394 * @file: The file pointer to read from.
4395 * @buf: The buffer to copy the user data from.
4396 * @nbytes: The number of bytes to get.
4397 * @ppos: The position in the file to start reading from.
4399 * This routine get the debugfs idiag command struct from user space and then
4400 * perform the syntax check for driver mailbox command (dump) and sets up the
4401 * necessary states in the idiag command struct accordingly.
4403 * It returns the @nbytges passing in from debugfs user space when successful.
4404 * In case of error conditions, it returns proper error code back to the user
4408 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
4409 size_t nbytes, loff_t *ppos)
4411 struct lpfc_debug *debug = file->private_data;
4412 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4415 /* This is a user write operation */
4416 debug->op = LPFC_IDIAG_OP_WR;
4418 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4422 /* Sanity check on command line arguments */
4423 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4424 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4425 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4426 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4428 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
4429 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
4431 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
4432 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4434 if (mbx_word_cnt > sizeof(MAILBOX_t))
4436 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
4437 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
4439 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
4440 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4442 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
4444 if (mbx_mbox_cmd != 0x9b)
4449 if (mbx_word_cnt == 0)
4451 if (rc != LPFC_MBX_DMP_ARG)
4453 if (mbx_mbox_cmd & ~0xff)
4456 /* condition for stop mailbox dump */
4457 if (mbx_dump_cnt == 0)
4463 /* Clean out command structure on command error out */
4464 memset(&idiag, 0, sizeof(idiag));
4468 /* Clean out command structure on command error out */
4469 memset(&idiag, 0, sizeof(idiag));
4474 * lpfc_idiag_extacc_avail_get - get the available extents information
4475 * @phba: pointer to lpfc hba data structure.
4476 * @pbuffer: pointer to internal buffer.
4477 * @len: length into the internal buffer data has been copied.
4480 * This routine is to get the available extent information.
4483 * overall lenth of the data read into the internal buffer.
4486 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
4488 uint16_t ext_cnt, ext_size;
4490 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4491 "\nAvailable Extents Information:\n");
4493 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4494 "\tPort Available VPI extents: ");
4495 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
4496 &ext_cnt, &ext_size);
4497 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4498 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4500 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4501 "\tPort Available VFI extents: ");
4502 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
4503 &ext_cnt, &ext_size);
4504 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4505 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4507 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4508 "\tPort Available RPI extents: ");
4509 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
4510 &ext_cnt, &ext_size);
4511 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4512 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4514 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4515 "\tPort Available XRI extents: ");
4516 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
4517 &ext_cnt, &ext_size);
4518 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4519 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4525 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
4526 * @phba: pointer to lpfc hba data structure.
4527 * @pbuffer: pointer to internal buffer.
4528 * @len: length into the internal buffer data has been copied.
4531 * This routine is to get the allocated extent information.
4534 * overall lenth of the data read into the internal buffer.
4537 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
4539 uint16_t ext_cnt, ext_size;
4542 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4543 "\nAllocated Extents Information:\n");
4545 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4546 "\tHost Allocated VPI extents: ");
4547 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
4548 &ext_cnt, &ext_size);
4550 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4551 "Port %d Extent %3d, Size %3d\n",
4552 phba->brd_no, ext_cnt, ext_size);
4554 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4557 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4558 "\tHost Allocated VFI extents: ");
4559 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
4560 &ext_cnt, &ext_size);
4562 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4563 "Port %d Extent %3d, Size %3d\n",
4564 phba->brd_no, ext_cnt, ext_size);
4566 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4569 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4570 "\tHost Allocated RPI extents: ");
4571 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
4572 &ext_cnt, &ext_size);
4574 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4575 "Port %d Extent %3d, Size %3d\n",
4576 phba->brd_no, ext_cnt, ext_size);
4578 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4581 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4582 "\tHost Allocated XRI extents: ");
4583 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
4584 &ext_cnt, &ext_size);
4586 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4587 "Port %d Extent %3d, Size %3d\n",
4588 phba->brd_no, ext_cnt, ext_size);
4590 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4597 * lpfc_idiag_extacc_drivr_get - get driver extent information
4598 * @phba: pointer to lpfc hba data structure.
4599 * @pbuffer: pointer to internal buffer.
4600 * @len: length into the internal buffer data has been copied.
4603 * This routine is to get the driver extent information.
4606 * overall lenth of the data read into the internal buffer.
4609 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
4611 struct lpfc_rsrc_blks *rsrc_blks;
4614 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4615 "\nDriver Extents Information:\n");
4617 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4618 "\tVPI extents:\n");
4620 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
4621 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4622 "\t\tBlock %3d: Start %4d, Count %4d\n",
4623 index, rsrc_blks->rsrc_start,
4624 rsrc_blks->rsrc_size);
4627 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4628 "\tVFI extents:\n");
4630 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
4632 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4633 "\t\tBlock %3d: Start %4d, Count %4d\n",
4634 index, rsrc_blks->rsrc_start,
4635 rsrc_blks->rsrc_size);
4639 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4640 "\tRPI extents:\n");
4642 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
4644 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4645 "\t\tBlock %3d: Start %4d, Count %4d\n",
4646 index, rsrc_blks->rsrc_start,
4647 rsrc_blks->rsrc_size);
4651 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4652 "\tXRI extents:\n");
4654 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
4656 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4657 "\t\tBlock %3d: Start %4d, Count %4d\n",
4658 index, rsrc_blks->rsrc_start,
4659 rsrc_blks->rsrc_size);
4667 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
4668 * @file: The file pointer to read from.
4669 * @buf: The buffer to copy the user data from.
4670 * @nbytes: The number of bytes to get.
4671 * @ppos: The position in the file to start reading from.
4673 * This routine get the debugfs idiag command struct from user space and then
4674 * perform the syntax check for extent information access commands and sets
4675 * up the necessary states in the idiag command struct accordingly.
4677 * It returns the @nbytges passing in from debugfs user space when successful.
4678 * In case of error conditions, it returns proper error code back to the user
4682 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
4683 size_t nbytes, loff_t *ppos)
4685 struct lpfc_debug *debug = file->private_data;
4689 /* This is a user write operation */
4690 debug->op = LPFC_IDIAG_OP_WR;
4692 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4696 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4698 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4700 if (rc != LPFC_EXT_ACC_CMD_ARG)
4702 if (!(ext_map & LPFC_EXT_ACC_ALL))
4707 /* Clean out command structure on command error out */
4708 memset(&idiag, 0, sizeof(idiag));
4713 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
4714 * @file: The file pointer to read from.
4715 * @buf: The buffer to copy the data to.
4716 * @nbytes: The number of bytes to read.
4717 * @ppos: The position in the file to start reading from.
4720 * This routine reads data from the proper extent information according to
4721 * the idiag command, and copies to user @buf.
4724 * This function returns the amount of data that was read (this could be less
4725 * than @nbytes if the end of the file was reached) or a negative error value.
4728 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
4731 struct lpfc_debug *debug = file->private_data;
4732 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4737 /* This is a user read operation */
4738 debug->op = LPFC_IDIAG_OP_RD;
4741 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
4744 pbuffer = debug->buffer;
4747 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4750 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4751 if (ext_map & LPFC_EXT_ACC_AVAIL)
4752 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
4753 if (ext_map & LPFC_EXT_ACC_ALLOC)
4754 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
4755 if (ext_map & LPFC_EXT_ACC_DRIVR)
4756 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
4758 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4761 #undef lpfc_debugfs_op_disc_trc
4762 static const struct file_operations lpfc_debugfs_op_disc_trc = {
4763 .owner = THIS_MODULE,
4764 .open = lpfc_debugfs_disc_trc_open,
4765 .llseek = lpfc_debugfs_lseek,
4766 .read = lpfc_debugfs_read,
4767 .release = lpfc_debugfs_release,
4770 #undef lpfc_debugfs_op_nodelist
4771 static const struct file_operations lpfc_debugfs_op_nodelist = {
4772 .owner = THIS_MODULE,
4773 .open = lpfc_debugfs_nodelist_open,
4774 .llseek = lpfc_debugfs_lseek,
4775 .read = lpfc_debugfs_read,
4776 .release = lpfc_debugfs_release,
4779 #undef lpfc_debugfs_op_hbqinfo
4780 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
4781 .owner = THIS_MODULE,
4782 .open = lpfc_debugfs_hbqinfo_open,
4783 .llseek = lpfc_debugfs_lseek,
4784 .read = lpfc_debugfs_read,
4785 .release = lpfc_debugfs_release,
4788 #undef lpfc_debugfs_op_dumpHBASlim
4789 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
4790 .owner = THIS_MODULE,
4791 .open = lpfc_debugfs_dumpHBASlim_open,
4792 .llseek = lpfc_debugfs_lseek,
4793 .read = lpfc_debugfs_read,
4794 .release = lpfc_debugfs_release,
4797 #undef lpfc_debugfs_op_dumpHostSlim
4798 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
4799 .owner = THIS_MODULE,
4800 .open = lpfc_debugfs_dumpHostSlim_open,
4801 .llseek = lpfc_debugfs_lseek,
4802 .read = lpfc_debugfs_read,
4803 .release = lpfc_debugfs_release,
4806 #undef lpfc_debugfs_op_nvmestat
4807 static const struct file_operations lpfc_debugfs_op_nvmestat = {
4808 .owner = THIS_MODULE,
4809 .open = lpfc_debugfs_nvmestat_open,
4810 .llseek = lpfc_debugfs_lseek,
4811 .read = lpfc_debugfs_read,
4812 .write = lpfc_debugfs_nvmestat_write,
4813 .release = lpfc_debugfs_release,
4816 #undef lpfc_debugfs_op_nvmektime
4817 static const struct file_operations lpfc_debugfs_op_nvmektime = {
4818 .owner = THIS_MODULE,
4819 .open = lpfc_debugfs_nvmektime_open,
4820 .llseek = lpfc_debugfs_lseek,
4821 .read = lpfc_debugfs_read,
4822 .write = lpfc_debugfs_nvmektime_write,
4823 .release = lpfc_debugfs_release,
4826 #undef lpfc_debugfs_op_nvmeio_trc
4827 static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
4828 .owner = THIS_MODULE,
4829 .open = lpfc_debugfs_nvmeio_trc_open,
4830 .llseek = lpfc_debugfs_lseek,
4831 .read = lpfc_debugfs_read,
4832 .write = lpfc_debugfs_nvmeio_trc_write,
4833 .release = lpfc_debugfs_release,
4836 #undef lpfc_debugfs_op_cpucheck
4837 static const struct file_operations lpfc_debugfs_op_cpucheck = {
4838 .owner = THIS_MODULE,
4839 .open = lpfc_debugfs_cpucheck_open,
4840 .llseek = lpfc_debugfs_lseek,
4841 .read = lpfc_debugfs_read,
4842 .write = lpfc_debugfs_cpucheck_write,
4843 .release = lpfc_debugfs_release,
4846 #undef lpfc_debugfs_op_dumpData
4847 static const struct file_operations lpfc_debugfs_op_dumpData = {
4848 .owner = THIS_MODULE,
4849 .open = lpfc_debugfs_dumpData_open,
4850 .llseek = lpfc_debugfs_lseek,
4851 .read = lpfc_debugfs_read,
4852 .write = lpfc_debugfs_dumpDataDif_write,
4853 .release = lpfc_debugfs_dumpDataDif_release,
4856 #undef lpfc_debugfs_op_dumpDif
4857 static const struct file_operations lpfc_debugfs_op_dumpDif = {
4858 .owner = THIS_MODULE,
4859 .open = lpfc_debugfs_dumpDif_open,
4860 .llseek = lpfc_debugfs_lseek,
4861 .read = lpfc_debugfs_read,
4862 .write = lpfc_debugfs_dumpDataDif_write,
4863 .release = lpfc_debugfs_dumpDataDif_release,
4866 #undef lpfc_debugfs_op_dif_err
4867 static const struct file_operations lpfc_debugfs_op_dif_err = {
4868 .owner = THIS_MODULE,
4869 .open = simple_open,
4870 .llseek = lpfc_debugfs_lseek,
4871 .read = lpfc_debugfs_dif_err_read,
4872 .write = lpfc_debugfs_dif_err_write,
4873 .release = lpfc_debugfs_dif_err_release,
4876 #undef lpfc_debugfs_op_slow_ring_trc
4877 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
4878 .owner = THIS_MODULE,
4879 .open = lpfc_debugfs_slow_ring_trc_open,
4880 .llseek = lpfc_debugfs_lseek,
4881 .read = lpfc_debugfs_read,
4882 .release = lpfc_debugfs_release,
4885 static struct dentry *lpfc_debugfs_root = NULL;
4886 static atomic_t lpfc_debugfs_hba_count;
4889 * File operations for the iDiag debugfs
4891 #undef lpfc_idiag_op_pciCfg
4892 static const struct file_operations lpfc_idiag_op_pciCfg = {
4893 .owner = THIS_MODULE,
4894 .open = lpfc_idiag_open,
4895 .llseek = lpfc_debugfs_lseek,
4896 .read = lpfc_idiag_pcicfg_read,
4897 .write = lpfc_idiag_pcicfg_write,
4898 .release = lpfc_idiag_cmd_release,
4901 #undef lpfc_idiag_op_barAcc
4902 static const struct file_operations lpfc_idiag_op_barAcc = {
4903 .owner = THIS_MODULE,
4904 .open = lpfc_idiag_open,
4905 .llseek = lpfc_debugfs_lseek,
4906 .read = lpfc_idiag_baracc_read,
4907 .write = lpfc_idiag_baracc_write,
4908 .release = lpfc_idiag_cmd_release,
4911 #undef lpfc_idiag_op_queInfo
4912 static const struct file_operations lpfc_idiag_op_queInfo = {
4913 .owner = THIS_MODULE,
4914 .open = lpfc_idiag_open,
4915 .read = lpfc_idiag_queinfo_read,
4916 .release = lpfc_idiag_release,
4919 #undef lpfc_idiag_op_queAcc
4920 static const struct file_operations lpfc_idiag_op_queAcc = {
4921 .owner = THIS_MODULE,
4922 .open = lpfc_idiag_open,
4923 .llseek = lpfc_debugfs_lseek,
4924 .read = lpfc_idiag_queacc_read,
4925 .write = lpfc_idiag_queacc_write,
4926 .release = lpfc_idiag_cmd_release,
4929 #undef lpfc_idiag_op_drbAcc
4930 static const struct file_operations lpfc_idiag_op_drbAcc = {
4931 .owner = THIS_MODULE,
4932 .open = lpfc_idiag_open,
4933 .llseek = lpfc_debugfs_lseek,
4934 .read = lpfc_idiag_drbacc_read,
4935 .write = lpfc_idiag_drbacc_write,
4936 .release = lpfc_idiag_cmd_release,
4939 #undef lpfc_idiag_op_ctlAcc
4940 static const struct file_operations lpfc_idiag_op_ctlAcc = {
4941 .owner = THIS_MODULE,
4942 .open = lpfc_idiag_open,
4943 .llseek = lpfc_debugfs_lseek,
4944 .read = lpfc_idiag_ctlacc_read,
4945 .write = lpfc_idiag_ctlacc_write,
4946 .release = lpfc_idiag_cmd_release,
4949 #undef lpfc_idiag_op_mbxAcc
4950 static const struct file_operations lpfc_idiag_op_mbxAcc = {
4951 .owner = THIS_MODULE,
4952 .open = lpfc_idiag_open,
4953 .llseek = lpfc_debugfs_lseek,
4954 .read = lpfc_idiag_mbxacc_read,
4955 .write = lpfc_idiag_mbxacc_write,
4956 .release = lpfc_idiag_cmd_release,
4959 #undef lpfc_idiag_op_extAcc
4960 static const struct file_operations lpfc_idiag_op_extAcc = {
4961 .owner = THIS_MODULE,
4962 .open = lpfc_idiag_open,
4963 .llseek = lpfc_debugfs_lseek,
4964 .read = lpfc_idiag_extacc_read,
4965 .write = lpfc_idiag_extacc_write,
4966 .release = lpfc_idiag_cmd_release,
4971 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
4972 * @phba: Pointer to HBA context object.
4973 * @dmabuf: Pointer to a DMA buffer descriptor.
4976 * This routine dump a bsg pass-through non-embedded mailbox command with
4980 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
4981 enum mbox_type mbox_tp, enum dma_type dma_tp,
4982 enum sta_type sta_tp,
4983 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
4985 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4986 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
4987 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
4989 uint32_t do_dump = 0;
4993 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
4996 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4997 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4998 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4999 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5001 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
5002 (*mbx_dump_cnt == 0) ||
5003 (*mbx_word_cnt == 0))
5006 if (*mbx_mbox_cmd != 0x9B)
5009 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5010 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5011 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
5012 pr_err("\nRead mbox command (x%x), "
5013 "nemb:0x%x, extbuf_cnt:%d:\n",
5014 sta_tp, nemb_tp, ext_buf);
5017 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5018 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5019 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
5020 pr_err("\nRead mbox buffer (x%x), "
5021 "nemb:0x%x, extbuf_seq:%d:\n",
5022 sta_tp, nemb_tp, ext_buf);
5025 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5026 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5027 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
5028 pr_err("\nWrite mbox command (x%x), "
5029 "nemb:0x%x, extbuf_cnt:%d:\n",
5030 sta_tp, nemb_tp, ext_buf);
5033 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5034 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5035 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
5036 pr_err("\nWrite mbox buffer (x%x), "
5037 "nemb:0x%x, extbuf_seq:%d:\n",
5038 sta_tp, nemb_tp, ext_buf);
5042 /* dump buffer content */
5044 pword = (uint32_t *)dmabuf->virt;
5045 for (i = 0; i < *mbx_word_cnt; i++) {
5048 pr_err("%s\n", line_buf);
5050 len += snprintf(line_buf+len,
5051 LPFC_MBX_ACC_LBUF_SZ-len,
5054 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5055 "%08x ", (uint32_t)*pword);
5059 pr_err("%s\n", line_buf);
5063 /* Clean out command structure on reaching dump count */
5064 if (*mbx_dump_cnt == 0)
5065 memset(&idiag, 0, sizeof(idiag));
5070 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5071 * @phba: Pointer to HBA context object.
5072 * @dmabuf: Pointer to a DMA buffer descriptor.
5075 * This routine dump a pass-through non-embedded mailbox command from issue
5079 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5081 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5082 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5083 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5089 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5092 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5093 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5094 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5095 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5097 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5098 (*mbx_dump_cnt == 0) ||
5099 (*mbx_word_cnt == 0))
5102 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5103 (*mbx_mbox_cmd != pmbox->mbxCommand))
5106 /* dump buffer content */
5107 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
5108 pr_err("Mailbox command:0x%x dump by word:\n",
5110 pword = (uint32_t *)pmbox;
5111 for (i = 0; i < *mbx_word_cnt; i++) {
5114 pr_err("%s\n", line_buf);
5116 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5117 len += snprintf(line_buf+len,
5118 LPFC_MBX_ACC_LBUF_SZ-len,
5121 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5123 ((uint32_t)*pword) & 0xffffffff);
5127 pr_err("%s\n", line_buf);
5130 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
5131 pr_err("Mailbox command:0x%x dump by byte:\n",
5133 pbyte = (uint8_t *)pmbox;
5134 for (i = 0; i < *mbx_word_cnt; i++) {
5137 pr_err("%s\n", line_buf);
5139 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5140 len += snprintf(line_buf+len,
5141 LPFC_MBX_ACC_LBUF_SZ-len,
5144 for (j = 0; j < 4; j++) {
5145 len += snprintf(line_buf+len,
5146 LPFC_MBX_ACC_LBUF_SZ-len,
5148 ((uint8_t)*pbyte) & 0xff);
5151 len += snprintf(line_buf+len,
5152 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5155 pr_err("%s\n", line_buf);
5160 /* Clean out command structure on reaching dump count */
5161 if (*mbx_dump_cnt == 0)
5162 memset(&idiag, 0, sizeof(idiag));
5168 * lpfc_debugfs_initialize - Initialize debugfs for a vport
5169 * @vport: The vport pointer to initialize.
5172 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5173 * If not already created, this routine will create the lpfc directory, and
5174 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5175 * also create each file used to access lpfc specific debugfs information.
5178 lpfc_debugfs_initialize(struct lpfc_vport *vport)
5180 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5181 struct lpfc_hba *phba = vport->phba;
5184 bool pport_setup = false;
5186 if (!lpfc_debugfs_enable)
5189 /* Setup lpfc root directory */
5190 if (!lpfc_debugfs_root) {
5191 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5192 atomic_set(&lpfc_debugfs_hba_count, 0);
5193 if (!lpfc_debugfs_root) {
5194 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5195 "0408 Cannot create debugfs root\n");
5199 if (!lpfc_debugfs_start_time)
5200 lpfc_debugfs_start_time = jiffies;
5202 /* Setup funcX directory for specific HBA PCI function */
5203 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
5204 if (!phba->hba_debugfs_root) {
5206 phba->hba_debugfs_root =
5207 debugfs_create_dir(name, lpfc_debugfs_root);
5208 if (!phba->hba_debugfs_root) {
5209 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5210 "0412 Cannot create debugfs hba\n");
5213 atomic_inc(&lpfc_debugfs_hba_count);
5214 atomic_set(&phba->debugfs_vport_count, 0);
5217 snprintf(name, sizeof(name), "hbqinfo");
5218 phba->debug_hbqinfo =
5219 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5220 phba->hba_debugfs_root,
5221 phba, &lpfc_debugfs_op_hbqinfo);
5222 if (!phba->debug_hbqinfo) {
5223 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5224 "0411 Cannot create debugfs hbqinfo\n");
5228 /* Setup dumpHBASlim */
5229 if (phba->sli_rev < LPFC_SLI_REV4) {
5230 snprintf(name, sizeof(name), "dumpHBASlim");
5231 phba->debug_dumpHBASlim =
5232 debugfs_create_file(name,
5233 S_IFREG|S_IRUGO|S_IWUSR,
5234 phba->hba_debugfs_root,
5235 phba, &lpfc_debugfs_op_dumpHBASlim);
5236 if (!phba->debug_dumpHBASlim) {
5237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5238 "0413 Cannot create debugfs "
5243 phba->debug_dumpHBASlim = NULL;
5245 /* Setup dumpHostSlim */
5246 if (phba->sli_rev < LPFC_SLI_REV4) {
5247 snprintf(name, sizeof(name), "dumpHostSlim");
5248 phba->debug_dumpHostSlim =
5249 debugfs_create_file(name,
5250 S_IFREG|S_IRUGO|S_IWUSR,
5251 phba->hba_debugfs_root,
5252 phba, &lpfc_debugfs_op_dumpHostSlim);
5253 if (!phba->debug_dumpHostSlim) {
5254 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5255 "0414 Cannot create debugfs "
5260 phba->debug_dumpHostSlim = NULL;
5262 /* Setup dumpData */
5263 snprintf(name, sizeof(name), "dumpData");
5264 phba->debug_dumpData =
5265 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5266 phba->hba_debugfs_root,
5267 phba, &lpfc_debugfs_op_dumpData);
5268 if (!phba->debug_dumpData) {
5269 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5270 "0800 Cannot create debugfs dumpData\n");
5275 snprintf(name, sizeof(name), "dumpDif");
5276 phba->debug_dumpDif =
5277 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5278 phba->hba_debugfs_root,
5279 phba, &lpfc_debugfs_op_dumpDif);
5280 if (!phba->debug_dumpDif) {
5281 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5282 "0801 Cannot create debugfs dumpDif\n");
5286 /* Setup DIF Error Injections */
5287 snprintf(name, sizeof(name), "InjErrLBA");
5288 phba->debug_InjErrLBA =
5289 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5290 phba->hba_debugfs_root,
5291 phba, &lpfc_debugfs_op_dif_err);
5292 if (!phba->debug_InjErrLBA) {
5293 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5294 "0807 Cannot create debugfs InjErrLBA\n");
5297 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5299 snprintf(name, sizeof(name), "InjErrNPortID");
5300 phba->debug_InjErrNPortID =
5301 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5302 phba->hba_debugfs_root,
5303 phba, &lpfc_debugfs_op_dif_err);
5304 if (!phba->debug_InjErrNPortID) {
5305 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5306 "0809 Cannot create debugfs InjErrNPortID\n");
5310 snprintf(name, sizeof(name), "InjErrWWPN");
5311 phba->debug_InjErrWWPN =
5312 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5313 phba->hba_debugfs_root,
5314 phba, &lpfc_debugfs_op_dif_err);
5315 if (!phba->debug_InjErrWWPN) {
5316 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5317 "0810 Cannot create debugfs InjErrWWPN\n");
5321 snprintf(name, sizeof(name), "writeGuardInjErr");
5322 phba->debug_writeGuard =
5323 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5324 phba->hba_debugfs_root,
5325 phba, &lpfc_debugfs_op_dif_err);
5326 if (!phba->debug_writeGuard) {
5327 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5328 "0802 Cannot create debugfs writeGuard\n");
5332 snprintf(name, sizeof(name), "writeAppInjErr");
5333 phba->debug_writeApp =
5334 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5335 phba->hba_debugfs_root,
5336 phba, &lpfc_debugfs_op_dif_err);
5337 if (!phba->debug_writeApp) {
5338 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5339 "0803 Cannot create debugfs writeApp\n");
5343 snprintf(name, sizeof(name), "writeRefInjErr");
5344 phba->debug_writeRef =
5345 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5346 phba->hba_debugfs_root,
5347 phba, &lpfc_debugfs_op_dif_err);
5348 if (!phba->debug_writeRef) {
5349 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5350 "0804 Cannot create debugfs writeRef\n");
5354 snprintf(name, sizeof(name), "readGuardInjErr");
5355 phba->debug_readGuard =
5356 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5357 phba->hba_debugfs_root,
5358 phba, &lpfc_debugfs_op_dif_err);
5359 if (!phba->debug_readGuard) {
5360 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5361 "0808 Cannot create debugfs readGuard\n");
5365 snprintf(name, sizeof(name), "readAppInjErr");
5366 phba->debug_readApp =
5367 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5368 phba->hba_debugfs_root,
5369 phba, &lpfc_debugfs_op_dif_err);
5370 if (!phba->debug_readApp) {
5371 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5372 "0805 Cannot create debugfs readApp\n");
5376 snprintf(name, sizeof(name), "readRefInjErr");
5377 phba->debug_readRef =
5378 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5379 phba->hba_debugfs_root,
5380 phba, &lpfc_debugfs_op_dif_err);
5381 if (!phba->debug_readRef) {
5382 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5383 "0806 Cannot create debugfs readApp\n");
5387 /* Setup slow ring trace */
5388 if (lpfc_debugfs_max_slow_ring_trc) {
5389 num = lpfc_debugfs_max_slow_ring_trc - 1;
5390 if (num & lpfc_debugfs_max_slow_ring_trc) {
5391 /* Change to be a power of 2 */
5392 num = lpfc_debugfs_max_slow_ring_trc;
5398 lpfc_debugfs_max_slow_ring_trc = (1 << i);
5399 pr_err("lpfc_debugfs_max_disc_trc changed to "
5400 "%d\n", lpfc_debugfs_max_disc_trc);
5404 snprintf(name, sizeof(name), "slow_ring_trace");
5405 phba->debug_slow_ring_trc =
5406 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5407 phba->hba_debugfs_root,
5408 phba, &lpfc_debugfs_op_slow_ring_trc);
5409 if (!phba->debug_slow_ring_trc) {
5410 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5411 "0415 Cannot create debugfs "
5412 "slow_ring_trace\n");
5415 if (!phba->slow_ring_trc) {
5416 phba->slow_ring_trc = kmalloc(
5417 (sizeof(struct lpfc_debugfs_trc) *
5418 lpfc_debugfs_max_slow_ring_trc),
5420 if (!phba->slow_ring_trc) {
5421 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5422 "0416 Cannot create debugfs "
5423 "slow_ring buffer\n");
5426 atomic_set(&phba->slow_ring_trc_cnt, 0);
5427 memset(phba->slow_ring_trc, 0,
5428 (sizeof(struct lpfc_debugfs_trc) *
5429 lpfc_debugfs_max_slow_ring_trc));
5432 snprintf(name, sizeof(name), "nvmeio_trc");
5433 phba->debug_nvmeio_trc =
5434 debugfs_create_file(name, 0644,
5435 phba->hba_debugfs_root,
5436 phba, &lpfc_debugfs_op_nvmeio_trc);
5437 if (!phba->debug_nvmeio_trc) {
5438 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5439 "0574 No create debugfs nvmeio_trc\n");
5443 atomic_set(&phba->nvmeio_trc_cnt, 0);
5444 if (lpfc_debugfs_max_nvmeio_trc) {
5445 num = lpfc_debugfs_max_nvmeio_trc - 1;
5446 if (num & lpfc_debugfs_max_disc_trc) {
5447 /* Change to be a power of 2 */
5448 num = lpfc_debugfs_max_nvmeio_trc;
5454 lpfc_debugfs_max_nvmeio_trc = (1 << i);
5455 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5456 "0575 lpfc_debugfs_max_nvmeio_trc "
5458 lpfc_debugfs_max_nvmeio_trc);
5460 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
5462 /* Allocate trace buffer and initialize */
5463 phba->nvmeio_trc = kmalloc(
5464 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5465 phba->nvmeio_trc_size), GFP_KERNEL);
5467 if (!phba->nvmeio_trc) {
5468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5469 "0576 Cannot create debugfs "
5470 "nvmeio_trc buffer\n");
5473 memset(phba->nvmeio_trc, 0,
5474 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5475 phba->nvmeio_trc_size));
5476 phba->nvmeio_trc_on = 1;
5477 phba->nvmeio_trc_output_idx = 0;
5478 phba->nvmeio_trc = NULL;
5481 phba->nvmeio_trc_size = 0;
5482 phba->nvmeio_trc_on = 0;
5483 phba->nvmeio_trc_output_idx = 0;
5484 phba->nvmeio_trc = NULL;
5488 snprintf(name, sizeof(name), "vport%d", vport->vpi);
5489 if (!vport->vport_debugfs_root) {
5490 vport->vport_debugfs_root =
5491 debugfs_create_dir(name, phba->hba_debugfs_root);
5492 if (!vport->vport_debugfs_root) {
5493 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5494 "0417 Can't create debugfs\n");
5497 atomic_inc(&phba->debugfs_vport_count);
5500 if (lpfc_debugfs_max_disc_trc) {
5501 num = lpfc_debugfs_max_disc_trc - 1;
5502 if (num & lpfc_debugfs_max_disc_trc) {
5503 /* Change to be a power of 2 */
5504 num = lpfc_debugfs_max_disc_trc;
5510 lpfc_debugfs_max_disc_trc = (1 << i);
5511 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
5512 lpfc_debugfs_max_disc_trc);
5516 vport->disc_trc = kzalloc(
5517 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
5520 if (!vport->disc_trc) {
5521 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5522 "0418 Cannot create debugfs disc trace "
5526 atomic_set(&vport->disc_trc_cnt, 0);
5528 snprintf(name, sizeof(name), "discovery_trace");
5529 vport->debug_disc_trc =
5530 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5531 vport->vport_debugfs_root,
5532 vport, &lpfc_debugfs_op_disc_trc);
5533 if (!vport->debug_disc_trc) {
5534 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5535 "0419 Cannot create debugfs "
5536 "discovery_trace\n");
5539 snprintf(name, sizeof(name), "nodelist");
5540 vport->debug_nodelist =
5541 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5542 vport->vport_debugfs_root,
5543 vport, &lpfc_debugfs_op_nodelist);
5544 if (!vport->debug_nodelist) {
5545 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5546 "2985 Can't create debugfs nodelist\n");
5550 snprintf(name, sizeof(name), "nvmestat");
5551 vport->debug_nvmestat =
5552 debugfs_create_file(name, 0644,
5553 vport->vport_debugfs_root,
5554 vport, &lpfc_debugfs_op_nvmestat);
5555 if (!vport->debug_nvmestat) {
5556 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5557 "0811 Cannot create debugfs nvmestat\n");
5561 snprintf(name, sizeof(name), "nvmektime");
5562 vport->debug_nvmektime =
5563 debugfs_create_file(name, 0644,
5564 vport->vport_debugfs_root,
5565 vport, &lpfc_debugfs_op_nvmektime);
5566 if (!vport->debug_nvmektime) {
5567 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5568 "0815 Cannot create debugfs nvmektime\n");
5572 snprintf(name, sizeof(name), "cpucheck");
5573 vport->debug_cpucheck =
5574 debugfs_create_file(name, 0644,
5575 vport->vport_debugfs_root,
5576 vport, &lpfc_debugfs_op_cpucheck);
5577 if (!vport->debug_cpucheck) {
5578 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5579 "0819 Cannot create debugfs cpucheck\n");
5584 * The following section is for additional directories/files for the
5592 * iDiag debugfs root entry points for SLI4 device only
5594 if (phba->sli_rev < LPFC_SLI_REV4)
5597 snprintf(name, sizeof(name), "iDiag");
5598 if (!phba->idiag_root) {
5600 debugfs_create_dir(name, phba->hba_debugfs_root);
5601 if (!phba->idiag_root) {
5602 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5603 "2922 Can't create idiag debugfs\n");
5606 /* Initialize iDiag data structure */
5607 memset(&idiag, 0, sizeof(idiag));
5610 /* iDiag read PCI config space */
5611 snprintf(name, sizeof(name), "pciCfg");
5612 if (!phba->idiag_pci_cfg) {
5613 phba->idiag_pci_cfg =
5614 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5615 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
5616 if (!phba->idiag_pci_cfg) {
5617 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5618 "2923 Can't create idiag debugfs\n");
5621 idiag.offset.last_rd = 0;
5624 /* iDiag PCI BAR access */
5625 snprintf(name, sizeof(name), "barAcc");
5626 if (!phba->idiag_bar_acc) {
5627 phba->idiag_bar_acc =
5628 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5629 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
5630 if (!phba->idiag_bar_acc) {
5631 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5632 "3056 Can't create idiag debugfs\n");
5635 idiag.offset.last_rd = 0;
5638 /* iDiag get PCI function queue information */
5639 snprintf(name, sizeof(name), "queInfo");
5640 if (!phba->idiag_que_info) {
5641 phba->idiag_que_info =
5642 debugfs_create_file(name, S_IFREG|S_IRUGO,
5643 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
5644 if (!phba->idiag_que_info) {
5645 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5646 "2924 Can't create idiag debugfs\n");
5651 /* iDiag access PCI function queue */
5652 snprintf(name, sizeof(name), "queAcc");
5653 if (!phba->idiag_que_acc) {
5654 phba->idiag_que_acc =
5655 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5656 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
5657 if (!phba->idiag_que_acc) {
5658 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5659 "2926 Can't create idiag debugfs\n");
5664 /* iDiag access PCI function doorbell registers */
5665 snprintf(name, sizeof(name), "drbAcc");
5666 if (!phba->idiag_drb_acc) {
5667 phba->idiag_drb_acc =
5668 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5669 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
5670 if (!phba->idiag_drb_acc) {
5671 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5672 "2927 Can't create idiag debugfs\n");
5677 /* iDiag access PCI function control registers */
5678 snprintf(name, sizeof(name), "ctlAcc");
5679 if (!phba->idiag_ctl_acc) {
5680 phba->idiag_ctl_acc =
5681 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5682 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
5683 if (!phba->idiag_ctl_acc) {
5684 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5685 "2981 Can't create idiag debugfs\n");
5690 /* iDiag access mbox commands */
5691 snprintf(name, sizeof(name), "mbxAcc");
5692 if (!phba->idiag_mbx_acc) {
5693 phba->idiag_mbx_acc =
5694 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5695 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
5696 if (!phba->idiag_mbx_acc) {
5697 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5698 "2980 Can't create idiag debugfs\n");
5703 /* iDiag extents access commands */
5704 if (phba->sli4_hba.extents_in_use) {
5705 snprintf(name, sizeof(name), "extAcc");
5706 if (!phba->idiag_ext_acc) {
5707 phba->idiag_ext_acc =
5708 debugfs_create_file(name,
5709 S_IFREG|S_IRUGO|S_IWUSR,
5710 phba->idiag_root, phba,
5711 &lpfc_idiag_op_extAcc);
5712 if (!phba->idiag_ext_acc) {
5713 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5727 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
5728 * @vport: The vport pointer to remove from debugfs.
5731 * When Debugfs is configured this routine removes debugfs file system elements
5732 * that are specific to this vport. It also checks to see if there are any
5733 * users left for the debugfs directories associated with the HBA and driver. If
5734 * this is the last user of the HBA directory or driver directory then it will
5735 * remove those from the debugfs infrastructure as well.
5738 lpfc_debugfs_terminate(struct lpfc_vport *vport)
5740 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5741 struct lpfc_hba *phba = vport->phba;
5743 kfree(vport->disc_trc);
5744 vport->disc_trc = NULL;
5746 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
5747 vport->debug_disc_trc = NULL;
5749 debugfs_remove(vport->debug_nodelist); /* nodelist */
5750 vport->debug_nodelist = NULL;
5752 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
5753 vport->debug_nvmestat = NULL;
5755 debugfs_remove(vport->debug_nvmektime); /* nvmektime */
5756 vport->debug_nvmektime = NULL;
5758 debugfs_remove(vport->debug_cpucheck); /* cpucheck */
5759 vport->debug_cpucheck = NULL;
5761 if (vport->vport_debugfs_root) {
5762 debugfs_remove(vport->vport_debugfs_root); /* vportX */
5763 vport->vport_debugfs_root = NULL;
5764 atomic_dec(&phba->debugfs_vport_count);
5767 if (atomic_read(&phba->debugfs_vport_count) == 0) {
5769 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
5770 phba->debug_hbqinfo = NULL;
5772 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
5773 phba->debug_dumpHBASlim = NULL;
5775 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
5776 phba->debug_dumpHostSlim = NULL;
5778 debugfs_remove(phba->debug_dumpData); /* dumpData */
5779 phba->debug_dumpData = NULL;
5781 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
5782 phba->debug_dumpDif = NULL;
5784 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
5785 phba->debug_InjErrLBA = NULL;
5787 debugfs_remove(phba->debug_InjErrNPortID);
5788 phba->debug_InjErrNPortID = NULL;
5790 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
5791 phba->debug_InjErrWWPN = NULL;
5793 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
5794 phba->debug_writeGuard = NULL;
5796 debugfs_remove(phba->debug_writeApp); /* writeApp */
5797 phba->debug_writeApp = NULL;
5799 debugfs_remove(phba->debug_writeRef); /* writeRef */
5800 phba->debug_writeRef = NULL;
5802 debugfs_remove(phba->debug_readGuard); /* readGuard */
5803 phba->debug_readGuard = NULL;
5805 debugfs_remove(phba->debug_readApp); /* readApp */
5806 phba->debug_readApp = NULL;
5808 debugfs_remove(phba->debug_readRef); /* readRef */
5809 phba->debug_readRef = NULL;
5811 kfree(phba->slow_ring_trc);
5812 phba->slow_ring_trc = NULL;
5814 /* slow_ring_trace */
5815 debugfs_remove(phba->debug_slow_ring_trc);
5816 phba->debug_slow_ring_trc = NULL;
5818 debugfs_remove(phba->debug_nvmeio_trc);
5819 phba->debug_nvmeio_trc = NULL;
5821 kfree(phba->nvmeio_trc);
5822 phba->nvmeio_trc = NULL;
5827 if (phba->sli_rev == LPFC_SLI_REV4) {
5829 debugfs_remove(phba->idiag_ext_acc);
5830 phba->idiag_ext_acc = NULL;
5833 debugfs_remove(phba->idiag_mbx_acc);
5834 phba->idiag_mbx_acc = NULL;
5837 debugfs_remove(phba->idiag_ctl_acc);
5838 phba->idiag_ctl_acc = NULL;
5841 debugfs_remove(phba->idiag_drb_acc);
5842 phba->idiag_drb_acc = NULL;
5845 debugfs_remove(phba->idiag_que_acc);
5846 phba->idiag_que_acc = NULL;
5849 debugfs_remove(phba->idiag_que_info);
5850 phba->idiag_que_info = NULL;
5853 debugfs_remove(phba->idiag_bar_acc);
5854 phba->idiag_bar_acc = NULL;
5857 debugfs_remove(phba->idiag_pci_cfg);
5858 phba->idiag_pci_cfg = NULL;
5860 /* Finally remove the iDiag debugfs root */
5861 debugfs_remove(phba->idiag_root);
5862 phba->idiag_root = NULL;
5865 if (phba->hba_debugfs_root) {
5866 debugfs_remove(phba->hba_debugfs_root); /* fnX */
5867 phba->hba_debugfs_root = NULL;
5868 atomic_dec(&lpfc_debugfs_hba_count);
5871 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
5872 debugfs_remove(lpfc_debugfs_root); /* lpfc */
5873 lpfc_debugfs_root = NULL;
5881 * Driver debug utility routines outside of debugfs. The debug utility
5882 * routines implemented here is intended to be used in the instrumented
5883 * debug driver for debugging host or port issues.
5887 * lpfc_debug_dump_all_queues - dump all the queues with a hba
5888 * @phba: Pointer to HBA context object.
5890 * This function dumps entries of all the queues asociated with the @phba.
5893 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
5898 * Dump Work Queues (WQs)
5900 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
5901 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
5902 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
5904 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5905 lpfc_debug_dump_wq(phba, DUMP_FCP, idx);
5907 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5908 lpfc_debug_dump_wq(phba, DUMP_NVME, idx);
5910 lpfc_debug_dump_hdr_rq(phba);
5911 lpfc_debug_dump_dat_rq(phba);
5913 * Dump Complete Queues (CQs)
5915 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
5916 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
5917 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
5919 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5920 lpfc_debug_dump_cq(phba, DUMP_FCP, idx);
5922 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5923 lpfc_debug_dump_cq(phba, DUMP_NVME, idx);
5926 * Dump Event Queues (EQs)
5928 for (idx = 0; idx < phba->io_channel_irqs; idx++)
5929 lpfc_debug_dump_hba_eq(phba, idx);