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 Cmpl: %08x err %08x drop %08x\n",
802 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
803 atomic_read(&tgtp->xmt_fcp_rsp_error),
804 atomic_read(&tgtp->xmt_fcp_rsp_drop));
806 len += snprintf(buf + len, size - len,
807 "ABORT: Xmt %08x Cmpl %08x\n",
808 atomic_read(&tgtp->xmt_fcp_abort),
809 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
811 len += snprintf(buf + len, size - len,
812 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
813 atomic_read(&tgtp->xmt_abort_sol),
814 atomic_read(&tgtp->xmt_abort_unsol),
815 atomic_read(&tgtp->xmt_abort_rsp),
816 atomic_read(&tgtp->xmt_abort_rsp_error));
818 len += snprintf(buf + len, size - len, "\n");
821 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
822 list_for_each_entry_safe(ctxp, next_ctxp,
823 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
827 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
829 len += snprintf(buf + len, size - len,
830 "ABORT: %d ctx entries\n", cnt);
831 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
832 list_for_each_entry_safe(ctxp, next_ctxp,
833 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
835 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
837 len += snprintf(buf + len, size - len,
838 "Entry: oxid %x state %x "
840 ctxp->oxid, ctxp->state,
843 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
846 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
849 len += snprintf(buf + len, size - len,
850 "\nNVME Lport Statistics\n");
852 len += snprintf(buf + len, size - len,
853 "LS: Xmt %016llx Cmpl %016llx\n",
854 phba->fc4NvmeLsRequests,
855 phba->fc4NvmeLsCmpls);
857 len += snprintf(buf + len, size - len,
858 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
859 phba->fc4NvmeInputRequests,
860 phba->fc4NvmeOutputRequests,
861 phba->fc4NvmeControlRequests);
863 len += snprintf(buf + len, size - len,
864 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
872 * lpfc_debugfs_nvmektime_data - Dump target node list to a buffer
873 * @vport: The vport to gather target node info from.
874 * @buf: The buffer to dump log into.
875 * @size: The maximum amount of data to process.
878 * This routine dumps the NVME statistics associated with @vport
881 * This routine returns the amount of bytes that were dumped into @buf and will
885 lpfc_debugfs_nvmektime_data(struct lpfc_vport *vport, char *buf, int size)
887 struct lpfc_hba *phba = vport->phba;
890 if (phba->nvmet_support == 0) {
892 len += snprintf(buf + len, PAGE_SIZE - len,
893 "ktime %s: Total Samples: %lld\n",
894 (phba->ktime_on ? "Enabled" : "Disabled"),
895 phba->ktime_data_samples);
896 if (phba->ktime_data_samples == 0)
900 buf + len, PAGE_SIZE - len,
901 "Segment 1: Last NVME Cmd cmpl "
902 "done -to- Start of next NVME cnd (in driver)\n");
904 buf + len, PAGE_SIZE - len,
905 "avg:%08lld min:%08lld max %08lld\n",
906 div_u64(phba->ktime_seg1_total,
907 phba->ktime_data_samples),
908 phba->ktime_seg1_min,
909 phba->ktime_seg1_max);
911 buf + len, PAGE_SIZE - len,
912 "Segment 2: Driver start of NVME cmd "
913 "-to- Firmware WQ doorbell\n");
915 buf + len, PAGE_SIZE - len,
916 "avg:%08lld min:%08lld max %08lld\n",
917 div_u64(phba->ktime_seg2_total,
918 phba->ktime_data_samples),
919 phba->ktime_seg2_min,
920 phba->ktime_seg2_max);
922 buf + len, PAGE_SIZE - len,
923 "Segment 3: Firmware WQ doorbell -to- "
926 buf + len, PAGE_SIZE - len,
927 "avg:%08lld min:%08lld max %08lld\n",
928 div_u64(phba->ktime_seg3_total,
929 phba->ktime_data_samples),
930 phba->ktime_seg3_min,
931 phba->ktime_seg3_max);
933 buf + len, PAGE_SIZE - len,
934 "Segment 4: MSI-X ISR cmpl -to- "
937 buf + len, PAGE_SIZE - len,
938 "avg:%08lld min:%08lld max %08lld\n",
939 div_u64(phba->ktime_seg4_total,
940 phba->ktime_data_samples),
941 phba->ktime_seg4_min,
942 phba->ktime_seg4_max);
944 buf + len, PAGE_SIZE - len,
945 "Total IO avg time: %08lld\n",
946 div_u64(phba->ktime_seg1_total +
947 phba->ktime_seg2_total +
948 phba->ktime_seg3_total +
949 phba->ktime_seg4_total,
950 phba->ktime_data_samples));
955 len += snprintf(buf + len, PAGE_SIZE-len,
956 "ktime %s: Total Samples: %lld %lld\n",
957 (phba->ktime_on ? "Enabled" : "Disabled"),
958 phba->ktime_data_samples,
959 phba->ktime_status_samples);
960 if (phba->ktime_data_samples == 0)
963 len += snprintf(buf + len, PAGE_SIZE-len,
964 "Segment 1: MSI-X ISR Rcv cmd -to- "
965 "cmd pass to NVME Layer\n");
966 len += snprintf(buf + len, PAGE_SIZE-len,
967 "avg:%08lld min:%08lld max %08lld\n",
968 div_u64(phba->ktime_seg1_total,
969 phba->ktime_data_samples),
970 phba->ktime_seg1_min,
971 phba->ktime_seg1_max);
972 len += snprintf(buf + len, PAGE_SIZE-len,
973 "Segment 2: cmd pass to NVME Layer- "
974 "-to- Driver rcv cmd OP (action)\n");
975 len += snprintf(buf + len, PAGE_SIZE-len,
976 "avg:%08lld min:%08lld max %08lld\n",
977 div_u64(phba->ktime_seg2_total,
978 phba->ktime_data_samples),
979 phba->ktime_seg2_min,
980 phba->ktime_seg2_max);
981 len += snprintf(buf + len, PAGE_SIZE-len,
982 "Segment 3: Driver rcv cmd OP -to- "
983 "Firmware WQ doorbell: cmd\n");
984 len += snprintf(buf + len, PAGE_SIZE-len,
985 "avg:%08lld min:%08lld max %08lld\n",
986 div_u64(phba->ktime_seg3_total,
987 phba->ktime_data_samples),
988 phba->ktime_seg3_min,
989 phba->ktime_seg3_max);
990 len += snprintf(buf + len, PAGE_SIZE-len,
991 "Segment 4: Firmware WQ doorbell: cmd "
992 "-to- MSI-X ISR for cmd cmpl\n");
993 len += snprintf(buf + len, PAGE_SIZE-len,
994 "avg:%08lld min:%08lld max %08lld\n",
995 div_u64(phba->ktime_seg4_total,
996 phba->ktime_data_samples),
997 phba->ktime_seg4_min,
998 phba->ktime_seg4_max);
999 len += snprintf(buf + len, PAGE_SIZE-len,
1000 "Segment 5: MSI-X ISR for cmd cmpl "
1001 "-to- NVME layer passed cmd done\n");
1002 len += snprintf(buf + len, PAGE_SIZE-len,
1003 "avg:%08lld min:%08lld max %08lld\n",
1004 div_u64(phba->ktime_seg5_total,
1005 phba->ktime_data_samples),
1006 phba->ktime_seg5_min,
1007 phba->ktime_seg5_max);
1009 if (phba->ktime_status_samples == 0) {
1010 len += snprintf(buf + len, PAGE_SIZE-len,
1011 "Total: cmd received by MSI-X ISR "
1012 "-to- cmd completed on wire\n");
1013 len += snprintf(buf + len, PAGE_SIZE-len,
1014 "avg:%08lld min:%08lld "
1016 div_u64(phba->ktime_seg10_total,
1017 phba->ktime_data_samples),
1018 phba->ktime_seg10_min,
1019 phba->ktime_seg10_max);
1023 len += snprintf(buf + len, PAGE_SIZE-len,
1024 "Segment 6: NVME layer passed cmd done "
1025 "-to- Driver rcv rsp status OP\n");
1026 len += snprintf(buf + len, PAGE_SIZE-len,
1027 "avg:%08lld min:%08lld max %08lld\n",
1028 div_u64(phba->ktime_seg6_total,
1029 phba->ktime_status_samples),
1030 phba->ktime_seg6_min,
1031 phba->ktime_seg6_max);
1032 len += snprintf(buf + len, PAGE_SIZE-len,
1033 "Segment 7: Driver rcv rsp status OP "
1034 "-to- Firmware WQ doorbell: status\n");
1035 len += snprintf(buf + len, PAGE_SIZE-len,
1036 "avg:%08lld min:%08lld max %08lld\n",
1037 div_u64(phba->ktime_seg7_total,
1038 phba->ktime_status_samples),
1039 phba->ktime_seg7_min,
1040 phba->ktime_seg7_max);
1041 len += snprintf(buf + len, PAGE_SIZE-len,
1042 "Segment 8: Firmware WQ doorbell: status"
1043 " -to- MSI-X ISR for status cmpl\n");
1044 len += snprintf(buf + len, PAGE_SIZE-len,
1045 "avg:%08lld min:%08lld max %08lld\n",
1046 div_u64(phba->ktime_seg8_total,
1047 phba->ktime_status_samples),
1048 phba->ktime_seg8_min,
1049 phba->ktime_seg8_max);
1050 len += snprintf(buf + len, PAGE_SIZE-len,
1051 "Segment 9: MSI-X ISR for status cmpl "
1052 "-to- NVME layer passed status done\n");
1053 len += snprintf(buf + len, PAGE_SIZE-len,
1054 "avg:%08lld min:%08lld max %08lld\n",
1055 div_u64(phba->ktime_seg9_total,
1056 phba->ktime_status_samples),
1057 phba->ktime_seg9_min,
1058 phba->ktime_seg9_max);
1059 len += snprintf(buf + len, PAGE_SIZE-len,
1060 "Total: cmd received by MSI-X ISR -to- "
1061 "cmd completed on wire\n");
1062 len += snprintf(buf + len, PAGE_SIZE-len,
1063 "avg:%08lld min:%08lld max %08lld\n",
1064 div_u64(phba->ktime_seg10_total,
1065 phba->ktime_status_samples),
1066 phba->ktime_seg10_min,
1067 phba->ktime_seg10_max);
1072 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1073 * @phba: The phba to gather target node info from.
1074 * @buf: The buffer to dump log into.
1075 * @size: The maximum amount of data to process.
1078 * This routine dumps the NVME IO trace associated with @phba
1081 * This routine returns the amount of bytes that were dumped into @buf and will
1085 lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1087 struct lpfc_debugfs_nvmeio_trc *dtp;
1088 int i, state, index, skip;
1091 state = phba->nvmeio_trc_on;
1093 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1094 (phba->nvmeio_trc_size - 1);
1095 skip = phba->nvmeio_trc_output_idx;
1097 len += snprintf(buf + len, size - len,
1098 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1099 (phba->nvmet_support ? "NVME" : "NVMET"),
1100 (state ? "Enabled" : "Disabled"),
1101 index, skip, phba->nvmeio_trc_size);
1103 if (!phba->nvmeio_trc || state)
1106 /* trace MUST bhe off to continue */
1108 for (i = index; i < phba->nvmeio_trc_size; i++) {
1113 dtp = phba->nvmeio_trc + i;
1114 phba->nvmeio_trc_output_idx++;
1119 len += snprintf(buf + len, size - len, dtp->fmt,
1120 dtp->data1, dtp->data2, dtp->data3);
1122 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1123 phba->nvmeio_trc_output_idx = 0;
1124 len += snprintf(buf + len, size - len,
1125 "Trace Complete\n");
1129 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1130 len += snprintf(buf + len, size - len,
1131 "Trace Continue (%d of %d)\n",
1132 phba->nvmeio_trc_output_idx,
1133 phba->nvmeio_trc_size);
1137 for (i = 0; i < index; i++) {
1142 dtp = phba->nvmeio_trc + i;
1143 phba->nvmeio_trc_output_idx++;
1148 len += snprintf(buf + len, size - len, dtp->fmt,
1149 dtp->data1, dtp->data2, dtp->data3);
1151 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1152 phba->nvmeio_trc_output_idx = 0;
1153 len += snprintf(buf + len, size - len,
1154 "Trace Complete\n");
1158 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1159 len += snprintf(buf + len, size - len,
1160 "Trace Continue (%d of %d)\n",
1161 phba->nvmeio_trc_output_idx,
1162 phba->nvmeio_trc_size);
1167 len += snprintf(buf + len, size - len,
1174 * lpfc_debugfs_cpucheck_data - Dump target node list to a buffer
1175 * @vport: The vport to gather target node info from.
1176 * @buf: The buffer to dump log into.
1177 * @size: The maximum amount of data to process.
1180 * This routine dumps the NVME statistics associated with @vport
1183 * This routine returns the amount of bytes that were dumped into @buf and will
1187 lpfc_debugfs_cpucheck_data(struct lpfc_vport *vport, char *buf, int size)
1189 struct lpfc_hba *phba = vport->phba;
1192 uint32_t tot_xmt = 0;
1193 uint32_t tot_rcv = 0;
1194 uint32_t tot_cmpl = 0;
1195 uint32_t tot_ccmpl = 0;
1197 if (phba->nvmet_support == 0) {
1198 /* NVME Initiator */
1199 len += snprintf(buf + len, PAGE_SIZE - len,
1201 (phba->cpucheck_on & LPFC_CHECK_NVME_IO ?
1202 "Enabled" : "Disabled"));
1203 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1204 if (i >= LPFC_CHECK_CPU_CNT)
1206 len += snprintf(buf + len, PAGE_SIZE - len,
1207 "%02d: xmit x%08x cmpl x%08x\n",
1208 i, phba->cpucheck_xmt_io[i],
1209 phba->cpucheck_cmpl_io[i]);
1210 tot_xmt += phba->cpucheck_xmt_io[i];
1211 tot_cmpl += phba->cpucheck_cmpl_io[i];
1213 len += snprintf(buf + len, PAGE_SIZE - len,
1214 "tot:xmit x%08x cmpl x%08x\n",
1220 len += snprintf(buf + len, PAGE_SIZE - len,
1222 (phba->cpucheck_on & LPFC_CHECK_NVMET_IO ?
1223 "IO Enabled - " : "IO Disabled - "));
1224 len += snprintf(buf + len, PAGE_SIZE - len,
1226 (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV ?
1227 "Rcv Enabled\n" : "Rcv Disabled\n"));
1228 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1229 if (i >= LPFC_CHECK_CPU_CNT)
1231 len += snprintf(buf + len, PAGE_SIZE - len,
1232 "%02d: xmit x%08x ccmpl x%08x "
1233 "cmpl x%08x rcv x%08x\n",
1234 i, phba->cpucheck_xmt_io[i],
1235 phba->cpucheck_ccmpl_io[i],
1236 phba->cpucheck_cmpl_io[i],
1237 phba->cpucheck_rcv_io[i]);
1238 tot_xmt += phba->cpucheck_xmt_io[i];
1239 tot_rcv += phba->cpucheck_rcv_io[i];
1240 tot_cmpl += phba->cpucheck_cmpl_io[i];
1241 tot_ccmpl += phba->cpucheck_ccmpl_io[i];
1243 len += snprintf(buf + len, PAGE_SIZE - len,
1244 "tot:xmit x%08x ccmpl x%08x cmpl x%08x rcv x%08x\n",
1245 tot_xmt, tot_ccmpl, tot_cmpl, tot_rcv);
1252 * lpfc_debugfs_disc_trc - Store discovery trace log
1253 * @vport: The vport to associate this trace string with for retrieval.
1254 * @mask: Log entry classification.
1255 * @fmt: Format string to be displayed when dumping the log.
1256 * @data1: 1st data parameter to be applied to @fmt.
1257 * @data2: 2nd data parameter to be applied to @fmt.
1258 * @data3: 3rd data parameter to be applied to @fmt.
1261 * This routine is used by the driver code to add a debugfs log entry to the
1262 * discovery trace buffer associated with @vport. Only entries with a @mask that
1263 * match the current debugfs discovery mask will be saved. Entries that do not
1264 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1265 * printf when displaying the log.
1268 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1269 uint32_t data1, uint32_t data2, uint32_t data3)
1271 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1272 struct lpfc_debugfs_trc *dtp;
1275 if (!(lpfc_debugfs_mask_disc_trc & mask))
1278 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1279 !vport || !vport->disc_trc)
1282 index = atomic_inc_return(&vport->disc_trc_cnt) &
1283 (lpfc_debugfs_max_disc_trc - 1);
1284 dtp = vport->disc_trc + index;
1289 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1296 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
1297 * @phba: The phba to associate this trace string with for retrieval.
1298 * @fmt: Format string to be displayed when dumping the log.
1299 * @data1: 1st data parameter to be applied to @fmt.
1300 * @data2: 2nd data parameter to be applied to @fmt.
1301 * @data3: 3rd data parameter to be applied to @fmt.
1304 * This routine is used by the driver code to add a debugfs log entry to the
1305 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1306 * @data3 are used like printf when displaying the log.
1309 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1310 uint32_t data1, uint32_t data2, uint32_t data3)
1312 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1313 struct lpfc_debugfs_trc *dtp;
1316 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1317 !phba || !phba->slow_ring_trc)
1320 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1321 (lpfc_debugfs_max_slow_ring_trc - 1);
1322 dtp = phba->slow_ring_trc + index;
1327 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1334 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1335 * @phba: The phba to associate this trace string with for retrieval.
1336 * @fmt: Format string to be displayed when dumping the log.
1337 * @data1: 1st data parameter to be applied to @fmt.
1338 * @data2: 2nd data parameter to be applied to @fmt.
1339 * @data3: 3rd data parameter to be applied to @fmt.
1342 * This routine is used by the driver code to add a debugfs log entry to the
1343 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1344 * @data3 are used like printf when displaying the log.
1347 lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1348 uint16_t data1, uint16_t data2, uint32_t data3)
1350 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1351 struct lpfc_debugfs_nvmeio_trc *dtp;
1354 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1357 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1358 (phba->nvmeio_trc_size - 1);
1359 dtp = phba->nvmeio_trc + index;
1367 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1369 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
1370 * @inode: The inode pointer that contains a vport pointer.
1371 * @file: The file pointer to attach the log output.
1374 * This routine is the entry point for the debugfs open file operation. It gets
1375 * the vport from the i_private field in @inode, allocates the necessary buffer
1376 * for the log, fills the buffer from the in-memory log for this vport, and then
1377 * returns a pointer to that log in the private_data field in @file.
1380 * This function returns zero if successful. On error it will return a negative
1384 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1386 struct lpfc_vport *vport = inode->i_private;
1387 struct lpfc_debug *debug;
1391 if (!lpfc_debugfs_max_disc_trc) {
1396 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1400 /* Round to page boundary */
1401 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1402 size = PAGE_ALIGN(size);
1404 debug->buffer = kmalloc(size, GFP_KERNEL);
1405 if (!debug->buffer) {
1410 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1411 file->private_data = debug;
1419 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
1420 * @inode: The inode pointer that contains a vport pointer.
1421 * @file: The file pointer to attach the log output.
1424 * This routine is the entry point for the debugfs open file operation. It gets
1425 * the vport from the i_private field in @inode, allocates the necessary buffer
1426 * for the log, fills the buffer from the in-memory log for this vport, and then
1427 * returns a pointer to that log in the private_data field in @file.
1430 * This function returns zero if successful. On error it will return a negative
1434 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1436 struct lpfc_hba *phba = inode->i_private;
1437 struct lpfc_debug *debug;
1441 if (!lpfc_debugfs_max_slow_ring_trc) {
1446 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1450 /* Round to page boundary */
1451 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1452 size = PAGE_ALIGN(size);
1454 debug->buffer = kmalloc(size, GFP_KERNEL);
1455 if (!debug->buffer) {
1460 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
1461 file->private_data = debug;
1469 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
1470 * @inode: The inode pointer that contains a vport pointer.
1471 * @file: The file pointer to attach the log output.
1474 * This routine is the entry point for the debugfs open file operation. It gets
1475 * the vport from the i_private field in @inode, allocates the necessary buffer
1476 * for the log, fills the buffer from the in-memory log for this vport, and then
1477 * returns a pointer to that log in the private_data field in @file.
1480 * This function returns zero if successful. On error it will return a negative
1484 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
1486 struct lpfc_hba *phba = inode->i_private;
1487 struct lpfc_debug *debug;
1490 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1494 /* Round to page boundary */
1495 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
1496 if (!debug->buffer) {
1501 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
1503 file->private_data = debug;
1511 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
1512 * @inode: The inode pointer that contains a vport pointer.
1513 * @file: The file pointer to attach the log output.
1516 * This routine is the entry point for the debugfs open file operation. It gets
1517 * the vport from the i_private field in @inode, allocates the necessary buffer
1518 * for the log, fills the buffer from the in-memory log for this vport, and then
1519 * returns a pointer to that log in the private_data field in @file.
1522 * This function returns zero if successful. On error it will return a negative
1526 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
1528 struct lpfc_hba *phba = inode->i_private;
1529 struct lpfc_debug *debug;
1532 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1536 /* Round to page boundary */
1537 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
1538 if (!debug->buffer) {
1543 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
1544 LPFC_DUMPHBASLIM_SIZE);
1545 file->private_data = debug;
1553 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
1554 * @inode: The inode pointer that contains a vport pointer.
1555 * @file: The file pointer to attach the log output.
1558 * This routine is the entry point for the debugfs open file operation. It gets
1559 * the vport from the i_private field in @inode, allocates the necessary buffer
1560 * for the log, fills the buffer from the in-memory log for this vport, and then
1561 * returns a pointer to that log in the private_data field in @file.
1564 * This function returns zero if successful. On error it will return a negative
1568 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
1570 struct lpfc_hba *phba = inode->i_private;
1571 struct lpfc_debug *debug;
1574 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1578 /* Round to page boundary */
1579 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
1580 if (!debug->buffer) {
1585 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
1586 LPFC_DUMPHOSTSLIM_SIZE);
1587 file->private_data = debug;
1595 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
1597 struct lpfc_debug *debug;
1600 if (!_dump_buf_data)
1603 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1607 /* Round to page boundary */
1608 pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
1609 __func__, _dump_buf_data);
1610 debug->buffer = _dump_buf_data;
1611 if (!debug->buffer) {
1616 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
1617 file->private_data = debug;
1625 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
1627 struct lpfc_debug *debug;
1633 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1637 /* Round to page boundary */
1638 pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n",
1639 __func__, _dump_buf_dif, file);
1640 debug->buffer = _dump_buf_dif;
1641 if (!debug->buffer) {
1646 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
1647 file->private_data = debug;
1655 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
1656 size_t nbytes, loff_t *ppos)
1659 * The Data/DIF buffers only save one failing IO
1660 * The write op is used as a reset mechanism after an IO has
1661 * already been saved to the next one can be saved
1663 spin_lock(&_dump_buf_lock);
1665 memset((void *)_dump_buf_data, 0,
1666 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
1667 memset((void *)_dump_buf_dif, 0,
1668 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
1672 spin_unlock(&_dump_buf_lock);
1678 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1679 size_t nbytes, loff_t *ppos)
1681 struct dentry *dent = file->f_path.dentry;
1682 struct lpfc_hba *phba = file->private_data;
1687 if (dent == phba->debug_writeGuard)
1688 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1689 else if (dent == phba->debug_writeApp)
1690 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
1691 else if (dent == phba->debug_writeRef)
1692 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
1693 else if (dent == phba->debug_readGuard)
1694 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1695 else if (dent == phba->debug_readApp)
1696 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
1697 else if (dent == phba->debug_readRef)
1698 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1699 else if (dent == phba->debug_InjErrNPortID)
1700 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1701 else if (dent == phba->debug_InjErrWWPN) {
1702 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1703 tmp = cpu_to_be64(tmp);
1704 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1705 } else if (dent == phba->debug_InjErrLBA) {
1706 if (phba->lpfc_injerr_lba == (sector_t)(-1))
1707 cnt = snprintf(cbuf, 32, "off\n");
1709 cnt = snprintf(cbuf, 32, "0x%llx\n",
1710 (uint64_t) phba->lpfc_injerr_lba);
1712 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1713 "0547 Unknown debugfs error injection entry\n");
1715 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1719 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1720 size_t nbytes, loff_t *ppos)
1722 struct dentry *dent = file->f_path.dentry;
1723 struct lpfc_hba *phba = file->private_data;
1728 memset(dstbuf, 0, 33);
1729 size = (nbytes < 32) ? nbytes : 32;
1730 if (copy_from_user(dstbuf, buf, size))
1733 if (dent == phba->debug_InjErrLBA) {
1734 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1735 tmp = (uint64_t)(-1);
1738 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
1741 if (dent == phba->debug_writeGuard)
1742 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1743 else if (dent == phba->debug_writeApp)
1744 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1745 else if (dent == phba->debug_writeRef)
1746 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1747 else if (dent == phba->debug_readGuard)
1748 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
1749 else if (dent == phba->debug_readApp)
1750 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1751 else if (dent == phba->debug_readRef)
1752 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1753 else if (dent == phba->debug_InjErrLBA)
1754 phba->lpfc_injerr_lba = (sector_t)tmp;
1755 else if (dent == phba->debug_InjErrNPortID)
1756 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1757 else if (dent == phba->debug_InjErrWWPN) {
1758 tmp = cpu_to_be64(tmp);
1759 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1761 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1762 "0548 Unknown debugfs error injection entry\n");
1768 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1774 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1775 * @inode: The inode pointer that contains a vport pointer.
1776 * @file: The file pointer to attach the log output.
1779 * This routine is the entry point for the debugfs open file operation. It gets
1780 * the vport from the i_private field in @inode, allocates the necessary buffer
1781 * for the log, fills the buffer from the in-memory log for this vport, and then
1782 * returns a pointer to that log in the private_data field in @file.
1785 * This function returns zero if successful. On error it will return a negative
1789 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1791 struct lpfc_vport *vport = inode->i_private;
1792 struct lpfc_debug *debug;
1795 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1799 /* Round to page boundary */
1800 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1801 if (!debug->buffer) {
1806 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1807 LPFC_NODELIST_SIZE);
1808 file->private_data = debug;
1816 * lpfc_debugfs_lseek - Seek through a debugfs file
1817 * @file: The file pointer to seek through.
1818 * @off: The offset to seek to or the amount to seek by.
1819 * @whence: Indicates how to seek.
1822 * This routine is the entry point for the debugfs lseek file operation. The
1823 * @whence parameter indicates whether @off is the offset to directly seek to,
1824 * or if it is a value to seek forward or reverse by. This function figures out
1825 * what the new offset of the debugfs file will be and assigns that value to the
1826 * f_pos field of @file.
1829 * This function returns the new offset if successful and returns a negative
1830 * error if unable to process the seek.
1833 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1835 struct lpfc_debug *debug = file->private_data;
1836 return fixed_size_llseek(file, off, whence, debug->len);
1840 * lpfc_debugfs_read - Read a debugfs file
1841 * @file: The file pointer to read from.
1842 * @buf: The buffer to copy the data to.
1843 * @nbytes: The number of bytes to read.
1844 * @ppos: The position in the file to start reading from.
1847 * This routine reads data from from the buffer indicated in the private_data
1848 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1852 * This function returns the amount of data that was read (this could be less
1853 * than @nbytes if the end of the file was reached) or a negative error value.
1856 lpfc_debugfs_read(struct file *file, char __user *buf,
1857 size_t nbytes, loff_t *ppos)
1859 struct lpfc_debug *debug = file->private_data;
1861 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1866 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1867 * @inode: The inode pointer that contains a vport pointer. (unused)
1868 * @file: The file pointer that contains the buffer to release.
1871 * This routine frees the buffer that was allocated when the debugfs file was
1875 * This function returns zero.
1878 lpfc_debugfs_release(struct inode *inode, struct file *file)
1880 struct lpfc_debug *debug = file->private_data;
1882 kfree(debug->buffer);
1889 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1891 struct lpfc_debug *debug = file->private_data;
1893 debug->buffer = NULL;
1901 lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
1903 struct lpfc_vport *vport = inode->i_private;
1904 struct lpfc_debug *debug;
1907 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1911 /* Round to page boundary */
1912 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
1913 if (!debug->buffer) {
1918 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
1919 LPFC_NVMESTAT_SIZE);
1921 debug->i_private = inode->i_private;
1922 file->private_data = debug;
1930 lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
1931 size_t nbytes, loff_t *ppos)
1933 struct lpfc_debug *debug = file->private_data;
1934 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
1935 struct lpfc_hba *phba = vport->phba;
1936 struct lpfc_nvmet_tgtport *tgtp;
1940 if (!phba->targetport)
1946 /* Protect copy from user */
1947 if (!access_ok(VERIFY_READ, buf, nbytes))
1950 memset(mybuf, 0, sizeof(mybuf));
1952 if (copy_from_user(mybuf, buf, nbytes))
1956 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1957 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
1958 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
1959 atomic_set(&tgtp->rcv_ls_req_in, 0);
1960 atomic_set(&tgtp->rcv_ls_req_out, 0);
1961 atomic_set(&tgtp->rcv_ls_req_drop, 0);
1962 atomic_set(&tgtp->xmt_ls_abort, 0);
1963 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
1964 atomic_set(&tgtp->xmt_ls_rsp, 0);
1965 atomic_set(&tgtp->xmt_ls_drop, 0);
1966 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
1967 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
1969 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
1970 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
1971 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
1972 atomic_set(&tgtp->xmt_fcp_drop, 0);
1973 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
1974 atomic_set(&tgtp->xmt_fcp_read, 0);
1975 atomic_set(&tgtp->xmt_fcp_write, 0);
1976 atomic_set(&tgtp->xmt_fcp_rsp, 0);
1977 atomic_set(&tgtp->xmt_fcp_release, 0);
1978 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
1979 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
1980 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
1982 atomic_set(&tgtp->xmt_fcp_abort, 0);
1983 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
1984 atomic_set(&tgtp->xmt_abort_sol, 0);
1985 atomic_set(&tgtp->xmt_abort_unsol, 0);
1986 atomic_set(&tgtp->xmt_abort_rsp, 0);
1987 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
1993 lpfc_debugfs_nvmektime_open(struct inode *inode, struct file *file)
1995 struct lpfc_vport *vport = inode->i_private;
1996 struct lpfc_debug *debug;
1999 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2003 /* Round to page boundary */
2004 debug->buffer = kmalloc(LPFC_NVMEKTIME_SIZE, GFP_KERNEL);
2005 if (!debug->buffer) {
2010 debug->len = lpfc_debugfs_nvmektime_data(vport, debug->buffer,
2011 LPFC_NVMEKTIME_SIZE);
2013 debug->i_private = inode->i_private;
2014 file->private_data = debug;
2022 lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf,
2023 size_t nbytes, loff_t *ppos)
2025 struct lpfc_debug *debug = file->private_data;
2026 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2027 struct lpfc_hba *phba = vport->phba;
2034 /* Protect copy from user */
2035 if (!access_ok(VERIFY_READ, buf, nbytes))
2038 memset(mybuf, 0, sizeof(mybuf));
2040 if (copy_from_user(mybuf, buf, nbytes))
2044 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2045 phba->ktime_data_samples = 0;
2046 phba->ktime_status_samples = 0;
2047 phba->ktime_seg1_total = 0;
2048 phba->ktime_seg1_max = 0;
2049 phba->ktime_seg1_min = 0xffffffff;
2050 phba->ktime_seg2_total = 0;
2051 phba->ktime_seg2_max = 0;
2052 phba->ktime_seg2_min = 0xffffffff;
2053 phba->ktime_seg3_total = 0;
2054 phba->ktime_seg3_max = 0;
2055 phba->ktime_seg3_min = 0xffffffff;
2056 phba->ktime_seg4_total = 0;
2057 phba->ktime_seg4_max = 0;
2058 phba->ktime_seg4_min = 0xffffffff;
2059 phba->ktime_seg5_total = 0;
2060 phba->ktime_seg5_max = 0;
2061 phba->ktime_seg5_min = 0xffffffff;
2062 phba->ktime_seg6_total = 0;
2063 phba->ktime_seg6_max = 0;
2064 phba->ktime_seg6_min = 0xffffffff;
2065 phba->ktime_seg7_total = 0;
2066 phba->ktime_seg7_max = 0;
2067 phba->ktime_seg7_min = 0xffffffff;
2068 phba->ktime_seg8_total = 0;
2069 phba->ktime_seg8_max = 0;
2070 phba->ktime_seg8_min = 0xffffffff;
2071 phba->ktime_seg9_total = 0;
2072 phba->ktime_seg9_max = 0;
2073 phba->ktime_seg9_min = 0xffffffff;
2074 phba->ktime_seg10_total = 0;
2075 phba->ktime_seg10_max = 0;
2076 phba->ktime_seg10_min = 0xffffffff;
2079 return strlen(pbuf);
2080 } else if ((strncmp(pbuf, "off",
2081 sizeof("off") - 1) == 0)) {
2083 return strlen(pbuf);
2084 } else if ((strncmp(pbuf, "zero",
2085 sizeof("zero") - 1) == 0)) {
2086 phba->ktime_data_samples = 0;
2087 phba->ktime_status_samples = 0;
2088 phba->ktime_seg1_total = 0;
2089 phba->ktime_seg1_max = 0;
2090 phba->ktime_seg1_min = 0xffffffff;
2091 phba->ktime_seg2_total = 0;
2092 phba->ktime_seg2_max = 0;
2093 phba->ktime_seg2_min = 0xffffffff;
2094 phba->ktime_seg3_total = 0;
2095 phba->ktime_seg3_max = 0;
2096 phba->ktime_seg3_min = 0xffffffff;
2097 phba->ktime_seg4_total = 0;
2098 phba->ktime_seg4_max = 0;
2099 phba->ktime_seg4_min = 0xffffffff;
2100 phba->ktime_seg5_total = 0;
2101 phba->ktime_seg5_max = 0;
2102 phba->ktime_seg5_min = 0xffffffff;
2103 phba->ktime_seg6_total = 0;
2104 phba->ktime_seg6_max = 0;
2105 phba->ktime_seg6_min = 0xffffffff;
2106 phba->ktime_seg7_total = 0;
2107 phba->ktime_seg7_max = 0;
2108 phba->ktime_seg7_min = 0xffffffff;
2109 phba->ktime_seg8_total = 0;
2110 phba->ktime_seg8_max = 0;
2111 phba->ktime_seg8_min = 0xffffffff;
2112 phba->ktime_seg9_total = 0;
2113 phba->ktime_seg9_max = 0;
2114 phba->ktime_seg9_min = 0xffffffff;
2115 phba->ktime_seg10_total = 0;
2116 phba->ktime_seg10_max = 0;
2117 phba->ktime_seg10_min = 0xffffffff;
2118 return strlen(pbuf);
2124 lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2126 struct lpfc_hba *phba = inode->i_private;
2127 struct lpfc_debug *debug;
2130 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2134 /* Round to page boundary */
2135 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2136 if (!debug->buffer) {
2141 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2142 LPFC_NVMEIO_TRC_SIZE);
2144 debug->i_private = inode->i_private;
2145 file->private_data = debug;
2153 lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2154 size_t nbytes, loff_t *ppos)
2156 struct lpfc_debug *debug = file->private_data;
2157 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2166 /* Protect copy from user */
2167 if (!access_ok(VERIFY_READ, buf, nbytes))
2170 memset(mybuf, 0, sizeof(mybuf));
2172 if (copy_from_user(mybuf, buf, nbytes))
2176 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2177 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2178 "0570 nvmeio_trc_off\n");
2179 phba->nvmeio_trc_output_idx = 0;
2180 phba->nvmeio_trc_on = 0;
2181 return strlen(pbuf);
2182 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2184 "0571 nvmeio_trc_on\n");
2185 phba->nvmeio_trc_output_idx = 0;
2186 phba->nvmeio_trc_on = 1;
2187 return strlen(pbuf);
2190 /* We must be off to allocate the trace buffer */
2191 if (phba->nvmeio_trc_on != 0)
2194 /* If not on or off, the parameter is the trace buffer size */
2195 i = kstrtoul(pbuf, 0, &sz);
2198 phba->nvmeio_trc_size = (uint32_t)sz;
2200 /* It must be a power of 2 - round down */
2207 if (phba->nvmeio_trc_size != sz)
2208 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2209 "0572 nvmeio_trc_size changed to %ld\n",
2211 phba->nvmeio_trc_size = (uint32_t)sz;
2213 /* If one previously exists, free it */
2214 kfree(phba->nvmeio_trc);
2216 /* Allocate new trace buffer and initialize */
2217 phba->nvmeio_trc = kmalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
2219 if (!phba->nvmeio_trc) {
2220 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2221 "0573 Cannot create debugfs "
2222 "nvmeio_trc buffer\n");
2225 memset(phba->nvmeio_trc, 0,
2226 (sizeof(struct lpfc_debugfs_nvmeio_trc) * sz));
2227 atomic_set(&phba->nvmeio_trc_cnt, 0);
2228 phba->nvmeio_trc_on = 0;
2229 phba->nvmeio_trc_output_idx = 0;
2231 return strlen(pbuf);
2235 lpfc_debugfs_cpucheck_open(struct inode *inode, struct file *file)
2237 struct lpfc_vport *vport = inode->i_private;
2238 struct lpfc_debug *debug;
2241 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2245 /* Round to page boundary */
2246 debug->buffer = kmalloc(LPFC_CPUCHECK_SIZE, GFP_KERNEL);
2247 if (!debug->buffer) {
2252 debug->len = lpfc_debugfs_cpucheck_data(vport, debug->buffer,
2253 LPFC_NVMEKTIME_SIZE);
2255 debug->i_private = inode->i_private;
2256 file->private_data = debug;
2264 lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
2265 size_t nbytes, loff_t *ppos)
2267 struct lpfc_debug *debug = file->private_data;
2268 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2269 struct lpfc_hba *phba = vport->phba;
2277 /* Protect copy from user */
2278 if (!access_ok(VERIFY_READ, buf, nbytes))
2281 memset(mybuf, 0, sizeof(mybuf));
2283 if (copy_from_user(mybuf, buf, nbytes))
2287 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2288 if (phba->nvmet_support)
2289 phba->cpucheck_on |= LPFC_CHECK_NVMET_IO;
2291 phba->cpucheck_on |= LPFC_CHECK_NVME_IO;
2292 return strlen(pbuf);
2293 } else if ((strncmp(pbuf, "rcv",
2294 sizeof("rcv") - 1) == 0)) {
2295 if (phba->nvmet_support)
2296 phba->cpucheck_on |= LPFC_CHECK_NVMET_RCV;
2299 return strlen(pbuf);
2300 } else if ((strncmp(pbuf, "off",
2301 sizeof("off") - 1) == 0)) {
2302 phba->cpucheck_on = LPFC_CHECK_OFF;
2303 return strlen(pbuf);
2304 } else if ((strncmp(pbuf, "zero",
2305 sizeof("zero") - 1) == 0)) {
2306 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
2307 if (i >= LPFC_CHECK_CPU_CNT)
2309 phba->cpucheck_rcv_io[i] = 0;
2310 phba->cpucheck_xmt_io[i] = 0;
2311 phba->cpucheck_cmpl_io[i] = 0;
2312 phba->cpucheck_ccmpl_io[i] = 0;
2314 return strlen(pbuf);
2320 * ---------------------------------
2321 * iDiag debugfs file access methods
2322 * ---------------------------------
2324 * All access methods are through the proper SLI4 PCI function's debugfs
2327 * /sys/kernel/debug/lpfc/fn<#>/iDiag
2331 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
2332 * @buf: The pointer to the user space buffer.
2333 * @nbytes: The number of bytes in the user space buffer.
2334 * @idiag_cmd: pointer to the idiag command struct.
2336 * This routine reads data from debugfs user space buffer and parses the
2337 * buffer for getting the idiag command and arguments. The while space in
2338 * between the set of data is used as the parsing separator.
2340 * This routine returns 0 when successful, it returns proper error code
2341 * back to the user space in error conditions.
2343 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
2344 struct lpfc_idiag_cmd *idiag_cmd)
2347 char *pbuf, *step_str;
2351 /* Protect copy from user */
2352 if (!access_ok(VERIFY_READ, buf, nbytes))
2355 memset(mybuf, 0, sizeof(mybuf));
2356 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
2357 bsize = min(nbytes, (sizeof(mybuf)-1));
2359 if (copy_from_user(mybuf, buf, bsize))
2362 step_str = strsep(&pbuf, "\t ");
2364 /* The opcode must present */
2368 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
2369 if (idiag_cmd->opcode == 0)
2372 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
2373 step_str = strsep(&pbuf, "\t ");
2376 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
2382 * lpfc_idiag_open - idiag open debugfs
2383 * @inode: The inode pointer that contains a pointer to phba.
2384 * @file: The file pointer to attach the file operation.
2387 * This routine is the entry point for the debugfs open file operation. It
2388 * gets the reference to phba from the i_private field in @inode, it then
2389 * allocates buffer for the file operation, performs the necessary PCI config
2390 * space read into the allocated buffer according to the idiag user command
2391 * setup, and then returns a pointer to buffer in the private_data field in
2395 * This function returns zero if successful. On error it will return an
2396 * negative error value.
2399 lpfc_idiag_open(struct inode *inode, struct file *file)
2401 struct lpfc_debug *debug;
2403 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2407 debug->i_private = inode->i_private;
2408 debug->buffer = NULL;
2409 file->private_data = debug;
2415 * lpfc_idiag_release - Release idiag access file operation
2416 * @inode: The inode pointer that contains a vport pointer. (unused)
2417 * @file: The file pointer that contains the buffer to release.
2420 * This routine is the generic release routine for the idiag access file
2421 * operation, it frees the buffer that was allocated when the debugfs file
2425 * This function returns zero.
2428 lpfc_idiag_release(struct inode *inode, struct file *file)
2430 struct lpfc_debug *debug = file->private_data;
2432 /* Free the buffers to the file operation */
2433 kfree(debug->buffer);
2440 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
2441 * @inode: The inode pointer that contains a vport pointer. (unused)
2442 * @file: The file pointer that contains the buffer to release.
2445 * This routine frees the buffer that was allocated when the debugfs file
2446 * was opened. It also reset the fields in the idiag command struct in the
2447 * case of command for write operation.
2450 * This function returns zero.
2453 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
2455 struct lpfc_debug *debug = file->private_data;
2457 if (debug->op == LPFC_IDIAG_OP_WR) {
2458 switch (idiag.cmd.opcode) {
2459 case LPFC_IDIAG_CMD_PCICFG_WR:
2460 case LPFC_IDIAG_CMD_PCICFG_ST:
2461 case LPFC_IDIAG_CMD_PCICFG_CL:
2462 case LPFC_IDIAG_CMD_QUEACC_WR:
2463 case LPFC_IDIAG_CMD_QUEACC_ST:
2464 case LPFC_IDIAG_CMD_QUEACC_CL:
2465 memset(&idiag, 0, sizeof(idiag));
2472 /* Free the buffers to the file operation */
2473 kfree(debug->buffer);
2480 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
2481 * @file: The file pointer to read from.
2482 * @buf: The buffer to copy the data to.
2483 * @nbytes: The number of bytes to read.
2484 * @ppos: The position in the file to start reading from.
2487 * This routine reads data from the @phba pci config space according to the
2488 * idiag command, and copies to user @buf. Depending on the PCI config space
2489 * read command setup, it does either a single register read of a byte
2490 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
2491 * registers from the 4K extended PCI config space.
2494 * This function returns the amount of data that was read (this could be less
2495 * than @nbytes if the end of the file was reached) or a negative error value.
2498 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
2501 struct lpfc_debug *debug = file->private_data;
2502 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2503 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
2506 struct pci_dev *pdev;
2511 pdev = phba->pcidev;
2515 /* This is a user read operation */
2516 debug->op = LPFC_IDIAG_OP_RD;
2519 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
2522 pbuffer = debug->buffer;
2527 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2528 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2529 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2533 /* Read single PCI config space register */
2535 case SIZE_U8: /* byte (8 bits) */
2536 pci_read_config_byte(pdev, where, &u8val);
2537 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2538 "%03x: %02x\n", where, u8val);
2540 case SIZE_U16: /* word (16 bits) */
2541 pci_read_config_word(pdev, where, &u16val);
2542 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2543 "%03x: %04x\n", where, u16val);
2545 case SIZE_U32: /* double word (32 bits) */
2546 pci_read_config_dword(pdev, where, &u32val);
2547 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2548 "%03x: %08x\n", where, u32val);
2550 case LPFC_PCI_CFG_BROWSE: /* browse all */
2558 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2562 /* Browse all PCI config space registers */
2563 offset_label = idiag.offset.last_rd;
2564 offset = offset_label;
2566 /* Read PCI config space */
2567 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2568 "%03x: ", offset_label);
2570 pci_read_config_dword(pdev, offset, &u32val);
2571 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2573 offset += sizeof(uint32_t);
2574 if (offset >= LPFC_PCI_CFG_SIZE) {
2575 len += snprintf(pbuffer+len,
2576 LPFC_PCI_CFG_SIZE-len, "\n");
2579 index -= sizeof(uint32_t);
2581 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2583 else if (!(index % (8 * sizeof(uint32_t)))) {
2584 offset_label += (8 * sizeof(uint32_t));
2585 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2586 "\n%03x: ", offset_label);
2590 /* Set up the offset for next portion of pci cfg read */
2592 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
2593 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
2594 idiag.offset.last_rd = 0;
2596 idiag.offset.last_rd = 0;
2598 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2602 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
2603 * @file: The file pointer to read from.
2604 * @buf: The buffer to copy the user data from.
2605 * @nbytes: The number of bytes to get.
2606 * @ppos: The position in the file to start reading from.
2608 * This routine get the debugfs idiag command struct from user space and
2609 * then perform the syntax check for PCI config space read or write command
2610 * accordingly. In the case of PCI config space read command, it sets up
2611 * the command in the idiag command struct for the debugfs read operation.
2612 * In the case of PCI config space write operation, it executes the write
2613 * operation into the PCI config space accordingly.
2615 * It returns the @nbytges passing in from debugfs user space when successful.
2616 * In case of error conditions, it returns proper error code back to the user
2620 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
2621 size_t nbytes, loff_t *ppos)
2623 struct lpfc_debug *debug = file->private_data;
2624 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2625 uint32_t where, value, count;
2629 struct pci_dev *pdev;
2632 pdev = phba->pcidev;
2636 /* This is a user write operation */
2637 debug->op = LPFC_IDIAG_OP_WR;
2639 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2643 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
2644 /* Sanity check on PCI config read command line arguments */
2645 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
2647 /* Read command from PCI config space, set up command fields */
2648 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2649 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2650 if (count == LPFC_PCI_CFG_BROWSE) {
2651 if (where % sizeof(uint32_t))
2653 /* Starting offset to browse */
2654 idiag.offset.last_rd = where;
2655 } else if ((count != sizeof(uint8_t)) &&
2656 (count != sizeof(uint16_t)) &&
2657 (count != sizeof(uint32_t)))
2659 if (count == sizeof(uint8_t)) {
2660 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2662 if (where % sizeof(uint8_t))
2665 if (count == sizeof(uint16_t)) {
2666 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2668 if (where % sizeof(uint16_t))
2671 if (count == sizeof(uint32_t)) {
2672 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2674 if (where % sizeof(uint32_t))
2677 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
2678 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
2679 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2680 /* Sanity check on PCI config write command line arguments */
2681 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
2683 /* Write command to PCI config space, read-modify-write */
2684 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2685 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2686 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
2688 if ((count != sizeof(uint8_t)) &&
2689 (count != sizeof(uint16_t)) &&
2690 (count != sizeof(uint32_t)))
2692 if (count == sizeof(uint8_t)) {
2693 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2695 if (where % sizeof(uint8_t))
2697 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2698 pci_write_config_byte(pdev, where,
2700 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2701 rc = pci_read_config_byte(pdev, where, &u8val);
2703 u8val |= (uint8_t)value;
2704 pci_write_config_byte(pdev, where,
2708 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2709 rc = pci_read_config_byte(pdev, where, &u8val);
2711 u8val &= (uint8_t)(~value);
2712 pci_write_config_byte(pdev, where,
2717 if (count == sizeof(uint16_t)) {
2718 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2720 if (where % sizeof(uint16_t))
2722 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2723 pci_write_config_word(pdev, where,
2725 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2726 rc = pci_read_config_word(pdev, where, &u16val);
2728 u16val |= (uint16_t)value;
2729 pci_write_config_word(pdev, where,
2733 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2734 rc = pci_read_config_word(pdev, where, &u16val);
2736 u16val &= (uint16_t)(~value);
2737 pci_write_config_word(pdev, where,
2742 if (count == sizeof(uint32_t)) {
2743 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2745 if (where % sizeof(uint32_t))
2747 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2748 pci_write_config_dword(pdev, where, value);
2749 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2750 rc = pci_read_config_dword(pdev, where,
2754 pci_write_config_dword(pdev, where,
2758 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2759 rc = pci_read_config_dword(pdev, where,
2763 pci_write_config_dword(pdev, where,
2769 /* All other opecodes are illegal for now */
2774 memset(&idiag, 0, sizeof(idiag));
2779 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
2780 * @file: The file pointer to read from.
2781 * @buf: The buffer to copy the data to.
2782 * @nbytes: The number of bytes to read.
2783 * @ppos: The position in the file to start reading from.
2786 * This routine reads data from the @phba pci bar memory mapped space
2787 * according to the idiag command, and copies to user @buf.
2790 * This function returns the amount of data that was read (this could be less
2791 * than @nbytes if the end of the file was reached) or a negative error value.
2794 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
2797 struct lpfc_debug *debug = file->private_data;
2798 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2799 int offset_label, offset, offset_run, len = 0, index;
2800 int bar_num, acc_range, bar_size;
2802 void __iomem *mem_mapped_bar;
2804 struct pci_dev *pdev;
2807 pdev = phba->pcidev;
2811 /* This is a user read operation */
2812 debug->op = LPFC_IDIAG_OP_RD;
2815 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
2818 pbuffer = debug->buffer;
2823 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
2824 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2825 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
2826 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
2827 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
2834 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2835 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2836 if (bar_num == IDIAG_BARACC_BAR_0)
2837 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2838 else if (bar_num == IDIAG_BARACC_BAR_1)
2839 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2840 else if (bar_num == IDIAG_BARACC_BAR_2)
2841 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2844 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2845 if (bar_num == IDIAG_BARACC_BAR_0)
2846 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2852 /* Read single PCI bar space register */
2853 if (acc_range == SINGLE_WORD) {
2854 offset_run = offset;
2855 u32val = readl(mem_mapped_bar + offset_run);
2856 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2857 "%05x: %08x\n", offset_run, u32val);
2861 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2865 /* Browse all PCI bar space registers */
2866 offset_label = idiag.offset.last_rd;
2867 offset_run = offset_label;
2869 /* Read PCI bar memory mapped space */
2870 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2871 "%05x: ", offset_label);
2872 index = LPFC_PCI_BAR_RD_SIZE;
2874 u32val = readl(mem_mapped_bar + offset_run);
2875 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2877 offset_run += sizeof(uint32_t);
2878 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2879 if (offset_run >= bar_size) {
2880 len += snprintf(pbuffer+len,
2881 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2885 if (offset_run >= offset +
2886 (acc_range * sizeof(uint32_t))) {
2887 len += snprintf(pbuffer+len,
2888 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2892 index -= sizeof(uint32_t);
2894 len += snprintf(pbuffer+len,
2895 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2896 else if (!(index % (8 * sizeof(uint32_t)))) {
2897 offset_label += (8 * sizeof(uint32_t));
2898 len += snprintf(pbuffer+len,
2899 LPFC_PCI_BAR_RD_BUF_SIZE-len,
2900 "\n%05x: ", offset_label);
2904 /* Set up the offset for next portion of pci bar read */
2906 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
2907 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2908 if (idiag.offset.last_rd >= bar_size)
2909 idiag.offset.last_rd = 0;
2911 if (offset_run >= offset +
2912 (acc_range * sizeof(uint32_t)))
2913 idiag.offset.last_rd = offset;
2916 if (acc_range == LPFC_PCI_BAR_BROWSE)
2917 idiag.offset.last_rd = 0;
2919 idiag.offset.last_rd = offset;
2922 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2926 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
2927 * @file: The file pointer to read from.
2928 * @buf: The buffer to copy the user data from.
2929 * @nbytes: The number of bytes to get.
2930 * @ppos: The position in the file to start reading from.
2932 * This routine get the debugfs idiag command struct from user space and
2933 * then perform the syntax check for PCI bar memory mapped space read or
2934 * write command accordingly. In the case of PCI bar memory mapped space
2935 * read command, it sets up the command in the idiag command struct for
2936 * the debugfs read operation. In the case of PCI bar memorpy mapped space
2937 * write operation, it executes the write operation into the PCI bar memory
2938 * mapped space accordingly.
2940 * It returns the @nbytges passing in from debugfs user space when successful.
2941 * In case of error conditions, it returns proper error code back to the user
2945 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
2946 size_t nbytes, loff_t *ppos)
2948 struct lpfc_debug *debug = file->private_data;
2949 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2950 uint32_t bar_num, bar_size, offset, value, acc_range;
2951 struct pci_dev *pdev;
2952 void __iomem *mem_mapped_bar;
2957 pdev = phba->pcidev;
2961 /* This is a user write operation */
2962 debug->op = LPFC_IDIAG_OP_WR;
2964 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2968 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2969 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2971 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2972 if ((bar_num != IDIAG_BARACC_BAR_0) &&
2973 (bar_num != IDIAG_BARACC_BAR_1) &&
2974 (bar_num != IDIAG_BARACC_BAR_2))
2976 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2977 if (bar_num != IDIAG_BARACC_BAR_0)
2982 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2983 if (bar_num == IDIAG_BARACC_BAR_0) {
2984 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2985 LPFC_PCI_IF0_BAR0_SIZE;
2986 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2987 } else if (bar_num == IDIAG_BARACC_BAR_1) {
2988 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2989 LPFC_PCI_IF0_BAR1_SIZE;
2990 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2991 } else if (bar_num == IDIAG_BARACC_BAR_2) {
2992 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2993 LPFC_PCI_IF0_BAR2_SIZE;
2994 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2997 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2998 if (bar_num == IDIAG_BARACC_BAR_0) {
2999 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3000 LPFC_PCI_IF2_BAR0_SIZE;
3001 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3007 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3008 if (offset % sizeof(uint32_t))
3011 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3012 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3013 /* Sanity check on PCI config read command line arguments */
3014 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3016 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3017 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3018 if (offset > bar_size - sizeof(uint32_t))
3020 /* Starting offset to browse */
3021 idiag.offset.last_rd = offset;
3022 } else if (acc_range > SINGLE_WORD) {
3023 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3025 /* Starting offset to browse */
3026 idiag.offset.last_rd = offset;
3027 } else if (acc_range != SINGLE_WORD)
3029 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3030 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3031 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3032 /* Sanity check on PCI bar write command line arguments */
3033 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3035 /* Write command to PCI bar space, read-modify-write */
3036 acc_range = SINGLE_WORD;
3037 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3038 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3039 writel(value, mem_mapped_bar + offset);
3040 readl(mem_mapped_bar + offset);
3042 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3043 u32val = readl(mem_mapped_bar + offset);
3045 writel(u32val, mem_mapped_bar + offset);
3046 readl(mem_mapped_bar + offset);
3048 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3049 u32val = readl(mem_mapped_bar + offset);
3051 writel(u32val, mem_mapped_bar + offset);
3052 readl(mem_mapped_bar + offset);
3055 /* All other opecodes are illegal for now */
3060 memset(&idiag, 0, sizeof(idiag));
3065 __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3066 char *pbuffer, int len)
3071 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3072 "\t\t%s WQ info: ", wqtype);
3073 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3074 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3075 qp->assoc_qid, qp->q_cnt_1,
3076 (unsigned long long)qp->q_cnt_4);
3077 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3078 "\t\tWQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3079 "HOST-IDX[%04d], PORT-IDX[%04d]",
3080 qp->queue_id, qp->entry_count,
3081 qp->entry_size, qp->host_index,
3083 len += snprintf(pbuffer + len,
3084 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3089 lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3090 int *len, int max_cnt, int cq_id)
3092 struct lpfc_queue *qp;
3095 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3096 qp = phba->sli4_hba.fcp_wq[qidx];
3097 if (qp->assoc_qid != cq_id)
3099 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3100 if (*len >= max_cnt)
3103 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3104 qp = phba->sli4_hba.nvme_wq[qidx];
3105 if (qp->assoc_qid != cq_id)
3107 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3108 if (*len >= max_cnt)
3115 __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3116 char *pbuffer, int len)
3121 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3122 "\t%s CQ info: ", cqtype);
3123 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3124 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3125 "xabt:x%x wq:x%llx]\n",
3126 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3127 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3128 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3129 "\tCQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3130 "HOST-IDX[%04d], PORT-IDX[%04d]",
3131 qp->queue_id, qp->entry_count,
3132 qp->entry_size, qp->host_index,
3135 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3141 __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3142 char *rqtype, char *pbuffer, int len)
3147 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3148 "\t\t%s RQ info: ", rqtype);
3149 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3150 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
3151 "posted:x%x rcv:x%llx]\n",
3152 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3153 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3154 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3155 "\t\tHQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3156 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
3157 qp->queue_id, qp->entry_count, qp->entry_size,
3158 qp->host_index, qp->hba_index);
3159 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3160 "\t\tDQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3161 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
3162 datqp->queue_id, datqp->entry_count,
3163 datqp->entry_size, datqp->host_index,
3169 lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
3170 int *len, int max_cnt, int eqidx, int eq_id)
3172 struct lpfc_queue *qp;
3175 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3176 qp = phba->sli4_hba.fcp_cq[qidx];
3177 if (qp->assoc_qid != eq_id)
3180 *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
3182 /* Reset max counter */
3185 if (*len >= max_cnt)
3188 rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
3189 max_cnt, qp->queue_id);
3194 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3195 qp = phba->sli4_hba.nvme_cq[qidx];
3196 if (qp->assoc_qid != eq_id)
3199 *len = __lpfc_idiag_print_cq(qp, "NVME", pbuffer, *len);
3201 /* Reset max counter */
3204 if (*len >= max_cnt)
3207 rc = lpfc_idiag_wqs_for_cq(phba, "NVME", pbuffer, len,
3208 max_cnt, qp->queue_id);
3213 if (eqidx < phba->cfg_nvmet_mrq) {
3215 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3216 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3218 /* Reset max counter */
3221 if (*len >= max_cnt)
3225 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3226 *len = __lpfc_idiag_print_rqpair(qp,
3227 phba->sli4_hba.nvmet_mrq_data[eqidx],
3228 "NVMET MRQ", pbuffer, *len);
3230 if (*len >= max_cnt)
3238 __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
3239 char *pbuffer, int len)
3244 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3245 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
3246 "bs:x%x proc:x%llx]\n",
3247 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
3248 (unsigned long long)qp->q_cnt_4);
3249 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3250 "EQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
3251 "HOST-IDX[%04d], PORT-IDX[%04d]",
3252 qp->queue_id, qp->entry_count, qp->entry_size,
3253 qp->host_index, qp->hba_index);
3254 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3260 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
3261 * @file: The file pointer to read from.
3262 * @buf: The buffer to copy the data to.
3263 * @nbytes: The number of bytes to read.
3264 * @ppos: The position in the file to start reading from.
3267 * This routine reads data from the @phba SLI4 PCI function queue information,
3268 * and copies to user @buf.
3269 * This routine only returns 1 EQs worth of information. It remembers the last
3270 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
3271 * retrieve all EQs allocated for the phba.
3274 * This function returns the amount of data that was read (this could be less
3275 * than @nbytes if the end of the file was reached) or a negative error value.
3278 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
3281 struct lpfc_debug *debug = file->private_data;
3282 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3284 int max_cnt, rc, x, len = 0;
3285 struct lpfc_queue *qp = NULL;
3288 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
3291 pbuffer = debug->buffer;
3292 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
3297 spin_lock_irq(&phba->hbalock);
3299 /* Fast-path event queue */
3300 if (phba->sli4_hba.hba_eq && phba->io_channel_irqs) {
3302 x = phba->lpfc_idiag_last_eq;
3303 if (phba->cfg_fof && (x >= phba->io_channel_irqs)) {
3304 phba->lpfc_idiag_last_eq = 0;
3307 phba->lpfc_idiag_last_eq++;
3308 if (phba->lpfc_idiag_last_eq >= phba->io_channel_irqs)
3309 if (phba->cfg_fof == 0)
3310 phba->lpfc_idiag_last_eq = 0;
3312 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3313 "EQ %d out of %d HBA EQs\n",
3314 x, phba->io_channel_irqs);
3317 qp = phba->sli4_hba.hba_eq[x];
3321 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
3323 /* Reset max counter */
3329 /* will dump both fcp and nvme cqs/wqs for the eq */
3330 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
3331 max_cnt, x, qp->queue_id);
3335 /* Only EQ 0 has slow path CQs configured */
3339 /* Slow-path mailbox CQ */
3340 qp = phba->sli4_hba.mbx_cq;
3341 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
3345 /* Slow-path MBOX MQ */
3346 qp = phba->sli4_hba.mbx_wq;
3347 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
3351 /* Slow-path ELS response CQ */
3352 qp = phba->sli4_hba.els_cq;
3353 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
3354 /* Reset max counter */
3360 /* Slow-path ELS WQ */
3361 qp = phba->sli4_hba.els_wq;
3362 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
3366 /* Slow-path NVME LS response CQ */
3367 qp = phba->sli4_hba.nvmels_cq;
3368 len = __lpfc_idiag_print_cq(qp, "NVME LS",
3370 /* Reset max counter */
3376 /* Slow-path NVME LS WQ */
3377 qp = phba->sli4_hba.nvmels_wq;
3378 len = __lpfc_idiag_print_wq(qp, "NVME LS",
3383 qp = phba->sli4_hba.hdr_rq;
3384 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
3385 "RQpair", pbuffer, len);
3393 if (phba->cfg_fof) {
3395 qp = phba->sli4_hba.fof_eq;
3396 len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
3398 /* Reset max counter */
3406 qp = phba->sli4_hba.oas_cq;
3407 len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
3408 /* Reset max counter */
3415 qp = phba->sli4_hba.oas_wq;
3416 len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
3421 spin_unlock_irq(&phba->hbalock);
3422 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3425 len += snprintf(pbuffer + len,
3426 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
3428 spin_unlock_irq(&phba->hbalock);
3429 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3433 * lpfc_idiag_que_param_check - queue access command parameter sanity check
3434 * @q: The pointer to queue structure.
3435 * @index: The index into a queue entry.
3436 * @count: The number of queue entries to access.
3439 * The routine performs sanity check on device queue access method commands.
3442 * This function returns -EINVAL when fails the sanity check, otherwise, it
3446 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
3448 /* Only support single entry read or browsing */
3449 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
3451 if (index > q->entry_count - 1)
3457 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
3458 * @pbuffer: The pointer to buffer to copy the read data into.
3459 * @pque: The pointer to the queue to be read.
3460 * @index: The index into the queue entry.
3463 * This routine reads out a single entry from the given queue's index location
3464 * and copies it into the buffer provided.
3467 * This function returns 0 when it fails, otherwise, it returns the length of
3468 * the data read into the buffer provided.
3471 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
3477 if (!pbuffer || !pque)
3480 esize = pque->entry_size;
3481 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3482 "QE-INDEX[%04d]:\n", index);
3485 pentry = pque->qe[index].address;
3487 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3490 offset += sizeof(uint32_t);
3491 esize -= sizeof(uint32_t);
3492 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
3493 len += snprintf(pbuffer+len,
3494 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3496 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3502 * lpfc_idiag_queacc_read - idiag debugfs read port queue
3503 * @file: The file pointer to read from.
3504 * @buf: The buffer to copy the data to.
3505 * @nbytes: The number of bytes to read.
3506 * @ppos: The position in the file to start reading from.
3509 * This routine reads data from the @phba device queue memory according to the
3510 * idiag command, and copies to user @buf. Depending on the queue dump read
3511 * command setup, it does either a single queue entry read or browing through
3512 * all entries of the queue.
3515 * This function returns the amount of data that was read (this could be less
3516 * than @nbytes if the end of the file was reached) or a negative error value.
3519 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
3522 struct lpfc_debug *debug = file->private_data;
3523 uint32_t last_index, index, count;
3524 struct lpfc_queue *pque = NULL;
3528 /* This is a user read operation */
3529 debug->op = LPFC_IDIAG_OP_RD;
3532 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
3535 pbuffer = debug->buffer;
3540 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3541 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3542 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3543 pque = (struct lpfc_queue *)idiag.ptr_private;
3547 /* Browse the queue starting from index */
3548 if (count == LPFC_QUE_ACC_BROWSE)
3551 /* Read a single entry from the queue */
3552 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3554 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3558 /* Browse all entries from the queue */
3559 last_index = idiag.offset.last_rd;
3562 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
3563 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3565 if (index > pque->entry_count - 1)
3569 /* Set up the offset for next portion of pci cfg read */
3570 if (index > pque->entry_count - 1)
3572 idiag.offset.last_rd = index;
3574 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3578 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
3579 * @file: The file pointer to read from.
3580 * @buf: The buffer to copy the user data from.
3581 * @nbytes: The number of bytes to get.
3582 * @ppos: The position in the file to start reading from.
3584 * This routine get the debugfs idiag command struct from user space and then
3585 * perform the syntax check for port queue read (dump) or write (set) command
3586 * accordingly. In the case of port queue read command, it sets up the command
3587 * in the idiag command struct for the following debugfs read operation. In
3588 * the case of port queue write operation, it executes the write operation
3589 * into the port queue entry accordingly.
3591 * It returns the @nbytges passing in from debugfs user space when successful.
3592 * In case of error conditions, it returns proper error code back to the user
3596 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3597 size_t nbytes, loff_t *ppos)
3599 struct lpfc_debug *debug = file->private_data;
3600 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3601 uint32_t qidx, quetp, queid, index, count, offset, value;
3603 struct lpfc_queue *pque, *qp;
3606 /* This is a user write operation */
3607 debug->op = LPFC_IDIAG_OP_WR;
3609 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3613 /* Get and sanity check on command feilds */
3614 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
3615 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
3616 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3617 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3618 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
3619 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
3621 /* Sanity check on command line arguments */
3622 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3623 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3624 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3625 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
3629 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3630 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
3637 /* HBA event queue */
3638 if (phba->sli4_hba.hba_eq) {
3639 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
3640 qp = phba->sli4_hba.hba_eq[qidx];
3641 if (qp && qp->queue_id == queid) {
3643 rc = lpfc_idiag_que_param_check(qp,
3647 idiag.ptr_private = qp;
3655 /* MBX complete queue */
3656 if (phba->sli4_hba.mbx_cq &&
3657 phba->sli4_hba.mbx_cq->queue_id == queid) {
3659 rc = lpfc_idiag_que_param_check(
3660 phba->sli4_hba.mbx_cq, index, count);
3663 idiag.ptr_private = phba->sli4_hba.mbx_cq;
3666 /* ELS complete queue */
3667 if (phba->sli4_hba.els_cq &&
3668 phba->sli4_hba.els_cq->queue_id == queid) {
3670 rc = lpfc_idiag_que_param_check(
3671 phba->sli4_hba.els_cq, index, count);
3674 idiag.ptr_private = phba->sli4_hba.els_cq;
3677 /* NVME LS complete queue */
3678 if (phba->sli4_hba.nvmels_cq &&
3679 phba->sli4_hba.nvmels_cq->queue_id == queid) {
3681 rc = lpfc_idiag_que_param_check(
3682 phba->sli4_hba.nvmels_cq, index, count);
3685 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3688 /* FCP complete queue */
3689 if (phba->sli4_hba.fcp_cq) {
3690 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3692 qp = phba->sli4_hba.fcp_cq[qidx];
3693 if (qp && qp->queue_id == queid) {
3695 rc = lpfc_idiag_que_param_check(
3699 idiag.ptr_private = qp;
3704 /* NVME complete queue */
3705 if (phba->sli4_hba.nvme_cq) {
3708 if (phba->sli4_hba.nvme_cq[qidx] &&
3709 phba->sli4_hba.nvme_cq[qidx]->queue_id ==
3712 rc = lpfc_idiag_que_param_check(
3713 phba->sli4_hba.nvme_cq[qidx],
3718 phba->sli4_hba.nvme_cq[qidx];
3721 } while (++qidx < phba->cfg_nvme_io_channel);
3726 /* MBX work queue */
3727 if (phba->sli4_hba.mbx_wq &&
3728 phba->sli4_hba.mbx_wq->queue_id == queid) {
3730 rc = lpfc_idiag_que_param_check(
3731 phba->sli4_hba.mbx_wq, index, count);
3734 idiag.ptr_private = phba->sli4_hba.mbx_wq;
3740 /* ELS work queue */
3741 if (phba->sli4_hba.els_wq &&
3742 phba->sli4_hba.els_wq->queue_id == queid) {
3744 rc = lpfc_idiag_que_param_check(
3745 phba->sli4_hba.els_wq, index, count);
3748 idiag.ptr_private = phba->sli4_hba.els_wq;
3751 /* NVME LS work queue */
3752 if (phba->sli4_hba.nvmels_wq &&
3753 phba->sli4_hba.nvmels_wq->queue_id == queid) {
3755 rc = lpfc_idiag_que_param_check(
3756 phba->sli4_hba.nvmels_wq, index, count);
3759 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3762 /* FCP work queue */
3763 if (phba->sli4_hba.fcp_wq) {
3764 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3766 qp = phba->sli4_hba.fcp_wq[qidx];
3767 if (qp && qp->queue_id == queid) {
3769 rc = lpfc_idiag_que_param_check(
3773 idiag.ptr_private = qp;
3778 /* NVME work queue */
3779 if (phba->sli4_hba.nvme_wq) {
3780 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3782 qp = phba->sli4_hba.nvme_wq[qidx];
3783 if (qp && qp->queue_id == queid) {
3785 rc = lpfc_idiag_que_param_check(
3789 idiag.ptr_private = qp;
3795 /* NVME work queues */
3796 if (phba->sli4_hba.nvme_wq) {
3797 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3799 if (!phba->sli4_hba.nvme_wq[qidx])
3801 if (phba->sli4_hba.nvme_wq[qidx]->queue_id ==
3804 rc = lpfc_idiag_que_param_check(
3805 phba->sli4_hba.nvme_wq[qidx],
3810 phba->sli4_hba.nvme_wq[qidx];
3819 if (phba->sli4_hba.hdr_rq &&
3820 phba->sli4_hba.hdr_rq->queue_id == queid) {
3822 rc = lpfc_idiag_que_param_check(
3823 phba->sli4_hba.hdr_rq, index, count);
3826 idiag.ptr_private = phba->sli4_hba.hdr_rq;
3830 if (phba->sli4_hba.dat_rq &&
3831 phba->sli4_hba.dat_rq->queue_id == queid) {
3833 rc = lpfc_idiag_que_param_check(
3834 phba->sli4_hba.dat_rq, index, count);
3837 idiag.ptr_private = phba->sli4_hba.dat_rq;
3849 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3850 if (count == LPFC_QUE_ACC_BROWSE)
3851 idiag.offset.last_rd = index;
3854 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3855 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3856 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3857 /* Additional sanity checks on write operation */
3858 pque = (struct lpfc_queue *)idiag.ptr_private;
3859 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
3861 pentry = pque->qe[index].address;
3863 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
3865 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
3867 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
3873 /* Clean out command structure on command error out */
3874 memset(&idiag, 0, sizeof(idiag));
3879 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
3880 * @phba: The pointer to hba structure.
3881 * @pbuffer: The pointer to the buffer to copy the data to.
3882 * @len: The lenght of bytes to copied.
3883 * @drbregid: The id to doorbell registers.
3886 * This routine reads a doorbell register and copies its content to the
3887 * user buffer pointed to by @pbuffer.
3890 * This function returns the amount of data that was copied into @pbuffer.
3893 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
3894 int len, uint32_t drbregid)
3902 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3903 "EQCQ-DRB-REG: 0x%08x\n",
3904 readl(phba->sli4_hba.EQCQDBregaddr));
3907 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3908 "MQ-DRB-REG: 0x%08x\n",
3909 readl(phba->sli4_hba.MQDBregaddr));
3912 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3913 "WQ-DRB-REG: 0x%08x\n",
3914 readl(phba->sli4_hba.WQDBregaddr));
3917 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3918 "RQ-DRB-REG: 0x%08x\n",
3919 readl(phba->sli4_hba.RQDBregaddr));
3929 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
3930 * @file: The file pointer to read from.
3931 * @buf: The buffer to copy the data to.
3932 * @nbytes: The number of bytes to read.
3933 * @ppos: The position in the file to start reading from.
3936 * This routine reads data from the @phba device doorbell register according
3937 * to the idiag command, and copies to user @buf. Depending on the doorbell
3938 * register read command setup, it does either a single doorbell register
3939 * read or dump all doorbell registers.
3942 * This function returns the amount of data that was read (this could be less
3943 * than @nbytes if the end of the file was reached) or a negative error value.
3946 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
3949 struct lpfc_debug *debug = file->private_data;
3950 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3951 uint32_t drb_reg_id, i;
3955 /* This is a user read operation */
3956 debug->op = LPFC_IDIAG_OP_RD;
3959 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
3962 pbuffer = debug->buffer;
3967 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
3968 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
3972 if (drb_reg_id == LPFC_DRB_ACC_ALL)
3973 for (i = 1; i <= LPFC_DRB_MAX; i++)
3974 len = lpfc_idiag_drbacc_read_reg(phba,
3977 len = lpfc_idiag_drbacc_read_reg(phba,
3978 pbuffer, len, drb_reg_id);
3980 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3984 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
3985 * @file: The file pointer to read from.
3986 * @buf: The buffer to copy the user data from.
3987 * @nbytes: The number of bytes to get.
3988 * @ppos: The position in the file to start reading from.
3990 * This routine get the debugfs idiag command struct from user space and then
3991 * perform the syntax check for port doorbell register read (dump) or write
3992 * (set) command accordingly. In the case of port queue read command, it sets
3993 * up the command in the idiag command struct for the following debugfs read
3994 * operation. In the case of port doorbell register write operation, it
3995 * executes the write operation into the port doorbell register accordingly.
3997 * It returns the @nbytges passing in from debugfs user space when successful.
3998 * In case of error conditions, it returns proper error code back to the user
4002 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4003 size_t nbytes, loff_t *ppos)
4005 struct lpfc_debug *debug = file->private_data;
4006 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4007 uint32_t drb_reg_id, value, reg_val = 0;
4008 void __iomem *drb_reg;
4011 /* This is a user write operation */
4012 debug->op = LPFC_IDIAG_OP_WR;
4014 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4018 /* Sanity check on command line arguments */
4019 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4020 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
4022 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4023 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4024 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4025 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4027 if (drb_reg_id > LPFC_DRB_MAX)
4029 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4030 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4032 if ((drb_reg_id > LPFC_DRB_MAX) &&
4033 (drb_reg_id != LPFC_DRB_ACC_ALL))
4038 /* Perform the write access operation */
4039 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4040 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4041 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4042 switch (drb_reg_id) {
4044 drb_reg = phba->sli4_hba.EQCQDBregaddr;
4047 drb_reg = phba->sli4_hba.MQDBregaddr;
4050 drb_reg = phba->sli4_hba.WQDBregaddr;
4053 drb_reg = phba->sli4_hba.RQDBregaddr;
4059 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4061 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4062 reg_val = readl(drb_reg);
4065 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4066 reg_val = readl(drb_reg);
4069 writel(reg_val, drb_reg);
4070 readl(drb_reg); /* flush */
4075 /* Clean out command structure on command error out */
4076 memset(&idiag, 0, sizeof(idiag));
4081 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4082 * @phba: The pointer to hba structure.
4083 * @pbuffer: The pointer to the buffer to copy the data to.
4084 * @len: The lenght of bytes to copied.
4085 * @drbregid: The id to doorbell registers.
4088 * This routine reads a control register and copies its content to the
4089 * user buffer pointed to by @pbuffer.
4092 * This function returns the amount of data that was copied into @pbuffer.
4095 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4096 int len, uint32_t ctlregid)
4103 case LPFC_CTL_PORT_SEM:
4104 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4105 "Port SemReg: 0x%08x\n",
4106 readl(phba->sli4_hba.conf_regs_memmap_p +
4107 LPFC_CTL_PORT_SEM_OFFSET));
4109 case LPFC_CTL_PORT_STA:
4110 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4111 "Port StaReg: 0x%08x\n",
4112 readl(phba->sli4_hba.conf_regs_memmap_p +
4113 LPFC_CTL_PORT_STA_OFFSET));
4115 case LPFC_CTL_PORT_CTL:
4116 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4117 "Port CtlReg: 0x%08x\n",
4118 readl(phba->sli4_hba.conf_regs_memmap_p +
4119 LPFC_CTL_PORT_CTL_OFFSET));
4121 case LPFC_CTL_PORT_ER1:
4122 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4123 "Port Er1Reg: 0x%08x\n",
4124 readl(phba->sli4_hba.conf_regs_memmap_p +
4125 LPFC_CTL_PORT_ER1_OFFSET));
4127 case LPFC_CTL_PORT_ER2:
4128 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4129 "Port Er2Reg: 0x%08x\n",
4130 readl(phba->sli4_hba.conf_regs_memmap_p +
4131 LPFC_CTL_PORT_ER2_OFFSET));
4133 case LPFC_CTL_PDEV_CTL:
4134 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4135 "PDev CtlReg: 0x%08x\n",
4136 readl(phba->sli4_hba.conf_regs_memmap_p +
4137 LPFC_CTL_PDEV_CTL_OFFSET));
4146 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4147 * @file: The file pointer to read from.
4148 * @buf: The buffer to copy the data to.
4149 * @nbytes: The number of bytes to read.
4150 * @ppos: The position in the file to start reading from.
4153 * This routine reads data from the @phba port and device registers according
4154 * to the idiag command, and copies to user @buf.
4157 * This function returns the amount of data that was read (this could be less
4158 * than @nbytes if the end of the file was reached) or a negative error value.
4161 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4164 struct lpfc_debug *debug = file->private_data;
4165 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4166 uint32_t ctl_reg_id, i;
4170 /* This is a user read operation */
4171 debug->op = LPFC_IDIAG_OP_RD;
4174 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4177 pbuffer = debug->buffer;
4182 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4183 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4187 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4188 for (i = 1; i <= LPFC_CTL_MAX; i++)
4189 len = lpfc_idiag_ctlacc_read_reg(phba,
4192 len = lpfc_idiag_ctlacc_read_reg(phba,
4193 pbuffer, len, ctl_reg_id);
4195 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4199 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4200 * @file: The file pointer to read from.
4201 * @buf: The buffer to copy the user data from.
4202 * @nbytes: The number of bytes to get.
4203 * @ppos: The position in the file to start reading from.
4205 * This routine get the debugfs idiag command struct from user space and then
4206 * perform the syntax check for port and device control register read (dump)
4207 * or write (set) command accordingly.
4209 * It returns the @nbytges passing in from debugfs user space when successful.
4210 * In case of error conditions, it returns proper error code back to the user
4214 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4215 size_t nbytes, loff_t *ppos)
4217 struct lpfc_debug *debug = file->private_data;
4218 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4219 uint32_t ctl_reg_id, value, reg_val = 0;
4220 void __iomem *ctl_reg;
4223 /* This is a user write operation */
4224 debug->op = LPFC_IDIAG_OP_WR;
4226 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4230 /* Sanity check on command line arguments */
4231 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4232 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4234 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4235 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4236 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4237 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4239 if (ctl_reg_id > LPFC_CTL_MAX)
4241 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4242 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4244 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4245 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4250 /* Perform the write access operation */
4251 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4252 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4253 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4254 switch (ctl_reg_id) {
4255 case LPFC_CTL_PORT_SEM:
4256 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4257 LPFC_CTL_PORT_SEM_OFFSET;
4259 case LPFC_CTL_PORT_STA:
4260 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4261 LPFC_CTL_PORT_STA_OFFSET;
4263 case LPFC_CTL_PORT_CTL:
4264 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4265 LPFC_CTL_PORT_CTL_OFFSET;
4267 case LPFC_CTL_PORT_ER1:
4268 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4269 LPFC_CTL_PORT_ER1_OFFSET;
4271 case LPFC_CTL_PORT_ER2:
4272 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4273 LPFC_CTL_PORT_ER2_OFFSET;
4275 case LPFC_CTL_PDEV_CTL:
4276 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4277 LPFC_CTL_PDEV_CTL_OFFSET;
4283 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4285 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4286 reg_val = readl(ctl_reg);
4289 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4290 reg_val = readl(ctl_reg);
4293 writel(reg_val, ctl_reg);
4294 readl(ctl_reg); /* flush */
4299 /* Clean out command structure on command error out */
4300 memset(&idiag, 0, sizeof(idiag));
4305 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4306 * @phba: Pointer to HBA context object.
4307 * @pbuffer: Pointer to data buffer.
4310 * This routine gets the driver mailbox access debugfs setup information.
4313 * This function returns the amount of data that was read (this could be less
4314 * than @nbytes if the end of the file was reached) or a negative error value.
4317 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
4319 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4322 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4323 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4324 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4325 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4327 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4328 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
4329 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4330 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
4331 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4332 "mbx_word_cnt: %04d\n", mbx_word_cnt);
4333 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4334 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
4340 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
4341 * @file: The file pointer to read from.
4342 * @buf: The buffer to copy the data to.
4343 * @nbytes: The number of bytes to read.
4344 * @ppos: The position in the file to start reading from.
4347 * This routine reads data from the @phba driver mailbox access debugfs setup
4351 * This function returns the amount of data that was read (this could be less
4352 * than @nbytes if the end of the file was reached) or a negative error value.
4355 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
4358 struct lpfc_debug *debug = file->private_data;
4359 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4363 /* This is a user read operation */
4364 debug->op = LPFC_IDIAG_OP_RD;
4367 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
4370 pbuffer = debug->buffer;
4375 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
4376 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
4379 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
4381 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4385 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
4386 * @file: The file pointer to read from.
4387 * @buf: The buffer to copy the user data from.
4388 * @nbytes: The number of bytes to get.
4389 * @ppos: The position in the file to start reading from.
4391 * This routine get the debugfs idiag command struct from user space and then
4392 * perform the syntax check for driver mailbox command (dump) and sets up the
4393 * necessary states in the idiag command struct accordingly.
4395 * It returns the @nbytges passing in from debugfs user space when successful.
4396 * In case of error conditions, it returns proper error code back to the user
4400 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
4401 size_t nbytes, loff_t *ppos)
4403 struct lpfc_debug *debug = file->private_data;
4404 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4407 /* This is a user write operation */
4408 debug->op = LPFC_IDIAG_OP_WR;
4410 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4414 /* Sanity check on command line arguments */
4415 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4416 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4417 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4418 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4420 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
4421 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
4423 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
4424 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4426 if (mbx_word_cnt > sizeof(MAILBOX_t))
4428 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
4429 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
4431 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
4432 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4434 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
4436 if (mbx_mbox_cmd != 0x9b)
4441 if (mbx_word_cnt == 0)
4443 if (rc != LPFC_MBX_DMP_ARG)
4445 if (mbx_mbox_cmd & ~0xff)
4448 /* condition for stop mailbox dump */
4449 if (mbx_dump_cnt == 0)
4455 /* Clean out command structure on command error out */
4456 memset(&idiag, 0, sizeof(idiag));
4460 /* Clean out command structure on command error out */
4461 memset(&idiag, 0, sizeof(idiag));
4466 * lpfc_idiag_extacc_avail_get - get the available extents information
4467 * @phba: pointer to lpfc hba data structure.
4468 * @pbuffer: pointer to internal buffer.
4469 * @len: length into the internal buffer data has been copied.
4472 * This routine is to get the available extent information.
4475 * overall lenth of the data read into the internal buffer.
4478 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
4480 uint16_t ext_cnt, ext_size;
4482 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4483 "\nAvailable Extents Information:\n");
4485 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4486 "\tPort Available VPI extents: ");
4487 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
4488 &ext_cnt, &ext_size);
4489 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4490 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4492 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4493 "\tPort Available VFI extents: ");
4494 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
4495 &ext_cnt, &ext_size);
4496 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4497 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4499 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4500 "\tPort Available RPI extents: ");
4501 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
4502 &ext_cnt, &ext_size);
4503 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4504 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4506 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4507 "\tPort Available XRI extents: ");
4508 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
4509 &ext_cnt, &ext_size);
4510 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4511 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4517 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
4518 * @phba: pointer to lpfc hba data structure.
4519 * @pbuffer: pointer to internal buffer.
4520 * @len: length into the internal buffer data has been copied.
4523 * This routine is to get the allocated extent information.
4526 * overall lenth of the data read into the internal buffer.
4529 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
4531 uint16_t ext_cnt, ext_size;
4534 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4535 "\nAllocated Extents Information:\n");
4537 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4538 "\tHost Allocated VPI extents: ");
4539 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
4540 &ext_cnt, &ext_size);
4542 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4543 "Port %d Extent %3d, Size %3d\n",
4544 phba->brd_no, ext_cnt, ext_size);
4546 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4549 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4550 "\tHost Allocated VFI extents: ");
4551 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
4552 &ext_cnt, &ext_size);
4554 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4555 "Port %d Extent %3d, Size %3d\n",
4556 phba->brd_no, ext_cnt, ext_size);
4558 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4561 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4562 "\tHost Allocated RPI extents: ");
4563 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
4564 &ext_cnt, &ext_size);
4566 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4567 "Port %d Extent %3d, Size %3d\n",
4568 phba->brd_no, ext_cnt, ext_size);
4570 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4573 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4574 "\tHost Allocated XRI extents: ");
4575 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
4576 &ext_cnt, &ext_size);
4578 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4579 "Port %d Extent %3d, Size %3d\n",
4580 phba->brd_no, ext_cnt, ext_size);
4582 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4589 * lpfc_idiag_extacc_drivr_get - get driver extent information
4590 * @phba: pointer to lpfc hba data structure.
4591 * @pbuffer: pointer to internal buffer.
4592 * @len: length into the internal buffer data has been copied.
4595 * This routine is to get the driver extent information.
4598 * overall lenth of the data read into the internal buffer.
4601 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
4603 struct lpfc_rsrc_blks *rsrc_blks;
4606 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4607 "\nDriver Extents Information:\n");
4609 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4610 "\tVPI extents:\n");
4612 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
4613 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4614 "\t\tBlock %3d: Start %4d, Count %4d\n",
4615 index, rsrc_blks->rsrc_start,
4616 rsrc_blks->rsrc_size);
4619 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4620 "\tVFI extents:\n");
4622 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
4624 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4625 "\t\tBlock %3d: Start %4d, Count %4d\n",
4626 index, rsrc_blks->rsrc_start,
4627 rsrc_blks->rsrc_size);
4631 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4632 "\tRPI extents:\n");
4634 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
4636 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4637 "\t\tBlock %3d: Start %4d, Count %4d\n",
4638 index, rsrc_blks->rsrc_start,
4639 rsrc_blks->rsrc_size);
4643 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4644 "\tXRI extents:\n");
4646 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
4648 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4649 "\t\tBlock %3d: Start %4d, Count %4d\n",
4650 index, rsrc_blks->rsrc_start,
4651 rsrc_blks->rsrc_size);
4659 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
4660 * @file: The file pointer to read from.
4661 * @buf: The buffer to copy the user data from.
4662 * @nbytes: The number of bytes to get.
4663 * @ppos: The position in the file to start reading from.
4665 * This routine get the debugfs idiag command struct from user space and then
4666 * perform the syntax check for extent information access commands and sets
4667 * up the necessary states in the idiag command struct accordingly.
4669 * It returns the @nbytges passing in from debugfs user space when successful.
4670 * In case of error conditions, it returns proper error code back to the user
4674 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
4675 size_t nbytes, loff_t *ppos)
4677 struct lpfc_debug *debug = file->private_data;
4681 /* This is a user write operation */
4682 debug->op = LPFC_IDIAG_OP_WR;
4684 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4688 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4690 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4692 if (rc != LPFC_EXT_ACC_CMD_ARG)
4694 if (!(ext_map & LPFC_EXT_ACC_ALL))
4699 /* Clean out command structure on command error out */
4700 memset(&idiag, 0, sizeof(idiag));
4705 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
4706 * @file: The file pointer to read from.
4707 * @buf: The buffer to copy the data to.
4708 * @nbytes: The number of bytes to read.
4709 * @ppos: The position in the file to start reading from.
4712 * This routine reads data from the proper extent information according to
4713 * the idiag command, and copies to user @buf.
4716 * This function returns the amount of data that was read (this could be less
4717 * than @nbytes if the end of the file was reached) or a negative error value.
4720 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
4723 struct lpfc_debug *debug = file->private_data;
4724 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4729 /* This is a user read operation */
4730 debug->op = LPFC_IDIAG_OP_RD;
4733 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
4736 pbuffer = debug->buffer;
4739 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4742 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4743 if (ext_map & LPFC_EXT_ACC_AVAIL)
4744 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
4745 if (ext_map & LPFC_EXT_ACC_ALLOC)
4746 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
4747 if (ext_map & LPFC_EXT_ACC_DRIVR)
4748 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
4750 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4753 #undef lpfc_debugfs_op_disc_trc
4754 static const struct file_operations lpfc_debugfs_op_disc_trc = {
4755 .owner = THIS_MODULE,
4756 .open = lpfc_debugfs_disc_trc_open,
4757 .llseek = lpfc_debugfs_lseek,
4758 .read = lpfc_debugfs_read,
4759 .release = lpfc_debugfs_release,
4762 #undef lpfc_debugfs_op_nodelist
4763 static const struct file_operations lpfc_debugfs_op_nodelist = {
4764 .owner = THIS_MODULE,
4765 .open = lpfc_debugfs_nodelist_open,
4766 .llseek = lpfc_debugfs_lseek,
4767 .read = lpfc_debugfs_read,
4768 .release = lpfc_debugfs_release,
4771 #undef lpfc_debugfs_op_hbqinfo
4772 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
4773 .owner = THIS_MODULE,
4774 .open = lpfc_debugfs_hbqinfo_open,
4775 .llseek = lpfc_debugfs_lseek,
4776 .read = lpfc_debugfs_read,
4777 .release = lpfc_debugfs_release,
4780 #undef lpfc_debugfs_op_dumpHBASlim
4781 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
4782 .owner = THIS_MODULE,
4783 .open = lpfc_debugfs_dumpHBASlim_open,
4784 .llseek = lpfc_debugfs_lseek,
4785 .read = lpfc_debugfs_read,
4786 .release = lpfc_debugfs_release,
4789 #undef lpfc_debugfs_op_dumpHostSlim
4790 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
4791 .owner = THIS_MODULE,
4792 .open = lpfc_debugfs_dumpHostSlim_open,
4793 .llseek = lpfc_debugfs_lseek,
4794 .read = lpfc_debugfs_read,
4795 .release = lpfc_debugfs_release,
4798 #undef lpfc_debugfs_op_nvmestat
4799 static const struct file_operations lpfc_debugfs_op_nvmestat = {
4800 .owner = THIS_MODULE,
4801 .open = lpfc_debugfs_nvmestat_open,
4802 .llseek = lpfc_debugfs_lseek,
4803 .read = lpfc_debugfs_read,
4804 .write = lpfc_debugfs_nvmestat_write,
4805 .release = lpfc_debugfs_release,
4808 #undef lpfc_debugfs_op_nvmektime
4809 static const struct file_operations lpfc_debugfs_op_nvmektime = {
4810 .owner = THIS_MODULE,
4811 .open = lpfc_debugfs_nvmektime_open,
4812 .llseek = lpfc_debugfs_lseek,
4813 .read = lpfc_debugfs_read,
4814 .write = lpfc_debugfs_nvmektime_write,
4815 .release = lpfc_debugfs_release,
4818 #undef lpfc_debugfs_op_nvmeio_trc
4819 static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
4820 .owner = THIS_MODULE,
4821 .open = lpfc_debugfs_nvmeio_trc_open,
4822 .llseek = lpfc_debugfs_lseek,
4823 .read = lpfc_debugfs_read,
4824 .write = lpfc_debugfs_nvmeio_trc_write,
4825 .release = lpfc_debugfs_release,
4828 #undef lpfc_debugfs_op_cpucheck
4829 static const struct file_operations lpfc_debugfs_op_cpucheck = {
4830 .owner = THIS_MODULE,
4831 .open = lpfc_debugfs_cpucheck_open,
4832 .llseek = lpfc_debugfs_lseek,
4833 .read = lpfc_debugfs_read,
4834 .write = lpfc_debugfs_cpucheck_write,
4835 .release = lpfc_debugfs_release,
4838 #undef lpfc_debugfs_op_dumpData
4839 static const struct file_operations lpfc_debugfs_op_dumpData = {
4840 .owner = THIS_MODULE,
4841 .open = lpfc_debugfs_dumpData_open,
4842 .llseek = lpfc_debugfs_lseek,
4843 .read = lpfc_debugfs_read,
4844 .write = lpfc_debugfs_dumpDataDif_write,
4845 .release = lpfc_debugfs_dumpDataDif_release,
4848 #undef lpfc_debugfs_op_dumpDif
4849 static const struct file_operations lpfc_debugfs_op_dumpDif = {
4850 .owner = THIS_MODULE,
4851 .open = lpfc_debugfs_dumpDif_open,
4852 .llseek = lpfc_debugfs_lseek,
4853 .read = lpfc_debugfs_read,
4854 .write = lpfc_debugfs_dumpDataDif_write,
4855 .release = lpfc_debugfs_dumpDataDif_release,
4858 #undef lpfc_debugfs_op_dif_err
4859 static const struct file_operations lpfc_debugfs_op_dif_err = {
4860 .owner = THIS_MODULE,
4861 .open = simple_open,
4862 .llseek = lpfc_debugfs_lseek,
4863 .read = lpfc_debugfs_dif_err_read,
4864 .write = lpfc_debugfs_dif_err_write,
4865 .release = lpfc_debugfs_dif_err_release,
4868 #undef lpfc_debugfs_op_slow_ring_trc
4869 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
4870 .owner = THIS_MODULE,
4871 .open = lpfc_debugfs_slow_ring_trc_open,
4872 .llseek = lpfc_debugfs_lseek,
4873 .read = lpfc_debugfs_read,
4874 .release = lpfc_debugfs_release,
4877 static struct dentry *lpfc_debugfs_root = NULL;
4878 static atomic_t lpfc_debugfs_hba_count;
4881 * File operations for the iDiag debugfs
4883 #undef lpfc_idiag_op_pciCfg
4884 static const struct file_operations lpfc_idiag_op_pciCfg = {
4885 .owner = THIS_MODULE,
4886 .open = lpfc_idiag_open,
4887 .llseek = lpfc_debugfs_lseek,
4888 .read = lpfc_idiag_pcicfg_read,
4889 .write = lpfc_idiag_pcicfg_write,
4890 .release = lpfc_idiag_cmd_release,
4893 #undef lpfc_idiag_op_barAcc
4894 static const struct file_operations lpfc_idiag_op_barAcc = {
4895 .owner = THIS_MODULE,
4896 .open = lpfc_idiag_open,
4897 .llseek = lpfc_debugfs_lseek,
4898 .read = lpfc_idiag_baracc_read,
4899 .write = lpfc_idiag_baracc_write,
4900 .release = lpfc_idiag_cmd_release,
4903 #undef lpfc_idiag_op_queInfo
4904 static const struct file_operations lpfc_idiag_op_queInfo = {
4905 .owner = THIS_MODULE,
4906 .open = lpfc_idiag_open,
4907 .read = lpfc_idiag_queinfo_read,
4908 .release = lpfc_idiag_release,
4911 #undef lpfc_idiag_op_queAcc
4912 static const struct file_operations lpfc_idiag_op_queAcc = {
4913 .owner = THIS_MODULE,
4914 .open = lpfc_idiag_open,
4915 .llseek = lpfc_debugfs_lseek,
4916 .read = lpfc_idiag_queacc_read,
4917 .write = lpfc_idiag_queacc_write,
4918 .release = lpfc_idiag_cmd_release,
4921 #undef lpfc_idiag_op_drbAcc
4922 static const struct file_operations lpfc_idiag_op_drbAcc = {
4923 .owner = THIS_MODULE,
4924 .open = lpfc_idiag_open,
4925 .llseek = lpfc_debugfs_lseek,
4926 .read = lpfc_idiag_drbacc_read,
4927 .write = lpfc_idiag_drbacc_write,
4928 .release = lpfc_idiag_cmd_release,
4931 #undef lpfc_idiag_op_ctlAcc
4932 static const struct file_operations lpfc_idiag_op_ctlAcc = {
4933 .owner = THIS_MODULE,
4934 .open = lpfc_idiag_open,
4935 .llseek = lpfc_debugfs_lseek,
4936 .read = lpfc_idiag_ctlacc_read,
4937 .write = lpfc_idiag_ctlacc_write,
4938 .release = lpfc_idiag_cmd_release,
4941 #undef lpfc_idiag_op_mbxAcc
4942 static const struct file_operations lpfc_idiag_op_mbxAcc = {
4943 .owner = THIS_MODULE,
4944 .open = lpfc_idiag_open,
4945 .llseek = lpfc_debugfs_lseek,
4946 .read = lpfc_idiag_mbxacc_read,
4947 .write = lpfc_idiag_mbxacc_write,
4948 .release = lpfc_idiag_cmd_release,
4951 #undef lpfc_idiag_op_extAcc
4952 static const struct file_operations lpfc_idiag_op_extAcc = {
4953 .owner = THIS_MODULE,
4954 .open = lpfc_idiag_open,
4955 .llseek = lpfc_debugfs_lseek,
4956 .read = lpfc_idiag_extacc_read,
4957 .write = lpfc_idiag_extacc_write,
4958 .release = lpfc_idiag_cmd_release,
4963 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
4964 * @phba: Pointer to HBA context object.
4965 * @dmabuf: Pointer to a DMA buffer descriptor.
4968 * This routine dump a bsg pass-through non-embedded mailbox command with
4972 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
4973 enum mbox_type mbox_tp, enum dma_type dma_tp,
4974 enum sta_type sta_tp,
4975 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
4977 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4978 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
4979 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
4981 uint32_t do_dump = 0;
4985 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
4988 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4989 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4990 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4991 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4993 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
4994 (*mbx_dump_cnt == 0) ||
4995 (*mbx_word_cnt == 0))
4998 if (*mbx_mbox_cmd != 0x9B)
5001 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5002 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5003 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
5004 pr_err("\nRead mbox command (x%x), "
5005 "nemb:0x%x, extbuf_cnt:%d:\n",
5006 sta_tp, nemb_tp, ext_buf);
5009 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5010 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5011 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
5012 pr_err("\nRead mbox buffer (x%x), "
5013 "nemb:0x%x, extbuf_seq:%d:\n",
5014 sta_tp, nemb_tp, ext_buf);
5017 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5018 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5019 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
5020 pr_err("\nWrite mbox command (x%x), "
5021 "nemb:0x%x, extbuf_cnt:%d:\n",
5022 sta_tp, nemb_tp, ext_buf);
5025 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5026 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5027 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
5028 pr_err("\nWrite mbox buffer (x%x), "
5029 "nemb:0x%x, extbuf_seq:%d:\n",
5030 sta_tp, nemb_tp, ext_buf);
5034 /* dump buffer content */
5036 pword = (uint32_t *)dmabuf->virt;
5037 for (i = 0; i < *mbx_word_cnt; i++) {
5040 pr_err("%s\n", line_buf);
5042 len += snprintf(line_buf+len,
5043 LPFC_MBX_ACC_LBUF_SZ-len,
5046 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5047 "%08x ", (uint32_t)*pword);
5051 pr_err("%s\n", line_buf);
5055 /* Clean out command structure on reaching dump count */
5056 if (*mbx_dump_cnt == 0)
5057 memset(&idiag, 0, sizeof(idiag));
5062 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5063 * @phba: Pointer to HBA context object.
5064 * @dmabuf: Pointer to a DMA buffer descriptor.
5067 * This routine dump a pass-through non-embedded mailbox command from issue
5071 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5073 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5074 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5075 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5081 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5084 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5085 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5086 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5087 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5089 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5090 (*mbx_dump_cnt == 0) ||
5091 (*mbx_word_cnt == 0))
5094 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5095 (*mbx_mbox_cmd != pmbox->mbxCommand))
5098 /* dump buffer content */
5099 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
5100 pr_err("Mailbox command:0x%x dump by word:\n",
5102 pword = (uint32_t *)pmbox;
5103 for (i = 0; i < *mbx_word_cnt; i++) {
5106 pr_err("%s\n", line_buf);
5108 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5109 len += snprintf(line_buf+len,
5110 LPFC_MBX_ACC_LBUF_SZ-len,
5113 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5115 ((uint32_t)*pword) & 0xffffffff);
5119 pr_err("%s\n", line_buf);
5122 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
5123 pr_err("Mailbox command:0x%x dump by byte:\n",
5125 pbyte = (uint8_t *)pmbox;
5126 for (i = 0; i < *mbx_word_cnt; i++) {
5129 pr_err("%s\n", line_buf);
5131 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5132 len += snprintf(line_buf+len,
5133 LPFC_MBX_ACC_LBUF_SZ-len,
5136 for (j = 0; j < 4; j++) {
5137 len += snprintf(line_buf+len,
5138 LPFC_MBX_ACC_LBUF_SZ-len,
5140 ((uint8_t)*pbyte) & 0xff);
5143 len += snprintf(line_buf+len,
5144 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5147 pr_err("%s\n", line_buf);
5152 /* Clean out command structure on reaching dump count */
5153 if (*mbx_dump_cnt == 0)
5154 memset(&idiag, 0, sizeof(idiag));
5160 * lpfc_debugfs_initialize - Initialize debugfs for a vport
5161 * @vport: The vport pointer to initialize.
5164 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5165 * If not already created, this routine will create the lpfc directory, and
5166 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5167 * also create each file used to access lpfc specific debugfs information.
5170 lpfc_debugfs_initialize(struct lpfc_vport *vport)
5172 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5173 struct lpfc_hba *phba = vport->phba;
5176 bool pport_setup = false;
5178 if (!lpfc_debugfs_enable)
5181 /* Setup lpfc root directory */
5182 if (!lpfc_debugfs_root) {
5183 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5184 atomic_set(&lpfc_debugfs_hba_count, 0);
5185 if (!lpfc_debugfs_root) {
5186 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5187 "0408 Cannot create debugfs root\n");
5191 if (!lpfc_debugfs_start_time)
5192 lpfc_debugfs_start_time = jiffies;
5194 /* Setup funcX directory for specific HBA PCI function */
5195 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
5196 if (!phba->hba_debugfs_root) {
5198 phba->hba_debugfs_root =
5199 debugfs_create_dir(name, lpfc_debugfs_root);
5200 if (!phba->hba_debugfs_root) {
5201 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5202 "0412 Cannot create debugfs hba\n");
5205 atomic_inc(&lpfc_debugfs_hba_count);
5206 atomic_set(&phba->debugfs_vport_count, 0);
5209 snprintf(name, sizeof(name), "hbqinfo");
5210 phba->debug_hbqinfo =
5211 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5212 phba->hba_debugfs_root,
5213 phba, &lpfc_debugfs_op_hbqinfo);
5214 if (!phba->debug_hbqinfo) {
5215 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5216 "0411 Cannot create debugfs hbqinfo\n");
5220 /* Setup dumpHBASlim */
5221 if (phba->sli_rev < LPFC_SLI_REV4) {
5222 snprintf(name, sizeof(name), "dumpHBASlim");
5223 phba->debug_dumpHBASlim =
5224 debugfs_create_file(name,
5225 S_IFREG|S_IRUGO|S_IWUSR,
5226 phba->hba_debugfs_root,
5227 phba, &lpfc_debugfs_op_dumpHBASlim);
5228 if (!phba->debug_dumpHBASlim) {
5229 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5230 "0413 Cannot create debugfs "
5235 phba->debug_dumpHBASlim = NULL;
5237 /* Setup dumpHostSlim */
5238 if (phba->sli_rev < LPFC_SLI_REV4) {
5239 snprintf(name, sizeof(name), "dumpHostSlim");
5240 phba->debug_dumpHostSlim =
5241 debugfs_create_file(name,
5242 S_IFREG|S_IRUGO|S_IWUSR,
5243 phba->hba_debugfs_root,
5244 phba, &lpfc_debugfs_op_dumpHostSlim);
5245 if (!phba->debug_dumpHostSlim) {
5246 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5247 "0414 Cannot create debugfs "
5252 phba->debug_dumpHostSlim = NULL;
5254 /* Setup dumpData */
5255 snprintf(name, sizeof(name), "dumpData");
5256 phba->debug_dumpData =
5257 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5258 phba->hba_debugfs_root,
5259 phba, &lpfc_debugfs_op_dumpData);
5260 if (!phba->debug_dumpData) {
5261 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5262 "0800 Cannot create debugfs dumpData\n");
5267 snprintf(name, sizeof(name), "dumpDif");
5268 phba->debug_dumpDif =
5269 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5270 phba->hba_debugfs_root,
5271 phba, &lpfc_debugfs_op_dumpDif);
5272 if (!phba->debug_dumpDif) {
5273 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5274 "0801 Cannot create debugfs dumpDif\n");
5278 /* Setup DIF Error Injections */
5279 snprintf(name, sizeof(name), "InjErrLBA");
5280 phba->debug_InjErrLBA =
5281 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5282 phba->hba_debugfs_root,
5283 phba, &lpfc_debugfs_op_dif_err);
5284 if (!phba->debug_InjErrLBA) {
5285 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5286 "0807 Cannot create debugfs InjErrLBA\n");
5289 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5291 snprintf(name, sizeof(name), "InjErrNPortID");
5292 phba->debug_InjErrNPortID =
5293 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5294 phba->hba_debugfs_root,
5295 phba, &lpfc_debugfs_op_dif_err);
5296 if (!phba->debug_InjErrNPortID) {
5297 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5298 "0809 Cannot create debugfs InjErrNPortID\n");
5302 snprintf(name, sizeof(name), "InjErrWWPN");
5303 phba->debug_InjErrWWPN =
5304 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5305 phba->hba_debugfs_root,
5306 phba, &lpfc_debugfs_op_dif_err);
5307 if (!phba->debug_InjErrWWPN) {
5308 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5309 "0810 Cannot create debugfs InjErrWWPN\n");
5313 snprintf(name, sizeof(name), "writeGuardInjErr");
5314 phba->debug_writeGuard =
5315 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5316 phba->hba_debugfs_root,
5317 phba, &lpfc_debugfs_op_dif_err);
5318 if (!phba->debug_writeGuard) {
5319 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5320 "0802 Cannot create debugfs writeGuard\n");
5324 snprintf(name, sizeof(name), "writeAppInjErr");
5325 phba->debug_writeApp =
5326 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5327 phba->hba_debugfs_root,
5328 phba, &lpfc_debugfs_op_dif_err);
5329 if (!phba->debug_writeApp) {
5330 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5331 "0803 Cannot create debugfs writeApp\n");
5335 snprintf(name, sizeof(name), "writeRefInjErr");
5336 phba->debug_writeRef =
5337 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5338 phba->hba_debugfs_root,
5339 phba, &lpfc_debugfs_op_dif_err);
5340 if (!phba->debug_writeRef) {
5341 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5342 "0804 Cannot create debugfs writeRef\n");
5346 snprintf(name, sizeof(name), "readGuardInjErr");
5347 phba->debug_readGuard =
5348 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5349 phba->hba_debugfs_root,
5350 phba, &lpfc_debugfs_op_dif_err);
5351 if (!phba->debug_readGuard) {
5352 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5353 "0808 Cannot create debugfs readGuard\n");
5357 snprintf(name, sizeof(name), "readAppInjErr");
5358 phba->debug_readApp =
5359 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5360 phba->hba_debugfs_root,
5361 phba, &lpfc_debugfs_op_dif_err);
5362 if (!phba->debug_readApp) {
5363 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5364 "0805 Cannot create debugfs readApp\n");
5368 snprintf(name, sizeof(name), "readRefInjErr");
5369 phba->debug_readRef =
5370 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5371 phba->hba_debugfs_root,
5372 phba, &lpfc_debugfs_op_dif_err);
5373 if (!phba->debug_readRef) {
5374 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5375 "0806 Cannot create debugfs readApp\n");
5379 /* Setup slow ring trace */
5380 if (lpfc_debugfs_max_slow_ring_trc) {
5381 num = lpfc_debugfs_max_slow_ring_trc - 1;
5382 if (num & lpfc_debugfs_max_slow_ring_trc) {
5383 /* Change to be a power of 2 */
5384 num = lpfc_debugfs_max_slow_ring_trc;
5390 lpfc_debugfs_max_slow_ring_trc = (1 << i);
5391 pr_err("lpfc_debugfs_max_disc_trc changed to "
5392 "%d\n", lpfc_debugfs_max_disc_trc);
5396 snprintf(name, sizeof(name), "slow_ring_trace");
5397 phba->debug_slow_ring_trc =
5398 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5399 phba->hba_debugfs_root,
5400 phba, &lpfc_debugfs_op_slow_ring_trc);
5401 if (!phba->debug_slow_ring_trc) {
5402 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5403 "0415 Cannot create debugfs "
5404 "slow_ring_trace\n");
5407 if (!phba->slow_ring_trc) {
5408 phba->slow_ring_trc = kmalloc(
5409 (sizeof(struct lpfc_debugfs_trc) *
5410 lpfc_debugfs_max_slow_ring_trc),
5412 if (!phba->slow_ring_trc) {
5413 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5414 "0416 Cannot create debugfs "
5415 "slow_ring buffer\n");
5418 atomic_set(&phba->slow_ring_trc_cnt, 0);
5419 memset(phba->slow_ring_trc, 0,
5420 (sizeof(struct lpfc_debugfs_trc) *
5421 lpfc_debugfs_max_slow_ring_trc));
5424 snprintf(name, sizeof(name), "nvmeio_trc");
5425 phba->debug_nvmeio_trc =
5426 debugfs_create_file(name, 0644,
5427 phba->hba_debugfs_root,
5428 phba, &lpfc_debugfs_op_nvmeio_trc);
5429 if (!phba->debug_nvmeio_trc) {
5430 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5431 "0574 No create debugfs nvmeio_trc\n");
5435 atomic_set(&phba->nvmeio_trc_cnt, 0);
5436 if (lpfc_debugfs_max_nvmeio_trc) {
5437 num = lpfc_debugfs_max_nvmeio_trc - 1;
5438 if (num & lpfc_debugfs_max_disc_trc) {
5439 /* Change to be a power of 2 */
5440 num = lpfc_debugfs_max_nvmeio_trc;
5446 lpfc_debugfs_max_nvmeio_trc = (1 << i);
5447 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5448 "0575 lpfc_debugfs_max_nvmeio_trc "
5450 lpfc_debugfs_max_nvmeio_trc);
5452 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
5454 /* Allocate trace buffer and initialize */
5455 phba->nvmeio_trc = kmalloc(
5456 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5457 phba->nvmeio_trc_size), GFP_KERNEL);
5459 if (!phba->nvmeio_trc) {
5460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5461 "0576 Cannot create debugfs "
5462 "nvmeio_trc buffer\n");
5465 memset(phba->nvmeio_trc, 0,
5466 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5467 phba->nvmeio_trc_size));
5468 phba->nvmeio_trc_on = 1;
5469 phba->nvmeio_trc_output_idx = 0;
5470 phba->nvmeio_trc = NULL;
5473 phba->nvmeio_trc_size = 0;
5474 phba->nvmeio_trc_on = 0;
5475 phba->nvmeio_trc_output_idx = 0;
5476 phba->nvmeio_trc = NULL;
5480 snprintf(name, sizeof(name), "vport%d", vport->vpi);
5481 if (!vport->vport_debugfs_root) {
5482 vport->vport_debugfs_root =
5483 debugfs_create_dir(name, phba->hba_debugfs_root);
5484 if (!vport->vport_debugfs_root) {
5485 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5486 "0417 Can't create debugfs\n");
5489 atomic_inc(&phba->debugfs_vport_count);
5492 if (lpfc_debugfs_max_disc_trc) {
5493 num = lpfc_debugfs_max_disc_trc - 1;
5494 if (num & lpfc_debugfs_max_disc_trc) {
5495 /* Change to be a power of 2 */
5496 num = lpfc_debugfs_max_disc_trc;
5502 lpfc_debugfs_max_disc_trc = (1 << i);
5503 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
5504 lpfc_debugfs_max_disc_trc);
5508 vport->disc_trc = kzalloc(
5509 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
5512 if (!vport->disc_trc) {
5513 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5514 "0418 Cannot create debugfs disc trace "
5518 atomic_set(&vport->disc_trc_cnt, 0);
5520 snprintf(name, sizeof(name), "discovery_trace");
5521 vport->debug_disc_trc =
5522 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5523 vport->vport_debugfs_root,
5524 vport, &lpfc_debugfs_op_disc_trc);
5525 if (!vport->debug_disc_trc) {
5526 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5527 "0419 Cannot create debugfs "
5528 "discovery_trace\n");
5531 snprintf(name, sizeof(name), "nodelist");
5532 vport->debug_nodelist =
5533 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5534 vport->vport_debugfs_root,
5535 vport, &lpfc_debugfs_op_nodelist);
5536 if (!vport->debug_nodelist) {
5537 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5538 "2985 Can't create debugfs nodelist\n");
5542 snprintf(name, sizeof(name), "nvmestat");
5543 vport->debug_nvmestat =
5544 debugfs_create_file(name, 0644,
5545 vport->vport_debugfs_root,
5546 vport, &lpfc_debugfs_op_nvmestat);
5547 if (!vport->debug_nvmestat) {
5548 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5549 "0811 Cannot create debugfs nvmestat\n");
5553 snprintf(name, sizeof(name), "nvmektime");
5554 vport->debug_nvmektime =
5555 debugfs_create_file(name, 0644,
5556 vport->vport_debugfs_root,
5557 vport, &lpfc_debugfs_op_nvmektime);
5558 if (!vport->debug_nvmektime) {
5559 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5560 "0815 Cannot create debugfs nvmektime\n");
5564 snprintf(name, sizeof(name), "cpucheck");
5565 vport->debug_cpucheck =
5566 debugfs_create_file(name, 0644,
5567 vport->vport_debugfs_root,
5568 vport, &lpfc_debugfs_op_cpucheck);
5569 if (!vport->debug_cpucheck) {
5570 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5571 "0819 Cannot create debugfs cpucheck\n");
5576 * The following section is for additional directories/files for the
5584 * iDiag debugfs root entry points for SLI4 device only
5586 if (phba->sli_rev < LPFC_SLI_REV4)
5589 snprintf(name, sizeof(name), "iDiag");
5590 if (!phba->idiag_root) {
5592 debugfs_create_dir(name, phba->hba_debugfs_root);
5593 if (!phba->idiag_root) {
5594 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5595 "2922 Can't create idiag debugfs\n");
5598 /* Initialize iDiag data structure */
5599 memset(&idiag, 0, sizeof(idiag));
5602 /* iDiag read PCI config space */
5603 snprintf(name, sizeof(name), "pciCfg");
5604 if (!phba->idiag_pci_cfg) {
5605 phba->idiag_pci_cfg =
5606 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5607 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
5608 if (!phba->idiag_pci_cfg) {
5609 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5610 "2923 Can't create idiag debugfs\n");
5613 idiag.offset.last_rd = 0;
5616 /* iDiag PCI BAR access */
5617 snprintf(name, sizeof(name), "barAcc");
5618 if (!phba->idiag_bar_acc) {
5619 phba->idiag_bar_acc =
5620 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5621 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
5622 if (!phba->idiag_bar_acc) {
5623 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5624 "3056 Can't create idiag debugfs\n");
5627 idiag.offset.last_rd = 0;
5630 /* iDiag get PCI function queue information */
5631 snprintf(name, sizeof(name), "queInfo");
5632 if (!phba->idiag_que_info) {
5633 phba->idiag_que_info =
5634 debugfs_create_file(name, S_IFREG|S_IRUGO,
5635 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
5636 if (!phba->idiag_que_info) {
5637 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5638 "2924 Can't create idiag debugfs\n");
5643 /* iDiag access PCI function queue */
5644 snprintf(name, sizeof(name), "queAcc");
5645 if (!phba->idiag_que_acc) {
5646 phba->idiag_que_acc =
5647 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5648 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
5649 if (!phba->idiag_que_acc) {
5650 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5651 "2926 Can't create idiag debugfs\n");
5656 /* iDiag access PCI function doorbell registers */
5657 snprintf(name, sizeof(name), "drbAcc");
5658 if (!phba->idiag_drb_acc) {
5659 phba->idiag_drb_acc =
5660 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5661 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
5662 if (!phba->idiag_drb_acc) {
5663 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5664 "2927 Can't create idiag debugfs\n");
5669 /* iDiag access PCI function control registers */
5670 snprintf(name, sizeof(name), "ctlAcc");
5671 if (!phba->idiag_ctl_acc) {
5672 phba->idiag_ctl_acc =
5673 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5674 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
5675 if (!phba->idiag_ctl_acc) {
5676 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5677 "2981 Can't create idiag debugfs\n");
5682 /* iDiag access mbox commands */
5683 snprintf(name, sizeof(name), "mbxAcc");
5684 if (!phba->idiag_mbx_acc) {
5685 phba->idiag_mbx_acc =
5686 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5687 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
5688 if (!phba->idiag_mbx_acc) {
5689 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5690 "2980 Can't create idiag debugfs\n");
5695 /* iDiag extents access commands */
5696 if (phba->sli4_hba.extents_in_use) {
5697 snprintf(name, sizeof(name), "extAcc");
5698 if (!phba->idiag_ext_acc) {
5699 phba->idiag_ext_acc =
5700 debugfs_create_file(name,
5701 S_IFREG|S_IRUGO|S_IWUSR,
5702 phba->idiag_root, phba,
5703 &lpfc_idiag_op_extAcc);
5704 if (!phba->idiag_ext_acc) {
5705 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5719 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
5720 * @vport: The vport pointer to remove from debugfs.
5723 * When Debugfs is configured this routine removes debugfs file system elements
5724 * that are specific to this vport. It also checks to see if there are any
5725 * users left for the debugfs directories associated with the HBA and driver. If
5726 * this is the last user of the HBA directory or driver directory then it will
5727 * remove those from the debugfs infrastructure as well.
5730 lpfc_debugfs_terminate(struct lpfc_vport *vport)
5732 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5733 struct lpfc_hba *phba = vport->phba;
5735 kfree(vport->disc_trc);
5736 vport->disc_trc = NULL;
5738 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
5739 vport->debug_disc_trc = NULL;
5741 debugfs_remove(vport->debug_nodelist); /* nodelist */
5742 vport->debug_nodelist = NULL;
5744 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
5745 vport->debug_nvmestat = NULL;
5747 debugfs_remove(vport->debug_nvmektime); /* nvmektime */
5748 vport->debug_nvmektime = NULL;
5750 debugfs_remove(vport->debug_cpucheck); /* cpucheck */
5751 vport->debug_cpucheck = NULL;
5753 if (vport->vport_debugfs_root) {
5754 debugfs_remove(vport->vport_debugfs_root); /* vportX */
5755 vport->vport_debugfs_root = NULL;
5756 atomic_dec(&phba->debugfs_vport_count);
5759 if (atomic_read(&phba->debugfs_vport_count) == 0) {
5761 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
5762 phba->debug_hbqinfo = NULL;
5764 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
5765 phba->debug_dumpHBASlim = NULL;
5767 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
5768 phba->debug_dumpHostSlim = NULL;
5770 debugfs_remove(phba->debug_dumpData); /* dumpData */
5771 phba->debug_dumpData = NULL;
5773 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
5774 phba->debug_dumpDif = NULL;
5776 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
5777 phba->debug_InjErrLBA = NULL;
5779 debugfs_remove(phba->debug_InjErrNPortID);
5780 phba->debug_InjErrNPortID = NULL;
5782 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
5783 phba->debug_InjErrWWPN = NULL;
5785 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
5786 phba->debug_writeGuard = NULL;
5788 debugfs_remove(phba->debug_writeApp); /* writeApp */
5789 phba->debug_writeApp = NULL;
5791 debugfs_remove(phba->debug_writeRef); /* writeRef */
5792 phba->debug_writeRef = NULL;
5794 debugfs_remove(phba->debug_readGuard); /* readGuard */
5795 phba->debug_readGuard = NULL;
5797 debugfs_remove(phba->debug_readApp); /* readApp */
5798 phba->debug_readApp = NULL;
5800 debugfs_remove(phba->debug_readRef); /* readRef */
5801 phba->debug_readRef = NULL;
5803 kfree(phba->slow_ring_trc);
5804 phba->slow_ring_trc = NULL;
5806 /* slow_ring_trace */
5807 debugfs_remove(phba->debug_slow_ring_trc);
5808 phba->debug_slow_ring_trc = NULL;
5810 debugfs_remove(phba->debug_nvmeio_trc);
5811 phba->debug_nvmeio_trc = NULL;
5813 kfree(phba->nvmeio_trc);
5814 phba->nvmeio_trc = NULL;
5819 if (phba->sli_rev == LPFC_SLI_REV4) {
5821 debugfs_remove(phba->idiag_ext_acc);
5822 phba->idiag_ext_acc = NULL;
5825 debugfs_remove(phba->idiag_mbx_acc);
5826 phba->idiag_mbx_acc = NULL;
5829 debugfs_remove(phba->idiag_ctl_acc);
5830 phba->idiag_ctl_acc = NULL;
5833 debugfs_remove(phba->idiag_drb_acc);
5834 phba->idiag_drb_acc = NULL;
5837 debugfs_remove(phba->idiag_que_acc);
5838 phba->idiag_que_acc = NULL;
5841 debugfs_remove(phba->idiag_que_info);
5842 phba->idiag_que_info = NULL;
5845 debugfs_remove(phba->idiag_bar_acc);
5846 phba->idiag_bar_acc = NULL;
5849 debugfs_remove(phba->idiag_pci_cfg);
5850 phba->idiag_pci_cfg = NULL;
5852 /* Finally remove the iDiag debugfs root */
5853 debugfs_remove(phba->idiag_root);
5854 phba->idiag_root = NULL;
5857 if (phba->hba_debugfs_root) {
5858 debugfs_remove(phba->hba_debugfs_root); /* fnX */
5859 phba->hba_debugfs_root = NULL;
5860 atomic_dec(&lpfc_debugfs_hba_count);
5863 debugfs_remove(lpfc_debugfs_root); /* lpfc */
5864 lpfc_debugfs_root = NULL;
5871 * Driver debug utility routines outside of debugfs. The debug utility
5872 * routines implemented here is intended to be used in the instrumented
5873 * debug driver for debugging host or port issues.
5877 * lpfc_debug_dump_all_queues - dump all the queues with a hba
5878 * @phba: Pointer to HBA context object.
5880 * This function dumps entries of all the queues asociated with the @phba.
5883 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
5888 * Dump Work Queues (WQs)
5890 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
5891 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
5892 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
5894 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5895 lpfc_debug_dump_wq(phba, DUMP_FCP, idx);
5897 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5898 lpfc_debug_dump_wq(phba, DUMP_NVME, idx);
5900 lpfc_debug_dump_hdr_rq(phba);
5901 lpfc_debug_dump_dat_rq(phba);
5903 * Dump Complete Queues (CQs)
5905 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
5906 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
5907 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
5909 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5910 lpfc_debug_dump_cq(phba, DUMP_FCP, idx);
5912 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5913 lpfc_debug_dump_cq(phba, DUMP_NVME, idx);
5916 * Dump Event Queues (EQs)
5918 for (idx = 0; idx < phba->io_channel_irqs; idx++)
5919 lpfc_debug_dump_hba_eq(phba, idx);