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>
30 #include <linux/version.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_version.h"
46 #include "lpfc_compat.h"
47 #include "lpfc_debugfs.h"
49 #ifdef CONFIG_LPFC_DEBUG_FS
52 * To access this interface the user should:
54 * # mount -t debugfs none /debug
56 * The lpfc debugfs directory hierachy is:
58 * where X is the lpfc hba unique_id
59 * where Y is the vport VPI on that hba
61 * Debugging services available per vport:
63 * This is an ACSII readable file that contains a trace of the last
64 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
65 * See lpfc_debugfs.h for different categories of
66 * discovery events. To enable the discovery trace, the following
67 * module parameters must be set:
68 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
69 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
70 * EACH vport. X MUST also be a power of 2.
71 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
74 static int lpfc_debugfs_enable = 1;
75 module_param(lpfc_debugfs_enable, int, 0);
76 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
78 /* This MUST be a power of 2 */
79 static int lpfc_debugfs_max_disc_trc;
80 module_param(lpfc_debugfs_max_disc_trc, int, 0);
81 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
82 "Set debugfs discovery trace depth");
84 /* This MUST be a power of 2 */
85 static int lpfc_debugfs_max_slow_ring_trc;
86 module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
87 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
88 "Set debugfs slow ring trace depth");
90 int lpfc_debugfs_mask_disc_trc;
91 module_param(lpfc_debugfs_mask_disc_trc, int, 0);
92 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
93 "Set debugfs discovery trace mask");
95 #include <linux/debugfs.h>
97 /* size of output line, for discovery_trace and slow_ring_trace */
98 #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
100 /* nodelist output buffer size */
101 #define LPFC_NODELIST_SIZE 8192
102 #define LPFC_NODELIST_ENTRY_SIZE 120
104 /* dumpHBASlim output buffer size */
105 #define LPFC_DUMPHBASLIM_SIZE 4096
107 /* dumpHostSlim output buffer size */
108 #define LPFC_DUMPHOSTSLIM_SIZE 4096
110 /* hbqinfo output buffer size */
111 #define LPFC_HBQINFO_SIZE 8192
118 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
119 static unsigned long lpfc_debugfs_start_time = 0L;
122 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
124 int i, index, len, enable;
126 struct lpfc_debugfs_trc *dtp;
127 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
130 enable = lpfc_debugfs_enable;
131 lpfc_debugfs_enable = 0;
134 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
135 (lpfc_debugfs_max_disc_trc - 1);
136 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
137 dtp = vport->disc_trc + i;
140 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
142 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
143 dtp->seq_cnt, ms, dtp->fmt);
144 len += snprintf(buf+len, size-len, buffer,
145 dtp->data1, dtp->data2, dtp->data3);
147 for (i = 0; i < index; i++) {
148 dtp = vport->disc_trc + i;
151 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
153 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
154 dtp->seq_cnt, ms, dtp->fmt);
155 len += snprintf(buf+len, size-len, buffer,
156 dtp->data1, dtp->data2, dtp->data3);
159 lpfc_debugfs_enable = enable;
164 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
166 int i, index, len, enable;
168 struct lpfc_debugfs_trc *dtp;
169 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
172 enable = lpfc_debugfs_enable;
173 lpfc_debugfs_enable = 0;
176 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
177 (lpfc_debugfs_max_slow_ring_trc - 1);
178 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
179 dtp = phba->slow_ring_trc + i;
182 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
184 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
185 dtp->seq_cnt, ms, dtp->fmt);
186 len += snprintf(buf+len, size-len, buffer,
187 dtp->data1, dtp->data2, dtp->data3);
189 for (i = 0; i < index; i++) {
190 dtp = phba->slow_ring_trc + i;
193 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
195 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
196 dtp->seq_cnt, ms, dtp->fmt);
197 len += snprintf(buf+len, size-len, buffer,
198 dtp->data1, dtp->data2, dtp->data3);
201 lpfc_debugfs_enable = enable;
205 static int lpfc_debugfs_last_hbq = -1;
208 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
211 int cnt, i, j, found, posted, low;
212 uint32_t phys, raw_index, getidx;
213 struct lpfc_hbq_init *hip;
215 struct lpfc_hbq_entry *hbqe;
216 struct lpfc_dmabuf *d_buf;
217 struct hbq_dmabuf *hbq_buf;
219 cnt = LPFC_HBQINFO_SIZE;
220 spin_lock_irq(&phba->hbalock);
222 /* toggle between multiple hbqs, if any */
223 i = lpfc_sli_hbq_count();
225 lpfc_debugfs_last_hbq++;
226 if (lpfc_debugfs_last_hbq >= i)
227 lpfc_debugfs_last_hbq = 0;
230 lpfc_debugfs_last_hbq = 0;
232 i = lpfc_debugfs_last_hbq;
234 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
236 hbqs = &phba->hbqs[i];
238 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
241 hip = lpfc_hbq_defs[i];
242 len += snprintf(buf+len, size-len,
243 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
244 hip->hbq_index, hip->profile, hip->rn,
245 hip->buffer_count, hip->init_count, hip->add_count, posted);
247 raw_index = phba->hbq_get[i];
248 getidx = le32_to_cpu(raw_index);
249 len += snprintf(buf+len, size-len,
250 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
251 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
252 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
254 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
255 for (j=0; j<hbqs->entry_count; j++) {
256 len += snprintf(buf+len, size-len,
257 "%03d: %08x %04x %05x ", j,
258 le32_to_cpu(hbqe->bde.addrLow),
259 le32_to_cpu(hbqe->bde.tus.w),
260 le32_to_cpu(hbqe->buffer_tag));
264 /* First calculate if slot has an associated posted buffer */
265 low = hbqs->hbqPutIdx - posted;
267 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
268 len += snprintf(buf+len, size-len, "Unused\n");
273 if ((j >= hbqs->hbqPutIdx) &&
274 (j < (hbqs->entry_count+low))) {
275 len += snprintf(buf+len, size-len, "Unused\n");
280 /* Get the Buffer info for the posted buffer */
281 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
282 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
283 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
284 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
285 len += snprintf(buf+len, size-len,
286 "Buf%d: %p %06x\n", i,
287 hbq_buf->dbuf.virt, hbq_buf->tag);
294 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
298 if (len > LPFC_HBQINFO_SIZE - 54)
301 spin_unlock_irq(&phba->hbalock);
305 static int lpfc_debugfs_last_hba_slim_off;
308 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
316 spin_lock_irq(&phba->hbalock);
318 len += snprintf(buf+len, size-len, "HBA SLIM\n");
319 lpfc_memcpy_from_slim(buffer,
320 ((uint8_t *)phba->MBslimaddr) + lpfc_debugfs_last_hba_slim_off,
323 ptr = (uint32_t *)&buffer[0];
324 off = lpfc_debugfs_last_hba_slim_off;
326 /* Set it up for the next time */
327 lpfc_debugfs_last_hba_slim_off += 1024;
328 if (lpfc_debugfs_last_hba_slim_off >= 4096)
329 lpfc_debugfs_last_hba_slim_off = 0;
333 len += snprintf(buf+len, size-len,
334 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
335 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
336 *(ptr+5), *(ptr+6), *(ptr+7));
338 i -= (8 * sizeof(uint32_t));
339 off += (8 * sizeof(uint32_t));
342 spin_unlock_irq(&phba->hbalock);
347 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
351 uint32_t word0, word1, word2, word3;
353 struct lpfc_pgp *pgpp;
354 struct lpfc_sli *psli = &phba->sli;
355 struct lpfc_sli_ring *pring;
358 spin_lock_irq(&phba->hbalock);
360 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
361 ptr = (uint32_t *)phba->slim2p;
362 i = sizeof(MAILBOX_t);
364 len += snprintf(buf+len, size-len,
365 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
366 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
367 *(ptr+5), *(ptr+6), *(ptr+7));
369 i -= (8 * sizeof(uint32_t));
370 off += (8 * sizeof(uint32_t));
373 len += snprintf(buf+len, size-len, "SLIM PCB\n");
374 ptr = (uint32_t *)&phba->slim2p->pcb;
377 len += snprintf(buf+len, size-len,
378 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
379 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
380 *(ptr+5), *(ptr+6), *(ptr+7));
382 i -= (8 * sizeof(uint32_t));
383 off += (8 * sizeof(uint32_t));
386 pgpp = (struct lpfc_pgp *)&phba->slim2p->mbx.us.s3_pgp.port;
387 pring = &psli->ring[0];
388 len += snprintf(buf+len, size-len,
389 "Ring 0: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
390 "RSP PutInx:%d Max:%d\n",
391 pgpp->cmdGetInx, pring->numCiocb,
392 pring->next_cmdidx, pring->local_getidx, pring->flag,
393 pgpp->rspPutInx, pring->numRiocb);
396 pring = &psli->ring[1];
397 len += snprintf(buf+len, size-len,
398 "Ring 1: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
399 "RSP PutInx:%d Max:%d\n",
400 pgpp->cmdGetInx, pring->numCiocb,
401 pring->next_cmdidx, pring->local_getidx, pring->flag,
402 pgpp->rspPutInx, pring->numRiocb);
405 pring = &psli->ring[2];
406 len += snprintf(buf+len, size-len,
407 "Ring 2: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
408 "RSP PutInx:%d Max:%d\n",
409 pgpp->cmdGetInx, pring->numCiocb,
410 pring->next_cmdidx, pring->local_getidx, pring->flag,
411 pgpp->rspPutInx, pring->numRiocb);
414 pring = &psli->ring[3];
415 len += snprintf(buf+len, size-len,
416 "Ring 3: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
417 "RSP PutInx:%d Max:%d\n",
418 pgpp->cmdGetInx, pring->numCiocb,
419 pring->next_cmdidx, pring->local_getidx, pring->flag,
420 pgpp->rspPutInx, pring->numRiocb);
423 ptr = (uint32_t *)&phba->slim2p->mbx.us.s3_pgp.hbq_get;
424 word0 = readl(phba->HAregaddr);
425 word1 = readl(phba->CAregaddr);
426 word2 = readl(phba->HSregaddr);
427 word3 = readl(phba->HCregaddr);
428 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n",
429 word0, word1, word2, word3);
430 spin_unlock_irq(&phba->hbalock);
435 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
439 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
440 struct lpfc_nodelist *ndlp;
441 unsigned char *statep, *name;
443 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
445 spin_lock_irq(shost->host_lock);
446 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
448 len += snprintf(buf+len, size-len,
449 "Missing Nodelist Entries\n");
453 switch (ndlp->nlp_state) {
454 case NLP_STE_UNUSED_NODE:
457 case NLP_STE_PLOGI_ISSUE:
460 case NLP_STE_ADISC_ISSUE:
463 case NLP_STE_REG_LOGIN_ISSUE:
466 case NLP_STE_PRLI_ISSUE:
469 case NLP_STE_UNMAPPED_NODE:
472 case NLP_STE_MAPPED_NODE:
475 case NLP_STE_NPR_NODE:
481 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
482 statep, ndlp->nlp_DID);
483 name = (unsigned char *)&ndlp->nlp_portname;
484 len += snprintf(buf+len, size-len,
485 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
486 *name, *(name+1), *(name+2), *(name+3),
487 *(name+4), *(name+5), *(name+6), *(name+7));
488 name = (unsigned char *)&ndlp->nlp_nodename;
489 len += snprintf(buf+len, size-len,
490 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
491 *name, *(name+1), *(name+2), *(name+3),
492 *(name+4), *(name+5), *(name+6), *(name+7));
493 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
494 ndlp->nlp_rpi, ndlp->nlp_flag);
496 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
497 if (ndlp->nlp_type & NLP_FC_NODE)
498 len += snprintf(buf+len, size-len, "FC_NODE ");
499 if (ndlp->nlp_type & NLP_FABRIC)
500 len += snprintf(buf+len, size-len, "FABRIC ");
501 if (ndlp->nlp_type & NLP_FCP_TARGET)
502 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
504 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
505 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
506 len += snprintf(buf+len, size-len, "usgmap:%x ",
508 len += snprintf(buf+len, size-len, "refcnt:%x",
509 atomic_read(&ndlp->kref.refcount));
510 len += snprintf(buf+len, size-len, "\n");
512 spin_unlock_irq(shost->host_lock);
519 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
520 uint32_t data1, uint32_t data2, uint32_t data3)
522 #ifdef CONFIG_LPFC_DEBUG_FS
523 struct lpfc_debugfs_trc *dtp;
526 if (!(lpfc_debugfs_mask_disc_trc & mask))
529 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
530 !vport || !vport->disc_trc)
533 index = atomic_inc_return(&vport->disc_trc_cnt) &
534 (lpfc_debugfs_max_disc_trc - 1);
535 dtp = vport->disc_trc + index;
540 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
547 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
548 uint32_t data1, uint32_t data2, uint32_t data3)
550 #ifdef CONFIG_LPFC_DEBUG_FS
551 struct lpfc_debugfs_trc *dtp;
554 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
555 !phba || !phba->slow_ring_trc)
558 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
559 (lpfc_debugfs_max_slow_ring_trc - 1);
560 dtp = phba->slow_ring_trc + index;
565 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
571 #ifdef CONFIG_LPFC_DEBUG_FS
573 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
575 struct lpfc_vport *vport = inode->i_private;
576 struct lpfc_debug *debug;
580 if (!lpfc_debugfs_max_disc_trc) {
585 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
589 /* Round to page boundry */
590 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
591 size = PAGE_ALIGN(size);
593 debug->buffer = kmalloc(size, GFP_KERNEL);
594 if (!debug->buffer) {
599 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
600 file->private_data = debug;
608 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
610 struct lpfc_hba *phba = inode->i_private;
611 struct lpfc_debug *debug;
615 if (!lpfc_debugfs_max_slow_ring_trc) {
620 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
624 /* Round to page boundry */
625 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
626 size = PAGE_ALIGN(size);
628 debug->buffer = kmalloc(size, GFP_KERNEL);
629 if (!debug->buffer) {
634 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
635 file->private_data = debug;
643 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
645 struct lpfc_hba *phba = inode->i_private;
646 struct lpfc_debug *debug;
649 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
653 /* Round to page boundry */
654 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
655 if (!debug->buffer) {
660 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
662 file->private_data = debug;
670 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
672 struct lpfc_hba *phba = inode->i_private;
673 struct lpfc_debug *debug;
676 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
680 /* Round to page boundry */
681 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
682 if (!debug->buffer) {
687 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
688 LPFC_DUMPHBASLIM_SIZE);
689 file->private_data = debug;
697 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
699 struct lpfc_hba *phba = inode->i_private;
700 struct lpfc_debug *debug;
703 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
707 /* Round to page boundry */
708 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
709 if (!debug->buffer) {
714 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
715 LPFC_DUMPHOSTSLIM_SIZE);
716 file->private_data = debug;
724 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
726 struct lpfc_vport *vport = inode->i_private;
727 struct lpfc_debug *debug;
730 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
734 /* Round to page boundry */
735 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
736 if (!debug->buffer) {
741 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
743 file->private_data = debug;
751 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
753 struct lpfc_debug *debug;
756 debug = file->private_data;
763 pos = file->f_pos + off;
766 pos = debug->len - off;
768 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
772 lpfc_debugfs_read(struct file *file, char __user *buf,
773 size_t nbytes, loff_t *ppos)
775 struct lpfc_debug *debug = file->private_data;
776 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
781 lpfc_debugfs_release(struct inode *inode, struct file *file)
783 struct lpfc_debug *debug = file->private_data;
785 kfree(debug->buffer);
791 #undef lpfc_debugfs_op_disc_trc
792 static struct file_operations lpfc_debugfs_op_disc_trc = {
793 .owner = THIS_MODULE,
794 .open = lpfc_debugfs_disc_trc_open,
795 .llseek = lpfc_debugfs_lseek,
796 .read = lpfc_debugfs_read,
797 .release = lpfc_debugfs_release,
800 #undef lpfc_debugfs_op_nodelist
801 static struct file_operations lpfc_debugfs_op_nodelist = {
802 .owner = THIS_MODULE,
803 .open = lpfc_debugfs_nodelist_open,
804 .llseek = lpfc_debugfs_lseek,
805 .read = lpfc_debugfs_read,
806 .release = lpfc_debugfs_release,
809 #undef lpfc_debugfs_op_hbqinfo
810 static struct file_operations lpfc_debugfs_op_hbqinfo = {
811 .owner = THIS_MODULE,
812 .open = lpfc_debugfs_hbqinfo_open,
813 .llseek = lpfc_debugfs_lseek,
814 .read = lpfc_debugfs_read,
815 .release = lpfc_debugfs_release,
818 #undef lpfc_debugfs_op_dumpHBASlim
819 static struct file_operations lpfc_debugfs_op_dumpHBASlim = {
820 .owner = THIS_MODULE,
821 .open = lpfc_debugfs_dumpHBASlim_open,
822 .llseek = lpfc_debugfs_lseek,
823 .read = lpfc_debugfs_read,
824 .release = lpfc_debugfs_release,
827 #undef lpfc_debugfs_op_dumpHostSlim
828 static struct file_operations lpfc_debugfs_op_dumpHostSlim = {
829 .owner = THIS_MODULE,
830 .open = lpfc_debugfs_dumpHostSlim_open,
831 .llseek = lpfc_debugfs_lseek,
832 .read = lpfc_debugfs_read,
833 .release = lpfc_debugfs_release,
836 #undef lpfc_debugfs_op_slow_ring_trc
837 static struct file_operations lpfc_debugfs_op_slow_ring_trc = {
838 .owner = THIS_MODULE,
839 .open = lpfc_debugfs_slow_ring_trc_open,
840 .llseek = lpfc_debugfs_lseek,
841 .read = lpfc_debugfs_read,
842 .release = lpfc_debugfs_release,
845 static struct dentry *lpfc_debugfs_root = NULL;
846 static atomic_t lpfc_debugfs_hba_count;
850 lpfc_debugfs_initialize(struct lpfc_vport *vport)
852 #ifdef CONFIG_LPFC_DEBUG_FS
853 struct lpfc_hba *phba = vport->phba;
857 if (!lpfc_debugfs_enable)
860 /* Setup lpfc root directory */
861 if (!lpfc_debugfs_root) {
862 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
863 atomic_set(&lpfc_debugfs_hba_count, 0);
864 if (!lpfc_debugfs_root) {
865 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
866 "0409 Cannot create debugfs root\n");
870 if (!lpfc_debugfs_start_time)
871 lpfc_debugfs_start_time = jiffies;
873 /* Setup lpfcX directory for specific HBA */
874 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
875 if (!phba->hba_debugfs_root) {
876 phba->hba_debugfs_root =
877 debugfs_create_dir(name, lpfc_debugfs_root);
878 if (!phba->hba_debugfs_root) {
879 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
880 "0409 Cannot create debugfs hba\n");
883 atomic_inc(&lpfc_debugfs_hba_count);
884 atomic_set(&phba->debugfs_vport_count, 0);
887 snprintf(name, sizeof(name), "hbqinfo");
888 phba->debug_hbqinfo =
889 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
890 phba->hba_debugfs_root,
891 phba, &lpfc_debugfs_op_hbqinfo);
892 if (!phba->debug_hbqinfo) {
893 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
894 "0409 Cannot create debugfs hbqinfo\n");
898 /* Setup dumpHBASlim */
899 snprintf(name, sizeof(name), "dumpHBASlim");
900 phba->debug_dumpHBASlim =
901 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
902 phba->hba_debugfs_root,
903 phba, &lpfc_debugfs_op_dumpHBASlim);
904 if (!phba->debug_dumpHBASlim) {
905 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
906 "0409 Cannot create debugfs dumpHBASlim\n");
910 /* Setup dumpHostSlim */
911 snprintf(name, sizeof(name), "dumpHostSlim");
912 phba->debug_dumpHostSlim =
913 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
914 phba->hba_debugfs_root,
915 phba, &lpfc_debugfs_op_dumpHostSlim);
916 if (!phba->debug_dumpHostSlim) {
917 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
918 "0409 Cannot create debugfs dumpHostSlim\n");
922 /* Setup slow ring trace */
923 if (lpfc_debugfs_max_slow_ring_trc) {
924 num = lpfc_debugfs_max_slow_ring_trc - 1;
925 if (num & lpfc_debugfs_max_slow_ring_trc) {
926 /* Change to be a power of 2 */
927 num = lpfc_debugfs_max_slow_ring_trc;
933 lpfc_debugfs_max_slow_ring_trc = (1 << i);
935 "lpfc_debugfs_max_disc_trc changed to "
936 "%d\n", lpfc_debugfs_max_disc_trc);
941 snprintf(name, sizeof(name), "slow_ring_trace");
942 phba->debug_slow_ring_trc =
943 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
944 phba->hba_debugfs_root,
945 phba, &lpfc_debugfs_op_slow_ring_trc);
946 if (!phba->debug_slow_ring_trc) {
947 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
948 "0409 Cannot create debugfs "
949 "slow_ring_trace\n");
952 if (!phba->slow_ring_trc) {
953 phba->slow_ring_trc = kmalloc(
954 (sizeof(struct lpfc_debugfs_trc) *
955 lpfc_debugfs_max_slow_ring_trc),
957 if (!phba->slow_ring_trc) {
958 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
959 "0409 Cannot create debugfs "
960 "slow_ring buffer\n");
963 atomic_set(&phba->slow_ring_trc_cnt, 0);
964 memset(phba->slow_ring_trc, 0,
965 (sizeof(struct lpfc_debugfs_trc) *
966 lpfc_debugfs_max_slow_ring_trc));
970 snprintf(name, sizeof(name), "vport%d", vport->vpi);
971 if (!vport->vport_debugfs_root) {
972 vport->vport_debugfs_root =
973 debugfs_create_dir(name, phba->hba_debugfs_root);
974 if (!vport->vport_debugfs_root) {
975 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
976 "0409 Cant create debugfs");
979 atomic_inc(&phba->debugfs_vport_count);
982 if (lpfc_debugfs_max_disc_trc) {
983 num = lpfc_debugfs_max_disc_trc - 1;
984 if (num & lpfc_debugfs_max_disc_trc) {
985 /* Change to be a power of 2 */
986 num = lpfc_debugfs_max_disc_trc;
992 lpfc_debugfs_max_disc_trc = (1 << i);
994 "lpfc_debugfs_max_disc_trc changed to %d\n",
995 lpfc_debugfs_max_disc_trc);
999 vport->disc_trc = kzalloc(
1000 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
1003 if (!vport->disc_trc) {
1004 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1005 "0409 Cannot create debugfs disc trace "
1009 atomic_set(&vport->disc_trc_cnt, 0);
1011 snprintf(name, sizeof(name), "discovery_trace");
1012 vport->debug_disc_trc =
1013 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1014 vport->vport_debugfs_root,
1015 vport, &lpfc_debugfs_op_disc_trc);
1016 if (!vport->debug_disc_trc) {
1017 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1018 "0409 Cannot create debugfs "
1019 "discovery_trace\n");
1022 snprintf(name, sizeof(name), "nodelist");
1023 vport->debug_nodelist =
1024 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1025 vport->vport_debugfs_root,
1026 vport, &lpfc_debugfs_op_nodelist);
1027 if (!vport->debug_nodelist) {
1028 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1029 "0409 Cant create debugfs nodelist");
1039 lpfc_debugfs_terminate(struct lpfc_vport *vport)
1041 #ifdef CONFIG_LPFC_DEBUG_FS
1042 struct lpfc_hba *phba = vport->phba;
1044 if (vport->disc_trc) {
1045 kfree(vport->disc_trc);
1046 vport->disc_trc = NULL;
1048 if (vport->debug_disc_trc) {
1049 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
1050 vport->debug_disc_trc = NULL;
1052 if (vport->debug_nodelist) {
1053 debugfs_remove(vport->debug_nodelist); /* nodelist */
1054 vport->debug_nodelist = NULL;
1057 if (vport->vport_debugfs_root) {
1058 debugfs_remove(vport->vport_debugfs_root); /* vportX */
1059 vport->vport_debugfs_root = NULL;
1060 atomic_dec(&phba->debugfs_vport_count);
1062 if (atomic_read(&phba->debugfs_vport_count) == 0) {
1064 if (phba->debug_hbqinfo) {
1065 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
1066 phba->debug_hbqinfo = NULL;
1068 if (phba->debug_dumpHBASlim) {
1069 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
1070 phba->debug_dumpHBASlim = NULL;
1072 if (phba->debug_dumpHostSlim) {
1073 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
1074 phba->debug_dumpHostSlim = NULL;
1076 if (phba->slow_ring_trc) {
1077 kfree(phba->slow_ring_trc);
1078 phba->slow_ring_trc = NULL;
1080 if (phba->debug_slow_ring_trc) {
1081 /* slow_ring_trace */
1082 debugfs_remove(phba->debug_slow_ring_trc);
1083 phba->debug_slow_ring_trc = NULL;
1086 if (phba->hba_debugfs_root) {
1087 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
1088 phba->hba_debugfs_root = NULL;
1089 atomic_dec(&lpfc_debugfs_hba_count);
1092 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
1093 debugfs_remove(lpfc_debugfs_root); /* lpfc */
1094 lpfc_debugfs_root = NULL;