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_UNMAPPED_NODE:
565 case NLP_STE_MAPPED_NODE:
568 case NLP_STE_NPR_NODE:
574 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
575 statep, ndlp->nlp_DID);
576 name = (unsigned char *)&ndlp->nlp_portname;
577 len += snprintf(buf+len, size-len,
578 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
579 *name, *(name+1), *(name+2), *(name+3),
580 *(name+4), *(name+5), *(name+6), *(name+7));
581 name = (unsigned char *)&ndlp->nlp_nodename;
582 len += snprintf(buf+len, size-len,
583 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
584 *name, *(name+1), *(name+2), *(name+3),
585 *(name+4), *(name+5), *(name+6), *(name+7));
586 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
587 ndlp->nlp_rpi, ndlp->nlp_flag);
589 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
590 if (ndlp->nlp_type & NLP_FC_NODE)
591 len += snprintf(buf+len, size-len, "FC_NODE ");
592 if (ndlp->nlp_type & NLP_FABRIC)
593 len += snprintf(buf+len, size-len, "FABRIC ");
594 if (ndlp->nlp_type & NLP_FCP_TARGET)
595 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
597 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
598 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
599 len += snprintf(buf+len, size-len, "usgmap:%x ",
601 len += snprintf(buf+len, size-len, "refcnt:%x",
602 atomic_read(&ndlp->kref.refcount));
603 len += snprintf(buf+len, size-len, "\n");
605 spin_unlock_irq(shost->host_lock);
611 * lpfc_debugfs_disc_trc - Store discovery trace log
612 * @vport: The vport to associate this trace string with for retrieval.
613 * @mask: Log entry classification.
614 * @fmt: Format string to be displayed when dumping the log.
615 * @data1: 1st data parameter to be applied to @fmt.
616 * @data2: 2nd data parameter to be applied to @fmt.
617 * @data3: 3rd data parameter to be applied to @fmt.
620 * This routine is used by the driver code to add a debugfs log entry to the
621 * discovery trace buffer associated with @vport. Only entries with a @mask that
622 * match the current debugfs discovery mask will be saved. Entries that do not
623 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
624 * printf when displaying the log.
627 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
628 uint32_t data1, uint32_t data2, uint32_t data3)
630 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
631 struct lpfc_debugfs_trc *dtp;
634 if (!(lpfc_debugfs_mask_disc_trc & mask))
637 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
638 !vport || !vport->disc_trc)
641 index = atomic_inc_return(&vport->disc_trc_cnt) &
642 (lpfc_debugfs_max_disc_trc - 1);
643 dtp = vport->disc_trc + index;
648 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
655 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
656 * @phba: The phba to associate this trace string with for retrieval.
657 * @fmt: Format string to be displayed when dumping the log.
658 * @data1: 1st data parameter to be applied to @fmt.
659 * @data2: 2nd data parameter to be applied to @fmt.
660 * @data3: 3rd data parameter to be applied to @fmt.
663 * This routine is used by the driver code to add a debugfs log entry to the
664 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
665 * @data3 are used like printf when displaying the log.
668 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
669 uint32_t data1, uint32_t data2, uint32_t data3)
671 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
672 struct lpfc_debugfs_trc *dtp;
675 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
676 !phba || !phba->slow_ring_trc)
679 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
680 (lpfc_debugfs_max_slow_ring_trc - 1);
681 dtp = phba->slow_ring_trc + index;
686 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
692 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
694 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
695 * @inode: The inode pointer that contains a vport pointer.
696 * @file: The file pointer to attach the log output.
699 * This routine is the entry point for the debugfs open file operation. It gets
700 * the vport from the i_private field in @inode, allocates the necessary buffer
701 * for the log, fills the buffer from the in-memory log for this vport, and then
702 * returns a pointer to that log in the private_data field in @file.
705 * This function returns zero if successful. On error it will return an negative
709 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
711 struct lpfc_vport *vport = inode->i_private;
712 struct lpfc_debug *debug;
716 if (!lpfc_debugfs_max_disc_trc) {
721 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
725 /* Round to page boundary */
726 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
727 size = PAGE_ALIGN(size);
729 debug->buffer = kmalloc(size, GFP_KERNEL);
730 if (!debug->buffer) {
735 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
736 file->private_data = debug;
744 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
745 * @inode: The inode pointer that contains a vport pointer.
746 * @file: The file pointer to attach the log output.
749 * This routine is the entry point for the debugfs open file operation. It gets
750 * the vport from the i_private field in @inode, allocates the necessary buffer
751 * for the log, fills the buffer from the in-memory log for this vport, and then
752 * returns a pointer to that log in the private_data field in @file.
755 * This function returns zero if successful. On error it will return an negative
759 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
761 struct lpfc_hba *phba = inode->i_private;
762 struct lpfc_debug *debug;
766 if (!lpfc_debugfs_max_slow_ring_trc) {
771 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
775 /* Round to page boundary */
776 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
777 size = PAGE_ALIGN(size);
779 debug->buffer = kmalloc(size, GFP_KERNEL);
780 if (!debug->buffer) {
785 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
786 file->private_data = debug;
794 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
795 * @inode: The inode pointer that contains a vport pointer.
796 * @file: The file pointer to attach the log output.
799 * This routine is the entry point for the debugfs open file operation. It gets
800 * the vport from the i_private field in @inode, allocates the necessary buffer
801 * for the log, fills the buffer from the in-memory log for this vport, and then
802 * returns a pointer to that log in the private_data field in @file.
805 * This function returns zero if successful. On error it will return an negative
809 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
811 struct lpfc_hba *phba = inode->i_private;
812 struct lpfc_debug *debug;
815 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
819 /* Round to page boundary */
820 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
821 if (!debug->buffer) {
826 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
828 file->private_data = debug;
836 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
837 * @inode: The inode pointer that contains a vport pointer.
838 * @file: The file pointer to attach the log output.
841 * This routine is the entry point for the debugfs open file operation. It gets
842 * the vport from the i_private field in @inode, allocates the necessary buffer
843 * for the log, fills the buffer from the in-memory log for this vport, and then
844 * returns a pointer to that log in the private_data field in @file.
847 * This function returns zero if successful. On error it will return an negative
851 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
853 struct lpfc_hba *phba = inode->i_private;
854 struct lpfc_debug *debug;
857 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
861 /* Round to page boundary */
862 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
863 if (!debug->buffer) {
868 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
869 LPFC_DUMPHBASLIM_SIZE);
870 file->private_data = debug;
878 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
879 * @inode: The inode pointer that contains a vport pointer.
880 * @file: The file pointer to attach the log output.
883 * This routine is the entry point for the debugfs open file operation. It gets
884 * the vport from the i_private field in @inode, allocates the necessary buffer
885 * for the log, fills the buffer from the in-memory log for this vport, and then
886 * returns a pointer to that log in the private_data field in @file.
889 * This function returns zero if successful. On error it will return an negative
893 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
895 struct lpfc_hba *phba = inode->i_private;
896 struct lpfc_debug *debug;
899 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
903 /* Round to page boundary */
904 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
905 if (!debug->buffer) {
910 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
911 LPFC_DUMPHOSTSLIM_SIZE);
912 file->private_data = debug;
920 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
922 struct lpfc_debug *debug;
928 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
932 /* Round to page boundary */
933 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
934 __func__, _dump_buf_data);
935 debug->buffer = _dump_buf_data;
936 if (!debug->buffer) {
941 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
942 file->private_data = debug;
950 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
952 struct lpfc_debug *debug;
958 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
962 /* Round to page boundary */
963 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
964 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
965 debug->buffer = _dump_buf_dif;
966 if (!debug->buffer) {
971 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
972 file->private_data = debug;
980 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
981 size_t nbytes, loff_t *ppos)
984 * The Data/DIF buffers only save one failing IO
985 * The write op is used as a reset mechanism after an IO has
986 * already been saved to the next one can be saved
988 spin_lock(&_dump_buf_lock);
990 memset((void *)_dump_buf_data, 0,
991 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
992 memset((void *)_dump_buf_dif, 0,
993 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
997 spin_unlock(&_dump_buf_lock);
1003 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1004 size_t nbytes, loff_t *ppos)
1006 struct dentry *dent = file->f_dentry;
1007 struct lpfc_hba *phba = file->private_data;
1012 if (dent == phba->debug_writeGuard)
1013 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1014 else if (dent == phba->debug_writeApp)
1015 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
1016 else if (dent == phba->debug_writeRef)
1017 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
1018 else if (dent == phba->debug_readGuard)
1019 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1020 else if (dent == phba->debug_readApp)
1021 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
1022 else if (dent == phba->debug_readRef)
1023 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1024 else if (dent == phba->debug_InjErrNPortID)
1025 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1026 else if (dent == phba->debug_InjErrWWPN) {
1027 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1028 tmp = cpu_to_be64(tmp);
1029 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1030 } else if (dent == phba->debug_InjErrLBA) {
1031 if (phba->lpfc_injerr_lba == (sector_t)(-1))
1032 cnt = snprintf(cbuf, 32, "off\n");
1034 cnt = snprintf(cbuf, 32, "0x%llx\n",
1035 (uint64_t) phba->lpfc_injerr_lba);
1037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1038 "0547 Unknown debugfs error injection entry\n");
1040 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1044 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1045 size_t nbytes, loff_t *ppos)
1047 struct dentry *dent = file->f_dentry;
1048 struct lpfc_hba *phba = file->private_data;
1053 memset(dstbuf, 0, 32);
1054 size = (nbytes < 32) ? nbytes : 32;
1055 if (copy_from_user(dstbuf, buf, size))
1058 if (dent == phba->debug_InjErrLBA) {
1059 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1060 tmp = (uint64_t)(-1);
1063 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
1066 if (dent == phba->debug_writeGuard)
1067 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1068 else if (dent == phba->debug_writeApp)
1069 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1070 else if (dent == phba->debug_writeRef)
1071 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1072 else if (dent == phba->debug_readGuard)
1073 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
1074 else if (dent == phba->debug_readApp)
1075 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1076 else if (dent == phba->debug_readRef)
1077 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1078 else if (dent == phba->debug_InjErrLBA)
1079 phba->lpfc_injerr_lba = (sector_t)tmp;
1080 else if (dent == phba->debug_InjErrNPortID)
1081 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1082 else if (dent == phba->debug_InjErrWWPN) {
1083 tmp = cpu_to_be64(tmp);
1084 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1086 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1087 "0548 Unknown debugfs error injection entry\n");
1093 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1099 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1100 * @inode: The inode pointer that contains a vport pointer.
1101 * @file: The file pointer to attach the log output.
1104 * This routine is the entry point for the debugfs open file operation. It gets
1105 * the vport from the i_private field in @inode, allocates the necessary buffer
1106 * for the log, fills the buffer from the in-memory log for this vport, and then
1107 * returns a pointer to that log in the private_data field in @file.
1110 * This function returns zero if successful. On error it will return an negative
1114 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1116 struct lpfc_vport *vport = inode->i_private;
1117 struct lpfc_debug *debug;
1120 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1124 /* Round to page boundary */
1125 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1126 if (!debug->buffer) {
1131 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1132 LPFC_NODELIST_SIZE);
1133 file->private_data = debug;
1141 * lpfc_debugfs_lseek - Seek through a debugfs file
1142 * @file: The file pointer to seek through.
1143 * @off: The offset to seek to or the amount to seek by.
1144 * @whence: Indicates how to seek.
1147 * This routine is the entry point for the debugfs lseek file operation. The
1148 * @whence parameter indicates whether @off is the offset to directly seek to,
1149 * or if it is a value to seek forward or reverse by. This function figures out
1150 * what the new offset of the debugfs file will be and assigns that value to the
1151 * f_pos field of @file.
1154 * This function returns the new offset if successful and returns a negative
1155 * error if unable to process the seek.
1158 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1160 struct lpfc_debug *debug;
1163 debug = file->private_data;
1170 pos = file->f_pos + off;
1173 pos = debug->len - off;
1175 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1179 * lpfc_debugfs_read - Read a debugfs file
1180 * @file: The file pointer to read from.
1181 * @buf: The buffer to copy the data to.
1182 * @nbytes: The number of bytes to read.
1183 * @ppos: The position in the file to start reading from.
1186 * This routine reads data from from the buffer indicated in the private_data
1187 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1191 * This function returns the amount of data that was read (this could be less
1192 * than @nbytes if the end of the file was reached) or a negative error value.
1195 lpfc_debugfs_read(struct file *file, char __user *buf,
1196 size_t nbytes, loff_t *ppos)
1198 struct lpfc_debug *debug = file->private_data;
1200 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1205 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1206 * @inode: The inode pointer that contains a vport pointer. (unused)
1207 * @file: The file pointer that contains the buffer to release.
1210 * This routine frees the buffer that was allocated when the debugfs file was
1214 * This function returns zero.
1217 lpfc_debugfs_release(struct inode *inode, struct file *file)
1219 struct lpfc_debug *debug = file->private_data;
1221 kfree(debug->buffer);
1228 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1230 struct lpfc_debug *debug = file->private_data;
1232 debug->buffer = NULL;
1239 * ---------------------------------
1240 * iDiag debugfs file access methods
1241 * ---------------------------------
1243 * All access methods are through the proper SLI4 PCI function's debugfs
1246 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1250 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1251 * @buf: The pointer to the user space buffer.
1252 * @nbytes: The number of bytes in the user space buffer.
1253 * @idiag_cmd: pointer to the idiag command struct.
1255 * This routine reads data from debugfs user space buffer and parses the
1256 * buffer for getting the idiag command and arguments. The while space in
1257 * between the set of data is used as the parsing separator.
1259 * This routine returns 0 when successful, it returns proper error code
1260 * back to the user space in error conditions.
1262 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1263 struct lpfc_idiag_cmd *idiag_cmd)
1266 char *pbuf, *step_str;
1270 /* Protect copy from user */
1271 if (!access_ok(VERIFY_READ, buf, nbytes))
1274 memset(mybuf, 0, sizeof(mybuf));
1275 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1276 bsize = min(nbytes, (sizeof(mybuf)-1));
1278 if (copy_from_user(mybuf, buf, bsize))
1281 step_str = strsep(&pbuf, "\t ");
1283 /* The opcode must present */
1287 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1288 if (idiag_cmd->opcode == 0)
1291 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1292 step_str = strsep(&pbuf, "\t ");
1295 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1301 * lpfc_idiag_open - idiag open debugfs
1302 * @inode: The inode pointer that contains a pointer to phba.
1303 * @file: The file pointer to attach the file operation.
1306 * This routine is the entry point for the debugfs open file operation. It
1307 * gets the reference to phba from the i_private field in @inode, it then
1308 * allocates buffer for the file operation, performs the necessary PCI config
1309 * space read into the allocated buffer according to the idiag user command
1310 * setup, and then returns a pointer to buffer in the private_data field in
1314 * This function returns zero if successful. On error it will return an
1315 * negative error value.
1318 lpfc_idiag_open(struct inode *inode, struct file *file)
1320 struct lpfc_debug *debug;
1322 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1326 debug->i_private = inode->i_private;
1327 debug->buffer = NULL;
1328 file->private_data = debug;
1334 * lpfc_idiag_release - Release idiag access file operation
1335 * @inode: The inode pointer that contains a vport pointer. (unused)
1336 * @file: The file pointer that contains the buffer to release.
1339 * This routine is the generic release routine for the idiag access file
1340 * operation, it frees the buffer that was allocated when the debugfs file
1344 * This function returns zero.
1347 lpfc_idiag_release(struct inode *inode, struct file *file)
1349 struct lpfc_debug *debug = file->private_data;
1351 /* Free the buffers to the file operation */
1352 kfree(debug->buffer);
1359 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1360 * @inode: The inode pointer that contains a vport pointer. (unused)
1361 * @file: The file pointer that contains the buffer to release.
1364 * This routine frees the buffer that was allocated when the debugfs file
1365 * was opened. It also reset the fields in the idiag command struct in the
1366 * case of command for write operation.
1369 * This function returns zero.
1372 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1374 struct lpfc_debug *debug = file->private_data;
1376 if (debug->op == LPFC_IDIAG_OP_WR) {
1377 switch (idiag.cmd.opcode) {
1378 case LPFC_IDIAG_CMD_PCICFG_WR:
1379 case LPFC_IDIAG_CMD_PCICFG_ST:
1380 case LPFC_IDIAG_CMD_PCICFG_CL:
1381 case LPFC_IDIAG_CMD_QUEACC_WR:
1382 case LPFC_IDIAG_CMD_QUEACC_ST:
1383 case LPFC_IDIAG_CMD_QUEACC_CL:
1384 memset(&idiag, 0, sizeof(idiag));
1391 /* Free the buffers to the file operation */
1392 kfree(debug->buffer);
1399 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1400 * @file: The file pointer to read from.
1401 * @buf: The buffer to copy the data to.
1402 * @nbytes: The number of bytes to read.
1403 * @ppos: The position in the file to start reading from.
1406 * This routine reads data from the @phba pci config space according to the
1407 * idiag command, and copies to user @buf. Depending on the PCI config space
1408 * read command setup, it does either a single register read of a byte
1409 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1410 * registers from the 4K extended PCI config space.
1413 * This function returns the amount of data that was read (this could be less
1414 * than @nbytes if the end of the file was reached) or a negative error value.
1417 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1420 struct lpfc_debug *debug = file->private_data;
1421 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1422 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1425 struct pci_dev *pdev;
1430 pdev = phba->pcidev;
1434 /* This is a user read operation */
1435 debug->op = LPFC_IDIAG_OP_RD;
1438 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1441 pbuffer = debug->buffer;
1446 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1447 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1448 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1452 /* Read single PCI config space register */
1454 case SIZE_U8: /* byte (8 bits) */
1455 pci_read_config_byte(pdev, where, &u8val);
1456 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1457 "%03x: %02x\n", where, u8val);
1459 case SIZE_U16: /* word (16 bits) */
1460 pci_read_config_word(pdev, where, &u16val);
1461 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1462 "%03x: %04x\n", where, u16val);
1464 case SIZE_U32: /* double word (32 bits) */
1465 pci_read_config_dword(pdev, where, &u32val);
1466 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1467 "%03x: %08x\n", where, u32val);
1469 case LPFC_PCI_CFG_BROWSE: /* browse all */
1477 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1481 /* Browse all PCI config space registers */
1482 offset_label = idiag.offset.last_rd;
1483 offset = offset_label;
1485 /* Read PCI config space */
1486 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1487 "%03x: ", offset_label);
1489 pci_read_config_dword(pdev, offset, &u32val);
1490 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1492 offset += sizeof(uint32_t);
1493 if (offset >= LPFC_PCI_CFG_SIZE) {
1494 len += snprintf(pbuffer+len,
1495 LPFC_PCI_CFG_SIZE-len, "\n");
1498 index -= sizeof(uint32_t);
1500 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1502 else if (!(index % (8 * sizeof(uint32_t)))) {
1503 offset_label += (8 * sizeof(uint32_t));
1504 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1505 "\n%03x: ", offset_label);
1509 /* Set up the offset for next portion of pci cfg read */
1511 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1512 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1513 idiag.offset.last_rd = 0;
1515 idiag.offset.last_rd = 0;
1517 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1521 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1522 * @file: The file pointer to read from.
1523 * @buf: The buffer to copy the user data from.
1524 * @nbytes: The number of bytes to get.
1525 * @ppos: The position in the file to start reading from.
1527 * This routine get the debugfs idiag command struct from user space and
1528 * then perform the syntax check for PCI config space read or write command
1529 * accordingly. In the case of PCI config space read command, it sets up
1530 * the command in the idiag command struct for the debugfs read operation.
1531 * In the case of PCI config space write operation, it executes the write
1532 * operation into the PCI config space accordingly.
1534 * It returns the @nbytges passing in from debugfs user space when successful.
1535 * In case of error conditions, it returns proper error code back to the user
1539 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1540 size_t nbytes, loff_t *ppos)
1542 struct lpfc_debug *debug = file->private_data;
1543 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1544 uint32_t where, value, count;
1548 struct pci_dev *pdev;
1551 pdev = phba->pcidev;
1555 /* This is a user write operation */
1556 debug->op = LPFC_IDIAG_OP_WR;
1558 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1562 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1563 /* Sanity check on PCI config read command line arguments */
1564 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1566 /* Read command from PCI config space, set up command fields */
1567 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1568 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1569 if (count == LPFC_PCI_CFG_BROWSE) {
1570 if (where % sizeof(uint32_t))
1572 /* Starting offset to browse */
1573 idiag.offset.last_rd = where;
1574 } else if ((count != sizeof(uint8_t)) &&
1575 (count != sizeof(uint16_t)) &&
1576 (count != sizeof(uint32_t)))
1578 if (count == sizeof(uint8_t)) {
1579 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1581 if (where % sizeof(uint8_t))
1584 if (count == sizeof(uint16_t)) {
1585 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1587 if (where % sizeof(uint16_t))
1590 if (count == sizeof(uint32_t)) {
1591 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1593 if (where % sizeof(uint32_t))
1596 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1597 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1598 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1599 /* Sanity check on PCI config write command line arguments */
1600 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1602 /* Write command to PCI config space, read-modify-write */
1603 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1604 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1605 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
1607 if ((count != sizeof(uint8_t)) &&
1608 (count != sizeof(uint16_t)) &&
1609 (count != sizeof(uint32_t)))
1611 if (count == sizeof(uint8_t)) {
1612 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1614 if (where % sizeof(uint8_t))
1616 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1617 pci_write_config_byte(pdev, where,
1619 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1620 rc = pci_read_config_byte(pdev, where, &u8val);
1622 u8val |= (uint8_t)value;
1623 pci_write_config_byte(pdev, where,
1627 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1628 rc = pci_read_config_byte(pdev, where, &u8val);
1630 u8val &= (uint8_t)(~value);
1631 pci_write_config_byte(pdev, where,
1636 if (count == sizeof(uint16_t)) {
1637 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1639 if (where % sizeof(uint16_t))
1641 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1642 pci_write_config_word(pdev, where,
1644 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1645 rc = pci_read_config_word(pdev, where, &u16val);
1647 u16val |= (uint16_t)value;
1648 pci_write_config_word(pdev, where,
1652 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1653 rc = pci_read_config_word(pdev, where, &u16val);
1655 u16val &= (uint16_t)(~value);
1656 pci_write_config_word(pdev, where,
1661 if (count == sizeof(uint32_t)) {
1662 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1664 if (where % sizeof(uint32_t))
1666 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1667 pci_write_config_dword(pdev, where, value);
1668 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1669 rc = pci_read_config_dword(pdev, where,
1673 pci_write_config_dword(pdev, where,
1677 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1678 rc = pci_read_config_dword(pdev, where,
1682 pci_write_config_dword(pdev, where,
1688 /* All other opecodes are illegal for now */
1693 memset(&idiag, 0, sizeof(idiag));
1698 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1699 * @file: The file pointer to read from.
1700 * @buf: The buffer to copy the data to.
1701 * @nbytes: The number of bytes to read.
1702 * @ppos: The position in the file to start reading from.
1705 * This routine reads data from the @phba pci bar memory mapped space
1706 * according to the idiag command, and copies to user @buf.
1709 * This function returns the amount of data that was read (this could be less
1710 * than @nbytes if the end of the file was reached) or a negative error value.
1713 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1716 struct lpfc_debug *debug = file->private_data;
1717 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1718 int offset_label, offset, offset_run, len = 0, index;
1719 int bar_num, acc_range, bar_size;
1721 void __iomem *mem_mapped_bar;
1723 struct pci_dev *pdev;
1726 pdev = phba->pcidev;
1730 /* This is a user read operation */
1731 debug->op = LPFC_IDIAG_OP_RD;
1734 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1737 pbuffer = debug->buffer;
1742 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1743 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1744 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1745 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1746 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1753 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1754 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1755 if (bar_num == IDIAG_BARACC_BAR_0)
1756 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1757 else if (bar_num == IDIAG_BARACC_BAR_1)
1758 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1759 else if (bar_num == IDIAG_BARACC_BAR_2)
1760 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1763 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1764 if (bar_num == IDIAG_BARACC_BAR_0)
1765 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1771 /* Read single PCI bar space register */
1772 if (acc_range == SINGLE_WORD) {
1773 offset_run = offset;
1774 u32val = readl(mem_mapped_bar + offset_run);
1775 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1776 "%05x: %08x\n", offset_run, u32val);
1780 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1784 /* Browse all PCI bar space registers */
1785 offset_label = idiag.offset.last_rd;
1786 offset_run = offset_label;
1788 /* Read PCI bar memory mapped space */
1789 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1790 "%05x: ", offset_label);
1791 index = LPFC_PCI_BAR_RD_SIZE;
1793 u32val = readl(mem_mapped_bar + offset_run);
1794 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1796 offset_run += sizeof(uint32_t);
1797 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1798 if (offset_run >= bar_size) {
1799 len += snprintf(pbuffer+len,
1800 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1804 if (offset_run >= offset +
1805 (acc_range * sizeof(uint32_t))) {
1806 len += snprintf(pbuffer+len,
1807 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1811 index -= sizeof(uint32_t);
1813 len += snprintf(pbuffer+len,
1814 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1815 else if (!(index % (8 * sizeof(uint32_t)))) {
1816 offset_label += (8 * sizeof(uint32_t));
1817 len += snprintf(pbuffer+len,
1818 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1819 "\n%05x: ", offset_label);
1823 /* Set up the offset for next portion of pci bar read */
1825 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1826 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1827 if (idiag.offset.last_rd >= bar_size)
1828 idiag.offset.last_rd = 0;
1830 if (offset_run >= offset +
1831 (acc_range * sizeof(uint32_t)))
1832 idiag.offset.last_rd = offset;
1835 if (acc_range == LPFC_PCI_BAR_BROWSE)
1836 idiag.offset.last_rd = 0;
1838 idiag.offset.last_rd = offset;
1841 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1845 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1846 * @file: The file pointer to read from.
1847 * @buf: The buffer to copy the user data from.
1848 * @nbytes: The number of bytes to get.
1849 * @ppos: The position in the file to start reading from.
1851 * This routine get the debugfs idiag command struct from user space and
1852 * then perform the syntax check for PCI bar memory mapped space read or
1853 * write command accordingly. In the case of PCI bar memory mapped space
1854 * read command, it sets up the command in the idiag command struct for
1855 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1856 * write operation, it executes the write operation into the PCI bar memory
1857 * mapped space accordingly.
1859 * It returns the @nbytges passing in from debugfs user space when successful.
1860 * In case of error conditions, it returns proper error code back to the user
1864 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1865 size_t nbytes, loff_t *ppos)
1867 struct lpfc_debug *debug = file->private_data;
1868 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1869 uint32_t bar_num, bar_size, offset, value, acc_range;
1870 struct pci_dev *pdev;
1871 void __iomem *mem_mapped_bar;
1876 pdev = phba->pcidev;
1880 /* This is a user write operation */
1881 debug->op = LPFC_IDIAG_OP_WR;
1883 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1887 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1888 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1890 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1891 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1892 (bar_num != IDIAG_BARACC_BAR_1) &&
1893 (bar_num != IDIAG_BARACC_BAR_2))
1895 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1896 if (bar_num != IDIAG_BARACC_BAR_0)
1901 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1902 if (bar_num == IDIAG_BARACC_BAR_0) {
1903 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1904 LPFC_PCI_IF0_BAR0_SIZE;
1905 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1906 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1907 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1908 LPFC_PCI_IF0_BAR1_SIZE;
1909 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1910 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1911 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1912 LPFC_PCI_IF0_BAR2_SIZE;
1913 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1916 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1917 if (bar_num == IDIAG_BARACC_BAR_0) {
1918 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1919 LPFC_PCI_IF2_BAR0_SIZE;
1920 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1926 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1927 if (offset % sizeof(uint32_t))
1930 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1931 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1932 /* Sanity check on PCI config read command line arguments */
1933 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1935 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1936 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1937 if (offset > bar_size - sizeof(uint32_t))
1939 /* Starting offset to browse */
1940 idiag.offset.last_rd = offset;
1941 } else if (acc_range > SINGLE_WORD) {
1942 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1944 /* Starting offset to browse */
1945 idiag.offset.last_rd = offset;
1946 } else if (acc_range != SINGLE_WORD)
1948 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1949 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1950 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1951 /* Sanity check on PCI bar write command line arguments */
1952 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1954 /* Write command to PCI bar space, read-modify-write */
1955 acc_range = SINGLE_WORD;
1956 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1957 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1958 writel(value, mem_mapped_bar + offset);
1959 readl(mem_mapped_bar + offset);
1961 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1962 u32val = readl(mem_mapped_bar + offset);
1964 writel(u32val, mem_mapped_bar + offset);
1965 readl(mem_mapped_bar + offset);
1967 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1968 u32val = readl(mem_mapped_bar + offset);
1970 writel(u32val, mem_mapped_bar + offset);
1971 readl(mem_mapped_bar + offset);
1974 /* All other opecodes are illegal for now */
1979 memset(&idiag, 0, sizeof(idiag));
1984 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1985 * @file: The file pointer to read from.
1986 * @buf: The buffer to copy the data to.
1987 * @nbytes: The number of bytes to read.
1988 * @ppos: The position in the file to start reading from.
1991 * This routine reads data from the @phba SLI4 PCI function queue information,
1992 * and copies to user @buf.
1995 * This function returns the amount of data that was read (this could be less
1996 * than @nbytes if the end of the file was reached) or a negative error value.
1999 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
2002 struct lpfc_debug *debug = file->private_data;
2003 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2008 struct lpfc_queue *qp = NULL;
2012 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
2015 pbuffer = debug->buffer;
2016 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 128;
2021 spin_lock_irq(&phba->hbalock);
2023 /* Fast-path event queue */
2024 if (phba->sli4_hba.hba_eq && phba->cfg_fcp_io_channel) {
2025 cnt = phba->cfg_fcp_io_channel;
2027 for (x = 0; x < cnt; x++) {
2030 qp = phba->sli4_hba.hba_eq[x];
2034 len += snprintf(pbuffer+len,
2035 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2037 "EQ-STAT[max:x%x noE:x%x "
2038 "bs:x%x proc:x%llx]\n",
2039 qp->q_cnt_1, qp->q_cnt_2,
2040 qp->q_cnt_3, qp->q_cnt_4);
2042 len += snprintf(pbuffer+len,
2043 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2045 "QE-CNT[%04d], QE-SIZE[%04d], "
2046 "HOST-IDX[%04d], PORT-IDX[%04d]",
2054 /* Reset max counter */
2057 len += snprintf(pbuffer+len,
2058 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2062 /* Fast-path FCP CQ */
2063 qp = phba->sli4_hba.fcp_cq[x];
2064 len += snprintf(pbuffer+len,
2065 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2067 len += snprintf(pbuffer+len,
2068 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2070 "CQ STAT[max:x%x relw:x%x "
2071 "xabt:x%x wq:x%llx]\n",
2073 qp->q_cnt_1, qp->q_cnt_2,
2074 qp->q_cnt_3, qp->q_cnt_4);
2075 len += snprintf(pbuffer+len,
2076 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2078 "QE-CNT[%04d], QE-SIZE[%04d], "
2079 "HOST-IDX[%04d], PORT-IDX[%04d]",
2080 qp->queue_id, qp->entry_count,
2081 qp->entry_size, qp->host_index,
2085 /* Reset max counter */
2088 len += snprintf(pbuffer+len,
2089 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2093 /* Fast-path FCP WQ */
2094 qp = phba->sli4_hba.fcp_wq[x];
2096 len += snprintf(pbuffer+len,
2097 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2098 "\t\tFCP WQ info: ");
2099 len += snprintf(pbuffer+len,
2100 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2102 "WQ-STAT[oflow:x%x posted:x%llx]\n",
2104 qp->q_cnt_1, qp->q_cnt_4);
2105 len += snprintf(pbuffer+len,
2106 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2108 "QE-CNT[%04d], QE-SIZE[%04d], "
2109 "HOST-IDX[%04d], PORT-IDX[%04d]",
2116 len += snprintf(pbuffer+len,
2117 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2124 /* Only EQ 0 has slow path CQs configured */
2126 /* Slow-path mailbox CQ */
2127 qp = phba->sli4_hba.mbx_cq;
2129 len += snprintf(pbuffer+len,
2130 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2132 len += snprintf(pbuffer+len,
2133 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2135 "CQ-STAT[mbox:x%x relw:x%x "
2136 "xabt:x%x wq:x%llx]\n",
2138 qp->q_cnt_1, qp->q_cnt_2,
2139 qp->q_cnt_3, qp->q_cnt_4);
2140 len += snprintf(pbuffer+len,
2141 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2143 "QE-CNT[%04d], QE-SIZE[%04d], "
2144 "HOST-IDX[%04d], PORT-IDX[%04d]",
2145 qp->queue_id, qp->entry_count,
2146 qp->entry_size, qp->host_index,
2149 len += snprintf(pbuffer+len,
2150 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2155 /* Slow-path MBOX MQ */
2156 qp = phba->sli4_hba.mbx_wq;
2158 len += snprintf(pbuffer+len,
2159 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2160 "\t\tMBX MQ info: ");
2161 len += snprintf(pbuffer+len,
2162 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2163 "AssocCQID[%02d]:\n",
2164 phba->sli4_hba.mbx_wq->assoc_qid);
2165 len += snprintf(pbuffer+len,
2166 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2168 "QE-CNT[%04d], QE-SIZE[%04d], "
2169 "HOST-IDX[%04d], PORT-IDX[%04d]",
2170 qp->queue_id, qp->entry_count,
2171 qp->entry_size, qp->host_index,
2174 len += snprintf(pbuffer+len,
2175 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2180 /* Slow-path ELS response CQ */
2181 qp = phba->sli4_hba.els_cq;
2183 len += snprintf(pbuffer+len,
2184 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2186 len += snprintf(pbuffer+len,
2187 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2189 "CQ-STAT[max:x%x relw:x%x "
2190 "xabt:x%x wq:x%llx]\n",
2192 qp->q_cnt_1, qp->q_cnt_2,
2193 qp->q_cnt_3, qp->q_cnt_4);
2194 len += snprintf(pbuffer+len,
2195 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2197 "QE-CNT[%04d], QE-SIZE[%04d], "
2198 "HOST-IDX[%04d], PORT-IDX[%04d]",
2199 qp->queue_id, qp->entry_count,
2200 qp->entry_size, qp->host_index,
2203 /* Reset max counter */
2206 len += snprintf(pbuffer+len,
2207 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2212 /* Slow-path ELS WQ */
2213 qp = phba->sli4_hba.els_wq;
2215 len += snprintf(pbuffer+len,
2216 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2217 "\t\tELS WQ info: ");
2218 len += snprintf(pbuffer+len,
2219 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2221 " WQ-STAT[oflow:x%x "
2224 qp->q_cnt_1, qp->q_cnt_4);
2225 len += snprintf(pbuffer+len,
2226 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2228 "QE-CNT[%04d], QE-SIZE[%04d], "
2229 "HOST-IDX[%04d], PORT-IDX[%04d]",
2230 qp->queue_id, qp->entry_count,
2231 qp->entry_size, qp->host_index,
2234 len += snprintf(pbuffer+len,
2235 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2240 if (phba->sli4_hba.hdr_rq && phba->sli4_hba.dat_rq) {
2241 /* Slow-path RQ header */
2242 qp = phba->sli4_hba.hdr_rq;
2244 len += snprintf(pbuffer+len,
2245 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2247 len += snprintf(pbuffer+len,
2248 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2250 "RQ-STAT[nopost:x%x nobuf:x%x "
2251 "trunc:x%x rcv:x%llx]\n",
2253 qp->q_cnt_1, qp->q_cnt_2,
2254 qp->q_cnt_3, qp->q_cnt_4);
2255 len += snprintf(pbuffer+len,
2256 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2258 "QE-CNT[%04d], QE-SIZE[%04d], "
2259 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
2266 /* Slow-path RQ data */
2267 qp = phba->sli4_hba.dat_rq;
2268 len += snprintf(pbuffer+len,
2269 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2271 "QE-CNT[%04d], QE-SIZE[%04d], "
2272 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
2279 len += snprintf(pbuffer+len,
2280 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2285 spin_unlock_irq(&phba->hbalock);
2286 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2289 len += snprintf(pbuffer+len,
2290 LPFC_QUE_INFO_GET_BUF_SIZE-len, "Truncated ...\n");
2291 spin_unlock_irq(&phba->hbalock);
2292 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2296 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2297 * @q: The pointer to queue structure.
2298 * @index: The index into a queue entry.
2299 * @count: The number of queue entries to access.
2302 * The routine performs sanity check on device queue access method commands.
2305 * This function returns -EINVAL when fails the sanity check, otherwise, it
2309 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2311 /* Only support single entry read or browsing */
2312 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2314 if (index > q->entry_count - 1)
2320 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2321 * @pbuffer: The pointer to buffer to copy the read data into.
2322 * @pque: The pointer to the queue to be read.
2323 * @index: The index into the queue entry.
2326 * This routine reads out a single entry from the given queue's index location
2327 * and copies it into the buffer provided.
2330 * This function returns 0 when it fails, otherwise, it returns the length of
2331 * the data read into the buffer provided.
2334 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2340 if (!pbuffer || !pque)
2343 esize = pque->entry_size;
2344 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2345 "QE-INDEX[%04d]:\n", index);
2348 pentry = pque->qe[index].address;
2350 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2353 offset += sizeof(uint32_t);
2354 esize -= sizeof(uint32_t);
2355 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2356 len += snprintf(pbuffer+len,
2357 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2359 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2365 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2366 * @file: The file pointer to read from.
2367 * @buf: The buffer to copy the data to.
2368 * @nbytes: The number of bytes to read.
2369 * @ppos: The position in the file to start reading from.
2372 * This routine reads data from the @phba device queue memory according to the
2373 * idiag command, and copies to user @buf. Depending on the queue dump read
2374 * command setup, it does either a single queue entry read or browing through
2375 * all entries of the queue.
2378 * This function returns the amount of data that was read (this could be less
2379 * than @nbytes if the end of the file was reached) or a negative error value.
2382 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2385 struct lpfc_debug *debug = file->private_data;
2386 uint32_t last_index, index, count;
2387 struct lpfc_queue *pque = NULL;
2391 /* This is a user read operation */
2392 debug->op = LPFC_IDIAG_OP_RD;
2395 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2398 pbuffer = debug->buffer;
2403 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2404 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2405 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2406 pque = (struct lpfc_queue *)idiag.ptr_private;
2410 /* Browse the queue starting from index */
2411 if (count == LPFC_QUE_ACC_BROWSE)
2414 /* Read a single entry from the queue */
2415 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2417 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2421 /* Browse all entries from the queue */
2422 last_index = idiag.offset.last_rd;
2425 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2426 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2428 if (index > pque->entry_count - 1)
2432 /* Set up the offset for next portion of pci cfg read */
2433 if (index > pque->entry_count - 1)
2435 idiag.offset.last_rd = index;
2437 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2441 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2442 * @file: The file pointer to read from.
2443 * @buf: The buffer to copy the user data from.
2444 * @nbytes: The number of bytes to get.
2445 * @ppos: The position in the file to start reading from.
2447 * This routine get the debugfs idiag command struct from user space and then
2448 * perform the syntax check for port queue read (dump) or write (set) command
2449 * accordingly. In the case of port queue read command, it sets up the command
2450 * in the idiag command struct for the following debugfs read operation. In
2451 * the case of port queue write operation, it executes the write operation
2452 * into the port queue entry accordingly.
2454 * It returns the @nbytges passing in from debugfs user space when successful.
2455 * In case of error conditions, it returns proper error code back to the user
2459 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2460 size_t nbytes, loff_t *ppos)
2462 struct lpfc_debug *debug = file->private_data;
2463 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2464 uint32_t qidx, quetp, queid, index, count, offset, value;
2466 struct lpfc_queue *pque;
2469 /* This is a user write operation */
2470 debug->op = LPFC_IDIAG_OP_WR;
2472 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2476 /* Get and sanity check on command feilds */
2477 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2478 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2479 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2480 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2481 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2482 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
2484 /* Sanity check on command line arguments */
2485 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2486 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2487 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2488 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2492 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2493 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2500 /* HBA event queue */
2501 if (phba->sli4_hba.hba_eq) {
2502 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
2504 if (phba->sli4_hba.hba_eq[qidx] &&
2505 phba->sli4_hba.hba_eq[qidx]->queue_id ==
2508 rc = lpfc_idiag_que_param_check(
2509 phba->sli4_hba.hba_eq[qidx],
2514 phba->sli4_hba.hba_eq[qidx];
2522 /* MBX complete queue */
2523 if (phba->sli4_hba.mbx_cq &&
2524 phba->sli4_hba.mbx_cq->queue_id == queid) {
2526 rc = lpfc_idiag_que_param_check(
2527 phba->sli4_hba.mbx_cq, index, count);
2530 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2533 /* ELS complete queue */
2534 if (phba->sli4_hba.els_cq &&
2535 phba->sli4_hba.els_cq->queue_id == queid) {
2537 rc = lpfc_idiag_que_param_check(
2538 phba->sli4_hba.els_cq, index, count);
2541 idiag.ptr_private = phba->sli4_hba.els_cq;
2544 /* FCP complete queue */
2545 if (phba->sli4_hba.fcp_cq) {
2548 if (phba->sli4_hba.fcp_cq[qidx] &&
2549 phba->sli4_hba.fcp_cq[qidx]->queue_id ==
2552 rc = lpfc_idiag_que_param_check(
2553 phba->sli4_hba.fcp_cq[qidx],
2558 phba->sli4_hba.fcp_cq[qidx];
2561 } while (++qidx < phba->cfg_fcp_io_channel);
2566 /* MBX work queue */
2567 if (phba->sli4_hba.mbx_wq &&
2568 phba->sli4_hba.mbx_wq->queue_id == queid) {
2570 rc = lpfc_idiag_que_param_check(
2571 phba->sli4_hba.mbx_wq, index, count);
2574 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2580 /* ELS work queue */
2581 if (phba->sli4_hba.els_wq &&
2582 phba->sli4_hba.els_wq->queue_id == queid) {
2584 rc = lpfc_idiag_que_param_check(
2585 phba->sli4_hba.els_wq, index, count);
2588 idiag.ptr_private = phba->sli4_hba.els_wq;
2591 /* FCP work queue */
2592 if (phba->sli4_hba.fcp_wq) {
2593 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
2595 if (!phba->sli4_hba.fcp_wq[qidx])
2597 if (phba->sli4_hba.fcp_wq[qidx]->queue_id ==
2600 rc = lpfc_idiag_que_param_check(
2601 phba->sli4_hba.fcp_wq[qidx],
2606 phba->sli4_hba.fcp_wq[qidx];
2615 if (phba->sli4_hba.hdr_rq &&
2616 phba->sli4_hba.hdr_rq->queue_id == queid) {
2618 rc = lpfc_idiag_que_param_check(
2619 phba->sli4_hba.hdr_rq, index, count);
2622 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2626 if (phba->sli4_hba.dat_rq &&
2627 phba->sli4_hba.dat_rq->queue_id == queid) {
2629 rc = lpfc_idiag_que_param_check(
2630 phba->sli4_hba.dat_rq, index, count);
2633 idiag.ptr_private = phba->sli4_hba.dat_rq;
2645 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2646 if (count == LPFC_QUE_ACC_BROWSE)
2647 idiag.offset.last_rd = index;
2650 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2651 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2652 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2653 /* Additional sanity checks on write operation */
2654 pque = (struct lpfc_queue *)idiag.ptr_private;
2655 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2657 pentry = pque->qe[index].address;
2659 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2661 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2663 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2669 /* Clean out command structure on command error out */
2670 memset(&idiag, 0, sizeof(idiag));
2675 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2676 * @phba: The pointer to hba structure.
2677 * @pbuffer: The pointer to the buffer to copy the data to.
2678 * @len: The lenght of bytes to copied.
2679 * @drbregid: The id to doorbell registers.
2682 * This routine reads a doorbell register and copies its content to the
2683 * user buffer pointed to by @pbuffer.
2686 * This function returns the amount of data that was copied into @pbuffer.
2689 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2690 int len, uint32_t drbregid)
2698 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2699 "EQCQ-DRB-REG: 0x%08x\n",
2700 readl(phba->sli4_hba.EQCQDBregaddr));
2703 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2704 "MQ-DRB-REG: 0x%08x\n",
2705 readl(phba->sli4_hba.MQDBregaddr));
2708 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2709 "WQ-DRB-REG: 0x%08x\n",
2710 readl(phba->sli4_hba.WQDBregaddr));
2713 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2714 "RQ-DRB-REG: 0x%08x\n",
2715 readl(phba->sli4_hba.RQDBregaddr));
2725 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2726 * @file: The file pointer to read from.
2727 * @buf: The buffer to copy the data to.
2728 * @nbytes: The number of bytes to read.
2729 * @ppos: The position in the file to start reading from.
2732 * This routine reads data from the @phba device doorbell register according
2733 * to the idiag command, and copies to user @buf. Depending on the doorbell
2734 * register read command setup, it does either a single doorbell register
2735 * read or dump all doorbell registers.
2738 * This function returns the amount of data that was read (this could be less
2739 * than @nbytes if the end of the file was reached) or a negative error value.
2742 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2745 struct lpfc_debug *debug = file->private_data;
2746 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2747 uint32_t drb_reg_id, i;
2751 /* This is a user read operation */
2752 debug->op = LPFC_IDIAG_OP_RD;
2755 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2758 pbuffer = debug->buffer;
2763 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
2764 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2768 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2769 for (i = 1; i <= LPFC_DRB_MAX; i++)
2770 len = lpfc_idiag_drbacc_read_reg(phba,
2773 len = lpfc_idiag_drbacc_read_reg(phba,
2774 pbuffer, len, drb_reg_id);
2776 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2780 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2781 * @file: The file pointer to read from.
2782 * @buf: The buffer to copy the user data from.
2783 * @nbytes: The number of bytes to get.
2784 * @ppos: The position in the file to start reading from.
2786 * This routine get the debugfs idiag command struct from user space and then
2787 * perform the syntax check for port doorbell register read (dump) or write
2788 * (set) command accordingly. In the case of port queue read command, it sets
2789 * up the command in the idiag command struct for the following debugfs read
2790 * operation. In the case of port doorbell register write operation, it
2791 * executes the write operation into the port doorbell register accordingly.
2793 * It returns the @nbytges passing in from debugfs user space when successful.
2794 * In case of error conditions, it returns proper error code back to the user
2798 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2799 size_t nbytes, loff_t *ppos)
2801 struct lpfc_debug *debug = file->private_data;
2802 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2803 uint32_t drb_reg_id, value, reg_val = 0;
2804 void __iomem *drb_reg;
2807 /* This is a user write operation */
2808 debug->op = LPFC_IDIAG_OP_WR;
2810 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2814 /* Sanity check on command line arguments */
2815 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2816 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
2818 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2819 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2820 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2821 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2823 if (drb_reg_id > LPFC_DRB_MAX)
2825 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2826 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2828 if ((drb_reg_id > LPFC_DRB_MAX) &&
2829 (drb_reg_id != LPFC_DRB_ACC_ALL))
2834 /* Perform the write access operation */
2835 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2836 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2837 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2838 switch (drb_reg_id) {
2840 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2843 drb_reg = phba->sli4_hba.MQDBregaddr;
2846 drb_reg = phba->sli4_hba.WQDBregaddr;
2849 drb_reg = phba->sli4_hba.RQDBregaddr;
2855 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2857 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2858 reg_val = readl(drb_reg);
2861 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2862 reg_val = readl(drb_reg);
2865 writel(reg_val, drb_reg);
2866 readl(drb_reg); /* flush */
2871 /* Clean out command structure on command error out */
2872 memset(&idiag, 0, sizeof(idiag));
2877 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2878 * @phba: The pointer to hba structure.
2879 * @pbuffer: The pointer to the buffer to copy the data to.
2880 * @len: The lenght of bytes to copied.
2881 * @drbregid: The id to doorbell registers.
2884 * This routine reads a control register and copies its content to the
2885 * user buffer pointed to by @pbuffer.
2888 * This function returns the amount of data that was copied into @pbuffer.
2891 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2892 int len, uint32_t ctlregid)
2899 case LPFC_CTL_PORT_SEM:
2900 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2901 "Port SemReg: 0x%08x\n",
2902 readl(phba->sli4_hba.conf_regs_memmap_p +
2903 LPFC_CTL_PORT_SEM_OFFSET));
2905 case LPFC_CTL_PORT_STA:
2906 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2907 "Port StaReg: 0x%08x\n",
2908 readl(phba->sli4_hba.conf_regs_memmap_p +
2909 LPFC_CTL_PORT_STA_OFFSET));
2911 case LPFC_CTL_PORT_CTL:
2912 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2913 "Port CtlReg: 0x%08x\n",
2914 readl(phba->sli4_hba.conf_regs_memmap_p +
2915 LPFC_CTL_PORT_CTL_OFFSET));
2917 case LPFC_CTL_PORT_ER1:
2918 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2919 "Port Er1Reg: 0x%08x\n",
2920 readl(phba->sli4_hba.conf_regs_memmap_p +
2921 LPFC_CTL_PORT_ER1_OFFSET));
2923 case LPFC_CTL_PORT_ER2:
2924 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2925 "Port Er2Reg: 0x%08x\n",
2926 readl(phba->sli4_hba.conf_regs_memmap_p +
2927 LPFC_CTL_PORT_ER2_OFFSET));
2929 case LPFC_CTL_PDEV_CTL:
2930 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2931 "PDev CtlReg: 0x%08x\n",
2932 readl(phba->sli4_hba.conf_regs_memmap_p +
2933 LPFC_CTL_PDEV_CTL_OFFSET));
2942 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2943 * @file: The file pointer to read from.
2944 * @buf: The buffer to copy the data to.
2945 * @nbytes: The number of bytes to read.
2946 * @ppos: The position in the file to start reading from.
2949 * This routine reads data from the @phba port and device registers according
2950 * to the idiag command, and copies to user @buf.
2953 * This function returns the amount of data that was read (this could be less
2954 * than @nbytes if the end of the file was reached) or a negative error value.
2957 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2960 struct lpfc_debug *debug = file->private_data;
2961 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2962 uint32_t ctl_reg_id, i;
2966 /* This is a user read operation */
2967 debug->op = LPFC_IDIAG_OP_RD;
2970 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2973 pbuffer = debug->buffer;
2978 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2979 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2983 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2984 for (i = 1; i <= LPFC_CTL_MAX; i++)
2985 len = lpfc_idiag_ctlacc_read_reg(phba,
2988 len = lpfc_idiag_ctlacc_read_reg(phba,
2989 pbuffer, len, ctl_reg_id);
2991 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2995 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2996 * @file: The file pointer to read from.
2997 * @buf: The buffer to copy the user data from.
2998 * @nbytes: The number of bytes to get.
2999 * @ppos: The position in the file to start reading from.
3001 * This routine get the debugfs idiag command struct from user space and then
3002 * perform the syntax check for port and device control register read (dump)
3003 * or write (set) command accordingly.
3005 * It returns the @nbytges passing in from debugfs user space when successful.
3006 * In case of error conditions, it returns proper error code back to the user
3010 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
3011 size_t nbytes, loff_t *ppos)
3013 struct lpfc_debug *debug = file->private_data;
3014 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3015 uint32_t ctl_reg_id, value, reg_val = 0;
3016 void __iomem *ctl_reg;
3019 /* This is a user write operation */
3020 debug->op = LPFC_IDIAG_OP_WR;
3022 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3026 /* Sanity check on command line arguments */
3027 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
3028 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
3030 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
3031 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
3032 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3033 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
3035 if (ctl_reg_id > LPFC_CTL_MAX)
3037 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
3038 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
3040 if ((ctl_reg_id > LPFC_CTL_MAX) &&
3041 (ctl_reg_id != LPFC_CTL_ACC_ALL))
3046 /* Perform the write access operation */
3047 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
3048 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
3049 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3050 switch (ctl_reg_id) {
3051 case LPFC_CTL_PORT_SEM:
3052 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3053 LPFC_CTL_PORT_SEM_OFFSET;
3055 case LPFC_CTL_PORT_STA:
3056 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3057 LPFC_CTL_PORT_STA_OFFSET;
3059 case LPFC_CTL_PORT_CTL:
3060 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3061 LPFC_CTL_PORT_CTL_OFFSET;
3063 case LPFC_CTL_PORT_ER1:
3064 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3065 LPFC_CTL_PORT_ER1_OFFSET;
3067 case LPFC_CTL_PORT_ER2:
3068 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3069 LPFC_CTL_PORT_ER2_OFFSET;
3071 case LPFC_CTL_PDEV_CTL:
3072 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3073 LPFC_CTL_PDEV_CTL_OFFSET;
3079 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
3081 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
3082 reg_val = readl(ctl_reg);
3085 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3086 reg_val = readl(ctl_reg);
3089 writel(reg_val, ctl_reg);
3090 readl(ctl_reg); /* flush */
3095 /* Clean out command structure on command error out */
3096 memset(&idiag, 0, sizeof(idiag));
3101 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
3102 * @phba: Pointer to HBA context object.
3103 * @pbuffer: Pointer to data buffer.
3106 * This routine gets the driver mailbox access debugfs setup information.
3109 * This function returns the amount of data that was read (this could be less
3110 * than @nbytes if the end of the file was reached) or a negative error value.
3113 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
3115 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3118 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3119 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3120 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3121 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3123 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3124 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
3125 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3126 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
3127 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3128 "mbx_word_cnt: %04d\n", mbx_word_cnt);
3129 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3130 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
3136 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
3137 * @file: The file pointer to read from.
3138 * @buf: The buffer to copy the data to.
3139 * @nbytes: The number of bytes to read.
3140 * @ppos: The position in the file to start reading from.
3143 * This routine reads data from the @phba driver mailbox access debugfs setup
3147 * This function returns the amount of data that was read (this could be less
3148 * than @nbytes if the end of the file was reached) or a negative error value.
3151 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3154 struct lpfc_debug *debug = file->private_data;
3155 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3159 /* This is a user read operation */
3160 debug->op = LPFC_IDIAG_OP_RD;
3163 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3166 pbuffer = debug->buffer;
3171 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3172 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3175 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3177 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3181 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3182 * @file: The file pointer to read from.
3183 * @buf: The buffer to copy the user data from.
3184 * @nbytes: The number of bytes to get.
3185 * @ppos: The position in the file to start reading from.
3187 * This routine get the debugfs idiag command struct from user space and then
3188 * perform the syntax check for driver mailbox command (dump) and sets up the
3189 * necessary states in the idiag command struct accordingly.
3191 * It returns the @nbytges passing in from debugfs user space when successful.
3192 * In case of error conditions, it returns proper error code back to the user
3196 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3197 size_t nbytes, loff_t *ppos)
3199 struct lpfc_debug *debug = file->private_data;
3200 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3203 /* This is a user write operation */
3204 debug->op = LPFC_IDIAG_OP_WR;
3206 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3210 /* Sanity check on command line arguments */
3211 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3212 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3213 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3214 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3216 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3217 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3219 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3220 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3222 if (mbx_word_cnt > sizeof(MAILBOX_t))
3224 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3225 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3227 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3228 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3230 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3232 if (mbx_mbox_cmd != 0x9b)
3237 if (mbx_word_cnt == 0)
3239 if (rc != LPFC_MBX_DMP_ARG)
3241 if (mbx_mbox_cmd & ~0xff)
3244 /* condition for stop mailbox dump */
3245 if (mbx_dump_cnt == 0)
3251 /* Clean out command structure on command error out */
3252 memset(&idiag, 0, sizeof(idiag));
3256 /* Clean out command structure on command error out */
3257 memset(&idiag, 0, sizeof(idiag));
3262 * lpfc_idiag_extacc_avail_get - get the available extents information
3263 * @phba: pointer to lpfc hba data structure.
3264 * @pbuffer: pointer to internal buffer.
3265 * @len: length into the internal buffer data has been copied.
3268 * This routine is to get the available extent information.
3271 * overall lenth of the data read into the internal buffer.
3274 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3276 uint16_t ext_cnt, ext_size;
3278 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3279 "\nAvailable Extents Information:\n");
3281 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3282 "\tPort Available VPI extents: ");
3283 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3284 &ext_cnt, &ext_size);
3285 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3286 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3288 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3289 "\tPort Available VFI extents: ");
3290 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3291 &ext_cnt, &ext_size);
3292 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3293 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3295 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3296 "\tPort Available RPI extents: ");
3297 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3298 &ext_cnt, &ext_size);
3299 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3300 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3302 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3303 "\tPort Available XRI extents: ");
3304 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3305 &ext_cnt, &ext_size);
3306 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3307 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3313 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3314 * @phba: pointer to lpfc hba data structure.
3315 * @pbuffer: pointer to internal buffer.
3316 * @len: length into the internal buffer data has been copied.
3319 * This routine is to get the allocated extent information.
3322 * overall lenth of the data read into the internal buffer.
3325 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3327 uint16_t ext_cnt, ext_size;
3330 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3331 "\nAllocated Extents Information:\n");
3333 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3334 "\tHost Allocated VPI extents: ");
3335 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3336 &ext_cnt, &ext_size);
3338 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3339 "Port %d Extent %3d, Size %3d\n",
3340 phba->brd_no, ext_cnt, ext_size);
3342 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3345 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3346 "\tHost Allocated VFI extents: ");
3347 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
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 RPI extents: ");
3359 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
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 XRI extents: ");
3371 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
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,
3385 * lpfc_idiag_extacc_drivr_get - get driver extent information
3386 * @phba: pointer to lpfc hba data structure.
3387 * @pbuffer: pointer to internal buffer.
3388 * @len: length into the internal buffer data has been copied.
3391 * This routine is to get the driver extent information.
3394 * overall lenth of the data read into the internal buffer.
3397 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3399 struct lpfc_rsrc_blks *rsrc_blks;
3402 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3403 "\nDriver Extents Information:\n");
3405 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3406 "\tVPI extents:\n");
3408 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3409 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3410 "\t\tBlock %3d: Start %4d, Count %4d\n",
3411 index, rsrc_blks->rsrc_start,
3412 rsrc_blks->rsrc_size);
3415 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3416 "\tVFI extents:\n");
3418 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3420 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3421 "\t\tBlock %3d: Start %4d, Count %4d\n",
3422 index, rsrc_blks->rsrc_start,
3423 rsrc_blks->rsrc_size);
3427 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3428 "\tRPI extents:\n");
3430 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_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 "\tXRI extents:\n");
3442 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_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);
3455 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3456 * @file: The file pointer to read from.
3457 * @buf: The buffer to copy the user data from.
3458 * @nbytes: The number of bytes to get.
3459 * @ppos: The position in the file to start reading from.
3461 * This routine get the debugfs idiag command struct from user space and then
3462 * perform the syntax check for extent information access commands and sets
3463 * up the necessary states in the idiag command struct accordingly.
3465 * It returns the @nbytges passing in from debugfs user space when successful.
3466 * In case of error conditions, it returns proper error code back to the user
3470 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3471 size_t nbytes, loff_t *ppos)
3473 struct lpfc_debug *debug = file->private_data;
3477 /* This is a user write operation */
3478 debug->op = LPFC_IDIAG_OP_WR;
3480 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3484 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3486 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3488 if (rc != LPFC_EXT_ACC_CMD_ARG)
3490 if (!(ext_map & LPFC_EXT_ACC_ALL))
3495 /* Clean out command structure on command error out */
3496 memset(&idiag, 0, sizeof(idiag));
3501 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3502 * @file: The file pointer to read from.
3503 * @buf: The buffer to copy the data to.
3504 * @nbytes: The number of bytes to read.
3505 * @ppos: The position in the file to start reading from.
3508 * This routine reads data from the proper extent information according to
3509 * the idiag command, and copies to user @buf.
3512 * This function returns the amount of data that was read (this could be less
3513 * than @nbytes if the end of the file was reached) or a negative error value.
3516 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3519 struct lpfc_debug *debug = file->private_data;
3520 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3525 /* This is a user read operation */
3526 debug->op = LPFC_IDIAG_OP_RD;
3529 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3532 pbuffer = debug->buffer;
3535 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3538 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3539 if (ext_map & LPFC_EXT_ACC_AVAIL)
3540 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3541 if (ext_map & LPFC_EXT_ACC_ALLOC)
3542 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3543 if (ext_map & LPFC_EXT_ACC_DRIVR)
3544 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3546 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3549 #undef lpfc_debugfs_op_disc_trc
3550 static const struct file_operations lpfc_debugfs_op_disc_trc = {
3551 .owner = THIS_MODULE,
3552 .open = lpfc_debugfs_disc_trc_open,
3553 .llseek = lpfc_debugfs_lseek,
3554 .read = lpfc_debugfs_read,
3555 .release = lpfc_debugfs_release,
3558 #undef lpfc_debugfs_op_nodelist
3559 static const struct file_operations lpfc_debugfs_op_nodelist = {
3560 .owner = THIS_MODULE,
3561 .open = lpfc_debugfs_nodelist_open,
3562 .llseek = lpfc_debugfs_lseek,
3563 .read = lpfc_debugfs_read,
3564 .release = lpfc_debugfs_release,
3567 #undef lpfc_debugfs_op_hbqinfo
3568 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
3569 .owner = THIS_MODULE,
3570 .open = lpfc_debugfs_hbqinfo_open,
3571 .llseek = lpfc_debugfs_lseek,
3572 .read = lpfc_debugfs_read,
3573 .release = lpfc_debugfs_release,
3576 #undef lpfc_debugfs_op_dumpHBASlim
3577 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
3578 .owner = THIS_MODULE,
3579 .open = lpfc_debugfs_dumpHBASlim_open,
3580 .llseek = lpfc_debugfs_lseek,
3581 .read = lpfc_debugfs_read,
3582 .release = lpfc_debugfs_release,
3585 #undef lpfc_debugfs_op_dumpHostSlim
3586 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
3587 .owner = THIS_MODULE,
3588 .open = lpfc_debugfs_dumpHostSlim_open,
3589 .llseek = lpfc_debugfs_lseek,
3590 .read = lpfc_debugfs_read,
3591 .release = lpfc_debugfs_release,
3594 #undef lpfc_debugfs_op_dumpData
3595 static const struct file_operations lpfc_debugfs_op_dumpData = {
3596 .owner = THIS_MODULE,
3597 .open = lpfc_debugfs_dumpData_open,
3598 .llseek = lpfc_debugfs_lseek,
3599 .read = lpfc_debugfs_read,
3600 .write = lpfc_debugfs_dumpDataDif_write,
3601 .release = lpfc_debugfs_dumpDataDif_release,
3604 #undef lpfc_debugfs_op_dumpDif
3605 static const struct file_operations lpfc_debugfs_op_dumpDif = {
3606 .owner = THIS_MODULE,
3607 .open = lpfc_debugfs_dumpDif_open,
3608 .llseek = lpfc_debugfs_lseek,
3609 .read = lpfc_debugfs_read,
3610 .write = lpfc_debugfs_dumpDataDif_write,
3611 .release = lpfc_debugfs_dumpDataDif_release,
3614 #undef lpfc_debugfs_op_dif_err
3615 static const struct file_operations lpfc_debugfs_op_dif_err = {
3616 .owner = THIS_MODULE,
3617 .open = simple_open,
3618 .llseek = lpfc_debugfs_lseek,
3619 .read = lpfc_debugfs_dif_err_read,
3620 .write = lpfc_debugfs_dif_err_write,
3621 .release = lpfc_debugfs_dif_err_release,
3624 #undef lpfc_debugfs_op_slow_ring_trc
3625 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
3626 .owner = THIS_MODULE,
3627 .open = lpfc_debugfs_slow_ring_trc_open,
3628 .llseek = lpfc_debugfs_lseek,
3629 .read = lpfc_debugfs_read,
3630 .release = lpfc_debugfs_release,
3633 static struct dentry *lpfc_debugfs_root = NULL;
3634 static atomic_t lpfc_debugfs_hba_count;
3637 * File operations for the iDiag debugfs
3639 #undef lpfc_idiag_op_pciCfg
3640 static const struct file_operations lpfc_idiag_op_pciCfg = {
3641 .owner = THIS_MODULE,
3642 .open = lpfc_idiag_open,
3643 .llseek = lpfc_debugfs_lseek,
3644 .read = lpfc_idiag_pcicfg_read,
3645 .write = lpfc_idiag_pcicfg_write,
3646 .release = lpfc_idiag_cmd_release,
3649 #undef lpfc_idiag_op_barAcc
3650 static const struct file_operations lpfc_idiag_op_barAcc = {
3651 .owner = THIS_MODULE,
3652 .open = lpfc_idiag_open,
3653 .llseek = lpfc_debugfs_lseek,
3654 .read = lpfc_idiag_baracc_read,
3655 .write = lpfc_idiag_baracc_write,
3656 .release = lpfc_idiag_cmd_release,
3659 #undef lpfc_idiag_op_queInfo
3660 static const struct file_operations lpfc_idiag_op_queInfo = {
3661 .owner = THIS_MODULE,
3662 .open = lpfc_idiag_open,
3663 .read = lpfc_idiag_queinfo_read,
3664 .release = lpfc_idiag_release,
3667 #undef lpfc_idiag_op_queAcc
3668 static const struct file_operations lpfc_idiag_op_queAcc = {
3669 .owner = THIS_MODULE,
3670 .open = lpfc_idiag_open,
3671 .llseek = lpfc_debugfs_lseek,
3672 .read = lpfc_idiag_queacc_read,
3673 .write = lpfc_idiag_queacc_write,
3674 .release = lpfc_idiag_cmd_release,
3677 #undef lpfc_idiag_op_drbAcc
3678 static const struct file_operations lpfc_idiag_op_drbAcc = {
3679 .owner = THIS_MODULE,
3680 .open = lpfc_idiag_open,
3681 .llseek = lpfc_debugfs_lseek,
3682 .read = lpfc_idiag_drbacc_read,
3683 .write = lpfc_idiag_drbacc_write,
3684 .release = lpfc_idiag_cmd_release,
3687 #undef lpfc_idiag_op_ctlAcc
3688 static const struct file_operations lpfc_idiag_op_ctlAcc = {
3689 .owner = THIS_MODULE,
3690 .open = lpfc_idiag_open,
3691 .llseek = lpfc_debugfs_lseek,
3692 .read = lpfc_idiag_ctlacc_read,
3693 .write = lpfc_idiag_ctlacc_write,
3694 .release = lpfc_idiag_cmd_release,
3697 #undef lpfc_idiag_op_mbxAcc
3698 static const struct file_operations lpfc_idiag_op_mbxAcc = {
3699 .owner = THIS_MODULE,
3700 .open = lpfc_idiag_open,
3701 .llseek = lpfc_debugfs_lseek,
3702 .read = lpfc_idiag_mbxacc_read,
3703 .write = lpfc_idiag_mbxacc_write,
3704 .release = lpfc_idiag_cmd_release,
3707 #undef lpfc_idiag_op_extAcc
3708 static const struct file_operations lpfc_idiag_op_extAcc = {
3709 .owner = THIS_MODULE,
3710 .open = lpfc_idiag_open,
3711 .llseek = lpfc_debugfs_lseek,
3712 .read = lpfc_idiag_extacc_read,
3713 .write = lpfc_idiag_extacc_write,
3714 .release = lpfc_idiag_cmd_release,
3719 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3720 * @phba: Pointer to HBA context object.
3721 * @dmabuf: Pointer to a DMA buffer descriptor.
3724 * This routine dump a bsg pass-through non-embedded mailbox command with
3728 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3729 enum mbox_type mbox_tp, enum dma_type dma_tp,
3730 enum sta_type sta_tp,
3731 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3733 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3734 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3735 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3737 uint32_t do_dump = 0;
3741 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3744 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3745 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3746 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3747 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3749 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3750 (*mbx_dump_cnt == 0) ||
3751 (*mbx_word_cnt == 0))
3754 if (*mbx_mbox_cmd != 0x9B)
3757 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3758 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3759 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3760 printk(KERN_ERR "\nRead mbox command (x%x), "
3761 "nemb:0x%x, extbuf_cnt:%d:\n",
3762 sta_tp, nemb_tp, ext_buf);
3765 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3766 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3767 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3768 printk(KERN_ERR "\nRead mbox buffer (x%x), "
3769 "nemb:0x%x, extbuf_seq:%d:\n",
3770 sta_tp, nemb_tp, ext_buf);
3773 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3774 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3775 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3776 printk(KERN_ERR "\nWrite mbox command (x%x), "
3777 "nemb:0x%x, extbuf_cnt:%d:\n",
3778 sta_tp, nemb_tp, ext_buf);
3781 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3782 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3783 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3784 printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3785 "nemb:0x%x, extbuf_seq:%d:\n",
3786 sta_tp, nemb_tp, ext_buf);
3790 /* dump buffer content */
3792 pword = (uint32_t *)dmabuf->virt;
3793 for (i = 0; i < *mbx_word_cnt; i++) {
3796 printk(KERN_ERR "%s\n", line_buf);
3798 len += snprintf(line_buf+len,
3799 LPFC_MBX_ACC_LBUF_SZ-len,
3802 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3803 "%08x ", (uint32_t)*pword);
3807 printk(KERN_ERR "%s\n", line_buf);
3811 /* Clean out command structure on reaching dump count */
3812 if (*mbx_dump_cnt == 0)
3813 memset(&idiag, 0, sizeof(idiag));
3818 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3819 * @phba: Pointer to HBA context object.
3820 * @dmabuf: Pointer to a DMA buffer descriptor.
3823 * This routine dump a pass-through non-embedded mailbox command from issue
3827 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3829 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3830 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3831 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3837 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3840 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3841 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3842 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3843 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3845 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3846 (*mbx_dump_cnt == 0) ||
3847 (*mbx_word_cnt == 0))
3850 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3851 (*mbx_mbox_cmd != pmbox->mbxCommand))
3854 /* dump buffer content */
3855 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3856 printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3858 pword = (uint32_t *)pmbox;
3859 for (i = 0; i < *mbx_word_cnt; i++) {
3862 printk(KERN_ERR "%s\n", line_buf);
3864 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3865 len += snprintf(line_buf+len,
3866 LPFC_MBX_ACC_LBUF_SZ-len,
3869 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3871 ((uint32_t)*pword) & 0xffffffff);
3875 printk(KERN_ERR "%s\n", line_buf);
3876 printk(KERN_ERR "\n");
3878 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3879 printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3881 pbyte = (uint8_t *)pmbox;
3882 for (i = 0; i < *mbx_word_cnt; i++) {
3885 printk(KERN_ERR "%s\n", line_buf);
3887 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3888 len += snprintf(line_buf+len,
3889 LPFC_MBX_ACC_LBUF_SZ-len,
3892 for (j = 0; j < 4; j++) {
3893 len += snprintf(line_buf+len,
3894 LPFC_MBX_ACC_LBUF_SZ-len,
3896 ((uint8_t)*pbyte) & 0xff);
3899 len += snprintf(line_buf+len,
3900 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3903 printk(KERN_ERR "%s\n", line_buf);
3904 printk(KERN_ERR "\n");
3908 /* Clean out command structure on reaching dump count */
3909 if (*mbx_dump_cnt == 0)
3910 memset(&idiag, 0, sizeof(idiag));
3916 * lpfc_debugfs_initialize - Initialize debugfs for a vport
3917 * @vport: The vport pointer to initialize.
3920 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3921 * If not already created, this routine will create the lpfc directory, and
3922 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3923 * also create each file used to access lpfc specific debugfs information.
3926 lpfc_debugfs_initialize(struct lpfc_vport *vport)
3928 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3929 struct lpfc_hba *phba = vport->phba;
3933 if (!lpfc_debugfs_enable)
3936 /* Setup lpfc root directory */
3937 if (!lpfc_debugfs_root) {
3938 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3939 atomic_set(&lpfc_debugfs_hba_count, 0);
3940 if (!lpfc_debugfs_root) {
3941 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3942 "0408 Cannot create debugfs root\n");
3946 if (!lpfc_debugfs_start_time)
3947 lpfc_debugfs_start_time = jiffies;
3949 /* Setup funcX directory for specific HBA PCI function */
3950 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
3951 if (!phba->hba_debugfs_root) {
3952 phba->hba_debugfs_root =
3953 debugfs_create_dir(name, lpfc_debugfs_root);
3954 if (!phba->hba_debugfs_root) {
3955 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3956 "0412 Cannot create debugfs hba\n");
3959 atomic_inc(&lpfc_debugfs_hba_count);
3960 atomic_set(&phba->debugfs_vport_count, 0);
3963 snprintf(name, sizeof(name), "hbqinfo");
3964 phba->debug_hbqinfo =
3965 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3966 phba->hba_debugfs_root,
3967 phba, &lpfc_debugfs_op_hbqinfo);
3968 if (!phba->debug_hbqinfo) {
3969 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3970 "0411 Cannot create debugfs hbqinfo\n");
3974 /* Setup dumpHBASlim */
3975 if (phba->sli_rev < LPFC_SLI_REV4) {
3976 snprintf(name, sizeof(name), "dumpHBASlim");
3977 phba->debug_dumpHBASlim =
3978 debugfs_create_file(name,
3979 S_IFREG|S_IRUGO|S_IWUSR,
3980 phba->hba_debugfs_root,
3981 phba, &lpfc_debugfs_op_dumpHBASlim);
3982 if (!phba->debug_dumpHBASlim) {
3983 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3984 "0413 Cannot create debugfs "
3989 phba->debug_dumpHBASlim = NULL;
3991 /* Setup dumpHostSlim */
3992 if (phba->sli_rev < LPFC_SLI_REV4) {
3993 snprintf(name, sizeof(name), "dumpHostSlim");
3994 phba->debug_dumpHostSlim =
3995 debugfs_create_file(name,
3996 S_IFREG|S_IRUGO|S_IWUSR,
3997 phba->hba_debugfs_root,
3998 phba, &lpfc_debugfs_op_dumpHostSlim);
3999 if (!phba->debug_dumpHostSlim) {
4000 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4001 "0414 Cannot create debugfs "
4006 phba->debug_dumpHBASlim = NULL;
4008 /* Setup dumpData */
4009 snprintf(name, sizeof(name), "dumpData");
4010 phba->debug_dumpData =
4011 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4012 phba->hba_debugfs_root,
4013 phba, &lpfc_debugfs_op_dumpData);
4014 if (!phba->debug_dumpData) {
4015 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4016 "0800 Cannot create debugfs dumpData\n");
4021 snprintf(name, sizeof(name), "dumpDif");
4022 phba->debug_dumpDif =
4023 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4024 phba->hba_debugfs_root,
4025 phba, &lpfc_debugfs_op_dumpDif);
4026 if (!phba->debug_dumpDif) {
4027 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4028 "0801 Cannot create debugfs dumpDif\n");
4032 /* Setup DIF Error Injections */
4033 snprintf(name, sizeof(name), "InjErrLBA");
4034 phba->debug_InjErrLBA =
4035 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4036 phba->hba_debugfs_root,
4037 phba, &lpfc_debugfs_op_dif_err);
4038 if (!phba->debug_InjErrLBA) {
4039 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4040 "0807 Cannot create debugfs InjErrLBA\n");
4043 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
4045 snprintf(name, sizeof(name), "InjErrNPortID");
4046 phba->debug_InjErrNPortID =
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_InjErrNPortID) {
4051 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4052 "0809 Cannot create debugfs InjErrNPortID\n");
4056 snprintf(name, sizeof(name), "InjErrWWPN");
4057 phba->debug_InjErrWWPN =
4058 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4059 phba->hba_debugfs_root,
4060 phba, &lpfc_debugfs_op_dif_err);
4061 if (!phba->debug_InjErrWWPN) {
4062 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4063 "0810 Cannot create debugfs InjErrWWPN\n");
4067 snprintf(name, sizeof(name), "writeGuardInjErr");
4068 phba->debug_writeGuard =
4069 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4070 phba->hba_debugfs_root,
4071 phba, &lpfc_debugfs_op_dif_err);
4072 if (!phba->debug_writeGuard) {
4073 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4074 "0802 Cannot create debugfs writeGuard\n");
4078 snprintf(name, sizeof(name), "writeAppInjErr");
4079 phba->debug_writeApp =
4080 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4081 phba->hba_debugfs_root,
4082 phba, &lpfc_debugfs_op_dif_err);
4083 if (!phba->debug_writeApp) {
4084 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4085 "0803 Cannot create debugfs writeApp\n");
4089 snprintf(name, sizeof(name), "writeRefInjErr");
4090 phba->debug_writeRef =
4091 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4092 phba->hba_debugfs_root,
4093 phba, &lpfc_debugfs_op_dif_err);
4094 if (!phba->debug_writeRef) {
4095 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4096 "0804 Cannot create debugfs writeRef\n");
4100 snprintf(name, sizeof(name), "readGuardInjErr");
4101 phba->debug_readGuard =
4102 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4103 phba->hba_debugfs_root,
4104 phba, &lpfc_debugfs_op_dif_err);
4105 if (!phba->debug_readGuard) {
4106 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4107 "0808 Cannot create debugfs readGuard\n");
4111 snprintf(name, sizeof(name), "readAppInjErr");
4112 phba->debug_readApp =
4113 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4114 phba->hba_debugfs_root,
4115 phba, &lpfc_debugfs_op_dif_err);
4116 if (!phba->debug_readApp) {
4117 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4118 "0805 Cannot create debugfs readApp\n");
4122 snprintf(name, sizeof(name), "readRefInjErr");
4123 phba->debug_readRef =
4124 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4125 phba->hba_debugfs_root,
4126 phba, &lpfc_debugfs_op_dif_err);
4127 if (!phba->debug_readRef) {
4128 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4129 "0806 Cannot create debugfs readApp\n");
4133 /* Setup slow ring trace */
4134 if (lpfc_debugfs_max_slow_ring_trc) {
4135 num = lpfc_debugfs_max_slow_ring_trc - 1;
4136 if (num & lpfc_debugfs_max_slow_ring_trc) {
4137 /* Change to be a power of 2 */
4138 num = lpfc_debugfs_max_slow_ring_trc;
4144 lpfc_debugfs_max_slow_ring_trc = (1 << i);
4146 "lpfc_debugfs_max_disc_trc changed to "
4147 "%d\n", lpfc_debugfs_max_disc_trc);
4151 snprintf(name, sizeof(name), "slow_ring_trace");
4152 phba->debug_slow_ring_trc =
4153 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4154 phba->hba_debugfs_root,
4155 phba, &lpfc_debugfs_op_slow_ring_trc);
4156 if (!phba->debug_slow_ring_trc) {
4157 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4158 "0415 Cannot create debugfs "
4159 "slow_ring_trace\n");
4162 if (!phba->slow_ring_trc) {
4163 phba->slow_ring_trc = kmalloc(
4164 (sizeof(struct lpfc_debugfs_trc) *
4165 lpfc_debugfs_max_slow_ring_trc),
4167 if (!phba->slow_ring_trc) {
4168 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4169 "0416 Cannot create debugfs "
4170 "slow_ring buffer\n");
4173 atomic_set(&phba->slow_ring_trc_cnt, 0);
4174 memset(phba->slow_ring_trc, 0,
4175 (sizeof(struct lpfc_debugfs_trc) *
4176 lpfc_debugfs_max_slow_ring_trc));
4180 snprintf(name, sizeof(name), "vport%d", vport->vpi);
4181 if (!vport->vport_debugfs_root) {
4182 vport->vport_debugfs_root =
4183 debugfs_create_dir(name, phba->hba_debugfs_root);
4184 if (!vport->vport_debugfs_root) {
4185 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4186 "0417 Can't create debugfs\n");
4189 atomic_inc(&phba->debugfs_vport_count);
4192 if (lpfc_debugfs_max_disc_trc) {
4193 num = lpfc_debugfs_max_disc_trc - 1;
4194 if (num & lpfc_debugfs_max_disc_trc) {
4195 /* Change to be a power of 2 */
4196 num = lpfc_debugfs_max_disc_trc;
4202 lpfc_debugfs_max_disc_trc = (1 << i);
4204 "lpfc_debugfs_max_disc_trc changed to %d\n",
4205 lpfc_debugfs_max_disc_trc);
4209 vport->disc_trc = kzalloc(
4210 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
4213 if (!vport->disc_trc) {
4214 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4215 "0418 Cannot create debugfs disc trace "
4219 atomic_set(&vport->disc_trc_cnt, 0);
4221 snprintf(name, sizeof(name), "discovery_trace");
4222 vport->debug_disc_trc =
4223 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4224 vport->vport_debugfs_root,
4225 vport, &lpfc_debugfs_op_disc_trc);
4226 if (!vport->debug_disc_trc) {
4227 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4228 "0419 Cannot create debugfs "
4229 "discovery_trace\n");
4232 snprintf(name, sizeof(name), "nodelist");
4233 vport->debug_nodelist =
4234 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4235 vport->vport_debugfs_root,
4236 vport, &lpfc_debugfs_op_nodelist);
4237 if (!vport->debug_nodelist) {
4238 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4239 "2985 Can't create debugfs nodelist\n");
4244 * iDiag debugfs root entry points for SLI4 device only
4246 if (phba->sli_rev < LPFC_SLI_REV4)
4249 snprintf(name, sizeof(name), "iDiag");
4250 if (!phba->idiag_root) {
4252 debugfs_create_dir(name, phba->hba_debugfs_root);
4253 if (!phba->idiag_root) {
4254 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4255 "2922 Can't create idiag debugfs\n");
4258 /* Initialize iDiag data structure */
4259 memset(&idiag, 0, sizeof(idiag));
4262 /* iDiag read PCI config space */
4263 snprintf(name, sizeof(name), "pciCfg");
4264 if (!phba->idiag_pci_cfg) {
4265 phba->idiag_pci_cfg =
4266 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4267 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
4268 if (!phba->idiag_pci_cfg) {
4269 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4270 "2923 Can't create idiag debugfs\n");
4273 idiag.offset.last_rd = 0;
4276 /* iDiag PCI BAR access */
4277 snprintf(name, sizeof(name), "barAcc");
4278 if (!phba->idiag_bar_acc) {
4279 phba->idiag_bar_acc =
4280 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4281 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
4282 if (!phba->idiag_bar_acc) {
4283 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4284 "3056 Can't create idiag debugfs\n");
4287 idiag.offset.last_rd = 0;
4290 /* iDiag get PCI function queue information */
4291 snprintf(name, sizeof(name), "queInfo");
4292 if (!phba->idiag_que_info) {
4293 phba->idiag_que_info =
4294 debugfs_create_file(name, S_IFREG|S_IRUGO,
4295 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
4296 if (!phba->idiag_que_info) {
4297 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4298 "2924 Can't create idiag debugfs\n");
4303 /* iDiag access PCI function queue */
4304 snprintf(name, sizeof(name), "queAcc");
4305 if (!phba->idiag_que_acc) {
4306 phba->idiag_que_acc =
4307 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4308 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
4309 if (!phba->idiag_que_acc) {
4310 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4311 "2926 Can't create idiag debugfs\n");
4316 /* iDiag access PCI function doorbell registers */
4317 snprintf(name, sizeof(name), "drbAcc");
4318 if (!phba->idiag_drb_acc) {
4319 phba->idiag_drb_acc =
4320 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4321 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
4322 if (!phba->idiag_drb_acc) {
4323 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4324 "2927 Can't create idiag debugfs\n");
4329 /* iDiag access PCI function control registers */
4330 snprintf(name, sizeof(name), "ctlAcc");
4331 if (!phba->idiag_ctl_acc) {
4332 phba->idiag_ctl_acc =
4333 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4334 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
4335 if (!phba->idiag_ctl_acc) {
4336 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4337 "2981 Can't create idiag debugfs\n");
4342 /* iDiag access mbox commands */
4343 snprintf(name, sizeof(name), "mbxAcc");
4344 if (!phba->idiag_mbx_acc) {
4345 phba->idiag_mbx_acc =
4346 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4347 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4348 if (!phba->idiag_mbx_acc) {
4349 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4350 "2980 Can't create idiag debugfs\n");
4355 /* iDiag extents access commands */
4356 if (phba->sli4_hba.extents_in_use) {
4357 snprintf(name, sizeof(name), "extAcc");
4358 if (!phba->idiag_ext_acc) {
4359 phba->idiag_ext_acc =
4360 debugfs_create_file(name,
4361 S_IFREG|S_IRUGO|S_IWUSR,
4362 phba->idiag_root, phba,
4363 &lpfc_idiag_op_extAcc);
4364 if (!phba->idiag_ext_acc) {
4365 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4379 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
4380 * @vport: The vport pointer to remove from debugfs.
4383 * When Debugfs is configured this routine removes debugfs file system elements
4384 * that are specific to this vport. It also checks to see if there are any
4385 * users left for the debugfs directories associated with the HBA and driver. If
4386 * this is the last user of the HBA directory or driver directory then it will
4387 * remove those from the debugfs infrastructure as well.
4390 lpfc_debugfs_terminate(struct lpfc_vport *vport)
4392 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4393 struct lpfc_hba *phba = vport->phba;
4395 if (vport->disc_trc) {
4396 kfree(vport->disc_trc);
4397 vport->disc_trc = NULL;
4399 if (vport->debug_disc_trc) {
4400 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4401 vport->debug_disc_trc = NULL;
4403 if (vport->debug_nodelist) {
4404 debugfs_remove(vport->debug_nodelist); /* nodelist */
4405 vport->debug_nodelist = NULL;
4407 if (vport->vport_debugfs_root) {
4408 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4409 vport->vport_debugfs_root = NULL;
4410 atomic_dec(&phba->debugfs_vport_count);
4412 if (atomic_read(&phba->debugfs_vport_count) == 0) {
4414 if (phba->debug_hbqinfo) {
4415 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4416 phba->debug_hbqinfo = NULL;
4418 if (phba->debug_dumpHBASlim) {
4419 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4420 phba->debug_dumpHBASlim = NULL;
4422 if (phba->debug_dumpHostSlim) {
4423 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4424 phba->debug_dumpHostSlim = NULL;
4426 if (phba->debug_dumpData) {
4427 debugfs_remove(phba->debug_dumpData); /* dumpData */
4428 phba->debug_dumpData = NULL;
4431 if (phba->debug_dumpDif) {
4432 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4433 phba->debug_dumpDif = NULL;
4435 if (phba->debug_InjErrLBA) {
4436 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
4437 phba->debug_InjErrLBA = NULL;
4439 if (phba->debug_InjErrNPortID) { /* InjErrNPortID */
4440 debugfs_remove(phba->debug_InjErrNPortID);
4441 phba->debug_InjErrNPortID = NULL;
4443 if (phba->debug_InjErrWWPN) {
4444 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
4445 phba->debug_InjErrWWPN = NULL;
4447 if (phba->debug_writeGuard) {
4448 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
4449 phba->debug_writeGuard = NULL;
4451 if (phba->debug_writeApp) {
4452 debugfs_remove(phba->debug_writeApp); /* writeApp */
4453 phba->debug_writeApp = NULL;
4455 if (phba->debug_writeRef) {
4456 debugfs_remove(phba->debug_writeRef); /* writeRef */
4457 phba->debug_writeRef = NULL;
4459 if (phba->debug_readGuard) {
4460 debugfs_remove(phba->debug_readGuard); /* readGuard */
4461 phba->debug_readGuard = NULL;
4463 if (phba->debug_readApp) {
4464 debugfs_remove(phba->debug_readApp); /* readApp */
4465 phba->debug_readApp = NULL;
4467 if (phba->debug_readRef) {
4468 debugfs_remove(phba->debug_readRef); /* readRef */
4469 phba->debug_readRef = NULL;
4472 if (phba->slow_ring_trc) {
4473 kfree(phba->slow_ring_trc);
4474 phba->slow_ring_trc = NULL;
4476 if (phba->debug_slow_ring_trc) {
4477 /* slow_ring_trace */
4478 debugfs_remove(phba->debug_slow_ring_trc);
4479 phba->debug_slow_ring_trc = NULL;
4485 if (phba->sli_rev == LPFC_SLI_REV4) {
4486 if (phba->idiag_ext_acc) {
4488 debugfs_remove(phba->idiag_ext_acc);
4489 phba->idiag_ext_acc = NULL;
4491 if (phba->idiag_mbx_acc) {
4493 debugfs_remove(phba->idiag_mbx_acc);
4494 phba->idiag_mbx_acc = NULL;
4496 if (phba->idiag_ctl_acc) {
4498 debugfs_remove(phba->idiag_ctl_acc);
4499 phba->idiag_ctl_acc = NULL;
4501 if (phba->idiag_drb_acc) {
4503 debugfs_remove(phba->idiag_drb_acc);
4504 phba->idiag_drb_acc = NULL;
4506 if (phba->idiag_que_acc) {
4508 debugfs_remove(phba->idiag_que_acc);
4509 phba->idiag_que_acc = NULL;
4511 if (phba->idiag_que_info) {
4513 debugfs_remove(phba->idiag_que_info);
4514 phba->idiag_que_info = NULL;
4516 if (phba->idiag_bar_acc) {
4518 debugfs_remove(phba->idiag_bar_acc);
4519 phba->idiag_bar_acc = NULL;
4521 if (phba->idiag_pci_cfg) {
4523 debugfs_remove(phba->idiag_pci_cfg);
4524 phba->idiag_pci_cfg = NULL;
4527 /* Finally remove the iDiag debugfs root */
4528 if (phba->idiag_root) {
4530 debugfs_remove(phba->idiag_root);
4531 phba->idiag_root = NULL;
4535 if (phba->hba_debugfs_root) {
4536 debugfs_remove(phba->hba_debugfs_root); /* fnX */
4537 phba->hba_debugfs_root = NULL;
4538 atomic_dec(&lpfc_debugfs_hba_count);
4541 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4542 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4543 lpfc_debugfs_root = NULL;
4551 * Driver debug utility routines outside of debugfs. The debug utility
4552 * routines implemented here is intended to be used in the instrumented
4553 * debug driver for debugging host or port issues.
4557 * lpfc_debug_dump_all_queues - dump all the queues with a hba
4558 * @phba: Pointer to HBA context object.
4560 * This function dumps entries of all the queues asociated with the @phba.
4563 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
4568 * Dump Work Queues (WQs)
4570 lpfc_debug_dump_mbx_wq(phba);
4571 lpfc_debug_dump_els_wq(phba);
4573 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
4574 lpfc_debug_dump_fcp_wq(phba, fcp_wqidx);
4576 lpfc_debug_dump_hdr_rq(phba);
4577 lpfc_debug_dump_dat_rq(phba);
4579 * Dump Complete Queues (CQs)
4581 lpfc_debug_dump_mbx_cq(phba);
4582 lpfc_debug_dump_els_cq(phba);
4584 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
4585 lpfc_debug_dump_fcp_cq(phba, fcp_wqidx);
4588 * Dump Event Queues (EQs)
4590 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
4591 lpfc_debug_dump_hba_eq(phba, fcp_wqidx);