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 = kmalloc((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 memset(phba->nvmeio_trc, 0,
2239 (sizeof(struct lpfc_debugfs_nvmeio_trc) * sz));
2240 atomic_set(&phba->nvmeio_trc_cnt, 0);
2241 phba->nvmeio_trc_on = 0;
2242 phba->nvmeio_trc_output_idx = 0;
2244 return strlen(pbuf);
2248 lpfc_debugfs_cpucheck_open(struct inode *inode, struct file *file)
2250 struct lpfc_vport *vport = inode->i_private;
2251 struct lpfc_debug *debug;
2254 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2258 /* Round to page boundary */
2259 debug->buffer = kmalloc(LPFC_CPUCHECK_SIZE, GFP_KERNEL);
2260 if (!debug->buffer) {
2265 debug->len = lpfc_debugfs_cpucheck_data(vport, debug->buffer,
2266 LPFC_NVMEKTIME_SIZE);
2268 debug->i_private = inode->i_private;
2269 file->private_data = debug;
2277 lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
2278 size_t nbytes, loff_t *ppos)
2280 struct lpfc_debug *debug = file->private_data;
2281 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2282 struct lpfc_hba *phba = vport->phba;
2290 memset(mybuf, 0, sizeof(mybuf));
2292 if (copy_from_user(mybuf, buf, nbytes))
2296 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2297 if (phba->nvmet_support)
2298 phba->cpucheck_on |= LPFC_CHECK_NVMET_IO;
2300 phba->cpucheck_on |= LPFC_CHECK_NVME_IO;
2301 return strlen(pbuf);
2302 } else if ((strncmp(pbuf, "rcv",
2303 sizeof("rcv") - 1) == 0)) {
2304 if (phba->nvmet_support)
2305 phba->cpucheck_on |= LPFC_CHECK_NVMET_RCV;
2308 return strlen(pbuf);
2309 } else if ((strncmp(pbuf, "off",
2310 sizeof("off") - 1) == 0)) {
2311 phba->cpucheck_on = LPFC_CHECK_OFF;
2312 return strlen(pbuf);
2313 } else if ((strncmp(pbuf, "zero",
2314 sizeof("zero") - 1) == 0)) {
2315 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
2316 if (i >= LPFC_CHECK_CPU_CNT)
2318 phba->cpucheck_rcv_io[i] = 0;
2319 phba->cpucheck_xmt_io[i] = 0;
2320 phba->cpucheck_cmpl_io[i] = 0;
2321 phba->cpucheck_ccmpl_io[i] = 0;
2323 return strlen(pbuf);
2329 * ---------------------------------
2330 * iDiag debugfs file access methods
2331 * ---------------------------------
2333 * All access methods are through the proper SLI4 PCI function's debugfs
2336 * /sys/kernel/debug/lpfc/fn<#>/iDiag
2340 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
2341 * @buf: The pointer to the user space buffer.
2342 * @nbytes: The number of bytes in the user space buffer.
2343 * @idiag_cmd: pointer to the idiag command struct.
2345 * This routine reads data from debugfs user space buffer and parses the
2346 * buffer for getting the idiag command and arguments. The while space in
2347 * between the set of data is used as the parsing separator.
2349 * This routine returns 0 when successful, it returns proper error code
2350 * back to the user space in error conditions.
2352 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
2353 struct lpfc_idiag_cmd *idiag_cmd)
2356 char *pbuf, *step_str;
2360 memset(mybuf, 0, sizeof(mybuf));
2361 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
2362 bsize = min(nbytes, (sizeof(mybuf)-1));
2364 if (copy_from_user(mybuf, buf, bsize))
2367 step_str = strsep(&pbuf, "\t ");
2369 /* The opcode must present */
2373 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
2374 if (idiag_cmd->opcode == 0)
2377 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
2378 step_str = strsep(&pbuf, "\t ");
2381 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
2387 * lpfc_idiag_open - idiag open debugfs
2388 * @inode: The inode pointer that contains a pointer to phba.
2389 * @file: The file pointer to attach the file operation.
2392 * This routine is the entry point for the debugfs open file operation. It
2393 * gets the reference to phba from the i_private field in @inode, it then
2394 * allocates buffer for the file operation, performs the necessary PCI config
2395 * space read into the allocated buffer according to the idiag user command
2396 * setup, and then returns a pointer to buffer in the private_data field in
2400 * This function returns zero if successful. On error it will return an
2401 * negative error value.
2404 lpfc_idiag_open(struct inode *inode, struct file *file)
2406 struct lpfc_debug *debug;
2408 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2412 debug->i_private = inode->i_private;
2413 debug->buffer = NULL;
2414 file->private_data = debug;
2420 * lpfc_idiag_release - Release idiag access file operation
2421 * @inode: The inode pointer that contains a vport pointer. (unused)
2422 * @file: The file pointer that contains the buffer to release.
2425 * This routine is the generic release routine for the idiag access file
2426 * operation, it frees the buffer that was allocated when the debugfs file
2430 * This function returns zero.
2433 lpfc_idiag_release(struct inode *inode, struct file *file)
2435 struct lpfc_debug *debug = file->private_data;
2437 /* Free the buffers to the file operation */
2438 kfree(debug->buffer);
2445 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
2446 * @inode: The inode pointer that contains a vport pointer. (unused)
2447 * @file: The file pointer that contains the buffer to release.
2450 * This routine frees the buffer that was allocated when the debugfs file
2451 * was opened. It also reset the fields in the idiag command struct in the
2452 * case of command for write operation.
2455 * This function returns zero.
2458 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
2460 struct lpfc_debug *debug = file->private_data;
2462 if (debug->op == LPFC_IDIAG_OP_WR) {
2463 switch (idiag.cmd.opcode) {
2464 case LPFC_IDIAG_CMD_PCICFG_WR:
2465 case LPFC_IDIAG_CMD_PCICFG_ST:
2466 case LPFC_IDIAG_CMD_PCICFG_CL:
2467 case LPFC_IDIAG_CMD_QUEACC_WR:
2468 case LPFC_IDIAG_CMD_QUEACC_ST:
2469 case LPFC_IDIAG_CMD_QUEACC_CL:
2470 memset(&idiag, 0, sizeof(idiag));
2477 /* Free the buffers to the file operation */
2478 kfree(debug->buffer);
2485 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
2486 * @file: The file pointer to read from.
2487 * @buf: The buffer to copy the data to.
2488 * @nbytes: The number of bytes to read.
2489 * @ppos: The position in the file to start reading from.
2492 * This routine reads data from the @phba pci config space according to the
2493 * idiag command, and copies to user @buf. Depending on the PCI config space
2494 * read command setup, it does either a single register read of a byte
2495 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
2496 * registers from the 4K extended PCI config space.
2499 * This function returns the amount of data that was read (this could be less
2500 * than @nbytes if the end of the file was reached) or a negative error value.
2503 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
2506 struct lpfc_debug *debug = file->private_data;
2507 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2508 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
2511 struct pci_dev *pdev;
2516 pdev = phba->pcidev;
2520 /* This is a user read operation */
2521 debug->op = LPFC_IDIAG_OP_RD;
2524 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
2527 pbuffer = debug->buffer;
2532 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2533 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2534 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2538 /* Read single PCI config space register */
2540 case SIZE_U8: /* byte (8 bits) */
2541 pci_read_config_byte(pdev, where, &u8val);
2542 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2543 "%03x: %02x\n", where, u8val);
2545 case SIZE_U16: /* word (16 bits) */
2546 pci_read_config_word(pdev, where, &u16val);
2547 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2548 "%03x: %04x\n", where, u16val);
2550 case SIZE_U32: /* double word (32 bits) */
2551 pci_read_config_dword(pdev, where, &u32val);
2552 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2553 "%03x: %08x\n", where, u32val);
2555 case LPFC_PCI_CFG_BROWSE: /* browse all */
2563 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2567 /* Browse all PCI config space registers */
2568 offset_label = idiag.offset.last_rd;
2569 offset = offset_label;
2571 /* Read PCI config space */
2572 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2573 "%03x: ", offset_label);
2575 pci_read_config_dword(pdev, offset, &u32val);
2576 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2578 offset += sizeof(uint32_t);
2579 if (offset >= LPFC_PCI_CFG_SIZE) {
2580 len += snprintf(pbuffer+len,
2581 LPFC_PCI_CFG_SIZE-len, "\n");
2584 index -= sizeof(uint32_t);
2586 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2588 else if (!(index % (8 * sizeof(uint32_t)))) {
2589 offset_label += (8 * sizeof(uint32_t));
2590 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2591 "\n%03x: ", offset_label);
2595 /* Set up the offset for next portion of pci cfg read */
2597 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
2598 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
2599 idiag.offset.last_rd = 0;
2601 idiag.offset.last_rd = 0;
2603 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2607 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
2608 * @file: The file pointer to read from.
2609 * @buf: The buffer to copy the user data from.
2610 * @nbytes: The number of bytes to get.
2611 * @ppos: The position in the file to start reading from.
2613 * This routine get the debugfs idiag command struct from user space and
2614 * then perform the syntax check for PCI config space read or write command
2615 * accordingly. In the case of PCI config space read command, it sets up
2616 * the command in the idiag command struct for the debugfs read operation.
2617 * In the case of PCI config space write operation, it executes the write
2618 * operation into the PCI config space accordingly.
2620 * It returns the @nbytges passing in from debugfs user space when successful.
2621 * In case of error conditions, it returns proper error code back to the user
2625 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
2626 size_t nbytes, loff_t *ppos)
2628 struct lpfc_debug *debug = file->private_data;
2629 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2630 uint32_t where, value, count;
2634 struct pci_dev *pdev;
2637 pdev = phba->pcidev;
2641 /* This is a user write operation */
2642 debug->op = LPFC_IDIAG_OP_WR;
2644 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2648 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2649 /* Sanity check on PCI config read command line arguments */
2650 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
2652 /* Read command from PCI config space, set up command fields */
2653 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2654 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2655 if (count == LPFC_PCI_CFG_BROWSE) {
2656 if (where % sizeof(uint32_t))
2658 /* Starting offset to browse */
2659 idiag.offset.last_rd = where;
2660 } else if ((count != sizeof(uint8_t)) &&
2661 (count != sizeof(uint16_t)) &&
2662 (count != sizeof(uint32_t)))
2664 if (count == sizeof(uint8_t)) {
2665 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2667 if (where % sizeof(uint8_t))
2670 if (count == sizeof(uint16_t)) {
2671 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2673 if (where % sizeof(uint16_t))
2676 if (count == sizeof(uint32_t)) {
2677 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2679 if (where % sizeof(uint32_t))
2682 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
2683 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
2684 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2685 /* Sanity check on PCI config write command line arguments */
2686 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
2688 /* Write command to PCI config space, read-modify-write */
2689 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2690 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2691 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
2693 if ((count != sizeof(uint8_t)) &&
2694 (count != sizeof(uint16_t)) &&
2695 (count != sizeof(uint32_t)))
2697 if (count == sizeof(uint8_t)) {
2698 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2700 if (where % sizeof(uint8_t))
2702 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2703 pci_write_config_byte(pdev, where,
2705 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2706 rc = pci_read_config_byte(pdev, where, &u8val);
2708 u8val |= (uint8_t)value;
2709 pci_write_config_byte(pdev, where,
2713 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2714 rc = pci_read_config_byte(pdev, where, &u8val);
2716 u8val &= (uint8_t)(~value);
2717 pci_write_config_byte(pdev, where,
2722 if (count == sizeof(uint16_t)) {
2723 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2725 if (where % sizeof(uint16_t))
2727 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2728 pci_write_config_word(pdev, where,
2730 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2731 rc = pci_read_config_word(pdev, where, &u16val);
2733 u16val |= (uint16_t)value;
2734 pci_write_config_word(pdev, where,
2738 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2739 rc = pci_read_config_word(pdev, where, &u16val);
2741 u16val &= (uint16_t)(~value);
2742 pci_write_config_word(pdev, where,
2747 if (count == sizeof(uint32_t)) {
2748 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2750 if (where % sizeof(uint32_t))
2752 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2753 pci_write_config_dword(pdev, where, value);
2754 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2755 rc = pci_read_config_dword(pdev, where,
2759 pci_write_config_dword(pdev, where,
2763 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2764 rc = pci_read_config_dword(pdev, where,
2768 pci_write_config_dword(pdev, where,
2774 /* All other opecodes are illegal for now */
2779 memset(&idiag, 0, sizeof(idiag));
2784 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
2785 * @file: The file pointer to read from.
2786 * @buf: The buffer to copy the data to.
2787 * @nbytes: The number of bytes to read.
2788 * @ppos: The position in the file to start reading from.
2791 * This routine reads data from the @phba pci bar memory mapped space
2792 * according to the idiag command, and copies to user @buf.
2795 * This function returns the amount of data that was read (this could be less
2796 * than @nbytes if the end of the file was reached) or a negative error value.
2799 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
2802 struct lpfc_debug *debug = file->private_data;
2803 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2804 int offset_label, offset, offset_run, len = 0, index;
2805 int bar_num, acc_range, bar_size;
2807 void __iomem *mem_mapped_bar;
2809 struct pci_dev *pdev;
2812 pdev = phba->pcidev;
2816 /* This is a user read operation */
2817 debug->op = LPFC_IDIAG_OP_RD;
2820 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
2823 pbuffer = debug->buffer;
2828 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
2829 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2830 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
2831 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
2832 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
2839 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2840 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2841 if (bar_num == IDIAG_BARACC_BAR_0)
2842 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2843 else if (bar_num == IDIAG_BARACC_BAR_1)
2844 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2845 else if (bar_num == IDIAG_BARACC_BAR_2)
2846 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2849 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2850 if (bar_num == IDIAG_BARACC_BAR_0)
2851 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2857 /* Read single PCI bar space register */
2858 if (acc_range == SINGLE_WORD) {
2859 offset_run = offset;
2860 u32val = readl(mem_mapped_bar + offset_run);
2861 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2862 "%05x: %08x\n", offset_run, u32val);
2866 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2870 /* Browse all PCI bar space registers */
2871 offset_label = idiag.offset.last_rd;
2872 offset_run = offset_label;
2874 /* Read PCI bar memory mapped space */
2875 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2876 "%05x: ", offset_label);
2877 index = LPFC_PCI_BAR_RD_SIZE;
2879 u32val = readl(mem_mapped_bar + offset_run);
2880 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2882 offset_run += sizeof(uint32_t);
2883 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2884 if (offset_run >= bar_size) {
2885 len += snprintf(pbuffer+len,
2886 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2890 if (offset_run >= offset +
2891 (acc_range * sizeof(uint32_t))) {
2892 len += snprintf(pbuffer+len,
2893 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2897 index -= sizeof(uint32_t);
2899 len += snprintf(pbuffer+len,
2900 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2901 else if (!(index % (8 * sizeof(uint32_t)))) {
2902 offset_label += (8 * sizeof(uint32_t));
2903 len += snprintf(pbuffer+len,
2904 LPFC_PCI_BAR_RD_BUF_SIZE-len,
2905 "\n%05x: ", offset_label);
2909 /* Set up the offset for next portion of pci bar read */
2911 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
2912 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2913 if (idiag.offset.last_rd >= bar_size)
2914 idiag.offset.last_rd = 0;
2916 if (offset_run >= offset +
2917 (acc_range * sizeof(uint32_t)))
2918 idiag.offset.last_rd = offset;
2921 if (acc_range == LPFC_PCI_BAR_BROWSE)
2922 idiag.offset.last_rd = 0;
2924 idiag.offset.last_rd = offset;
2927 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2931 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
2932 * @file: The file pointer to read from.
2933 * @buf: The buffer to copy the user data from.
2934 * @nbytes: The number of bytes to get.
2935 * @ppos: The position in the file to start reading from.
2937 * This routine get the debugfs idiag command struct from user space and
2938 * then perform the syntax check for PCI bar memory mapped space read or
2939 * write command accordingly. In the case of PCI bar memory mapped space
2940 * read command, it sets up the command in the idiag command struct for
2941 * the debugfs read operation. In the case of PCI bar memorpy mapped space
2942 * write operation, it executes the write operation into the PCI bar memory
2943 * mapped space accordingly.
2945 * It returns the @nbytges passing in from debugfs user space when successful.
2946 * In case of error conditions, it returns proper error code back to the user
2950 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
2951 size_t nbytes, loff_t *ppos)
2953 struct lpfc_debug *debug = file->private_data;
2954 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2955 uint32_t bar_num, bar_size, offset, value, acc_range;
2956 struct pci_dev *pdev;
2957 void __iomem *mem_mapped_bar;
2962 pdev = phba->pcidev;
2966 /* This is a user write operation */
2967 debug->op = LPFC_IDIAG_OP_WR;
2969 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2973 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2974 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2976 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2977 if ((bar_num != IDIAG_BARACC_BAR_0) &&
2978 (bar_num != IDIAG_BARACC_BAR_1) &&
2979 (bar_num != IDIAG_BARACC_BAR_2))
2981 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2982 if (bar_num != IDIAG_BARACC_BAR_0)
2987 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2988 if (bar_num == IDIAG_BARACC_BAR_0) {
2989 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2990 LPFC_PCI_IF0_BAR0_SIZE;
2991 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2992 } else if (bar_num == IDIAG_BARACC_BAR_1) {
2993 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2994 LPFC_PCI_IF0_BAR1_SIZE;
2995 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2996 } else if (bar_num == IDIAG_BARACC_BAR_2) {
2997 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2998 LPFC_PCI_IF0_BAR2_SIZE;
2999 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3002 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3003 if (bar_num == IDIAG_BARACC_BAR_0) {
3004 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3005 LPFC_PCI_IF2_BAR0_SIZE;
3006 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3012 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3013 if (offset % sizeof(uint32_t))
3016 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3017 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3018 /* Sanity check on PCI config read command line arguments */
3019 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3021 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3022 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3023 if (offset > bar_size - sizeof(uint32_t))
3025 /* Starting offset to browse */
3026 idiag.offset.last_rd = offset;
3027 } else if (acc_range > SINGLE_WORD) {
3028 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3030 /* Starting offset to browse */
3031 idiag.offset.last_rd = offset;
3032 } else if (acc_range != SINGLE_WORD)
3034 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3035 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3036 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3037 /* Sanity check on PCI bar write command line arguments */
3038 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3040 /* Write command to PCI bar space, read-modify-write */
3041 acc_range = SINGLE_WORD;
3042 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3043 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3044 writel(value, mem_mapped_bar + offset);
3045 readl(mem_mapped_bar + offset);
3047 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3048 u32val = readl(mem_mapped_bar + offset);
3050 writel(u32val, mem_mapped_bar + offset);
3051 readl(mem_mapped_bar + offset);
3053 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3054 u32val = readl(mem_mapped_bar + offset);
3056 writel(u32val, mem_mapped_bar + offset);
3057 readl(mem_mapped_bar + offset);
3060 /* All other opecodes are illegal for now */
3065 memset(&idiag, 0, sizeof(idiag));
3070 __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3071 char *pbuffer, int len)
3076 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3077 "\t\t%s WQ info: ", wqtype);
3078 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3079 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3080 qp->assoc_qid, qp->q_cnt_1,
3081 (unsigned long long)qp->q_cnt_4);
3082 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3083 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3084 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3085 qp->queue_id, qp->entry_count,
3086 qp->entry_size, qp->host_index,
3087 qp->hba_index, qp->entry_repost);
3088 len += snprintf(pbuffer + len,
3089 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3094 lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3095 int *len, int max_cnt, int cq_id)
3097 struct lpfc_queue *qp;
3100 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3101 qp = phba->sli4_hba.fcp_wq[qidx];
3102 if (qp->assoc_qid != cq_id)
3104 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3105 if (*len >= max_cnt)
3108 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3109 qp = phba->sli4_hba.nvme_wq[qidx];
3110 if (qp->assoc_qid != cq_id)
3112 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3113 if (*len >= max_cnt)
3120 __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3121 char *pbuffer, int len)
3126 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3127 "\t%s CQ info: ", cqtype);
3128 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3129 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3130 "xabt:x%x wq:x%llx]\n",
3131 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3132 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3133 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3134 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3135 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3136 qp->queue_id, qp->entry_count,
3137 qp->entry_size, qp->host_index,
3138 qp->hba_index, qp->entry_repost);
3140 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3146 __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3147 char *rqtype, char *pbuffer, int len)
3152 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3153 "\t\t%s RQ info: ", rqtype);
3154 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3155 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
3156 "posted:x%x rcv:x%llx]\n",
3157 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3158 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3159 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3160 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3161 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
3162 qp->queue_id, qp->entry_count, qp->entry_size,
3163 qp->host_index, qp->hba_index, qp->entry_repost);
3164 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3165 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3166 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
3167 datqp->queue_id, datqp->entry_count,
3168 datqp->entry_size, datqp->host_index,
3169 datqp->hba_index, datqp->entry_repost);
3174 lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
3175 int *len, int max_cnt, int eqidx, int eq_id)
3177 struct lpfc_queue *qp;
3180 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3181 qp = phba->sli4_hba.fcp_cq[qidx];
3182 if (qp->assoc_qid != eq_id)
3185 *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
3187 /* Reset max counter */
3190 if (*len >= max_cnt)
3193 rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
3194 max_cnt, qp->queue_id);
3199 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3200 qp = phba->sli4_hba.nvme_cq[qidx];
3201 if (qp->assoc_qid != eq_id)
3204 *len = __lpfc_idiag_print_cq(qp, "NVME", pbuffer, *len);
3206 /* Reset max counter */
3209 if (*len >= max_cnt)
3212 rc = lpfc_idiag_wqs_for_cq(phba, "NVME", pbuffer, len,
3213 max_cnt, qp->queue_id);
3218 if (eqidx < phba->cfg_nvmet_mrq) {
3220 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3221 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3223 /* Reset max counter */
3226 if (*len >= max_cnt)
3230 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3231 *len = __lpfc_idiag_print_rqpair(qp,
3232 phba->sli4_hba.nvmet_mrq_data[eqidx],
3233 "NVMET MRQ", pbuffer, *len);
3235 if (*len >= max_cnt)
3243 __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
3244 char *pbuffer, int len)
3249 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3250 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
3251 "bs:x%x proc:x%llx eqd %d]\n",
3252 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
3253 (unsigned long long)qp->q_cnt_4, qp->q_mode);
3254 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3255 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3256 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
3257 qp->queue_id, qp->entry_count, qp->entry_size,
3258 qp->host_index, qp->hba_index, qp->entry_repost);
3259 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3265 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
3266 * @file: The file pointer to read from.
3267 * @buf: The buffer to copy the data to.
3268 * @nbytes: The number of bytes to read.
3269 * @ppos: The position in the file to start reading from.
3272 * This routine reads data from the @phba SLI4 PCI function queue information,
3273 * and copies to user @buf.
3274 * This routine only returns 1 EQs worth of information. It remembers the last
3275 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
3276 * retrieve all EQs allocated for the phba.
3279 * This function returns the amount of data that was read (this could be less
3280 * than @nbytes if the end of the file was reached) or a negative error value.
3283 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
3286 struct lpfc_debug *debug = file->private_data;
3287 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3289 int max_cnt, rc, x, len = 0;
3290 struct lpfc_queue *qp = NULL;
3293 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
3296 pbuffer = debug->buffer;
3297 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
3302 spin_lock_irq(&phba->hbalock);
3304 /* Fast-path event queue */
3305 if (phba->sli4_hba.hba_eq && phba->io_channel_irqs) {
3307 x = phba->lpfc_idiag_last_eq;
3308 if (phba->cfg_fof && (x >= phba->io_channel_irqs)) {
3309 phba->lpfc_idiag_last_eq = 0;
3312 phba->lpfc_idiag_last_eq++;
3313 if (phba->lpfc_idiag_last_eq >= phba->io_channel_irqs)
3314 if (phba->cfg_fof == 0)
3315 phba->lpfc_idiag_last_eq = 0;
3317 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3318 "EQ %d out of %d HBA EQs\n",
3319 x, phba->io_channel_irqs);
3322 qp = phba->sli4_hba.hba_eq[x];
3326 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
3328 /* Reset max counter */
3334 /* will dump both fcp and nvme cqs/wqs for the eq */
3335 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
3336 max_cnt, x, qp->queue_id);
3340 /* Only EQ 0 has slow path CQs configured */
3344 /* Slow-path mailbox CQ */
3345 qp = phba->sli4_hba.mbx_cq;
3346 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
3350 /* Slow-path MBOX MQ */
3351 qp = phba->sli4_hba.mbx_wq;
3352 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
3356 /* Slow-path ELS response CQ */
3357 qp = phba->sli4_hba.els_cq;
3358 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
3359 /* Reset max counter */
3365 /* Slow-path ELS WQ */
3366 qp = phba->sli4_hba.els_wq;
3367 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
3371 /* Slow-path NVME LS response CQ */
3372 qp = phba->sli4_hba.nvmels_cq;
3373 len = __lpfc_idiag_print_cq(qp, "NVME LS",
3375 /* Reset max counter */
3381 /* Slow-path NVME LS WQ */
3382 qp = phba->sli4_hba.nvmels_wq;
3383 len = __lpfc_idiag_print_wq(qp, "NVME LS",
3388 qp = phba->sli4_hba.hdr_rq;
3389 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
3390 "RQpair", pbuffer, len);
3398 if (phba->cfg_fof) {
3400 qp = phba->sli4_hba.fof_eq;
3401 len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
3403 /* Reset max counter */
3411 qp = phba->sli4_hba.oas_cq;
3412 len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
3413 /* Reset max counter */
3420 qp = phba->sli4_hba.oas_wq;
3421 len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
3426 spin_unlock_irq(&phba->hbalock);
3427 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3430 len += snprintf(pbuffer + len,
3431 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
3433 spin_unlock_irq(&phba->hbalock);
3434 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3438 * lpfc_idiag_que_param_check - queue access command parameter sanity check
3439 * @q: The pointer to queue structure.
3440 * @index: The index into a queue entry.
3441 * @count: The number of queue entries to access.
3444 * The routine performs sanity check on device queue access method commands.
3447 * This function returns -EINVAL when fails the sanity check, otherwise, it
3451 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
3453 /* Only support single entry read or browsing */
3454 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
3456 if (index > q->entry_count - 1)
3462 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
3463 * @pbuffer: The pointer to buffer to copy the read data into.
3464 * @pque: The pointer to the queue to be read.
3465 * @index: The index into the queue entry.
3468 * This routine reads out a single entry from the given queue's index location
3469 * and copies it into the buffer provided.
3472 * This function returns 0 when it fails, otherwise, it returns the length of
3473 * the data read into the buffer provided.
3476 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
3482 if (!pbuffer || !pque)
3485 esize = pque->entry_size;
3486 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3487 "QE-INDEX[%04d]:\n", index);
3490 pentry = pque->qe[index].address;
3492 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3495 offset += sizeof(uint32_t);
3496 esize -= sizeof(uint32_t);
3497 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
3498 len += snprintf(pbuffer+len,
3499 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3501 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3507 * lpfc_idiag_queacc_read - idiag debugfs read port queue
3508 * @file: The file pointer to read from.
3509 * @buf: The buffer to copy the data to.
3510 * @nbytes: The number of bytes to read.
3511 * @ppos: The position in the file to start reading from.
3514 * This routine reads data from the @phba device queue memory according to the
3515 * idiag command, and copies to user @buf. Depending on the queue dump read
3516 * command setup, it does either a single queue entry read or browing through
3517 * all entries of the queue.
3520 * This function returns the amount of data that was read (this could be less
3521 * than @nbytes if the end of the file was reached) or a negative error value.
3524 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
3527 struct lpfc_debug *debug = file->private_data;
3528 uint32_t last_index, index, count;
3529 struct lpfc_queue *pque = NULL;
3533 /* This is a user read operation */
3534 debug->op = LPFC_IDIAG_OP_RD;
3537 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
3540 pbuffer = debug->buffer;
3545 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3546 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3547 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3548 pque = (struct lpfc_queue *)idiag.ptr_private;
3552 /* Browse the queue starting from index */
3553 if (count == LPFC_QUE_ACC_BROWSE)
3556 /* Read a single entry from the queue */
3557 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3559 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3563 /* Browse all entries from the queue */
3564 last_index = idiag.offset.last_rd;
3567 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
3568 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3570 if (index > pque->entry_count - 1)
3574 /* Set up the offset for next portion of pci cfg read */
3575 if (index > pque->entry_count - 1)
3577 idiag.offset.last_rd = index;
3579 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3583 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
3584 * @file: The file pointer to read from.
3585 * @buf: The buffer to copy the user data from.
3586 * @nbytes: The number of bytes to get.
3587 * @ppos: The position in the file to start reading from.
3589 * This routine get the debugfs idiag command struct from user space and then
3590 * perform the syntax check for port queue read (dump) or write (set) command
3591 * accordingly. In the case of port queue read command, it sets up the command
3592 * in the idiag command struct for the following debugfs read operation. In
3593 * the case of port queue write operation, it executes the write operation
3594 * into the port queue entry accordingly.
3596 * It returns the @nbytges passing in from debugfs user space when successful.
3597 * In case of error conditions, it returns proper error code back to the user
3601 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3602 size_t nbytes, loff_t *ppos)
3604 struct lpfc_debug *debug = file->private_data;
3605 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3606 uint32_t qidx, quetp, queid, index, count, offset, value;
3608 struct lpfc_queue *pque, *qp;
3611 /* This is a user write operation */
3612 debug->op = LPFC_IDIAG_OP_WR;
3614 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3618 /* Get and sanity check on command feilds */
3619 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
3620 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
3621 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3622 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3623 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
3624 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
3626 /* Sanity check on command line arguments */
3627 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3628 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3629 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3630 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
3634 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3635 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
3642 /* HBA event queue */
3643 if (phba->sli4_hba.hba_eq) {
3644 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
3645 qp = phba->sli4_hba.hba_eq[qidx];
3646 if (qp && qp->queue_id == queid) {
3648 rc = lpfc_idiag_que_param_check(qp,
3652 idiag.ptr_private = qp;
3660 /* MBX complete queue */
3661 if (phba->sli4_hba.mbx_cq &&
3662 phba->sli4_hba.mbx_cq->queue_id == queid) {
3664 rc = lpfc_idiag_que_param_check(
3665 phba->sli4_hba.mbx_cq, index, count);
3668 idiag.ptr_private = phba->sli4_hba.mbx_cq;
3671 /* ELS complete queue */
3672 if (phba->sli4_hba.els_cq &&
3673 phba->sli4_hba.els_cq->queue_id == queid) {
3675 rc = lpfc_idiag_que_param_check(
3676 phba->sli4_hba.els_cq, index, count);
3679 idiag.ptr_private = phba->sli4_hba.els_cq;
3682 /* NVME LS complete queue */
3683 if (phba->sli4_hba.nvmels_cq &&
3684 phba->sli4_hba.nvmels_cq->queue_id == queid) {
3686 rc = lpfc_idiag_que_param_check(
3687 phba->sli4_hba.nvmels_cq, index, count);
3690 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3693 /* FCP complete queue */
3694 if (phba->sli4_hba.fcp_cq) {
3695 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3697 qp = phba->sli4_hba.fcp_cq[qidx];
3698 if (qp && qp->queue_id == queid) {
3700 rc = lpfc_idiag_que_param_check(
3704 idiag.ptr_private = qp;
3709 /* NVME complete queue */
3710 if (phba->sli4_hba.nvme_cq) {
3713 if (phba->sli4_hba.nvme_cq[qidx] &&
3714 phba->sli4_hba.nvme_cq[qidx]->queue_id ==
3717 rc = lpfc_idiag_que_param_check(
3718 phba->sli4_hba.nvme_cq[qidx],
3723 phba->sli4_hba.nvme_cq[qidx];
3726 } while (++qidx < phba->cfg_nvme_io_channel);
3731 /* MBX work queue */
3732 if (phba->sli4_hba.mbx_wq &&
3733 phba->sli4_hba.mbx_wq->queue_id == queid) {
3735 rc = lpfc_idiag_que_param_check(
3736 phba->sli4_hba.mbx_wq, index, count);
3739 idiag.ptr_private = phba->sli4_hba.mbx_wq;
3745 /* ELS work queue */
3746 if (phba->sli4_hba.els_wq &&
3747 phba->sli4_hba.els_wq->queue_id == queid) {
3749 rc = lpfc_idiag_que_param_check(
3750 phba->sli4_hba.els_wq, index, count);
3753 idiag.ptr_private = phba->sli4_hba.els_wq;
3756 /* NVME LS work queue */
3757 if (phba->sli4_hba.nvmels_wq &&
3758 phba->sli4_hba.nvmels_wq->queue_id == queid) {
3760 rc = lpfc_idiag_que_param_check(
3761 phba->sli4_hba.nvmels_wq, index, count);
3764 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3767 /* FCP work queue */
3768 if (phba->sli4_hba.fcp_wq) {
3769 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3771 qp = phba->sli4_hba.fcp_wq[qidx];
3772 if (qp && qp->queue_id == queid) {
3774 rc = lpfc_idiag_que_param_check(
3778 idiag.ptr_private = qp;
3783 /* NVME work queue */
3784 if (phba->sli4_hba.nvme_wq) {
3785 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3787 qp = phba->sli4_hba.nvme_wq[qidx];
3788 if (qp && qp->queue_id == queid) {
3790 rc = lpfc_idiag_que_param_check(
3794 idiag.ptr_private = qp;
3800 /* NVME work queues */
3801 if (phba->sli4_hba.nvme_wq) {
3802 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3804 if (!phba->sli4_hba.nvme_wq[qidx])
3806 if (phba->sli4_hba.nvme_wq[qidx]->queue_id ==
3809 rc = lpfc_idiag_que_param_check(
3810 phba->sli4_hba.nvme_wq[qidx],
3815 phba->sli4_hba.nvme_wq[qidx];
3824 if (phba->sli4_hba.hdr_rq &&
3825 phba->sli4_hba.hdr_rq->queue_id == queid) {
3827 rc = lpfc_idiag_que_param_check(
3828 phba->sli4_hba.hdr_rq, index, count);
3831 idiag.ptr_private = phba->sli4_hba.hdr_rq;
3835 if (phba->sli4_hba.dat_rq &&
3836 phba->sli4_hba.dat_rq->queue_id == queid) {
3838 rc = lpfc_idiag_que_param_check(
3839 phba->sli4_hba.dat_rq, index, count);
3842 idiag.ptr_private = phba->sli4_hba.dat_rq;
3854 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3855 if (count == LPFC_QUE_ACC_BROWSE)
3856 idiag.offset.last_rd = index;
3859 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3860 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3861 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3862 /* Additional sanity checks on write operation */
3863 pque = (struct lpfc_queue *)idiag.ptr_private;
3864 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
3866 pentry = pque->qe[index].address;
3868 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
3870 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
3872 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
3878 /* Clean out command structure on command error out */
3879 memset(&idiag, 0, sizeof(idiag));
3884 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
3885 * @phba: The pointer to hba structure.
3886 * @pbuffer: The pointer to the buffer to copy the data to.
3887 * @len: The lenght of bytes to copied.
3888 * @drbregid: The id to doorbell registers.
3891 * This routine reads a doorbell register and copies its content to the
3892 * user buffer pointed to by @pbuffer.
3895 * This function returns the amount of data that was copied into @pbuffer.
3898 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
3899 int len, uint32_t drbregid)
3907 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3908 "EQCQ-DRB-REG: 0x%08x\n",
3909 readl(phba->sli4_hba.EQCQDBregaddr));
3912 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3913 "MQ-DRB-REG: 0x%08x\n",
3914 readl(phba->sli4_hba.MQDBregaddr));
3917 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3918 "WQ-DRB-REG: 0x%08x\n",
3919 readl(phba->sli4_hba.WQDBregaddr));
3922 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3923 "RQ-DRB-REG: 0x%08x\n",
3924 readl(phba->sli4_hba.RQDBregaddr));
3934 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
3935 * @file: The file pointer to read from.
3936 * @buf: The buffer to copy the data to.
3937 * @nbytes: The number of bytes to read.
3938 * @ppos: The position in the file to start reading from.
3941 * This routine reads data from the @phba device doorbell register according
3942 * to the idiag command, and copies to user @buf. Depending on the doorbell
3943 * register read command setup, it does either a single doorbell register
3944 * read or dump all doorbell registers.
3947 * This function returns the amount of data that was read (this could be less
3948 * than @nbytes if the end of the file was reached) or a negative error value.
3951 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
3954 struct lpfc_debug *debug = file->private_data;
3955 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3956 uint32_t drb_reg_id, i;
3960 /* This is a user read operation */
3961 debug->op = LPFC_IDIAG_OP_RD;
3964 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
3967 pbuffer = debug->buffer;
3972 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
3973 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
3977 if (drb_reg_id == LPFC_DRB_ACC_ALL)
3978 for (i = 1; i <= LPFC_DRB_MAX; i++)
3979 len = lpfc_idiag_drbacc_read_reg(phba,
3982 len = lpfc_idiag_drbacc_read_reg(phba,
3983 pbuffer, len, drb_reg_id);
3985 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3989 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
3990 * @file: The file pointer to read from.
3991 * @buf: The buffer to copy the user data from.
3992 * @nbytes: The number of bytes to get.
3993 * @ppos: The position in the file to start reading from.
3995 * This routine get the debugfs idiag command struct from user space and then
3996 * perform the syntax check for port doorbell register read (dump) or write
3997 * (set) command accordingly. In the case of port queue read command, it sets
3998 * up the command in the idiag command struct for the following debugfs read
3999 * operation. In the case of port doorbell register write operation, it
4000 * executes the write operation into the port doorbell register accordingly.
4002 * It returns the @nbytges passing in from debugfs user space when successful.
4003 * In case of error conditions, it returns proper error code back to the user
4007 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4008 size_t nbytes, loff_t *ppos)
4010 struct lpfc_debug *debug = file->private_data;
4011 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4012 uint32_t drb_reg_id, value, reg_val = 0;
4013 void __iomem *drb_reg;
4016 /* This is a user write operation */
4017 debug->op = LPFC_IDIAG_OP_WR;
4019 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4023 /* Sanity check on command line arguments */
4024 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4025 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
4027 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4028 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4029 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4030 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4032 if (drb_reg_id > LPFC_DRB_MAX)
4034 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4035 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4037 if ((drb_reg_id > LPFC_DRB_MAX) &&
4038 (drb_reg_id != LPFC_DRB_ACC_ALL))
4043 /* Perform the write access operation */
4044 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4045 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4046 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4047 switch (drb_reg_id) {
4049 drb_reg = phba->sli4_hba.EQCQDBregaddr;
4052 drb_reg = phba->sli4_hba.MQDBregaddr;
4055 drb_reg = phba->sli4_hba.WQDBregaddr;
4058 drb_reg = phba->sli4_hba.RQDBregaddr;
4064 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4066 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4067 reg_val = readl(drb_reg);
4070 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4071 reg_val = readl(drb_reg);
4074 writel(reg_val, drb_reg);
4075 readl(drb_reg); /* flush */
4080 /* Clean out command structure on command error out */
4081 memset(&idiag, 0, sizeof(idiag));
4086 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4087 * @phba: The pointer to hba structure.
4088 * @pbuffer: The pointer to the buffer to copy the data to.
4089 * @len: The lenght of bytes to copied.
4090 * @drbregid: The id to doorbell registers.
4093 * This routine reads a control register and copies its content to the
4094 * user buffer pointed to by @pbuffer.
4097 * This function returns the amount of data that was copied into @pbuffer.
4100 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4101 int len, uint32_t ctlregid)
4108 case LPFC_CTL_PORT_SEM:
4109 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4110 "Port SemReg: 0x%08x\n",
4111 readl(phba->sli4_hba.conf_regs_memmap_p +
4112 LPFC_CTL_PORT_SEM_OFFSET));
4114 case LPFC_CTL_PORT_STA:
4115 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4116 "Port StaReg: 0x%08x\n",
4117 readl(phba->sli4_hba.conf_regs_memmap_p +
4118 LPFC_CTL_PORT_STA_OFFSET));
4120 case LPFC_CTL_PORT_CTL:
4121 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4122 "Port CtlReg: 0x%08x\n",
4123 readl(phba->sli4_hba.conf_regs_memmap_p +
4124 LPFC_CTL_PORT_CTL_OFFSET));
4126 case LPFC_CTL_PORT_ER1:
4127 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4128 "Port Er1Reg: 0x%08x\n",
4129 readl(phba->sli4_hba.conf_regs_memmap_p +
4130 LPFC_CTL_PORT_ER1_OFFSET));
4132 case LPFC_CTL_PORT_ER2:
4133 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4134 "Port Er2Reg: 0x%08x\n",
4135 readl(phba->sli4_hba.conf_regs_memmap_p +
4136 LPFC_CTL_PORT_ER2_OFFSET));
4138 case LPFC_CTL_PDEV_CTL:
4139 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4140 "PDev CtlReg: 0x%08x\n",
4141 readl(phba->sli4_hba.conf_regs_memmap_p +
4142 LPFC_CTL_PDEV_CTL_OFFSET));
4151 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4152 * @file: The file pointer to read from.
4153 * @buf: The buffer to copy the data to.
4154 * @nbytes: The number of bytes to read.
4155 * @ppos: The position in the file to start reading from.
4158 * This routine reads data from the @phba port and device registers according
4159 * to the idiag command, and copies to user @buf.
4162 * This function returns the amount of data that was read (this could be less
4163 * than @nbytes if the end of the file was reached) or a negative error value.
4166 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4169 struct lpfc_debug *debug = file->private_data;
4170 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4171 uint32_t ctl_reg_id, i;
4175 /* This is a user read operation */
4176 debug->op = LPFC_IDIAG_OP_RD;
4179 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4182 pbuffer = debug->buffer;
4187 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4188 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4192 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4193 for (i = 1; i <= LPFC_CTL_MAX; i++)
4194 len = lpfc_idiag_ctlacc_read_reg(phba,
4197 len = lpfc_idiag_ctlacc_read_reg(phba,
4198 pbuffer, len, ctl_reg_id);
4200 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4204 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4205 * @file: The file pointer to read from.
4206 * @buf: The buffer to copy the user data from.
4207 * @nbytes: The number of bytes to get.
4208 * @ppos: The position in the file to start reading from.
4210 * This routine get the debugfs idiag command struct from user space and then
4211 * perform the syntax check for port and device control register read (dump)
4212 * or write (set) command accordingly.
4214 * It returns the @nbytges passing in from debugfs user space when successful.
4215 * In case of error conditions, it returns proper error code back to the user
4219 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4220 size_t nbytes, loff_t *ppos)
4222 struct lpfc_debug *debug = file->private_data;
4223 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4224 uint32_t ctl_reg_id, value, reg_val = 0;
4225 void __iomem *ctl_reg;
4228 /* This is a user write operation */
4229 debug->op = LPFC_IDIAG_OP_WR;
4231 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4235 /* Sanity check on command line arguments */
4236 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4237 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4239 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4240 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4241 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4242 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4244 if (ctl_reg_id > LPFC_CTL_MAX)
4246 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4247 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4249 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4250 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4255 /* Perform the write access operation */
4256 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4257 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4258 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4259 switch (ctl_reg_id) {
4260 case LPFC_CTL_PORT_SEM:
4261 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4262 LPFC_CTL_PORT_SEM_OFFSET;
4264 case LPFC_CTL_PORT_STA:
4265 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4266 LPFC_CTL_PORT_STA_OFFSET;
4268 case LPFC_CTL_PORT_CTL:
4269 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4270 LPFC_CTL_PORT_CTL_OFFSET;
4272 case LPFC_CTL_PORT_ER1:
4273 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4274 LPFC_CTL_PORT_ER1_OFFSET;
4276 case LPFC_CTL_PORT_ER2:
4277 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4278 LPFC_CTL_PORT_ER2_OFFSET;
4280 case LPFC_CTL_PDEV_CTL:
4281 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4282 LPFC_CTL_PDEV_CTL_OFFSET;
4288 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4290 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4291 reg_val = readl(ctl_reg);
4294 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4295 reg_val = readl(ctl_reg);
4298 writel(reg_val, ctl_reg);
4299 readl(ctl_reg); /* flush */
4304 /* Clean out command structure on command error out */
4305 memset(&idiag, 0, sizeof(idiag));
4310 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4311 * @phba: Pointer to HBA context object.
4312 * @pbuffer: Pointer to data buffer.
4315 * This routine gets the driver mailbox access debugfs setup information.
4318 * This function returns the amount of data that was read (this could be less
4319 * than @nbytes if the end of the file was reached) or a negative error value.
4322 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
4324 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4327 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4328 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4329 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4330 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4332 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4333 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
4334 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4335 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
4336 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4337 "mbx_word_cnt: %04d\n", mbx_word_cnt);
4338 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4339 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
4345 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
4346 * @file: The file pointer to read from.
4347 * @buf: The buffer to copy the data to.
4348 * @nbytes: The number of bytes to read.
4349 * @ppos: The position in the file to start reading from.
4352 * This routine reads data from the @phba driver mailbox access debugfs setup
4356 * This function returns the amount of data that was read (this could be less
4357 * than @nbytes if the end of the file was reached) or a negative error value.
4360 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
4363 struct lpfc_debug *debug = file->private_data;
4364 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4368 /* This is a user read operation */
4369 debug->op = LPFC_IDIAG_OP_RD;
4372 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
4375 pbuffer = debug->buffer;
4380 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
4381 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
4384 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
4386 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4390 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
4391 * @file: The file pointer to read from.
4392 * @buf: The buffer to copy the user data from.
4393 * @nbytes: The number of bytes to get.
4394 * @ppos: The position in the file to start reading from.
4396 * This routine get the debugfs idiag command struct from user space and then
4397 * perform the syntax check for driver mailbox command (dump) and sets up the
4398 * necessary states in the idiag command struct accordingly.
4400 * It returns the @nbytges passing in from debugfs user space when successful.
4401 * In case of error conditions, it returns proper error code back to the user
4405 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
4406 size_t nbytes, loff_t *ppos)
4408 struct lpfc_debug *debug = file->private_data;
4409 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4412 /* This is a user write operation */
4413 debug->op = LPFC_IDIAG_OP_WR;
4415 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4419 /* Sanity check on command line arguments */
4420 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4421 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4422 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4423 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4425 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
4426 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
4428 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
4429 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4431 if (mbx_word_cnt > sizeof(MAILBOX_t))
4433 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
4434 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
4436 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
4437 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4439 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
4441 if (mbx_mbox_cmd != 0x9b)
4446 if (mbx_word_cnt == 0)
4448 if (rc != LPFC_MBX_DMP_ARG)
4450 if (mbx_mbox_cmd & ~0xff)
4453 /* condition for stop mailbox dump */
4454 if (mbx_dump_cnt == 0)
4460 /* Clean out command structure on command error out */
4461 memset(&idiag, 0, sizeof(idiag));
4465 /* Clean out command structure on command error out */
4466 memset(&idiag, 0, sizeof(idiag));
4471 * lpfc_idiag_extacc_avail_get - get the available extents information
4472 * @phba: pointer to lpfc hba data structure.
4473 * @pbuffer: pointer to internal buffer.
4474 * @len: length into the internal buffer data has been copied.
4477 * This routine is to get the available extent information.
4480 * overall lenth of the data read into the internal buffer.
4483 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
4485 uint16_t ext_cnt, ext_size;
4487 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4488 "\nAvailable Extents Information:\n");
4490 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4491 "\tPort Available VPI extents: ");
4492 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
4493 &ext_cnt, &ext_size);
4494 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4495 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4497 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4498 "\tPort Available VFI extents: ");
4499 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
4500 &ext_cnt, &ext_size);
4501 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4502 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4504 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4505 "\tPort Available RPI extents: ");
4506 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
4507 &ext_cnt, &ext_size);
4508 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4509 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4511 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4512 "\tPort Available XRI extents: ");
4513 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
4514 &ext_cnt, &ext_size);
4515 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4516 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4522 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
4523 * @phba: pointer to lpfc hba data structure.
4524 * @pbuffer: pointer to internal buffer.
4525 * @len: length into the internal buffer data has been copied.
4528 * This routine is to get the allocated extent information.
4531 * overall lenth of the data read into the internal buffer.
4534 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
4536 uint16_t ext_cnt, ext_size;
4539 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4540 "\nAllocated Extents Information:\n");
4542 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4543 "\tHost Allocated VPI extents: ");
4544 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
4545 &ext_cnt, &ext_size);
4547 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4548 "Port %d Extent %3d, Size %3d\n",
4549 phba->brd_no, ext_cnt, ext_size);
4551 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4554 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4555 "\tHost Allocated VFI extents: ");
4556 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
4557 &ext_cnt, &ext_size);
4559 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4560 "Port %d Extent %3d, Size %3d\n",
4561 phba->brd_no, ext_cnt, ext_size);
4563 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4566 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4567 "\tHost Allocated RPI extents: ");
4568 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
4569 &ext_cnt, &ext_size);
4571 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4572 "Port %d Extent %3d, Size %3d\n",
4573 phba->brd_no, ext_cnt, ext_size);
4575 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4578 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4579 "\tHost Allocated XRI extents: ");
4580 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
4581 &ext_cnt, &ext_size);
4583 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4584 "Port %d Extent %3d, Size %3d\n",
4585 phba->brd_no, ext_cnt, ext_size);
4587 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4594 * lpfc_idiag_extacc_drivr_get - get driver extent information
4595 * @phba: pointer to lpfc hba data structure.
4596 * @pbuffer: pointer to internal buffer.
4597 * @len: length into the internal buffer data has been copied.
4600 * This routine is to get the driver extent information.
4603 * overall lenth of the data read into the internal buffer.
4606 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
4608 struct lpfc_rsrc_blks *rsrc_blks;
4611 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4612 "\nDriver Extents Information:\n");
4614 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4615 "\tVPI extents:\n");
4617 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
4618 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4619 "\t\tBlock %3d: Start %4d, Count %4d\n",
4620 index, rsrc_blks->rsrc_start,
4621 rsrc_blks->rsrc_size);
4624 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4625 "\tVFI extents:\n");
4627 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
4629 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4630 "\t\tBlock %3d: Start %4d, Count %4d\n",
4631 index, rsrc_blks->rsrc_start,
4632 rsrc_blks->rsrc_size);
4636 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4637 "\tRPI extents:\n");
4639 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
4641 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4642 "\t\tBlock %3d: Start %4d, Count %4d\n",
4643 index, rsrc_blks->rsrc_start,
4644 rsrc_blks->rsrc_size);
4648 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4649 "\tXRI extents:\n");
4651 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
4653 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4654 "\t\tBlock %3d: Start %4d, Count %4d\n",
4655 index, rsrc_blks->rsrc_start,
4656 rsrc_blks->rsrc_size);
4664 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
4665 * @file: The file pointer to read from.
4666 * @buf: The buffer to copy the user data from.
4667 * @nbytes: The number of bytes to get.
4668 * @ppos: The position in the file to start reading from.
4670 * This routine get the debugfs idiag command struct from user space and then
4671 * perform the syntax check for extent information access commands and sets
4672 * up the necessary states in the idiag command struct accordingly.
4674 * It returns the @nbytges passing in from debugfs user space when successful.
4675 * In case of error conditions, it returns proper error code back to the user
4679 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
4680 size_t nbytes, loff_t *ppos)
4682 struct lpfc_debug *debug = file->private_data;
4686 /* This is a user write operation */
4687 debug->op = LPFC_IDIAG_OP_WR;
4689 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4693 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4695 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4697 if (rc != LPFC_EXT_ACC_CMD_ARG)
4699 if (!(ext_map & LPFC_EXT_ACC_ALL))
4704 /* Clean out command structure on command error out */
4705 memset(&idiag, 0, sizeof(idiag));
4710 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
4711 * @file: The file pointer to read from.
4712 * @buf: The buffer to copy the data to.
4713 * @nbytes: The number of bytes to read.
4714 * @ppos: The position in the file to start reading from.
4717 * This routine reads data from the proper extent information according to
4718 * the idiag command, and copies to user @buf.
4721 * This function returns the amount of data that was read (this could be less
4722 * than @nbytes if the end of the file was reached) or a negative error value.
4725 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
4728 struct lpfc_debug *debug = file->private_data;
4729 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4734 /* This is a user read operation */
4735 debug->op = LPFC_IDIAG_OP_RD;
4738 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
4741 pbuffer = debug->buffer;
4744 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4747 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4748 if (ext_map & LPFC_EXT_ACC_AVAIL)
4749 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
4750 if (ext_map & LPFC_EXT_ACC_ALLOC)
4751 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
4752 if (ext_map & LPFC_EXT_ACC_DRIVR)
4753 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
4755 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4758 #undef lpfc_debugfs_op_disc_trc
4759 static const struct file_operations lpfc_debugfs_op_disc_trc = {
4760 .owner = THIS_MODULE,
4761 .open = lpfc_debugfs_disc_trc_open,
4762 .llseek = lpfc_debugfs_lseek,
4763 .read = lpfc_debugfs_read,
4764 .release = lpfc_debugfs_release,
4767 #undef lpfc_debugfs_op_nodelist
4768 static const struct file_operations lpfc_debugfs_op_nodelist = {
4769 .owner = THIS_MODULE,
4770 .open = lpfc_debugfs_nodelist_open,
4771 .llseek = lpfc_debugfs_lseek,
4772 .read = lpfc_debugfs_read,
4773 .release = lpfc_debugfs_release,
4776 #undef lpfc_debugfs_op_hbqinfo
4777 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
4778 .owner = THIS_MODULE,
4779 .open = lpfc_debugfs_hbqinfo_open,
4780 .llseek = lpfc_debugfs_lseek,
4781 .read = lpfc_debugfs_read,
4782 .release = lpfc_debugfs_release,
4785 #undef lpfc_debugfs_op_dumpHBASlim
4786 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
4787 .owner = THIS_MODULE,
4788 .open = lpfc_debugfs_dumpHBASlim_open,
4789 .llseek = lpfc_debugfs_lseek,
4790 .read = lpfc_debugfs_read,
4791 .release = lpfc_debugfs_release,
4794 #undef lpfc_debugfs_op_dumpHostSlim
4795 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
4796 .owner = THIS_MODULE,
4797 .open = lpfc_debugfs_dumpHostSlim_open,
4798 .llseek = lpfc_debugfs_lseek,
4799 .read = lpfc_debugfs_read,
4800 .release = lpfc_debugfs_release,
4803 #undef lpfc_debugfs_op_nvmestat
4804 static const struct file_operations lpfc_debugfs_op_nvmestat = {
4805 .owner = THIS_MODULE,
4806 .open = lpfc_debugfs_nvmestat_open,
4807 .llseek = lpfc_debugfs_lseek,
4808 .read = lpfc_debugfs_read,
4809 .write = lpfc_debugfs_nvmestat_write,
4810 .release = lpfc_debugfs_release,
4813 #undef lpfc_debugfs_op_nvmektime
4814 static const struct file_operations lpfc_debugfs_op_nvmektime = {
4815 .owner = THIS_MODULE,
4816 .open = lpfc_debugfs_nvmektime_open,
4817 .llseek = lpfc_debugfs_lseek,
4818 .read = lpfc_debugfs_read,
4819 .write = lpfc_debugfs_nvmektime_write,
4820 .release = lpfc_debugfs_release,
4823 #undef lpfc_debugfs_op_nvmeio_trc
4824 static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
4825 .owner = THIS_MODULE,
4826 .open = lpfc_debugfs_nvmeio_trc_open,
4827 .llseek = lpfc_debugfs_lseek,
4828 .read = lpfc_debugfs_read,
4829 .write = lpfc_debugfs_nvmeio_trc_write,
4830 .release = lpfc_debugfs_release,
4833 #undef lpfc_debugfs_op_cpucheck
4834 static const struct file_operations lpfc_debugfs_op_cpucheck = {
4835 .owner = THIS_MODULE,
4836 .open = lpfc_debugfs_cpucheck_open,
4837 .llseek = lpfc_debugfs_lseek,
4838 .read = lpfc_debugfs_read,
4839 .write = lpfc_debugfs_cpucheck_write,
4840 .release = lpfc_debugfs_release,
4843 #undef lpfc_debugfs_op_dumpData
4844 static const struct file_operations lpfc_debugfs_op_dumpData = {
4845 .owner = THIS_MODULE,
4846 .open = lpfc_debugfs_dumpData_open,
4847 .llseek = lpfc_debugfs_lseek,
4848 .read = lpfc_debugfs_read,
4849 .write = lpfc_debugfs_dumpDataDif_write,
4850 .release = lpfc_debugfs_dumpDataDif_release,
4853 #undef lpfc_debugfs_op_dumpDif
4854 static const struct file_operations lpfc_debugfs_op_dumpDif = {
4855 .owner = THIS_MODULE,
4856 .open = lpfc_debugfs_dumpDif_open,
4857 .llseek = lpfc_debugfs_lseek,
4858 .read = lpfc_debugfs_read,
4859 .write = lpfc_debugfs_dumpDataDif_write,
4860 .release = lpfc_debugfs_dumpDataDif_release,
4863 #undef lpfc_debugfs_op_dif_err
4864 static const struct file_operations lpfc_debugfs_op_dif_err = {
4865 .owner = THIS_MODULE,
4866 .open = simple_open,
4867 .llseek = lpfc_debugfs_lseek,
4868 .read = lpfc_debugfs_dif_err_read,
4869 .write = lpfc_debugfs_dif_err_write,
4870 .release = lpfc_debugfs_dif_err_release,
4873 #undef lpfc_debugfs_op_slow_ring_trc
4874 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
4875 .owner = THIS_MODULE,
4876 .open = lpfc_debugfs_slow_ring_trc_open,
4877 .llseek = lpfc_debugfs_lseek,
4878 .read = lpfc_debugfs_read,
4879 .release = lpfc_debugfs_release,
4882 static struct dentry *lpfc_debugfs_root = NULL;
4883 static atomic_t lpfc_debugfs_hba_count;
4886 * File operations for the iDiag debugfs
4888 #undef lpfc_idiag_op_pciCfg
4889 static const struct file_operations lpfc_idiag_op_pciCfg = {
4890 .owner = THIS_MODULE,
4891 .open = lpfc_idiag_open,
4892 .llseek = lpfc_debugfs_lseek,
4893 .read = lpfc_idiag_pcicfg_read,
4894 .write = lpfc_idiag_pcicfg_write,
4895 .release = lpfc_idiag_cmd_release,
4898 #undef lpfc_idiag_op_barAcc
4899 static const struct file_operations lpfc_idiag_op_barAcc = {
4900 .owner = THIS_MODULE,
4901 .open = lpfc_idiag_open,
4902 .llseek = lpfc_debugfs_lseek,
4903 .read = lpfc_idiag_baracc_read,
4904 .write = lpfc_idiag_baracc_write,
4905 .release = lpfc_idiag_cmd_release,
4908 #undef lpfc_idiag_op_queInfo
4909 static const struct file_operations lpfc_idiag_op_queInfo = {
4910 .owner = THIS_MODULE,
4911 .open = lpfc_idiag_open,
4912 .read = lpfc_idiag_queinfo_read,
4913 .release = lpfc_idiag_release,
4916 #undef lpfc_idiag_op_queAcc
4917 static const struct file_operations lpfc_idiag_op_queAcc = {
4918 .owner = THIS_MODULE,
4919 .open = lpfc_idiag_open,
4920 .llseek = lpfc_debugfs_lseek,
4921 .read = lpfc_idiag_queacc_read,
4922 .write = lpfc_idiag_queacc_write,
4923 .release = lpfc_idiag_cmd_release,
4926 #undef lpfc_idiag_op_drbAcc
4927 static const struct file_operations lpfc_idiag_op_drbAcc = {
4928 .owner = THIS_MODULE,
4929 .open = lpfc_idiag_open,
4930 .llseek = lpfc_debugfs_lseek,
4931 .read = lpfc_idiag_drbacc_read,
4932 .write = lpfc_idiag_drbacc_write,
4933 .release = lpfc_idiag_cmd_release,
4936 #undef lpfc_idiag_op_ctlAcc
4937 static const struct file_operations lpfc_idiag_op_ctlAcc = {
4938 .owner = THIS_MODULE,
4939 .open = lpfc_idiag_open,
4940 .llseek = lpfc_debugfs_lseek,
4941 .read = lpfc_idiag_ctlacc_read,
4942 .write = lpfc_idiag_ctlacc_write,
4943 .release = lpfc_idiag_cmd_release,
4946 #undef lpfc_idiag_op_mbxAcc
4947 static const struct file_operations lpfc_idiag_op_mbxAcc = {
4948 .owner = THIS_MODULE,
4949 .open = lpfc_idiag_open,
4950 .llseek = lpfc_debugfs_lseek,
4951 .read = lpfc_idiag_mbxacc_read,
4952 .write = lpfc_idiag_mbxacc_write,
4953 .release = lpfc_idiag_cmd_release,
4956 #undef lpfc_idiag_op_extAcc
4957 static const struct file_operations lpfc_idiag_op_extAcc = {
4958 .owner = THIS_MODULE,
4959 .open = lpfc_idiag_open,
4960 .llseek = lpfc_debugfs_lseek,
4961 .read = lpfc_idiag_extacc_read,
4962 .write = lpfc_idiag_extacc_write,
4963 .release = lpfc_idiag_cmd_release,
4968 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
4969 * @phba: Pointer to HBA context object.
4970 * @dmabuf: Pointer to a DMA buffer descriptor.
4973 * This routine dump a bsg pass-through non-embedded mailbox command with
4977 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
4978 enum mbox_type mbox_tp, enum dma_type dma_tp,
4979 enum sta_type sta_tp,
4980 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
4982 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4983 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
4984 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
4986 uint32_t do_dump = 0;
4990 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
4993 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4994 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4995 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4996 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4998 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
4999 (*mbx_dump_cnt == 0) ||
5000 (*mbx_word_cnt == 0))
5003 if (*mbx_mbox_cmd != 0x9B)
5006 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5007 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5008 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
5009 pr_err("\nRead mbox command (x%x), "
5010 "nemb:0x%x, extbuf_cnt:%d:\n",
5011 sta_tp, nemb_tp, ext_buf);
5014 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5015 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5016 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
5017 pr_err("\nRead mbox buffer (x%x), "
5018 "nemb:0x%x, extbuf_seq:%d:\n",
5019 sta_tp, nemb_tp, ext_buf);
5022 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5023 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5024 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
5025 pr_err("\nWrite mbox command (x%x), "
5026 "nemb:0x%x, extbuf_cnt:%d:\n",
5027 sta_tp, nemb_tp, ext_buf);
5030 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5031 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5032 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
5033 pr_err("\nWrite mbox buffer (x%x), "
5034 "nemb:0x%x, extbuf_seq:%d:\n",
5035 sta_tp, nemb_tp, ext_buf);
5039 /* dump buffer content */
5041 pword = (uint32_t *)dmabuf->virt;
5042 for (i = 0; i < *mbx_word_cnt; i++) {
5045 pr_err("%s\n", line_buf);
5047 len += snprintf(line_buf+len,
5048 LPFC_MBX_ACC_LBUF_SZ-len,
5051 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5052 "%08x ", (uint32_t)*pword);
5056 pr_err("%s\n", line_buf);
5060 /* Clean out command structure on reaching dump count */
5061 if (*mbx_dump_cnt == 0)
5062 memset(&idiag, 0, sizeof(idiag));
5067 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5068 * @phba: Pointer to HBA context object.
5069 * @dmabuf: Pointer to a DMA buffer descriptor.
5072 * This routine dump a pass-through non-embedded mailbox command from issue
5076 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5078 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5079 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5080 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5086 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5089 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5090 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5091 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5092 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5094 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5095 (*mbx_dump_cnt == 0) ||
5096 (*mbx_word_cnt == 0))
5099 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5100 (*mbx_mbox_cmd != pmbox->mbxCommand))
5103 /* dump buffer content */
5104 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
5105 pr_err("Mailbox command:0x%x dump by word:\n",
5107 pword = (uint32_t *)pmbox;
5108 for (i = 0; i < *mbx_word_cnt; i++) {
5111 pr_err("%s\n", line_buf);
5113 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5114 len += snprintf(line_buf+len,
5115 LPFC_MBX_ACC_LBUF_SZ-len,
5118 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5120 ((uint32_t)*pword) & 0xffffffff);
5124 pr_err("%s\n", line_buf);
5127 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
5128 pr_err("Mailbox command:0x%x dump by byte:\n",
5130 pbyte = (uint8_t *)pmbox;
5131 for (i = 0; i < *mbx_word_cnt; i++) {
5134 pr_err("%s\n", line_buf);
5136 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5137 len += snprintf(line_buf+len,
5138 LPFC_MBX_ACC_LBUF_SZ-len,
5141 for (j = 0; j < 4; j++) {
5142 len += snprintf(line_buf+len,
5143 LPFC_MBX_ACC_LBUF_SZ-len,
5145 ((uint8_t)*pbyte) & 0xff);
5148 len += snprintf(line_buf+len,
5149 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5152 pr_err("%s\n", line_buf);
5157 /* Clean out command structure on reaching dump count */
5158 if (*mbx_dump_cnt == 0)
5159 memset(&idiag, 0, sizeof(idiag));
5165 * lpfc_debugfs_initialize - Initialize debugfs for a vport
5166 * @vport: The vport pointer to initialize.
5169 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5170 * If not already created, this routine will create the lpfc directory, and
5171 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5172 * also create each file used to access lpfc specific debugfs information.
5175 lpfc_debugfs_initialize(struct lpfc_vport *vport)
5177 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5178 struct lpfc_hba *phba = vport->phba;
5181 bool pport_setup = false;
5183 if (!lpfc_debugfs_enable)
5186 /* Setup lpfc root directory */
5187 if (!lpfc_debugfs_root) {
5188 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5189 atomic_set(&lpfc_debugfs_hba_count, 0);
5190 if (!lpfc_debugfs_root) {
5191 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5192 "0408 Cannot create debugfs root\n");
5196 if (!lpfc_debugfs_start_time)
5197 lpfc_debugfs_start_time = jiffies;
5199 /* Setup funcX directory for specific HBA PCI function */
5200 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
5201 if (!phba->hba_debugfs_root) {
5203 phba->hba_debugfs_root =
5204 debugfs_create_dir(name, lpfc_debugfs_root);
5205 if (!phba->hba_debugfs_root) {
5206 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5207 "0412 Cannot create debugfs hba\n");
5210 atomic_inc(&lpfc_debugfs_hba_count);
5211 atomic_set(&phba->debugfs_vport_count, 0);
5214 snprintf(name, sizeof(name), "hbqinfo");
5215 phba->debug_hbqinfo =
5216 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5217 phba->hba_debugfs_root,
5218 phba, &lpfc_debugfs_op_hbqinfo);
5219 if (!phba->debug_hbqinfo) {
5220 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5221 "0411 Cannot create debugfs hbqinfo\n");
5225 /* Setup dumpHBASlim */
5226 if (phba->sli_rev < LPFC_SLI_REV4) {
5227 snprintf(name, sizeof(name), "dumpHBASlim");
5228 phba->debug_dumpHBASlim =
5229 debugfs_create_file(name,
5230 S_IFREG|S_IRUGO|S_IWUSR,
5231 phba->hba_debugfs_root,
5232 phba, &lpfc_debugfs_op_dumpHBASlim);
5233 if (!phba->debug_dumpHBASlim) {
5234 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5235 "0413 Cannot create debugfs "
5240 phba->debug_dumpHBASlim = NULL;
5242 /* Setup dumpHostSlim */
5243 if (phba->sli_rev < LPFC_SLI_REV4) {
5244 snprintf(name, sizeof(name), "dumpHostSlim");
5245 phba->debug_dumpHostSlim =
5246 debugfs_create_file(name,
5247 S_IFREG|S_IRUGO|S_IWUSR,
5248 phba->hba_debugfs_root,
5249 phba, &lpfc_debugfs_op_dumpHostSlim);
5250 if (!phba->debug_dumpHostSlim) {
5251 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5252 "0414 Cannot create debugfs "
5257 phba->debug_dumpHostSlim = NULL;
5259 /* Setup dumpData */
5260 snprintf(name, sizeof(name), "dumpData");
5261 phba->debug_dumpData =
5262 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5263 phba->hba_debugfs_root,
5264 phba, &lpfc_debugfs_op_dumpData);
5265 if (!phba->debug_dumpData) {
5266 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5267 "0800 Cannot create debugfs dumpData\n");
5272 snprintf(name, sizeof(name), "dumpDif");
5273 phba->debug_dumpDif =
5274 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5275 phba->hba_debugfs_root,
5276 phba, &lpfc_debugfs_op_dumpDif);
5277 if (!phba->debug_dumpDif) {
5278 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5279 "0801 Cannot create debugfs dumpDif\n");
5283 /* Setup DIF Error Injections */
5284 snprintf(name, sizeof(name), "InjErrLBA");
5285 phba->debug_InjErrLBA =
5286 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5287 phba->hba_debugfs_root,
5288 phba, &lpfc_debugfs_op_dif_err);
5289 if (!phba->debug_InjErrLBA) {
5290 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5291 "0807 Cannot create debugfs InjErrLBA\n");
5294 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5296 snprintf(name, sizeof(name), "InjErrNPortID");
5297 phba->debug_InjErrNPortID =
5298 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5299 phba->hba_debugfs_root,
5300 phba, &lpfc_debugfs_op_dif_err);
5301 if (!phba->debug_InjErrNPortID) {
5302 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5303 "0809 Cannot create debugfs InjErrNPortID\n");
5307 snprintf(name, sizeof(name), "InjErrWWPN");
5308 phba->debug_InjErrWWPN =
5309 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5310 phba->hba_debugfs_root,
5311 phba, &lpfc_debugfs_op_dif_err);
5312 if (!phba->debug_InjErrWWPN) {
5313 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5314 "0810 Cannot create debugfs InjErrWWPN\n");
5318 snprintf(name, sizeof(name), "writeGuardInjErr");
5319 phba->debug_writeGuard =
5320 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5321 phba->hba_debugfs_root,
5322 phba, &lpfc_debugfs_op_dif_err);
5323 if (!phba->debug_writeGuard) {
5324 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5325 "0802 Cannot create debugfs writeGuard\n");
5329 snprintf(name, sizeof(name), "writeAppInjErr");
5330 phba->debug_writeApp =
5331 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5332 phba->hba_debugfs_root,
5333 phba, &lpfc_debugfs_op_dif_err);
5334 if (!phba->debug_writeApp) {
5335 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5336 "0803 Cannot create debugfs writeApp\n");
5340 snprintf(name, sizeof(name), "writeRefInjErr");
5341 phba->debug_writeRef =
5342 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5343 phba->hba_debugfs_root,
5344 phba, &lpfc_debugfs_op_dif_err);
5345 if (!phba->debug_writeRef) {
5346 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5347 "0804 Cannot create debugfs writeRef\n");
5351 snprintf(name, sizeof(name), "readGuardInjErr");
5352 phba->debug_readGuard =
5353 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5354 phba->hba_debugfs_root,
5355 phba, &lpfc_debugfs_op_dif_err);
5356 if (!phba->debug_readGuard) {
5357 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5358 "0808 Cannot create debugfs readGuard\n");
5362 snprintf(name, sizeof(name), "readAppInjErr");
5363 phba->debug_readApp =
5364 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5365 phba->hba_debugfs_root,
5366 phba, &lpfc_debugfs_op_dif_err);
5367 if (!phba->debug_readApp) {
5368 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5369 "0805 Cannot create debugfs readApp\n");
5373 snprintf(name, sizeof(name), "readRefInjErr");
5374 phba->debug_readRef =
5375 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5376 phba->hba_debugfs_root,
5377 phba, &lpfc_debugfs_op_dif_err);
5378 if (!phba->debug_readRef) {
5379 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5380 "0806 Cannot create debugfs readApp\n");
5384 /* Setup slow ring trace */
5385 if (lpfc_debugfs_max_slow_ring_trc) {
5386 num = lpfc_debugfs_max_slow_ring_trc - 1;
5387 if (num & lpfc_debugfs_max_slow_ring_trc) {
5388 /* Change to be a power of 2 */
5389 num = lpfc_debugfs_max_slow_ring_trc;
5395 lpfc_debugfs_max_slow_ring_trc = (1 << i);
5396 pr_err("lpfc_debugfs_max_disc_trc changed to "
5397 "%d\n", lpfc_debugfs_max_disc_trc);
5401 snprintf(name, sizeof(name), "slow_ring_trace");
5402 phba->debug_slow_ring_trc =
5403 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5404 phba->hba_debugfs_root,
5405 phba, &lpfc_debugfs_op_slow_ring_trc);
5406 if (!phba->debug_slow_ring_trc) {
5407 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5408 "0415 Cannot create debugfs "
5409 "slow_ring_trace\n");
5412 if (!phba->slow_ring_trc) {
5413 phba->slow_ring_trc = kmalloc(
5414 (sizeof(struct lpfc_debugfs_trc) *
5415 lpfc_debugfs_max_slow_ring_trc),
5417 if (!phba->slow_ring_trc) {
5418 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5419 "0416 Cannot create debugfs "
5420 "slow_ring buffer\n");
5423 atomic_set(&phba->slow_ring_trc_cnt, 0);
5424 memset(phba->slow_ring_trc, 0,
5425 (sizeof(struct lpfc_debugfs_trc) *
5426 lpfc_debugfs_max_slow_ring_trc));
5429 snprintf(name, sizeof(name), "nvmeio_trc");
5430 phba->debug_nvmeio_trc =
5431 debugfs_create_file(name, 0644,
5432 phba->hba_debugfs_root,
5433 phba, &lpfc_debugfs_op_nvmeio_trc);
5434 if (!phba->debug_nvmeio_trc) {
5435 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5436 "0574 No create debugfs nvmeio_trc\n");
5440 atomic_set(&phba->nvmeio_trc_cnt, 0);
5441 if (lpfc_debugfs_max_nvmeio_trc) {
5442 num = lpfc_debugfs_max_nvmeio_trc - 1;
5443 if (num & lpfc_debugfs_max_disc_trc) {
5444 /* Change to be a power of 2 */
5445 num = lpfc_debugfs_max_nvmeio_trc;
5451 lpfc_debugfs_max_nvmeio_trc = (1 << i);
5452 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5453 "0575 lpfc_debugfs_max_nvmeio_trc "
5455 lpfc_debugfs_max_nvmeio_trc);
5457 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
5459 /* Allocate trace buffer and initialize */
5460 phba->nvmeio_trc = kmalloc(
5461 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5462 phba->nvmeio_trc_size), GFP_KERNEL);
5464 if (!phba->nvmeio_trc) {
5465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5466 "0576 Cannot create debugfs "
5467 "nvmeio_trc buffer\n");
5470 memset(phba->nvmeio_trc, 0,
5471 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5472 phba->nvmeio_trc_size));
5473 phba->nvmeio_trc_on = 1;
5474 phba->nvmeio_trc_output_idx = 0;
5475 phba->nvmeio_trc = NULL;
5478 phba->nvmeio_trc_size = 0;
5479 phba->nvmeio_trc_on = 0;
5480 phba->nvmeio_trc_output_idx = 0;
5481 phba->nvmeio_trc = NULL;
5485 snprintf(name, sizeof(name), "vport%d", vport->vpi);
5486 if (!vport->vport_debugfs_root) {
5487 vport->vport_debugfs_root =
5488 debugfs_create_dir(name, phba->hba_debugfs_root);
5489 if (!vport->vport_debugfs_root) {
5490 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5491 "0417 Can't create debugfs\n");
5494 atomic_inc(&phba->debugfs_vport_count);
5497 if (lpfc_debugfs_max_disc_trc) {
5498 num = lpfc_debugfs_max_disc_trc - 1;
5499 if (num & lpfc_debugfs_max_disc_trc) {
5500 /* Change to be a power of 2 */
5501 num = lpfc_debugfs_max_disc_trc;
5507 lpfc_debugfs_max_disc_trc = (1 << i);
5508 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
5509 lpfc_debugfs_max_disc_trc);
5513 vport->disc_trc = kzalloc(
5514 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
5517 if (!vport->disc_trc) {
5518 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5519 "0418 Cannot create debugfs disc trace "
5523 atomic_set(&vport->disc_trc_cnt, 0);
5525 snprintf(name, sizeof(name), "discovery_trace");
5526 vport->debug_disc_trc =
5527 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5528 vport->vport_debugfs_root,
5529 vport, &lpfc_debugfs_op_disc_trc);
5530 if (!vport->debug_disc_trc) {
5531 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5532 "0419 Cannot create debugfs "
5533 "discovery_trace\n");
5536 snprintf(name, sizeof(name), "nodelist");
5537 vport->debug_nodelist =
5538 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5539 vport->vport_debugfs_root,
5540 vport, &lpfc_debugfs_op_nodelist);
5541 if (!vport->debug_nodelist) {
5542 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5543 "2985 Can't create debugfs nodelist\n");
5547 snprintf(name, sizeof(name), "nvmestat");
5548 vport->debug_nvmestat =
5549 debugfs_create_file(name, 0644,
5550 vport->vport_debugfs_root,
5551 vport, &lpfc_debugfs_op_nvmestat);
5552 if (!vport->debug_nvmestat) {
5553 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5554 "0811 Cannot create debugfs nvmestat\n");
5558 snprintf(name, sizeof(name), "nvmektime");
5559 vport->debug_nvmektime =
5560 debugfs_create_file(name, 0644,
5561 vport->vport_debugfs_root,
5562 vport, &lpfc_debugfs_op_nvmektime);
5563 if (!vport->debug_nvmektime) {
5564 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5565 "0815 Cannot create debugfs nvmektime\n");
5569 snprintf(name, sizeof(name), "cpucheck");
5570 vport->debug_cpucheck =
5571 debugfs_create_file(name, 0644,
5572 vport->vport_debugfs_root,
5573 vport, &lpfc_debugfs_op_cpucheck);
5574 if (!vport->debug_cpucheck) {
5575 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5576 "0819 Cannot create debugfs cpucheck\n");
5581 * The following section is for additional directories/files for the
5589 * iDiag debugfs root entry points for SLI4 device only
5591 if (phba->sli_rev < LPFC_SLI_REV4)
5594 snprintf(name, sizeof(name), "iDiag");
5595 if (!phba->idiag_root) {
5597 debugfs_create_dir(name, phba->hba_debugfs_root);
5598 if (!phba->idiag_root) {
5599 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5600 "2922 Can't create idiag debugfs\n");
5603 /* Initialize iDiag data structure */
5604 memset(&idiag, 0, sizeof(idiag));
5607 /* iDiag read PCI config space */
5608 snprintf(name, sizeof(name), "pciCfg");
5609 if (!phba->idiag_pci_cfg) {
5610 phba->idiag_pci_cfg =
5611 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5612 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
5613 if (!phba->idiag_pci_cfg) {
5614 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5615 "2923 Can't create idiag debugfs\n");
5618 idiag.offset.last_rd = 0;
5621 /* iDiag PCI BAR access */
5622 snprintf(name, sizeof(name), "barAcc");
5623 if (!phba->idiag_bar_acc) {
5624 phba->idiag_bar_acc =
5625 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5626 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
5627 if (!phba->idiag_bar_acc) {
5628 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5629 "3056 Can't create idiag debugfs\n");
5632 idiag.offset.last_rd = 0;
5635 /* iDiag get PCI function queue information */
5636 snprintf(name, sizeof(name), "queInfo");
5637 if (!phba->idiag_que_info) {
5638 phba->idiag_que_info =
5639 debugfs_create_file(name, S_IFREG|S_IRUGO,
5640 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
5641 if (!phba->idiag_que_info) {
5642 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5643 "2924 Can't create idiag debugfs\n");
5648 /* iDiag access PCI function queue */
5649 snprintf(name, sizeof(name), "queAcc");
5650 if (!phba->idiag_que_acc) {
5651 phba->idiag_que_acc =
5652 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5653 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
5654 if (!phba->idiag_que_acc) {
5655 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5656 "2926 Can't create idiag debugfs\n");
5661 /* iDiag access PCI function doorbell registers */
5662 snprintf(name, sizeof(name), "drbAcc");
5663 if (!phba->idiag_drb_acc) {
5664 phba->idiag_drb_acc =
5665 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5666 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
5667 if (!phba->idiag_drb_acc) {
5668 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5669 "2927 Can't create idiag debugfs\n");
5674 /* iDiag access PCI function control registers */
5675 snprintf(name, sizeof(name), "ctlAcc");
5676 if (!phba->idiag_ctl_acc) {
5677 phba->idiag_ctl_acc =
5678 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5679 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
5680 if (!phba->idiag_ctl_acc) {
5681 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5682 "2981 Can't create idiag debugfs\n");
5687 /* iDiag access mbox commands */
5688 snprintf(name, sizeof(name), "mbxAcc");
5689 if (!phba->idiag_mbx_acc) {
5690 phba->idiag_mbx_acc =
5691 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5692 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
5693 if (!phba->idiag_mbx_acc) {
5694 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5695 "2980 Can't create idiag debugfs\n");
5700 /* iDiag extents access commands */
5701 if (phba->sli4_hba.extents_in_use) {
5702 snprintf(name, sizeof(name), "extAcc");
5703 if (!phba->idiag_ext_acc) {
5704 phba->idiag_ext_acc =
5705 debugfs_create_file(name,
5706 S_IFREG|S_IRUGO|S_IWUSR,
5707 phba->idiag_root, phba,
5708 &lpfc_idiag_op_extAcc);
5709 if (!phba->idiag_ext_acc) {
5710 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5724 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
5725 * @vport: The vport pointer to remove from debugfs.
5728 * When Debugfs is configured this routine removes debugfs file system elements
5729 * that are specific to this vport. It also checks to see if there are any
5730 * users left for the debugfs directories associated with the HBA and driver. If
5731 * this is the last user of the HBA directory or driver directory then it will
5732 * remove those from the debugfs infrastructure as well.
5735 lpfc_debugfs_terminate(struct lpfc_vport *vport)
5737 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5738 struct lpfc_hba *phba = vport->phba;
5740 kfree(vport->disc_trc);
5741 vport->disc_trc = NULL;
5743 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
5744 vport->debug_disc_trc = NULL;
5746 debugfs_remove(vport->debug_nodelist); /* nodelist */
5747 vport->debug_nodelist = NULL;
5749 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
5750 vport->debug_nvmestat = NULL;
5752 debugfs_remove(vport->debug_nvmektime); /* nvmektime */
5753 vport->debug_nvmektime = NULL;
5755 debugfs_remove(vport->debug_cpucheck); /* cpucheck */
5756 vport->debug_cpucheck = NULL;
5758 if (vport->vport_debugfs_root) {
5759 debugfs_remove(vport->vport_debugfs_root); /* vportX */
5760 vport->vport_debugfs_root = NULL;
5761 atomic_dec(&phba->debugfs_vport_count);
5764 if (atomic_read(&phba->debugfs_vport_count) == 0) {
5766 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
5767 phba->debug_hbqinfo = NULL;
5769 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
5770 phba->debug_dumpHBASlim = NULL;
5772 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
5773 phba->debug_dumpHostSlim = NULL;
5775 debugfs_remove(phba->debug_dumpData); /* dumpData */
5776 phba->debug_dumpData = NULL;
5778 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
5779 phba->debug_dumpDif = NULL;
5781 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
5782 phba->debug_InjErrLBA = NULL;
5784 debugfs_remove(phba->debug_InjErrNPortID);
5785 phba->debug_InjErrNPortID = NULL;
5787 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
5788 phba->debug_InjErrWWPN = NULL;
5790 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
5791 phba->debug_writeGuard = NULL;
5793 debugfs_remove(phba->debug_writeApp); /* writeApp */
5794 phba->debug_writeApp = NULL;
5796 debugfs_remove(phba->debug_writeRef); /* writeRef */
5797 phba->debug_writeRef = NULL;
5799 debugfs_remove(phba->debug_readGuard); /* readGuard */
5800 phba->debug_readGuard = NULL;
5802 debugfs_remove(phba->debug_readApp); /* readApp */
5803 phba->debug_readApp = NULL;
5805 debugfs_remove(phba->debug_readRef); /* readRef */
5806 phba->debug_readRef = NULL;
5808 kfree(phba->slow_ring_trc);
5809 phba->slow_ring_trc = NULL;
5811 /* slow_ring_trace */
5812 debugfs_remove(phba->debug_slow_ring_trc);
5813 phba->debug_slow_ring_trc = NULL;
5815 debugfs_remove(phba->debug_nvmeio_trc);
5816 phba->debug_nvmeio_trc = NULL;
5818 kfree(phba->nvmeio_trc);
5819 phba->nvmeio_trc = NULL;
5824 if (phba->sli_rev == LPFC_SLI_REV4) {
5826 debugfs_remove(phba->idiag_ext_acc);
5827 phba->idiag_ext_acc = NULL;
5830 debugfs_remove(phba->idiag_mbx_acc);
5831 phba->idiag_mbx_acc = NULL;
5834 debugfs_remove(phba->idiag_ctl_acc);
5835 phba->idiag_ctl_acc = NULL;
5838 debugfs_remove(phba->idiag_drb_acc);
5839 phba->idiag_drb_acc = NULL;
5842 debugfs_remove(phba->idiag_que_acc);
5843 phba->idiag_que_acc = NULL;
5846 debugfs_remove(phba->idiag_que_info);
5847 phba->idiag_que_info = NULL;
5850 debugfs_remove(phba->idiag_bar_acc);
5851 phba->idiag_bar_acc = NULL;
5854 debugfs_remove(phba->idiag_pci_cfg);
5855 phba->idiag_pci_cfg = NULL;
5857 /* Finally remove the iDiag debugfs root */
5858 debugfs_remove(phba->idiag_root);
5859 phba->idiag_root = NULL;
5862 if (phba->hba_debugfs_root) {
5863 debugfs_remove(phba->hba_debugfs_root); /* fnX */
5864 phba->hba_debugfs_root = NULL;
5865 atomic_dec(&lpfc_debugfs_hba_count);
5868 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
5869 debugfs_remove(lpfc_debugfs_root); /* lpfc */
5870 lpfc_debugfs_root = NULL;
5878 * Driver debug utility routines outside of debugfs. The debug utility
5879 * routines implemented here is intended to be used in the instrumented
5880 * debug driver for debugging host or port issues.
5884 * lpfc_debug_dump_all_queues - dump all the queues with a hba
5885 * @phba: Pointer to HBA context object.
5887 * This function dumps entries of all the queues asociated with the @phba.
5890 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
5895 * Dump Work Queues (WQs)
5897 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
5898 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
5899 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
5901 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5902 lpfc_debug_dump_wq(phba, DUMP_FCP, idx);
5904 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5905 lpfc_debug_dump_wq(phba, DUMP_NVME, idx);
5907 lpfc_debug_dump_hdr_rq(phba);
5908 lpfc_debug_dump_dat_rq(phba);
5910 * Dump Complete Queues (CQs)
5912 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
5913 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
5914 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
5916 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5917 lpfc_debug_dump_cq(phba, DUMP_FCP, idx);
5919 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5920 lpfc_debug_dump_cq(phba, DUMP_NVME, idx);
5923 * Dump Event Queues (EQs)
5925 for (idx = 0; idx < phba->io_channel_irqs; idx++)
5926 lpfc_debug_dump_hba_eq(phba, idx);