1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
21 #include <linux/blkdev.h>
22 #include <linux/delay.h>
23 #include <linux/module.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/kthread.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/ctype.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
41 #include "lpfc_sli4.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
49 #include "lpfc_version.h"
50 #include "lpfc_compat.h"
51 #include "lpfc_debugfs.h"
54 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
58 * To access this interface the user should:
59 * # mount -t debugfs none /sys/kernel/debug
61 * The lpfc debugfs directory hierarchy is:
62 * /sys/kernel/debug/lpfc/fnX/vportY
63 * where X is the lpfc hba function unique_id
64 * where Y is the vport VPI on that hba
66 * Debugging services available per vport:
68 * This is an ACSII readable file that contains a trace of the last
69 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
70 * See lpfc_debugfs.h for different categories of discovery events.
71 * To enable the discovery trace, the following module parameters must be set:
72 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
73 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
74 * EACH vport. X MUST also be a power of 2.
75 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
79 * This is an ACSII readable file that contains a trace of the last
80 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
81 * To enable the slow ring trace, the following module parameters must be set:
82 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
83 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
84 * the HBA. X MUST also be a power of 2.
86 static int lpfc_debugfs_enable = 1;
87 module_param(lpfc_debugfs_enable, int, S_IRUGO);
88 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
90 /* This MUST be a power of 2 */
91 static int lpfc_debugfs_max_disc_trc;
92 module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
93 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
94 "Set debugfs discovery trace depth");
96 /* This MUST be a power of 2 */
97 static int lpfc_debugfs_max_slow_ring_trc;
98 module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
99 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
100 "Set debugfs slow ring trace depth");
102 static int lpfc_debugfs_mask_disc_trc;
103 module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
104 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
105 "Set debugfs discovery trace mask");
107 #include <linux/debugfs.h>
109 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
110 static unsigned long lpfc_debugfs_start_time = 0L;
113 static struct lpfc_idiag idiag;
116 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
117 * @vport: The vport to gather the log info from.
118 * @buf: The buffer to dump log into.
119 * @size: The maximum amount of data to process.
122 * This routine gathers the lpfc discovery debugfs data from the @vport and
123 * dumps it to @buf up to @size number of bytes. It will start at the next entry
124 * in the log and process the log until the end of the buffer. Then it will
125 * gather from the beginning of the log and process until the current entry.
128 * Discovery logging will be disabled while while this routine dumps the log.
131 * This routine returns the amount of bytes that were dumped into @buf and will
135 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
137 int i, index, len, enable;
139 struct lpfc_debugfs_trc *dtp;
142 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
146 enable = lpfc_debugfs_enable;
147 lpfc_debugfs_enable = 0;
150 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
151 (lpfc_debugfs_max_disc_trc - 1);
152 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
153 dtp = vport->disc_trc + i;
156 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
158 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
159 dtp->seq_cnt, ms, dtp->fmt);
160 len += snprintf(buf+len, size-len, buffer,
161 dtp->data1, dtp->data2, dtp->data3);
163 for (i = 0; i < index; i++) {
164 dtp = vport->disc_trc + i;
167 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
169 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
170 dtp->seq_cnt, ms, dtp->fmt);
171 len += snprintf(buf+len, size-len, buffer,
172 dtp->data1, dtp->data2, dtp->data3);
175 lpfc_debugfs_enable = enable;
182 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
183 * @phba: The HBA to gather the log info from.
184 * @buf: The buffer to dump log into.
185 * @size: The maximum amount of data to process.
188 * This routine gathers the lpfc slow ring debugfs data from the @phba and
189 * dumps it to @buf up to @size number of bytes. It will start at the next entry
190 * in the log and process the log until the end of the buffer. Then it will
191 * gather from the beginning of the log and process until the current entry.
194 * Slow ring logging will be disabled while while this routine dumps the log.
197 * This routine returns the amount of bytes that were dumped into @buf and will
201 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
203 int i, index, len, enable;
205 struct lpfc_debugfs_trc *dtp;
208 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
212 enable = lpfc_debugfs_enable;
213 lpfc_debugfs_enable = 0;
216 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
217 (lpfc_debugfs_max_slow_ring_trc - 1);
218 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
219 dtp = phba->slow_ring_trc + i;
222 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
224 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
225 dtp->seq_cnt, ms, dtp->fmt);
226 len += snprintf(buf+len, size-len, buffer,
227 dtp->data1, dtp->data2, dtp->data3);
229 for (i = 0; i < index; i++) {
230 dtp = phba->slow_ring_trc + i;
233 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
235 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
236 dtp->seq_cnt, ms, dtp->fmt);
237 len += snprintf(buf+len, size-len, buffer,
238 dtp->data1, dtp->data2, dtp->data3);
241 lpfc_debugfs_enable = enable;
247 static int lpfc_debugfs_last_hbq = -1;
250 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
251 * @phba: The HBA to gather host buffer info from.
252 * @buf: The buffer to dump log into.
253 * @size: The maximum amount of data to process.
256 * This routine dumps the host buffer queue info from the @phba to @buf up to
257 * @size number of bytes. A header that describes the current hbq state will be
258 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
259 * until @size bytes have been dumped or all the hbq info has been dumped.
262 * This routine will rotate through each configured HBQ each time called.
265 * This routine returns the amount of bytes that were dumped into @buf and will
269 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
272 int cnt, i, j, found, posted, low;
273 uint32_t phys, raw_index, getidx;
274 struct lpfc_hbq_init *hip;
276 struct lpfc_hbq_entry *hbqe;
277 struct lpfc_dmabuf *d_buf;
278 struct hbq_dmabuf *hbq_buf;
280 if (phba->sli_rev != 3)
282 cnt = LPFC_HBQINFO_SIZE;
283 spin_lock_irq(&phba->hbalock);
285 /* toggle between multiple hbqs, if any */
286 i = lpfc_sli_hbq_count();
288 lpfc_debugfs_last_hbq++;
289 if (lpfc_debugfs_last_hbq >= i)
290 lpfc_debugfs_last_hbq = 0;
293 lpfc_debugfs_last_hbq = 0;
295 i = lpfc_debugfs_last_hbq;
297 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
299 hbqs = &phba->hbqs[i];
301 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
304 hip = lpfc_hbq_defs[i];
305 len += snprintf(buf+len, size-len,
306 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
307 hip->hbq_index, hip->profile, hip->rn,
308 hip->buffer_count, hip->init_count, hip->add_count, posted);
310 raw_index = phba->hbq_get[i];
311 getidx = le32_to_cpu(raw_index);
312 len += snprintf(buf+len, size-len,
313 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
314 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
315 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
317 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
318 for (j=0; j<hbqs->entry_count; j++) {
319 len += snprintf(buf+len, size-len,
320 "%03d: %08x %04x %05x ", j,
321 le32_to_cpu(hbqe->bde.addrLow),
322 le32_to_cpu(hbqe->bde.tus.w),
323 le32_to_cpu(hbqe->buffer_tag));
327 /* First calculate if slot has an associated posted buffer */
328 low = hbqs->hbqPutIdx - posted;
330 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
331 len += snprintf(buf+len, size-len, "Unused\n");
336 if ((j >= hbqs->hbqPutIdx) &&
337 (j < (hbqs->entry_count+low))) {
338 len += snprintf(buf+len, size-len, "Unused\n");
343 /* Get the Buffer info for the posted buffer */
344 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
345 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
346 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
347 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
348 len += snprintf(buf+len, size-len,
349 "Buf%d: %p %06x\n", i,
350 hbq_buf->dbuf.virt, hbq_buf->tag);
357 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
361 if (len > LPFC_HBQINFO_SIZE - 54)
364 spin_unlock_irq(&phba->hbalock);
368 static int lpfc_debugfs_last_hba_slim_off;
371 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
372 * @phba: The HBA to gather SLIM info from.
373 * @buf: The buffer to dump log into.
374 * @size: The maximum amount of data to process.
377 * This routine dumps the current contents of HBA SLIM for the HBA associated
378 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
381 * This routine will only dump up to 1024 bytes of data each time called and
382 * should be called multiple times to dump the entire HBA SLIM.
385 * This routine returns the amount of bytes that were dumped into @buf and will
389 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
396 buffer = kmalloc(1024, GFP_KERNEL);
401 spin_lock_irq(&phba->hbalock);
403 len += snprintf(buf+len, size-len, "HBA SLIM\n");
404 lpfc_memcpy_from_slim(buffer,
405 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
407 ptr = (uint32_t *)&buffer[0];
408 off = lpfc_debugfs_last_hba_slim_off;
410 /* Set it up for the next time */
411 lpfc_debugfs_last_hba_slim_off += 1024;
412 if (lpfc_debugfs_last_hba_slim_off >= 4096)
413 lpfc_debugfs_last_hba_slim_off = 0;
417 len += snprintf(buf+len, size-len,
418 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
419 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
420 *(ptr+5), *(ptr+6), *(ptr+7));
422 i -= (8 * sizeof(uint32_t));
423 off += (8 * sizeof(uint32_t));
426 spin_unlock_irq(&phba->hbalock);
433 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
434 * @phba: The HBA to gather Host SLIM info from.
435 * @buf: The buffer to dump log into.
436 * @size: The maximum amount of data to process.
439 * This routine dumps the current contents of host SLIM for the host associated
440 * with @phba to @buf up to @size bytes of data. The dump will contain the
441 * Mailbox, PCB, Rings, and Registers that are located in host memory.
444 * This routine returns the amount of bytes that were dumped into @buf and will
448 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
452 uint32_t word0, word1, word2, word3;
454 struct lpfc_pgp *pgpp;
455 struct lpfc_sli *psli = &phba->sli;
456 struct lpfc_sli_ring *pring;
459 spin_lock_irq(&phba->hbalock);
461 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
462 ptr = (uint32_t *)phba->slim2p.virt;
463 i = sizeof(MAILBOX_t);
465 len += snprintf(buf+len, size-len,
466 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
467 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
468 *(ptr+5), *(ptr+6), *(ptr+7));
470 i -= (8 * sizeof(uint32_t));
471 off += (8 * sizeof(uint32_t));
474 len += snprintf(buf+len, size-len, "SLIM PCB\n");
475 ptr = (uint32_t *)phba->pcb;
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 for (i = 0; i < 4; i++) {
488 pgpp = &phba->port_gp[i];
489 pring = &psli->ring[i];
490 len += snprintf(buf+len, size-len,
491 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
492 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
493 i, pgpp->cmdGetInx, pring->sli.sli3.numCiocb,
494 pring->sli.sli3.next_cmdidx,
495 pring->sli.sli3.local_getidx,
496 pring->flag, pgpp->rspPutInx,
497 pring->sli.sli3.numRiocb);
500 if (phba->sli_rev <= LPFC_SLI_REV3) {
501 word0 = readl(phba->HAregaddr);
502 word1 = readl(phba->CAregaddr);
503 word2 = readl(phba->HSregaddr);
504 word3 = readl(phba->HCregaddr);
505 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
506 "HC:%08x\n", word0, word1, word2, word3);
508 spin_unlock_irq(&phba->hbalock);
513 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
514 * @vport: The vport to gather target node info from.
515 * @buf: The buffer to dump log into.
516 * @size: The maximum amount of data to process.
519 * This routine dumps the current target node list associated with @vport to
520 * @buf up to @size bytes of data. Each node entry in the dump will contain a
521 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
524 * This routine returns the amount of bytes that were dumped into @buf and will
528 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
532 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
533 struct lpfc_nodelist *ndlp;
534 unsigned char *statep, *name;
536 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
538 spin_lock_irq(shost->host_lock);
539 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
541 len += snprintf(buf+len, size-len,
542 "Missing Nodelist Entries\n");
546 switch (ndlp->nlp_state) {
547 case NLP_STE_UNUSED_NODE:
550 case NLP_STE_PLOGI_ISSUE:
553 case NLP_STE_ADISC_ISSUE:
556 case NLP_STE_REG_LOGIN_ISSUE:
559 case NLP_STE_PRLI_ISSUE:
562 case NLP_STE_LOGO_ISSUE:
565 case NLP_STE_UNMAPPED_NODE:
568 case NLP_STE_MAPPED_NODE:
571 case NLP_STE_NPR_NODE:
577 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
578 statep, ndlp->nlp_DID);
579 name = (unsigned char *)&ndlp->nlp_portname;
580 len += snprintf(buf+len, size-len,
581 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
582 *name, *(name+1), *(name+2), *(name+3),
583 *(name+4), *(name+5), *(name+6), *(name+7));
584 name = (unsigned char *)&ndlp->nlp_nodename;
585 len += snprintf(buf+len, size-len,
586 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
587 *name, *(name+1), *(name+2), *(name+3),
588 *(name+4), *(name+5), *(name+6), *(name+7));
589 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
590 len += snprintf(buf+len, size-len, "RPI:%03d ",
593 len += snprintf(buf+len, size-len, "RPI:none ");
594 len += snprintf(buf+len, size-len, "flag:x%08x ",
597 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
598 if (ndlp->nlp_type & NLP_FC_NODE)
599 len += snprintf(buf+len, size-len, "FC_NODE ");
600 if (ndlp->nlp_type & NLP_FABRIC)
601 len += snprintf(buf+len, size-len, "FABRIC ");
602 if (ndlp->nlp_type & NLP_FCP_TARGET)
603 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
605 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
606 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
607 len += snprintf(buf+len, size-len, "usgmap:%x ",
609 len += snprintf(buf+len, size-len, "refcnt:%x",
610 atomic_read(&ndlp->kref.refcount));
611 len += snprintf(buf+len, size-len, "\n");
613 spin_unlock_irq(shost->host_lock);
619 * lpfc_debugfs_disc_trc - Store discovery trace log
620 * @vport: The vport to associate this trace string with for retrieval.
621 * @mask: Log entry classification.
622 * @fmt: Format string to be displayed when dumping the log.
623 * @data1: 1st data parameter to be applied to @fmt.
624 * @data2: 2nd data parameter to be applied to @fmt.
625 * @data3: 3rd data parameter to be applied to @fmt.
628 * This routine is used by the driver code to add a debugfs log entry to the
629 * discovery trace buffer associated with @vport. Only entries with a @mask that
630 * match the current debugfs discovery mask will be saved. Entries that do not
631 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
632 * printf when displaying the log.
635 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
636 uint32_t data1, uint32_t data2, uint32_t data3)
638 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
639 struct lpfc_debugfs_trc *dtp;
642 if (!(lpfc_debugfs_mask_disc_trc & mask))
645 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
646 !vport || !vport->disc_trc)
649 index = atomic_inc_return(&vport->disc_trc_cnt) &
650 (lpfc_debugfs_max_disc_trc - 1);
651 dtp = vport->disc_trc + index;
656 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
663 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
664 * @phba: The phba to associate this trace string with for retrieval.
665 * @fmt: Format string to be displayed when dumping the log.
666 * @data1: 1st data parameter to be applied to @fmt.
667 * @data2: 2nd data parameter to be applied to @fmt.
668 * @data3: 3rd data parameter to be applied to @fmt.
671 * This routine is used by the driver code to add a debugfs log entry to the
672 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
673 * @data3 are used like printf when displaying the log.
676 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
677 uint32_t data1, uint32_t data2, uint32_t data3)
679 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
680 struct lpfc_debugfs_trc *dtp;
683 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
684 !phba || !phba->slow_ring_trc)
687 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
688 (lpfc_debugfs_max_slow_ring_trc - 1);
689 dtp = phba->slow_ring_trc + index;
694 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
700 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
702 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
703 * @inode: The inode pointer that contains a vport pointer.
704 * @file: The file pointer to attach the log output.
707 * This routine is the entry point for the debugfs open file operation. It gets
708 * the vport from the i_private field in @inode, allocates the necessary buffer
709 * for the log, fills the buffer from the in-memory log for this vport, and then
710 * returns a pointer to that log in the private_data field in @file.
713 * This function returns zero if successful. On error it will return an negative
717 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
719 struct lpfc_vport *vport = inode->i_private;
720 struct lpfc_debug *debug;
724 if (!lpfc_debugfs_max_disc_trc) {
729 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
733 /* Round to page boundary */
734 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
735 size = PAGE_ALIGN(size);
737 debug->buffer = kmalloc(size, GFP_KERNEL);
738 if (!debug->buffer) {
743 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
744 file->private_data = debug;
752 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
753 * @inode: The inode pointer that contains a vport pointer.
754 * @file: The file pointer to attach the log output.
757 * This routine is the entry point for the debugfs open file operation. It gets
758 * the vport from the i_private field in @inode, allocates the necessary buffer
759 * for the log, fills the buffer from the in-memory log for this vport, and then
760 * returns a pointer to that log in the private_data field in @file.
763 * This function returns zero if successful. On error it will return an negative
767 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
769 struct lpfc_hba *phba = inode->i_private;
770 struct lpfc_debug *debug;
774 if (!lpfc_debugfs_max_slow_ring_trc) {
779 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
783 /* Round to page boundary */
784 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
785 size = PAGE_ALIGN(size);
787 debug->buffer = kmalloc(size, GFP_KERNEL);
788 if (!debug->buffer) {
793 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
794 file->private_data = debug;
802 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
803 * @inode: The inode pointer that contains a vport pointer.
804 * @file: The file pointer to attach the log output.
807 * This routine is the entry point for the debugfs open file operation. It gets
808 * the vport from the i_private field in @inode, allocates the necessary buffer
809 * for the log, fills the buffer from the in-memory log for this vport, and then
810 * returns a pointer to that log in the private_data field in @file.
813 * This function returns zero if successful. On error it will return an negative
817 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
819 struct lpfc_hba *phba = inode->i_private;
820 struct lpfc_debug *debug;
823 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
827 /* Round to page boundary */
828 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
829 if (!debug->buffer) {
834 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
836 file->private_data = debug;
844 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
845 * @inode: The inode pointer that contains a vport pointer.
846 * @file: The file pointer to attach the log output.
849 * This routine is the entry point for the debugfs open file operation. It gets
850 * the vport from the i_private field in @inode, allocates the necessary buffer
851 * for the log, fills the buffer from the in-memory log for this vport, and then
852 * returns a pointer to that log in the private_data field in @file.
855 * This function returns zero if successful. On error it will return an negative
859 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
861 struct lpfc_hba *phba = inode->i_private;
862 struct lpfc_debug *debug;
865 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
869 /* Round to page boundary */
870 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
871 if (!debug->buffer) {
876 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
877 LPFC_DUMPHBASLIM_SIZE);
878 file->private_data = debug;
886 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
887 * @inode: The inode pointer that contains a vport pointer.
888 * @file: The file pointer to attach the log output.
891 * This routine is the entry point for the debugfs open file operation. It gets
892 * the vport from the i_private field in @inode, allocates the necessary buffer
893 * for the log, fills the buffer from the in-memory log for this vport, and then
894 * returns a pointer to that log in the private_data field in @file.
897 * This function returns zero if successful. On error it will return an negative
901 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
903 struct lpfc_hba *phba = inode->i_private;
904 struct lpfc_debug *debug;
907 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
911 /* Round to page boundary */
912 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
913 if (!debug->buffer) {
918 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
919 LPFC_DUMPHOSTSLIM_SIZE);
920 file->private_data = debug;
928 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
930 struct lpfc_debug *debug;
936 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
940 /* Round to page boundary */
941 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
942 __func__, _dump_buf_data);
943 debug->buffer = _dump_buf_data;
944 if (!debug->buffer) {
949 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
950 file->private_data = debug;
958 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
960 struct lpfc_debug *debug;
966 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
970 /* Round to page boundary */
971 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
972 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
973 debug->buffer = _dump_buf_dif;
974 if (!debug->buffer) {
979 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
980 file->private_data = debug;
988 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
989 size_t nbytes, loff_t *ppos)
992 * The Data/DIF buffers only save one failing IO
993 * The write op is used as a reset mechanism after an IO has
994 * already been saved to the next one can be saved
996 spin_lock(&_dump_buf_lock);
998 memset((void *)_dump_buf_data, 0,
999 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
1000 memset((void *)_dump_buf_dif, 0,
1001 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
1005 spin_unlock(&_dump_buf_lock);
1011 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1012 size_t nbytes, loff_t *ppos)
1014 struct dentry *dent = file->f_dentry;
1015 struct lpfc_hba *phba = file->private_data;
1020 if (dent == phba->debug_writeGuard)
1021 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1022 else if (dent == phba->debug_writeApp)
1023 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
1024 else if (dent == phba->debug_writeRef)
1025 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
1026 else if (dent == phba->debug_readGuard)
1027 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1028 else if (dent == phba->debug_readApp)
1029 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
1030 else if (dent == phba->debug_readRef)
1031 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1032 else if (dent == phba->debug_InjErrNPortID)
1033 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1034 else if (dent == phba->debug_InjErrWWPN) {
1035 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1036 tmp = cpu_to_be64(tmp);
1037 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1038 } else if (dent == phba->debug_InjErrLBA) {
1039 if (phba->lpfc_injerr_lba == (sector_t)(-1))
1040 cnt = snprintf(cbuf, 32, "off\n");
1042 cnt = snprintf(cbuf, 32, "0x%llx\n",
1043 (uint64_t) phba->lpfc_injerr_lba);
1045 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1046 "0547 Unknown debugfs error injection entry\n");
1048 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1052 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1053 size_t nbytes, loff_t *ppos)
1055 struct dentry *dent = file->f_dentry;
1056 struct lpfc_hba *phba = file->private_data;
1061 memset(dstbuf, 0, 32);
1062 size = (nbytes < 32) ? nbytes : 32;
1063 if (copy_from_user(dstbuf, buf, size))
1066 if (dent == phba->debug_InjErrLBA) {
1067 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1068 tmp = (uint64_t)(-1);
1071 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
1074 if (dent == phba->debug_writeGuard)
1075 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1076 else if (dent == phba->debug_writeApp)
1077 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1078 else if (dent == phba->debug_writeRef)
1079 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1080 else if (dent == phba->debug_readGuard)
1081 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
1082 else if (dent == phba->debug_readApp)
1083 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1084 else if (dent == phba->debug_readRef)
1085 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1086 else if (dent == phba->debug_InjErrLBA)
1087 phba->lpfc_injerr_lba = (sector_t)tmp;
1088 else if (dent == phba->debug_InjErrNPortID)
1089 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1090 else if (dent == phba->debug_InjErrWWPN) {
1091 tmp = cpu_to_be64(tmp);
1092 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1095 "0548 Unknown debugfs error injection entry\n");
1101 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1107 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1108 * @inode: The inode pointer that contains a vport pointer.
1109 * @file: The file pointer to attach the log output.
1112 * This routine is the entry point for the debugfs open file operation. It gets
1113 * the vport from the i_private field in @inode, allocates the necessary buffer
1114 * for the log, fills the buffer from the in-memory log for this vport, and then
1115 * returns a pointer to that log in the private_data field in @file.
1118 * This function returns zero if successful. On error it will return an negative
1122 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1124 struct lpfc_vport *vport = inode->i_private;
1125 struct lpfc_debug *debug;
1128 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1132 /* Round to page boundary */
1133 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1134 if (!debug->buffer) {
1139 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1140 LPFC_NODELIST_SIZE);
1141 file->private_data = debug;
1149 * lpfc_debugfs_lseek - Seek through a debugfs file
1150 * @file: The file pointer to seek through.
1151 * @off: The offset to seek to or the amount to seek by.
1152 * @whence: Indicates how to seek.
1155 * This routine is the entry point for the debugfs lseek file operation. The
1156 * @whence parameter indicates whether @off is the offset to directly seek to,
1157 * or if it is a value to seek forward or reverse by. This function figures out
1158 * what the new offset of the debugfs file will be and assigns that value to the
1159 * f_pos field of @file.
1162 * This function returns the new offset if successful and returns a negative
1163 * error if unable to process the seek.
1166 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1168 struct lpfc_debug *debug;
1171 debug = file->private_data;
1178 pos = file->f_pos + off;
1181 pos = debug->len - off;
1183 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1187 * lpfc_debugfs_read - Read a debugfs file
1188 * @file: The file pointer to read from.
1189 * @buf: The buffer to copy the data to.
1190 * @nbytes: The number of bytes to read.
1191 * @ppos: The position in the file to start reading from.
1194 * This routine reads data from from the buffer indicated in the private_data
1195 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1199 * This function returns the amount of data that was read (this could be less
1200 * than @nbytes if the end of the file was reached) or a negative error value.
1203 lpfc_debugfs_read(struct file *file, char __user *buf,
1204 size_t nbytes, loff_t *ppos)
1206 struct lpfc_debug *debug = file->private_data;
1208 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1213 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1214 * @inode: The inode pointer that contains a vport pointer. (unused)
1215 * @file: The file pointer that contains the buffer to release.
1218 * This routine frees the buffer that was allocated when the debugfs file was
1222 * This function returns zero.
1225 lpfc_debugfs_release(struct inode *inode, struct file *file)
1227 struct lpfc_debug *debug = file->private_data;
1229 kfree(debug->buffer);
1236 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1238 struct lpfc_debug *debug = file->private_data;
1240 debug->buffer = NULL;
1247 * ---------------------------------
1248 * iDiag debugfs file access methods
1249 * ---------------------------------
1251 * All access methods are through the proper SLI4 PCI function's debugfs
1254 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1258 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1259 * @buf: The pointer to the user space buffer.
1260 * @nbytes: The number of bytes in the user space buffer.
1261 * @idiag_cmd: pointer to the idiag command struct.
1263 * This routine reads data from debugfs user space buffer and parses the
1264 * buffer for getting the idiag command and arguments. The while space in
1265 * between the set of data is used as the parsing separator.
1267 * This routine returns 0 when successful, it returns proper error code
1268 * back to the user space in error conditions.
1270 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1271 struct lpfc_idiag_cmd *idiag_cmd)
1274 char *pbuf, *step_str;
1278 /* Protect copy from user */
1279 if (!access_ok(VERIFY_READ, buf, nbytes))
1282 memset(mybuf, 0, sizeof(mybuf));
1283 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1284 bsize = min(nbytes, (sizeof(mybuf)-1));
1286 if (copy_from_user(mybuf, buf, bsize))
1289 step_str = strsep(&pbuf, "\t ");
1291 /* The opcode must present */
1295 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1296 if (idiag_cmd->opcode == 0)
1299 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1300 step_str = strsep(&pbuf, "\t ");
1303 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1309 * lpfc_idiag_open - idiag open debugfs
1310 * @inode: The inode pointer that contains a pointer to phba.
1311 * @file: The file pointer to attach the file operation.
1314 * This routine is the entry point for the debugfs open file operation. It
1315 * gets the reference to phba from the i_private field in @inode, it then
1316 * allocates buffer for the file operation, performs the necessary PCI config
1317 * space read into the allocated buffer according to the idiag user command
1318 * setup, and then returns a pointer to buffer in the private_data field in
1322 * This function returns zero if successful. On error it will return an
1323 * negative error value.
1326 lpfc_idiag_open(struct inode *inode, struct file *file)
1328 struct lpfc_debug *debug;
1330 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1334 debug->i_private = inode->i_private;
1335 debug->buffer = NULL;
1336 file->private_data = debug;
1342 * lpfc_idiag_release - Release idiag access file operation
1343 * @inode: The inode pointer that contains a vport pointer. (unused)
1344 * @file: The file pointer that contains the buffer to release.
1347 * This routine is the generic release routine for the idiag access file
1348 * operation, it frees the buffer that was allocated when the debugfs file
1352 * This function returns zero.
1355 lpfc_idiag_release(struct inode *inode, struct file *file)
1357 struct lpfc_debug *debug = file->private_data;
1359 /* Free the buffers to the file operation */
1360 kfree(debug->buffer);
1367 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1368 * @inode: The inode pointer that contains a vport pointer. (unused)
1369 * @file: The file pointer that contains the buffer to release.
1372 * This routine frees the buffer that was allocated when the debugfs file
1373 * was opened. It also reset the fields in the idiag command struct in the
1374 * case of command for write operation.
1377 * This function returns zero.
1380 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1382 struct lpfc_debug *debug = file->private_data;
1384 if (debug->op == LPFC_IDIAG_OP_WR) {
1385 switch (idiag.cmd.opcode) {
1386 case LPFC_IDIAG_CMD_PCICFG_WR:
1387 case LPFC_IDIAG_CMD_PCICFG_ST:
1388 case LPFC_IDIAG_CMD_PCICFG_CL:
1389 case LPFC_IDIAG_CMD_QUEACC_WR:
1390 case LPFC_IDIAG_CMD_QUEACC_ST:
1391 case LPFC_IDIAG_CMD_QUEACC_CL:
1392 memset(&idiag, 0, sizeof(idiag));
1399 /* Free the buffers to the file operation */
1400 kfree(debug->buffer);
1407 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1408 * @file: The file pointer to read from.
1409 * @buf: The buffer to copy the data to.
1410 * @nbytes: The number of bytes to read.
1411 * @ppos: The position in the file to start reading from.
1414 * This routine reads data from the @phba pci config space according to the
1415 * idiag command, and copies to user @buf. Depending on the PCI config space
1416 * read command setup, it does either a single register read of a byte
1417 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1418 * registers from the 4K extended PCI config space.
1421 * This function returns the amount of data that was read (this could be less
1422 * than @nbytes if the end of the file was reached) or a negative error value.
1425 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1428 struct lpfc_debug *debug = file->private_data;
1429 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1430 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1433 struct pci_dev *pdev;
1438 pdev = phba->pcidev;
1442 /* This is a user read operation */
1443 debug->op = LPFC_IDIAG_OP_RD;
1446 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1449 pbuffer = debug->buffer;
1454 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1455 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1456 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1460 /* Read single PCI config space register */
1462 case SIZE_U8: /* byte (8 bits) */
1463 pci_read_config_byte(pdev, where, &u8val);
1464 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1465 "%03x: %02x\n", where, u8val);
1467 case SIZE_U16: /* word (16 bits) */
1468 pci_read_config_word(pdev, where, &u16val);
1469 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1470 "%03x: %04x\n", where, u16val);
1472 case SIZE_U32: /* double word (32 bits) */
1473 pci_read_config_dword(pdev, where, &u32val);
1474 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1475 "%03x: %08x\n", where, u32val);
1477 case LPFC_PCI_CFG_BROWSE: /* browse all */
1485 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1489 /* Browse all PCI config space registers */
1490 offset_label = idiag.offset.last_rd;
1491 offset = offset_label;
1493 /* Read PCI config space */
1494 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1495 "%03x: ", offset_label);
1497 pci_read_config_dword(pdev, offset, &u32val);
1498 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1500 offset += sizeof(uint32_t);
1501 if (offset >= LPFC_PCI_CFG_SIZE) {
1502 len += snprintf(pbuffer+len,
1503 LPFC_PCI_CFG_SIZE-len, "\n");
1506 index -= sizeof(uint32_t);
1508 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1510 else if (!(index % (8 * sizeof(uint32_t)))) {
1511 offset_label += (8 * sizeof(uint32_t));
1512 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1513 "\n%03x: ", offset_label);
1517 /* Set up the offset for next portion of pci cfg read */
1519 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1520 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1521 idiag.offset.last_rd = 0;
1523 idiag.offset.last_rd = 0;
1525 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1529 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1530 * @file: The file pointer to read from.
1531 * @buf: The buffer to copy the user data from.
1532 * @nbytes: The number of bytes to get.
1533 * @ppos: The position in the file to start reading from.
1535 * This routine get the debugfs idiag command struct from user space and
1536 * then perform the syntax check for PCI config space read or write command
1537 * accordingly. In the case of PCI config space read command, it sets up
1538 * the command in the idiag command struct for the debugfs read operation.
1539 * In the case of PCI config space write operation, it executes the write
1540 * operation into the PCI config space accordingly.
1542 * It returns the @nbytges passing in from debugfs user space when successful.
1543 * In case of error conditions, it returns proper error code back to the user
1547 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1548 size_t nbytes, loff_t *ppos)
1550 struct lpfc_debug *debug = file->private_data;
1551 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1552 uint32_t where, value, count;
1556 struct pci_dev *pdev;
1559 pdev = phba->pcidev;
1563 /* This is a user write operation */
1564 debug->op = LPFC_IDIAG_OP_WR;
1566 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1570 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1571 /* Sanity check on PCI config read command line arguments */
1572 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1574 /* Read command from PCI config space, set up command fields */
1575 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1576 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1577 if (count == LPFC_PCI_CFG_BROWSE) {
1578 if (where % sizeof(uint32_t))
1580 /* Starting offset to browse */
1581 idiag.offset.last_rd = where;
1582 } else if ((count != sizeof(uint8_t)) &&
1583 (count != sizeof(uint16_t)) &&
1584 (count != sizeof(uint32_t)))
1586 if (count == sizeof(uint8_t)) {
1587 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1589 if (where % sizeof(uint8_t))
1592 if (count == sizeof(uint16_t)) {
1593 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1595 if (where % sizeof(uint16_t))
1598 if (count == sizeof(uint32_t)) {
1599 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1601 if (where % sizeof(uint32_t))
1604 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1605 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1606 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1607 /* Sanity check on PCI config write command line arguments */
1608 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1610 /* Write command to PCI config space, read-modify-write */
1611 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1612 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1613 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
1615 if ((count != sizeof(uint8_t)) &&
1616 (count != sizeof(uint16_t)) &&
1617 (count != sizeof(uint32_t)))
1619 if (count == sizeof(uint8_t)) {
1620 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1622 if (where % sizeof(uint8_t))
1624 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1625 pci_write_config_byte(pdev, where,
1627 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1628 rc = pci_read_config_byte(pdev, where, &u8val);
1630 u8val |= (uint8_t)value;
1631 pci_write_config_byte(pdev, where,
1635 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1636 rc = pci_read_config_byte(pdev, where, &u8val);
1638 u8val &= (uint8_t)(~value);
1639 pci_write_config_byte(pdev, where,
1644 if (count == sizeof(uint16_t)) {
1645 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1647 if (where % sizeof(uint16_t))
1649 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1650 pci_write_config_word(pdev, where,
1652 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1653 rc = pci_read_config_word(pdev, where, &u16val);
1655 u16val |= (uint16_t)value;
1656 pci_write_config_word(pdev, where,
1660 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1661 rc = pci_read_config_word(pdev, where, &u16val);
1663 u16val &= (uint16_t)(~value);
1664 pci_write_config_word(pdev, where,
1669 if (count == sizeof(uint32_t)) {
1670 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1672 if (where % sizeof(uint32_t))
1674 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1675 pci_write_config_dword(pdev, where, value);
1676 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1677 rc = pci_read_config_dword(pdev, where,
1681 pci_write_config_dword(pdev, where,
1685 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1686 rc = pci_read_config_dword(pdev, where,
1690 pci_write_config_dword(pdev, where,
1696 /* All other opecodes are illegal for now */
1701 memset(&idiag, 0, sizeof(idiag));
1706 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1707 * @file: The file pointer to read from.
1708 * @buf: The buffer to copy the data to.
1709 * @nbytes: The number of bytes to read.
1710 * @ppos: The position in the file to start reading from.
1713 * This routine reads data from the @phba pci bar memory mapped space
1714 * according to the idiag command, and copies to user @buf.
1717 * This function returns the amount of data that was read (this could be less
1718 * than @nbytes if the end of the file was reached) or a negative error value.
1721 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1724 struct lpfc_debug *debug = file->private_data;
1725 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1726 int offset_label, offset, offset_run, len = 0, index;
1727 int bar_num, acc_range, bar_size;
1729 void __iomem *mem_mapped_bar;
1731 struct pci_dev *pdev;
1734 pdev = phba->pcidev;
1738 /* This is a user read operation */
1739 debug->op = LPFC_IDIAG_OP_RD;
1742 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1745 pbuffer = debug->buffer;
1750 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1751 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1752 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1753 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1754 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1761 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1762 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1763 if (bar_num == IDIAG_BARACC_BAR_0)
1764 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1765 else if (bar_num == IDIAG_BARACC_BAR_1)
1766 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1767 else if (bar_num == IDIAG_BARACC_BAR_2)
1768 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1771 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1772 if (bar_num == IDIAG_BARACC_BAR_0)
1773 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1779 /* Read single PCI bar space register */
1780 if (acc_range == SINGLE_WORD) {
1781 offset_run = offset;
1782 u32val = readl(mem_mapped_bar + offset_run);
1783 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1784 "%05x: %08x\n", offset_run, u32val);
1788 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1792 /* Browse all PCI bar space registers */
1793 offset_label = idiag.offset.last_rd;
1794 offset_run = offset_label;
1796 /* Read PCI bar memory mapped space */
1797 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1798 "%05x: ", offset_label);
1799 index = LPFC_PCI_BAR_RD_SIZE;
1801 u32val = readl(mem_mapped_bar + offset_run);
1802 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1804 offset_run += sizeof(uint32_t);
1805 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1806 if (offset_run >= bar_size) {
1807 len += snprintf(pbuffer+len,
1808 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1812 if (offset_run >= offset +
1813 (acc_range * sizeof(uint32_t))) {
1814 len += snprintf(pbuffer+len,
1815 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1819 index -= sizeof(uint32_t);
1821 len += snprintf(pbuffer+len,
1822 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1823 else if (!(index % (8 * sizeof(uint32_t)))) {
1824 offset_label += (8 * sizeof(uint32_t));
1825 len += snprintf(pbuffer+len,
1826 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1827 "\n%05x: ", offset_label);
1831 /* Set up the offset for next portion of pci bar read */
1833 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1834 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1835 if (idiag.offset.last_rd >= bar_size)
1836 idiag.offset.last_rd = 0;
1838 if (offset_run >= offset +
1839 (acc_range * sizeof(uint32_t)))
1840 idiag.offset.last_rd = offset;
1843 if (acc_range == LPFC_PCI_BAR_BROWSE)
1844 idiag.offset.last_rd = 0;
1846 idiag.offset.last_rd = offset;
1849 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1853 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1854 * @file: The file pointer to read from.
1855 * @buf: The buffer to copy the user data from.
1856 * @nbytes: The number of bytes to get.
1857 * @ppos: The position in the file to start reading from.
1859 * This routine get the debugfs idiag command struct from user space and
1860 * then perform the syntax check for PCI bar memory mapped space read or
1861 * write command accordingly. In the case of PCI bar memory mapped space
1862 * read command, it sets up the command in the idiag command struct for
1863 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1864 * write operation, it executes the write operation into the PCI bar memory
1865 * mapped space accordingly.
1867 * It returns the @nbytges passing in from debugfs user space when successful.
1868 * In case of error conditions, it returns proper error code back to the user
1872 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1873 size_t nbytes, loff_t *ppos)
1875 struct lpfc_debug *debug = file->private_data;
1876 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1877 uint32_t bar_num, bar_size, offset, value, acc_range;
1878 struct pci_dev *pdev;
1879 void __iomem *mem_mapped_bar;
1884 pdev = phba->pcidev;
1888 /* This is a user write operation */
1889 debug->op = LPFC_IDIAG_OP_WR;
1891 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1895 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1896 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1898 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1899 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1900 (bar_num != IDIAG_BARACC_BAR_1) &&
1901 (bar_num != IDIAG_BARACC_BAR_2))
1903 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1904 if (bar_num != IDIAG_BARACC_BAR_0)
1909 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1910 if (bar_num == IDIAG_BARACC_BAR_0) {
1911 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1912 LPFC_PCI_IF0_BAR0_SIZE;
1913 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1914 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1915 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1916 LPFC_PCI_IF0_BAR1_SIZE;
1917 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1918 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1919 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1920 LPFC_PCI_IF0_BAR2_SIZE;
1921 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1924 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1925 if (bar_num == IDIAG_BARACC_BAR_0) {
1926 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1927 LPFC_PCI_IF2_BAR0_SIZE;
1928 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1934 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1935 if (offset % sizeof(uint32_t))
1938 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1939 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1940 /* Sanity check on PCI config read command line arguments */
1941 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1943 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1944 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1945 if (offset > bar_size - sizeof(uint32_t))
1947 /* Starting offset to browse */
1948 idiag.offset.last_rd = offset;
1949 } else if (acc_range > SINGLE_WORD) {
1950 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1952 /* Starting offset to browse */
1953 idiag.offset.last_rd = offset;
1954 } else if (acc_range != SINGLE_WORD)
1956 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1957 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1958 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1959 /* Sanity check on PCI bar write command line arguments */
1960 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1962 /* Write command to PCI bar space, read-modify-write */
1963 acc_range = SINGLE_WORD;
1964 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1965 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1966 writel(value, mem_mapped_bar + offset);
1967 readl(mem_mapped_bar + offset);
1969 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1970 u32val = readl(mem_mapped_bar + offset);
1972 writel(u32val, mem_mapped_bar + offset);
1973 readl(mem_mapped_bar + offset);
1975 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1976 u32val = readl(mem_mapped_bar + offset);
1978 writel(u32val, mem_mapped_bar + offset);
1979 readl(mem_mapped_bar + offset);
1982 /* All other opecodes are illegal for now */
1987 memset(&idiag, 0, sizeof(idiag));
1992 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1993 * @file: The file pointer to read from.
1994 * @buf: The buffer to copy the data to.
1995 * @nbytes: The number of bytes to read.
1996 * @ppos: The position in the file to start reading from.
1999 * This routine reads data from the @phba SLI4 PCI function queue information,
2000 * and copies to user @buf.
2003 * This function returns the amount of data that was read (this could be less
2004 * than @nbytes if the end of the file was reached) or a negative error value.
2007 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
2010 struct lpfc_debug *debug = file->private_data;
2011 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2016 struct lpfc_queue *qp = NULL;
2020 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
2023 pbuffer = debug->buffer;
2024 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 128;
2029 spin_lock_irq(&phba->hbalock);
2031 /* Fast-path event queue */
2032 if (phba->sli4_hba.hba_eq && phba->cfg_fcp_io_channel) {
2033 cnt = phba->cfg_fcp_io_channel;
2035 for (x = 0; x < cnt; x++) {
2038 qp = phba->sli4_hba.hba_eq[x];
2042 len += snprintf(pbuffer+len,
2043 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2045 "EQ-STAT[max:x%x noE:x%x "
2046 "bs:x%x proc:x%llx]\n",
2047 qp->q_cnt_1, qp->q_cnt_2,
2048 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
2050 len += snprintf(pbuffer+len,
2051 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2053 "QE-CNT[%04d], QE-SIZE[%04d], "
2054 "HOST-IDX[%04d], PORT-IDX[%04d]",
2062 /* Reset max counter */
2065 len += snprintf(pbuffer+len,
2066 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2070 /* Fast-path FCP CQ */
2071 qp = phba->sli4_hba.fcp_cq[x];
2072 len += snprintf(pbuffer+len,
2073 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2075 len += snprintf(pbuffer+len,
2076 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2078 "CQ STAT[max:x%x relw:x%x "
2079 "xabt:x%x wq:x%llx]\n",
2081 qp->q_cnt_1, qp->q_cnt_2,
2082 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
2083 len += snprintf(pbuffer+len,
2084 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2086 "QE-CNT[%04d], QE-SIZE[%04d], "
2087 "HOST-IDX[%04d], PORT-IDX[%04d]",
2088 qp->queue_id, qp->entry_count,
2089 qp->entry_size, qp->host_index,
2093 /* Reset max counter */
2096 len += snprintf(pbuffer+len,
2097 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2101 /* Fast-path FCP WQ */
2102 qp = phba->sli4_hba.fcp_wq[x];
2104 len += snprintf(pbuffer+len,
2105 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2106 "\t\tFCP WQ info: ");
2107 len += snprintf(pbuffer+len,
2108 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2110 "WQ-STAT[oflow:x%x posted:x%llx]\n",
2112 qp->q_cnt_1, (unsigned long long)qp->q_cnt_4);
2113 len += snprintf(pbuffer+len,
2114 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2116 "QE-CNT[%04d], QE-SIZE[%04d], "
2117 "HOST-IDX[%04d], PORT-IDX[%04d]",
2124 len += snprintf(pbuffer+len,
2125 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2132 /* Only EQ 0 has slow path CQs configured */
2134 /* Slow-path mailbox CQ */
2135 qp = phba->sli4_hba.mbx_cq;
2137 len += snprintf(pbuffer+len,
2138 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2140 len += snprintf(pbuffer+len,
2141 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2143 "CQ-STAT[mbox:x%x relw:x%x "
2144 "xabt:x%x wq:x%llx]\n",
2146 qp->q_cnt_1, qp->q_cnt_2,
2148 (unsigned long long)qp->q_cnt_4);
2149 len += snprintf(pbuffer+len,
2150 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2152 "QE-CNT[%04d], QE-SIZE[%04d], "
2153 "HOST-IDX[%04d], PORT-IDX[%04d]",
2154 qp->queue_id, qp->entry_count,
2155 qp->entry_size, qp->host_index,
2158 len += snprintf(pbuffer+len,
2159 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2164 /* Slow-path MBOX MQ */
2165 qp = phba->sli4_hba.mbx_wq;
2167 len += snprintf(pbuffer+len,
2168 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2169 "\t\tMBX MQ info: ");
2170 len += snprintf(pbuffer+len,
2171 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2172 "AssocCQID[%02d]:\n",
2173 phba->sli4_hba.mbx_wq->assoc_qid);
2174 len += snprintf(pbuffer+len,
2175 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2177 "QE-CNT[%04d], QE-SIZE[%04d], "
2178 "HOST-IDX[%04d], PORT-IDX[%04d]",
2179 qp->queue_id, qp->entry_count,
2180 qp->entry_size, qp->host_index,
2183 len += snprintf(pbuffer+len,
2184 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2189 /* Slow-path ELS response CQ */
2190 qp = phba->sli4_hba.els_cq;
2192 len += snprintf(pbuffer+len,
2193 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2195 len += snprintf(pbuffer+len,
2196 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2198 "CQ-STAT[max:x%x relw:x%x "
2199 "xabt:x%x wq:x%llx]\n",
2201 qp->q_cnt_1, qp->q_cnt_2,
2203 (unsigned long long)qp->q_cnt_4);
2204 len += snprintf(pbuffer+len,
2205 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2207 "QE-CNT[%04d], QE-SIZE[%04d], "
2208 "HOST-IDX[%04d], PORT-IDX[%04d]",
2209 qp->queue_id, qp->entry_count,
2210 qp->entry_size, qp->host_index,
2213 /* Reset max counter */
2216 len += snprintf(pbuffer+len,
2217 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2222 /* Slow-path ELS WQ */
2223 qp = phba->sli4_hba.els_wq;
2225 len += snprintf(pbuffer+len,
2226 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2227 "\t\tELS WQ info: ");
2228 len += snprintf(pbuffer+len,
2229 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2231 " WQ-STAT[oflow:x%x "
2235 (unsigned long long)qp->q_cnt_4);
2236 len += snprintf(pbuffer+len,
2237 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2239 "QE-CNT[%04d], QE-SIZE[%04d], "
2240 "HOST-IDX[%04d], PORT-IDX[%04d]",
2241 qp->queue_id, qp->entry_count,
2242 qp->entry_size, qp->host_index,
2245 len += snprintf(pbuffer+len,
2246 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2251 if (phba->sli4_hba.hdr_rq && phba->sli4_hba.dat_rq) {
2252 /* Slow-path RQ header */
2253 qp = phba->sli4_hba.hdr_rq;
2255 len += snprintf(pbuffer+len,
2256 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2258 len += snprintf(pbuffer+len,
2259 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2261 "RQ-STAT[nopost:x%x nobuf:x%x "
2262 "trunc:x%x rcv:x%llx]\n",
2264 qp->q_cnt_1, qp->q_cnt_2,
2266 (unsigned long long)qp->q_cnt_4);
2267 len += snprintf(pbuffer+len,
2268 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2270 "QE-CNT[%04d], QE-SIZE[%04d], "
2271 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
2278 /* Slow-path RQ data */
2279 qp = phba->sli4_hba.dat_rq;
2280 len += snprintf(pbuffer+len,
2281 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2283 "QE-CNT[%04d], QE-SIZE[%04d], "
2284 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
2291 len += snprintf(pbuffer+len,
2292 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2297 spin_unlock_irq(&phba->hbalock);
2298 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2301 len += snprintf(pbuffer+len,
2302 LPFC_QUE_INFO_GET_BUF_SIZE-len, "Truncated ...\n");
2303 spin_unlock_irq(&phba->hbalock);
2304 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2308 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2309 * @q: The pointer to queue structure.
2310 * @index: The index into a queue entry.
2311 * @count: The number of queue entries to access.
2314 * The routine performs sanity check on device queue access method commands.
2317 * This function returns -EINVAL when fails the sanity check, otherwise, it
2321 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2323 /* Only support single entry read or browsing */
2324 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2326 if (index > q->entry_count - 1)
2332 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2333 * @pbuffer: The pointer to buffer to copy the read data into.
2334 * @pque: The pointer to the queue to be read.
2335 * @index: The index into the queue entry.
2338 * This routine reads out a single entry from the given queue's index location
2339 * and copies it into the buffer provided.
2342 * This function returns 0 when it fails, otherwise, it returns the length of
2343 * the data read into the buffer provided.
2346 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2352 if (!pbuffer || !pque)
2355 esize = pque->entry_size;
2356 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2357 "QE-INDEX[%04d]:\n", index);
2360 pentry = pque->qe[index].address;
2362 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2365 offset += sizeof(uint32_t);
2366 esize -= sizeof(uint32_t);
2367 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2368 len += snprintf(pbuffer+len,
2369 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2371 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2377 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2378 * @file: The file pointer to read from.
2379 * @buf: The buffer to copy the data to.
2380 * @nbytes: The number of bytes to read.
2381 * @ppos: The position in the file to start reading from.
2384 * This routine reads data from the @phba device queue memory according to the
2385 * idiag command, and copies to user @buf. Depending on the queue dump read
2386 * command setup, it does either a single queue entry read or browing through
2387 * all entries of the queue.
2390 * This function returns the amount of data that was read (this could be less
2391 * than @nbytes if the end of the file was reached) or a negative error value.
2394 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2397 struct lpfc_debug *debug = file->private_data;
2398 uint32_t last_index, index, count;
2399 struct lpfc_queue *pque = NULL;
2403 /* This is a user read operation */
2404 debug->op = LPFC_IDIAG_OP_RD;
2407 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2410 pbuffer = debug->buffer;
2415 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2416 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2417 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2418 pque = (struct lpfc_queue *)idiag.ptr_private;
2422 /* Browse the queue starting from index */
2423 if (count == LPFC_QUE_ACC_BROWSE)
2426 /* Read a single entry from the queue */
2427 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2429 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2433 /* Browse all entries from the queue */
2434 last_index = idiag.offset.last_rd;
2437 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2438 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2440 if (index > pque->entry_count - 1)
2444 /* Set up the offset for next portion of pci cfg read */
2445 if (index > pque->entry_count - 1)
2447 idiag.offset.last_rd = index;
2449 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2453 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2454 * @file: The file pointer to read from.
2455 * @buf: The buffer to copy the user data from.
2456 * @nbytes: The number of bytes to get.
2457 * @ppos: The position in the file to start reading from.
2459 * This routine get the debugfs idiag command struct from user space and then
2460 * perform the syntax check for port queue read (dump) or write (set) command
2461 * accordingly. In the case of port queue read command, it sets up the command
2462 * in the idiag command struct for the following debugfs read operation. In
2463 * the case of port queue write operation, it executes the write operation
2464 * into the port queue entry accordingly.
2466 * It returns the @nbytges passing in from debugfs user space when successful.
2467 * In case of error conditions, it returns proper error code back to the user
2471 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2472 size_t nbytes, loff_t *ppos)
2474 struct lpfc_debug *debug = file->private_data;
2475 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2476 uint32_t qidx, quetp, queid, index, count, offset, value;
2478 struct lpfc_queue *pque;
2481 /* This is a user write operation */
2482 debug->op = LPFC_IDIAG_OP_WR;
2484 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2488 /* Get and sanity check on command feilds */
2489 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2490 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2491 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2492 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2493 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2494 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
2496 /* Sanity check on command line arguments */
2497 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2498 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2499 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2500 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2504 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2505 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2512 /* HBA event queue */
2513 if (phba->sli4_hba.hba_eq) {
2514 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
2516 if (phba->sli4_hba.hba_eq[qidx] &&
2517 phba->sli4_hba.hba_eq[qidx]->queue_id ==
2520 rc = lpfc_idiag_que_param_check(
2521 phba->sli4_hba.hba_eq[qidx],
2526 phba->sli4_hba.hba_eq[qidx];
2534 /* MBX complete queue */
2535 if (phba->sli4_hba.mbx_cq &&
2536 phba->sli4_hba.mbx_cq->queue_id == queid) {
2538 rc = lpfc_idiag_que_param_check(
2539 phba->sli4_hba.mbx_cq, index, count);
2542 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2545 /* ELS complete queue */
2546 if (phba->sli4_hba.els_cq &&
2547 phba->sli4_hba.els_cq->queue_id == queid) {
2549 rc = lpfc_idiag_que_param_check(
2550 phba->sli4_hba.els_cq, index, count);
2553 idiag.ptr_private = phba->sli4_hba.els_cq;
2556 /* FCP complete queue */
2557 if (phba->sli4_hba.fcp_cq) {
2560 if (phba->sli4_hba.fcp_cq[qidx] &&
2561 phba->sli4_hba.fcp_cq[qidx]->queue_id ==
2564 rc = lpfc_idiag_que_param_check(
2565 phba->sli4_hba.fcp_cq[qidx],
2570 phba->sli4_hba.fcp_cq[qidx];
2573 } while (++qidx < phba->cfg_fcp_io_channel);
2578 /* MBX work queue */
2579 if (phba->sli4_hba.mbx_wq &&
2580 phba->sli4_hba.mbx_wq->queue_id == queid) {
2582 rc = lpfc_idiag_que_param_check(
2583 phba->sli4_hba.mbx_wq, index, count);
2586 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2592 /* ELS work queue */
2593 if (phba->sli4_hba.els_wq &&
2594 phba->sli4_hba.els_wq->queue_id == queid) {
2596 rc = lpfc_idiag_que_param_check(
2597 phba->sli4_hba.els_wq, index, count);
2600 idiag.ptr_private = phba->sli4_hba.els_wq;
2603 /* FCP work queue */
2604 if (phba->sli4_hba.fcp_wq) {
2605 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
2607 if (!phba->sli4_hba.fcp_wq[qidx])
2609 if (phba->sli4_hba.fcp_wq[qidx]->queue_id ==
2612 rc = lpfc_idiag_que_param_check(
2613 phba->sli4_hba.fcp_wq[qidx],
2618 phba->sli4_hba.fcp_wq[qidx];
2627 if (phba->sli4_hba.hdr_rq &&
2628 phba->sli4_hba.hdr_rq->queue_id == queid) {
2630 rc = lpfc_idiag_que_param_check(
2631 phba->sli4_hba.hdr_rq, index, count);
2634 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2638 if (phba->sli4_hba.dat_rq &&
2639 phba->sli4_hba.dat_rq->queue_id == queid) {
2641 rc = lpfc_idiag_que_param_check(
2642 phba->sli4_hba.dat_rq, index, count);
2645 idiag.ptr_private = phba->sli4_hba.dat_rq;
2657 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2658 if (count == LPFC_QUE_ACC_BROWSE)
2659 idiag.offset.last_rd = index;
2662 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2663 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2664 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2665 /* Additional sanity checks on write operation */
2666 pque = (struct lpfc_queue *)idiag.ptr_private;
2667 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2669 pentry = pque->qe[index].address;
2671 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2673 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2675 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2681 /* Clean out command structure on command error out */
2682 memset(&idiag, 0, sizeof(idiag));
2687 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2688 * @phba: The pointer to hba structure.
2689 * @pbuffer: The pointer to the buffer to copy the data to.
2690 * @len: The lenght of bytes to copied.
2691 * @drbregid: The id to doorbell registers.
2694 * This routine reads a doorbell register and copies its content to the
2695 * user buffer pointed to by @pbuffer.
2698 * This function returns the amount of data that was copied into @pbuffer.
2701 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2702 int len, uint32_t drbregid)
2710 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2711 "EQCQ-DRB-REG: 0x%08x\n",
2712 readl(phba->sli4_hba.EQCQDBregaddr));
2715 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2716 "MQ-DRB-REG: 0x%08x\n",
2717 readl(phba->sli4_hba.MQDBregaddr));
2720 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2721 "WQ-DRB-REG: 0x%08x\n",
2722 readl(phba->sli4_hba.WQDBregaddr));
2725 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2726 "RQ-DRB-REG: 0x%08x\n",
2727 readl(phba->sli4_hba.RQDBregaddr));
2737 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2738 * @file: The file pointer to read from.
2739 * @buf: The buffer to copy the data to.
2740 * @nbytes: The number of bytes to read.
2741 * @ppos: The position in the file to start reading from.
2744 * This routine reads data from the @phba device doorbell register according
2745 * to the idiag command, and copies to user @buf. Depending on the doorbell
2746 * register read command setup, it does either a single doorbell register
2747 * read or dump all doorbell registers.
2750 * This function returns the amount of data that was read (this could be less
2751 * than @nbytes if the end of the file was reached) or a negative error value.
2754 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2757 struct lpfc_debug *debug = file->private_data;
2758 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2759 uint32_t drb_reg_id, i;
2763 /* This is a user read operation */
2764 debug->op = LPFC_IDIAG_OP_RD;
2767 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2770 pbuffer = debug->buffer;
2775 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
2776 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2780 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2781 for (i = 1; i <= LPFC_DRB_MAX; i++)
2782 len = lpfc_idiag_drbacc_read_reg(phba,
2785 len = lpfc_idiag_drbacc_read_reg(phba,
2786 pbuffer, len, drb_reg_id);
2788 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2792 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2793 * @file: The file pointer to read from.
2794 * @buf: The buffer to copy the user data from.
2795 * @nbytes: The number of bytes to get.
2796 * @ppos: The position in the file to start reading from.
2798 * This routine get the debugfs idiag command struct from user space and then
2799 * perform the syntax check for port doorbell register read (dump) or write
2800 * (set) command accordingly. In the case of port queue read command, it sets
2801 * up the command in the idiag command struct for the following debugfs read
2802 * operation. In the case of port doorbell register write operation, it
2803 * executes the write operation into the port doorbell register accordingly.
2805 * It returns the @nbytges passing in from debugfs user space when successful.
2806 * In case of error conditions, it returns proper error code back to the user
2810 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2811 size_t nbytes, loff_t *ppos)
2813 struct lpfc_debug *debug = file->private_data;
2814 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2815 uint32_t drb_reg_id, value, reg_val = 0;
2816 void __iomem *drb_reg;
2819 /* This is a user write operation */
2820 debug->op = LPFC_IDIAG_OP_WR;
2822 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2826 /* Sanity check on command line arguments */
2827 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2828 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
2830 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2831 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2832 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2833 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2835 if (drb_reg_id > LPFC_DRB_MAX)
2837 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2838 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2840 if ((drb_reg_id > LPFC_DRB_MAX) &&
2841 (drb_reg_id != LPFC_DRB_ACC_ALL))
2846 /* Perform the write access operation */
2847 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2848 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2849 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2850 switch (drb_reg_id) {
2852 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2855 drb_reg = phba->sli4_hba.MQDBregaddr;
2858 drb_reg = phba->sli4_hba.WQDBregaddr;
2861 drb_reg = phba->sli4_hba.RQDBregaddr;
2867 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2869 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2870 reg_val = readl(drb_reg);
2873 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2874 reg_val = readl(drb_reg);
2877 writel(reg_val, drb_reg);
2878 readl(drb_reg); /* flush */
2883 /* Clean out command structure on command error out */
2884 memset(&idiag, 0, sizeof(idiag));
2889 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2890 * @phba: The pointer to hba structure.
2891 * @pbuffer: The pointer to the buffer to copy the data to.
2892 * @len: The lenght of bytes to copied.
2893 * @drbregid: The id to doorbell registers.
2896 * This routine reads a control register and copies its content to the
2897 * user buffer pointed to by @pbuffer.
2900 * This function returns the amount of data that was copied into @pbuffer.
2903 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2904 int len, uint32_t ctlregid)
2911 case LPFC_CTL_PORT_SEM:
2912 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2913 "Port SemReg: 0x%08x\n",
2914 readl(phba->sli4_hba.conf_regs_memmap_p +
2915 LPFC_CTL_PORT_SEM_OFFSET));
2917 case LPFC_CTL_PORT_STA:
2918 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2919 "Port StaReg: 0x%08x\n",
2920 readl(phba->sli4_hba.conf_regs_memmap_p +
2921 LPFC_CTL_PORT_STA_OFFSET));
2923 case LPFC_CTL_PORT_CTL:
2924 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2925 "Port CtlReg: 0x%08x\n",
2926 readl(phba->sli4_hba.conf_regs_memmap_p +
2927 LPFC_CTL_PORT_CTL_OFFSET));
2929 case LPFC_CTL_PORT_ER1:
2930 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2931 "Port Er1Reg: 0x%08x\n",
2932 readl(phba->sli4_hba.conf_regs_memmap_p +
2933 LPFC_CTL_PORT_ER1_OFFSET));
2935 case LPFC_CTL_PORT_ER2:
2936 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2937 "Port Er2Reg: 0x%08x\n",
2938 readl(phba->sli4_hba.conf_regs_memmap_p +
2939 LPFC_CTL_PORT_ER2_OFFSET));
2941 case LPFC_CTL_PDEV_CTL:
2942 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2943 "PDev CtlReg: 0x%08x\n",
2944 readl(phba->sli4_hba.conf_regs_memmap_p +
2945 LPFC_CTL_PDEV_CTL_OFFSET));
2954 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2955 * @file: The file pointer to read from.
2956 * @buf: The buffer to copy the data to.
2957 * @nbytes: The number of bytes to read.
2958 * @ppos: The position in the file to start reading from.
2961 * This routine reads data from the @phba port and device registers according
2962 * to the idiag command, and copies to user @buf.
2965 * This function returns the amount of data that was read (this could be less
2966 * than @nbytes if the end of the file was reached) or a negative error value.
2969 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2972 struct lpfc_debug *debug = file->private_data;
2973 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2974 uint32_t ctl_reg_id, i;
2978 /* This is a user read operation */
2979 debug->op = LPFC_IDIAG_OP_RD;
2982 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2985 pbuffer = debug->buffer;
2990 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2991 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2995 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2996 for (i = 1; i <= LPFC_CTL_MAX; i++)
2997 len = lpfc_idiag_ctlacc_read_reg(phba,
3000 len = lpfc_idiag_ctlacc_read_reg(phba,
3001 pbuffer, len, ctl_reg_id);
3003 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3007 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
3008 * @file: The file pointer to read from.
3009 * @buf: The buffer to copy the user data from.
3010 * @nbytes: The number of bytes to get.
3011 * @ppos: The position in the file to start reading from.
3013 * This routine get the debugfs idiag command struct from user space and then
3014 * perform the syntax check for port and device control register read (dump)
3015 * or write (set) command accordingly.
3017 * It returns the @nbytges passing in from debugfs user space when successful.
3018 * In case of error conditions, it returns proper error code back to the user
3022 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
3023 size_t nbytes, loff_t *ppos)
3025 struct lpfc_debug *debug = file->private_data;
3026 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3027 uint32_t ctl_reg_id, value, reg_val = 0;
3028 void __iomem *ctl_reg;
3031 /* This is a user write operation */
3032 debug->op = LPFC_IDIAG_OP_WR;
3034 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3038 /* Sanity check on command line arguments */
3039 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
3040 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
3042 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
3043 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
3044 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3045 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
3047 if (ctl_reg_id > LPFC_CTL_MAX)
3049 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
3050 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
3052 if ((ctl_reg_id > LPFC_CTL_MAX) &&
3053 (ctl_reg_id != LPFC_CTL_ACC_ALL))
3058 /* Perform the write access operation */
3059 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
3060 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
3061 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3062 switch (ctl_reg_id) {
3063 case LPFC_CTL_PORT_SEM:
3064 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3065 LPFC_CTL_PORT_SEM_OFFSET;
3067 case LPFC_CTL_PORT_STA:
3068 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3069 LPFC_CTL_PORT_STA_OFFSET;
3071 case LPFC_CTL_PORT_CTL:
3072 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3073 LPFC_CTL_PORT_CTL_OFFSET;
3075 case LPFC_CTL_PORT_ER1:
3076 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3077 LPFC_CTL_PORT_ER1_OFFSET;
3079 case LPFC_CTL_PORT_ER2:
3080 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3081 LPFC_CTL_PORT_ER2_OFFSET;
3083 case LPFC_CTL_PDEV_CTL:
3084 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3085 LPFC_CTL_PDEV_CTL_OFFSET;
3091 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
3093 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
3094 reg_val = readl(ctl_reg);
3097 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3098 reg_val = readl(ctl_reg);
3101 writel(reg_val, ctl_reg);
3102 readl(ctl_reg); /* flush */
3107 /* Clean out command structure on command error out */
3108 memset(&idiag, 0, sizeof(idiag));
3113 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
3114 * @phba: Pointer to HBA context object.
3115 * @pbuffer: Pointer to data buffer.
3118 * This routine gets the driver mailbox access debugfs setup information.
3121 * This function returns the amount of data that was read (this could be less
3122 * than @nbytes if the end of the file was reached) or a negative error value.
3125 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
3127 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3130 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3131 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3132 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3133 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3135 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3136 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
3137 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3138 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
3139 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3140 "mbx_word_cnt: %04d\n", mbx_word_cnt);
3141 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3142 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
3148 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
3149 * @file: The file pointer to read from.
3150 * @buf: The buffer to copy the data to.
3151 * @nbytes: The number of bytes to read.
3152 * @ppos: The position in the file to start reading from.
3155 * This routine reads data from the @phba driver mailbox access debugfs setup
3159 * This function returns the amount of data that was read (this could be less
3160 * than @nbytes if the end of the file was reached) or a negative error value.
3163 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3166 struct lpfc_debug *debug = file->private_data;
3167 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3171 /* This is a user read operation */
3172 debug->op = LPFC_IDIAG_OP_RD;
3175 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3178 pbuffer = debug->buffer;
3183 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3184 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3187 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3189 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3193 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3194 * @file: The file pointer to read from.
3195 * @buf: The buffer to copy the user data from.
3196 * @nbytes: The number of bytes to get.
3197 * @ppos: The position in the file to start reading from.
3199 * This routine get the debugfs idiag command struct from user space and then
3200 * perform the syntax check for driver mailbox command (dump) and sets up the
3201 * necessary states in the idiag command struct accordingly.
3203 * It returns the @nbytges passing in from debugfs user space when successful.
3204 * In case of error conditions, it returns proper error code back to the user
3208 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3209 size_t nbytes, loff_t *ppos)
3211 struct lpfc_debug *debug = file->private_data;
3212 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3215 /* This is a user write operation */
3216 debug->op = LPFC_IDIAG_OP_WR;
3218 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3222 /* Sanity check on command line arguments */
3223 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3224 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3225 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3226 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3228 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3229 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3231 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3232 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3234 if (mbx_word_cnt > sizeof(MAILBOX_t))
3236 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3237 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3239 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3240 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3242 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3244 if (mbx_mbox_cmd != 0x9b)
3249 if (mbx_word_cnt == 0)
3251 if (rc != LPFC_MBX_DMP_ARG)
3253 if (mbx_mbox_cmd & ~0xff)
3256 /* condition for stop mailbox dump */
3257 if (mbx_dump_cnt == 0)
3263 /* Clean out command structure on command error out */
3264 memset(&idiag, 0, sizeof(idiag));
3268 /* Clean out command structure on command error out */
3269 memset(&idiag, 0, sizeof(idiag));
3274 * lpfc_idiag_extacc_avail_get - get the available extents information
3275 * @phba: pointer to lpfc hba data structure.
3276 * @pbuffer: pointer to internal buffer.
3277 * @len: length into the internal buffer data has been copied.
3280 * This routine is to get the available extent information.
3283 * overall lenth of the data read into the internal buffer.
3286 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3288 uint16_t ext_cnt, ext_size;
3290 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3291 "\nAvailable Extents Information:\n");
3293 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3294 "\tPort Available VPI extents: ");
3295 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3296 &ext_cnt, &ext_size);
3297 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3298 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3300 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3301 "\tPort Available VFI extents: ");
3302 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3303 &ext_cnt, &ext_size);
3304 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3305 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3307 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3308 "\tPort Available RPI extents: ");
3309 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3310 &ext_cnt, &ext_size);
3311 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3312 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3314 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3315 "\tPort Available XRI extents: ");
3316 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3317 &ext_cnt, &ext_size);
3318 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3319 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3325 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3326 * @phba: pointer to lpfc hba data structure.
3327 * @pbuffer: pointer to internal buffer.
3328 * @len: length into the internal buffer data has been copied.
3331 * This routine is to get the allocated extent information.
3334 * overall lenth of the data read into the internal buffer.
3337 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3339 uint16_t ext_cnt, ext_size;
3342 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3343 "\nAllocated Extents Information:\n");
3345 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3346 "\tHost Allocated VPI extents: ");
3347 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3348 &ext_cnt, &ext_size);
3350 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3351 "Port %d Extent %3d, Size %3d\n",
3352 phba->brd_no, ext_cnt, ext_size);
3354 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3357 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3358 "\tHost Allocated VFI extents: ");
3359 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
3360 &ext_cnt, &ext_size);
3362 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3363 "Port %d Extent %3d, Size %3d\n",
3364 phba->brd_no, ext_cnt, ext_size);
3366 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3369 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3370 "\tHost Allocated RPI extents: ");
3371 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
3372 &ext_cnt, &ext_size);
3374 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3375 "Port %d Extent %3d, Size %3d\n",
3376 phba->brd_no, ext_cnt, ext_size);
3378 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3381 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3382 "\tHost Allocated XRI extents: ");
3383 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3384 &ext_cnt, &ext_size);
3386 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3387 "Port %d Extent %3d, Size %3d\n",
3388 phba->brd_no, ext_cnt, ext_size);
3390 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3397 * lpfc_idiag_extacc_drivr_get - get driver extent information
3398 * @phba: pointer to lpfc hba data structure.
3399 * @pbuffer: pointer to internal buffer.
3400 * @len: length into the internal buffer data has been copied.
3403 * This routine is to get the driver extent information.
3406 * overall lenth of the data read into the internal buffer.
3409 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3411 struct lpfc_rsrc_blks *rsrc_blks;
3414 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3415 "\nDriver Extents Information:\n");
3417 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3418 "\tVPI extents:\n");
3420 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3421 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3422 "\t\tBlock %3d: Start %4d, Count %4d\n",
3423 index, rsrc_blks->rsrc_start,
3424 rsrc_blks->rsrc_size);
3427 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3428 "\tVFI extents:\n");
3430 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3432 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3433 "\t\tBlock %3d: Start %4d, Count %4d\n",
3434 index, rsrc_blks->rsrc_start,
3435 rsrc_blks->rsrc_size);
3439 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3440 "\tRPI extents:\n");
3442 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
3444 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3445 "\t\tBlock %3d: Start %4d, Count %4d\n",
3446 index, rsrc_blks->rsrc_start,
3447 rsrc_blks->rsrc_size);
3451 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3452 "\tXRI extents:\n");
3454 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3456 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3457 "\t\tBlock %3d: Start %4d, Count %4d\n",
3458 index, rsrc_blks->rsrc_start,
3459 rsrc_blks->rsrc_size);
3467 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3468 * @file: The file pointer to read from.
3469 * @buf: The buffer to copy the user data from.
3470 * @nbytes: The number of bytes to get.
3471 * @ppos: The position in the file to start reading from.
3473 * This routine get the debugfs idiag command struct from user space and then
3474 * perform the syntax check for extent information access commands and sets
3475 * up the necessary states in the idiag command struct accordingly.
3477 * It returns the @nbytges passing in from debugfs user space when successful.
3478 * In case of error conditions, it returns proper error code back to the user
3482 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3483 size_t nbytes, loff_t *ppos)
3485 struct lpfc_debug *debug = file->private_data;
3489 /* This is a user write operation */
3490 debug->op = LPFC_IDIAG_OP_WR;
3492 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3496 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3498 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3500 if (rc != LPFC_EXT_ACC_CMD_ARG)
3502 if (!(ext_map & LPFC_EXT_ACC_ALL))
3507 /* Clean out command structure on command error out */
3508 memset(&idiag, 0, sizeof(idiag));
3513 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3514 * @file: The file pointer to read from.
3515 * @buf: The buffer to copy the data to.
3516 * @nbytes: The number of bytes to read.
3517 * @ppos: The position in the file to start reading from.
3520 * This routine reads data from the proper extent information according to
3521 * the idiag command, and copies to user @buf.
3524 * This function returns the amount of data that was read (this could be less
3525 * than @nbytes if the end of the file was reached) or a negative error value.
3528 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3531 struct lpfc_debug *debug = file->private_data;
3532 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3537 /* This is a user read operation */
3538 debug->op = LPFC_IDIAG_OP_RD;
3541 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3544 pbuffer = debug->buffer;
3547 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3550 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3551 if (ext_map & LPFC_EXT_ACC_AVAIL)
3552 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3553 if (ext_map & LPFC_EXT_ACC_ALLOC)
3554 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3555 if (ext_map & LPFC_EXT_ACC_DRIVR)
3556 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3558 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3561 #undef lpfc_debugfs_op_disc_trc
3562 static const struct file_operations lpfc_debugfs_op_disc_trc = {
3563 .owner = THIS_MODULE,
3564 .open = lpfc_debugfs_disc_trc_open,
3565 .llseek = lpfc_debugfs_lseek,
3566 .read = lpfc_debugfs_read,
3567 .release = lpfc_debugfs_release,
3570 #undef lpfc_debugfs_op_nodelist
3571 static const struct file_operations lpfc_debugfs_op_nodelist = {
3572 .owner = THIS_MODULE,
3573 .open = lpfc_debugfs_nodelist_open,
3574 .llseek = lpfc_debugfs_lseek,
3575 .read = lpfc_debugfs_read,
3576 .release = lpfc_debugfs_release,
3579 #undef lpfc_debugfs_op_hbqinfo
3580 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
3581 .owner = THIS_MODULE,
3582 .open = lpfc_debugfs_hbqinfo_open,
3583 .llseek = lpfc_debugfs_lseek,
3584 .read = lpfc_debugfs_read,
3585 .release = lpfc_debugfs_release,
3588 #undef lpfc_debugfs_op_dumpHBASlim
3589 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
3590 .owner = THIS_MODULE,
3591 .open = lpfc_debugfs_dumpHBASlim_open,
3592 .llseek = lpfc_debugfs_lseek,
3593 .read = lpfc_debugfs_read,
3594 .release = lpfc_debugfs_release,
3597 #undef lpfc_debugfs_op_dumpHostSlim
3598 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
3599 .owner = THIS_MODULE,
3600 .open = lpfc_debugfs_dumpHostSlim_open,
3601 .llseek = lpfc_debugfs_lseek,
3602 .read = lpfc_debugfs_read,
3603 .release = lpfc_debugfs_release,
3606 #undef lpfc_debugfs_op_dumpData
3607 static const struct file_operations lpfc_debugfs_op_dumpData = {
3608 .owner = THIS_MODULE,
3609 .open = lpfc_debugfs_dumpData_open,
3610 .llseek = lpfc_debugfs_lseek,
3611 .read = lpfc_debugfs_read,
3612 .write = lpfc_debugfs_dumpDataDif_write,
3613 .release = lpfc_debugfs_dumpDataDif_release,
3616 #undef lpfc_debugfs_op_dumpDif
3617 static const struct file_operations lpfc_debugfs_op_dumpDif = {
3618 .owner = THIS_MODULE,
3619 .open = lpfc_debugfs_dumpDif_open,
3620 .llseek = lpfc_debugfs_lseek,
3621 .read = lpfc_debugfs_read,
3622 .write = lpfc_debugfs_dumpDataDif_write,
3623 .release = lpfc_debugfs_dumpDataDif_release,
3626 #undef lpfc_debugfs_op_dif_err
3627 static const struct file_operations lpfc_debugfs_op_dif_err = {
3628 .owner = THIS_MODULE,
3629 .open = simple_open,
3630 .llseek = lpfc_debugfs_lseek,
3631 .read = lpfc_debugfs_dif_err_read,
3632 .write = lpfc_debugfs_dif_err_write,
3633 .release = lpfc_debugfs_dif_err_release,
3636 #undef lpfc_debugfs_op_slow_ring_trc
3637 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
3638 .owner = THIS_MODULE,
3639 .open = lpfc_debugfs_slow_ring_trc_open,
3640 .llseek = lpfc_debugfs_lseek,
3641 .read = lpfc_debugfs_read,
3642 .release = lpfc_debugfs_release,
3645 static struct dentry *lpfc_debugfs_root = NULL;
3646 static atomic_t lpfc_debugfs_hba_count;
3649 * File operations for the iDiag debugfs
3651 #undef lpfc_idiag_op_pciCfg
3652 static const struct file_operations lpfc_idiag_op_pciCfg = {
3653 .owner = THIS_MODULE,
3654 .open = lpfc_idiag_open,
3655 .llseek = lpfc_debugfs_lseek,
3656 .read = lpfc_idiag_pcicfg_read,
3657 .write = lpfc_idiag_pcicfg_write,
3658 .release = lpfc_idiag_cmd_release,
3661 #undef lpfc_idiag_op_barAcc
3662 static const struct file_operations lpfc_idiag_op_barAcc = {
3663 .owner = THIS_MODULE,
3664 .open = lpfc_idiag_open,
3665 .llseek = lpfc_debugfs_lseek,
3666 .read = lpfc_idiag_baracc_read,
3667 .write = lpfc_idiag_baracc_write,
3668 .release = lpfc_idiag_cmd_release,
3671 #undef lpfc_idiag_op_queInfo
3672 static const struct file_operations lpfc_idiag_op_queInfo = {
3673 .owner = THIS_MODULE,
3674 .open = lpfc_idiag_open,
3675 .read = lpfc_idiag_queinfo_read,
3676 .release = lpfc_idiag_release,
3679 #undef lpfc_idiag_op_queAcc
3680 static const struct file_operations lpfc_idiag_op_queAcc = {
3681 .owner = THIS_MODULE,
3682 .open = lpfc_idiag_open,
3683 .llseek = lpfc_debugfs_lseek,
3684 .read = lpfc_idiag_queacc_read,
3685 .write = lpfc_idiag_queacc_write,
3686 .release = lpfc_idiag_cmd_release,
3689 #undef lpfc_idiag_op_drbAcc
3690 static const struct file_operations lpfc_idiag_op_drbAcc = {
3691 .owner = THIS_MODULE,
3692 .open = lpfc_idiag_open,
3693 .llseek = lpfc_debugfs_lseek,
3694 .read = lpfc_idiag_drbacc_read,
3695 .write = lpfc_idiag_drbacc_write,
3696 .release = lpfc_idiag_cmd_release,
3699 #undef lpfc_idiag_op_ctlAcc
3700 static const struct file_operations lpfc_idiag_op_ctlAcc = {
3701 .owner = THIS_MODULE,
3702 .open = lpfc_idiag_open,
3703 .llseek = lpfc_debugfs_lseek,
3704 .read = lpfc_idiag_ctlacc_read,
3705 .write = lpfc_idiag_ctlacc_write,
3706 .release = lpfc_idiag_cmd_release,
3709 #undef lpfc_idiag_op_mbxAcc
3710 static const struct file_operations lpfc_idiag_op_mbxAcc = {
3711 .owner = THIS_MODULE,
3712 .open = lpfc_idiag_open,
3713 .llseek = lpfc_debugfs_lseek,
3714 .read = lpfc_idiag_mbxacc_read,
3715 .write = lpfc_idiag_mbxacc_write,
3716 .release = lpfc_idiag_cmd_release,
3719 #undef lpfc_idiag_op_extAcc
3720 static const struct file_operations lpfc_idiag_op_extAcc = {
3721 .owner = THIS_MODULE,
3722 .open = lpfc_idiag_open,
3723 .llseek = lpfc_debugfs_lseek,
3724 .read = lpfc_idiag_extacc_read,
3725 .write = lpfc_idiag_extacc_write,
3726 .release = lpfc_idiag_cmd_release,
3731 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3732 * @phba: Pointer to HBA context object.
3733 * @dmabuf: Pointer to a DMA buffer descriptor.
3736 * This routine dump a bsg pass-through non-embedded mailbox command with
3740 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3741 enum mbox_type mbox_tp, enum dma_type dma_tp,
3742 enum sta_type sta_tp,
3743 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3745 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3746 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3747 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3749 uint32_t do_dump = 0;
3753 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3756 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3757 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3758 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3759 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3761 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3762 (*mbx_dump_cnt == 0) ||
3763 (*mbx_word_cnt == 0))
3766 if (*mbx_mbox_cmd != 0x9B)
3769 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3770 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3771 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3772 printk(KERN_ERR "\nRead mbox command (x%x), "
3773 "nemb:0x%x, extbuf_cnt:%d:\n",
3774 sta_tp, nemb_tp, ext_buf);
3777 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3778 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3779 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3780 printk(KERN_ERR "\nRead mbox buffer (x%x), "
3781 "nemb:0x%x, extbuf_seq:%d:\n",
3782 sta_tp, nemb_tp, ext_buf);
3785 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3786 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3787 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3788 printk(KERN_ERR "\nWrite mbox command (x%x), "
3789 "nemb:0x%x, extbuf_cnt:%d:\n",
3790 sta_tp, nemb_tp, ext_buf);
3793 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3794 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3795 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3796 printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3797 "nemb:0x%x, extbuf_seq:%d:\n",
3798 sta_tp, nemb_tp, ext_buf);
3802 /* dump buffer content */
3804 pword = (uint32_t *)dmabuf->virt;
3805 for (i = 0; i < *mbx_word_cnt; i++) {
3808 printk(KERN_ERR "%s\n", line_buf);
3810 len += snprintf(line_buf+len,
3811 LPFC_MBX_ACC_LBUF_SZ-len,
3814 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3815 "%08x ", (uint32_t)*pword);
3819 printk(KERN_ERR "%s\n", line_buf);
3823 /* Clean out command structure on reaching dump count */
3824 if (*mbx_dump_cnt == 0)
3825 memset(&idiag, 0, sizeof(idiag));
3830 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3831 * @phba: Pointer to HBA context object.
3832 * @dmabuf: Pointer to a DMA buffer descriptor.
3835 * This routine dump a pass-through non-embedded mailbox command from issue
3839 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3841 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3842 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3843 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3849 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3852 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3853 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3854 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3855 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3857 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3858 (*mbx_dump_cnt == 0) ||
3859 (*mbx_word_cnt == 0))
3862 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3863 (*mbx_mbox_cmd != pmbox->mbxCommand))
3866 /* dump buffer content */
3867 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3868 printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3870 pword = (uint32_t *)pmbox;
3871 for (i = 0; i < *mbx_word_cnt; i++) {
3874 printk(KERN_ERR "%s\n", line_buf);
3876 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3877 len += snprintf(line_buf+len,
3878 LPFC_MBX_ACC_LBUF_SZ-len,
3881 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3883 ((uint32_t)*pword) & 0xffffffff);
3887 printk(KERN_ERR "%s\n", line_buf);
3888 printk(KERN_ERR "\n");
3890 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3891 printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3893 pbyte = (uint8_t *)pmbox;
3894 for (i = 0; i < *mbx_word_cnt; i++) {
3897 printk(KERN_ERR "%s\n", line_buf);
3899 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3900 len += snprintf(line_buf+len,
3901 LPFC_MBX_ACC_LBUF_SZ-len,
3904 for (j = 0; j < 4; j++) {
3905 len += snprintf(line_buf+len,
3906 LPFC_MBX_ACC_LBUF_SZ-len,
3908 ((uint8_t)*pbyte) & 0xff);
3911 len += snprintf(line_buf+len,
3912 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3915 printk(KERN_ERR "%s\n", line_buf);
3916 printk(KERN_ERR "\n");
3920 /* Clean out command structure on reaching dump count */
3921 if (*mbx_dump_cnt == 0)
3922 memset(&idiag, 0, sizeof(idiag));
3928 * lpfc_debugfs_initialize - Initialize debugfs for a vport
3929 * @vport: The vport pointer to initialize.
3932 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3933 * If not already created, this routine will create the lpfc directory, and
3934 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3935 * also create each file used to access lpfc specific debugfs information.
3938 lpfc_debugfs_initialize(struct lpfc_vport *vport)
3940 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3941 struct lpfc_hba *phba = vport->phba;
3945 if (!lpfc_debugfs_enable)
3948 /* Setup lpfc root directory */
3949 if (!lpfc_debugfs_root) {
3950 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3951 atomic_set(&lpfc_debugfs_hba_count, 0);
3952 if (!lpfc_debugfs_root) {
3953 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3954 "0408 Cannot create debugfs root\n");
3958 if (!lpfc_debugfs_start_time)
3959 lpfc_debugfs_start_time = jiffies;
3961 /* Setup funcX directory for specific HBA PCI function */
3962 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
3963 if (!phba->hba_debugfs_root) {
3964 phba->hba_debugfs_root =
3965 debugfs_create_dir(name, lpfc_debugfs_root);
3966 if (!phba->hba_debugfs_root) {
3967 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3968 "0412 Cannot create debugfs hba\n");
3971 atomic_inc(&lpfc_debugfs_hba_count);
3972 atomic_set(&phba->debugfs_vport_count, 0);
3975 snprintf(name, sizeof(name), "hbqinfo");
3976 phba->debug_hbqinfo =
3977 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3978 phba->hba_debugfs_root,
3979 phba, &lpfc_debugfs_op_hbqinfo);
3980 if (!phba->debug_hbqinfo) {
3981 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3982 "0411 Cannot create debugfs hbqinfo\n");
3986 /* Setup dumpHBASlim */
3987 if (phba->sli_rev < LPFC_SLI_REV4) {
3988 snprintf(name, sizeof(name), "dumpHBASlim");
3989 phba->debug_dumpHBASlim =
3990 debugfs_create_file(name,
3991 S_IFREG|S_IRUGO|S_IWUSR,
3992 phba->hba_debugfs_root,
3993 phba, &lpfc_debugfs_op_dumpHBASlim);
3994 if (!phba->debug_dumpHBASlim) {
3995 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3996 "0413 Cannot create debugfs "
4001 phba->debug_dumpHBASlim = NULL;
4003 /* Setup dumpHostSlim */
4004 if (phba->sli_rev < LPFC_SLI_REV4) {
4005 snprintf(name, sizeof(name), "dumpHostSlim");
4006 phba->debug_dumpHostSlim =
4007 debugfs_create_file(name,
4008 S_IFREG|S_IRUGO|S_IWUSR,
4009 phba->hba_debugfs_root,
4010 phba, &lpfc_debugfs_op_dumpHostSlim);
4011 if (!phba->debug_dumpHostSlim) {
4012 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4013 "0414 Cannot create debugfs "
4018 phba->debug_dumpHBASlim = NULL;
4020 /* Setup dumpData */
4021 snprintf(name, sizeof(name), "dumpData");
4022 phba->debug_dumpData =
4023 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4024 phba->hba_debugfs_root,
4025 phba, &lpfc_debugfs_op_dumpData);
4026 if (!phba->debug_dumpData) {
4027 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4028 "0800 Cannot create debugfs dumpData\n");
4033 snprintf(name, sizeof(name), "dumpDif");
4034 phba->debug_dumpDif =
4035 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4036 phba->hba_debugfs_root,
4037 phba, &lpfc_debugfs_op_dumpDif);
4038 if (!phba->debug_dumpDif) {
4039 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4040 "0801 Cannot create debugfs dumpDif\n");
4044 /* Setup DIF Error Injections */
4045 snprintf(name, sizeof(name), "InjErrLBA");
4046 phba->debug_InjErrLBA =
4047 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4048 phba->hba_debugfs_root,
4049 phba, &lpfc_debugfs_op_dif_err);
4050 if (!phba->debug_InjErrLBA) {
4051 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4052 "0807 Cannot create debugfs InjErrLBA\n");
4055 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
4057 snprintf(name, sizeof(name), "InjErrNPortID");
4058 phba->debug_InjErrNPortID =
4059 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4060 phba->hba_debugfs_root,
4061 phba, &lpfc_debugfs_op_dif_err);
4062 if (!phba->debug_InjErrNPortID) {
4063 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4064 "0809 Cannot create debugfs InjErrNPortID\n");
4068 snprintf(name, sizeof(name), "InjErrWWPN");
4069 phba->debug_InjErrWWPN =
4070 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4071 phba->hba_debugfs_root,
4072 phba, &lpfc_debugfs_op_dif_err);
4073 if (!phba->debug_InjErrWWPN) {
4074 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4075 "0810 Cannot create debugfs InjErrWWPN\n");
4079 snprintf(name, sizeof(name), "writeGuardInjErr");
4080 phba->debug_writeGuard =
4081 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4082 phba->hba_debugfs_root,
4083 phba, &lpfc_debugfs_op_dif_err);
4084 if (!phba->debug_writeGuard) {
4085 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4086 "0802 Cannot create debugfs writeGuard\n");
4090 snprintf(name, sizeof(name), "writeAppInjErr");
4091 phba->debug_writeApp =
4092 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4093 phba->hba_debugfs_root,
4094 phba, &lpfc_debugfs_op_dif_err);
4095 if (!phba->debug_writeApp) {
4096 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4097 "0803 Cannot create debugfs writeApp\n");
4101 snprintf(name, sizeof(name), "writeRefInjErr");
4102 phba->debug_writeRef =
4103 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4104 phba->hba_debugfs_root,
4105 phba, &lpfc_debugfs_op_dif_err);
4106 if (!phba->debug_writeRef) {
4107 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4108 "0804 Cannot create debugfs writeRef\n");
4112 snprintf(name, sizeof(name), "readGuardInjErr");
4113 phba->debug_readGuard =
4114 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4115 phba->hba_debugfs_root,
4116 phba, &lpfc_debugfs_op_dif_err);
4117 if (!phba->debug_readGuard) {
4118 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4119 "0808 Cannot create debugfs readGuard\n");
4123 snprintf(name, sizeof(name), "readAppInjErr");
4124 phba->debug_readApp =
4125 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4126 phba->hba_debugfs_root,
4127 phba, &lpfc_debugfs_op_dif_err);
4128 if (!phba->debug_readApp) {
4129 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4130 "0805 Cannot create debugfs readApp\n");
4134 snprintf(name, sizeof(name), "readRefInjErr");
4135 phba->debug_readRef =
4136 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4137 phba->hba_debugfs_root,
4138 phba, &lpfc_debugfs_op_dif_err);
4139 if (!phba->debug_readRef) {
4140 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4141 "0806 Cannot create debugfs readApp\n");
4145 /* Setup slow ring trace */
4146 if (lpfc_debugfs_max_slow_ring_trc) {
4147 num = lpfc_debugfs_max_slow_ring_trc - 1;
4148 if (num & lpfc_debugfs_max_slow_ring_trc) {
4149 /* Change to be a power of 2 */
4150 num = lpfc_debugfs_max_slow_ring_trc;
4156 lpfc_debugfs_max_slow_ring_trc = (1 << i);
4158 "lpfc_debugfs_max_disc_trc changed to "
4159 "%d\n", lpfc_debugfs_max_disc_trc);
4163 snprintf(name, sizeof(name), "slow_ring_trace");
4164 phba->debug_slow_ring_trc =
4165 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4166 phba->hba_debugfs_root,
4167 phba, &lpfc_debugfs_op_slow_ring_trc);
4168 if (!phba->debug_slow_ring_trc) {
4169 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4170 "0415 Cannot create debugfs "
4171 "slow_ring_trace\n");
4174 if (!phba->slow_ring_trc) {
4175 phba->slow_ring_trc = kmalloc(
4176 (sizeof(struct lpfc_debugfs_trc) *
4177 lpfc_debugfs_max_slow_ring_trc),
4179 if (!phba->slow_ring_trc) {
4180 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4181 "0416 Cannot create debugfs "
4182 "slow_ring buffer\n");
4185 atomic_set(&phba->slow_ring_trc_cnt, 0);
4186 memset(phba->slow_ring_trc, 0,
4187 (sizeof(struct lpfc_debugfs_trc) *
4188 lpfc_debugfs_max_slow_ring_trc));
4192 snprintf(name, sizeof(name), "vport%d", vport->vpi);
4193 if (!vport->vport_debugfs_root) {
4194 vport->vport_debugfs_root =
4195 debugfs_create_dir(name, phba->hba_debugfs_root);
4196 if (!vport->vport_debugfs_root) {
4197 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4198 "0417 Can't create debugfs\n");
4201 atomic_inc(&phba->debugfs_vport_count);
4204 if (lpfc_debugfs_max_disc_trc) {
4205 num = lpfc_debugfs_max_disc_trc - 1;
4206 if (num & lpfc_debugfs_max_disc_trc) {
4207 /* Change to be a power of 2 */
4208 num = lpfc_debugfs_max_disc_trc;
4214 lpfc_debugfs_max_disc_trc = (1 << i);
4216 "lpfc_debugfs_max_disc_trc changed to %d\n",
4217 lpfc_debugfs_max_disc_trc);
4221 vport->disc_trc = kzalloc(
4222 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
4225 if (!vport->disc_trc) {
4226 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4227 "0418 Cannot create debugfs disc trace "
4231 atomic_set(&vport->disc_trc_cnt, 0);
4233 snprintf(name, sizeof(name), "discovery_trace");
4234 vport->debug_disc_trc =
4235 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4236 vport->vport_debugfs_root,
4237 vport, &lpfc_debugfs_op_disc_trc);
4238 if (!vport->debug_disc_trc) {
4239 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4240 "0419 Cannot create debugfs "
4241 "discovery_trace\n");
4244 snprintf(name, sizeof(name), "nodelist");
4245 vport->debug_nodelist =
4246 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4247 vport->vport_debugfs_root,
4248 vport, &lpfc_debugfs_op_nodelist);
4249 if (!vport->debug_nodelist) {
4250 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4251 "2985 Can't create debugfs nodelist\n");
4256 * iDiag debugfs root entry points for SLI4 device only
4258 if (phba->sli_rev < LPFC_SLI_REV4)
4261 snprintf(name, sizeof(name), "iDiag");
4262 if (!phba->idiag_root) {
4264 debugfs_create_dir(name, phba->hba_debugfs_root);
4265 if (!phba->idiag_root) {
4266 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4267 "2922 Can't create idiag debugfs\n");
4270 /* Initialize iDiag data structure */
4271 memset(&idiag, 0, sizeof(idiag));
4274 /* iDiag read PCI config space */
4275 snprintf(name, sizeof(name), "pciCfg");
4276 if (!phba->idiag_pci_cfg) {
4277 phba->idiag_pci_cfg =
4278 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4279 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
4280 if (!phba->idiag_pci_cfg) {
4281 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4282 "2923 Can't create idiag debugfs\n");
4285 idiag.offset.last_rd = 0;
4288 /* iDiag PCI BAR access */
4289 snprintf(name, sizeof(name), "barAcc");
4290 if (!phba->idiag_bar_acc) {
4291 phba->idiag_bar_acc =
4292 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4293 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
4294 if (!phba->idiag_bar_acc) {
4295 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4296 "3056 Can't create idiag debugfs\n");
4299 idiag.offset.last_rd = 0;
4302 /* iDiag get PCI function queue information */
4303 snprintf(name, sizeof(name), "queInfo");
4304 if (!phba->idiag_que_info) {
4305 phba->idiag_que_info =
4306 debugfs_create_file(name, S_IFREG|S_IRUGO,
4307 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
4308 if (!phba->idiag_que_info) {
4309 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4310 "2924 Can't create idiag debugfs\n");
4315 /* iDiag access PCI function queue */
4316 snprintf(name, sizeof(name), "queAcc");
4317 if (!phba->idiag_que_acc) {
4318 phba->idiag_que_acc =
4319 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4320 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
4321 if (!phba->idiag_que_acc) {
4322 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4323 "2926 Can't create idiag debugfs\n");
4328 /* iDiag access PCI function doorbell registers */
4329 snprintf(name, sizeof(name), "drbAcc");
4330 if (!phba->idiag_drb_acc) {
4331 phba->idiag_drb_acc =
4332 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4333 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
4334 if (!phba->idiag_drb_acc) {
4335 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4336 "2927 Can't create idiag debugfs\n");
4341 /* iDiag access PCI function control registers */
4342 snprintf(name, sizeof(name), "ctlAcc");
4343 if (!phba->idiag_ctl_acc) {
4344 phba->idiag_ctl_acc =
4345 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4346 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
4347 if (!phba->idiag_ctl_acc) {
4348 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4349 "2981 Can't create idiag debugfs\n");
4354 /* iDiag access mbox commands */
4355 snprintf(name, sizeof(name), "mbxAcc");
4356 if (!phba->idiag_mbx_acc) {
4357 phba->idiag_mbx_acc =
4358 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4359 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4360 if (!phba->idiag_mbx_acc) {
4361 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4362 "2980 Can't create idiag debugfs\n");
4367 /* iDiag extents access commands */
4368 if (phba->sli4_hba.extents_in_use) {
4369 snprintf(name, sizeof(name), "extAcc");
4370 if (!phba->idiag_ext_acc) {
4371 phba->idiag_ext_acc =
4372 debugfs_create_file(name,
4373 S_IFREG|S_IRUGO|S_IWUSR,
4374 phba->idiag_root, phba,
4375 &lpfc_idiag_op_extAcc);
4376 if (!phba->idiag_ext_acc) {
4377 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4391 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
4392 * @vport: The vport pointer to remove from debugfs.
4395 * When Debugfs is configured this routine removes debugfs file system elements
4396 * that are specific to this vport. It also checks to see if there are any
4397 * users left for the debugfs directories associated with the HBA and driver. If
4398 * this is the last user of the HBA directory or driver directory then it will
4399 * remove those from the debugfs infrastructure as well.
4402 lpfc_debugfs_terminate(struct lpfc_vport *vport)
4404 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4405 struct lpfc_hba *phba = vport->phba;
4407 if (vport->disc_trc) {
4408 kfree(vport->disc_trc);
4409 vport->disc_trc = NULL;
4411 if (vport->debug_disc_trc) {
4412 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4413 vport->debug_disc_trc = NULL;
4415 if (vport->debug_nodelist) {
4416 debugfs_remove(vport->debug_nodelist); /* nodelist */
4417 vport->debug_nodelist = NULL;
4419 if (vport->vport_debugfs_root) {
4420 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4421 vport->vport_debugfs_root = NULL;
4422 atomic_dec(&phba->debugfs_vport_count);
4424 if (atomic_read(&phba->debugfs_vport_count) == 0) {
4426 if (phba->debug_hbqinfo) {
4427 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4428 phba->debug_hbqinfo = NULL;
4430 if (phba->debug_dumpHBASlim) {
4431 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4432 phba->debug_dumpHBASlim = NULL;
4434 if (phba->debug_dumpHostSlim) {
4435 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4436 phba->debug_dumpHostSlim = NULL;
4438 if (phba->debug_dumpData) {
4439 debugfs_remove(phba->debug_dumpData); /* dumpData */
4440 phba->debug_dumpData = NULL;
4443 if (phba->debug_dumpDif) {
4444 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4445 phba->debug_dumpDif = NULL;
4447 if (phba->debug_InjErrLBA) {
4448 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
4449 phba->debug_InjErrLBA = NULL;
4451 if (phba->debug_InjErrNPortID) { /* InjErrNPortID */
4452 debugfs_remove(phba->debug_InjErrNPortID);
4453 phba->debug_InjErrNPortID = NULL;
4455 if (phba->debug_InjErrWWPN) {
4456 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
4457 phba->debug_InjErrWWPN = NULL;
4459 if (phba->debug_writeGuard) {
4460 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
4461 phba->debug_writeGuard = NULL;
4463 if (phba->debug_writeApp) {
4464 debugfs_remove(phba->debug_writeApp); /* writeApp */
4465 phba->debug_writeApp = NULL;
4467 if (phba->debug_writeRef) {
4468 debugfs_remove(phba->debug_writeRef); /* writeRef */
4469 phba->debug_writeRef = NULL;
4471 if (phba->debug_readGuard) {
4472 debugfs_remove(phba->debug_readGuard); /* readGuard */
4473 phba->debug_readGuard = NULL;
4475 if (phba->debug_readApp) {
4476 debugfs_remove(phba->debug_readApp); /* readApp */
4477 phba->debug_readApp = NULL;
4479 if (phba->debug_readRef) {
4480 debugfs_remove(phba->debug_readRef); /* readRef */
4481 phba->debug_readRef = NULL;
4484 if (phba->slow_ring_trc) {
4485 kfree(phba->slow_ring_trc);
4486 phba->slow_ring_trc = NULL;
4488 if (phba->debug_slow_ring_trc) {
4489 /* slow_ring_trace */
4490 debugfs_remove(phba->debug_slow_ring_trc);
4491 phba->debug_slow_ring_trc = NULL;
4497 if (phba->sli_rev == LPFC_SLI_REV4) {
4498 if (phba->idiag_ext_acc) {
4500 debugfs_remove(phba->idiag_ext_acc);
4501 phba->idiag_ext_acc = NULL;
4503 if (phba->idiag_mbx_acc) {
4505 debugfs_remove(phba->idiag_mbx_acc);
4506 phba->idiag_mbx_acc = NULL;
4508 if (phba->idiag_ctl_acc) {
4510 debugfs_remove(phba->idiag_ctl_acc);
4511 phba->idiag_ctl_acc = NULL;
4513 if (phba->idiag_drb_acc) {
4515 debugfs_remove(phba->idiag_drb_acc);
4516 phba->idiag_drb_acc = NULL;
4518 if (phba->idiag_que_acc) {
4520 debugfs_remove(phba->idiag_que_acc);
4521 phba->idiag_que_acc = NULL;
4523 if (phba->idiag_que_info) {
4525 debugfs_remove(phba->idiag_que_info);
4526 phba->idiag_que_info = NULL;
4528 if (phba->idiag_bar_acc) {
4530 debugfs_remove(phba->idiag_bar_acc);
4531 phba->idiag_bar_acc = NULL;
4533 if (phba->idiag_pci_cfg) {
4535 debugfs_remove(phba->idiag_pci_cfg);
4536 phba->idiag_pci_cfg = NULL;
4539 /* Finally remove the iDiag debugfs root */
4540 if (phba->idiag_root) {
4542 debugfs_remove(phba->idiag_root);
4543 phba->idiag_root = NULL;
4547 if (phba->hba_debugfs_root) {
4548 debugfs_remove(phba->hba_debugfs_root); /* fnX */
4549 phba->hba_debugfs_root = NULL;
4550 atomic_dec(&lpfc_debugfs_hba_count);
4553 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4554 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4555 lpfc_debugfs_root = NULL;
4563 * Driver debug utility routines outside of debugfs. The debug utility
4564 * routines implemented here is intended to be used in the instrumented
4565 * debug driver for debugging host or port issues.
4569 * lpfc_debug_dump_all_queues - dump all the queues with a hba
4570 * @phba: Pointer to HBA context object.
4572 * This function dumps entries of all the queues asociated with the @phba.
4575 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
4580 * Dump Work Queues (WQs)
4582 lpfc_debug_dump_mbx_wq(phba);
4583 lpfc_debug_dump_els_wq(phba);
4585 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
4586 lpfc_debug_dump_fcp_wq(phba, fcp_wqidx);
4588 lpfc_debug_dump_hdr_rq(phba);
4589 lpfc_debug_dump_dat_rq(phba);
4591 * Dump Complete Queues (CQs)
4593 lpfc_debug_dump_mbx_cq(phba);
4594 lpfc_debug_dump_els_cq(phba);
4596 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
4597 lpfc_debug_dump_fcp_cq(phba, fcp_wqidx);
4600 * Dump Event Queues (EQs)
4602 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
4603 lpfc_debug_dump_hba_eq(phba, fcp_wqidx);