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 /* Calculate outstanding IOs */
855 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
856 tot += atomic_read(&tgtp->xmt_fcp_release);
857 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
859 len += snprintf(buf + len, size - len,
860 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
861 "CTX Outstanding %08llx\n",
862 phba->sli4_hba.nvmet_xri_cnt,
863 phba->sli4_hba.nvmet_io_wait_cnt,
864 phba->sli4_hba.nvmet_io_wait_total,
867 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
870 len += snprintf(buf + len, size - len,
871 "\nNVME Lport Statistics\n");
873 len += snprintf(buf + len, size - len,
874 "LS: Xmt %016x Cmpl %016x\n",
875 atomic_read(&phba->fc4NvmeLsRequests),
876 atomic_read(&phba->fc4NvmeLsCmpls));
878 tot = atomic_read(&phba->fc4NvmeIoCmpls);
879 data1 = atomic_read(&phba->fc4NvmeInputRequests);
880 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
881 data3 = atomic_read(&phba->fc4NvmeControlRequests);
883 len += snprintf(buf + len, size - len,
884 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
885 data1, data2, data3);
887 len += snprintf(buf + len, size - len,
888 " Cmpl %016llx Outstanding %016llx\n",
889 tot, (data1 + data2 + data3) - tot);
897 * lpfc_debugfs_nvmektime_data - Dump target node list to a buffer
898 * @vport: The vport to gather target node info from.
899 * @buf: The buffer to dump log into.
900 * @size: The maximum amount of data to process.
903 * This routine dumps the NVME statistics associated with @vport
906 * This routine returns the amount of bytes that were dumped into @buf and will
910 lpfc_debugfs_nvmektime_data(struct lpfc_vport *vport, char *buf, int size)
912 struct lpfc_hba *phba = vport->phba;
915 if (phba->nvmet_support == 0) {
917 len += snprintf(buf + len, PAGE_SIZE - len,
918 "ktime %s: Total Samples: %lld\n",
919 (phba->ktime_on ? "Enabled" : "Disabled"),
920 phba->ktime_data_samples);
921 if (phba->ktime_data_samples == 0)
925 buf + len, PAGE_SIZE - len,
926 "Segment 1: Last NVME Cmd cmpl "
927 "done -to- Start of next NVME cnd (in driver)\n");
929 buf + len, PAGE_SIZE - len,
930 "avg:%08lld min:%08lld max %08lld\n",
931 div_u64(phba->ktime_seg1_total,
932 phba->ktime_data_samples),
933 phba->ktime_seg1_min,
934 phba->ktime_seg1_max);
936 buf + len, PAGE_SIZE - len,
937 "Segment 2: Driver start of NVME cmd "
938 "-to- Firmware WQ doorbell\n");
940 buf + len, PAGE_SIZE - len,
941 "avg:%08lld min:%08lld max %08lld\n",
942 div_u64(phba->ktime_seg2_total,
943 phba->ktime_data_samples),
944 phba->ktime_seg2_min,
945 phba->ktime_seg2_max);
947 buf + len, PAGE_SIZE - len,
948 "Segment 3: Firmware WQ doorbell -to- "
951 buf + len, PAGE_SIZE - len,
952 "avg:%08lld min:%08lld max %08lld\n",
953 div_u64(phba->ktime_seg3_total,
954 phba->ktime_data_samples),
955 phba->ktime_seg3_min,
956 phba->ktime_seg3_max);
958 buf + len, PAGE_SIZE - len,
959 "Segment 4: MSI-X ISR cmpl -to- "
962 buf + len, PAGE_SIZE - len,
963 "avg:%08lld min:%08lld max %08lld\n",
964 div_u64(phba->ktime_seg4_total,
965 phba->ktime_data_samples),
966 phba->ktime_seg4_min,
967 phba->ktime_seg4_max);
969 buf + len, PAGE_SIZE - len,
970 "Total IO avg time: %08lld\n",
971 div_u64(phba->ktime_seg1_total +
972 phba->ktime_seg2_total +
973 phba->ktime_seg3_total +
974 phba->ktime_seg4_total,
975 phba->ktime_data_samples));
980 len += snprintf(buf + len, PAGE_SIZE-len,
981 "ktime %s: Total Samples: %lld %lld\n",
982 (phba->ktime_on ? "Enabled" : "Disabled"),
983 phba->ktime_data_samples,
984 phba->ktime_status_samples);
985 if (phba->ktime_data_samples == 0)
988 len += snprintf(buf + len, PAGE_SIZE-len,
989 "Segment 1: MSI-X ISR Rcv cmd -to- "
990 "cmd pass to NVME Layer\n");
991 len += snprintf(buf + len, PAGE_SIZE-len,
992 "avg:%08lld min:%08lld max %08lld\n",
993 div_u64(phba->ktime_seg1_total,
994 phba->ktime_data_samples),
995 phba->ktime_seg1_min,
996 phba->ktime_seg1_max);
997 len += snprintf(buf + len, PAGE_SIZE-len,
998 "Segment 2: cmd pass to NVME Layer- "
999 "-to- Driver rcv cmd OP (action)\n");
1000 len += snprintf(buf + len, PAGE_SIZE-len,
1001 "avg:%08lld min:%08lld max %08lld\n",
1002 div_u64(phba->ktime_seg2_total,
1003 phba->ktime_data_samples),
1004 phba->ktime_seg2_min,
1005 phba->ktime_seg2_max);
1006 len += snprintf(buf + len, PAGE_SIZE-len,
1007 "Segment 3: Driver rcv cmd OP -to- "
1008 "Firmware WQ doorbell: cmd\n");
1009 len += snprintf(buf + len, PAGE_SIZE-len,
1010 "avg:%08lld min:%08lld max %08lld\n",
1011 div_u64(phba->ktime_seg3_total,
1012 phba->ktime_data_samples),
1013 phba->ktime_seg3_min,
1014 phba->ktime_seg3_max);
1015 len += snprintf(buf + len, PAGE_SIZE-len,
1016 "Segment 4: Firmware WQ doorbell: cmd "
1017 "-to- MSI-X ISR for cmd cmpl\n");
1018 len += snprintf(buf + len, PAGE_SIZE-len,
1019 "avg:%08lld min:%08lld max %08lld\n",
1020 div_u64(phba->ktime_seg4_total,
1021 phba->ktime_data_samples),
1022 phba->ktime_seg4_min,
1023 phba->ktime_seg4_max);
1024 len += snprintf(buf + len, PAGE_SIZE-len,
1025 "Segment 5: MSI-X ISR for cmd cmpl "
1026 "-to- NVME layer passed cmd done\n");
1027 len += snprintf(buf + len, PAGE_SIZE-len,
1028 "avg:%08lld min:%08lld max %08lld\n",
1029 div_u64(phba->ktime_seg5_total,
1030 phba->ktime_data_samples),
1031 phba->ktime_seg5_min,
1032 phba->ktime_seg5_max);
1034 if (phba->ktime_status_samples == 0) {
1035 len += snprintf(buf + len, PAGE_SIZE-len,
1036 "Total: cmd received by MSI-X ISR "
1037 "-to- cmd completed on wire\n");
1038 len += snprintf(buf + len, PAGE_SIZE-len,
1039 "avg:%08lld min:%08lld "
1041 div_u64(phba->ktime_seg10_total,
1042 phba->ktime_data_samples),
1043 phba->ktime_seg10_min,
1044 phba->ktime_seg10_max);
1048 len += snprintf(buf + len, PAGE_SIZE-len,
1049 "Segment 6: NVME layer passed cmd done "
1050 "-to- Driver rcv rsp status OP\n");
1051 len += snprintf(buf + len, PAGE_SIZE-len,
1052 "avg:%08lld min:%08lld max %08lld\n",
1053 div_u64(phba->ktime_seg6_total,
1054 phba->ktime_status_samples),
1055 phba->ktime_seg6_min,
1056 phba->ktime_seg6_max);
1057 len += snprintf(buf + len, PAGE_SIZE-len,
1058 "Segment 7: Driver rcv rsp status OP "
1059 "-to- Firmware WQ doorbell: status\n");
1060 len += snprintf(buf + len, PAGE_SIZE-len,
1061 "avg:%08lld min:%08lld max %08lld\n",
1062 div_u64(phba->ktime_seg7_total,
1063 phba->ktime_status_samples),
1064 phba->ktime_seg7_min,
1065 phba->ktime_seg7_max);
1066 len += snprintf(buf + len, PAGE_SIZE-len,
1067 "Segment 8: Firmware WQ doorbell: status"
1068 " -to- MSI-X ISR for status cmpl\n");
1069 len += snprintf(buf + len, PAGE_SIZE-len,
1070 "avg:%08lld min:%08lld max %08lld\n",
1071 div_u64(phba->ktime_seg8_total,
1072 phba->ktime_status_samples),
1073 phba->ktime_seg8_min,
1074 phba->ktime_seg8_max);
1075 len += snprintf(buf + len, PAGE_SIZE-len,
1076 "Segment 9: MSI-X ISR for status cmpl "
1077 "-to- NVME layer passed status done\n");
1078 len += snprintf(buf + len, PAGE_SIZE-len,
1079 "avg:%08lld min:%08lld max %08lld\n",
1080 div_u64(phba->ktime_seg9_total,
1081 phba->ktime_status_samples),
1082 phba->ktime_seg9_min,
1083 phba->ktime_seg9_max);
1084 len += snprintf(buf + len, PAGE_SIZE-len,
1085 "Total: cmd received by MSI-X ISR -to- "
1086 "cmd completed on wire\n");
1087 len += snprintf(buf + len, PAGE_SIZE-len,
1088 "avg:%08lld min:%08lld max %08lld\n",
1089 div_u64(phba->ktime_seg10_total,
1090 phba->ktime_status_samples),
1091 phba->ktime_seg10_min,
1092 phba->ktime_seg10_max);
1097 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1098 * @phba: The phba to gather target node info from.
1099 * @buf: The buffer to dump log into.
1100 * @size: The maximum amount of data to process.
1103 * This routine dumps the NVME IO trace associated with @phba
1106 * This routine returns the amount of bytes that were dumped into @buf and will
1110 lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1112 struct lpfc_debugfs_nvmeio_trc *dtp;
1113 int i, state, index, skip;
1116 state = phba->nvmeio_trc_on;
1118 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1119 (phba->nvmeio_trc_size - 1);
1120 skip = phba->nvmeio_trc_output_idx;
1122 len += snprintf(buf + len, size - len,
1123 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1124 (phba->nvmet_support ? "NVME" : "NVMET"),
1125 (state ? "Enabled" : "Disabled"),
1126 index, skip, phba->nvmeio_trc_size);
1128 if (!phba->nvmeio_trc || state)
1131 /* trace MUST bhe off to continue */
1133 for (i = index; i < phba->nvmeio_trc_size; i++) {
1138 dtp = phba->nvmeio_trc + i;
1139 phba->nvmeio_trc_output_idx++;
1144 len += snprintf(buf + len, size - len, dtp->fmt,
1145 dtp->data1, dtp->data2, dtp->data3);
1147 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1148 phba->nvmeio_trc_output_idx = 0;
1149 len += snprintf(buf + len, size - len,
1150 "Trace Complete\n");
1154 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1155 len += snprintf(buf + len, size - len,
1156 "Trace Continue (%d of %d)\n",
1157 phba->nvmeio_trc_output_idx,
1158 phba->nvmeio_trc_size);
1162 for (i = 0; i < index; i++) {
1167 dtp = phba->nvmeio_trc + i;
1168 phba->nvmeio_trc_output_idx++;
1173 len += snprintf(buf + len, size - len, dtp->fmt,
1174 dtp->data1, dtp->data2, dtp->data3);
1176 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1177 phba->nvmeio_trc_output_idx = 0;
1178 len += snprintf(buf + len, size - len,
1179 "Trace Complete\n");
1183 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1184 len += snprintf(buf + len, size - len,
1185 "Trace Continue (%d of %d)\n",
1186 phba->nvmeio_trc_output_idx,
1187 phba->nvmeio_trc_size);
1192 len += snprintf(buf + len, size - len,
1199 * lpfc_debugfs_cpucheck_data - Dump target node list to a buffer
1200 * @vport: The vport to gather target node info from.
1201 * @buf: The buffer to dump log into.
1202 * @size: The maximum amount of data to process.
1205 * This routine dumps the NVME statistics associated with @vport
1208 * This routine returns the amount of bytes that were dumped into @buf and will
1212 lpfc_debugfs_cpucheck_data(struct lpfc_vport *vport, char *buf, int size)
1214 struct lpfc_hba *phba = vport->phba;
1217 uint32_t tot_xmt = 0;
1218 uint32_t tot_rcv = 0;
1219 uint32_t tot_cmpl = 0;
1220 uint32_t tot_ccmpl = 0;
1222 if (phba->nvmet_support == 0) {
1223 /* NVME Initiator */
1224 len += snprintf(buf + len, PAGE_SIZE - len,
1226 (phba->cpucheck_on & LPFC_CHECK_NVME_IO ?
1227 "Enabled" : "Disabled"));
1228 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1229 if (i >= LPFC_CHECK_CPU_CNT)
1231 len += snprintf(buf + len, PAGE_SIZE - len,
1232 "%02d: xmit x%08x cmpl x%08x\n",
1233 i, phba->cpucheck_xmt_io[i],
1234 phba->cpucheck_cmpl_io[i]);
1235 tot_xmt += phba->cpucheck_xmt_io[i];
1236 tot_cmpl += phba->cpucheck_cmpl_io[i];
1238 len += snprintf(buf + len, PAGE_SIZE - len,
1239 "tot:xmit x%08x cmpl x%08x\n",
1245 len += snprintf(buf + len, PAGE_SIZE - len,
1247 (phba->cpucheck_on & LPFC_CHECK_NVMET_IO ?
1248 "IO Enabled - " : "IO Disabled - "));
1249 len += snprintf(buf + len, PAGE_SIZE - len,
1251 (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV ?
1252 "Rcv Enabled\n" : "Rcv Disabled\n"));
1253 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1254 if (i >= LPFC_CHECK_CPU_CNT)
1256 len += snprintf(buf + len, PAGE_SIZE - len,
1257 "%02d: xmit x%08x ccmpl x%08x "
1258 "cmpl x%08x rcv x%08x\n",
1259 i, phba->cpucheck_xmt_io[i],
1260 phba->cpucheck_ccmpl_io[i],
1261 phba->cpucheck_cmpl_io[i],
1262 phba->cpucheck_rcv_io[i]);
1263 tot_xmt += phba->cpucheck_xmt_io[i];
1264 tot_rcv += phba->cpucheck_rcv_io[i];
1265 tot_cmpl += phba->cpucheck_cmpl_io[i];
1266 tot_ccmpl += phba->cpucheck_ccmpl_io[i];
1268 len += snprintf(buf + len, PAGE_SIZE - len,
1269 "tot:xmit x%08x ccmpl x%08x cmpl x%08x rcv x%08x\n",
1270 tot_xmt, tot_ccmpl, tot_cmpl, tot_rcv);
1277 * lpfc_debugfs_disc_trc - Store discovery trace log
1278 * @vport: The vport to associate this trace string with for retrieval.
1279 * @mask: Log entry classification.
1280 * @fmt: Format string to be displayed when dumping the log.
1281 * @data1: 1st data parameter to be applied to @fmt.
1282 * @data2: 2nd data parameter to be applied to @fmt.
1283 * @data3: 3rd data parameter to be applied to @fmt.
1286 * This routine is used by the driver code to add a debugfs log entry to the
1287 * discovery trace buffer associated with @vport. Only entries with a @mask that
1288 * match the current debugfs discovery mask will be saved. Entries that do not
1289 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1290 * printf when displaying the log.
1293 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1294 uint32_t data1, uint32_t data2, uint32_t data3)
1296 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1297 struct lpfc_debugfs_trc *dtp;
1300 if (!(lpfc_debugfs_mask_disc_trc & mask))
1303 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1304 !vport || !vport->disc_trc)
1307 index = atomic_inc_return(&vport->disc_trc_cnt) &
1308 (lpfc_debugfs_max_disc_trc - 1);
1309 dtp = vport->disc_trc + index;
1314 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1321 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
1322 * @phba: The phba to associate this trace string with for retrieval.
1323 * @fmt: Format string to be displayed when dumping the log.
1324 * @data1: 1st data parameter to be applied to @fmt.
1325 * @data2: 2nd data parameter to be applied to @fmt.
1326 * @data3: 3rd data parameter to be applied to @fmt.
1329 * This routine is used by the driver code to add a debugfs log entry to the
1330 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1331 * @data3 are used like printf when displaying the log.
1334 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1335 uint32_t data1, uint32_t data2, uint32_t data3)
1337 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1338 struct lpfc_debugfs_trc *dtp;
1341 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1342 !phba || !phba->slow_ring_trc)
1345 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1346 (lpfc_debugfs_max_slow_ring_trc - 1);
1347 dtp = phba->slow_ring_trc + index;
1352 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1359 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1360 * @phba: The phba to associate this trace string with for retrieval.
1361 * @fmt: Format string to be displayed when dumping the log.
1362 * @data1: 1st data parameter to be applied to @fmt.
1363 * @data2: 2nd data parameter to be applied to @fmt.
1364 * @data3: 3rd data parameter to be applied to @fmt.
1367 * This routine is used by the driver code to add a debugfs log entry to the
1368 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1369 * @data3 are used like printf when displaying the log.
1372 lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1373 uint16_t data1, uint16_t data2, uint32_t data3)
1375 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1376 struct lpfc_debugfs_nvmeio_trc *dtp;
1379 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1382 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1383 (phba->nvmeio_trc_size - 1);
1384 dtp = phba->nvmeio_trc + index;
1392 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1394 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
1395 * @inode: The inode pointer that contains a vport pointer.
1396 * @file: The file pointer to attach the log output.
1399 * This routine is the entry point for the debugfs open file operation. It gets
1400 * the vport from the i_private field in @inode, allocates the necessary buffer
1401 * for the log, fills the buffer from the in-memory log for this vport, and then
1402 * returns a pointer to that log in the private_data field in @file.
1405 * This function returns zero if successful. On error it will return a negative
1409 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1411 struct lpfc_vport *vport = inode->i_private;
1412 struct lpfc_debug *debug;
1416 if (!lpfc_debugfs_max_disc_trc) {
1421 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1425 /* Round to page boundary */
1426 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1427 size = PAGE_ALIGN(size);
1429 debug->buffer = kmalloc(size, GFP_KERNEL);
1430 if (!debug->buffer) {
1435 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1436 file->private_data = debug;
1444 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
1445 * @inode: The inode pointer that contains a vport pointer.
1446 * @file: The file pointer to attach the log output.
1449 * This routine is the entry point for the debugfs open file operation. It gets
1450 * the vport from the i_private field in @inode, allocates the necessary buffer
1451 * for the log, fills the buffer from the in-memory log for this vport, and then
1452 * returns a pointer to that log in the private_data field in @file.
1455 * This function returns zero if successful. On error it will return a negative
1459 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1461 struct lpfc_hba *phba = inode->i_private;
1462 struct lpfc_debug *debug;
1466 if (!lpfc_debugfs_max_slow_ring_trc) {
1471 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1475 /* Round to page boundary */
1476 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1477 size = PAGE_ALIGN(size);
1479 debug->buffer = kmalloc(size, GFP_KERNEL);
1480 if (!debug->buffer) {
1485 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
1486 file->private_data = debug;
1494 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
1495 * @inode: The inode pointer that contains a vport pointer.
1496 * @file: The file pointer to attach the log output.
1499 * This routine is the entry point for the debugfs open file operation. It gets
1500 * the vport from the i_private field in @inode, allocates the necessary buffer
1501 * for the log, fills the buffer from the in-memory log for this vport, and then
1502 * returns a pointer to that log in the private_data field in @file.
1505 * This function returns zero if successful. On error it will return a negative
1509 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
1511 struct lpfc_hba *phba = inode->i_private;
1512 struct lpfc_debug *debug;
1515 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1519 /* Round to page boundary */
1520 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
1521 if (!debug->buffer) {
1526 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
1528 file->private_data = debug;
1536 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
1537 * @inode: The inode pointer that contains a vport pointer.
1538 * @file: The file pointer to attach the log output.
1541 * This routine is the entry point for the debugfs open file operation. It gets
1542 * the vport from the i_private field in @inode, allocates the necessary buffer
1543 * for the log, fills the buffer from the in-memory log for this vport, and then
1544 * returns a pointer to that log in the private_data field in @file.
1547 * This function returns zero if successful. On error it will return a negative
1551 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
1553 struct lpfc_hba *phba = inode->i_private;
1554 struct lpfc_debug *debug;
1557 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1561 /* Round to page boundary */
1562 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
1563 if (!debug->buffer) {
1568 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
1569 LPFC_DUMPHBASLIM_SIZE);
1570 file->private_data = debug;
1578 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
1579 * @inode: The inode pointer that contains a vport pointer.
1580 * @file: The file pointer to attach the log output.
1583 * This routine is the entry point for the debugfs open file operation. It gets
1584 * the vport from the i_private field in @inode, allocates the necessary buffer
1585 * for the log, fills the buffer from the in-memory log for this vport, and then
1586 * returns a pointer to that log in the private_data field in @file.
1589 * This function returns zero if successful. On error it will return a negative
1593 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
1595 struct lpfc_hba *phba = inode->i_private;
1596 struct lpfc_debug *debug;
1599 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1603 /* Round to page boundary */
1604 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
1605 if (!debug->buffer) {
1610 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
1611 LPFC_DUMPHOSTSLIM_SIZE);
1612 file->private_data = debug;
1620 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
1622 struct lpfc_debug *debug;
1625 if (!_dump_buf_data)
1628 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1632 /* Round to page boundary */
1633 pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
1634 __func__, _dump_buf_data);
1635 debug->buffer = _dump_buf_data;
1636 if (!debug->buffer) {
1641 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
1642 file->private_data = debug;
1650 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
1652 struct lpfc_debug *debug;
1658 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1662 /* Round to page boundary */
1663 pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n",
1664 __func__, _dump_buf_dif, file);
1665 debug->buffer = _dump_buf_dif;
1666 if (!debug->buffer) {
1671 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
1672 file->private_data = debug;
1680 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
1681 size_t nbytes, loff_t *ppos)
1684 * The Data/DIF buffers only save one failing IO
1685 * The write op is used as a reset mechanism after an IO has
1686 * already been saved to the next one can be saved
1688 spin_lock(&_dump_buf_lock);
1690 memset((void *)_dump_buf_data, 0,
1691 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
1692 memset((void *)_dump_buf_dif, 0,
1693 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
1697 spin_unlock(&_dump_buf_lock);
1703 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1704 size_t nbytes, loff_t *ppos)
1706 struct dentry *dent = file->f_path.dentry;
1707 struct lpfc_hba *phba = file->private_data;
1712 if (dent == phba->debug_writeGuard)
1713 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1714 else if (dent == phba->debug_writeApp)
1715 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
1716 else if (dent == phba->debug_writeRef)
1717 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
1718 else if (dent == phba->debug_readGuard)
1719 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1720 else if (dent == phba->debug_readApp)
1721 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
1722 else if (dent == phba->debug_readRef)
1723 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1724 else if (dent == phba->debug_InjErrNPortID)
1725 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1726 else if (dent == phba->debug_InjErrWWPN) {
1727 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1728 tmp = cpu_to_be64(tmp);
1729 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1730 } else if (dent == phba->debug_InjErrLBA) {
1731 if (phba->lpfc_injerr_lba == (sector_t)(-1))
1732 cnt = snprintf(cbuf, 32, "off\n");
1734 cnt = snprintf(cbuf, 32, "0x%llx\n",
1735 (uint64_t) phba->lpfc_injerr_lba);
1737 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1738 "0547 Unknown debugfs error injection entry\n");
1740 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1744 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1745 size_t nbytes, loff_t *ppos)
1747 struct dentry *dent = file->f_path.dentry;
1748 struct lpfc_hba *phba = file->private_data;
1753 memset(dstbuf, 0, 33);
1754 size = (nbytes < 32) ? nbytes : 32;
1755 if (copy_from_user(dstbuf, buf, size))
1758 if (dent == phba->debug_InjErrLBA) {
1759 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1760 tmp = (uint64_t)(-1);
1763 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
1766 if (dent == phba->debug_writeGuard)
1767 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1768 else if (dent == phba->debug_writeApp)
1769 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1770 else if (dent == phba->debug_writeRef)
1771 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1772 else if (dent == phba->debug_readGuard)
1773 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
1774 else if (dent == phba->debug_readApp)
1775 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1776 else if (dent == phba->debug_readRef)
1777 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1778 else if (dent == phba->debug_InjErrLBA)
1779 phba->lpfc_injerr_lba = (sector_t)tmp;
1780 else if (dent == phba->debug_InjErrNPortID)
1781 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1782 else if (dent == phba->debug_InjErrWWPN) {
1783 tmp = cpu_to_be64(tmp);
1784 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1787 "0548 Unknown debugfs error injection entry\n");
1793 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1799 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1800 * @inode: The inode pointer that contains a vport pointer.
1801 * @file: The file pointer to attach the log output.
1804 * This routine is the entry point for the debugfs open file operation. It gets
1805 * the vport from the i_private field in @inode, allocates the necessary buffer
1806 * for the log, fills the buffer from the in-memory log for this vport, and then
1807 * returns a pointer to that log in the private_data field in @file.
1810 * This function returns zero if successful. On error it will return a negative
1814 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1816 struct lpfc_vport *vport = inode->i_private;
1817 struct lpfc_debug *debug;
1820 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1824 /* Round to page boundary */
1825 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1826 if (!debug->buffer) {
1831 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1832 LPFC_NODELIST_SIZE);
1833 file->private_data = debug;
1841 * lpfc_debugfs_lseek - Seek through a debugfs file
1842 * @file: The file pointer to seek through.
1843 * @off: The offset to seek to or the amount to seek by.
1844 * @whence: Indicates how to seek.
1847 * This routine is the entry point for the debugfs lseek file operation. The
1848 * @whence parameter indicates whether @off is the offset to directly seek to,
1849 * or if it is a value to seek forward or reverse by. This function figures out
1850 * what the new offset of the debugfs file will be and assigns that value to the
1851 * f_pos field of @file.
1854 * This function returns the new offset if successful and returns a negative
1855 * error if unable to process the seek.
1858 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1860 struct lpfc_debug *debug = file->private_data;
1861 return fixed_size_llseek(file, off, whence, debug->len);
1865 * lpfc_debugfs_read - Read a debugfs file
1866 * @file: The file pointer to read from.
1867 * @buf: The buffer to copy the data to.
1868 * @nbytes: The number of bytes to read.
1869 * @ppos: The position in the file to start reading from.
1872 * This routine reads data from from the buffer indicated in the private_data
1873 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1877 * This function returns the amount of data that was read (this could be less
1878 * than @nbytes if the end of the file was reached) or a negative error value.
1881 lpfc_debugfs_read(struct file *file, char __user *buf,
1882 size_t nbytes, loff_t *ppos)
1884 struct lpfc_debug *debug = file->private_data;
1886 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1891 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1892 * @inode: The inode pointer that contains a vport pointer. (unused)
1893 * @file: The file pointer that contains the buffer to release.
1896 * This routine frees the buffer that was allocated when the debugfs file was
1900 * This function returns zero.
1903 lpfc_debugfs_release(struct inode *inode, struct file *file)
1905 struct lpfc_debug *debug = file->private_data;
1907 kfree(debug->buffer);
1914 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1916 struct lpfc_debug *debug = file->private_data;
1918 debug->buffer = NULL;
1926 lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
1928 struct lpfc_vport *vport = inode->i_private;
1929 struct lpfc_debug *debug;
1932 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1936 /* Round to page boundary */
1937 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
1938 if (!debug->buffer) {
1943 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
1944 LPFC_NVMESTAT_SIZE);
1946 debug->i_private = inode->i_private;
1947 file->private_data = debug;
1955 lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
1956 size_t nbytes, loff_t *ppos)
1958 struct lpfc_debug *debug = file->private_data;
1959 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
1960 struct lpfc_hba *phba = vport->phba;
1961 struct lpfc_nvmet_tgtport *tgtp;
1965 if (!phba->targetport)
1971 memset(mybuf, 0, sizeof(mybuf));
1973 if (copy_from_user(mybuf, buf, nbytes))
1977 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1978 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
1979 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
1980 atomic_set(&tgtp->rcv_ls_req_in, 0);
1981 atomic_set(&tgtp->rcv_ls_req_out, 0);
1982 atomic_set(&tgtp->rcv_ls_req_drop, 0);
1983 atomic_set(&tgtp->xmt_ls_abort, 0);
1984 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
1985 atomic_set(&tgtp->xmt_ls_rsp, 0);
1986 atomic_set(&tgtp->xmt_ls_drop, 0);
1987 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
1988 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
1990 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
1991 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
1992 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
1993 atomic_set(&tgtp->xmt_fcp_drop, 0);
1994 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
1995 atomic_set(&tgtp->xmt_fcp_read, 0);
1996 atomic_set(&tgtp->xmt_fcp_write, 0);
1997 atomic_set(&tgtp->xmt_fcp_rsp, 0);
1998 atomic_set(&tgtp->xmt_fcp_release, 0);
1999 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
2000 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
2001 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
2003 atomic_set(&tgtp->xmt_fcp_abort, 0);
2004 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
2005 atomic_set(&tgtp->xmt_abort_sol, 0);
2006 atomic_set(&tgtp->xmt_abort_unsol, 0);
2007 atomic_set(&tgtp->xmt_abort_rsp, 0);
2008 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
2014 lpfc_debugfs_nvmektime_open(struct inode *inode, struct file *file)
2016 struct lpfc_vport *vport = inode->i_private;
2017 struct lpfc_debug *debug;
2020 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2024 /* Round to page boundary */
2025 debug->buffer = kmalloc(LPFC_NVMEKTIME_SIZE, GFP_KERNEL);
2026 if (!debug->buffer) {
2031 debug->len = lpfc_debugfs_nvmektime_data(vport, debug->buffer,
2032 LPFC_NVMEKTIME_SIZE);
2034 debug->i_private = inode->i_private;
2035 file->private_data = debug;
2043 lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf,
2044 size_t nbytes, loff_t *ppos)
2046 struct lpfc_debug *debug = file->private_data;
2047 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2048 struct lpfc_hba *phba = vport->phba;
2055 memset(mybuf, 0, sizeof(mybuf));
2057 if (copy_from_user(mybuf, buf, nbytes))
2061 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2062 phba->ktime_data_samples = 0;
2063 phba->ktime_status_samples = 0;
2064 phba->ktime_seg1_total = 0;
2065 phba->ktime_seg1_max = 0;
2066 phba->ktime_seg1_min = 0xffffffff;
2067 phba->ktime_seg2_total = 0;
2068 phba->ktime_seg2_max = 0;
2069 phba->ktime_seg2_min = 0xffffffff;
2070 phba->ktime_seg3_total = 0;
2071 phba->ktime_seg3_max = 0;
2072 phba->ktime_seg3_min = 0xffffffff;
2073 phba->ktime_seg4_total = 0;
2074 phba->ktime_seg4_max = 0;
2075 phba->ktime_seg4_min = 0xffffffff;
2076 phba->ktime_seg5_total = 0;
2077 phba->ktime_seg5_max = 0;
2078 phba->ktime_seg5_min = 0xffffffff;
2079 phba->ktime_seg6_total = 0;
2080 phba->ktime_seg6_max = 0;
2081 phba->ktime_seg6_min = 0xffffffff;
2082 phba->ktime_seg7_total = 0;
2083 phba->ktime_seg7_max = 0;
2084 phba->ktime_seg7_min = 0xffffffff;
2085 phba->ktime_seg8_total = 0;
2086 phba->ktime_seg8_max = 0;
2087 phba->ktime_seg8_min = 0xffffffff;
2088 phba->ktime_seg9_total = 0;
2089 phba->ktime_seg9_max = 0;
2090 phba->ktime_seg9_min = 0xffffffff;
2091 phba->ktime_seg10_total = 0;
2092 phba->ktime_seg10_max = 0;
2093 phba->ktime_seg10_min = 0xffffffff;
2096 return strlen(pbuf);
2097 } else if ((strncmp(pbuf, "off",
2098 sizeof("off") - 1) == 0)) {
2100 return strlen(pbuf);
2101 } else if ((strncmp(pbuf, "zero",
2102 sizeof("zero") - 1) == 0)) {
2103 phba->ktime_data_samples = 0;
2104 phba->ktime_status_samples = 0;
2105 phba->ktime_seg1_total = 0;
2106 phba->ktime_seg1_max = 0;
2107 phba->ktime_seg1_min = 0xffffffff;
2108 phba->ktime_seg2_total = 0;
2109 phba->ktime_seg2_max = 0;
2110 phba->ktime_seg2_min = 0xffffffff;
2111 phba->ktime_seg3_total = 0;
2112 phba->ktime_seg3_max = 0;
2113 phba->ktime_seg3_min = 0xffffffff;
2114 phba->ktime_seg4_total = 0;
2115 phba->ktime_seg4_max = 0;
2116 phba->ktime_seg4_min = 0xffffffff;
2117 phba->ktime_seg5_total = 0;
2118 phba->ktime_seg5_max = 0;
2119 phba->ktime_seg5_min = 0xffffffff;
2120 phba->ktime_seg6_total = 0;
2121 phba->ktime_seg6_max = 0;
2122 phba->ktime_seg6_min = 0xffffffff;
2123 phba->ktime_seg7_total = 0;
2124 phba->ktime_seg7_max = 0;
2125 phba->ktime_seg7_min = 0xffffffff;
2126 phba->ktime_seg8_total = 0;
2127 phba->ktime_seg8_max = 0;
2128 phba->ktime_seg8_min = 0xffffffff;
2129 phba->ktime_seg9_total = 0;
2130 phba->ktime_seg9_max = 0;
2131 phba->ktime_seg9_min = 0xffffffff;
2132 phba->ktime_seg10_total = 0;
2133 phba->ktime_seg10_max = 0;
2134 phba->ktime_seg10_min = 0xffffffff;
2135 return strlen(pbuf);
2141 lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2143 struct lpfc_hba *phba = inode->i_private;
2144 struct lpfc_debug *debug;
2147 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2151 /* Round to page boundary */
2152 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2153 if (!debug->buffer) {
2158 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2159 LPFC_NVMEIO_TRC_SIZE);
2161 debug->i_private = inode->i_private;
2162 file->private_data = debug;
2170 lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2171 size_t nbytes, loff_t *ppos)
2173 struct lpfc_debug *debug = file->private_data;
2174 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2183 memset(mybuf, 0, sizeof(mybuf));
2185 if (copy_from_user(mybuf, buf, nbytes))
2189 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2190 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2191 "0570 nvmeio_trc_off\n");
2192 phba->nvmeio_trc_output_idx = 0;
2193 phba->nvmeio_trc_on = 0;
2194 return strlen(pbuf);
2195 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2197 "0571 nvmeio_trc_on\n");
2198 phba->nvmeio_trc_output_idx = 0;
2199 phba->nvmeio_trc_on = 1;
2200 return strlen(pbuf);
2203 /* We must be off to allocate the trace buffer */
2204 if (phba->nvmeio_trc_on != 0)
2207 /* If not on or off, the parameter is the trace buffer size */
2208 i = kstrtoul(pbuf, 0, &sz);
2211 phba->nvmeio_trc_size = (uint32_t)sz;
2213 /* It must be a power of 2 - round down */
2220 if (phba->nvmeio_trc_size != sz)
2221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2222 "0572 nvmeio_trc_size changed to %ld\n",
2224 phba->nvmeio_trc_size = (uint32_t)sz;
2226 /* If one previously exists, free it */
2227 kfree(phba->nvmeio_trc);
2229 /* Allocate new trace buffer and initialize */
2230 phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
2232 if (!phba->nvmeio_trc) {
2233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2234 "0573 Cannot create debugfs "
2235 "nvmeio_trc buffer\n");
2238 atomic_set(&phba->nvmeio_trc_cnt, 0);
2239 phba->nvmeio_trc_on = 0;
2240 phba->nvmeio_trc_output_idx = 0;
2242 return strlen(pbuf);
2246 lpfc_debugfs_cpucheck_open(struct inode *inode, struct file *file)
2248 struct lpfc_vport *vport = inode->i_private;
2249 struct lpfc_debug *debug;
2252 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2256 /* Round to page boundary */
2257 debug->buffer = kmalloc(LPFC_CPUCHECK_SIZE, GFP_KERNEL);
2258 if (!debug->buffer) {
2263 debug->len = lpfc_debugfs_cpucheck_data(vport, debug->buffer,
2264 LPFC_NVMEKTIME_SIZE);
2266 debug->i_private = inode->i_private;
2267 file->private_data = debug;
2275 lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
2276 size_t nbytes, loff_t *ppos)
2278 struct lpfc_debug *debug = file->private_data;
2279 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2280 struct lpfc_hba *phba = vport->phba;
2288 memset(mybuf, 0, sizeof(mybuf));
2290 if (copy_from_user(mybuf, buf, nbytes))
2294 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2295 if (phba->nvmet_support)
2296 phba->cpucheck_on |= LPFC_CHECK_NVMET_IO;
2298 phba->cpucheck_on |= LPFC_CHECK_NVME_IO;
2299 return strlen(pbuf);
2300 } else if ((strncmp(pbuf, "rcv",
2301 sizeof("rcv") - 1) == 0)) {
2302 if (phba->nvmet_support)
2303 phba->cpucheck_on |= LPFC_CHECK_NVMET_RCV;
2306 return strlen(pbuf);
2307 } else if ((strncmp(pbuf, "off",
2308 sizeof("off") - 1) == 0)) {
2309 phba->cpucheck_on = LPFC_CHECK_OFF;
2310 return strlen(pbuf);
2311 } else if ((strncmp(pbuf, "zero",
2312 sizeof("zero") - 1) == 0)) {
2313 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
2314 if (i >= LPFC_CHECK_CPU_CNT)
2316 phba->cpucheck_rcv_io[i] = 0;
2317 phba->cpucheck_xmt_io[i] = 0;
2318 phba->cpucheck_cmpl_io[i] = 0;
2319 phba->cpucheck_ccmpl_io[i] = 0;
2321 return strlen(pbuf);
2327 * ---------------------------------
2328 * iDiag debugfs file access methods
2329 * ---------------------------------
2331 * All access methods are through the proper SLI4 PCI function's debugfs
2334 * /sys/kernel/debug/lpfc/fn<#>/iDiag
2338 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
2339 * @buf: The pointer to the user space buffer.
2340 * @nbytes: The number of bytes in the user space buffer.
2341 * @idiag_cmd: pointer to the idiag command struct.
2343 * This routine reads data from debugfs user space buffer and parses the
2344 * buffer for getting the idiag command and arguments. The while space in
2345 * between the set of data is used as the parsing separator.
2347 * This routine returns 0 when successful, it returns proper error code
2348 * back to the user space in error conditions.
2350 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
2351 struct lpfc_idiag_cmd *idiag_cmd)
2354 char *pbuf, *step_str;
2358 memset(mybuf, 0, sizeof(mybuf));
2359 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
2360 bsize = min(nbytes, (sizeof(mybuf)-1));
2362 if (copy_from_user(mybuf, buf, bsize))
2365 step_str = strsep(&pbuf, "\t ");
2367 /* The opcode must present */
2371 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
2372 if (idiag_cmd->opcode == 0)
2375 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
2376 step_str = strsep(&pbuf, "\t ");
2379 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
2385 * lpfc_idiag_open - idiag open debugfs
2386 * @inode: The inode pointer that contains a pointer to phba.
2387 * @file: The file pointer to attach the file operation.
2390 * This routine is the entry point for the debugfs open file operation. It
2391 * gets the reference to phba from the i_private field in @inode, it then
2392 * allocates buffer for the file operation, performs the necessary PCI config
2393 * space read into the allocated buffer according to the idiag user command
2394 * setup, and then returns a pointer to buffer in the private_data field in
2398 * This function returns zero if successful. On error it will return an
2399 * negative error value.
2402 lpfc_idiag_open(struct inode *inode, struct file *file)
2404 struct lpfc_debug *debug;
2406 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2410 debug->i_private = inode->i_private;
2411 debug->buffer = NULL;
2412 file->private_data = debug;
2418 * lpfc_idiag_release - Release idiag access file operation
2419 * @inode: The inode pointer that contains a vport pointer. (unused)
2420 * @file: The file pointer that contains the buffer to release.
2423 * This routine is the generic release routine for the idiag access file
2424 * operation, it frees the buffer that was allocated when the debugfs file
2428 * This function returns zero.
2431 lpfc_idiag_release(struct inode *inode, struct file *file)
2433 struct lpfc_debug *debug = file->private_data;
2435 /* Free the buffers to the file operation */
2436 kfree(debug->buffer);
2443 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
2444 * @inode: The inode pointer that contains a vport pointer. (unused)
2445 * @file: The file pointer that contains the buffer to release.
2448 * This routine frees the buffer that was allocated when the debugfs file
2449 * was opened. It also reset the fields in the idiag command struct in the
2450 * case of command for write operation.
2453 * This function returns zero.
2456 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
2458 struct lpfc_debug *debug = file->private_data;
2460 if (debug->op == LPFC_IDIAG_OP_WR) {
2461 switch (idiag.cmd.opcode) {
2462 case LPFC_IDIAG_CMD_PCICFG_WR:
2463 case LPFC_IDIAG_CMD_PCICFG_ST:
2464 case LPFC_IDIAG_CMD_PCICFG_CL:
2465 case LPFC_IDIAG_CMD_QUEACC_WR:
2466 case LPFC_IDIAG_CMD_QUEACC_ST:
2467 case LPFC_IDIAG_CMD_QUEACC_CL:
2468 memset(&idiag, 0, sizeof(idiag));
2475 /* Free the buffers to the file operation */
2476 kfree(debug->buffer);
2483 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
2484 * @file: The file pointer to read from.
2485 * @buf: The buffer to copy the data to.
2486 * @nbytes: The number of bytes to read.
2487 * @ppos: The position in the file to start reading from.
2490 * This routine reads data from the @phba pci config space according to the
2491 * idiag command, and copies to user @buf. Depending on the PCI config space
2492 * read command setup, it does either a single register read of a byte
2493 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
2494 * registers from the 4K extended PCI config space.
2497 * This function returns the amount of data that was read (this could be less
2498 * than @nbytes if the end of the file was reached) or a negative error value.
2501 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
2504 struct lpfc_debug *debug = file->private_data;
2505 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2506 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
2509 struct pci_dev *pdev;
2514 pdev = phba->pcidev;
2518 /* This is a user read operation */
2519 debug->op = LPFC_IDIAG_OP_RD;
2522 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
2525 pbuffer = debug->buffer;
2530 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2531 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2532 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2536 /* Read single PCI config space register */
2538 case SIZE_U8: /* byte (8 bits) */
2539 pci_read_config_byte(pdev, where, &u8val);
2540 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2541 "%03x: %02x\n", where, u8val);
2543 case SIZE_U16: /* word (16 bits) */
2544 pci_read_config_word(pdev, where, &u16val);
2545 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2546 "%03x: %04x\n", where, u16val);
2548 case SIZE_U32: /* double word (32 bits) */
2549 pci_read_config_dword(pdev, where, &u32val);
2550 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2551 "%03x: %08x\n", where, u32val);
2553 case LPFC_PCI_CFG_BROWSE: /* browse all */
2561 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2565 /* Browse all PCI config space registers */
2566 offset_label = idiag.offset.last_rd;
2567 offset = offset_label;
2569 /* Read PCI config space */
2570 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2571 "%03x: ", offset_label);
2573 pci_read_config_dword(pdev, offset, &u32val);
2574 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2576 offset += sizeof(uint32_t);
2577 if (offset >= LPFC_PCI_CFG_SIZE) {
2578 len += snprintf(pbuffer+len,
2579 LPFC_PCI_CFG_SIZE-len, "\n");
2582 index -= sizeof(uint32_t);
2584 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2586 else if (!(index % (8 * sizeof(uint32_t)))) {
2587 offset_label += (8 * sizeof(uint32_t));
2588 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2589 "\n%03x: ", offset_label);
2593 /* Set up the offset for next portion of pci cfg read */
2595 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
2596 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
2597 idiag.offset.last_rd = 0;
2599 idiag.offset.last_rd = 0;
2601 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2605 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
2606 * @file: The file pointer to read from.
2607 * @buf: The buffer to copy the user data from.
2608 * @nbytes: The number of bytes to get.
2609 * @ppos: The position in the file to start reading from.
2611 * This routine get the debugfs idiag command struct from user space and
2612 * then perform the syntax check for PCI config space read or write command
2613 * accordingly. In the case of PCI config space read command, it sets up
2614 * the command in the idiag command struct for the debugfs read operation.
2615 * In the case of PCI config space write operation, it executes the write
2616 * operation into the PCI config space accordingly.
2618 * It returns the @nbytges passing in from debugfs user space when successful.
2619 * In case of error conditions, it returns proper error code back to the user
2623 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
2624 size_t nbytes, loff_t *ppos)
2626 struct lpfc_debug *debug = file->private_data;
2627 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2628 uint32_t where, value, count;
2632 struct pci_dev *pdev;
2635 pdev = phba->pcidev;
2639 /* This is a user write operation */
2640 debug->op = LPFC_IDIAG_OP_WR;
2642 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2646 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2647 /* Sanity check on PCI config read command line arguments */
2648 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
2650 /* Read command from PCI config space, set up command fields */
2651 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2652 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2653 if (count == LPFC_PCI_CFG_BROWSE) {
2654 if (where % sizeof(uint32_t))
2656 /* Starting offset to browse */
2657 idiag.offset.last_rd = where;
2658 } else if ((count != sizeof(uint8_t)) &&
2659 (count != sizeof(uint16_t)) &&
2660 (count != sizeof(uint32_t)))
2662 if (count == sizeof(uint8_t)) {
2663 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2665 if (where % sizeof(uint8_t))
2668 if (count == sizeof(uint16_t)) {
2669 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2671 if (where % sizeof(uint16_t))
2674 if (count == sizeof(uint32_t)) {
2675 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2677 if (where % sizeof(uint32_t))
2680 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
2681 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
2682 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2683 /* Sanity check on PCI config write command line arguments */
2684 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
2686 /* Write command to PCI config space, read-modify-write */
2687 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2688 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2689 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
2691 if ((count != sizeof(uint8_t)) &&
2692 (count != sizeof(uint16_t)) &&
2693 (count != sizeof(uint32_t)))
2695 if (count == sizeof(uint8_t)) {
2696 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2698 if (where % sizeof(uint8_t))
2700 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2701 pci_write_config_byte(pdev, where,
2703 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2704 rc = pci_read_config_byte(pdev, where, &u8val);
2706 u8val |= (uint8_t)value;
2707 pci_write_config_byte(pdev, where,
2711 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2712 rc = pci_read_config_byte(pdev, where, &u8val);
2714 u8val &= (uint8_t)(~value);
2715 pci_write_config_byte(pdev, where,
2720 if (count == sizeof(uint16_t)) {
2721 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2723 if (where % sizeof(uint16_t))
2725 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2726 pci_write_config_word(pdev, where,
2728 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2729 rc = pci_read_config_word(pdev, where, &u16val);
2731 u16val |= (uint16_t)value;
2732 pci_write_config_word(pdev, where,
2736 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2737 rc = pci_read_config_word(pdev, where, &u16val);
2739 u16val &= (uint16_t)(~value);
2740 pci_write_config_word(pdev, where,
2745 if (count == sizeof(uint32_t)) {
2746 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2748 if (where % sizeof(uint32_t))
2750 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2751 pci_write_config_dword(pdev, where, value);
2752 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2753 rc = pci_read_config_dword(pdev, where,
2757 pci_write_config_dword(pdev, where,
2761 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2762 rc = pci_read_config_dword(pdev, where,
2766 pci_write_config_dword(pdev, where,
2772 /* All other opecodes are illegal for now */
2777 memset(&idiag, 0, sizeof(idiag));
2782 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
2783 * @file: The file pointer to read from.
2784 * @buf: The buffer to copy the data to.
2785 * @nbytes: The number of bytes to read.
2786 * @ppos: The position in the file to start reading from.
2789 * This routine reads data from the @phba pci bar memory mapped space
2790 * according to the idiag command, and copies to user @buf.
2793 * This function returns the amount of data that was read (this could be less
2794 * than @nbytes if the end of the file was reached) or a negative error value.
2797 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
2800 struct lpfc_debug *debug = file->private_data;
2801 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2802 int offset_label, offset, offset_run, len = 0, index;
2803 int bar_num, acc_range, bar_size;
2805 void __iomem *mem_mapped_bar;
2807 struct pci_dev *pdev;
2810 pdev = phba->pcidev;
2814 /* This is a user read operation */
2815 debug->op = LPFC_IDIAG_OP_RD;
2818 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
2821 pbuffer = debug->buffer;
2826 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
2827 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2828 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
2829 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
2830 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
2837 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2838 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2839 if (bar_num == IDIAG_BARACC_BAR_0)
2840 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2841 else if (bar_num == IDIAG_BARACC_BAR_1)
2842 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2843 else if (bar_num == IDIAG_BARACC_BAR_2)
2844 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2847 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2848 if (bar_num == IDIAG_BARACC_BAR_0)
2849 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2855 /* Read single PCI bar space register */
2856 if (acc_range == SINGLE_WORD) {
2857 offset_run = offset;
2858 u32val = readl(mem_mapped_bar + offset_run);
2859 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2860 "%05x: %08x\n", offset_run, u32val);
2864 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2868 /* Browse all PCI bar space registers */
2869 offset_label = idiag.offset.last_rd;
2870 offset_run = offset_label;
2872 /* Read PCI bar memory mapped space */
2873 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2874 "%05x: ", offset_label);
2875 index = LPFC_PCI_BAR_RD_SIZE;
2877 u32val = readl(mem_mapped_bar + offset_run);
2878 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2880 offset_run += sizeof(uint32_t);
2881 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2882 if (offset_run >= bar_size) {
2883 len += snprintf(pbuffer+len,
2884 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2888 if (offset_run >= offset +
2889 (acc_range * sizeof(uint32_t))) {
2890 len += snprintf(pbuffer+len,
2891 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2895 index -= sizeof(uint32_t);
2897 len += snprintf(pbuffer+len,
2898 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2899 else if (!(index % (8 * sizeof(uint32_t)))) {
2900 offset_label += (8 * sizeof(uint32_t));
2901 len += snprintf(pbuffer+len,
2902 LPFC_PCI_BAR_RD_BUF_SIZE-len,
2903 "\n%05x: ", offset_label);
2907 /* Set up the offset for next portion of pci bar read */
2909 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
2910 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2911 if (idiag.offset.last_rd >= bar_size)
2912 idiag.offset.last_rd = 0;
2914 if (offset_run >= offset +
2915 (acc_range * sizeof(uint32_t)))
2916 idiag.offset.last_rd = offset;
2919 if (acc_range == LPFC_PCI_BAR_BROWSE)
2920 idiag.offset.last_rd = 0;
2922 idiag.offset.last_rd = offset;
2925 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2929 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
2930 * @file: The file pointer to read from.
2931 * @buf: The buffer to copy the user data from.
2932 * @nbytes: The number of bytes to get.
2933 * @ppos: The position in the file to start reading from.
2935 * This routine get the debugfs idiag command struct from user space and
2936 * then perform the syntax check for PCI bar memory mapped space read or
2937 * write command accordingly. In the case of PCI bar memory mapped space
2938 * read command, it sets up the command in the idiag command struct for
2939 * the debugfs read operation. In the case of PCI bar memorpy mapped space
2940 * write operation, it executes the write operation into the PCI bar memory
2941 * mapped space accordingly.
2943 * It returns the @nbytges passing in from debugfs user space when successful.
2944 * In case of error conditions, it returns proper error code back to the user
2948 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
2949 size_t nbytes, loff_t *ppos)
2951 struct lpfc_debug *debug = file->private_data;
2952 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2953 uint32_t bar_num, bar_size, offset, value, acc_range;
2954 struct pci_dev *pdev;
2955 void __iomem *mem_mapped_bar;
2960 pdev = phba->pcidev;
2964 /* This is a user write operation */
2965 debug->op = LPFC_IDIAG_OP_WR;
2967 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2971 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2972 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2974 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2975 if ((bar_num != IDIAG_BARACC_BAR_0) &&
2976 (bar_num != IDIAG_BARACC_BAR_1) &&
2977 (bar_num != IDIAG_BARACC_BAR_2))
2979 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2980 if (bar_num != IDIAG_BARACC_BAR_0)
2985 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2986 if (bar_num == IDIAG_BARACC_BAR_0) {
2987 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2988 LPFC_PCI_IF0_BAR0_SIZE;
2989 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2990 } else if (bar_num == IDIAG_BARACC_BAR_1) {
2991 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2992 LPFC_PCI_IF0_BAR1_SIZE;
2993 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2994 } else if (bar_num == IDIAG_BARACC_BAR_2) {
2995 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2996 LPFC_PCI_IF0_BAR2_SIZE;
2997 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3000 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3001 if (bar_num == IDIAG_BARACC_BAR_0) {
3002 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3003 LPFC_PCI_IF2_BAR0_SIZE;
3004 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3010 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3011 if (offset % sizeof(uint32_t))
3014 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3015 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3016 /* Sanity check on PCI config read command line arguments */
3017 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3019 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3020 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3021 if (offset > bar_size - sizeof(uint32_t))
3023 /* Starting offset to browse */
3024 idiag.offset.last_rd = offset;
3025 } else if (acc_range > SINGLE_WORD) {
3026 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3028 /* Starting offset to browse */
3029 idiag.offset.last_rd = offset;
3030 } else if (acc_range != SINGLE_WORD)
3032 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3033 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3034 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3035 /* Sanity check on PCI bar write command line arguments */
3036 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3038 /* Write command to PCI bar space, read-modify-write */
3039 acc_range = SINGLE_WORD;
3040 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3041 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3042 writel(value, mem_mapped_bar + offset);
3043 readl(mem_mapped_bar + offset);
3045 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3046 u32val = readl(mem_mapped_bar + offset);
3048 writel(u32val, mem_mapped_bar + offset);
3049 readl(mem_mapped_bar + offset);
3051 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3052 u32val = readl(mem_mapped_bar + offset);
3054 writel(u32val, mem_mapped_bar + offset);
3055 readl(mem_mapped_bar + offset);
3058 /* All other opecodes are illegal for now */
3063 memset(&idiag, 0, sizeof(idiag));
3068 __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3069 char *pbuffer, int len)
3074 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3075 "\t\t%s WQ info: ", wqtype);
3076 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3077 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3078 qp->assoc_qid, qp->q_cnt_1,
3079 (unsigned long long)qp->q_cnt_4);
3080 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3081 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3082 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3083 qp->queue_id, qp->entry_count,
3084 qp->entry_size, qp->host_index,
3085 qp->hba_index, qp->entry_repost);
3086 len += snprintf(pbuffer + len,
3087 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3092 lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3093 int *len, int max_cnt, int cq_id)
3095 struct lpfc_queue *qp;
3098 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3099 qp = phba->sli4_hba.fcp_wq[qidx];
3100 if (qp->assoc_qid != cq_id)
3102 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3103 if (*len >= max_cnt)
3106 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3107 qp = phba->sli4_hba.nvme_wq[qidx];
3108 if (qp->assoc_qid != cq_id)
3110 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3111 if (*len >= max_cnt)
3118 __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3119 char *pbuffer, int len)
3124 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3125 "\t%s CQ info: ", cqtype);
3126 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3127 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3128 "xabt:x%x wq:x%llx]\n",
3129 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3130 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3131 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3132 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3133 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3134 qp->queue_id, qp->entry_count,
3135 qp->entry_size, qp->host_index,
3136 qp->hba_index, qp->entry_repost);
3138 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3144 __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3145 char *rqtype, char *pbuffer, int len)
3150 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3151 "\t\t%s RQ info: ", rqtype);
3152 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3153 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
3154 "posted:x%x rcv:x%llx]\n",
3155 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3156 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3157 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3158 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3159 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
3160 qp->queue_id, qp->entry_count, qp->entry_size,
3161 qp->host_index, qp->hba_index, qp->entry_repost);
3162 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3163 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3164 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
3165 datqp->queue_id, datqp->entry_count,
3166 datqp->entry_size, datqp->host_index,
3167 datqp->hba_index, datqp->entry_repost);
3172 lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
3173 int *len, int max_cnt, int eqidx, int eq_id)
3175 struct lpfc_queue *qp;
3178 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3179 qp = phba->sli4_hba.fcp_cq[qidx];
3180 if (qp->assoc_qid != eq_id)
3183 *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
3185 /* Reset max counter */
3188 if (*len >= max_cnt)
3191 rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
3192 max_cnt, qp->queue_id);
3197 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3198 qp = phba->sli4_hba.nvme_cq[qidx];
3199 if (qp->assoc_qid != eq_id)
3202 *len = __lpfc_idiag_print_cq(qp, "NVME", pbuffer, *len);
3204 /* Reset max counter */
3207 if (*len >= max_cnt)
3210 rc = lpfc_idiag_wqs_for_cq(phba, "NVME", pbuffer, len,
3211 max_cnt, qp->queue_id);
3216 if (eqidx < phba->cfg_nvmet_mrq) {
3218 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3219 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3221 /* Reset max counter */
3224 if (*len >= max_cnt)
3228 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3229 *len = __lpfc_idiag_print_rqpair(qp,
3230 phba->sli4_hba.nvmet_mrq_data[eqidx],
3231 "NVMET MRQ", pbuffer, *len);
3233 if (*len >= max_cnt)
3241 __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
3242 char *pbuffer, int len)
3247 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3248 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
3249 "bs:x%x proc:x%llx eqd %d]\n",
3250 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
3251 (unsigned long long)qp->q_cnt_4, qp->q_mode);
3252 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3253 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3254 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3255 qp->queue_id, qp->entry_count, qp->entry_size,
3256 qp->host_index, qp->hba_index, qp->entry_repost);
3257 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3263 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
3264 * @file: The file pointer to read from.
3265 * @buf: The buffer to copy the data to.
3266 * @nbytes: The number of bytes to read.
3267 * @ppos: The position in the file to start reading from.
3270 * This routine reads data from the @phba SLI4 PCI function queue information,
3271 * and copies to user @buf.
3272 * This routine only returns 1 EQs worth of information. It remembers the last
3273 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
3274 * retrieve all EQs allocated for the phba.
3277 * This function returns the amount of data that was read (this could be less
3278 * than @nbytes if the end of the file was reached) or a negative error value.
3281 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
3284 struct lpfc_debug *debug = file->private_data;
3285 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3287 int max_cnt, rc, x, len = 0;
3288 struct lpfc_queue *qp = NULL;
3291 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
3294 pbuffer = debug->buffer;
3295 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
3300 spin_lock_irq(&phba->hbalock);
3302 /* Fast-path event queue */
3303 if (phba->sli4_hba.hba_eq && phba->io_channel_irqs) {
3305 x = phba->lpfc_idiag_last_eq;
3306 if (phba->cfg_fof && (x >= phba->io_channel_irqs)) {
3307 phba->lpfc_idiag_last_eq = 0;
3310 phba->lpfc_idiag_last_eq++;
3311 if (phba->lpfc_idiag_last_eq >= phba->io_channel_irqs)
3312 if (phba->cfg_fof == 0)
3313 phba->lpfc_idiag_last_eq = 0;
3315 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3316 "EQ %d out of %d HBA EQs\n",
3317 x, phba->io_channel_irqs);
3320 qp = phba->sli4_hba.hba_eq[x];
3324 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
3326 /* Reset max counter */
3332 /* will dump both fcp and nvme cqs/wqs for the eq */
3333 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
3334 max_cnt, x, qp->queue_id);
3338 /* Only EQ 0 has slow path CQs configured */
3342 /* Slow-path mailbox CQ */
3343 qp = phba->sli4_hba.mbx_cq;
3344 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
3348 /* Slow-path MBOX MQ */
3349 qp = phba->sli4_hba.mbx_wq;
3350 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
3354 /* Slow-path ELS response CQ */
3355 qp = phba->sli4_hba.els_cq;
3356 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
3357 /* Reset max counter */
3363 /* Slow-path ELS WQ */
3364 qp = phba->sli4_hba.els_wq;
3365 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
3369 /* Slow-path NVME LS response CQ */
3370 qp = phba->sli4_hba.nvmels_cq;
3371 len = __lpfc_idiag_print_cq(qp, "NVME LS",
3373 /* Reset max counter */
3379 /* Slow-path NVME LS WQ */
3380 qp = phba->sli4_hba.nvmels_wq;
3381 len = __lpfc_idiag_print_wq(qp, "NVME LS",
3386 qp = phba->sli4_hba.hdr_rq;
3387 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
3388 "RQpair", pbuffer, len);
3396 if (phba->cfg_fof) {
3398 qp = phba->sli4_hba.fof_eq;
3399 len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
3401 /* Reset max counter */
3409 qp = phba->sli4_hba.oas_cq;
3410 len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
3411 /* Reset max counter */
3418 qp = phba->sli4_hba.oas_wq;
3419 len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
3424 spin_unlock_irq(&phba->hbalock);
3425 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3428 len += snprintf(pbuffer + len,
3429 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
3431 spin_unlock_irq(&phba->hbalock);
3432 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3436 * lpfc_idiag_que_param_check - queue access command parameter sanity check
3437 * @q: The pointer to queue structure.
3438 * @index: The index into a queue entry.
3439 * @count: The number of queue entries to access.
3442 * The routine performs sanity check on device queue access method commands.
3445 * This function returns -EINVAL when fails the sanity check, otherwise, it
3449 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
3451 /* Only support single entry read or browsing */
3452 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
3454 if (index > q->entry_count - 1)
3460 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
3461 * @pbuffer: The pointer to buffer to copy the read data into.
3462 * @pque: The pointer to the queue to be read.
3463 * @index: The index into the queue entry.
3466 * This routine reads out a single entry from the given queue's index location
3467 * and copies it into the buffer provided.
3470 * This function returns 0 when it fails, otherwise, it returns the length of
3471 * the data read into the buffer provided.
3474 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
3480 if (!pbuffer || !pque)
3483 esize = pque->entry_size;
3484 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3485 "QE-INDEX[%04d]:\n", index);
3488 pentry = pque->qe[index].address;
3490 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3493 offset += sizeof(uint32_t);
3494 esize -= sizeof(uint32_t);
3495 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
3496 len += snprintf(pbuffer+len,
3497 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3499 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3505 * lpfc_idiag_queacc_read - idiag debugfs read port queue
3506 * @file: The file pointer to read from.
3507 * @buf: The buffer to copy the data to.
3508 * @nbytes: The number of bytes to read.
3509 * @ppos: The position in the file to start reading from.
3512 * This routine reads data from the @phba device queue memory according to the
3513 * idiag command, and copies to user @buf. Depending on the queue dump read
3514 * command setup, it does either a single queue entry read or browing through
3515 * all entries of the queue.
3518 * This function returns the amount of data that was read (this could be less
3519 * than @nbytes if the end of the file was reached) or a negative error value.
3522 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
3525 struct lpfc_debug *debug = file->private_data;
3526 uint32_t last_index, index, count;
3527 struct lpfc_queue *pque = NULL;
3531 /* This is a user read operation */
3532 debug->op = LPFC_IDIAG_OP_RD;
3535 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
3538 pbuffer = debug->buffer;
3543 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3544 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3545 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3546 pque = (struct lpfc_queue *)idiag.ptr_private;
3550 /* Browse the queue starting from index */
3551 if (count == LPFC_QUE_ACC_BROWSE)
3554 /* Read a single entry from the queue */
3555 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3557 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3561 /* Browse all entries from the queue */
3562 last_index = idiag.offset.last_rd;
3565 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
3566 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3568 if (index > pque->entry_count - 1)
3572 /* Set up the offset for next portion of pci cfg read */
3573 if (index > pque->entry_count - 1)
3575 idiag.offset.last_rd = index;
3577 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3581 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
3582 * @file: The file pointer to read from.
3583 * @buf: The buffer to copy the user data from.
3584 * @nbytes: The number of bytes to get.
3585 * @ppos: The position in the file to start reading from.
3587 * This routine get the debugfs idiag command struct from user space and then
3588 * perform the syntax check for port queue read (dump) or write (set) command
3589 * accordingly. In the case of port queue read command, it sets up the command
3590 * in the idiag command struct for the following debugfs read operation. In
3591 * the case of port queue write operation, it executes the write operation
3592 * into the port queue entry accordingly.
3594 * It returns the @nbytges passing in from debugfs user space when successful.
3595 * In case of error conditions, it returns proper error code back to the user
3599 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3600 size_t nbytes, loff_t *ppos)
3602 struct lpfc_debug *debug = file->private_data;
3603 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3604 uint32_t qidx, quetp, queid, index, count, offset, value;
3606 struct lpfc_queue *pque, *qp;
3609 /* This is a user write operation */
3610 debug->op = LPFC_IDIAG_OP_WR;
3612 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3616 /* Get and sanity check on command feilds */
3617 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
3618 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
3619 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3620 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3621 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
3622 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
3624 /* Sanity check on command line arguments */
3625 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3626 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3627 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3628 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
3632 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3633 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
3640 /* HBA event queue */
3641 if (phba->sli4_hba.hba_eq) {
3642 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
3643 qp = phba->sli4_hba.hba_eq[qidx];
3644 if (qp && qp->queue_id == queid) {
3646 rc = lpfc_idiag_que_param_check(qp,
3650 idiag.ptr_private = qp;
3658 /* MBX complete queue */
3659 if (phba->sli4_hba.mbx_cq &&
3660 phba->sli4_hba.mbx_cq->queue_id == queid) {
3662 rc = lpfc_idiag_que_param_check(
3663 phba->sli4_hba.mbx_cq, index, count);
3666 idiag.ptr_private = phba->sli4_hba.mbx_cq;
3669 /* ELS complete queue */
3670 if (phba->sli4_hba.els_cq &&
3671 phba->sli4_hba.els_cq->queue_id == queid) {
3673 rc = lpfc_idiag_que_param_check(
3674 phba->sli4_hba.els_cq, index, count);
3677 idiag.ptr_private = phba->sli4_hba.els_cq;
3680 /* NVME LS complete queue */
3681 if (phba->sli4_hba.nvmels_cq &&
3682 phba->sli4_hba.nvmels_cq->queue_id == queid) {
3684 rc = lpfc_idiag_que_param_check(
3685 phba->sli4_hba.nvmels_cq, index, count);
3688 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3691 /* FCP complete queue */
3692 if (phba->sli4_hba.fcp_cq) {
3693 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3695 qp = phba->sli4_hba.fcp_cq[qidx];
3696 if (qp && qp->queue_id == queid) {
3698 rc = lpfc_idiag_que_param_check(
3702 idiag.ptr_private = qp;
3707 /* NVME complete queue */
3708 if (phba->sli4_hba.nvme_cq) {
3711 if (phba->sli4_hba.nvme_cq[qidx] &&
3712 phba->sli4_hba.nvme_cq[qidx]->queue_id ==
3715 rc = lpfc_idiag_que_param_check(
3716 phba->sli4_hba.nvme_cq[qidx],
3721 phba->sli4_hba.nvme_cq[qidx];
3724 } while (++qidx < phba->cfg_nvme_io_channel);
3729 /* MBX work queue */
3730 if (phba->sli4_hba.mbx_wq &&
3731 phba->sli4_hba.mbx_wq->queue_id == queid) {
3733 rc = lpfc_idiag_que_param_check(
3734 phba->sli4_hba.mbx_wq, index, count);
3737 idiag.ptr_private = phba->sli4_hba.mbx_wq;
3743 /* ELS work queue */
3744 if (phba->sli4_hba.els_wq &&
3745 phba->sli4_hba.els_wq->queue_id == queid) {
3747 rc = lpfc_idiag_que_param_check(
3748 phba->sli4_hba.els_wq, index, count);
3751 idiag.ptr_private = phba->sli4_hba.els_wq;
3754 /* NVME LS work queue */
3755 if (phba->sli4_hba.nvmels_wq &&
3756 phba->sli4_hba.nvmels_wq->queue_id == queid) {
3758 rc = lpfc_idiag_que_param_check(
3759 phba->sli4_hba.nvmels_wq, index, count);
3762 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3765 /* FCP work queue */
3766 if (phba->sli4_hba.fcp_wq) {
3767 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3769 qp = phba->sli4_hba.fcp_wq[qidx];
3770 if (qp && qp->queue_id == queid) {
3772 rc = lpfc_idiag_que_param_check(
3776 idiag.ptr_private = qp;
3781 /* NVME work queue */
3782 if (phba->sli4_hba.nvme_wq) {
3783 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3785 qp = phba->sli4_hba.nvme_wq[qidx];
3786 if (qp && qp->queue_id == queid) {
3788 rc = lpfc_idiag_que_param_check(
3792 idiag.ptr_private = qp;
3798 /* NVME work queues */
3799 if (phba->sli4_hba.nvme_wq) {
3800 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3802 if (!phba->sli4_hba.nvme_wq[qidx])
3804 if (phba->sli4_hba.nvme_wq[qidx]->queue_id ==
3807 rc = lpfc_idiag_que_param_check(
3808 phba->sli4_hba.nvme_wq[qidx],
3813 phba->sli4_hba.nvme_wq[qidx];
3822 if (phba->sli4_hba.hdr_rq &&
3823 phba->sli4_hba.hdr_rq->queue_id == queid) {
3825 rc = lpfc_idiag_que_param_check(
3826 phba->sli4_hba.hdr_rq, index, count);
3829 idiag.ptr_private = phba->sli4_hba.hdr_rq;
3833 if (phba->sli4_hba.dat_rq &&
3834 phba->sli4_hba.dat_rq->queue_id == queid) {
3836 rc = lpfc_idiag_que_param_check(
3837 phba->sli4_hba.dat_rq, index, count);
3840 idiag.ptr_private = phba->sli4_hba.dat_rq;
3852 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3853 if (count == LPFC_QUE_ACC_BROWSE)
3854 idiag.offset.last_rd = index;
3857 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3858 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3859 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3860 /* Additional sanity checks on write operation */
3861 pque = (struct lpfc_queue *)idiag.ptr_private;
3862 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
3864 pentry = pque->qe[index].address;
3866 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
3868 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
3870 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
3876 /* Clean out command structure on command error out */
3877 memset(&idiag, 0, sizeof(idiag));
3882 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
3883 * @phba: The pointer to hba structure.
3884 * @pbuffer: The pointer to the buffer to copy the data to.
3885 * @len: The lenght of bytes to copied.
3886 * @drbregid: The id to doorbell registers.
3889 * This routine reads a doorbell register and copies its content to the
3890 * user buffer pointed to by @pbuffer.
3893 * This function returns the amount of data that was copied into @pbuffer.
3896 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
3897 int len, uint32_t drbregid)
3905 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3906 "EQCQ-DRB-REG: 0x%08x\n",
3907 readl(phba->sli4_hba.EQCQDBregaddr));
3910 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3911 "MQ-DRB-REG: 0x%08x\n",
3912 readl(phba->sli4_hba.MQDBregaddr));
3915 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3916 "WQ-DRB-REG: 0x%08x\n",
3917 readl(phba->sli4_hba.WQDBregaddr));
3920 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3921 "RQ-DRB-REG: 0x%08x\n",
3922 readl(phba->sli4_hba.RQDBregaddr));
3932 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
3933 * @file: The file pointer to read from.
3934 * @buf: The buffer to copy the data to.
3935 * @nbytes: The number of bytes to read.
3936 * @ppos: The position in the file to start reading from.
3939 * This routine reads data from the @phba device doorbell register according
3940 * to the idiag command, and copies to user @buf. Depending on the doorbell
3941 * register read command setup, it does either a single doorbell register
3942 * read or dump all doorbell registers.
3945 * This function returns the amount of data that was read (this could be less
3946 * than @nbytes if the end of the file was reached) or a negative error value.
3949 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
3952 struct lpfc_debug *debug = file->private_data;
3953 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3954 uint32_t drb_reg_id, i;
3958 /* This is a user read operation */
3959 debug->op = LPFC_IDIAG_OP_RD;
3962 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
3965 pbuffer = debug->buffer;
3970 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
3971 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
3975 if (drb_reg_id == LPFC_DRB_ACC_ALL)
3976 for (i = 1; i <= LPFC_DRB_MAX; i++)
3977 len = lpfc_idiag_drbacc_read_reg(phba,
3980 len = lpfc_idiag_drbacc_read_reg(phba,
3981 pbuffer, len, drb_reg_id);
3983 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3987 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
3988 * @file: The file pointer to read from.
3989 * @buf: The buffer to copy the user data from.
3990 * @nbytes: The number of bytes to get.
3991 * @ppos: The position in the file to start reading from.
3993 * This routine get the debugfs idiag command struct from user space and then
3994 * perform the syntax check for port doorbell register read (dump) or write
3995 * (set) command accordingly. In the case of port queue read command, it sets
3996 * up the command in the idiag command struct for the following debugfs read
3997 * operation. In the case of port doorbell register write operation, it
3998 * executes the write operation into the port doorbell register accordingly.
4000 * It returns the @nbytges passing in from debugfs user space when successful.
4001 * In case of error conditions, it returns proper error code back to the user
4005 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4006 size_t nbytes, loff_t *ppos)
4008 struct lpfc_debug *debug = file->private_data;
4009 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4010 uint32_t drb_reg_id, value, reg_val = 0;
4011 void __iomem *drb_reg;
4014 /* This is a user write operation */
4015 debug->op = LPFC_IDIAG_OP_WR;
4017 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4021 /* Sanity check on command line arguments */
4022 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4023 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
4025 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4026 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4027 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4028 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4030 if (drb_reg_id > LPFC_DRB_MAX)
4032 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4033 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4035 if ((drb_reg_id > LPFC_DRB_MAX) &&
4036 (drb_reg_id != LPFC_DRB_ACC_ALL))
4041 /* Perform the write access operation */
4042 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4043 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4044 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4045 switch (drb_reg_id) {
4047 drb_reg = phba->sli4_hba.EQCQDBregaddr;
4050 drb_reg = phba->sli4_hba.MQDBregaddr;
4053 drb_reg = phba->sli4_hba.WQDBregaddr;
4056 drb_reg = phba->sli4_hba.RQDBregaddr;
4062 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4064 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4065 reg_val = readl(drb_reg);
4068 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4069 reg_val = readl(drb_reg);
4072 writel(reg_val, drb_reg);
4073 readl(drb_reg); /* flush */
4078 /* Clean out command structure on command error out */
4079 memset(&idiag, 0, sizeof(idiag));
4084 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4085 * @phba: The pointer to hba structure.
4086 * @pbuffer: The pointer to the buffer to copy the data to.
4087 * @len: The lenght of bytes to copied.
4088 * @drbregid: The id to doorbell registers.
4091 * This routine reads a control register and copies its content to the
4092 * user buffer pointed to by @pbuffer.
4095 * This function returns the amount of data that was copied into @pbuffer.
4098 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4099 int len, uint32_t ctlregid)
4106 case LPFC_CTL_PORT_SEM:
4107 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4108 "Port SemReg: 0x%08x\n",
4109 readl(phba->sli4_hba.conf_regs_memmap_p +
4110 LPFC_CTL_PORT_SEM_OFFSET));
4112 case LPFC_CTL_PORT_STA:
4113 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4114 "Port StaReg: 0x%08x\n",
4115 readl(phba->sli4_hba.conf_regs_memmap_p +
4116 LPFC_CTL_PORT_STA_OFFSET));
4118 case LPFC_CTL_PORT_CTL:
4119 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4120 "Port CtlReg: 0x%08x\n",
4121 readl(phba->sli4_hba.conf_regs_memmap_p +
4122 LPFC_CTL_PORT_CTL_OFFSET));
4124 case LPFC_CTL_PORT_ER1:
4125 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4126 "Port Er1Reg: 0x%08x\n",
4127 readl(phba->sli4_hba.conf_regs_memmap_p +
4128 LPFC_CTL_PORT_ER1_OFFSET));
4130 case LPFC_CTL_PORT_ER2:
4131 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4132 "Port Er2Reg: 0x%08x\n",
4133 readl(phba->sli4_hba.conf_regs_memmap_p +
4134 LPFC_CTL_PORT_ER2_OFFSET));
4136 case LPFC_CTL_PDEV_CTL:
4137 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4138 "PDev CtlReg: 0x%08x\n",
4139 readl(phba->sli4_hba.conf_regs_memmap_p +
4140 LPFC_CTL_PDEV_CTL_OFFSET));
4149 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4150 * @file: The file pointer to read from.
4151 * @buf: The buffer to copy the data to.
4152 * @nbytes: The number of bytes to read.
4153 * @ppos: The position in the file to start reading from.
4156 * This routine reads data from the @phba port and device registers according
4157 * to the idiag command, and copies to user @buf.
4160 * This function returns the amount of data that was read (this could be less
4161 * than @nbytes if the end of the file was reached) or a negative error value.
4164 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4167 struct lpfc_debug *debug = file->private_data;
4168 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4169 uint32_t ctl_reg_id, i;
4173 /* This is a user read operation */
4174 debug->op = LPFC_IDIAG_OP_RD;
4177 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4180 pbuffer = debug->buffer;
4185 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4186 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4190 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4191 for (i = 1; i <= LPFC_CTL_MAX; i++)
4192 len = lpfc_idiag_ctlacc_read_reg(phba,
4195 len = lpfc_idiag_ctlacc_read_reg(phba,
4196 pbuffer, len, ctl_reg_id);
4198 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4202 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4203 * @file: The file pointer to read from.
4204 * @buf: The buffer to copy the user data from.
4205 * @nbytes: The number of bytes to get.
4206 * @ppos: The position in the file to start reading from.
4208 * This routine get the debugfs idiag command struct from user space and then
4209 * perform the syntax check for port and device control register read (dump)
4210 * or write (set) command accordingly.
4212 * It returns the @nbytges passing in from debugfs user space when successful.
4213 * In case of error conditions, it returns proper error code back to the user
4217 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4218 size_t nbytes, loff_t *ppos)
4220 struct lpfc_debug *debug = file->private_data;
4221 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4222 uint32_t ctl_reg_id, value, reg_val = 0;
4223 void __iomem *ctl_reg;
4226 /* This is a user write operation */
4227 debug->op = LPFC_IDIAG_OP_WR;
4229 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4233 /* Sanity check on command line arguments */
4234 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4235 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4237 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4238 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4239 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4240 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4242 if (ctl_reg_id > LPFC_CTL_MAX)
4244 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4245 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4247 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4248 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4253 /* Perform the write access operation */
4254 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4255 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4256 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4257 switch (ctl_reg_id) {
4258 case LPFC_CTL_PORT_SEM:
4259 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4260 LPFC_CTL_PORT_SEM_OFFSET;
4262 case LPFC_CTL_PORT_STA:
4263 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4264 LPFC_CTL_PORT_STA_OFFSET;
4266 case LPFC_CTL_PORT_CTL:
4267 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4268 LPFC_CTL_PORT_CTL_OFFSET;
4270 case LPFC_CTL_PORT_ER1:
4271 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4272 LPFC_CTL_PORT_ER1_OFFSET;
4274 case LPFC_CTL_PORT_ER2:
4275 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4276 LPFC_CTL_PORT_ER2_OFFSET;
4278 case LPFC_CTL_PDEV_CTL:
4279 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4280 LPFC_CTL_PDEV_CTL_OFFSET;
4286 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4288 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4289 reg_val = readl(ctl_reg);
4292 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4293 reg_val = readl(ctl_reg);
4296 writel(reg_val, ctl_reg);
4297 readl(ctl_reg); /* flush */
4302 /* Clean out command structure on command error out */
4303 memset(&idiag, 0, sizeof(idiag));
4308 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4309 * @phba: Pointer to HBA context object.
4310 * @pbuffer: Pointer to data buffer.
4313 * This routine gets the driver mailbox access debugfs setup information.
4316 * This function returns the amount of data that was read (this could be less
4317 * than @nbytes if the end of the file was reached) or a negative error value.
4320 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
4322 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4325 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4326 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4327 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4328 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4330 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4331 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
4332 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4333 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
4334 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4335 "mbx_word_cnt: %04d\n", mbx_word_cnt);
4336 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4337 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
4343 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
4344 * @file: The file pointer to read from.
4345 * @buf: The buffer to copy the data to.
4346 * @nbytes: The number of bytes to read.
4347 * @ppos: The position in the file to start reading from.
4350 * This routine reads data from the @phba driver mailbox access debugfs setup
4354 * This function returns the amount of data that was read (this could be less
4355 * than @nbytes if the end of the file was reached) or a negative error value.
4358 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
4361 struct lpfc_debug *debug = file->private_data;
4362 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4366 /* This is a user read operation */
4367 debug->op = LPFC_IDIAG_OP_RD;
4370 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
4373 pbuffer = debug->buffer;
4378 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
4379 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
4382 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
4384 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4388 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
4389 * @file: The file pointer to read from.
4390 * @buf: The buffer to copy the user data from.
4391 * @nbytes: The number of bytes to get.
4392 * @ppos: The position in the file to start reading from.
4394 * This routine get the debugfs idiag command struct from user space and then
4395 * perform the syntax check for driver mailbox command (dump) and sets up the
4396 * necessary states in the idiag command struct accordingly.
4398 * It returns the @nbytges passing in from debugfs user space when successful.
4399 * In case of error conditions, it returns proper error code back to the user
4403 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
4404 size_t nbytes, loff_t *ppos)
4406 struct lpfc_debug *debug = file->private_data;
4407 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4410 /* This is a user write operation */
4411 debug->op = LPFC_IDIAG_OP_WR;
4413 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4417 /* Sanity check on command line arguments */
4418 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4419 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4420 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4421 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4423 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
4424 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
4426 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
4427 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4429 if (mbx_word_cnt > sizeof(MAILBOX_t))
4431 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
4432 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
4434 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
4435 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4437 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
4439 if (mbx_mbox_cmd != 0x9b)
4444 if (mbx_word_cnt == 0)
4446 if (rc != LPFC_MBX_DMP_ARG)
4448 if (mbx_mbox_cmd & ~0xff)
4451 /* condition for stop mailbox dump */
4452 if (mbx_dump_cnt == 0)
4458 /* Clean out command structure on command error out */
4459 memset(&idiag, 0, sizeof(idiag));
4463 /* Clean out command structure on command error out */
4464 memset(&idiag, 0, sizeof(idiag));
4469 * lpfc_idiag_extacc_avail_get - get the available extents information
4470 * @phba: pointer to lpfc hba data structure.
4471 * @pbuffer: pointer to internal buffer.
4472 * @len: length into the internal buffer data has been copied.
4475 * This routine is to get the available extent information.
4478 * overall lenth of the data read into the internal buffer.
4481 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
4483 uint16_t ext_cnt, ext_size;
4485 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4486 "\nAvailable Extents Information:\n");
4488 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4489 "\tPort Available VPI extents: ");
4490 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
4491 &ext_cnt, &ext_size);
4492 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4493 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4495 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4496 "\tPort Available VFI extents: ");
4497 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
4498 &ext_cnt, &ext_size);
4499 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4500 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4502 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4503 "\tPort Available RPI extents: ");
4504 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
4505 &ext_cnt, &ext_size);
4506 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4507 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4509 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4510 "\tPort Available XRI extents: ");
4511 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
4512 &ext_cnt, &ext_size);
4513 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4514 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4520 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
4521 * @phba: pointer to lpfc hba data structure.
4522 * @pbuffer: pointer to internal buffer.
4523 * @len: length into the internal buffer data has been copied.
4526 * This routine is to get the allocated extent information.
4529 * overall lenth of the data read into the internal buffer.
4532 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
4534 uint16_t ext_cnt, ext_size;
4537 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4538 "\nAllocated Extents Information:\n");
4540 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4541 "\tHost Allocated VPI extents: ");
4542 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
4543 &ext_cnt, &ext_size);
4545 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4546 "Port %d Extent %3d, Size %3d\n",
4547 phba->brd_no, ext_cnt, ext_size);
4549 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4552 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4553 "\tHost Allocated VFI extents: ");
4554 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
4555 &ext_cnt, &ext_size);
4557 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4558 "Port %d Extent %3d, Size %3d\n",
4559 phba->brd_no, ext_cnt, ext_size);
4561 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4564 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4565 "\tHost Allocated RPI extents: ");
4566 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
4567 &ext_cnt, &ext_size);
4569 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4570 "Port %d Extent %3d, Size %3d\n",
4571 phba->brd_no, ext_cnt, ext_size);
4573 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4576 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4577 "\tHost Allocated XRI extents: ");
4578 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
4579 &ext_cnt, &ext_size);
4581 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4582 "Port %d Extent %3d, Size %3d\n",
4583 phba->brd_no, ext_cnt, ext_size);
4585 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4592 * lpfc_idiag_extacc_drivr_get - get driver extent information
4593 * @phba: pointer to lpfc hba data structure.
4594 * @pbuffer: pointer to internal buffer.
4595 * @len: length into the internal buffer data has been copied.
4598 * This routine is to get the driver extent information.
4601 * overall lenth of the data read into the internal buffer.
4604 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
4606 struct lpfc_rsrc_blks *rsrc_blks;
4609 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4610 "\nDriver Extents Information:\n");
4612 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4613 "\tVPI extents:\n");
4615 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
4616 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4617 "\t\tBlock %3d: Start %4d, Count %4d\n",
4618 index, rsrc_blks->rsrc_start,
4619 rsrc_blks->rsrc_size);
4622 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4623 "\tVFI extents:\n");
4625 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
4627 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4628 "\t\tBlock %3d: Start %4d, Count %4d\n",
4629 index, rsrc_blks->rsrc_start,
4630 rsrc_blks->rsrc_size);
4634 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4635 "\tRPI extents:\n");
4637 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
4639 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4640 "\t\tBlock %3d: Start %4d, Count %4d\n",
4641 index, rsrc_blks->rsrc_start,
4642 rsrc_blks->rsrc_size);
4646 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4647 "\tXRI extents:\n");
4649 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
4651 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4652 "\t\tBlock %3d: Start %4d, Count %4d\n",
4653 index, rsrc_blks->rsrc_start,
4654 rsrc_blks->rsrc_size);
4662 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
4663 * @file: The file pointer to read from.
4664 * @buf: The buffer to copy the user data from.
4665 * @nbytes: The number of bytes to get.
4666 * @ppos: The position in the file to start reading from.
4668 * This routine get the debugfs idiag command struct from user space and then
4669 * perform the syntax check for extent information access commands and sets
4670 * up the necessary states in the idiag command struct accordingly.
4672 * It returns the @nbytges passing in from debugfs user space when successful.
4673 * In case of error conditions, it returns proper error code back to the user
4677 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
4678 size_t nbytes, loff_t *ppos)
4680 struct lpfc_debug *debug = file->private_data;
4684 /* This is a user write operation */
4685 debug->op = LPFC_IDIAG_OP_WR;
4687 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4691 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4693 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4695 if (rc != LPFC_EXT_ACC_CMD_ARG)
4697 if (!(ext_map & LPFC_EXT_ACC_ALL))
4702 /* Clean out command structure on command error out */
4703 memset(&idiag, 0, sizeof(idiag));
4708 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
4709 * @file: The file pointer to read from.
4710 * @buf: The buffer to copy the data to.
4711 * @nbytes: The number of bytes to read.
4712 * @ppos: The position in the file to start reading from.
4715 * This routine reads data from the proper extent information according to
4716 * the idiag command, and copies to user @buf.
4719 * This function returns the amount of data that was read (this could be less
4720 * than @nbytes if the end of the file was reached) or a negative error value.
4723 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
4726 struct lpfc_debug *debug = file->private_data;
4727 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4732 /* This is a user read operation */
4733 debug->op = LPFC_IDIAG_OP_RD;
4736 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
4739 pbuffer = debug->buffer;
4742 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4745 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4746 if (ext_map & LPFC_EXT_ACC_AVAIL)
4747 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
4748 if (ext_map & LPFC_EXT_ACC_ALLOC)
4749 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
4750 if (ext_map & LPFC_EXT_ACC_DRIVR)
4751 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
4753 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4756 #undef lpfc_debugfs_op_disc_trc
4757 static const struct file_operations lpfc_debugfs_op_disc_trc = {
4758 .owner = THIS_MODULE,
4759 .open = lpfc_debugfs_disc_trc_open,
4760 .llseek = lpfc_debugfs_lseek,
4761 .read = lpfc_debugfs_read,
4762 .release = lpfc_debugfs_release,
4765 #undef lpfc_debugfs_op_nodelist
4766 static const struct file_operations lpfc_debugfs_op_nodelist = {
4767 .owner = THIS_MODULE,
4768 .open = lpfc_debugfs_nodelist_open,
4769 .llseek = lpfc_debugfs_lseek,
4770 .read = lpfc_debugfs_read,
4771 .release = lpfc_debugfs_release,
4774 #undef lpfc_debugfs_op_hbqinfo
4775 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
4776 .owner = THIS_MODULE,
4777 .open = lpfc_debugfs_hbqinfo_open,
4778 .llseek = lpfc_debugfs_lseek,
4779 .read = lpfc_debugfs_read,
4780 .release = lpfc_debugfs_release,
4783 #undef lpfc_debugfs_op_dumpHBASlim
4784 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
4785 .owner = THIS_MODULE,
4786 .open = lpfc_debugfs_dumpHBASlim_open,
4787 .llseek = lpfc_debugfs_lseek,
4788 .read = lpfc_debugfs_read,
4789 .release = lpfc_debugfs_release,
4792 #undef lpfc_debugfs_op_dumpHostSlim
4793 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
4794 .owner = THIS_MODULE,
4795 .open = lpfc_debugfs_dumpHostSlim_open,
4796 .llseek = lpfc_debugfs_lseek,
4797 .read = lpfc_debugfs_read,
4798 .release = lpfc_debugfs_release,
4801 #undef lpfc_debugfs_op_nvmestat
4802 static const struct file_operations lpfc_debugfs_op_nvmestat = {
4803 .owner = THIS_MODULE,
4804 .open = lpfc_debugfs_nvmestat_open,
4805 .llseek = lpfc_debugfs_lseek,
4806 .read = lpfc_debugfs_read,
4807 .write = lpfc_debugfs_nvmestat_write,
4808 .release = lpfc_debugfs_release,
4811 #undef lpfc_debugfs_op_nvmektime
4812 static const struct file_operations lpfc_debugfs_op_nvmektime = {
4813 .owner = THIS_MODULE,
4814 .open = lpfc_debugfs_nvmektime_open,
4815 .llseek = lpfc_debugfs_lseek,
4816 .read = lpfc_debugfs_read,
4817 .write = lpfc_debugfs_nvmektime_write,
4818 .release = lpfc_debugfs_release,
4821 #undef lpfc_debugfs_op_nvmeio_trc
4822 static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
4823 .owner = THIS_MODULE,
4824 .open = lpfc_debugfs_nvmeio_trc_open,
4825 .llseek = lpfc_debugfs_lseek,
4826 .read = lpfc_debugfs_read,
4827 .write = lpfc_debugfs_nvmeio_trc_write,
4828 .release = lpfc_debugfs_release,
4831 #undef lpfc_debugfs_op_cpucheck
4832 static const struct file_operations lpfc_debugfs_op_cpucheck = {
4833 .owner = THIS_MODULE,
4834 .open = lpfc_debugfs_cpucheck_open,
4835 .llseek = lpfc_debugfs_lseek,
4836 .read = lpfc_debugfs_read,
4837 .write = lpfc_debugfs_cpucheck_write,
4838 .release = lpfc_debugfs_release,
4841 #undef lpfc_debugfs_op_dumpData
4842 static const struct file_operations lpfc_debugfs_op_dumpData = {
4843 .owner = THIS_MODULE,
4844 .open = lpfc_debugfs_dumpData_open,
4845 .llseek = lpfc_debugfs_lseek,
4846 .read = lpfc_debugfs_read,
4847 .write = lpfc_debugfs_dumpDataDif_write,
4848 .release = lpfc_debugfs_dumpDataDif_release,
4851 #undef lpfc_debugfs_op_dumpDif
4852 static const struct file_operations lpfc_debugfs_op_dumpDif = {
4853 .owner = THIS_MODULE,
4854 .open = lpfc_debugfs_dumpDif_open,
4855 .llseek = lpfc_debugfs_lseek,
4856 .read = lpfc_debugfs_read,
4857 .write = lpfc_debugfs_dumpDataDif_write,
4858 .release = lpfc_debugfs_dumpDataDif_release,
4861 #undef lpfc_debugfs_op_dif_err
4862 static const struct file_operations lpfc_debugfs_op_dif_err = {
4863 .owner = THIS_MODULE,
4864 .open = simple_open,
4865 .llseek = lpfc_debugfs_lseek,
4866 .read = lpfc_debugfs_dif_err_read,
4867 .write = lpfc_debugfs_dif_err_write,
4868 .release = lpfc_debugfs_dif_err_release,
4871 #undef lpfc_debugfs_op_slow_ring_trc
4872 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
4873 .owner = THIS_MODULE,
4874 .open = lpfc_debugfs_slow_ring_trc_open,
4875 .llseek = lpfc_debugfs_lseek,
4876 .read = lpfc_debugfs_read,
4877 .release = lpfc_debugfs_release,
4880 static struct dentry *lpfc_debugfs_root = NULL;
4881 static atomic_t lpfc_debugfs_hba_count;
4884 * File operations for the iDiag debugfs
4886 #undef lpfc_idiag_op_pciCfg
4887 static const struct file_operations lpfc_idiag_op_pciCfg = {
4888 .owner = THIS_MODULE,
4889 .open = lpfc_idiag_open,
4890 .llseek = lpfc_debugfs_lseek,
4891 .read = lpfc_idiag_pcicfg_read,
4892 .write = lpfc_idiag_pcicfg_write,
4893 .release = lpfc_idiag_cmd_release,
4896 #undef lpfc_idiag_op_barAcc
4897 static const struct file_operations lpfc_idiag_op_barAcc = {
4898 .owner = THIS_MODULE,
4899 .open = lpfc_idiag_open,
4900 .llseek = lpfc_debugfs_lseek,
4901 .read = lpfc_idiag_baracc_read,
4902 .write = lpfc_idiag_baracc_write,
4903 .release = lpfc_idiag_cmd_release,
4906 #undef lpfc_idiag_op_queInfo
4907 static const struct file_operations lpfc_idiag_op_queInfo = {
4908 .owner = THIS_MODULE,
4909 .open = lpfc_idiag_open,
4910 .read = lpfc_idiag_queinfo_read,
4911 .release = lpfc_idiag_release,
4914 #undef lpfc_idiag_op_queAcc
4915 static const struct file_operations lpfc_idiag_op_queAcc = {
4916 .owner = THIS_MODULE,
4917 .open = lpfc_idiag_open,
4918 .llseek = lpfc_debugfs_lseek,
4919 .read = lpfc_idiag_queacc_read,
4920 .write = lpfc_idiag_queacc_write,
4921 .release = lpfc_idiag_cmd_release,
4924 #undef lpfc_idiag_op_drbAcc
4925 static const struct file_operations lpfc_idiag_op_drbAcc = {
4926 .owner = THIS_MODULE,
4927 .open = lpfc_idiag_open,
4928 .llseek = lpfc_debugfs_lseek,
4929 .read = lpfc_idiag_drbacc_read,
4930 .write = lpfc_idiag_drbacc_write,
4931 .release = lpfc_idiag_cmd_release,
4934 #undef lpfc_idiag_op_ctlAcc
4935 static const struct file_operations lpfc_idiag_op_ctlAcc = {
4936 .owner = THIS_MODULE,
4937 .open = lpfc_idiag_open,
4938 .llseek = lpfc_debugfs_lseek,
4939 .read = lpfc_idiag_ctlacc_read,
4940 .write = lpfc_idiag_ctlacc_write,
4941 .release = lpfc_idiag_cmd_release,
4944 #undef lpfc_idiag_op_mbxAcc
4945 static const struct file_operations lpfc_idiag_op_mbxAcc = {
4946 .owner = THIS_MODULE,
4947 .open = lpfc_idiag_open,
4948 .llseek = lpfc_debugfs_lseek,
4949 .read = lpfc_idiag_mbxacc_read,
4950 .write = lpfc_idiag_mbxacc_write,
4951 .release = lpfc_idiag_cmd_release,
4954 #undef lpfc_idiag_op_extAcc
4955 static const struct file_operations lpfc_idiag_op_extAcc = {
4956 .owner = THIS_MODULE,
4957 .open = lpfc_idiag_open,
4958 .llseek = lpfc_debugfs_lseek,
4959 .read = lpfc_idiag_extacc_read,
4960 .write = lpfc_idiag_extacc_write,
4961 .release = lpfc_idiag_cmd_release,
4966 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
4967 * @phba: Pointer to HBA context object.
4968 * @dmabuf: Pointer to a DMA buffer descriptor.
4971 * This routine dump a bsg pass-through non-embedded mailbox command with
4975 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
4976 enum mbox_type mbox_tp, enum dma_type dma_tp,
4977 enum sta_type sta_tp,
4978 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
4980 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4981 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
4982 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
4984 uint32_t do_dump = 0;
4988 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
4991 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4992 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4993 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4994 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4996 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
4997 (*mbx_dump_cnt == 0) ||
4998 (*mbx_word_cnt == 0))
5001 if (*mbx_mbox_cmd != 0x9B)
5004 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5005 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5006 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
5007 pr_err("\nRead mbox command (x%x), "
5008 "nemb:0x%x, extbuf_cnt:%d:\n",
5009 sta_tp, nemb_tp, ext_buf);
5012 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5013 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5014 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
5015 pr_err("\nRead mbox buffer (x%x), "
5016 "nemb:0x%x, extbuf_seq:%d:\n",
5017 sta_tp, nemb_tp, ext_buf);
5020 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5021 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5022 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
5023 pr_err("\nWrite mbox command (x%x), "
5024 "nemb:0x%x, extbuf_cnt:%d:\n",
5025 sta_tp, nemb_tp, ext_buf);
5028 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5029 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5030 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
5031 pr_err("\nWrite mbox buffer (x%x), "
5032 "nemb:0x%x, extbuf_seq:%d:\n",
5033 sta_tp, nemb_tp, ext_buf);
5037 /* dump buffer content */
5039 pword = (uint32_t *)dmabuf->virt;
5040 for (i = 0; i < *mbx_word_cnt; i++) {
5043 pr_err("%s\n", line_buf);
5045 len += snprintf(line_buf+len,
5046 LPFC_MBX_ACC_LBUF_SZ-len,
5049 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5050 "%08x ", (uint32_t)*pword);
5054 pr_err("%s\n", line_buf);
5058 /* Clean out command structure on reaching dump count */
5059 if (*mbx_dump_cnt == 0)
5060 memset(&idiag, 0, sizeof(idiag));
5065 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5066 * @phba: Pointer to HBA context object.
5067 * @dmabuf: Pointer to a DMA buffer descriptor.
5070 * This routine dump a pass-through non-embedded mailbox command from issue
5074 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5076 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5077 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5078 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5084 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5087 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5088 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5089 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5090 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5092 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5093 (*mbx_dump_cnt == 0) ||
5094 (*mbx_word_cnt == 0))
5097 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5098 (*mbx_mbox_cmd != pmbox->mbxCommand))
5101 /* dump buffer content */
5102 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
5103 pr_err("Mailbox command:0x%x dump by word:\n",
5105 pword = (uint32_t *)pmbox;
5106 for (i = 0; i < *mbx_word_cnt; i++) {
5109 pr_err("%s\n", line_buf);
5111 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5112 len += snprintf(line_buf+len,
5113 LPFC_MBX_ACC_LBUF_SZ-len,
5116 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5118 ((uint32_t)*pword) & 0xffffffff);
5122 pr_err("%s\n", line_buf);
5125 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
5126 pr_err("Mailbox command:0x%x dump by byte:\n",
5128 pbyte = (uint8_t *)pmbox;
5129 for (i = 0; i < *mbx_word_cnt; i++) {
5132 pr_err("%s\n", line_buf);
5134 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5135 len += snprintf(line_buf+len,
5136 LPFC_MBX_ACC_LBUF_SZ-len,
5139 for (j = 0; j < 4; j++) {
5140 len += snprintf(line_buf+len,
5141 LPFC_MBX_ACC_LBUF_SZ-len,
5143 ((uint8_t)*pbyte) & 0xff);
5146 len += snprintf(line_buf+len,
5147 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5150 pr_err("%s\n", line_buf);
5155 /* Clean out command structure on reaching dump count */
5156 if (*mbx_dump_cnt == 0)
5157 memset(&idiag, 0, sizeof(idiag));
5163 * lpfc_debugfs_initialize - Initialize debugfs for a vport
5164 * @vport: The vport pointer to initialize.
5167 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5168 * If not already created, this routine will create the lpfc directory, and
5169 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5170 * also create each file used to access lpfc specific debugfs information.
5173 lpfc_debugfs_initialize(struct lpfc_vport *vport)
5175 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5176 struct lpfc_hba *phba = vport->phba;
5179 bool pport_setup = false;
5181 if (!lpfc_debugfs_enable)
5184 /* Setup lpfc root directory */
5185 if (!lpfc_debugfs_root) {
5186 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5187 atomic_set(&lpfc_debugfs_hba_count, 0);
5188 if (!lpfc_debugfs_root) {
5189 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5190 "0408 Cannot create debugfs root\n");
5194 if (!lpfc_debugfs_start_time)
5195 lpfc_debugfs_start_time = jiffies;
5197 /* Setup funcX directory for specific HBA PCI function */
5198 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
5199 if (!phba->hba_debugfs_root) {
5201 phba->hba_debugfs_root =
5202 debugfs_create_dir(name, lpfc_debugfs_root);
5203 if (!phba->hba_debugfs_root) {
5204 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5205 "0412 Cannot create debugfs hba\n");
5208 atomic_inc(&lpfc_debugfs_hba_count);
5209 atomic_set(&phba->debugfs_vport_count, 0);
5212 snprintf(name, sizeof(name), "hbqinfo");
5213 phba->debug_hbqinfo =
5214 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5215 phba->hba_debugfs_root,
5216 phba, &lpfc_debugfs_op_hbqinfo);
5217 if (!phba->debug_hbqinfo) {
5218 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5219 "0411 Cannot create debugfs hbqinfo\n");
5223 /* Setup dumpHBASlim */
5224 if (phba->sli_rev < LPFC_SLI_REV4) {
5225 snprintf(name, sizeof(name), "dumpHBASlim");
5226 phba->debug_dumpHBASlim =
5227 debugfs_create_file(name,
5228 S_IFREG|S_IRUGO|S_IWUSR,
5229 phba->hba_debugfs_root,
5230 phba, &lpfc_debugfs_op_dumpHBASlim);
5231 if (!phba->debug_dumpHBASlim) {
5232 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5233 "0413 Cannot create debugfs "
5238 phba->debug_dumpHBASlim = NULL;
5240 /* Setup dumpHostSlim */
5241 if (phba->sli_rev < LPFC_SLI_REV4) {
5242 snprintf(name, sizeof(name), "dumpHostSlim");
5243 phba->debug_dumpHostSlim =
5244 debugfs_create_file(name,
5245 S_IFREG|S_IRUGO|S_IWUSR,
5246 phba->hba_debugfs_root,
5247 phba, &lpfc_debugfs_op_dumpHostSlim);
5248 if (!phba->debug_dumpHostSlim) {
5249 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5250 "0414 Cannot create debugfs "
5255 phba->debug_dumpHostSlim = NULL;
5257 /* Setup dumpData */
5258 snprintf(name, sizeof(name), "dumpData");
5259 phba->debug_dumpData =
5260 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5261 phba->hba_debugfs_root,
5262 phba, &lpfc_debugfs_op_dumpData);
5263 if (!phba->debug_dumpData) {
5264 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5265 "0800 Cannot create debugfs dumpData\n");
5270 snprintf(name, sizeof(name), "dumpDif");
5271 phba->debug_dumpDif =
5272 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5273 phba->hba_debugfs_root,
5274 phba, &lpfc_debugfs_op_dumpDif);
5275 if (!phba->debug_dumpDif) {
5276 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5277 "0801 Cannot create debugfs dumpDif\n");
5281 /* Setup DIF Error Injections */
5282 snprintf(name, sizeof(name), "InjErrLBA");
5283 phba->debug_InjErrLBA =
5284 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5285 phba->hba_debugfs_root,
5286 phba, &lpfc_debugfs_op_dif_err);
5287 if (!phba->debug_InjErrLBA) {
5288 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5289 "0807 Cannot create debugfs InjErrLBA\n");
5292 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5294 snprintf(name, sizeof(name), "InjErrNPortID");
5295 phba->debug_InjErrNPortID =
5296 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5297 phba->hba_debugfs_root,
5298 phba, &lpfc_debugfs_op_dif_err);
5299 if (!phba->debug_InjErrNPortID) {
5300 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5301 "0809 Cannot create debugfs InjErrNPortID\n");
5305 snprintf(name, sizeof(name), "InjErrWWPN");
5306 phba->debug_InjErrWWPN =
5307 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5308 phba->hba_debugfs_root,
5309 phba, &lpfc_debugfs_op_dif_err);
5310 if (!phba->debug_InjErrWWPN) {
5311 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5312 "0810 Cannot create debugfs InjErrWWPN\n");
5316 snprintf(name, sizeof(name), "writeGuardInjErr");
5317 phba->debug_writeGuard =
5318 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5319 phba->hba_debugfs_root,
5320 phba, &lpfc_debugfs_op_dif_err);
5321 if (!phba->debug_writeGuard) {
5322 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5323 "0802 Cannot create debugfs writeGuard\n");
5327 snprintf(name, sizeof(name), "writeAppInjErr");
5328 phba->debug_writeApp =
5329 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5330 phba->hba_debugfs_root,
5331 phba, &lpfc_debugfs_op_dif_err);
5332 if (!phba->debug_writeApp) {
5333 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5334 "0803 Cannot create debugfs writeApp\n");
5338 snprintf(name, sizeof(name), "writeRefInjErr");
5339 phba->debug_writeRef =
5340 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5341 phba->hba_debugfs_root,
5342 phba, &lpfc_debugfs_op_dif_err);
5343 if (!phba->debug_writeRef) {
5344 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5345 "0804 Cannot create debugfs writeRef\n");
5349 snprintf(name, sizeof(name), "readGuardInjErr");
5350 phba->debug_readGuard =
5351 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5352 phba->hba_debugfs_root,
5353 phba, &lpfc_debugfs_op_dif_err);
5354 if (!phba->debug_readGuard) {
5355 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5356 "0808 Cannot create debugfs readGuard\n");
5360 snprintf(name, sizeof(name), "readAppInjErr");
5361 phba->debug_readApp =
5362 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5363 phba->hba_debugfs_root,
5364 phba, &lpfc_debugfs_op_dif_err);
5365 if (!phba->debug_readApp) {
5366 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5367 "0805 Cannot create debugfs readApp\n");
5371 snprintf(name, sizeof(name), "readRefInjErr");
5372 phba->debug_readRef =
5373 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5374 phba->hba_debugfs_root,
5375 phba, &lpfc_debugfs_op_dif_err);
5376 if (!phba->debug_readRef) {
5377 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5378 "0806 Cannot create debugfs readApp\n");
5382 /* Setup slow ring trace */
5383 if (lpfc_debugfs_max_slow_ring_trc) {
5384 num = lpfc_debugfs_max_slow_ring_trc - 1;
5385 if (num & lpfc_debugfs_max_slow_ring_trc) {
5386 /* Change to be a power of 2 */
5387 num = lpfc_debugfs_max_slow_ring_trc;
5393 lpfc_debugfs_max_slow_ring_trc = (1 << i);
5394 pr_err("lpfc_debugfs_max_disc_trc changed to "
5395 "%d\n", lpfc_debugfs_max_disc_trc);
5399 snprintf(name, sizeof(name), "slow_ring_trace");
5400 phba->debug_slow_ring_trc =
5401 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5402 phba->hba_debugfs_root,
5403 phba, &lpfc_debugfs_op_slow_ring_trc);
5404 if (!phba->debug_slow_ring_trc) {
5405 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5406 "0415 Cannot create debugfs "
5407 "slow_ring_trace\n");
5410 if (!phba->slow_ring_trc) {
5411 phba->slow_ring_trc = kmalloc(
5412 (sizeof(struct lpfc_debugfs_trc) *
5413 lpfc_debugfs_max_slow_ring_trc),
5415 if (!phba->slow_ring_trc) {
5416 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5417 "0416 Cannot create debugfs "
5418 "slow_ring buffer\n");
5421 atomic_set(&phba->slow_ring_trc_cnt, 0);
5422 memset(phba->slow_ring_trc, 0,
5423 (sizeof(struct lpfc_debugfs_trc) *
5424 lpfc_debugfs_max_slow_ring_trc));
5427 snprintf(name, sizeof(name), "nvmeio_trc");
5428 phba->debug_nvmeio_trc =
5429 debugfs_create_file(name, 0644,
5430 phba->hba_debugfs_root,
5431 phba, &lpfc_debugfs_op_nvmeio_trc);
5432 if (!phba->debug_nvmeio_trc) {
5433 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5434 "0574 No create debugfs nvmeio_trc\n");
5438 atomic_set(&phba->nvmeio_trc_cnt, 0);
5439 if (lpfc_debugfs_max_nvmeio_trc) {
5440 num = lpfc_debugfs_max_nvmeio_trc - 1;
5441 if (num & lpfc_debugfs_max_disc_trc) {
5442 /* Change to be a power of 2 */
5443 num = lpfc_debugfs_max_nvmeio_trc;
5449 lpfc_debugfs_max_nvmeio_trc = (1 << i);
5450 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5451 "0575 lpfc_debugfs_max_nvmeio_trc "
5453 lpfc_debugfs_max_nvmeio_trc);
5455 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
5457 /* Allocate trace buffer and initialize */
5458 phba->nvmeio_trc = kzalloc(
5459 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5460 phba->nvmeio_trc_size), GFP_KERNEL);
5462 if (!phba->nvmeio_trc) {
5463 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5464 "0576 Cannot create debugfs "
5465 "nvmeio_trc buffer\n");
5468 phba->nvmeio_trc_on = 1;
5469 phba->nvmeio_trc_output_idx = 0;
5470 phba->nvmeio_trc = NULL;
5473 phba->nvmeio_trc_size = 0;
5474 phba->nvmeio_trc_on = 0;
5475 phba->nvmeio_trc_output_idx = 0;
5476 phba->nvmeio_trc = NULL;
5480 snprintf(name, sizeof(name), "vport%d", vport->vpi);
5481 if (!vport->vport_debugfs_root) {
5482 vport->vport_debugfs_root =
5483 debugfs_create_dir(name, phba->hba_debugfs_root);
5484 if (!vport->vport_debugfs_root) {
5485 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5486 "0417 Can't create debugfs\n");
5489 atomic_inc(&phba->debugfs_vport_count);
5492 if (lpfc_debugfs_max_disc_trc) {
5493 num = lpfc_debugfs_max_disc_trc - 1;
5494 if (num & lpfc_debugfs_max_disc_trc) {
5495 /* Change to be a power of 2 */
5496 num = lpfc_debugfs_max_disc_trc;
5502 lpfc_debugfs_max_disc_trc = (1 << i);
5503 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
5504 lpfc_debugfs_max_disc_trc);
5508 vport->disc_trc = kzalloc(
5509 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
5512 if (!vport->disc_trc) {
5513 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5514 "0418 Cannot create debugfs disc trace "
5518 atomic_set(&vport->disc_trc_cnt, 0);
5520 snprintf(name, sizeof(name), "discovery_trace");
5521 vport->debug_disc_trc =
5522 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5523 vport->vport_debugfs_root,
5524 vport, &lpfc_debugfs_op_disc_trc);
5525 if (!vport->debug_disc_trc) {
5526 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5527 "0419 Cannot create debugfs "
5528 "discovery_trace\n");
5531 snprintf(name, sizeof(name), "nodelist");
5532 vport->debug_nodelist =
5533 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5534 vport->vport_debugfs_root,
5535 vport, &lpfc_debugfs_op_nodelist);
5536 if (!vport->debug_nodelist) {
5537 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5538 "2985 Can't create debugfs nodelist\n");
5542 snprintf(name, sizeof(name), "nvmestat");
5543 vport->debug_nvmestat =
5544 debugfs_create_file(name, 0644,
5545 vport->vport_debugfs_root,
5546 vport, &lpfc_debugfs_op_nvmestat);
5547 if (!vport->debug_nvmestat) {
5548 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5549 "0811 Cannot create debugfs nvmestat\n");
5553 snprintf(name, sizeof(name), "nvmektime");
5554 vport->debug_nvmektime =
5555 debugfs_create_file(name, 0644,
5556 vport->vport_debugfs_root,
5557 vport, &lpfc_debugfs_op_nvmektime);
5558 if (!vport->debug_nvmektime) {
5559 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5560 "0815 Cannot create debugfs nvmektime\n");
5564 snprintf(name, sizeof(name), "cpucheck");
5565 vport->debug_cpucheck =
5566 debugfs_create_file(name, 0644,
5567 vport->vport_debugfs_root,
5568 vport, &lpfc_debugfs_op_cpucheck);
5569 if (!vport->debug_cpucheck) {
5570 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5571 "0819 Cannot create debugfs cpucheck\n");
5576 * The following section is for additional directories/files for the
5584 * iDiag debugfs root entry points for SLI4 device only
5586 if (phba->sli_rev < LPFC_SLI_REV4)
5589 snprintf(name, sizeof(name), "iDiag");
5590 if (!phba->idiag_root) {
5592 debugfs_create_dir(name, phba->hba_debugfs_root);
5593 if (!phba->idiag_root) {
5594 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5595 "2922 Can't create idiag debugfs\n");
5598 /* Initialize iDiag data structure */
5599 memset(&idiag, 0, sizeof(idiag));
5602 /* iDiag read PCI config space */
5603 snprintf(name, sizeof(name), "pciCfg");
5604 if (!phba->idiag_pci_cfg) {
5605 phba->idiag_pci_cfg =
5606 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5607 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
5608 if (!phba->idiag_pci_cfg) {
5609 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5610 "2923 Can't create idiag debugfs\n");
5613 idiag.offset.last_rd = 0;
5616 /* iDiag PCI BAR access */
5617 snprintf(name, sizeof(name), "barAcc");
5618 if (!phba->idiag_bar_acc) {
5619 phba->idiag_bar_acc =
5620 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5621 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
5622 if (!phba->idiag_bar_acc) {
5623 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5624 "3056 Can't create idiag debugfs\n");
5627 idiag.offset.last_rd = 0;
5630 /* iDiag get PCI function queue information */
5631 snprintf(name, sizeof(name), "queInfo");
5632 if (!phba->idiag_que_info) {
5633 phba->idiag_que_info =
5634 debugfs_create_file(name, S_IFREG|S_IRUGO,
5635 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
5636 if (!phba->idiag_que_info) {
5637 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5638 "2924 Can't create idiag debugfs\n");
5643 /* iDiag access PCI function queue */
5644 snprintf(name, sizeof(name), "queAcc");
5645 if (!phba->idiag_que_acc) {
5646 phba->idiag_que_acc =
5647 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5648 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
5649 if (!phba->idiag_que_acc) {
5650 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5651 "2926 Can't create idiag debugfs\n");
5656 /* iDiag access PCI function doorbell registers */
5657 snprintf(name, sizeof(name), "drbAcc");
5658 if (!phba->idiag_drb_acc) {
5659 phba->idiag_drb_acc =
5660 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5661 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
5662 if (!phba->idiag_drb_acc) {
5663 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5664 "2927 Can't create idiag debugfs\n");
5669 /* iDiag access PCI function control registers */
5670 snprintf(name, sizeof(name), "ctlAcc");
5671 if (!phba->idiag_ctl_acc) {
5672 phba->idiag_ctl_acc =
5673 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5674 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
5675 if (!phba->idiag_ctl_acc) {
5676 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5677 "2981 Can't create idiag debugfs\n");
5682 /* iDiag access mbox commands */
5683 snprintf(name, sizeof(name), "mbxAcc");
5684 if (!phba->idiag_mbx_acc) {
5685 phba->idiag_mbx_acc =
5686 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5687 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
5688 if (!phba->idiag_mbx_acc) {
5689 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5690 "2980 Can't create idiag debugfs\n");
5695 /* iDiag extents access commands */
5696 if (phba->sli4_hba.extents_in_use) {
5697 snprintf(name, sizeof(name), "extAcc");
5698 if (!phba->idiag_ext_acc) {
5699 phba->idiag_ext_acc =
5700 debugfs_create_file(name,
5701 S_IFREG|S_IRUGO|S_IWUSR,
5702 phba->idiag_root, phba,
5703 &lpfc_idiag_op_extAcc);
5704 if (!phba->idiag_ext_acc) {
5705 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5719 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
5720 * @vport: The vport pointer to remove from debugfs.
5723 * When Debugfs is configured this routine removes debugfs file system elements
5724 * that are specific to this vport. It also checks to see if there are any
5725 * users left for the debugfs directories associated with the HBA and driver. If
5726 * this is the last user of the HBA directory or driver directory then it will
5727 * remove those from the debugfs infrastructure as well.
5730 lpfc_debugfs_terminate(struct lpfc_vport *vport)
5732 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5733 struct lpfc_hba *phba = vport->phba;
5735 kfree(vport->disc_trc);
5736 vport->disc_trc = NULL;
5738 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
5739 vport->debug_disc_trc = NULL;
5741 debugfs_remove(vport->debug_nodelist); /* nodelist */
5742 vport->debug_nodelist = NULL;
5744 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
5745 vport->debug_nvmestat = NULL;
5747 debugfs_remove(vport->debug_nvmektime); /* nvmektime */
5748 vport->debug_nvmektime = NULL;
5750 debugfs_remove(vport->debug_cpucheck); /* cpucheck */
5751 vport->debug_cpucheck = NULL;
5753 if (vport->vport_debugfs_root) {
5754 debugfs_remove(vport->vport_debugfs_root); /* vportX */
5755 vport->vport_debugfs_root = NULL;
5756 atomic_dec(&phba->debugfs_vport_count);
5759 if (atomic_read(&phba->debugfs_vport_count) == 0) {
5761 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
5762 phba->debug_hbqinfo = NULL;
5764 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
5765 phba->debug_dumpHBASlim = NULL;
5767 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
5768 phba->debug_dumpHostSlim = NULL;
5770 debugfs_remove(phba->debug_dumpData); /* dumpData */
5771 phba->debug_dumpData = NULL;
5773 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
5774 phba->debug_dumpDif = NULL;
5776 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
5777 phba->debug_InjErrLBA = NULL;
5779 debugfs_remove(phba->debug_InjErrNPortID);
5780 phba->debug_InjErrNPortID = NULL;
5782 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
5783 phba->debug_InjErrWWPN = NULL;
5785 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
5786 phba->debug_writeGuard = NULL;
5788 debugfs_remove(phba->debug_writeApp); /* writeApp */
5789 phba->debug_writeApp = NULL;
5791 debugfs_remove(phba->debug_writeRef); /* writeRef */
5792 phba->debug_writeRef = NULL;
5794 debugfs_remove(phba->debug_readGuard); /* readGuard */
5795 phba->debug_readGuard = NULL;
5797 debugfs_remove(phba->debug_readApp); /* readApp */
5798 phba->debug_readApp = NULL;
5800 debugfs_remove(phba->debug_readRef); /* readRef */
5801 phba->debug_readRef = NULL;
5803 kfree(phba->slow_ring_trc);
5804 phba->slow_ring_trc = NULL;
5806 /* slow_ring_trace */
5807 debugfs_remove(phba->debug_slow_ring_trc);
5808 phba->debug_slow_ring_trc = NULL;
5810 debugfs_remove(phba->debug_nvmeio_trc);
5811 phba->debug_nvmeio_trc = NULL;
5813 kfree(phba->nvmeio_trc);
5814 phba->nvmeio_trc = NULL;
5819 if (phba->sli_rev == LPFC_SLI_REV4) {
5821 debugfs_remove(phba->idiag_ext_acc);
5822 phba->idiag_ext_acc = NULL;
5825 debugfs_remove(phba->idiag_mbx_acc);
5826 phba->idiag_mbx_acc = NULL;
5829 debugfs_remove(phba->idiag_ctl_acc);
5830 phba->idiag_ctl_acc = NULL;
5833 debugfs_remove(phba->idiag_drb_acc);
5834 phba->idiag_drb_acc = NULL;
5837 debugfs_remove(phba->idiag_que_acc);
5838 phba->idiag_que_acc = NULL;
5841 debugfs_remove(phba->idiag_que_info);
5842 phba->idiag_que_info = NULL;
5845 debugfs_remove(phba->idiag_bar_acc);
5846 phba->idiag_bar_acc = NULL;
5849 debugfs_remove(phba->idiag_pci_cfg);
5850 phba->idiag_pci_cfg = NULL;
5852 /* Finally remove the iDiag debugfs root */
5853 debugfs_remove(phba->idiag_root);
5854 phba->idiag_root = NULL;
5857 if (phba->hba_debugfs_root) {
5858 debugfs_remove(phba->hba_debugfs_root); /* fnX */
5859 phba->hba_debugfs_root = NULL;
5860 atomic_dec(&lpfc_debugfs_hba_count);
5863 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
5864 debugfs_remove(lpfc_debugfs_root); /* lpfc */
5865 lpfc_debugfs_root = NULL;
5873 * Driver debug utility routines outside of debugfs. The debug utility
5874 * routines implemented here is intended to be used in the instrumented
5875 * debug driver for debugging host or port issues.
5879 * lpfc_debug_dump_all_queues - dump all the queues with a hba
5880 * @phba: Pointer to HBA context object.
5882 * This function dumps entries of all the queues asociated with the @phba.
5885 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
5890 * Dump Work Queues (WQs)
5892 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
5893 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
5894 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
5896 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5897 lpfc_debug_dump_wq(phba, DUMP_FCP, idx);
5899 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5900 lpfc_debug_dump_wq(phba, DUMP_NVME, idx);
5902 lpfc_debug_dump_hdr_rq(phba);
5903 lpfc_debug_dump_dat_rq(phba);
5905 * Dump Complete Queues (CQs)
5907 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
5908 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
5909 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
5911 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5912 lpfc_debug_dump_cq(phba, DUMP_FCP, idx);
5914 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5915 lpfc_debug_dump_cq(phba, DUMP_NVME, idx);
5918 * Dump Event Queues (EQs)
5920 for (idx = 0; idx < phba->io_channel_irqs; idx++)
5921 lpfc_debug_dump_hba_eq(phba, idx);