1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007 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/dma-mapping.h>
24 #include <linux/idr.h>
25 #include <linux/interrupt.h>
26 #include <linux/kthread.h>
27 #include <linux/pci.h>
28 #include <linux/spinlock.h>
29 #include <linux/ctype.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_transport_fc.h>
38 #include "lpfc_disc.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_vport.h"
44 #include "lpfc_version.h"
45 #include "lpfc_compat.h"
46 #include "lpfc_debugfs.h"
48 #ifdef CONFIG_LPFC_DEBUG_FS
51 * To access this interface the user should:
53 * # mount -t debugfs none /debug
55 * The lpfc debugfs directory hierachy is:
57 * where X is the lpfc hba unique_id
58 * where Y is the vport VPI on that hba
60 * Debugging services available per vport:
62 * This is an ACSII readable file that contains a trace of the last
63 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
64 * See lpfc_debugfs.h for different categories of
65 * discovery events. To enable the discovery trace, the following
66 * module parameters must be set:
67 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
68 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
69 * EACH vport. X MUST also be a power of 2.
70 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
73 static int lpfc_debugfs_enable = 1;
74 module_param(lpfc_debugfs_enable, int, 0);
75 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
77 /* This MUST be a power of 2 */
78 static int lpfc_debugfs_max_disc_trc;
79 module_param(lpfc_debugfs_max_disc_trc, int, 0);
80 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
81 "Set debugfs discovery trace depth");
83 /* This MUST be a power of 2 */
84 static int lpfc_debugfs_max_slow_ring_trc;
85 module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
86 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
87 "Set debugfs slow ring trace depth");
89 int lpfc_debugfs_mask_disc_trc;
90 module_param(lpfc_debugfs_mask_disc_trc, int, 0);
91 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
92 "Set debugfs discovery trace mask");
94 #include <linux/debugfs.h>
96 /* size of output line, for discovery_trace and slow_ring_trace */
97 #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
99 /* nodelist output buffer size */
100 #define LPFC_NODELIST_SIZE 8192
101 #define LPFC_NODELIST_ENTRY_SIZE 120
103 /* dumpHBASlim output buffer size */
104 #define LPFC_DUMPHBASLIM_SIZE 4096
106 /* dumpHostSlim output buffer size */
107 #define LPFC_DUMPHOSTSLIM_SIZE 4096
109 /* hbqinfo output buffer size */
110 #define LPFC_HBQINFO_SIZE 8192
117 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
118 static unsigned long lpfc_debugfs_start_time = 0L;
121 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
123 int i, index, len, enable;
125 struct lpfc_debugfs_trc *dtp;
126 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
129 enable = lpfc_debugfs_enable;
130 lpfc_debugfs_enable = 0;
133 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
134 (lpfc_debugfs_max_disc_trc - 1);
135 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
136 dtp = vport->disc_trc + i;
139 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
141 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
142 dtp->seq_cnt, ms, dtp->fmt);
143 len += snprintf(buf+len, size-len, buffer,
144 dtp->data1, dtp->data2, dtp->data3);
146 for (i = 0; i < index; i++) {
147 dtp = vport->disc_trc + i;
150 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
152 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
153 dtp->seq_cnt, ms, dtp->fmt);
154 len += snprintf(buf+len, size-len, buffer,
155 dtp->data1, dtp->data2, dtp->data3);
158 lpfc_debugfs_enable = enable;
163 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
165 int i, index, len, enable;
167 struct lpfc_debugfs_trc *dtp;
168 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
171 enable = lpfc_debugfs_enable;
172 lpfc_debugfs_enable = 0;
175 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
176 (lpfc_debugfs_max_slow_ring_trc - 1);
177 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
178 dtp = phba->slow_ring_trc + i;
181 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
183 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
184 dtp->seq_cnt, ms, dtp->fmt);
185 len += snprintf(buf+len, size-len, buffer,
186 dtp->data1, dtp->data2, dtp->data3);
188 for (i = 0; i < index; i++) {
189 dtp = phba->slow_ring_trc + i;
192 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
194 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
195 dtp->seq_cnt, ms, dtp->fmt);
196 len += snprintf(buf+len, size-len, buffer,
197 dtp->data1, dtp->data2, dtp->data3);
200 lpfc_debugfs_enable = enable;
204 static int lpfc_debugfs_last_hbq = -1;
207 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
210 int cnt, i, j, found, posted, low;
211 uint32_t phys, raw_index, getidx;
212 struct lpfc_hbq_init *hip;
214 struct lpfc_hbq_entry *hbqe;
215 struct lpfc_dmabuf *d_buf;
216 struct hbq_dmabuf *hbq_buf;
218 cnt = LPFC_HBQINFO_SIZE;
219 spin_lock_irq(&phba->hbalock);
221 /* toggle between multiple hbqs, if any */
222 i = lpfc_sli_hbq_count();
224 lpfc_debugfs_last_hbq++;
225 if (lpfc_debugfs_last_hbq >= i)
226 lpfc_debugfs_last_hbq = 0;
229 lpfc_debugfs_last_hbq = 0;
231 i = lpfc_debugfs_last_hbq;
233 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
235 hbqs = &phba->hbqs[i];
237 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
240 hip = lpfc_hbq_defs[i];
241 len += snprintf(buf+len, size-len,
242 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
243 hip->hbq_index, hip->profile, hip->rn,
244 hip->buffer_count, hip->init_count, hip->add_count, posted);
246 raw_index = phba->hbq_get[i];
247 getidx = le32_to_cpu(raw_index);
248 len += snprintf(buf+len, size-len,
249 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
250 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
251 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
253 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
254 for (j=0; j<hbqs->entry_count; j++) {
255 len += snprintf(buf+len, size-len,
256 "%03d: %08x %04x %05x ", j,
257 le32_to_cpu(hbqe->bde.addrLow),
258 le32_to_cpu(hbqe->bde.tus.w),
259 le32_to_cpu(hbqe->buffer_tag));
263 /* First calculate if slot has an associated posted buffer */
264 low = hbqs->hbqPutIdx - posted;
266 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
267 len += snprintf(buf+len, size-len, "Unused\n");
272 if ((j >= hbqs->hbqPutIdx) &&
273 (j < (hbqs->entry_count+low))) {
274 len += snprintf(buf+len, size-len, "Unused\n");
279 /* Get the Buffer info for the posted buffer */
280 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
281 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
282 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
283 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
284 len += snprintf(buf+len, size-len,
285 "Buf%d: %p %06x\n", i,
286 hbq_buf->dbuf.virt, hbq_buf->tag);
293 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
297 if (len > LPFC_HBQINFO_SIZE - 54)
300 spin_unlock_irq(&phba->hbalock);
304 static int lpfc_debugfs_last_hba_slim_off;
307 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
315 spin_lock_irq(&phba->hbalock);
317 len += snprintf(buf+len, size-len, "HBA SLIM\n");
318 lpfc_memcpy_from_slim(buffer,
319 ((uint8_t *)phba->MBslimaddr) + lpfc_debugfs_last_hba_slim_off,
322 ptr = (uint32_t *)&buffer[0];
323 off = lpfc_debugfs_last_hba_slim_off;
325 /* Set it up for the next time */
326 lpfc_debugfs_last_hba_slim_off += 1024;
327 if (lpfc_debugfs_last_hba_slim_off >= 4096)
328 lpfc_debugfs_last_hba_slim_off = 0;
332 len += snprintf(buf+len, size-len,
333 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
334 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
335 *(ptr+5), *(ptr+6), *(ptr+7));
337 i -= (8 * sizeof(uint32_t));
338 off += (8 * sizeof(uint32_t));
341 spin_unlock_irq(&phba->hbalock);
346 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
350 uint32_t word0, word1, word2, word3;
352 struct lpfc_pgp *pgpp;
353 struct lpfc_sli *psli = &phba->sli;
354 struct lpfc_sli_ring *pring;
357 spin_lock_irq(&phba->hbalock);
359 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
360 ptr = (uint32_t *)phba->slim2p;
361 i = sizeof(MAILBOX_t);
363 len += snprintf(buf+len, size-len,
364 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
365 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
366 *(ptr+5), *(ptr+6), *(ptr+7));
368 i -= (8 * sizeof(uint32_t));
369 off += (8 * sizeof(uint32_t));
372 len += snprintf(buf+len, size-len, "SLIM PCB\n");
373 ptr = (uint32_t *)&phba->slim2p->pcb;
376 len += snprintf(buf+len, size-len,
377 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
378 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
379 *(ptr+5), *(ptr+6), *(ptr+7));
381 i -= (8 * sizeof(uint32_t));
382 off += (8 * sizeof(uint32_t));
385 pgpp = (struct lpfc_pgp *)&phba->slim2p->mbx.us.s3_pgp.port;
386 pring = &psli->ring[0];
387 len += snprintf(buf+len, size-len,
388 "Ring 0: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
389 "RSP PutInx:%d Max:%d\n",
390 pgpp->cmdGetInx, pring->numCiocb,
391 pring->next_cmdidx, pring->local_getidx, pring->flag,
392 pgpp->rspPutInx, pring->numRiocb);
395 pring = &psli->ring[1];
396 len += snprintf(buf+len, size-len,
397 "Ring 1: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
398 "RSP PutInx:%d Max:%d\n",
399 pgpp->cmdGetInx, pring->numCiocb,
400 pring->next_cmdidx, pring->local_getidx, pring->flag,
401 pgpp->rspPutInx, pring->numRiocb);
404 pring = &psli->ring[2];
405 len += snprintf(buf+len, size-len,
406 "Ring 2: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
407 "RSP PutInx:%d Max:%d\n",
408 pgpp->cmdGetInx, pring->numCiocb,
409 pring->next_cmdidx, pring->local_getidx, pring->flag,
410 pgpp->rspPutInx, pring->numRiocb);
413 pring = &psli->ring[3];
414 len += snprintf(buf+len, size-len,
415 "Ring 3: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
416 "RSP PutInx:%d Max:%d\n",
417 pgpp->cmdGetInx, pring->numCiocb,
418 pring->next_cmdidx, pring->local_getidx, pring->flag,
419 pgpp->rspPutInx, pring->numRiocb);
422 ptr = (uint32_t *)&phba->slim2p->mbx.us.s3_pgp.hbq_get;
423 word0 = readl(phba->HAregaddr);
424 word1 = readl(phba->CAregaddr);
425 word2 = readl(phba->HSregaddr);
426 word3 = readl(phba->HCregaddr);
427 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n",
428 word0, word1, word2, word3);
429 spin_unlock_irq(&phba->hbalock);
434 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
438 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
439 struct lpfc_nodelist *ndlp;
440 unsigned char *statep, *name;
442 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
444 spin_lock_irq(shost->host_lock);
445 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
447 len += snprintf(buf+len, size-len,
448 "Missing Nodelist Entries\n");
452 switch (ndlp->nlp_state) {
453 case NLP_STE_UNUSED_NODE:
456 case NLP_STE_PLOGI_ISSUE:
459 case NLP_STE_ADISC_ISSUE:
462 case NLP_STE_REG_LOGIN_ISSUE:
465 case NLP_STE_PRLI_ISSUE:
468 case NLP_STE_UNMAPPED_NODE:
471 case NLP_STE_MAPPED_NODE:
474 case NLP_STE_NPR_NODE:
480 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
481 statep, ndlp->nlp_DID);
482 name = (unsigned char *)&ndlp->nlp_portname;
483 len += snprintf(buf+len, size-len,
484 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
485 *name, *(name+1), *(name+2), *(name+3),
486 *(name+4), *(name+5), *(name+6), *(name+7));
487 name = (unsigned char *)&ndlp->nlp_nodename;
488 len += snprintf(buf+len, size-len,
489 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
490 *name, *(name+1), *(name+2), *(name+3),
491 *(name+4), *(name+5), *(name+6), *(name+7));
492 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
493 ndlp->nlp_rpi, ndlp->nlp_flag);
495 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
496 if (ndlp->nlp_type & NLP_FC_NODE)
497 len += snprintf(buf+len, size-len, "FC_NODE ");
498 if (ndlp->nlp_type & NLP_FABRIC)
499 len += snprintf(buf+len, size-len, "FABRIC ");
500 if (ndlp->nlp_type & NLP_FCP_TARGET)
501 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
503 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
504 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
505 len += snprintf(buf+len, size-len, "usgmap:%x ",
507 len += snprintf(buf+len, size-len, "refcnt:%x",
508 atomic_read(&ndlp->kref.refcount));
509 len += snprintf(buf+len, size-len, "\n");
511 spin_unlock_irq(shost->host_lock);
518 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
519 uint32_t data1, uint32_t data2, uint32_t data3)
521 #ifdef CONFIG_LPFC_DEBUG_FS
522 struct lpfc_debugfs_trc *dtp;
525 if (!(lpfc_debugfs_mask_disc_trc & mask))
528 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
529 !vport || !vport->disc_trc)
532 index = atomic_inc_return(&vport->disc_trc_cnt) &
533 (lpfc_debugfs_max_disc_trc - 1);
534 dtp = vport->disc_trc + index;
539 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
546 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
547 uint32_t data1, uint32_t data2, uint32_t data3)
549 #ifdef CONFIG_LPFC_DEBUG_FS
550 struct lpfc_debugfs_trc *dtp;
553 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
554 !phba || !phba->slow_ring_trc)
557 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
558 (lpfc_debugfs_max_slow_ring_trc - 1);
559 dtp = phba->slow_ring_trc + index;
564 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
570 #ifdef CONFIG_LPFC_DEBUG_FS
572 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
574 struct lpfc_vport *vport = inode->i_private;
575 struct lpfc_debug *debug;
579 if (!lpfc_debugfs_max_disc_trc) {
584 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
588 /* Round to page boundry */
589 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
590 size = PAGE_ALIGN(size);
592 debug->buffer = kmalloc(size, GFP_KERNEL);
593 if (!debug->buffer) {
598 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
599 file->private_data = debug;
607 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
609 struct lpfc_hba *phba = inode->i_private;
610 struct lpfc_debug *debug;
614 if (!lpfc_debugfs_max_slow_ring_trc) {
619 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
623 /* Round to page boundry */
624 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
625 size = PAGE_ALIGN(size);
627 debug->buffer = kmalloc(size, GFP_KERNEL);
628 if (!debug->buffer) {
633 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
634 file->private_data = debug;
642 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
644 struct lpfc_hba *phba = inode->i_private;
645 struct lpfc_debug *debug;
648 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
652 /* Round to page boundry */
653 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
654 if (!debug->buffer) {
659 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
661 file->private_data = debug;
669 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
671 struct lpfc_hba *phba = inode->i_private;
672 struct lpfc_debug *debug;
675 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
679 /* Round to page boundry */
680 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
681 if (!debug->buffer) {
686 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
687 LPFC_DUMPHBASLIM_SIZE);
688 file->private_data = debug;
696 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
698 struct lpfc_hba *phba = inode->i_private;
699 struct lpfc_debug *debug;
702 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
706 /* Round to page boundry */
707 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
708 if (!debug->buffer) {
713 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
714 LPFC_DUMPHOSTSLIM_SIZE);
715 file->private_data = debug;
723 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
725 struct lpfc_vport *vport = inode->i_private;
726 struct lpfc_debug *debug;
729 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
733 /* Round to page boundry */
734 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
735 if (!debug->buffer) {
740 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
742 file->private_data = debug;
750 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
752 struct lpfc_debug *debug;
755 debug = file->private_data;
762 pos = file->f_pos + off;
765 pos = debug->len - off;
767 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
771 lpfc_debugfs_read(struct file *file, char __user *buf,
772 size_t nbytes, loff_t *ppos)
774 struct lpfc_debug *debug = file->private_data;
775 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
780 lpfc_debugfs_release(struct inode *inode, struct file *file)
782 struct lpfc_debug *debug = file->private_data;
784 kfree(debug->buffer);
790 #undef lpfc_debugfs_op_disc_trc
791 static struct file_operations lpfc_debugfs_op_disc_trc = {
792 .owner = THIS_MODULE,
793 .open = lpfc_debugfs_disc_trc_open,
794 .llseek = lpfc_debugfs_lseek,
795 .read = lpfc_debugfs_read,
796 .release = lpfc_debugfs_release,
799 #undef lpfc_debugfs_op_nodelist
800 static struct file_operations lpfc_debugfs_op_nodelist = {
801 .owner = THIS_MODULE,
802 .open = lpfc_debugfs_nodelist_open,
803 .llseek = lpfc_debugfs_lseek,
804 .read = lpfc_debugfs_read,
805 .release = lpfc_debugfs_release,
808 #undef lpfc_debugfs_op_hbqinfo
809 static struct file_operations lpfc_debugfs_op_hbqinfo = {
810 .owner = THIS_MODULE,
811 .open = lpfc_debugfs_hbqinfo_open,
812 .llseek = lpfc_debugfs_lseek,
813 .read = lpfc_debugfs_read,
814 .release = lpfc_debugfs_release,
817 #undef lpfc_debugfs_op_dumpHBASlim
818 static struct file_operations lpfc_debugfs_op_dumpHBASlim = {
819 .owner = THIS_MODULE,
820 .open = lpfc_debugfs_dumpHBASlim_open,
821 .llseek = lpfc_debugfs_lseek,
822 .read = lpfc_debugfs_read,
823 .release = lpfc_debugfs_release,
826 #undef lpfc_debugfs_op_dumpHostSlim
827 static struct file_operations lpfc_debugfs_op_dumpHostSlim = {
828 .owner = THIS_MODULE,
829 .open = lpfc_debugfs_dumpHostSlim_open,
830 .llseek = lpfc_debugfs_lseek,
831 .read = lpfc_debugfs_read,
832 .release = lpfc_debugfs_release,
835 #undef lpfc_debugfs_op_slow_ring_trc
836 static struct file_operations lpfc_debugfs_op_slow_ring_trc = {
837 .owner = THIS_MODULE,
838 .open = lpfc_debugfs_slow_ring_trc_open,
839 .llseek = lpfc_debugfs_lseek,
840 .read = lpfc_debugfs_read,
841 .release = lpfc_debugfs_release,
844 static struct dentry *lpfc_debugfs_root = NULL;
845 static atomic_t lpfc_debugfs_hba_count;
849 lpfc_debugfs_initialize(struct lpfc_vport *vport)
851 #ifdef CONFIG_LPFC_DEBUG_FS
852 struct lpfc_hba *phba = vport->phba;
856 if (!lpfc_debugfs_enable)
859 /* Setup lpfc root directory */
860 if (!lpfc_debugfs_root) {
861 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
862 atomic_set(&lpfc_debugfs_hba_count, 0);
863 if (!lpfc_debugfs_root) {
864 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
865 "0409 Cannot create debugfs root\n");
869 if (!lpfc_debugfs_start_time)
870 lpfc_debugfs_start_time = jiffies;
872 /* Setup lpfcX directory for specific HBA */
873 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
874 if (!phba->hba_debugfs_root) {
875 phba->hba_debugfs_root =
876 debugfs_create_dir(name, lpfc_debugfs_root);
877 if (!phba->hba_debugfs_root) {
878 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
879 "0409 Cannot create debugfs hba\n");
882 atomic_inc(&lpfc_debugfs_hba_count);
883 atomic_set(&phba->debugfs_vport_count, 0);
886 snprintf(name, sizeof(name), "hbqinfo");
887 phba->debug_hbqinfo =
888 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
889 phba->hba_debugfs_root,
890 phba, &lpfc_debugfs_op_hbqinfo);
891 if (!phba->debug_hbqinfo) {
892 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
893 "0409 Cannot create debugfs hbqinfo\n");
897 /* Setup dumpHBASlim */
898 snprintf(name, sizeof(name), "dumpHBASlim");
899 phba->debug_dumpHBASlim =
900 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
901 phba->hba_debugfs_root,
902 phba, &lpfc_debugfs_op_dumpHBASlim);
903 if (!phba->debug_dumpHBASlim) {
904 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
905 "0409 Cannot create debugfs dumpHBASlim\n");
909 /* Setup dumpHostSlim */
910 snprintf(name, sizeof(name), "dumpHostSlim");
911 phba->debug_dumpHostSlim =
912 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
913 phba->hba_debugfs_root,
914 phba, &lpfc_debugfs_op_dumpHostSlim);
915 if (!phba->debug_dumpHostSlim) {
916 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
917 "0409 Cannot create debugfs dumpHostSlim\n");
921 /* Setup slow ring trace */
922 if (lpfc_debugfs_max_slow_ring_trc) {
923 num = lpfc_debugfs_max_slow_ring_trc - 1;
924 if (num & lpfc_debugfs_max_slow_ring_trc) {
925 /* Change to be a power of 2 */
926 num = lpfc_debugfs_max_slow_ring_trc;
932 lpfc_debugfs_max_slow_ring_trc = (1 << i);
934 "lpfc_debugfs_max_disc_trc changed to "
935 "%d\n", lpfc_debugfs_max_disc_trc);
940 snprintf(name, sizeof(name), "slow_ring_trace");
941 phba->debug_slow_ring_trc =
942 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
943 phba->hba_debugfs_root,
944 phba, &lpfc_debugfs_op_slow_ring_trc);
945 if (!phba->debug_slow_ring_trc) {
946 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
947 "0409 Cannot create debugfs "
948 "slow_ring_trace\n");
951 if (!phba->slow_ring_trc) {
952 phba->slow_ring_trc = kmalloc(
953 (sizeof(struct lpfc_debugfs_trc) *
954 lpfc_debugfs_max_slow_ring_trc),
956 if (!phba->slow_ring_trc) {
957 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
958 "0409 Cannot create debugfs "
959 "slow_ring buffer\n");
962 atomic_set(&phba->slow_ring_trc_cnt, 0);
963 memset(phba->slow_ring_trc, 0,
964 (sizeof(struct lpfc_debugfs_trc) *
965 lpfc_debugfs_max_slow_ring_trc));
969 snprintf(name, sizeof(name), "vport%d", vport->vpi);
970 if (!vport->vport_debugfs_root) {
971 vport->vport_debugfs_root =
972 debugfs_create_dir(name, phba->hba_debugfs_root);
973 if (!vport->vport_debugfs_root) {
974 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
975 "0409 Cant create debugfs");
978 atomic_inc(&phba->debugfs_vport_count);
981 if (lpfc_debugfs_max_disc_trc) {
982 num = lpfc_debugfs_max_disc_trc - 1;
983 if (num & lpfc_debugfs_max_disc_trc) {
984 /* Change to be a power of 2 */
985 num = lpfc_debugfs_max_disc_trc;
991 lpfc_debugfs_max_disc_trc = (1 << i);
993 "lpfc_debugfs_max_disc_trc changed to %d\n",
994 lpfc_debugfs_max_disc_trc);
998 vport->disc_trc = kzalloc(
999 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
1002 if (!vport->disc_trc) {
1003 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1004 "0409 Cannot create debugfs disc trace "
1008 atomic_set(&vport->disc_trc_cnt, 0);
1010 snprintf(name, sizeof(name), "discovery_trace");
1011 vport->debug_disc_trc =
1012 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1013 vport->vport_debugfs_root,
1014 vport, &lpfc_debugfs_op_disc_trc);
1015 if (!vport->debug_disc_trc) {
1016 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1017 "0409 Cannot create debugfs "
1018 "discovery_trace\n");
1021 snprintf(name, sizeof(name), "nodelist");
1022 vport->debug_nodelist =
1023 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1024 vport->vport_debugfs_root,
1025 vport, &lpfc_debugfs_op_nodelist);
1026 if (!vport->debug_nodelist) {
1027 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1028 "0409 Cant create debugfs nodelist");
1038 lpfc_debugfs_terminate(struct lpfc_vport *vport)
1040 #ifdef CONFIG_LPFC_DEBUG_FS
1041 struct lpfc_hba *phba = vport->phba;
1043 if (vport->disc_trc) {
1044 kfree(vport->disc_trc);
1045 vport->disc_trc = NULL;
1047 if (vport->debug_disc_trc) {
1048 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
1049 vport->debug_disc_trc = NULL;
1051 if (vport->debug_nodelist) {
1052 debugfs_remove(vport->debug_nodelist); /* nodelist */
1053 vport->debug_nodelist = NULL;
1056 if (vport->vport_debugfs_root) {
1057 debugfs_remove(vport->vport_debugfs_root); /* vportX */
1058 vport->vport_debugfs_root = NULL;
1059 atomic_dec(&phba->debugfs_vport_count);
1061 if (atomic_read(&phba->debugfs_vport_count) == 0) {
1063 if (phba->debug_hbqinfo) {
1064 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
1065 phba->debug_hbqinfo = NULL;
1067 if (phba->debug_dumpHBASlim) {
1068 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
1069 phba->debug_dumpHBASlim = NULL;
1071 if (phba->debug_dumpHostSlim) {
1072 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
1073 phba->debug_dumpHostSlim = NULL;
1075 if (phba->slow_ring_trc) {
1076 kfree(phba->slow_ring_trc);
1077 phba->slow_ring_trc = NULL;
1079 if (phba->debug_slow_ring_trc) {
1080 /* slow_ring_trace */
1081 debugfs_remove(phba->debug_slow_ring_trc);
1082 phba->debug_slow_ring_trc = NULL;
1085 if (phba->hba_debugfs_root) {
1086 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
1087 phba->hba_debugfs_root = NULL;
1088 atomic_dec(&lpfc_debugfs_hba_count);
1091 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
1092 debugfs_remove(lpfc_debugfs_root); /* lpfc */
1093 lpfc_debugfs_root = NULL;