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 "entrys:%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_nvme_lport *lport;
554 struct lpfc_nvme_rport *rport;
555 struct lpfc_nvmet_tgtport *tgtp;
556 struct nvme_fc_remote_port *nrport;
558 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
560 len += snprintf(buf+len, size-len, "\nFCP Nodelist Entries ...\n");
561 spin_lock_irq(shost->host_lock);
562 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
564 len += snprintf(buf+len, size-len,
565 "Missing Nodelist Entries\n");
569 switch (ndlp->nlp_state) {
570 case NLP_STE_UNUSED_NODE:
573 case NLP_STE_PLOGI_ISSUE:
576 case NLP_STE_ADISC_ISSUE:
579 case NLP_STE_REG_LOGIN_ISSUE:
582 case NLP_STE_PRLI_ISSUE:
585 case NLP_STE_LOGO_ISSUE:
588 case NLP_STE_UNMAPPED_NODE:
591 case NLP_STE_MAPPED_NODE:
594 case NLP_STE_NPR_NODE:
600 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
601 statep, ndlp->nlp_DID);
602 len += snprintf(buf+len, size-len,
604 wwn_to_u64(ndlp->nlp_portname.u.wwn));
605 len += snprintf(buf+len, size-len,
607 wwn_to_u64(ndlp->nlp_nodename.u.wwn));
608 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
609 len += snprintf(buf+len, size-len, "RPI:%03d ",
612 len += snprintf(buf+len, size-len, "RPI:none ");
613 len += snprintf(buf+len, size-len, "flag:x%08x ",
616 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
617 if (ndlp->nlp_type & NLP_FC_NODE)
618 len += snprintf(buf+len, size-len, "FC_NODE ");
619 if (ndlp->nlp_type & NLP_FABRIC)
620 len += snprintf(buf+len, size-len, "FABRIC ");
621 if (ndlp->nlp_type & NLP_FCP_TARGET)
622 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
624 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
625 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
626 len += snprintf(buf+len, size-len, "usgmap:%x ",
628 len += snprintf(buf+len, size-len, "refcnt:%x",
629 kref_read(&ndlp->kref));
630 len += snprintf(buf+len, size-len, "\n");
632 spin_unlock_irq(shost->host_lock);
634 if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
635 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
636 len += snprintf(buf + len, size - len,
637 "\nNVME Targetport Entry ...\n");
639 /* Port state is only one of two values for now. */
640 if (phba->targetport->port_id)
641 statep = "REGISTERED";
644 len += snprintf(buf + len, size - len,
645 "TGT WWNN x%llx WWPN x%llx State %s\n",
646 wwn_to_u64(vport->fc_nodename.u.wwn),
647 wwn_to_u64(vport->fc_portname.u.wwn),
649 len += snprintf(buf + len, size - len,
650 " Targetport DID x%06x\n",
651 phba->targetport->port_id);
655 len += snprintf(buf + len, size - len,
656 "\nNVME Lport/Rport Entries ...\n");
658 localport = vport->localport;
662 spin_lock_irq(shost->host_lock);
663 lport = (struct lpfc_nvme_lport *)localport->private;
665 /* Port state is only one of two values for now. */
666 if (localport->port_id)
671 len += snprintf(buf + len, size - len,
672 "Lport DID x%06x PortState %s\n",
673 localport->port_id, statep);
675 len += snprintf(buf + len, size - len, "\tRport List:\n");
676 list_for_each_entry(rport, &lport->rport_list, list) {
677 /* local short-hand pointer. */
678 nrport = rport->remoteport;
680 /* Port state is only one of two values for now. */
681 switch (nrport->port_state) {
682 case FC_OBJSTATE_ONLINE:
685 case FC_OBJSTATE_UNKNOWN:
689 statep = "UNSUPPORTED";
693 /* Tab in to show lport ownership. */
694 len += snprintf(buf + len, size - len,
695 "\t%s Port ID:x%06x ",
696 statep, nrport->port_id);
697 len += snprintf(buf + len, size - len, "WWPN x%llx ",
699 len += snprintf(buf + len, size - len, "WWNN x%llx ",
701 switch (nrport->port_role) {
702 case FC_PORT_ROLE_NVME_INITIATOR:
703 len += snprintf(buf + len, size - len,
706 case FC_PORT_ROLE_NVME_TARGET:
707 len += snprintf(buf + len, size - len,
710 case FC_PORT_ROLE_NVME_DISCOVERY:
711 len += snprintf(buf + len, size - len,
715 len += snprintf(buf + len, size - len,
721 /* Terminate the string. */
722 len += snprintf(buf + len, size - len, "\n");
725 spin_unlock_irq(shost->host_lock);
731 * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
732 * @vport: The vport to gather target node info from.
733 * @buf: The buffer to dump log into.
734 * @size: The maximum amount of data to process.
737 * This routine dumps the NVME statistics associated with @vport
740 * This routine returns the amount of bytes that were dumped into @buf and will
744 lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
746 struct lpfc_hba *phba = vport->phba;
747 struct lpfc_nvmet_tgtport *tgtp;
748 struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp;
752 if (phba->nvmet_support) {
753 if (!phba->targetport)
755 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
756 len += snprintf(buf + len, size - len,
757 "\nNVME Targetport Statistics\n");
759 len += snprintf(buf + len, size - len,
760 "LS: Rcv %08x Drop %08x Abort %08x\n",
761 atomic_read(&tgtp->rcv_ls_req_in),
762 atomic_read(&tgtp->rcv_ls_req_drop),
763 atomic_read(&tgtp->xmt_ls_abort));
764 if (atomic_read(&tgtp->rcv_ls_req_in) !=
765 atomic_read(&tgtp->rcv_ls_req_out)) {
766 len += snprintf(buf + len, size - len,
767 "Rcv LS: in %08x != out %08x\n",
768 atomic_read(&tgtp->rcv_ls_req_in),
769 atomic_read(&tgtp->rcv_ls_req_out));
772 len += snprintf(buf + len, size - len,
773 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
774 atomic_read(&tgtp->xmt_ls_rsp),
775 atomic_read(&tgtp->xmt_ls_drop),
776 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
777 atomic_read(&tgtp->xmt_ls_rsp_error));
779 len += snprintf(buf + len, size - len,
780 "FCP: Rcv %08x Drop %08x\n",
781 atomic_read(&tgtp->rcv_fcp_cmd_in),
782 atomic_read(&tgtp->rcv_fcp_cmd_drop));
784 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
785 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
786 len += snprintf(buf + len, size - len,
787 "Rcv FCP: in %08x != out %08x\n",
788 atomic_read(&tgtp->rcv_fcp_cmd_in),
789 atomic_read(&tgtp->rcv_fcp_cmd_out));
792 len += snprintf(buf + len, size - len,
793 "FCP Rsp: read %08x readrsp %08x "
794 "write %08x rsp %08x\n",
795 atomic_read(&tgtp->xmt_fcp_read),
796 atomic_read(&tgtp->xmt_fcp_read_rsp),
797 atomic_read(&tgtp->xmt_fcp_write),
798 atomic_read(&tgtp->xmt_fcp_rsp));
800 len += snprintf(buf + len, size - len,
801 "FCP Rsp: abort %08x drop %08x\n",
802 atomic_read(&tgtp->xmt_fcp_abort),
803 atomic_read(&tgtp->xmt_fcp_drop));
805 len += snprintf(buf + len, size - len,
806 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
807 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
808 atomic_read(&tgtp->xmt_fcp_rsp_error),
809 atomic_read(&tgtp->xmt_fcp_rsp_drop));
811 len += snprintf(buf + len, size - len,
812 "ABORT: Xmt %08x Err %08x Cmpl %08x",
813 atomic_read(&tgtp->xmt_abort_rsp),
814 atomic_read(&tgtp->xmt_abort_rsp_error),
815 atomic_read(&tgtp->xmt_abort_cmpl));
817 len += snprintf(buf + len, size - len, "\n");
820 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
821 list_for_each_entry_safe(ctxp, next_ctxp,
822 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
826 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
828 len += snprintf(buf + len, size - len,
829 "ABORT: %d ctx entries\n", cnt);
830 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
831 list_for_each_entry_safe(ctxp, next_ctxp,
832 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
834 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
836 len += snprintf(buf + len, size - len,
837 "Entry: oxid %x state %x "
839 ctxp->oxid, ctxp->state,
842 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
845 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
848 len += snprintf(buf + len, size - len,
849 "\nNVME Lport Statistics\n");
851 len += snprintf(buf + len, size - len,
852 "LS: Xmt %016llx Cmpl %016llx\n",
853 phba->fc4NvmeLsRequests,
854 phba->fc4NvmeLsCmpls);
856 len += snprintf(buf + len, size - len,
857 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
858 phba->fc4NvmeInputRequests,
859 phba->fc4NvmeOutputRequests,
860 phba->fc4NvmeControlRequests);
862 len += snprintf(buf + len, size - len,
863 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
871 * lpfc_debugfs_nvmektime_data - Dump target node list to a buffer
872 * @vport: The vport to gather target node info from.
873 * @buf: The buffer to dump log into.
874 * @size: The maximum amount of data to process.
877 * This routine dumps the NVME statistics associated with @vport
880 * This routine returns the amount of bytes that were dumped into @buf and will
884 lpfc_debugfs_nvmektime_data(struct lpfc_vport *vport, char *buf, int size)
886 struct lpfc_hba *phba = vport->phba;
889 if (phba->nvmet_support == 0) {
891 len += snprintf(buf + len, PAGE_SIZE - len,
892 "ktime %s: Total Samples: %lld\n",
893 (phba->ktime_on ? "Enabled" : "Disabled"),
894 phba->ktime_data_samples);
895 if (phba->ktime_data_samples == 0)
899 buf + len, PAGE_SIZE - len,
900 "Segment 1: Last NVME Cmd cmpl "
901 "done -to- Start of next NVME cnd (in driver)\n");
903 buf + len, PAGE_SIZE - len,
904 "avg:%08lld min:%08lld max %08lld\n",
905 div_u64(phba->ktime_seg1_total,
906 phba->ktime_data_samples),
907 phba->ktime_seg1_min,
908 phba->ktime_seg1_max);
910 buf + len, PAGE_SIZE - len,
911 "Segment 2: Driver start of NVME cmd "
912 "-to- Firmware WQ doorbell\n");
914 buf + len, PAGE_SIZE - len,
915 "avg:%08lld min:%08lld max %08lld\n",
916 div_u64(phba->ktime_seg2_total,
917 phba->ktime_data_samples),
918 phba->ktime_seg2_min,
919 phba->ktime_seg2_max);
921 buf + len, PAGE_SIZE - len,
922 "Segment 3: Firmware WQ doorbell -to- "
925 buf + len, PAGE_SIZE - len,
926 "avg:%08lld min:%08lld max %08lld\n",
927 div_u64(phba->ktime_seg3_total,
928 phba->ktime_data_samples),
929 phba->ktime_seg3_min,
930 phba->ktime_seg3_max);
932 buf + len, PAGE_SIZE - len,
933 "Segment 4: MSI-X ISR cmpl -to- "
936 buf + len, PAGE_SIZE - len,
937 "avg:%08lld min:%08lld max %08lld\n",
938 div_u64(phba->ktime_seg4_total,
939 phba->ktime_data_samples),
940 phba->ktime_seg4_min,
941 phba->ktime_seg4_max);
943 buf + len, PAGE_SIZE - len,
944 "Total IO avg time: %08lld\n",
945 div_u64(phba->ktime_seg1_total +
946 phba->ktime_seg2_total +
947 phba->ktime_seg3_total +
948 phba->ktime_seg4_total,
949 phba->ktime_data_samples));
954 len += snprintf(buf + len, PAGE_SIZE-len,
955 "ktime %s: Total Samples: %lld %lld\n",
956 (phba->ktime_on ? "Enabled" : "Disabled"),
957 phba->ktime_data_samples,
958 phba->ktime_status_samples);
959 if (phba->ktime_data_samples == 0)
962 len += snprintf(buf + len, PAGE_SIZE-len,
963 "Segment 1: MSI-X ISR Rcv cmd -to- "
964 "cmd pass to NVME Layer\n");
965 len += snprintf(buf + len, PAGE_SIZE-len,
966 "avg:%08lld min:%08lld max %08lld\n",
967 div_u64(phba->ktime_seg1_total,
968 phba->ktime_data_samples),
969 phba->ktime_seg1_min,
970 phba->ktime_seg1_max);
971 len += snprintf(buf + len, PAGE_SIZE-len,
972 "Segment 2: cmd pass to NVME Layer- "
973 "-to- Driver rcv cmd OP (action)\n");
974 len += snprintf(buf + len, PAGE_SIZE-len,
975 "avg:%08lld min:%08lld max %08lld\n",
976 div_u64(phba->ktime_seg2_total,
977 phba->ktime_data_samples),
978 phba->ktime_seg2_min,
979 phba->ktime_seg2_max);
980 len += snprintf(buf + len, PAGE_SIZE-len,
981 "Segment 3: Driver rcv cmd OP -to- "
982 "Firmware WQ doorbell: cmd\n");
983 len += snprintf(buf + len, PAGE_SIZE-len,
984 "avg:%08lld min:%08lld max %08lld\n",
985 div_u64(phba->ktime_seg3_total,
986 phba->ktime_data_samples),
987 phba->ktime_seg3_min,
988 phba->ktime_seg3_max);
989 len += snprintf(buf + len, PAGE_SIZE-len,
990 "Segment 4: Firmware WQ doorbell: cmd "
991 "-to- MSI-X ISR for cmd cmpl\n");
992 len += snprintf(buf + len, PAGE_SIZE-len,
993 "avg:%08lld min:%08lld max %08lld\n",
994 div_u64(phba->ktime_seg4_total,
995 phba->ktime_data_samples),
996 phba->ktime_seg4_min,
997 phba->ktime_seg4_max);
998 len += snprintf(buf + len, PAGE_SIZE-len,
999 "Segment 5: MSI-X ISR for cmd cmpl "
1000 "-to- NVME layer passed cmd done\n");
1001 len += snprintf(buf + len, PAGE_SIZE-len,
1002 "avg:%08lld min:%08lld max %08lld\n",
1003 div_u64(phba->ktime_seg5_total,
1004 phba->ktime_data_samples),
1005 phba->ktime_seg5_min,
1006 phba->ktime_seg5_max);
1008 if (phba->ktime_status_samples == 0) {
1009 len += snprintf(buf + len, PAGE_SIZE-len,
1010 "Total: cmd received by MSI-X ISR "
1011 "-to- cmd completed on wire\n");
1012 len += snprintf(buf + len, PAGE_SIZE-len,
1013 "avg:%08lld min:%08lld "
1015 div_u64(phba->ktime_seg10_total,
1016 phba->ktime_data_samples),
1017 phba->ktime_seg10_min,
1018 phba->ktime_seg10_max);
1022 len += snprintf(buf + len, PAGE_SIZE-len,
1023 "Segment 6: NVME layer passed cmd done "
1024 "-to- Driver rcv rsp status OP\n");
1025 len += snprintf(buf + len, PAGE_SIZE-len,
1026 "avg:%08lld min:%08lld max %08lld\n",
1027 div_u64(phba->ktime_seg6_total,
1028 phba->ktime_status_samples),
1029 phba->ktime_seg6_min,
1030 phba->ktime_seg6_max);
1031 len += snprintf(buf + len, PAGE_SIZE-len,
1032 "Segment 7: Driver rcv rsp status OP "
1033 "-to- Firmware WQ doorbell: status\n");
1034 len += snprintf(buf + len, PAGE_SIZE-len,
1035 "avg:%08lld min:%08lld max %08lld\n",
1036 div_u64(phba->ktime_seg7_total,
1037 phba->ktime_status_samples),
1038 phba->ktime_seg7_min,
1039 phba->ktime_seg7_max);
1040 len += snprintf(buf + len, PAGE_SIZE-len,
1041 "Segment 8: Firmware WQ doorbell: status"
1042 " -to- MSI-X ISR for status cmpl\n");
1043 len += snprintf(buf + len, PAGE_SIZE-len,
1044 "avg:%08lld min:%08lld max %08lld\n",
1045 div_u64(phba->ktime_seg8_total,
1046 phba->ktime_status_samples),
1047 phba->ktime_seg8_min,
1048 phba->ktime_seg8_max);
1049 len += snprintf(buf + len, PAGE_SIZE-len,
1050 "Segment 9: MSI-X ISR for status cmpl "
1051 "-to- NVME layer passed status done\n");
1052 len += snprintf(buf + len, PAGE_SIZE-len,
1053 "avg:%08lld min:%08lld max %08lld\n",
1054 div_u64(phba->ktime_seg9_total,
1055 phba->ktime_status_samples),
1056 phba->ktime_seg9_min,
1057 phba->ktime_seg9_max);
1058 len += snprintf(buf + len, PAGE_SIZE-len,
1059 "Total: cmd received by MSI-X ISR -to- "
1060 "cmd completed on wire\n");
1061 len += snprintf(buf + len, PAGE_SIZE-len,
1062 "avg:%08lld min:%08lld max %08lld\n",
1063 div_u64(phba->ktime_seg10_total,
1064 phba->ktime_status_samples),
1065 phba->ktime_seg10_min,
1066 phba->ktime_seg10_max);
1071 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1072 * @phba: The phba to gather target node info from.
1073 * @buf: The buffer to dump log into.
1074 * @size: The maximum amount of data to process.
1077 * This routine dumps the NVME IO trace associated with @phba
1080 * This routine returns the amount of bytes that were dumped into @buf and will
1084 lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1086 struct lpfc_debugfs_nvmeio_trc *dtp;
1087 int i, state, index, skip;
1090 state = phba->nvmeio_trc_on;
1092 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1093 (phba->nvmeio_trc_size - 1);
1094 skip = phba->nvmeio_trc_output_idx;
1096 len += snprintf(buf + len, size - len,
1097 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1098 (phba->nvmet_support ? "NVME" : "NVMET"),
1099 (state ? "Enabled" : "Disabled"),
1100 index, skip, phba->nvmeio_trc_size);
1102 if (!phba->nvmeio_trc || state)
1105 /* trace MUST bhe off to continue */
1107 for (i = index; i < phba->nvmeio_trc_size; i++) {
1112 dtp = phba->nvmeio_trc + i;
1113 phba->nvmeio_trc_output_idx++;
1118 len += snprintf(buf + len, size - len, dtp->fmt,
1119 dtp->data1, dtp->data2, dtp->data3);
1121 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1122 phba->nvmeio_trc_output_idx = 0;
1123 len += snprintf(buf + len, size - len,
1124 "Trace Complete\n");
1128 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1129 len += snprintf(buf + len, size - len,
1130 "Trace Continue (%d of %d)\n",
1131 phba->nvmeio_trc_output_idx,
1132 phba->nvmeio_trc_size);
1136 for (i = 0; i < index; i++) {
1141 dtp = phba->nvmeio_trc + i;
1142 phba->nvmeio_trc_output_idx++;
1147 len += snprintf(buf + len, size - len, dtp->fmt,
1148 dtp->data1, dtp->data2, dtp->data3);
1150 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1151 phba->nvmeio_trc_output_idx = 0;
1152 len += snprintf(buf + len, size - len,
1153 "Trace Complete\n");
1157 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1158 len += snprintf(buf + len, size - len,
1159 "Trace Continue (%d of %d)\n",
1160 phba->nvmeio_trc_output_idx,
1161 phba->nvmeio_trc_size);
1166 len += snprintf(buf + len, size - len,
1173 * lpfc_debugfs_cpucheck_data - Dump target node list to a buffer
1174 * @vport: The vport to gather target node info from.
1175 * @buf: The buffer to dump log into.
1176 * @size: The maximum amount of data to process.
1179 * This routine dumps the NVME statistics associated with @vport
1182 * This routine returns the amount of bytes that were dumped into @buf and will
1186 lpfc_debugfs_cpucheck_data(struct lpfc_vport *vport, char *buf, int size)
1188 struct lpfc_hba *phba = vport->phba;
1191 uint32_t tot_xmt = 0;
1192 uint32_t tot_rcv = 0;
1193 uint32_t tot_cmpl = 0;
1194 uint32_t tot_ccmpl = 0;
1196 if (phba->nvmet_support == 0) {
1197 /* NVME Initiator */
1198 len += snprintf(buf + len, PAGE_SIZE - len,
1200 (phba->cpucheck_on & LPFC_CHECK_NVME_IO ?
1201 "Enabled" : "Disabled"));
1202 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1203 if (i >= LPFC_CHECK_CPU_CNT)
1205 len += snprintf(buf + len, PAGE_SIZE - len,
1206 "%02d: xmit x%08x cmpl x%08x\n",
1207 i, phba->cpucheck_xmt_io[i],
1208 phba->cpucheck_cmpl_io[i]);
1209 tot_xmt += phba->cpucheck_xmt_io[i];
1210 tot_cmpl += phba->cpucheck_cmpl_io[i];
1212 len += snprintf(buf + len, PAGE_SIZE - len,
1213 "tot:xmit x%08x cmpl x%08x\n",
1219 len += snprintf(buf + len, PAGE_SIZE - len,
1221 (phba->cpucheck_on & LPFC_CHECK_NVMET_IO ?
1222 "IO Enabled - " : "IO Disabled - "));
1223 len += snprintf(buf + len, PAGE_SIZE - len,
1225 (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV ?
1226 "Rcv Enabled\n" : "Rcv Disabled\n"));
1227 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1228 if (i >= LPFC_CHECK_CPU_CNT)
1230 len += snprintf(buf + len, PAGE_SIZE - len,
1231 "%02d: xmit x%08x ccmpl x%08x "
1232 "cmpl x%08x rcv x%08x\n",
1233 i, phba->cpucheck_xmt_io[i],
1234 phba->cpucheck_ccmpl_io[i],
1235 phba->cpucheck_cmpl_io[i],
1236 phba->cpucheck_rcv_io[i]);
1237 tot_xmt += phba->cpucheck_xmt_io[i];
1238 tot_rcv += phba->cpucheck_rcv_io[i];
1239 tot_cmpl += phba->cpucheck_cmpl_io[i];
1240 tot_ccmpl += phba->cpucheck_ccmpl_io[i];
1242 len += snprintf(buf + len, PAGE_SIZE - len,
1243 "tot:xmit x%08x ccmpl x%08x cmpl x%08x rcv x%08x\n",
1244 tot_xmt, tot_ccmpl, tot_cmpl, tot_rcv);
1251 * lpfc_debugfs_disc_trc - Store discovery trace log
1252 * @vport: The vport to associate this trace string with for retrieval.
1253 * @mask: Log entry classification.
1254 * @fmt: Format string to be displayed when dumping the log.
1255 * @data1: 1st data parameter to be applied to @fmt.
1256 * @data2: 2nd data parameter to be applied to @fmt.
1257 * @data3: 3rd data parameter to be applied to @fmt.
1260 * This routine is used by the driver code to add a debugfs log entry to the
1261 * discovery trace buffer associated with @vport. Only entries with a @mask that
1262 * match the current debugfs discovery mask will be saved. Entries that do not
1263 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1264 * printf when displaying the log.
1267 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1268 uint32_t data1, uint32_t data2, uint32_t data3)
1270 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1271 struct lpfc_debugfs_trc *dtp;
1274 if (!(lpfc_debugfs_mask_disc_trc & mask))
1277 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1278 !vport || !vport->disc_trc)
1281 index = atomic_inc_return(&vport->disc_trc_cnt) &
1282 (lpfc_debugfs_max_disc_trc - 1);
1283 dtp = vport->disc_trc + index;
1288 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1295 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
1296 * @phba: The phba to associate this trace string with for retrieval.
1297 * @fmt: Format string to be displayed when dumping the log.
1298 * @data1: 1st data parameter to be applied to @fmt.
1299 * @data2: 2nd data parameter to be applied to @fmt.
1300 * @data3: 3rd data parameter to be applied to @fmt.
1303 * This routine is used by the driver code to add a debugfs log entry to the
1304 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1305 * @data3 are used like printf when displaying the log.
1308 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1309 uint32_t data1, uint32_t data2, uint32_t data3)
1311 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1312 struct lpfc_debugfs_trc *dtp;
1315 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1316 !phba || !phba->slow_ring_trc)
1319 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1320 (lpfc_debugfs_max_slow_ring_trc - 1);
1321 dtp = phba->slow_ring_trc + index;
1326 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1333 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1334 * @phba: The phba to associate this trace string with for retrieval.
1335 * @fmt: Format string to be displayed when dumping the log.
1336 * @data1: 1st data parameter to be applied to @fmt.
1337 * @data2: 2nd data parameter to be applied to @fmt.
1338 * @data3: 3rd data parameter to be applied to @fmt.
1341 * This routine is used by the driver code to add a debugfs log entry to the
1342 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1343 * @data3 are used like printf when displaying the log.
1346 lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1347 uint16_t data1, uint16_t data2, uint32_t data3)
1349 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1350 struct lpfc_debugfs_nvmeio_trc *dtp;
1353 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1356 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1357 (phba->nvmeio_trc_size - 1);
1358 dtp = phba->nvmeio_trc + index;
1366 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1368 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
1369 * @inode: The inode pointer that contains a vport pointer.
1370 * @file: The file pointer to attach the log output.
1373 * This routine is the entry point for the debugfs open file operation. It gets
1374 * the vport from the i_private field in @inode, allocates the necessary buffer
1375 * for the log, fills the buffer from the in-memory log for this vport, and then
1376 * returns a pointer to that log in the private_data field in @file.
1379 * This function returns zero if successful. On error it will return a negative
1383 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1385 struct lpfc_vport *vport = inode->i_private;
1386 struct lpfc_debug *debug;
1390 if (!lpfc_debugfs_max_disc_trc) {
1395 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1399 /* Round to page boundary */
1400 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1401 size = PAGE_ALIGN(size);
1403 debug->buffer = kmalloc(size, GFP_KERNEL);
1404 if (!debug->buffer) {
1409 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1410 file->private_data = debug;
1418 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
1419 * @inode: The inode pointer that contains a vport pointer.
1420 * @file: The file pointer to attach the log output.
1423 * This routine is the entry point for the debugfs open file operation. It gets
1424 * the vport from the i_private field in @inode, allocates the necessary buffer
1425 * for the log, fills the buffer from the in-memory log for this vport, and then
1426 * returns a pointer to that log in the private_data field in @file.
1429 * This function returns zero if successful. On error it will return a negative
1433 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1435 struct lpfc_hba *phba = inode->i_private;
1436 struct lpfc_debug *debug;
1440 if (!lpfc_debugfs_max_slow_ring_trc) {
1445 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1449 /* Round to page boundary */
1450 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1451 size = PAGE_ALIGN(size);
1453 debug->buffer = kmalloc(size, GFP_KERNEL);
1454 if (!debug->buffer) {
1459 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
1460 file->private_data = debug;
1468 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
1469 * @inode: The inode pointer that contains a vport pointer.
1470 * @file: The file pointer to attach the log output.
1473 * This routine is the entry point for the debugfs open file operation. It gets
1474 * the vport from the i_private field in @inode, allocates the necessary buffer
1475 * for the log, fills the buffer from the in-memory log for this vport, and then
1476 * returns a pointer to that log in the private_data field in @file.
1479 * This function returns zero if successful. On error it will return a negative
1483 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
1485 struct lpfc_hba *phba = inode->i_private;
1486 struct lpfc_debug *debug;
1489 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1493 /* Round to page boundary */
1494 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
1495 if (!debug->buffer) {
1500 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
1502 file->private_data = debug;
1510 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
1511 * @inode: The inode pointer that contains a vport pointer.
1512 * @file: The file pointer to attach the log output.
1515 * This routine is the entry point for the debugfs open file operation. It gets
1516 * the vport from the i_private field in @inode, allocates the necessary buffer
1517 * for the log, fills the buffer from the in-memory log for this vport, and then
1518 * returns a pointer to that log in the private_data field in @file.
1521 * This function returns zero if successful. On error it will return a negative
1525 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
1527 struct lpfc_hba *phba = inode->i_private;
1528 struct lpfc_debug *debug;
1531 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1535 /* Round to page boundary */
1536 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
1537 if (!debug->buffer) {
1542 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
1543 LPFC_DUMPHBASLIM_SIZE);
1544 file->private_data = debug;
1552 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
1553 * @inode: The inode pointer that contains a vport pointer.
1554 * @file: The file pointer to attach the log output.
1557 * This routine is the entry point for the debugfs open file operation. It gets
1558 * the vport from the i_private field in @inode, allocates the necessary buffer
1559 * for the log, fills the buffer from the in-memory log for this vport, and then
1560 * returns a pointer to that log in the private_data field in @file.
1563 * This function returns zero if successful. On error it will return a negative
1567 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
1569 struct lpfc_hba *phba = inode->i_private;
1570 struct lpfc_debug *debug;
1573 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1577 /* Round to page boundary */
1578 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
1579 if (!debug->buffer) {
1584 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
1585 LPFC_DUMPHOSTSLIM_SIZE);
1586 file->private_data = debug;
1594 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
1596 struct lpfc_debug *debug;
1599 if (!_dump_buf_data)
1602 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1606 /* Round to page boundary */
1607 pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
1608 __func__, _dump_buf_data);
1609 debug->buffer = _dump_buf_data;
1610 if (!debug->buffer) {
1615 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
1616 file->private_data = debug;
1624 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
1626 struct lpfc_debug *debug;
1632 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1636 /* Round to page boundary */
1637 pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n",
1638 __func__, _dump_buf_dif, file);
1639 debug->buffer = _dump_buf_dif;
1640 if (!debug->buffer) {
1645 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
1646 file->private_data = debug;
1654 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
1655 size_t nbytes, loff_t *ppos)
1658 * The Data/DIF buffers only save one failing IO
1659 * The write op is used as a reset mechanism after an IO has
1660 * already been saved to the next one can be saved
1662 spin_lock(&_dump_buf_lock);
1664 memset((void *)_dump_buf_data, 0,
1665 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
1666 memset((void *)_dump_buf_dif, 0,
1667 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
1671 spin_unlock(&_dump_buf_lock);
1677 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1678 size_t nbytes, loff_t *ppos)
1680 struct dentry *dent = file->f_path.dentry;
1681 struct lpfc_hba *phba = file->private_data;
1686 if (dent == phba->debug_writeGuard)
1687 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1688 else if (dent == phba->debug_writeApp)
1689 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
1690 else if (dent == phba->debug_writeRef)
1691 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
1692 else if (dent == phba->debug_readGuard)
1693 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1694 else if (dent == phba->debug_readApp)
1695 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
1696 else if (dent == phba->debug_readRef)
1697 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1698 else if (dent == phba->debug_InjErrNPortID)
1699 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1700 else if (dent == phba->debug_InjErrWWPN) {
1701 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1702 tmp = cpu_to_be64(tmp);
1703 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1704 } else if (dent == phba->debug_InjErrLBA) {
1705 if (phba->lpfc_injerr_lba == (sector_t)(-1))
1706 cnt = snprintf(cbuf, 32, "off\n");
1708 cnt = snprintf(cbuf, 32, "0x%llx\n",
1709 (uint64_t) phba->lpfc_injerr_lba);
1711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1712 "0547 Unknown debugfs error injection entry\n");
1714 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1718 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1719 size_t nbytes, loff_t *ppos)
1721 struct dentry *dent = file->f_path.dentry;
1722 struct lpfc_hba *phba = file->private_data;
1727 memset(dstbuf, 0, 33);
1728 size = (nbytes < 32) ? nbytes : 32;
1729 if (copy_from_user(dstbuf, buf, size))
1732 if (dent == phba->debug_InjErrLBA) {
1733 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1734 tmp = (uint64_t)(-1);
1737 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
1740 if (dent == phba->debug_writeGuard)
1741 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1742 else if (dent == phba->debug_writeApp)
1743 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1744 else if (dent == phba->debug_writeRef)
1745 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1746 else if (dent == phba->debug_readGuard)
1747 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
1748 else if (dent == phba->debug_readApp)
1749 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1750 else if (dent == phba->debug_readRef)
1751 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1752 else if (dent == phba->debug_InjErrLBA)
1753 phba->lpfc_injerr_lba = (sector_t)tmp;
1754 else if (dent == phba->debug_InjErrNPortID)
1755 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1756 else if (dent == phba->debug_InjErrWWPN) {
1757 tmp = cpu_to_be64(tmp);
1758 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1760 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1761 "0548 Unknown debugfs error injection entry\n");
1767 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1773 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1774 * @inode: The inode pointer that contains a vport pointer.
1775 * @file: The file pointer to attach the log output.
1778 * This routine is the entry point for the debugfs open file operation. It gets
1779 * the vport from the i_private field in @inode, allocates the necessary buffer
1780 * for the log, fills the buffer from the in-memory log for this vport, and then
1781 * returns a pointer to that log in the private_data field in @file.
1784 * This function returns zero if successful. On error it will return a negative
1788 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1790 struct lpfc_vport *vport = inode->i_private;
1791 struct lpfc_debug *debug;
1794 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1798 /* Round to page boundary */
1799 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1800 if (!debug->buffer) {
1805 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1806 LPFC_NODELIST_SIZE);
1807 file->private_data = debug;
1815 * lpfc_debugfs_lseek - Seek through a debugfs file
1816 * @file: The file pointer to seek through.
1817 * @off: The offset to seek to or the amount to seek by.
1818 * @whence: Indicates how to seek.
1821 * This routine is the entry point for the debugfs lseek file operation. The
1822 * @whence parameter indicates whether @off is the offset to directly seek to,
1823 * or if it is a value to seek forward or reverse by. This function figures out
1824 * what the new offset of the debugfs file will be and assigns that value to the
1825 * f_pos field of @file.
1828 * This function returns the new offset if successful and returns a negative
1829 * error if unable to process the seek.
1832 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1834 struct lpfc_debug *debug = file->private_data;
1835 return fixed_size_llseek(file, off, whence, debug->len);
1839 * lpfc_debugfs_read - Read a debugfs file
1840 * @file: The file pointer to read from.
1841 * @buf: The buffer to copy the data to.
1842 * @nbytes: The number of bytes to read.
1843 * @ppos: The position in the file to start reading from.
1846 * This routine reads data from from the buffer indicated in the private_data
1847 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1851 * This function returns the amount of data that was read (this could be less
1852 * than @nbytes if the end of the file was reached) or a negative error value.
1855 lpfc_debugfs_read(struct file *file, char __user *buf,
1856 size_t nbytes, loff_t *ppos)
1858 struct lpfc_debug *debug = file->private_data;
1860 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1865 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1866 * @inode: The inode pointer that contains a vport pointer. (unused)
1867 * @file: The file pointer that contains the buffer to release.
1870 * This routine frees the buffer that was allocated when the debugfs file was
1874 * This function returns zero.
1877 lpfc_debugfs_release(struct inode *inode, struct file *file)
1879 struct lpfc_debug *debug = file->private_data;
1881 kfree(debug->buffer);
1888 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1890 struct lpfc_debug *debug = file->private_data;
1892 debug->buffer = NULL;
1900 lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
1902 struct lpfc_vport *vport = inode->i_private;
1903 struct lpfc_debug *debug;
1906 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1910 /* Round to page boundary */
1911 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
1912 if (!debug->buffer) {
1917 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
1918 LPFC_NVMESTAT_SIZE);
1920 debug->i_private = inode->i_private;
1921 file->private_data = debug;
1929 lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
1930 size_t nbytes, loff_t *ppos)
1932 struct lpfc_debug *debug = file->private_data;
1933 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
1934 struct lpfc_hba *phba = vport->phba;
1935 struct lpfc_nvmet_tgtport *tgtp;
1939 if (!phba->targetport)
1945 /* Protect copy from user */
1946 if (!access_ok(VERIFY_READ, buf, nbytes))
1949 memset(mybuf, 0, sizeof(mybuf));
1951 if (copy_from_user(mybuf, buf, nbytes))
1955 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1956 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
1957 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
1958 atomic_set(&tgtp->rcv_ls_req_in, 0);
1959 atomic_set(&tgtp->rcv_ls_req_out, 0);
1960 atomic_set(&tgtp->rcv_ls_req_drop, 0);
1961 atomic_set(&tgtp->xmt_ls_abort, 0);
1962 atomic_set(&tgtp->xmt_ls_rsp, 0);
1963 atomic_set(&tgtp->xmt_ls_drop, 0);
1964 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
1965 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
1967 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
1968 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
1969 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
1970 atomic_set(&tgtp->xmt_fcp_abort, 0);
1971 atomic_set(&tgtp->xmt_fcp_drop, 0);
1972 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
1973 atomic_set(&tgtp->xmt_fcp_read, 0);
1974 atomic_set(&tgtp->xmt_fcp_write, 0);
1975 atomic_set(&tgtp->xmt_fcp_rsp, 0);
1976 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
1977 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
1978 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
1980 atomic_set(&tgtp->xmt_abort_rsp, 0);
1981 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
1982 atomic_set(&tgtp->xmt_abort_cmpl, 0);
1988 lpfc_debugfs_nvmektime_open(struct inode *inode, struct file *file)
1990 struct lpfc_vport *vport = inode->i_private;
1991 struct lpfc_debug *debug;
1994 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1998 /* Round to page boundary */
1999 debug->buffer = kmalloc(LPFC_NVMEKTIME_SIZE, GFP_KERNEL);
2000 if (!debug->buffer) {
2005 debug->len = lpfc_debugfs_nvmektime_data(vport, debug->buffer,
2006 LPFC_NVMEKTIME_SIZE);
2008 debug->i_private = inode->i_private;
2009 file->private_data = debug;
2017 lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf,
2018 size_t nbytes, loff_t *ppos)
2020 struct lpfc_debug *debug = file->private_data;
2021 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2022 struct lpfc_hba *phba = vport->phba;
2029 /* Protect copy from user */
2030 if (!access_ok(VERIFY_READ, buf, nbytes))
2033 memset(mybuf, 0, sizeof(mybuf));
2035 if (copy_from_user(mybuf, buf, nbytes))
2039 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2040 phba->ktime_data_samples = 0;
2041 phba->ktime_status_samples = 0;
2042 phba->ktime_seg1_total = 0;
2043 phba->ktime_seg1_max = 0;
2044 phba->ktime_seg1_min = 0xffffffff;
2045 phba->ktime_seg2_total = 0;
2046 phba->ktime_seg2_max = 0;
2047 phba->ktime_seg2_min = 0xffffffff;
2048 phba->ktime_seg3_total = 0;
2049 phba->ktime_seg3_max = 0;
2050 phba->ktime_seg3_min = 0xffffffff;
2051 phba->ktime_seg4_total = 0;
2052 phba->ktime_seg4_max = 0;
2053 phba->ktime_seg4_min = 0xffffffff;
2054 phba->ktime_seg5_total = 0;
2055 phba->ktime_seg5_max = 0;
2056 phba->ktime_seg5_min = 0xffffffff;
2057 phba->ktime_seg6_total = 0;
2058 phba->ktime_seg6_max = 0;
2059 phba->ktime_seg6_min = 0xffffffff;
2060 phba->ktime_seg7_total = 0;
2061 phba->ktime_seg7_max = 0;
2062 phba->ktime_seg7_min = 0xffffffff;
2063 phba->ktime_seg8_total = 0;
2064 phba->ktime_seg8_max = 0;
2065 phba->ktime_seg8_min = 0xffffffff;
2066 phba->ktime_seg9_total = 0;
2067 phba->ktime_seg9_max = 0;
2068 phba->ktime_seg9_min = 0xffffffff;
2069 phba->ktime_seg10_total = 0;
2070 phba->ktime_seg10_max = 0;
2071 phba->ktime_seg10_min = 0xffffffff;
2074 return strlen(pbuf);
2075 } else if ((strncmp(pbuf, "off",
2076 sizeof("off") - 1) == 0)) {
2078 return strlen(pbuf);
2079 } else if ((strncmp(pbuf, "zero",
2080 sizeof("zero") - 1) == 0)) {
2081 phba->ktime_data_samples = 0;
2082 phba->ktime_status_samples = 0;
2083 phba->ktime_seg1_total = 0;
2084 phba->ktime_seg1_max = 0;
2085 phba->ktime_seg1_min = 0xffffffff;
2086 phba->ktime_seg2_total = 0;
2087 phba->ktime_seg2_max = 0;
2088 phba->ktime_seg2_min = 0xffffffff;
2089 phba->ktime_seg3_total = 0;
2090 phba->ktime_seg3_max = 0;
2091 phba->ktime_seg3_min = 0xffffffff;
2092 phba->ktime_seg4_total = 0;
2093 phba->ktime_seg4_max = 0;
2094 phba->ktime_seg4_min = 0xffffffff;
2095 phba->ktime_seg5_total = 0;
2096 phba->ktime_seg5_max = 0;
2097 phba->ktime_seg5_min = 0xffffffff;
2098 phba->ktime_seg6_total = 0;
2099 phba->ktime_seg6_max = 0;
2100 phba->ktime_seg6_min = 0xffffffff;
2101 phba->ktime_seg7_total = 0;
2102 phba->ktime_seg7_max = 0;
2103 phba->ktime_seg7_min = 0xffffffff;
2104 phba->ktime_seg8_total = 0;
2105 phba->ktime_seg8_max = 0;
2106 phba->ktime_seg8_min = 0xffffffff;
2107 phba->ktime_seg9_total = 0;
2108 phba->ktime_seg9_max = 0;
2109 phba->ktime_seg9_min = 0xffffffff;
2110 phba->ktime_seg10_total = 0;
2111 phba->ktime_seg10_max = 0;
2112 phba->ktime_seg10_min = 0xffffffff;
2113 return strlen(pbuf);
2119 lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2121 struct lpfc_hba *phba = inode->i_private;
2122 struct lpfc_debug *debug;
2125 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2129 /* Round to page boundary */
2130 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2131 if (!debug->buffer) {
2136 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2137 LPFC_NVMEIO_TRC_SIZE);
2139 debug->i_private = inode->i_private;
2140 file->private_data = debug;
2148 lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2149 size_t nbytes, loff_t *ppos)
2151 struct lpfc_debug *debug = file->private_data;
2152 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2161 /* Protect copy from user */
2162 if (!access_ok(VERIFY_READ, buf, nbytes))
2165 memset(mybuf, 0, sizeof(mybuf));
2167 if (copy_from_user(mybuf, buf, nbytes))
2171 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2173 "0570 nvmeio_trc_off\n");
2174 phba->nvmeio_trc_output_idx = 0;
2175 phba->nvmeio_trc_on = 0;
2176 return strlen(pbuf);
2177 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2178 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2179 "0571 nvmeio_trc_on\n");
2180 phba->nvmeio_trc_output_idx = 0;
2181 phba->nvmeio_trc_on = 1;
2182 return strlen(pbuf);
2185 /* We must be off to allocate the trace buffer */
2186 if (phba->nvmeio_trc_on != 0)
2189 /* If not on or off, the parameter is the trace buffer size */
2190 i = kstrtoul(pbuf, 0, &sz);
2193 phba->nvmeio_trc_size = (uint32_t)sz;
2195 /* It must be a power of 2 - round down */
2202 if (phba->nvmeio_trc_size != sz)
2203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2204 "0572 nvmeio_trc_size changed to %ld\n",
2206 phba->nvmeio_trc_size = (uint32_t)sz;
2208 /* If one previously exists, free it */
2209 kfree(phba->nvmeio_trc);
2211 /* Allocate new trace buffer and initialize */
2212 phba->nvmeio_trc = kmalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
2214 if (!phba->nvmeio_trc) {
2215 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2216 "0573 Cannot create debugfs "
2217 "nvmeio_trc buffer\n");
2220 memset(phba->nvmeio_trc, 0,
2221 (sizeof(struct lpfc_debugfs_nvmeio_trc) * sz));
2222 atomic_set(&phba->nvmeio_trc_cnt, 0);
2223 phba->nvmeio_trc_on = 0;
2224 phba->nvmeio_trc_output_idx = 0;
2226 return strlen(pbuf);
2230 lpfc_debugfs_cpucheck_open(struct inode *inode, struct file *file)
2232 struct lpfc_vport *vport = inode->i_private;
2233 struct lpfc_debug *debug;
2236 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2240 /* Round to page boundary */
2241 debug->buffer = kmalloc(LPFC_CPUCHECK_SIZE, GFP_KERNEL);
2242 if (!debug->buffer) {
2247 debug->len = lpfc_debugfs_cpucheck_data(vport, debug->buffer,
2248 LPFC_NVMEKTIME_SIZE);
2250 debug->i_private = inode->i_private;
2251 file->private_data = debug;
2259 lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
2260 size_t nbytes, loff_t *ppos)
2262 struct lpfc_debug *debug = file->private_data;
2263 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2264 struct lpfc_hba *phba = vport->phba;
2272 /* Protect copy from user */
2273 if (!access_ok(VERIFY_READ, buf, nbytes))
2276 memset(mybuf, 0, sizeof(mybuf));
2278 if (copy_from_user(mybuf, buf, nbytes))
2282 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2283 if (phba->nvmet_support)
2284 phba->cpucheck_on |= LPFC_CHECK_NVMET_IO;
2286 phba->cpucheck_on |= LPFC_CHECK_NVME_IO;
2287 return strlen(pbuf);
2288 } else if ((strncmp(pbuf, "rcv",
2289 sizeof("rcv") - 1) == 0)) {
2290 if (phba->nvmet_support)
2291 phba->cpucheck_on |= LPFC_CHECK_NVMET_RCV;
2294 return strlen(pbuf);
2295 } else if ((strncmp(pbuf, "off",
2296 sizeof("off") - 1) == 0)) {
2297 phba->cpucheck_on = LPFC_CHECK_OFF;
2298 return strlen(pbuf);
2299 } else if ((strncmp(pbuf, "zero",
2300 sizeof("zero") - 1) == 0)) {
2301 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
2302 if (i >= LPFC_CHECK_CPU_CNT)
2304 phba->cpucheck_rcv_io[i] = 0;
2305 phba->cpucheck_xmt_io[i] = 0;
2306 phba->cpucheck_cmpl_io[i] = 0;
2307 phba->cpucheck_ccmpl_io[i] = 0;
2309 return strlen(pbuf);
2315 * ---------------------------------
2316 * iDiag debugfs file access methods
2317 * ---------------------------------
2319 * All access methods are through the proper SLI4 PCI function's debugfs
2322 * /sys/kernel/debug/lpfc/fn<#>/iDiag
2326 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
2327 * @buf: The pointer to the user space buffer.
2328 * @nbytes: The number of bytes in the user space buffer.
2329 * @idiag_cmd: pointer to the idiag command struct.
2331 * This routine reads data from debugfs user space buffer and parses the
2332 * buffer for getting the idiag command and arguments. The while space in
2333 * between the set of data is used as the parsing separator.
2335 * This routine returns 0 when successful, it returns proper error code
2336 * back to the user space in error conditions.
2338 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
2339 struct lpfc_idiag_cmd *idiag_cmd)
2342 char *pbuf, *step_str;
2346 /* Protect copy from user */
2347 if (!access_ok(VERIFY_READ, buf, nbytes))
2350 memset(mybuf, 0, sizeof(mybuf));
2351 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
2352 bsize = min(nbytes, (sizeof(mybuf)-1));
2354 if (copy_from_user(mybuf, buf, bsize))
2357 step_str = strsep(&pbuf, "\t ");
2359 /* The opcode must present */
2363 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
2364 if (idiag_cmd->opcode == 0)
2367 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
2368 step_str = strsep(&pbuf, "\t ");
2371 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
2377 * lpfc_idiag_open - idiag open debugfs
2378 * @inode: The inode pointer that contains a pointer to phba.
2379 * @file: The file pointer to attach the file operation.
2382 * This routine is the entry point for the debugfs open file operation. It
2383 * gets the reference to phba from the i_private field in @inode, it then
2384 * allocates buffer for the file operation, performs the necessary PCI config
2385 * space read into the allocated buffer according to the idiag user command
2386 * setup, and then returns a pointer to buffer in the private_data field in
2390 * This function returns zero if successful. On error it will return an
2391 * negative error value.
2394 lpfc_idiag_open(struct inode *inode, struct file *file)
2396 struct lpfc_debug *debug;
2398 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2402 debug->i_private = inode->i_private;
2403 debug->buffer = NULL;
2404 file->private_data = debug;
2410 * lpfc_idiag_release - Release idiag access file operation
2411 * @inode: The inode pointer that contains a vport pointer. (unused)
2412 * @file: The file pointer that contains the buffer to release.
2415 * This routine is the generic release routine for the idiag access file
2416 * operation, it frees the buffer that was allocated when the debugfs file
2420 * This function returns zero.
2423 lpfc_idiag_release(struct inode *inode, struct file *file)
2425 struct lpfc_debug *debug = file->private_data;
2427 /* Free the buffers to the file operation */
2428 kfree(debug->buffer);
2435 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
2436 * @inode: The inode pointer that contains a vport pointer. (unused)
2437 * @file: The file pointer that contains the buffer to release.
2440 * This routine frees the buffer that was allocated when the debugfs file
2441 * was opened. It also reset the fields in the idiag command struct in the
2442 * case of command for write operation.
2445 * This function returns zero.
2448 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
2450 struct lpfc_debug *debug = file->private_data;
2452 if (debug->op == LPFC_IDIAG_OP_WR) {
2453 switch (idiag.cmd.opcode) {
2454 case LPFC_IDIAG_CMD_PCICFG_WR:
2455 case LPFC_IDIAG_CMD_PCICFG_ST:
2456 case LPFC_IDIAG_CMD_PCICFG_CL:
2457 case LPFC_IDIAG_CMD_QUEACC_WR:
2458 case LPFC_IDIAG_CMD_QUEACC_ST:
2459 case LPFC_IDIAG_CMD_QUEACC_CL:
2460 memset(&idiag, 0, sizeof(idiag));
2467 /* Free the buffers to the file operation */
2468 kfree(debug->buffer);
2475 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
2476 * @file: The file pointer to read from.
2477 * @buf: The buffer to copy the data to.
2478 * @nbytes: The number of bytes to read.
2479 * @ppos: The position in the file to start reading from.
2482 * This routine reads data from the @phba pci config space according to the
2483 * idiag command, and copies to user @buf. Depending on the PCI config space
2484 * read command setup, it does either a single register read of a byte
2485 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
2486 * registers from the 4K extended PCI config space.
2489 * This function returns the amount of data that was read (this could be less
2490 * than @nbytes if the end of the file was reached) or a negative error value.
2493 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
2496 struct lpfc_debug *debug = file->private_data;
2497 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2498 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
2501 struct pci_dev *pdev;
2506 pdev = phba->pcidev;
2510 /* This is a user read operation */
2511 debug->op = LPFC_IDIAG_OP_RD;
2514 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
2517 pbuffer = debug->buffer;
2522 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2523 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2524 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2528 /* Read single PCI config space register */
2530 case SIZE_U8: /* byte (8 bits) */
2531 pci_read_config_byte(pdev, where, &u8val);
2532 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2533 "%03x: %02x\n", where, u8val);
2535 case SIZE_U16: /* word (16 bits) */
2536 pci_read_config_word(pdev, where, &u16val);
2537 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2538 "%03x: %04x\n", where, u16val);
2540 case SIZE_U32: /* double word (32 bits) */
2541 pci_read_config_dword(pdev, where, &u32val);
2542 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2543 "%03x: %08x\n", where, u32val);
2545 case LPFC_PCI_CFG_BROWSE: /* browse all */
2553 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2557 /* Browse all PCI config space registers */
2558 offset_label = idiag.offset.last_rd;
2559 offset = offset_label;
2561 /* Read PCI config space */
2562 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2563 "%03x: ", offset_label);
2565 pci_read_config_dword(pdev, offset, &u32val);
2566 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2568 offset += sizeof(uint32_t);
2569 if (offset >= LPFC_PCI_CFG_SIZE) {
2570 len += snprintf(pbuffer+len,
2571 LPFC_PCI_CFG_SIZE-len, "\n");
2574 index -= sizeof(uint32_t);
2576 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2578 else if (!(index % (8 * sizeof(uint32_t)))) {
2579 offset_label += (8 * sizeof(uint32_t));
2580 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2581 "\n%03x: ", offset_label);
2585 /* Set up the offset for next portion of pci cfg read */
2587 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
2588 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
2589 idiag.offset.last_rd = 0;
2591 idiag.offset.last_rd = 0;
2593 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2597 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
2598 * @file: The file pointer to read from.
2599 * @buf: The buffer to copy the user data from.
2600 * @nbytes: The number of bytes to get.
2601 * @ppos: The position in the file to start reading from.
2603 * This routine get the debugfs idiag command struct from user space and
2604 * then perform the syntax check for PCI config space read or write command
2605 * accordingly. In the case of PCI config space read command, it sets up
2606 * the command in the idiag command struct for the debugfs read operation.
2607 * In the case of PCI config space write operation, it executes the write
2608 * operation into the PCI config space accordingly.
2610 * It returns the @nbytges passing in from debugfs user space when successful.
2611 * In case of error conditions, it returns proper error code back to the user
2615 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
2616 size_t nbytes, loff_t *ppos)
2618 struct lpfc_debug *debug = file->private_data;
2619 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2620 uint32_t where, value, count;
2624 struct pci_dev *pdev;
2627 pdev = phba->pcidev;
2631 /* This is a user write operation */
2632 debug->op = LPFC_IDIAG_OP_WR;
2634 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2638 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2639 /* Sanity check on PCI config read command line arguments */
2640 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
2642 /* Read command from PCI config space, set up command fields */
2643 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2644 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2645 if (count == LPFC_PCI_CFG_BROWSE) {
2646 if (where % sizeof(uint32_t))
2648 /* Starting offset to browse */
2649 idiag.offset.last_rd = where;
2650 } else if ((count != sizeof(uint8_t)) &&
2651 (count != sizeof(uint16_t)) &&
2652 (count != sizeof(uint32_t)))
2654 if (count == sizeof(uint8_t)) {
2655 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2657 if (where % sizeof(uint8_t))
2660 if (count == sizeof(uint16_t)) {
2661 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2663 if (where % sizeof(uint16_t))
2666 if (count == sizeof(uint32_t)) {
2667 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2669 if (where % sizeof(uint32_t))
2672 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
2673 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
2674 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2675 /* Sanity check on PCI config write command line arguments */
2676 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
2678 /* Write command to PCI config space, read-modify-write */
2679 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2680 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2681 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
2683 if ((count != sizeof(uint8_t)) &&
2684 (count != sizeof(uint16_t)) &&
2685 (count != sizeof(uint32_t)))
2687 if (count == sizeof(uint8_t)) {
2688 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2690 if (where % sizeof(uint8_t))
2692 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2693 pci_write_config_byte(pdev, where,
2695 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2696 rc = pci_read_config_byte(pdev, where, &u8val);
2698 u8val |= (uint8_t)value;
2699 pci_write_config_byte(pdev, where,
2703 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2704 rc = pci_read_config_byte(pdev, where, &u8val);
2706 u8val &= (uint8_t)(~value);
2707 pci_write_config_byte(pdev, where,
2712 if (count == sizeof(uint16_t)) {
2713 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2715 if (where % sizeof(uint16_t))
2717 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2718 pci_write_config_word(pdev, where,
2720 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2721 rc = pci_read_config_word(pdev, where, &u16val);
2723 u16val |= (uint16_t)value;
2724 pci_write_config_word(pdev, where,
2728 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2729 rc = pci_read_config_word(pdev, where, &u16val);
2731 u16val &= (uint16_t)(~value);
2732 pci_write_config_word(pdev, where,
2737 if (count == sizeof(uint32_t)) {
2738 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2740 if (where % sizeof(uint32_t))
2742 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2743 pci_write_config_dword(pdev, where, value);
2744 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2745 rc = pci_read_config_dword(pdev, where,
2749 pci_write_config_dword(pdev, where,
2753 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2754 rc = pci_read_config_dword(pdev, where,
2758 pci_write_config_dword(pdev, where,
2764 /* All other opecodes are illegal for now */
2769 memset(&idiag, 0, sizeof(idiag));
2774 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
2775 * @file: The file pointer to read from.
2776 * @buf: The buffer to copy the data to.
2777 * @nbytes: The number of bytes to read.
2778 * @ppos: The position in the file to start reading from.
2781 * This routine reads data from the @phba pci bar memory mapped space
2782 * according to the idiag command, and copies to user @buf.
2785 * This function returns the amount of data that was read (this could be less
2786 * than @nbytes if the end of the file was reached) or a negative error value.
2789 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
2792 struct lpfc_debug *debug = file->private_data;
2793 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2794 int offset_label, offset, offset_run, len = 0, index;
2795 int bar_num, acc_range, bar_size;
2797 void __iomem *mem_mapped_bar;
2799 struct pci_dev *pdev;
2802 pdev = phba->pcidev;
2806 /* This is a user read operation */
2807 debug->op = LPFC_IDIAG_OP_RD;
2810 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
2813 pbuffer = debug->buffer;
2818 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
2819 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2820 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
2821 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
2822 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
2829 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2830 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2831 if (bar_num == IDIAG_BARACC_BAR_0)
2832 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2833 else if (bar_num == IDIAG_BARACC_BAR_1)
2834 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2835 else if (bar_num == IDIAG_BARACC_BAR_2)
2836 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2839 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2840 if (bar_num == IDIAG_BARACC_BAR_0)
2841 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2847 /* Read single PCI bar space register */
2848 if (acc_range == SINGLE_WORD) {
2849 offset_run = offset;
2850 u32val = readl(mem_mapped_bar + offset_run);
2851 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2852 "%05x: %08x\n", offset_run, u32val);
2856 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2860 /* Browse all PCI bar space registers */
2861 offset_label = idiag.offset.last_rd;
2862 offset_run = offset_label;
2864 /* Read PCI bar memory mapped space */
2865 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2866 "%05x: ", offset_label);
2867 index = LPFC_PCI_BAR_RD_SIZE;
2869 u32val = readl(mem_mapped_bar + offset_run);
2870 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2872 offset_run += sizeof(uint32_t);
2873 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2874 if (offset_run >= bar_size) {
2875 len += snprintf(pbuffer+len,
2876 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2880 if (offset_run >= offset +
2881 (acc_range * sizeof(uint32_t))) {
2882 len += snprintf(pbuffer+len,
2883 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2887 index -= sizeof(uint32_t);
2889 len += snprintf(pbuffer+len,
2890 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2891 else if (!(index % (8 * sizeof(uint32_t)))) {
2892 offset_label += (8 * sizeof(uint32_t));
2893 len += snprintf(pbuffer+len,
2894 LPFC_PCI_BAR_RD_BUF_SIZE-len,
2895 "\n%05x: ", offset_label);
2899 /* Set up the offset for next portion of pci bar read */
2901 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
2902 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2903 if (idiag.offset.last_rd >= bar_size)
2904 idiag.offset.last_rd = 0;
2906 if (offset_run >= offset +
2907 (acc_range * sizeof(uint32_t)))
2908 idiag.offset.last_rd = offset;
2911 if (acc_range == LPFC_PCI_BAR_BROWSE)
2912 idiag.offset.last_rd = 0;
2914 idiag.offset.last_rd = offset;
2917 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2921 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
2922 * @file: The file pointer to read from.
2923 * @buf: The buffer to copy the user data from.
2924 * @nbytes: The number of bytes to get.
2925 * @ppos: The position in the file to start reading from.
2927 * This routine get the debugfs idiag command struct from user space and
2928 * then perform the syntax check for PCI bar memory mapped space read or
2929 * write command accordingly. In the case of PCI bar memory mapped space
2930 * read command, it sets up the command in the idiag command struct for
2931 * the debugfs read operation. In the case of PCI bar memorpy mapped space
2932 * write operation, it executes the write operation into the PCI bar memory
2933 * mapped space accordingly.
2935 * It returns the @nbytges passing in from debugfs user space when successful.
2936 * In case of error conditions, it returns proper error code back to the user
2940 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
2941 size_t nbytes, loff_t *ppos)
2943 struct lpfc_debug *debug = file->private_data;
2944 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2945 uint32_t bar_num, bar_size, offset, value, acc_range;
2946 struct pci_dev *pdev;
2947 void __iomem *mem_mapped_bar;
2952 pdev = phba->pcidev;
2956 /* This is a user write operation */
2957 debug->op = LPFC_IDIAG_OP_WR;
2959 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2963 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2964 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2966 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2967 if ((bar_num != IDIAG_BARACC_BAR_0) &&
2968 (bar_num != IDIAG_BARACC_BAR_1) &&
2969 (bar_num != IDIAG_BARACC_BAR_2))
2971 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2972 if (bar_num != IDIAG_BARACC_BAR_0)
2977 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2978 if (bar_num == IDIAG_BARACC_BAR_0) {
2979 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2980 LPFC_PCI_IF0_BAR0_SIZE;
2981 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2982 } else if (bar_num == IDIAG_BARACC_BAR_1) {
2983 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2984 LPFC_PCI_IF0_BAR1_SIZE;
2985 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2986 } else if (bar_num == IDIAG_BARACC_BAR_2) {
2987 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2988 LPFC_PCI_IF0_BAR2_SIZE;
2989 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2992 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2993 if (bar_num == IDIAG_BARACC_BAR_0) {
2994 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2995 LPFC_PCI_IF2_BAR0_SIZE;
2996 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3002 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3003 if (offset % sizeof(uint32_t))
3006 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3007 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3008 /* Sanity check on PCI config read command line arguments */
3009 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3011 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3012 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3013 if (offset > bar_size - sizeof(uint32_t))
3015 /* Starting offset to browse */
3016 idiag.offset.last_rd = offset;
3017 } else if (acc_range > SINGLE_WORD) {
3018 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3020 /* Starting offset to browse */
3021 idiag.offset.last_rd = offset;
3022 } else if (acc_range != SINGLE_WORD)
3024 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3025 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3026 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3027 /* Sanity check on PCI bar write command line arguments */
3028 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3030 /* Write command to PCI bar space, read-modify-write */
3031 acc_range = SINGLE_WORD;
3032 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3033 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3034 writel(value, mem_mapped_bar + offset);
3035 readl(mem_mapped_bar + offset);
3037 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3038 u32val = readl(mem_mapped_bar + offset);
3040 writel(u32val, mem_mapped_bar + offset);
3041 readl(mem_mapped_bar + offset);
3043 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3044 u32val = readl(mem_mapped_bar + offset);
3046 writel(u32val, mem_mapped_bar + offset);
3047 readl(mem_mapped_bar + offset);
3050 /* All other opecodes are illegal for now */
3055 memset(&idiag, 0, sizeof(idiag));
3060 __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3061 char *pbuffer, int len)
3066 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3067 "\t\t%s WQ info: ", wqtype);
3068 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3069 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3070 qp->assoc_qid, qp->q_cnt_1,
3071 (unsigned long long)qp->q_cnt_4);
3072 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3073 "\t\tWQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3074 "HOST-IDX[%04d], PORT-IDX[%04d]",
3075 qp->queue_id, qp->entry_count,
3076 qp->entry_size, qp->host_index,
3078 len += snprintf(pbuffer + len,
3079 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3084 lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3085 int *len, int max_cnt, int cq_id)
3087 struct lpfc_queue *qp;
3090 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3091 qp = phba->sli4_hba.fcp_wq[qidx];
3092 if (qp->assoc_qid != cq_id)
3094 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3095 if (*len >= max_cnt)
3098 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3099 qp = phba->sli4_hba.nvme_wq[qidx];
3100 if (qp->assoc_qid != cq_id)
3102 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3103 if (*len >= max_cnt)
3110 __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3111 char *pbuffer, int len)
3116 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3117 "\t%s CQ info: ", cqtype);
3118 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3119 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3120 "xabt:x%x wq:x%llx]\n",
3121 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3122 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3123 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3124 "\tCQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3125 "HOST-IDX[%04d], PORT-IDX[%04d]",
3126 qp->queue_id, qp->entry_count,
3127 qp->entry_size, qp->host_index,
3130 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3136 __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3137 char *rqtype, char *pbuffer, int len)
3142 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3143 "\t\t%s RQ info: ", rqtype);
3144 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3145 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
3146 "trunc:x%x rcv:x%llx]\n",
3147 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3148 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3149 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3150 "\t\tHQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3151 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
3152 qp->queue_id, qp->entry_count, qp->entry_size,
3153 qp->host_index, qp->hba_index);
3154 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3155 "\t\tDQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3156 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
3157 datqp->queue_id, datqp->entry_count,
3158 datqp->entry_size, datqp->host_index,
3164 lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
3165 int *len, int max_cnt, int eqidx, int eq_id)
3167 struct lpfc_queue *qp;
3170 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3171 qp = phba->sli4_hba.fcp_cq[qidx];
3172 if (qp->assoc_qid != eq_id)
3175 *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
3177 /* Reset max counter */
3180 if (*len >= max_cnt)
3183 rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
3184 max_cnt, qp->queue_id);
3189 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3190 qp = phba->sli4_hba.nvme_cq[qidx];
3191 if (qp->assoc_qid != eq_id)
3194 *len = __lpfc_idiag_print_cq(qp, "NVME", pbuffer, *len);
3196 /* Reset max counter */
3199 if (*len >= max_cnt)
3202 rc = lpfc_idiag_wqs_for_cq(phba, "NVME", pbuffer, len,
3203 max_cnt, qp->queue_id);
3208 if (eqidx < phba->cfg_nvmet_mrq) {
3210 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3211 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3213 /* Reset max counter */
3216 if (*len >= max_cnt)
3220 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3221 *len = __lpfc_idiag_print_rqpair(qp,
3222 phba->sli4_hba.nvmet_mrq_data[eqidx],
3223 "NVMET MRQ", pbuffer, *len);
3225 if (*len >= max_cnt)
3233 __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
3234 char *pbuffer, int len)
3239 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3240 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
3241 "bs:x%x proc:x%llx]\n",
3242 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
3243 (unsigned long long)qp->q_cnt_4);
3244 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3245 "EQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3246 "HOST-IDX[%04d], PORT-IDX[%04d]",
3247 qp->queue_id, qp->entry_count, qp->entry_size,
3248 qp->host_index, qp->hba_index);
3249 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3255 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
3256 * @file: The file pointer to read from.
3257 * @buf: The buffer to copy the data to.
3258 * @nbytes: The number of bytes to read.
3259 * @ppos: The position in the file to start reading from.
3262 * This routine reads data from the @phba SLI4 PCI function queue information,
3263 * and copies to user @buf.
3264 * This routine only returns 1 EQs worth of information. It remembers the last
3265 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
3266 * retrieve all EQs allocated for the phba.
3269 * This function returns the amount of data that was read (this could be less
3270 * than @nbytes if the end of the file was reached) or a negative error value.
3273 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
3276 struct lpfc_debug *debug = file->private_data;
3277 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3279 int max_cnt, rc, x, len = 0;
3280 struct lpfc_queue *qp = NULL;
3283 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
3286 pbuffer = debug->buffer;
3287 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
3292 spin_lock_irq(&phba->hbalock);
3294 /* Fast-path event queue */
3295 if (phba->sli4_hba.hba_eq && phba->io_channel_irqs) {
3297 x = phba->lpfc_idiag_last_eq;
3298 if (phba->cfg_fof && (x >= phba->io_channel_irqs)) {
3299 phba->lpfc_idiag_last_eq = 0;
3302 phba->lpfc_idiag_last_eq++;
3303 if (phba->lpfc_idiag_last_eq >= phba->io_channel_irqs)
3304 if (phba->cfg_fof == 0)
3305 phba->lpfc_idiag_last_eq = 0;
3307 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3308 "EQ %d out of %d HBA EQs\n",
3309 x, phba->io_channel_irqs);
3312 qp = phba->sli4_hba.hba_eq[x];
3316 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
3318 /* Reset max counter */
3324 /* will dump both fcp and nvme cqs/wqs for the eq */
3325 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
3326 max_cnt, x, qp->queue_id);
3330 /* Only EQ 0 has slow path CQs configured */
3334 /* Slow-path mailbox CQ */
3335 qp = phba->sli4_hba.mbx_cq;
3336 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
3340 /* Slow-path MBOX MQ */
3341 qp = phba->sli4_hba.mbx_wq;
3342 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
3346 /* Slow-path ELS response CQ */
3347 qp = phba->sli4_hba.els_cq;
3348 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
3349 /* Reset max counter */
3355 /* Slow-path ELS WQ */
3356 qp = phba->sli4_hba.els_wq;
3357 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
3361 /* Slow-path NVME LS response CQ */
3362 qp = phba->sli4_hba.nvmels_cq;
3363 len = __lpfc_idiag_print_cq(qp, "NVME LS",
3365 /* Reset max counter */
3371 /* Slow-path NVME LS WQ */
3372 qp = phba->sli4_hba.nvmels_wq;
3373 len = __lpfc_idiag_print_wq(qp, "NVME LS",
3378 qp = phba->sli4_hba.hdr_rq;
3379 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
3380 "RQpair", pbuffer, len);
3388 if (phba->cfg_fof) {
3390 qp = phba->sli4_hba.fof_eq;
3391 len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
3393 /* Reset max counter */
3401 qp = phba->sli4_hba.oas_cq;
3402 len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
3403 /* Reset max counter */
3410 qp = phba->sli4_hba.oas_wq;
3411 len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
3416 spin_unlock_irq(&phba->hbalock);
3417 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3420 len += snprintf(pbuffer + len,
3421 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
3423 spin_unlock_irq(&phba->hbalock);
3424 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3428 * lpfc_idiag_que_param_check - queue access command parameter sanity check
3429 * @q: The pointer to queue structure.
3430 * @index: The index into a queue entry.
3431 * @count: The number of queue entries to access.
3434 * The routine performs sanity check on device queue access method commands.
3437 * This function returns -EINVAL when fails the sanity check, otherwise, it
3441 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
3443 /* Only support single entry read or browsing */
3444 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
3446 if (index > q->entry_count - 1)
3452 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
3453 * @pbuffer: The pointer to buffer to copy the read data into.
3454 * @pque: The pointer to the queue to be read.
3455 * @index: The index into the queue entry.
3458 * This routine reads out a single entry from the given queue's index location
3459 * and copies it into the buffer provided.
3462 * This function returns 0 when it fails, otherwise, it returns the length of
3463 * the data read into the buffer provided.
3466 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
3472 if (!pbuffer || !pque)
3475 esize = pque->entry_size;
3476 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3477 "QE-INDEX[%04d]:\n", index);
3480 pentry = pque->qe[index].address;
3482 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3485 offset += sizeof(uint32_t);
3486 esize -= sizeof(uint32_t);
3487 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
3488 len += snprintf(pbuffer+len,
3489 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3491 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3497 * lpfc_idiag_queacc_read - idiag debugfs read port queue
3498 * @file: The file pointer to read from.
3499 * @buf: The buffer to copy the data to.
3500 * @nbytes: The number of bytes to read.
3501 * @ppos: The position in the file to start reading from.
3504 * This routine reads data from the @phba device queue memory according to the
3505 * idiag command, and copies to user @buf. Depending on the queue dump read
3506 * command setup, it does either a single queue entry read or browing through
3507 * all entries of the queue.
3510 * This function returns the amount of data that was read (this could be less
3511 * than @nbytes if the end of the file was reached) or a negative error value.
3514 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
3517 struct lpfc_debug *debug = file->private_data;
3518 uint32_t last_index, index, count;
3519 struct lpfc_queue *pque = NULL;
3523 /* This is a user read operation */
3524 debug->op = LPFC_IDIAG_OP_RD;
3527 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
3530 pbuffer = debug->buffer;
3535 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3536 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3537 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3538 pque = (struct lpfc_queue *)idiag.ptr_private;
3542 /* Browse the queue starting from index */
3543 if (count == LPFC_QUE_ACC_BROWSE)
3546 /* Read a single entry from the queue */
3547 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3549 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3553 /* Browse all entries from the queue */
3554 last_index = idiag.offset.last_rd;
3557 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
3558 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3560 if (index > pque->entry_count - 1)
3564 /* Set up the offset for next portion of pci cfg read */
3565 if (index > pque->entry_count - 1)
3567 idiag.offset.last_rd = index;
3569 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3573 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
3574 * @file: The file pointer to read from.
3575 * @buf: The buffer to copy the user data from.
3576 * @nbytes: The number of bytes to get.
3577 * @ppos: The position in the file to start reading from.
3579 * This routine get the debugfs idiag command struct from user space and then
3580 * perform the syntax check for port queue read (dump) or write (set) command
3581 * accordingly. In the case of port queue read command, it sets up the command
3582 * in the idiag command struct for the following debugfs read operation. In
3583 * the case of port queue write operation, it executes the write operation
3584 * into the port queue entry accordingly.
3586 * It returns the @nbytges passing in from debugfs user space when successful.
3587 * In case of error conditions, it returns proper error code back to the user
3591 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3592 size_t nbytes, loff_t *ppos)
3594 struct lpfc_debug *debug = file->private_data;
3595 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3596 uint32_t qidx, quetp, queid, index, count, offset, value;
3598 struct lpfc_queue *pque, *qp;
3601 /* This is a user write operation */
3602 debug->op = LPFC_IDIAG_OP_WR;
3604 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3608 /* Get and sanity check on command feilds */
3609 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
3610 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
3611 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3612 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3613 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
3614 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
3616 /* Sanity check on command line arguments */
3617 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3618 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3619 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3620 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
3624 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3625 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
3632 /* HBA event queue */
3633 if (phba->sli4_hba.hba_eq) {
3634 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
3635 qp = phba->sli4_hba.hba_eq[qidx];
3636 if (qp && qp->queue_id == queid) {
3638 rc = lpfc_idiag_que_param_check(qp,
3642 idiag.ptr_private = qp;
3650 /* MBX complete queue */
3651 if (phba->sli4_hba.mbx_cq &&
3652 phba->sli4_hba.mbx_cq->queue_id == queid) {
3654 rc = lpfc_idiag_que_param_check(
3655 phba->sli4_hba.mbx_cq, index, count);
3658 idiag.ptr_private = phba->sli4_hba.mbx_cq;
3661 /* ELS complete queue */
3662 if (phba->sli4_hba.els_cq &&
3663 phba->sli4_hba.els_cq->queue_id == queid) {
3665 rc = lpfc_idiag_que_param_check(
3666 phba->sli4_hba.els_cq, index, count);
3669 idiag.ptr_private = phba->sli4_hba.els_cq;
3672 /* NVME LS complete queue */
3673 if (phba->sli4_hba.nvmels_cq &&
3674 phba->sli4_hba.nvmels_cq->queue_id == queid) {
3676 rc = lpfc_idiag_que_param_check(
3677 phba->sli4_hba.nvmels_cq, index, count);
3680 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3683 /* FCP complete queue */
3684 if (phba->sli4_hba.fcp_cq) {
3685 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3687 qp = phba->sli4_hba.fcp_cq[qidx];
3688 if (qp && qp->queue_id == queid) {
3690 rc = lpfc_idiag_que_param_check(
3694 idiag.ptr_private = qp;
3699 /* NVME complete queue */
3700 if (phba->sli4_hba.nvme_cq) {
3703 if (phba->sli4_hba.nvme_cq[qidx] &&
3704 phba->sli4_hba.nvme_cq[qidx]->queue_id ==
3707 rc = lpfc_idiag_que_param_check(
3708 phba->sli4_hba.nvme_cq[qidx],
3713 phba->sli4_hba.nvme_cq[qidx];
3716 } while (++qidx < phba->cfg_nvme_io_channel);
3721 /* MBX work queue */
3722 if (phba->sli4_hba.mbx_wq &&
3723 phba->sli4_hba.mbx_wq->queue_id == queid) {
3725 rc = lpfc_idiag_que_param_check(
3726 phba->sli4_hba.mbx_wq, index, count);
3729 idiag.ptr_private = phba->sli4_hba.mbx_wq;
3735 /* ELS work queue */
3736 if (phba->sli4_hba.els_wq &&
3737 phba->sli4_hba.els_wq->queue_id == queid) {
3739 rc = lpfc_idiag_que_param_check(
3740 phba->sli4_hba.els_wq, index, count);
3743 idiag.ptr_private = phba->sli4_hba.els_wq;
3746 /* NVME LS work queue */
3747 if (phba->sli4_hba.nvmels_wq &&
3748 phba->sli4_hba.nvmels_wq->queue_id == queid) {
3750 rc = lpfc_idiag_que_param_check(
3751 phba->sli4_hba.nvmels_wq, index, count);
3754 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3757 /* FCP work queue */
3758 if (phba->sli4_hba.fcp_wq) {
3759 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3761 qp = phba->sli4_hba.fcp_wq[qidx];
3762 if (qp && qp->queue_id == queid) {
3764 rc = lpfc_idiag_que_param_check(
3768 idiag.ptr_private = qp;
3773 /* NVME work queue */
3774 if (phba->sli4_hba.nvme_wq) {
3775 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3777 qp = phba->sli4_hba.nvme_wq[qidx];
3778 if (qp && qp->queue_id == queid) {
3780 rc = lpfc_idiag_que_param_check(
3784 idiag.ptr_private = qp;
3790 /* NVME work queues */
3791 if (phba->sli4_hba.nvme_wq) {
3792 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3794 if (!phba->sli4_hba.nvme_wq[qidx])
3796 if (phba->sli4_hba.nvme_wq[qidx]->queue_id ==
3799 rc = lpfc_idiag_que_param_check(
3800 phba->sli4_hba.nvme_wq[qidx],
3805 phba->sli4_hba.nvme_wq[qidx];
3814 if (phba->sli4_hba.hdr_rq &&
3815 phba->sli4_hba.hdr_rq->queue_id == queid) {
3817 rc = lpfc_idiag_que_param_check(
3818 phba->sli4_hba.hdr_rq, index, count);
3821 idiag.ptr_private = phba->sli4_hba.hdr_rq;
3825 if (phba->sli4_hba.dat_rq &&
3826 phba->sli4_hba.dat_rq->queue_id == queid) {
3828 rc = lpfc_idiag_que_param_check(
3829 phba->sli4_hba.dat_rq, index, count);
3832 idiag.ptr_private = phba->sli4_hba.dat_rq;
3844 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3845 if (count == LPFC_QUE_ACC_BROWSE)
3846 idiag.offset.last_rd = index;
3849 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3850 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3851 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3852 /* Additional sanity checks on write operation */
3853 pque = (struct lpfc_queue *)idiag.ptr_private;
3854 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
3856 pentry = pque->qe[index].address;
3858 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
3860 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
3862 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
3868 /* Clean out command structure on command error out */
3869 memset(&idiag, 0, sizeof(idiag));
3874 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
3875 * @phba: The pointer to hba structure.
3876 * @pbuffer: The pointer to the buffer to copy the data to.
3877 * @len: The lenght of bytes to copied.
3878 * @drbregid: The id to doorbell registers.
3881 * This routine reads a doorbell register and copies its content to the
3882 * user buffer pointed to by @pbuffer.
3885 * This function returns the amount of data that was copied into @pbuffer.
3888 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
3889 int len, uint32_t drbregid)
3897 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3898 "EQCQ-DRB-REG: 0x%08x\n",
3899 readl(phba->sli4_hba.EQCQDBregaddr));
3902 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3903 "MQ-DRB-REG: 0x%08x\n",
3904 readl(phba->sli4_hba.MQDBregaddr));
3907 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3908 "WQ-DRB-REG: 0x%08x\n",
3909 readl(phba->sli4_hba.WQDBregaddr));
3912 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3913 "RQ-DRB-REG: 0x%08x\n",
3914 readl(phba->sli4_hba.RQDBregaddr));
3924 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
3925 * @file: The file pointer to read from.
3926 * @buf: The buffer to copy the data to.
3927 * @nbytes: The number of bytes to read.
3928 * @ppos: The position in the file to start reading from.
3931 * This routine reads data from the @phba device doorbell register according
3932 * to the idiag command, and copies to user @buf. Depending on the doorbell
3933 * register read command setup, it does either a single doorbell register
3934 * read or dump all doorbell registers.
3937 * This function returns the amount of data that was read (this could be less
3938 * than @nbytes if the end of the file was reached) or a negative error value.
3941 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
3944 struct lpfc_debug *debug = file->private_data;
3945 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3946 uint32_t drb_reg_id, i;
3950 /* This is a user read operation */
3951 debug->op = LPFC_IDIAG_OP_RD;
3954 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
3957 pbuffer = debug->buffer;
3962 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
3963 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
3967 if (drb_reg_id == LPFC_DRB_ACC_ALL)
3968 for (i = 1; i <= LPFC_DRB_MAX; i++)
3969 len = lpfc_idiag_drbacc_read_reg(phba,
3972 len = lpfc_idiag_drbacc_read_reg(phba,
3973 pbuffer, len, drb_reg_id);
3975 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3979 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
3980 * @file: The file pointer to read from.
3981 * @buf: The buffer to copy the user data from.
3982 * @nbytes: The number of bytes to get.
3983 * @ppos: The position in the file to start reading from.
3985 * This routine get the debugfs idiag command struct from user space and then
3986 * perform the syntax check for port doorbell register read (dump) or write
3987 * (set) command accordingly. In the case of port queue read command, it sets
3988 * up the command in the idiag command struct for the following debugfs read
3989 * operation. In the case of port doorbell register write operation, it
3990 * executes the write operation into the port doorbell register accordingly.
3992 * It returns the @nbytges passing in from debugfs user space when successful.
3993 * In case of error conditions, it returns proper error code back to the user
3997 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
3998 size_t nbytes, loff_t *ppos)
4000 struct lpfc_debug *debug = file->private_data;
4001 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4002 uint32_t drb_reg_id, value, reg_val = 0;
4003 void __iomem *drb_reg;
4006 /* This is a user write operation */
4007 debug->op = LPFC_IDIAG_OP_WR;
4009 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4013 /* Sanity check on command line arguments */
4014 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4015 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
4017 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4018 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4019 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4020 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4022 if (drb_reg_id > LPFC_DRB_MAX)
4024 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4025 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4027 if ((drb_reg_id > LPFC_DRB_MAX) &&
4028 (drb_reg_id != LPFC_DRB_ACC_ALL))
4033 /* Perform the write access operation */
4034 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4035 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4036 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4037 switch (drb_reg_id) {
4039 drb_reg = phba->sli4_hba.EQCQDBregaddr;
4042 drb_reg = phba->sli4_hba.MQDBregaddr;
4045 drb_reg = phba->sli4_hba.WQDBregaddr;
4048 drb_reg = phba->sli4_hba.RQDBregaddr;
4054 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4056 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4057 reg_val = readl(drb_reg);
4060 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4061 reg_val = readl(drb_reg);
4064 writel(reg_val, drb_reg);
4065 readl(drb_reg); /* flush */
4070 /* Clean out command structure on command error out */
4071 memset(&idiag, 0, sizeof(idiag));
4076 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4077 * @phba: The pointer to hba structure.
4078 * @pbuffer: The pointer to the buffer to copy the data to.
4079 * @len: The lenght of bytes to copied.
4080 * @drbregid: The id to doorbell registers.
4083 * This routine reads a control register and copies its content to the
4084 * user buffer pointed to by @pbuffer.
4087 * This function returns the amount of data that was copied into @pbuffer.
4090 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4091 int len, uint32_t ctlregid)
4098 case LPFC_CTL_PORT_SEM:
4099 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4100 "Port SemReg: 0x%08x\n",
4101 readl(phba->sli4_hba.conf_regs_memmap_p +
4102 LPFC_CTL_PORT_SEM_OFFSET));
4104 case LPFC_CTL_PORT_STA:
4105 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4106 "Port StaReg: 0x%08x\n",
4107 readl(phba->sli4_hba.conf_regs_memmap_p +
4108 LPFC_CTL_PORT_STA_OFFSET));
4110 case LPFC_CTL_PORT_CTL:
4111 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4112 "Port CtlReg: 0x%08x\n",
4113 readl(phba->sli4_hba.conf_regs_memmap_p +
4114 LPFC_CTL_PORT_CTL_OFFSET));
4116 case LPFC_CTL_PORT_ER1:
4117 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4118 "Port Er1Reg: 0x%08x\n",
4119 readl(phba->sli4_hba.conf_regs_memmap_p +
4120 LPFC_CTL_PORT_ER1_OFFSET));
4122 case LPFC_CTL_PORT_ER2:
4123 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4124 "Port Er2Reg: 0x%08x\n",
4125 readl(phba->sli4_hba.conf_regs_memmap_p +
4126 LPFC_CTL_PORT_ER2_OFFSET));
4128 case LPFC_CTL_PDEV_CTL:
4129 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4130 "PDev CtlReg: 0x%08x\n",
4131 readl(phba->sli4_hba.conf_regs_memmap_p +
4132 LPFC_CTL_PDEV_CTL_OFFSET));
4141 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4142 * @file: The file pointer to read from.
4143 * @buf: The buffer to copy the data to.
4144 * @nbytes: The number of bytes to read.
4145 * @ppos: The position in the file to start reading from.
4148 * This routine reads data from the @phba port and device registers according
4149 * to the idiag command, and copies to user @buf.
4152 * This function returns the amount of data that was read (this could be less
4153 * than @nbytes if the end of the file was reached) or a negative error value.
4156 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4159 struct lpfc_debug *debug = file->private_data;
4160 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4161 uint32_t ctl_reg_id, i;
4165 /* This is a user read operation */
4166 debug->op = LPFC_IDIAG_OP_RD;
4169 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4172 pbuffer = debug->buffer;
4177 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4178 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4182 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4183 for (i = 1; i <= LPFC_CTL_MAX; i++)
4184 len = lpfc_idiag_ctlacc_read_reg(phba,
4187 len = lpfc_idiag_ctlacc_read_reg(phba,
4188 pbuffer, len, ctl_reg_id);
4190 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4194 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4195 * @file: The file pointer to read from.
4196 * @buf: The buffer to copy the user data from.
4197 * @nbytes: The number of bytes to get.
4198 * @ppos: The position in the file to start reading from.
4200 * This routine get the debugfs idiag command struct from user space and then
4201 * perform the syntax check for port and device control register read (dump)
4202 * or write (set) command accordingly.
4204 * It returns the @nbytges passing in from debugfs user space when successful.
4205 * In case of error conditions, it returns proper error code back to the user
4209 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4210 size_t nbytes, loff_t *ppos)
4212 struct lpfc_debug *debug = file->private_data;
4213 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4214 uint32_t ctl_reg_id, value, reg_val = 0;
4215 void __iomem *ctl_reg;
4218 /* This is a user write operation */
4219 debug->op = LPFC_IDIAG_OP_WR;
4221 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4225 /* Sanity check on command line arguments */
4226 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4227 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4229 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4230 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4231 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4232 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4234 if (ctl_reg_id > LPFC_CTL_MAX)
4236 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4237 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4239 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4240 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4245 /* Perform the write access operation */
4246 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4247 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4248 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4249 switch (ctl_reg_id) {
4250 case LPFC_CTL_PORT_SEM:
4251 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4252 LPFC_CTL_PORT_SEM_OFFSET;
4254 case LPFC_CTL_PORT_STA:
4255 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4256 LPFC_CTL_PORT_STA_OFFSET;
4258 case LPFC_CTL_PORT_CTL:
4259 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4260 LPFC_CTL_PORT_CTL_OFFSET;
4262 case LPFC_CTL_PORT_ER1:
4263 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4264 LPFC_CTL_PORT_ER1_OFFSET;
4266 case LPFC_CTL_PORT_ER2:
4267 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4268 LPFC_CTL_PORT_ER2_OFFSET;
4270 case LPFC_CTL_PDEV_CTL:
4271 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4272 LPFC_CTL_PDEV_CTL_OFFSET;
4278 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4280 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4281 reg_val = readl(ctl_reg);
4284 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4285 reg_val = readl(ctl_reg);
4288 writel(reg_val, ctl_reg);
4289 readl(ctl_reg); /* flush */
4294 /* Clean out command structure on command error out */
4295 memset(&idiag, 0, sizeof(idiag));
4300 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4301 * @phba: Pointer to HBA context object.
4302 * @pbuffer: Pointer to data buffer.
4305 * This routine gets the driver mailbox access debugfs setup information.
4308 * This function returns the amount of data that was read (this could be less
4309 * than @nbytes if the end of the file was reached) or a negative error value.
4312 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
4314 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4317 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4318 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4319 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4320 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4322 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4323 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
4324 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4325 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
4326 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4327 "mbx_word_cnt: %04d\n", mbx_word_cnt);
4328 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4329 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
4335 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
4336 * @file: The file pointer to read from.
4337 * @buf: The buffer to copy the data to.
4338 * @nbytes: The number of bytes to read.
4339 * @ppos: The position in the file to start reading from.
4342 * This routine reads data from the @phba driver mailbox access debugfs setup
4346 * This function returns the amount of data that was read (this could be less
4347 * than @nbytes if the end of the file was reached) or a negative error value.
4350 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
4353 struct lpfc_debug *debug = file->private_data;
4354 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4358 /* This is a user read operation */
4359 debug->op = LPFC_IDIAG_OP_RD;
4362 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
4365 pbuffer = debug->buffer;
4370 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
4371 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
4374 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
4376 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4380 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
4381 * @file: The file pointer to read from.
4382 * @buf: The buffer to copy the user data from.
4383 * @nbytes: The number of bytes to get.
4384 * @ppos: The position in the file to start reading from.
4386 * This routine get the debugfs idiag command struct from user space and then
4387 * perform the syntax check for driver mailbox command (dump) and sets up the
4388 * necessary states in the idiag command struct accordingly.
4390 * It returns the @nbytges passing in from debugfs user space when successful.
4391 * In case of error conditions, it returns proper error code back to the user
4395 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
4396 size_t nbytes, loff_t *ppos)
4398 struct lpfc_debug *debug = file->private_data;
4399 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4402 /* This is a user write operation */
4403 debug->op = LPFC_IDIAG_OP_WR;
4405 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4409 /* Sanity check on command line arguments */
4410 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4411 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4412 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4413 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4415 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
4416 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
4418 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
4419 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4421 if (mbx_word_cnt > sizeof(MAILBOX_t))
4423 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
4424 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
4426 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
4427 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4429 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
4431 if (mbx_mbox_cmd != 0x9b)
4436 if (mbx_word_cnt == 0)
4438 if (rc != LPFC_MBX_DMP_ARG)
4440 if (mbx_mbox_cmd & ~0xff)
4443 /* condition for stop mailbox dump */
4444 if (mbx_dump_cnt == 0)
4450 /* Clean out command structure on command error out */
4451 memset(&idiag, 0, sizeof(idiag));
4455 /* Clean out command structure on command error out */
4456 memset(&idiag, 0, sizeof(idiag));
4461 * lpfc_idiag_extacc_avail_get - get the available extents information
4462 * @phba: pointer to lpfc hba data structure.
4463 * @pbuffer: pointer to internal buffer.
4464 * @len: length into the internal buffer data has been copied.
4467 * This routine is to get the available extent information.
4470 * overall lenth of the data read into the internal buffer.
4473 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
4475 uint16_t ext_cnt, ext_size;
4477 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4478 "\nAvailable Extents Information:\n");
4480 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4481 "\tPort Available VPI extents: ");
4482 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
4483 &ext_cnt, &ext_size);
4484 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4485 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4487 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4488 "\tPort Available VFI extents: ");
4489 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
4490 &ext_cnt, &ext_size);
4491 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4492 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4494 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4495 "\tPort Available RPI extents: ");
4496 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
4497 &ext_cnt, &ext_size);
4498 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4499 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4501 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4502 "\tPort Available XRI extents: ");
4503 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
4504 &ext_cnt, &ext_size);
4505 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4506 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4512 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
4513 * @phba: pointer to lpfc hba data structure.
4514 * @pbuffer: pointer to internal buffer.
4515 * @len: length into the internal buffer data has been copied.
4518 * This routine is to get the allocated extent information.
4521 * overall lenth of the data read into the internal buffer.
4524 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
4526 uint16_t ext_cnt, ext_size;
4529 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4530 "\nAllocated Extents Information:\n");
4532 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4533 "\tHost Allocated VPI extents: ");
4534 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
4535 &ext_cnt, &ext_size);
4537 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4538 "Port %d Extent %3d, Size %3d\n",
4539 phba->brd_no, ext_cnt, ext_size);
4541 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4544 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4545 "\tHost Allocated VFI extents: ");
4546 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
4547 &ext_cnt, &ext_size);
4549 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4550 "Port %d Extent %3d, Size %3d\n",
4551 phba->brd_no, ext_cnt, ext_size);
4553 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4556 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4557 "\tHost Allocated RPI extents: ");
4558 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
4559 &ext_cnt, &ext_size);
4561 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4562 "Port %d Extent %3d, Size %3d\n",
4563 phba->brd_no, ext_cnt, ext_size);
4565 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4568 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4569 "\tHost Allocated XRI extents: ");
4570 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
4571 &ext_cnt, &ext_size);
4573 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4574 "Port %d Extent %3d, Size %3d\n",
4575 phba->brd_no, ext_cnt, ext_size);
4577 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4584 * lpfc_idiag_extacc_drivr_get - get driver extent information
4585 * @phba: pointer to lpfc hba data structure.
4586 * @pbuffer: pointer to internal buffer.
4587 * @len: length into the internal buffer data has been copied.
4590 * This routine is to get the driver extent information.
4593 * overall lenth of the data read into the internal buffer.
4596 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
4598 struct lpfc_rsrc_blks *rsrc_blks;
4601 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4602 "\nDriver Extents Information:\n");
4604 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4605 "\tVPI extents:\n");
4607 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
4608 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4609 "\t\tBlock %3d: Start %4d, Count %4d\n",
4610 index, rsrc_blks->rsrc_start,
4611 rsrc_blks->rsrc_size);
4614 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4615 "\tVFI extents:\n");
4617 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
4619 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4620 "\t\tBlock %3d: Start %4d, Count %4d\n",
4621 index, rsrc_blks->rsrc_start,
4622 rsrc_blks->rsrc_size);
4626 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4627 "\tRPI extents:\n");
4629 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
4631 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4632 "\t\tBlock %3d: Start %4d, Count %4d\n",
4633 index, rsrc_blks->rsrc_start,
4634 rsrc_blks->rsrc_size);
4638 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4639 "\tXRI extents:\n");
4641 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
4643 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4644 "\t\tBlock %3d: Start %4d, Count %4d\n",
4645 index, rsrc_blks->rsrc_start,
4646 rsrc_blks->rsrc_size);
4654 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
4655 * @file: The file pointer to read from.
4656 * @buf: The buffer to copy the user data from.
4657 * @nbytes: The number of bytes to get.
4658 * @ppos: The position in the file to start reading from.
4660 * This routine get the debugfs idiag command struct from user space and then
4661 * perform the syntax check for extent information access commands and sets
4662 * up the necessary states in the idiag command struct accordingly.
4664 * It returns the @nbytges passing in from debugfs user space when successful.
4665 * In case of error conditions, it returns proper error code back to the user
4669 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
4670 size_t nbytes, loff_t *ppos)
4672 struct lpfc_debug *debug = file->private_data;
4676 /* This is a user write operation */
4677 debug->op = LPFC_IDIAG_OP_WR;
4679 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4683 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4685 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4687 if (rc != LPFC_EXT_ACC_CMD_ARG)
4689 if (!(ext_map & LPFC_EXT_ACC_ALL))
4694 /* Clean out command structure on command error out */
4695 memset(&idiag, 0, sizeof(idiag));
4700 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
4701 * @file: The file pointer to read from.
4702 * @buf: The buffer to copy the data to.
4703 * @nbytes: The number of bytes to read.
4704 * @ppos: The position in the file to start reading from.
4707 * This routine reads data from the proper extent information according to
4708 * the idiag command, and copies to user @buf.
4711 * This function returns the amount of data that was read (this could be less
4712 * than @nbytes if the end of the file was reached) or a negative error value.
4715 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
4718 struct lpfc_debug *debug = file->private_data;
4719 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4724 /* This is a user read operation */
4725 debug->op = LPFC_IDIAG_OP_RD;
4728 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
4731 pbuffer = debug->buffer;
4734 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4737 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4738 if (ext_map & LPFC_EXT_ACC_AVAIL)
4739 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
4740 if (ext_map & LPFC_EXT_ACC_ALLOC)
4741 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
4742 if (ext_map & LPFC_EXT_ACC_DRIVR)
4743 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
4745 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4748 #undef lpfc_debugfs_op_disc_trc
4749 static const struct file_operations lpfc_debugfs_op_disc_trc = {
4750 .owner = THIS_MODULE,
4751 .open = lpfc_debugfs_disc_trc_open,
4752 .llseek = lpfc_debugfs_lseek,
4753 .read = lpfc_debugfs_read,
4754 .release = lpfc_debugfs_release,
4757 #undef lpfc_debugfs_op_nodelist
4758 static const struct file_operations lpfc_debugfs_op_nodelist = {
4759 .owner = THIS_MODULE,
4760 .open = lpfc_debugfs_nodelist_open,
4761 .llseek = lpfc_debugfs_lseek,
4762 .read = lpfc_debugfs_read,
4763 .release = lpfc_debugfs_release,
4766 #undef lpfc_debugfs_op_hbqinfo
4767 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
4768 .owner = THIS_MODULE,
4769 .open = lpfc_debugfs_hbqinfo_open,
4770 .llseek = lpfc_debugfs_lseek,
4771 .read = lpfc_debugfs_read,
4772 .release = lpfc_debugfs_release,
4775 #undef lpfc_debugfs_op_dumpHBASlim
4776 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
4777 .owner = THIS_MODULE,
4778 .open = lpfc_debugfs_dumpHBASlim_open,
4779 .llseek = lpfc_debugfs_lseek,
4780 .read = lpfc_debugfs_read,
4781 .release = lpfc_debugfs_release,
4784 #undef lpfc_debugfs_op_dumpHostSlim
4785 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
4786 .owner = THIS_MODULE,
4787 .open = lpfc_debugfs_dumpHostSlim_open,
4788 .llseek = lpfc_debugfs_lseek,
4789 .read = lpfc_debugfs_read,
4790 .release = lpfc_debugfs_release,
4793 #undef lpfc_debugfs_op_nvmestat
4794 static const struct file_operations lpfc_debugfs_op_nvmestat = {
4795 .owner = THIS_MODULE,
4796 .open = lpfc_debugfs_nvmestat_open,
4797 .llseek = lpfc_debugfs_lseek,
4798 .read = lpfc_debugfs_read,
4799 .write = lpfc_debugfs_nvmestat_write,
4800 .release = lpfc_debugfs_release,
4803 #undef lpfc_debugfs_op_nvmektime
4804 static const struct file_operations lpfc_debugfs_op_nvmektime = {
4805 .owner = THIS_MODULE,
4806 .open = lpfc_debugfs_nvmektime_open,
4807 .llseek = lpfc_debugfs_lseek,
4808 .read = lpfc_debugfs_read,
4809 .write = lpfc_debugfs_nvmektime_write,
4810 .release = lpfc_debugfs_release,
4813 #undef lpfc_debugfs_op_nvmeio_trc
4814 static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
4815 .owner = THIS_MODULE,
4816 .open = lpfc_debugfs_nvmeio_trc_open,
4817 .llseek = lpfc_debugfs_lseek,
4818 .read = lpfc_debugfs_read,
4819 .write = lpfc_debugfs_nvmeio_trc_write,
4820 .release = lpfc_debugfs_release,
4823 #undef lpfc_debugfs_op_cpucheck
4824 static const struct file_operations lpfc_debugfs_op_cpucheck = {
4825 .owner = THIS_MODULE,
4826 .open = lpfc_debugfs_cpucheck_open,
4827 .llseek = lpfc_debugfs_lseek,
4828 .read = lpfc_debugfs_read,
4829 .write = lpfc_debugfs_cpucheck_write,
4830 .release = lpfc_debugfs_release,
4833 #undef lpfc_debugfs_op_dumpData
4834 static const struct file_operations lpfc_debugfs_op_dumpData = {
4835 .owner = THIS_MODULE,
4836 .open = lpfc_debugfs_dumpData_open,
4837 .llseek = lpfc_debugfs_lseek,
4838 .read = lpfc_debugfs_read,
4839 .write = lpfc_debugfs_dumpDataDif_write,
4840 .release = lpfc_debugfs_dumpDataDif_release,
4843 #undef lpfc_debugfs_op_dumpDif
4844 static const struct file_operations lpfc_debugfs_op_dumpDif = {
4845 .owner = THIS_MODULE,
4846 .open = lpfc_debugfs_dumpDif_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_dif_err
4854 static const struct file_operations lpfc_debugfs_op_dif_err = {
4855 .owner = THIS_MODULE,
4856 .open = simple_open,
4857 .llseek = lpfc_debugfs_lseek,
4858 .read = lpfc_debugfs_dif_err_read,
4859 .write = lpfc_debugfs_dif_err_write,
4860 .release = lpfc_debugfs_dif_err_release,
4863 #undef lpfc_debugfs_op_slow_ring_trc
4864 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
4865 .owner = THIS_MODULE,
4866 .open = lpfc_debugfs_slow_ring_trc_open,
4867 .llseek = lpfc_debugfs_lseek,
4868 .read = lpfc_debugfs_read,
4869 .release = lpfc_debugfs_release,
4872 static struct dentry *lpfc_debugfs_root = NULL;
4873 static atomic_t lpfc_debugfs_hba_count;
4876 * File operations for the iDiag debugfs
4878 #undef lpfc_idiag_op_pciCfg
4879 static const struct file_operations lpfc_idiag_op_pciCfg = {
4880 .owner = THIS_MODULE,
4881 .open = lpfc_idiag_open,
4882 .llseek = lpfc_debugfs_lseek,
4883 .read = lpfc_idiag_pcicfg_read,
4884 .write = lpfc_idiag_pcicfg_write,
4885 .release = lpfc_idiag_cmd_release,
4888 #undef lpfc_idiag_op_barAcc
4889 static const struct file_operations lpfc_idiag_op_barAcc = {
4890 .owner = THIS_MODULE,
4891 .open = lpfc_idiag_open,
4892 .llseek = lpfc_debugfs_lseek,
4893 .read = lpfc_idiag_baracc_read,
4894 .write = lpfc_idiag_baracc_write,
4895 .release = lpfc_idiag_cmd_release,
4898 #undef lpfc_idiag_op_queInfo
4899 static const struct file_operations lpfc_idiag_op_queInfo = {
4900 .owner = THIS_MODULE,
4901 .open = lpfc_idiag_open,
4902 .read = lpfc_idiag_queinfo_read,
4903 .release = lpfc_idiag_release,
4906 #undef lpfc_idiag_op_queAcc
4907 static const struct file_operations lpfc_idiag_op_queAcc = {
4908 .owner = THIS_MODULE,
4909 .open = lpfc_idiag_open,
4910 .llseek = lpfc_debugfs_lseek,
4911 .read = lpfc_idiag_queacc_read,
4912 .write = lpfc_idiag_queacc_write,
4913 .release = lpfc_idiag_cmd_release,
4916 #undef lpfc_idiag_op_drbAcc
4917 static const struct file_operations lpfc_idiag_op_drbAcc = {
4918 .owner = THIS_MODULE,
4919 .open = lpfc_idiag_open,
4920 .llseek = lpfc_debugfs_lseek,
4921 .read = lpfc_idiag_drbacc_read,
4922 .write = lpfc_idiag_drbacc_write,
4923 .release = lpfc_idiag_cmd_release,
4926 #undef lpfc_idiag_op_ctlAcc
4927 static const struct file_operations lpfc_idiag_op_ctlAcc = {
4928 .owner = THIS_MODULE,
4929 .open = lpfc_idiag_open,
4930 .llseek = lpfc_debugfs_lseek,
4931 .read = lpfc_idiag_ctlacc_read,
4932 .write = lpfc_idiag_ctlacc_write,
4933 .release = lpfc_idiag_cmd_release,
4936 #undef lpfc_idiag_op_mbxAcc
4937 static const struct file_operations lpfc_idiag_op_mbxAcc = {
4938 .owner = THIS_MODULE,
4939 .open = lpfc_idiag_open,
4940 .llseek = lpfc_debugfs_lseek,
4941 .read = lpfc_idiag_mbxacc_read,
4942 .write = lpfc_idiag_mbxacc_write,
4943 .release = lpfc_idiag_cmd_release,
4946 #undef lpfc_idiag_op_extAcc
4947 static const struct file_operations lpfc_idiag_op_extAcc = {
4948 .owner = THIS_MODULE,
4949 .open = lpfc_idiag_open,
4950 .llseek = lpfc_debugfs_lseek,
4951 .read = lpfc_idiag_extacc_read,
4952 .write = lpfc_idiag_extacc_write,
4953 .release = lpfc_idiag_cmd_release,
4958 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
4959 * @phba: Pointer to HBA context object.
4960 * @dmabuf: Pointer to a DMA buffer descriptor.
4963 * This routine dump a bsg pass-through non-embedded mailbox command with
4967 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
4968 enum mbox_type mbox_tp, enum dma_type dma_tp,
4969 enum sta_type sta_tp,
4970 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
4972 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4973 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
4974 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
4976 uint32_t do_dump = 0;
4980 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
4983 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4984 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4985 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4986 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4988 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
4989 (*mbx_dump_cnt == 0) ||
4990 (*mbx_word_cnt == 0))
4993 if (*mbx_mbox_cmd != 0x9B)
4996 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
4997 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
4998 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
4999 pr_err("\nRead mbox command (x%x), "
5000 "nemb:0x%x, extbuf_cnt:%d:\n",
5001 sta_tp, nemb_tp, ext_buf);
5004 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5005 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5006 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
5007 pr_err("\nRead mbox buffer (x%x), "
5008 "nemb:0x%x, extbuf_seq:%d:\n",
5009 sta_tp, nemb_tp, ext_buf);
5012 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5013 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5014 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
5015 pr_err("\nWrite mbox command (x%x), "
5016 "nemb:0x%x, extbuf_cnt:%d:\n",
5017 sta_tp, nemb_tp, ext_buf);
5020 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5021 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5022 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
5023 pr_err("\nWrite mbox buffer (x%x), "
5024 "nemb:0x%x, extbuf_seq:%d:\n",
5025 sta_tp, nemb_tp, ext_buf);
5029 /* dump buffer content */
5031 pword = (uint32_t *)dmabuf->virt;
5032 for (i = 0; i < *mbx_word_cnt; i++) {
5035 pr_err("%s\n", line_buf);
5037 len += snprintf(line_buf+len,
5038 LPFC_MBX_ACC_LBUF_SZ-len,
5041 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5042 "%08x ", (uint32_t)*pword);
5046 pr_err("%s\n", line_buf);
5050 /* Clean out command structure on reaching dump count */
5051 if (*mbx_dump_cnt == 0)
5052 memset(&idiag, 0, sizeof(idiag));
5057 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5058 * @phba: Pointer to HBA context object.
5059 * @dmabuf: Pointer to a DMA buffer descriptor.
5062 * This routine dump a pass-through non-embedded mailbox command from issue
5066 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5068 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5069 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5070 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5076 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5079 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5080 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5081 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5082 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5084 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5085 (*mbx_dump_cnt == 0) ||
5086 (*mbx_word_cnt == 0))
5089 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5090 (*mbx_mbox_cmd != pmbox->mbxCommand))
5093 /* dump buffer content */
5094 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
5095 pr_err("Mailbox command:0x%x dump by word:\n",
5097 pword = (uint32_t *)pmbox;
5098 for (i = 0; i < *mbx_word_cnt; i++) {
5101 pr_err("%s\n", line_buf);
5103 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5104 len += snprintf(line_buf+len,
5105 LPFC_MBX_ACC_LBUF_SZ-len,
5108 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5110 ((uint32_t)*pword) & 0xffffffff);
5114 pr_err("%s\n", line_buf);
5117 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
5118 pr_err("Mailbox command:0x%x dump by byte:\n",
5120 pbyte = (uint8_t *)pmbox;
5121 for (i = 0; i < *mbx_word_cnt; i++) {
5124 pr_err("%s\n", line_buf);
5126 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5127 len += snprintf(line_buf+len,
5128 LPFC_MBX_ACC_LBUF_SZ-len,
5131 for (j = 0; j < 4; j++) {
5132 len += snprintf(line_buf+len,
5133 LPFC_MBX_ACC_LBUF_SZ-len,
5135 ((uint8_t)*pbyte) & 0xff);
5138 len += snprintf(line_buf+len,
5139 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5142 pr_err("%s\n", line_buf);
5147 /* Clean out command structure on reaching dump count */
5148 if (*mbx_dump_cnt == 0)
5149 memset(&idiag, 0, sizeof(idiag));
5155 * lpfc_debugfs_initialize - Initialize debugfs for a vport
5156 * @vport: The vport pointer to initialize.
5159 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5160 * If not already created, this routine will create the lpfc directory, and
5161 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5162 * also create each file used to access lpfc specific debugfs information.
5165 lpfc_debugfs_initialize(struct lpfc_vport *vport)
5167 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5168 struct lpfc_hba *phba = vport->phba;
5171 bool pport_setup = false;
5173 if (!lpfc_debugfs_enable)
5176 /* Setup lpfc root directory */
5177 if (!lpfc_debugfs_root) {
5178 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5179 atomic_set(&lpfc_debugfs_hba_count, 0);
5180 if (!lpfc_debugfs_root) {
5181 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5182 "0408 Cannot create debugfs root\n");
5186 if (!lpfc_debugfs_start_time)
5187 lpfc_debugfs_start_time = jiffies;
5189 /* Setup funcX directory for specific HBA PCI function */
5190 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
5191 if (!phba->hba_debugfs_root) {
5193 phba->hba_debugfs_root =
5194 debugfs_create_dir(name, lpfc_debugfs_root);
5195 if (!phba->hba_debugfs_root) {
5196 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5197 "0412 Cannot create debugfs hba\n");
5200 atomic_inc(&lpfc_debugfs_hba_count);
5201 atomic_set(&phba->debugfs_vport_count, 0);
5204 snprintf(name, sizeof(name), "hbqinfo");
5205 phba->debug_hbqinfo =
5206 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5207 phba->hba_debugfs_root,
5208 phba, &lpfc_debugfs_op_hbqinfo);
5209 if (!phba->debug_hbqinfo) {
5210 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5211 "0411 Cannot create debugfs hbqinfo\n");
5215 /* Setup dumpHBASlim */
5216 if (phba->sli_rev < LPFC_SLI_REV4) {
5217 snprintf(name, sizeof(name), "dumpHBASlim");
5218 phba->debug_dumpHBASlim =
5219 debugfs_create_file(name,
5220 S_IFREG|S_IRUGO|S_IWUSR,
5221 phba->hba_debugfs_root,
5222 phba, &lpfc_debugfs_op_dumpHBASlim);
5223 if (!phba->debug_dumpHBASlim) {
5224 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5225 "0413 Cannot create debugfs "
5230 phba->debug_dumpHBASlim = NULL;
5232 /* Setup dumpHostSlim */
5233 if (phba->sli_rev < LPFC_SLI_REV4) {
5234 snprintf(name, sizeof(name), "dumpHostSlim");
5235 phba->debug_dumpHostSlim =
5236 debugfs_create_file(name,
5237 S_IFREG|S_IRUGO|S_IWUSR,
5238 phba->hba_debugfs_root,
5239 phba, &lpfc_debugfs_op_dumpHostSlim);
5240 if (!phba->debug_dumpHostSlim) {
5241 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5242 "0414 Cannot create debugfs "
5247 phba->debug_dumpHostSlim = NULL;
5249 /* Setup dumpData */
5250 snprintf(name, sizeof(name), "dumpData");
5251 phba->debug_dumpData =
5252 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5253 phba->hba_debugfs_root,
5254 phba, &lpfc_debugfs_op_dumpData);
5255 if (!phba->debug_dumpData) {
5256 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5257 "0800 Cannot create debugfs dumpData\n");
5262 snprintf(name, sizeof(name), "dumpDif");
5263 phba->debug_dumpDif =
5264 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5265 phba->hba_debugfs_root,
5266 phba, &lpfc_debugfs_op_dumpDif);
5267 if (!phba->debug_dumpDif) {
5268 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5269 "0801 Cannot create debugfs dumpDif\n");
5273 /* Setup DIF Error Injections */
5274 snprintf(name, sizeof(name), "InjErrLBA");
5275 phba->debug_InjErrLBA =
5276 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5277 phba->hba_debugfs_root,
5278 phba, &lpfc_debugfs_op_dif_err);
5279 if (!phba->debug_InjErrLBA) {
5280 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5281 "0807 Cannot create debugfs InjErrLBA\n");
5284 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5286 snprintf(name, sizeof(name), "InjErrNPortID");
5287 phba->debug_InjErrNPortID =
5288 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5289 phba->hba_debugfs_root,
5290 phba, &lpfc_debugfs_op_dif_err);
5291 if (!phba->debug_InjErrNPortID) {
5292 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5293 "0809 Cannot create debugfs InjErrNPortID\n");
5297 snprintf(name, sizeof(name), "InjErrWWPN");
5298 phba->debug_InjErrWWPN =
5299 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5300 phba->hba_debugfs_root,
5301 phba, &lpfc_debugfs_op_dif_err);
5302 if (!phba->debug_InjErrWWPN) {
5303 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5304 "0810 Cannot create debugfs InjErrWWPN\n");
5308 snprintf(name, sizeof(name), "writeGuardInjErr");
5309 phba->debug_writeGuard =
5310 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5311 phba->hba_debugfs_root,
5312 phba, &lpfc_debugfs_op_dif_err);
5313 if (!phba->debug_writeGuard) {
5314 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5315 "0802 Cannot create debugfs writeGuard\n");
5319 snprintf(name, sizeof(name), "writeAppInjErr");
5320 phba->debug_writeApp =
5321 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5322 phba->hba_debugfs_root,
5323 phba, &lpfc_debugfs_op_dif_err);
5324 if (!phba->debug_writeApp) {
5325 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5326 "0803 Cannot create debugfs writeApp\n");
5330 snprintf(name, sizeof(name), "writeRefInjErr");
5331 phba->debug_writeRef =
5332 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5333 phba->hba_debugfs_root,
5334 phba, &lpfc_debugfs_op_dif_err);
5335 if (!phba->debug_writeRef) {
5336 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5337 "0804 Cannot create debugfs writeRef\n");
5341 snprintf(name, sizeof(name), "readGuardInjErr");
5342 phba->debug_readGuard =
5343 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5344 phba->hba_debugfs_root,
5345 phba, &lpfc_debugfs_op_dif_err);
5346 if (!phba->debug_readGuard) {
5347 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5348 "0808 Cannot create debugfs readGuard\n");
5352 snprintf(name, sizeof(name), "readAppInjErr");
5353 phba->debug_readApp =
5354 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5355 phba->hba_debugfs_root,
5356 phba, &lpfc_debugfs_op_dif_err);
5357 if (!phba->debug_readApp) {
5358 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5359 "0805 Cannot create debugfs readApp\n");
5363 snprintf(name, sizeof(name), "readRefInjErr");
5364 phba->debug_readRef =
5365 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5366 phba->hba_debugfs_root,
5367 phba, &lpfc_debugfs_op_dif_err);
5368 if (!phba->debug_readRef) {
5369 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5370 "0806 Cannot create debugfs readApp\n");
5374 /* Setup slow ring trace */
5375 if (lpfc_debugfs_max_slow_ring_trc) {
5376 num = lpfc_debugfs_max_slow_ring_trc - 1;
5377 if (num & lpfc_debugfs_max_slow_ring_trc) {
5378 /* Change to be a power of 2 */
5379 num = lpfc_debugfs_max_slow_ring_trc;
5385 lpfc_debugfs_max_slow_ring_trc = (1 << i);
5386 pr_err("lpfc_debugfs_max_disc_trc changed to "
5387 "%d\n", lpfc_debugfs_max_disc_trc);
5391 snprintf(name, sizeof(name), "slow_ring_trace");
5392 phba->debug_slow_ring_trc =
5393 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5394 phba->hba_debugfs_root,
5395 phba, &lpfc_debugfs_op_slow_ring_trc);
5396 if (!phba->debug_slow_ring_trc) {
5397 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5398 "0415 Cannot create debugfs "
5399 "slow_ring_trace\n");
5402 if (!phba->slow_ring_trc) {
5403 phba->slow_ring_trc = kmalloc(
5404 (sizeof(struct lpfc_debugfs_trc) *
5405 lpfc_debugfs_max_slow_ring_trc),
5407 if (!phba->slow_ring_trc) {
5408 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5409 "0416 Cannot create debugfs "
5410 "slow_ring buffer\n");
5413 atomic_set(&phba->slow_ring_trc_cnt, 0);
5414 memset(phba->slow_ring_trc, 0,
5415 (sizeof(struct lpfc_debugfs_trc) *
5416 lpfc_debugfs_max_slow_ring_trc));
5419 snprintf(name, sizeof(name), "nvmeio_trc");
5420 phba->debug_nvmeio_trc =
5421 debugfs_create_file(name, 0644,
5422 phba->hba_debugfs_root,
5423 phba, &lpfc_debugfs_op_nvmeio_trc);
5424 if (!phba->debug_nvmeio_trc) {
5425 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5426 "0574 No create debugfs nvmeio_trc\n");
5430 atomic_set(&phba->nvmeio_trc_cnt, 0);
5431 if (lpfc_debugfs_max_nvmeio_trc) {
5432 num = lpfc_debugfs_max_nvmeio_trc - 1;
5433 if (num & lpfc_debugfs_max_disc_trc) {
5434 /* Change to be a power of 2 */
5435 num = lpfc_debugfs_max_nvmeio_trc;
5441 lpfc_debugfs_max_nvmeio_trc = (1 << i);
5442 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5443 "0575 lpfc_debugfs_max_nvmeio_trc "
5445 lpfc_debugfs_max_nvmeio_trc);
5447 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
5449 /* Allocate trace buffer and initialize */
5450 phba->nvmeio_trc = kmalloc(
5451 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5452 phba->nvmeio_trc_size), GFP_KERNEL);
5454 if (!phba->nvmeio_trc) {
5455 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5456 "0576 Cannot create debugfs "
5457 "nvmeio_trc buffer\n");
5460 memset(phba->nvmeio_trc, 0,
5461 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5462 phba->nvmeio_trc_size));
5463 phba->nvmeio_trc_on = 1;
5464 phba->nvmeio_trc_output_idx = 0;
5465 phba->nvmeio_trc = NULL;
5468 phba->nvmeio_trc_size = 0;
5469 phba->nvmeio_trc_on = 0;
5470 phba->nvmeio_trc_output_idx = 0;
5471 phba->nvmeio_trc = NULL;
5475 snprintf(name, sizeof(name), "vport%d", vport->vpi);
5476 if (!vport->vport_debugfs_root) {
5477 vport->vport_debugfs_root =
5478 debugfs_create_dir(name, phba->hba_debugfs_root);
5479 if (!vport->vport_debugfs_root) {
5480 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5481 "0417 Can't create debugfs\n");
5484 atomic_inc(&phba->debugfs_vport_count);
5487 if (lpfc_debugfs_max_disc_trc) {
5488 num = lpfc_debugfs_max_disc_trc - 1;
5489 if (num & lpfc_debugfs_max_disc_trc) {
5490 /* Change to be a power of 2 */
5491 num = lpfc_debugfs_max_disc_trc;
5497 lpfc_debugfs_max_disc_trc = (1 << i);
5498 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
5499 lpfc_debugfs_max_disc_trc);
5503 vport->disc_trc = kzalloc(
5504 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
5507 if (!vport->disc_trc) {
5508 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5509 "0418 Cannot create debugfs disc trace "
5513 atomic_set(&vport->disc_trc_cnt, 0);
5515 snprintf(name, sizeof(name), "discovery_trace");
5516 vport->debug_disc_trc =
5517 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5518 vport->vport_debugfs_root,
5519 vport, &lpfc_debugfs_op_disc_trc);
5520 if (!vport->debug_disc_trc) {
5521 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5522 "0419 Cannot create debugfs "
5523 "discovery_trace\n");
5526 snprintf(name, sizeof(name), "nodelist");
5527 vport->debug_nodelist =
5528 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5529 vport->vport_debugfs_root,
5530 vport, &lpfc_debugfs_op_nodelist);
5531 if (!vport->debug_nodelist) {
5532 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5533 "2985 Can't create debugfs nodelist\n");
5537 snprintf(name, sizeof(name), "nvmestat");
5538 vport->debug_nvmestat =
5539 debugfs_create_file(name, 0644,
5540 vport->vport_debugfs_root,
5541 vport, &lpfc_debugfs_op_nvmestat);
5542 if (!vport->debug_nvmestat) {
5543 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5544 "0811 Cannot create debugfs nvmestat\n");
5548 snprintf(name, sizeof(name), "nvmektime");
5549 vport->debug_nvmektime =
5550 debugfs_create_file(name, 0644,
5551 vport->vport_debugfs_root,
5552 vport, &lpfc_debugfs_op_nvmektime);
5553 if (!vport->debug_nvmektime) {
5554 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5555 "0815 Cannot create debugfs nvmektime\n");
5559 snprintf(name, sizeof(name), "cpucheck");
5560 vport->debug_cpucheck =
5561 debugfs_create_file(name, 0644,
5562 vport->vport_debugfs_root,
5563 vport, &lpfc_debugfs_op_cpucheck);
5564 if (!vport->debug_cpucheck) {
5565 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5566 "0819 Cannot create debugfs cpucheck\n");
5571 * The following section is for additional directories/files for the
5579 * iDiag debugfs root entry points for SLI4 device only
5581 if (phba->sli_rev < LPFC_SLI_REV4)
5584 snprintf(name, sizeof(name), "iDiag");
5585 if (!phba->idiag_root) {
5587 debugfs_create_dir(name, phba->hba_debugfs_root);
5588 if (!phba->idiag_root) {
5589 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5590 "2922 Can't create idiag debugfs\n");
5593 /* Initialize iDiag data structure */
5594 memset(&idiag, 0, sizeof(idiag));
5597 /* iDiag read PCI config space */
5598 snprintf(name, sizeof(name), "pciCfg");
5599 if (!phba->idiag_pci_cfg) {
5600 phba->idiag_pci_cfg =
5601 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5602 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
5603 if (!phba->idiag_pci_cfg) {
5604 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5605 "2923 Can't create idiag debugfs\n");
5608 idiag.offset.last_rd = 0;
5611 /* iDiag PCI BAR access */
5612 snprintf(name, sizeof(name), "barAcc");
5613 if (!phba->idiag_bar_acc) {
5614 phba->idiag_bar_acc =
5615 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5616 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
5617 if (!phba->idiag_bar_acc) {
5618 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5619 "3056 Can't create idiag debugfs\n");
5622 idiag.offset.last_rd = 0;
5625 /* iDiag get PCI function queue information */
5626 snprintf(name, sizeof(name), "queInfo");
5627 if (!phba->idiag_que_info) {
5628 phba->idiag_que_info =
5629 debugfs_create_file(name, S_IFREG|S_IRUGO,
5630 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
5631 if (!phba->idiag_que_info) {
5632 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5633 "2924 Can't create idiag debugfs\n");
5638 /* iDiag access PCI function queue */
5639 snprintf(name, sizeof(name), "queAcc");
5640 if (!phba->idiag_que_acc) {
5641 phba->idiag_que_acc =
5642 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5643 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
5644 if (!phba->idiag_que_acc) {
5645 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5646 "2926 Can't create idiag debugfs\n");
5651 /* iDiag access PCI function doorbell registers */
5652 snprintf(name, sizeof(name), "drbAcc");
5653 if (!phba->idiag_drb_acc) {
5654 phba->idiag_drb_acc =
5655 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5656 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
5657 if (!phba->idiag_drb_acc) {
5658 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5659 "2927 Can't create idiag debugfs\n");
5664 /* iDiag access PCI function control registers */
5665 snprintf(name, sizeof(name), "ctlAcc");
5666 if (!phba->idiag_ctl_acc) {
5667 phba->idiag_ctl_acc =
5668 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5669 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
5670 if (!phba->idiag_ctl_acc) {
5671 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5672 "2981 Can't create idiag debugfs\n");
5677 /* iDiag access mbox commands */
5678 snprintf(name, sizeof(name), "mbxAcc");
5679 if (!phba->idiag_mbx_acc) {
5680 phba->idiag_mbx_acc =
5681 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5682 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
5683 if (!phba->idiag_mbx_acc) {
5684 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5685 "2980 Can't create idiag debugfs\n");
5690 /* iDiag extents access commands */
5691 if (phba->sli4_hba.extents_in_use) {
5692 snprintf(name, sizeof(name), "extAcc");
5693 if (!phba->idiag_ext_acc) {
5694 phba->idiag_ext_acc =
5695 debugfs_create_file(name,
5696 S_IFREG|S_IRUGO|S_IWUSR,
5697 phba->idiag_root, phba,
5698 &lpfc_idiag_op_extAcc);
5699 if (!phba->idiag_ext_acc) {
5700 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5714 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
5715 * @vport: The vport pointer to remove from debugfs.
5718 * When Debugfs is configured this routine removes debugfs file system elements
5719 * that are specific to this vport. It also checks to see if there are any
5720 * users left for the debugfs directories associated with the HBA and driver. If
5721 * this is the last user of the HBA directory or driver directory then it will
5722 * remove those from the debugfs infrastructure as well.
5725 lpfc_debugfs_terminate(struct lpfc_vport *vport)
5727 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5728 struct lpfc_hba *phba = vport->phba;
5730 kfree(vport->disc_trc);
5731 vport->disc_trc = NULL;
5733 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
5734 vport->debug_disc_trc = NULL;
5736 debugfs_remove(vport->debug_nodelist); /* nodelist */
5737 vport->debug_nodelist = NULL;
5739 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
5740 vport->debug_nvmestat = NULL;
5742 debugfs_remove(vport->debug_nvmektime); /* nvmektime */
5743 vport->debug_nvmektime = NULL;
5745 debugfs_remove(vport->debug_cpucheck); /* cpucheck */
5746 vport->debug_cpucheck = NULL;
5748 if (vport->vport_debugfs_root) {
5749 debugfs_remove(vport->vport_debugfs_root); /* vportX */
5750 vport->vport_debugfs_root = NULL;
5751 atomic_dec(&phba->debugfs_vport_count);
5754 if (atomic_read(&phba->debugfs_vport_count) == 0) {
5756 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
5757 phba->debug_hbqinfo = NULL;
5759 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
5760 phba->debug_dumpHBASlim = NULL;
5762 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
5763 phba->debug_dumpHostSlim = NULL;
5765 debugfs_remove(phba->debug_dumpData); /* dumpData */
5766 phba->debug_dumpData = NULL;
5768 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
5769 phba->debug_dumpDif = NULL;
5771 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
5772 phba->debug_InjErrLBA = NULL;
5774 debugfs_remove(phba->debug_InjErrNPortID);
5775 phba->debug_InjErrNPortID = NULL;
5777 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
5778 phba->debug_InjErrWWPN = NULL;
5780 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
5781 phba->debug_writeGuard = NULL;
5783 debugfs_remove(phba->debug_writeApp); /* writeApp */
5784 phba->debug_writeApp = NULL;
5786 debugfs_remove(phba->debug_writeRef); /* writeRef */
5787 phba->debug_writeRef = NULL;
5789 debugfs_remove(phba->debug_readGuard); /* readGuard */
5790 phba->debug_readGuard = NULL;
5792 debugfs_remove(phba->debug_readApp); /* readApp */
5793 phba->debug_readApp = NULL;
5795 debugfs_remove(phba->debug_readRef); /* readRef */
5796 phba->debug_readRef = NULL;
5798 kfree(phba->slow_ring_trc);
5799 phba->slow_ring_trc = NULL;
5801 /* slow_ring_trace */
5802 debugfs_remove(phba->debug_slow_ring_trc);
5803 phba->debug_slow_ring_trc = NULL;
5805 debugfs_remove(phba->debug_nvmeio_trc);
5806 phba->debug_nvmeio_trc = NULL;
5808 kfree(phba->nvmeio_trc);
5809 phba->nvmeio_trc = NULL;
5814 if (phba->sli_rev == LPFC_SLI_REV4) {
5816 debugfs_remove(phba->idiag_ext_acc);
5817 phba->idiag_ext_acc = NULL;
5820 debugfs_remove(phba->idiag_mbx_acc);
5821 phba->idiag_mbx_acc = NULL;
5824 debugfs_remove(phba->idiag_ctl_acc);
5825 phba->idiag_ctl_acc = NULL;
5828 debugfs_remove(phba->idiag_drb_acc);
5829 phba->idiag_drb_acc = NULL;
5832 debugfs_remove(phba->idiag_que_acc);
5833 phba->idiag_que_acc = NULL;
5836 debugfs_remove(phba->idiag_que_info);
5837 phba->idiag_que_info = NULL;
5840 debugfs_remove(phba->idiag_bar_acc);
5841 phba->idiag_bar_acc = NULL;
5844 debugfs_remove(phba->idiag_pci_cfg);
5845 phba->idiag_pci_cfg = NULL;
5847 /* Finally remove the iDiag debugfs root */
5848 debugfs_remove(phba->idiag_root);
5849 phba->idiag_root = NULL;
5852 if (phba->hba_debugfs_root) {
5853 debugfs_remove(phba->hba_debugfs_root); /* fnX */
5854 phba->hba_debugfs_root = NULL;
5855 atomic_dec(&lpfc_debugfs_hba_count);
5858 debugfs_remove(lpfc_debugfs_root); /* lpfc */
5859 lpfc_debugfs_root = NULL;
5866 * Driver debug utility routines outside of debugfs. The debug utility
5867 * routines implemented here is intended to be used in the instrumented
5868 * debug driver for debugging host or port issues.
5872 * lpfc_debug_dump_all_queues - dump all the queues with a hba
5873 * @phba: Pointer to HBA context object.
5875 * This function dumps entries of all the queues asociated with the @phba.
5878 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
5883 * Dump Work Queues (WQs)
5885 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
5886 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
5887 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
5889 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5890 lpfc_debug_dump_wq(phba, DUMP_FCP, idx);
5892 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5893 lpfc_debug_dump_wq(phba, DUMP_NVME, idx);
5895 lpfc_debug_dump_hdr_rq(phba);
5896 lpfc_debug_dump_dat_rq(phba);
5898 * Dump Complete Queues (CQs)
5900 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
5901 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
5902 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
5904 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5905 lpfc_debug_dump_cq(phba, DUMP_FCP, idx);
5907 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5908 lpfc_debug_dump_cq(phba, DUMP_NVME, idx);
5911 * Dump Event Queues (EQs)
5913 for (idx = 0; idx < phba->io_channel_irqs; idx++)
5914 lpfc_debug_dump_hba_eq(phba, idx);