1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007-2008 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
52 * To access this interface the user should:
54 * # mount -t debugfs none /debug
56 * The lpfc debugfs directory hierarchy 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 discovery events.
66 * To enable the discovery trace, the following 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
74 * This is an ACSII readable file that contains a trace of the last
75 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
76 * To enable the slow ring trace, the following module parameters must be set:
77 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
78 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
79 * the HBA. X MUST also be a power of 2.
81 static int lpfc_debugfs_enable = 1;
82 module_param(lpfc_debugfs_enable, int, 0);
83 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
85 /* This MUST be a power of 2 */
86 static int lpfc_debugfs_max_disc_trc;
87 module_param(lpfc_debugfs_max_disc_trc, int, 0);
88 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
89 "Set debugfs discovery trace depth");
91 /* This MUST be a power of 2 */
92 static int lpfc_debugfs_max_slow_ring_trc;
93 module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
94 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
95 "Set debugfs slow ring trace depth");
97 int lpfc_debugfs_mask_disc_trc;
98 module_param(lpfc_debugfs_mask_disc_trc, int, 0);
99 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
100 "Set debugfs discovery trace mask");
102 #include <linux/debugfs.h>
104 /* size of output line, for discovery_trace and slow_ring_trace */
105 #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
107 /* nodelist output buffer size */
108 #define LPFC_NODELIST_SIZE 8192
109 #define LPFC_NODELIST_ENTRY_SIZE 120
111 /* dumpHBASlim output buffer size */
112 #define LPFC_DUMPHBASLIM_SIZE 4096
114 /* dumpHostSlim output buffer size */
115 #define LPFC_DUMPHOSTSLIM_SIZE 4096
117 /* hbqinfo output buffer size */
118 #define LPFC_HBQINFO_SIZE 8192
125 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
126 static unsigned long lpfc_debugfs_start_time = 0L;
129 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer.
130 * @vport: The vport to gather the log info from.
131 * @buf: The buffer to dump log into.
132 * @size: The maximum amount of data to process.
135 * This routine gathers the lpfc discovery debugfs data from the @vport and
136 * dumps it to @buf up to @size number of bytes. It will start at the next entry
137 * in the log and process the log until the end of the buffer. Then it will
138 * gather from the beginning of the log and process until the current entry.
141 * Discovery logging will be disabled while while this routine dumps the log.
144 * This routine returns the amount of bytes that were dumped into @buf and will
148 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
150 int i, index, len, enable;
152 struct lpfc_debugfs_trc *dtp;
153 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
155 enable = lpfc_debugfs_enable;
156 lpfc_debugfs_enable = 0;
159 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
160 (lpfc_debugfs_max_disc_trc - 1);
161 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
162 dtp = vport->disc_trc + i;
165 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
167 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
168 dtp->seq_cnt, ms, dtp->fmt);
169 len += snprintf(buf+len, size-len, buffer,
170 dtp->data1, dtp->data2, dtp->data3);
172 for (i = 0; i < index; i++) {
173 dtp = vport->disc_trc + i;
176 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
178 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
179 dtp->seq_cnt, ms, dtp->fmt);
180 len += snprintf(buf+len, size-len, buffer,
181 dtp->data1, dtp->data2, dtp->data3);
184 lpfc_debugfs_enable = enable;
189 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer.
190 * @phba: The HBA to gather the log info from.
191 * @buf: The buffer to dump log into.
192 * @size: The maximum amount of data to process.
195 * This routine gathers the lpfc slow ring debugfs data from the @phba and
196 * dumps it to @buf up to @size number of bytes. It will start at the next entry
197 * in the log and process the log until the end of the buffer. Then it will
198 * gather from the beginning of the log and process until the current entry.
201 * Slow ring logging will be disabled while while this routine dumps the log.
204 * This routine returns the amount of bytes that were dumped into @buf and will
208 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
210 int i, index, len, enable;
212 struct lpfc_debugfs_trc *dtp;
213 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
216 enable = lpfc_debugfs_enable;
217 lpfc_debugfs_enable = 0;
220 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
221 (lpfc_debugfs_max_slow_ring_trc - 1);
222 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
223 dtp = phba->slow_ring_trc + i;
226 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
228 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
229 dtp->seq_cnt, ms, dtp->fmt);
230 len += snprintf(buf+len, size-len, buffer,
231 dtp->data1, dtp->data2, dtp->data3);
233 for (i = 0; i < index; i++) {
234 dtp = phba->slow_ring_trc + i;
237 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
239 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
240 dtp->seq_cnt, ms, dtp->fmt);
241 len += snprintf(buf+len, size-len, buffer,
242 dtp->data1, dtp->data2, dtp->data3);
245 lpfc_debugfs_enable = enable;
249 static int lpfc_debugfs_last_hbq = -1;
252 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer.
253 * @phba: The HBA to gather host buffer info from.
254 * @buf: The buffer to dump log into.
255 * @size: The maximum amount of data to process.
258 * This routine dumps the host buffer queue info from the @phba to @buf up to
259 * @size number of bytes. A header that describes the current hbq state will be
260 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
261 * until @size bytes have been dumped or all the hbq info has been dumped.
264 * This routine will rotate through each configured HBQ each time called.
267 * This routine returns the amount of bytes that were dumped into @buf and will
271 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
274 int cnt, i, j, found, posted, low;
275 uint32_t phys, raw_index, getidx;
276 struct lpfc_hbq_init *hip;
278 struct lpfc_hbq_entry *hbqe;
279 struct lpfc_dmabuf *d_buf;
280 struct hbq_dmabuf *hbq_buf;
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)
397 spin_lock_irq(&phba->hbalock);
399 len += snprintf(buf+len, size-len, "HBA SLIM\n");
400 lpfc_memcpy_from_slim(buffer,
401 ((uint8_t *)phba->MBslimaddr) + lpfc_debugfs_last_hba_slim_off,
404 ptr = (uint32_t *)&buffer[0];
405 off = lpfc_debugfs_last_hba_slim_off;
407 /* Set it up for the next time */
408 lpfc_debugfs_last_hba_slim_off += 1024;
409 if (lpfc_debugfs_last_hba_slim_off >= 4096)
410 lpfc_debugfs_last_hba_slim_off = 0;
414 len += snprintf(buf+len, size-len,
415 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
416 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
417 *(ptr+5), *(ptr+6), *(ptr+7));
419 i -= (8 * sizeof(uint32_t));
420 off += (8 * sizeof(uint32_t));
423 spin_unlock_irq(&phba->hbalock);
428 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer.
429 * @phba: The HBA to gather Host SLIM info from.
430 * @buf: The buffer to dump log into.
431 * @size: The maximum amount of data to process.
434 * This routine dumps the current contents of host SLIM for the host associated
435 * with @phba to @buf up to @size bytes of data. The dump will contain the
436 * Mailbox, PCB, Rings, and Registers that are located in host memory.
439 * This routine returns the amount of bytes that were dumped into @buf and will
443 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
447 uint32_t word0, word1, word2, word3;
449 struct lpfc_pgp *pgpp;
450 struct lpfc_sli *psli = &phba->sli;
451 struct lpfc_sli_ring *pring;
454 spin_lock_irq(&phba->hbalock);
456 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
457 ptr = (uint32_t *)phba->slim2p;
458 i = sizeof(MAILBOX_t);
460 len += snprintf(buf+len, size-len,
461 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
462 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
463 *(ptr+5), *(ptr+6), *(ptr+7));
465 i -= (8 * sizeof(uint32_t));
466 off += (8 * sizeof(uint32_t));
469 len += snprintf(buf+len, size-len, "SLIM PCB\n");
470 ptr = (uint32_t *)&phba->slim2p->pcb;
473 len += snprintf(buf+len, size-len,
474 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
475 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
476 *(ptr+5), *(ptr+6), *(ptr+7));
478 i -= (8 * sizeof(uint32_t));
479 off += (8 * sizeof(uint32_t));
482 pgpp = (struct lpfc_pgp *)&phba->slim2p->mbx.us.s3_pgp.port;
483 pring = &psli->ring[0];
484 len += snprintf(buf+len, size-len,
485 "Ring 0: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
486 "RSP PutInx:%d Max:%d\n",
487 pgpp->cmdGetInx, pring->numCiocb,
488 pring->next_cmdidx, pring->local_getidx, pring->flag,
489 pgpp->rspPutInx, pring->numRiocb);
492 pring = &psli->ring[1];
493 len += snprintf(buf+len, size-len,
494 "Ring 1: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
495 "RSP PutInx:%d Max:%d\n",
496 pgpp->cmdGetInx, pring->numCiocb,
497 pring->next_cmdidx, pring->local_getidx, pring->flag,
498 pgpp->rspPutInx, pring->numRiocb);
501 pring = &psli->ring[2];
502 len += snprintf(buf+len, size-len,
503 "Ring 2: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
504 "RSP PutInx:%d Max:%d\n",
505 pgpp->cmdGetInx, pring->numCiocb,
506 pring->next_cmdidx, pring->local_getidx, pring->flag,
507 pgpp->rspPutInx, pring->numRiocb);
510 pring = &psli->ring[3];
511 len += snprintf(buf+len, size-len,
512 "Ring 3: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
513 "RSP PutInx:%d Max:%d\n",
514 pgpp->cmdGetInx, pring->numCiocb,
515 pring->next_cmdidx, pring->local_getidx, pring->flag,
516 pgpp->rspPutInx, pring->numRiocb);
519 ptr = (uint32_t *)&phba->slim2p->mbx.us.s3_pgp.hbq_get;
520 word0 = readl(phba->HAregaddr);
521 word1 = readl(phba->CAregaddr);
522 word2 = readl(phba->HSregaddr);
523 word3 = readl(phba->HCregaddr);
524 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n",
525 word0, word1, word2, word3);
526 spin_unlock_irq(&phba->hbalock);
531 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer.
532 * @vport: The vport to gather target node info from.
533 * @buf: The buffer to dump log into.
534 * @size: The maximum amount of data to process.
537 * This routine dumps the current target node list associated with @vport to
538 * @buf up to @size bytes of data. Each node entry in the dump will contain a
539 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
542 * This routine returns the amount of bytes that were dumped into @buf and will
546 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
550 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
551 struct lpfc_nodelist *ndlp;
552 unsigned char *statep, *name;
554 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
556 spin_lock_irq(shost->host_lock);
557 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
559 len += snprintf(buf+len, size-len,
560 "Missing Nodelist Entries\n");
564 switch (ndlp->nlp_state) {
565 case NLP_STE_UNUSED_NODE:
568 case NLP_STE_PLOGI_ISSUE:
571 case NLP_STE_ADISC_ISSUE:
574 case NLP_STE_REG_LOGIN_ISSUE:
577 case NLP_STE_PRLI_ISSUE:
580 case NLP_STE_UNMAPPED_NODE:
583 case NLP_STE_MAPPED_NODE:
586 case NLP_STE_NPR_NODE:
592 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
593 statep, ndlp->nlp_DID);
594 name = (unsigned char *)&ndlp->nlp_portname;
595 len += snprintf(buf+len, size-len,
596 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
597 *name, *(name+1), *(name+2), *(name+3),
598 *(name+4), *(name+5), *(name+6), *(name+7));
599 name = (unsigned char *)&ndlp->nlp_nodename;
600 len += snprintf(buf+len, size-len,
601 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
602 *name, *(name+1), *(name+2), *(name+3),
603 *(name+4), *(name+5), *(name+6), *(name+7));
604 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
605 ndlp->nlp_rpi, ndlp->nlp_flag);
607 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
608 if (ndlp->nlp_type & NLP_FC_NODE)
609 len += snprintf(buf+len, size-len, "FC_NODE ");
610 if (ndlp->nlp_type & NLP_FABRIC)
611 len += snprintf(buf+len, size-len, "FABRIC ");
612 if (ndlp->nlp_type & NLP_FCP_TARGET)
613 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
615 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
616 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
617 len += snprintf(buf+len, size-len, "usgmap:%x ",
619 len += snprintf(buf+len, size-len, "refcnt:%x",
620 atomic_read(&ndlp->kref.refcount));
621 len += snprintf(buf+len, size-len, "\n");
623 spin_unlock_irq(shost->host_lock);
629 * lpfc_debugfs_disc_trc - Store discovery trace log.
630 * @vport: The vport to associate this trace string with for retrieval.
631 * @mask: Log entry classification.
632 * @fmt: Format string to be displayed when dumping the log.
633 * @data1: 1st data parameter to be applied to @fmt.
634 * @data2: 2nd data parameter to be applied to @fmt.
635 * @data3: 3rd data parameter to be applied to @fmt.
638 * This routine is used by the driver code to add a debugfs log entry to the
639 * discovery trace buffer associated with @vport. Only entries with a @mask that
640 * match the current debugfs discovery mask will be saved. Entries that do not
641 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
642 * printf when displaying the log.
645 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
646 uint32_t data1, uint32_t data2, uint32_t data3)
648 #ifdef CONFIG_LPFC_DEBUG_FS
649 struct lpfc_debugfs_trc *dtp;
652 if (!(lpfc_debugfs_mask_disc_trc & mask))
655 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
656 !vport || !vport->disc_trc)
659 index = atomic_inc_return(&vport->disc_trc_cnt) &
660 (lpfc_debugfs_max_disc_trc - 1);
661 dtp = vport->disc_trc + index;
666 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
673 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log.
674 * @phba: The phba to associate this trace string with for retrieval.
675 * @fmt: Format string to be displayed when dumping the log.
676 * @data1: 1st data parameter to be applied to @fmt.
677 * @data2: 2nd data parameter to be applied to @fmt.
678 * @data3: 3rd data parameter to be applied to @fmt.
681 * This routine is used by the driver code to add a debugfs log entry to the
682 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
683 * @data3 are used like printf when displaying the log.
686 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
687 uint32_t data1, uint32_t data2, uint32_t data3)
689 #ifdef CONFIG_LPFC_DEBUG_FS
690 struct lpfc_debugfs_trc *dtp;
693 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
694 !phba || !phba->slow_ring_trc)
697 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
698 (lpfc_debugfs_max_slow_ring_trc - 1);
699 dtp = phba->slow_ring_trc + index;
704 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
710 #ifdef CONFIG_LPFC_DEBUG_FS
712 * lpfc_debugfs_disc_trc_open - Open the discovery trace log.
713 * @inode: The inode pointer that contains a vport pointer.
714 * @file: The file pointer to attach the log output.
717 * This routine is the entry point for the debugfs open file operation. It gets
718 * the vport from the i_private field in @inode, allocates the necessary buffer
719 * for the log, fills the buffer from the in-memory log for this vport, and then
720 * returns a pointer to that log in the private_data field in @file.
723 * This function returns zero if successful. On error it will return an negative
727 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
729 struct lpfc_vport *vport = inode->i_private;
730 struct lpfc_debug *debug;
734 if (!lpfc_debugfs_max_disc_trc) {
739 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
743 /* Round to page boundary */
744 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
745 size = PAGE_ALIGN(size);
747 debug->buffer = kmalloc(size, GFP_KERNEL);
748 if (!debug->buffer) {
753 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
754 file->private_data = debug;
762 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log.
763 * @inode: The inode pointer that contains a vport pointer.
764 * @file: The file pointer to attach the log output.
767 * This routine is the entry point for the debugfs open file operation. It gets
768 * the vport from the i_private field in @inode, allocates the necessary buffer
769 * for the log, fills the buffer from the in-memory log for this vport, and then
770 * returns a pointer to that log in the private_data field in @file.
773 * This function returns zero if successful. On error it will return an negative
777 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
779 struct lpfc_hba *phba = inode->i_private;
780 struct lpfc_debug *debug;
784 if (!lpfc_debugfs_max_slow_ring_trc) {
789 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
793 /* Round to page boundary */
794 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
795 size = PAGE_ALIGN(size);
797 debug->buffer = kmalloc(size, GFP_KERNEL);
798 if (!debug->buffer) {
803 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
804 file->private_data = debug;
812 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer.
813 * @inode: The inode pointer that contains a vport pointer.
814 * @file: The file pointer to attach the log output.
817 * This routine is the entry point for the debugfs open file operation. It gets
818 * the vport from the i_private field in @inode, allocates the necessary buffer
819 * for the log, fills the buffer from the in-memory log for this vport, and then
820 * returns a pointer to that log in the private_data field in @file.
823 * This function returns zero if successful. On error it will return an negative
827 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
829 struct lpfc_hba *phba = inode->i_private;
830 struct lpfc_debug *debug;
833 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
837 /* Round to page boundary */
838 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
839 if (!debug->buffer) {
844 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
846 file->private_data = debug;
854 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer.
855 * @inode: The inode pointer that contains a vport pointer.
856 * @file: The file pointer to attach the log output.
859 * This routine is the entry point for the debugfs open file operation. It gets
860 * the vport from the i_private field in @inode, allocates the necessary buffer
861 * for the log, fills the buffer from the in-memory log for this vport, and then
862 * returns a pointer to that log in the private_data field in @file.
865 * This function returns zero if successful. On error it will return an negative
869 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
871 struct lpfc_hba *phba = inode->i_private;
872 struct lpfc_debug *debug;
875 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
879 /* Round to page boundary */
880 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
881 if (!debug->buffer) {
886 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
887 LPFC_DUMPHBASLIM_SIZE);
888 file->private_data = debug;
896 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer.
897 * @inode: The inode pointer that contains a vport pointer.
898 * @file: The file pointer to attach the log output.
901 * This routine is the entry point for the debugfs open file operation. It gets
902 * the vport from the i_private field in @inode, allocates the necessary buffer
903 * for the log, fills the buffer from the in-memory log for this vport, and then
904 * returns a pointer to that log in the private_data field in @file.
907 * This function returns zero if successful. On error it will return an negative
911 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
913 struct lpfc_hba *phba = inode->i_private;
914 struct lpfc_debug *debug;
917 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
921 /* Round to page boundary */
922 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
923 if (!debug->buffer) {
928 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
929 LPFC_DUMPHOSTSLIM_SIZE);
930 file->private_data = debug;
938 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file.
939 * @inode: The inode pointer that contains a vport pointer.
940 * @file: The file pointer to attach the log output.
943 * This routine is the entry point for the debugfs open file operation. It gets
944 * the vport from the i_private field in @inode, allocates the necessary buffer
945 * for the log, fills the buffer from the in-memory log for this vport, and then
946 * returns a pointer to that log in the private_data field in @file.
949 * This function returns zero if successful. On error it will return an negative
953 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
955 struct lpfc_vport *vport = inode->i_private;
956 struct lpfc_debug *debug;
959 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
963 /* Round to page boundary */
964 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
965 if (!debug->buffer) {
970 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
972 file->private_data = debug;
980 * lpfc_debugfs_lseek - Seek through a debugfs file.
981 * @file: The file pointer to seek through.
982 * @off: The offset to seek to or the amount to seek by.
983 * @whence: Indicates how to seek.
986 * This routine is the entry point for the debugfs lseek file operation. The
987 * @whence parameter indicates whether @off is the offset to directly seek to,
988 * or if it is a value to seek forward or reverse by. This function figures out
989 * what the new offset of the debugfs file will be and assigns that value to the
990 * f_pos field of @file.
993 * This function returns the new offset if successful and returns a negative
994 * error if unable to process the seek.
997 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
999 struct lpfc_debug *debug;
1002 debug = file->private_data;
1009 pos = file->f_pos + off;
1012 pos = debug->len - off;
1014 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1018 * lpfc_debugfs_read - Read a debugfs file.
1019 * @file: The file pointer to read from.
1020 * @buf: The buffer to copy the data to.
1021 * @nbytes: The number of bytes to read.
1022 * @ppos: The position in the file to start reading from.
1025 * This routine reads data from from the buffer indicated in the private_data
1026 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1030 * This function returns the amount of data that was read (this could be less
1031 * than @nbytes if the end of the file was reached) or a negative error value.
1034 lpfc_debugfs_read(struct file *file, char __user *buf,
1035 size_t nbytes, loff_t *ppos)
1037 struct lpfc_debug *debug = file->private_data;
1038 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1043 * lpfc_debugfs_release - Release the buffer used to store debugfs file data.
1044 * @inode: The inode pointer that contains a vport pointer. (unused)
1045 * @file: The file pointer that contains the buffer to release.
1048 * This routine frees the buffer that was allocated when the debugfs file was
1052 * This function returns zero.
1055 lpfc_debugfs_release(struct inode *inode, struct file *file)
1057 struct lpfc_debug *debug = file->private_data;
1059 kfree(debug->buffer);
1065 #undef lpfc_debugfs_op_disc_trc
1066 static struct file_operations lpfc_debugfs_op_disc_trc = {
1067 .owner = THIS_MODULE,
1068 .open = lpfc_debugfs_disc_trc_open,
1069 .llseek = lpfc_debugfs_lseek,
1070 .read = lpfc_debugfs_read,
1071 .release = lpfc_debugfs_release,
1074 #undef lpfc_debugfs_op_nodelist
1075 static struct file_operations lpfc_debugfs_op_nodelist = {
1076 .owner = THIS_MODULE,
1077 .open = lpfc_debugfs_nodelist_open,
1078 .llseek = lpfc_debugfs_lseek,
1079 .read = lpfc_debugfs_read,
1080 .release = lpfc_debugfs_release,
1083 #undef lpfc_debugfs_op_hbqinfo
1084 static struct file_operations lpfc_debugfs_op_hbqinfo = {
1085 .owner = THIS_MODULE,
1086 .open = lpfc_debugfs_hbqinfo_open,
1087 .llseek = lpfc_debugfs_lseek,
1088 .read = lpfc_debugfs_read,
1089 .release = lpfc_debugfs_release,
1092 #undef lpfc_debugfs_op_dumpHBASlim
1093 static struct file_operations lpfc_debugfs_op_dumpHBASlim = {
1094 .owner = THIS_MODULE,
1095 .open = lpfc_debugfs_dumpHBASlim_open,
1096 .llseek = lpfc_debugfs_lseek,
1097 .read = lpfc_debugfs_read,
1098 .release = lpfc_debugfs_release,
1101 #undef lpfc_debugfs_op_dumpHostSlim
1102 static struct file_operations lpfc_debugfs_op_dumpHostSlim = {
1103 .owner = THIS_MODULE,
1104 .open = lpfc_debugfs_dumpHostSlim_open,
1105 .llseek = lpfc_debugfs_lseek,
1106 .read = lpfc_debugfs_read,
1107 .release = lpfc_debugfs_release,
1110 #undef lpfc_debugfs_op_slow_ring_trc
1111 static struct file_operations lpfc_debugfs_op_slow_ring_trc = {
1112 .owner = THIS_MODULE,
1113 .open = lpfc_debugfs_slow_ring_trc_open,
1114 .llseek = lpfc_debugfs_lseek,
1115 .read = lpfc_debugfs_read,
1116 .release = lpfc_debugfs_release,
1119 static struct dentry *lpfc_debugfs_root = NULL;
1120 static atomic_t lpfc_debugfs_hba_count;
1124 * lpfc_debugfs_initialize - Initialize debugfs for a vport.
1125 * @vport: The vport pointer to initialize.
1128 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1129 * If not already created, this routine will create the lpfc directory, and
1130 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1131 * also create each file used to access lpfc specific debugfs information.
1134 lpfc_debugfs_initialize(struct lpfc_vport *vport)
1136 #ifdef CONFIG_LPFC_DEBUG_FS
1137 struct lpfc_hba *phba = vport->phba;
1141 if (!lpfc_debugfs_enable)
1144 /* Setup lpfc root directory */
1145 if (!lpfc_debugfs_root) {
1146 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
1147 atomic_set(&lpfc_debugfs_hba_count, 0);
1148 if (!lpfc_debugfs_root) {
1149 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1150 "0409 Cannot create debugfs root\n");
1154 if (!lpfc_debugfs_start_time)
1155 lpfc_debugfs_start_time = jiffies;
1157 /* Setup lpfcX directory for specific HBA */
1158 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
1159 if (!phba->hba_debugfs_root) {
1160 phba->hba_debugfs_root =
1161 debugfs_create_dir(name, lpfc_debugfs_root);
1162 if (!phba->hba_debugfs_root) {
1163 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1164 "0409 Cannot create debugfs hba\n");
1167 atomic_inc(&lpfc_debugfs_hba_count);
1168 atomic_set(&phba->debugfs_vport_count, 0);
1171 snprintf(name, sizeof(name), "hbqinfo");
1172 phba->debug_hbqinfo =
1173 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1174 phba->hba_debugfs_root,
1175 phba, &lpfc_debugfs_op_hbqinfo);
1176 if (!phba->debug_hbqinfo) {
1177 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1178 "0409 Cannot create debugfs hbqinfo\n");
1182 /* Setup dumpHBASlim */
1183 snprintf(name, sizeof(name), "dumpHBASlim");
1184 phba->debug_dumpHBASlim =
1185 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1186 phba->hba_debugfs_root,
1187 phba, &lpfc_debugfs_op_dumpHBASlim);
1188 if (!phba->debug_dumpHBASlim) {
1189 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1190 "0409 Cannot create debugfs dumpHBASlim\n");
1194 /* Setup dumpHostSlim */
1195 snprintf(name, sizeof(name), "dumpHostSlim");
1196 phba->debug_dumpHostSlim =
1197 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1198 phba->hba_debugfs_root,
1199 phba, &lpfc_debugfs_op_dumpHostSlim);
1200 if (!phba->debug_dumpHostSlim) {
1201 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1202 "0409 Cannot create debugfs dumpHostSlim\n");
1206 /* Setup slow ring trace */
1207 if (lpfc_debugfs_max_slow_ring_trc) {
1208 num = lpfc_debugfs_max_slow_ring_trc - 1;
1209 if (num & lpfc_debugfs_max_slow_ring_trc) {
1210 /* Change to be a power of 2 */
1211 num = lpfc_debugfs_max_slow_ring_trc;
1217 lpfc_debugfs_max_slow_ring_trc = (1 << i);
1219 "lpfc_debugfs_max_disc_trc changed to "
1220 "%d\n", lpfc_debugfs_max_disc_trc);
1225 snprintf(name, sizeof(name), "slow_ring_trace");
1226 phba->debug_slow_ring_trc =
1227 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1228 phba->hba_debugfs_root,
1229 phba, &lpfc_debugfs_op_slow_ring_trc);
1230 if (!phba->debug_slow_ring_trc) {
1231 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1232 "0409 Cannot create debugfs "
1233 "slow_ring_trace\n");
1236 if (!phba->slow_ring_trc) {
1237 phba->slow_ring_trc = kmalloc(
1238 (sizeof(struct lpfc_debugfs_trc) *
1239 lpfc_debugfs_max_slow_ring_trc),
1241 if (!phba->slow_ring_trc) {
1242 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1243 "0409 Cannot create debugfs "
1244 "slow_ring buffer\n");
1247 atomic_set(&phba->slow_ring_trc_cnt, 0);
1248 memset(phba->slow_ring_trc, 0,
1249 (sizeof(struct lpfc_debugfs_trc) *
1250 lpfc_debugfs_max_slow_ring_trc));
1254 snprintf(name, sizeof(name), "vport%d", vport->vpi);
1255 if (!vport->vport_debugfs_root) {
1256 vport->vport_debugfs_root =
1257 debugfs_create_dir(name, phba->hba_debugfs_root);
1258 if (!vport->vport_debugfs_root) {
1259 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1260 "0409 Cant create debugfs");
1263 atomic_inc(&phba->debugfs_vport_count);
1266 if (lpfc_debugfs_max_disc_trc) {
1267 num = lpfc_debugfs_max_disc_trc - 1;
1268 if (num & lpfc_debugfs_max_disc_trc) {
1269 /* Change to be a power of 2 */
1270 num = lpfc_debugfs_max_disc_trc;
1276 lpfc_debugfs_max_disc_trc = (1 << i);
1278 "lpfc_debugfs_max_disc_trc changed to %d\n",
1279 lpfc_debugfs_max_disc_trc);
1283 vport->disc_trc = kzalloc(
1284 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
1287 if (!vport->disc_trc) {
1288 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1289 "0409 Cannot create debugfs disc trace "
1293 atomic_set(&vport->disc_trc_cnt, 0);
1295 snprintf(name, sizeof(name), "discovery_trace");
1296 vport->debug_disc_trc =
1297 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1298 vport->vport_debugfs_root,
1299 vport, &lpfc_debugfs_op_disc_trc);
1300 if (!vport->debug_disc_trc) {
1301 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1302 "0409 Cannot create debugfs "
1303 "discovery_trace\n");
1306 snprintf(name, sizeof(name), "nodelist");
1307 vport->debug_nodelist =
1308 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1309 vport->vport_debugfs_root,
1310 vport, &lpfc_debugfs_op_nodelist);
1311 if (!vport->debug_nodelist) {
1312 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1313 "0409 Cant create debugfs nodelist");
1322 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport.
1323 * @vport: The vport pointer to remove from debugfs.
1326 * When Debugfs is configured this routine removes debugfs file system elements
1327 * that are specific to this vport. It also checks to see if there are any
1328 * users left for the debugfs directories associated with the HBA and driver. If
1329 * this is the last user of the HBA directory or driver directory then it will
1330 * remove those from the debugfs infrastructure as well.
1333 lpfc_debugfs_terminate(struct lpfc_vport *vport)
1335 #ifdef CONFIG_LPFC_DEBUG_FS
1336 struct lpfc_hba *phba = vport->phba;
1338 if (vport->disc_trc) {
1339 kfree(vport->disc_trc);
1340 vport->disc_trc = NULL;
1342 if (vport->debug_disc_trc) {
1343 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
1344 vport->debug_disc_trc = NULL;
1346 if (vport->debug_nodelist) {
1347 debugfs_remove(vport->debug_nodelist); /* nodelist */
1348 vport->debug_nodelist = NULL;
1351 if (vport->vport_debugfs_root) {
1352 debugfs_remove(vport->vport_debugfs_root); /* vportX */
1353 vport->vport_debugfs_root = NULL;
1354 atomic_dec(&phba->debugfs_vport_count);
1356 if (atomic_read(&phba->debugfs_vport_count) == 0) {
1358 if (phba->debug_hbqinfo) {
1359 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
1360 phba->debug_hbqinfo = NULL;
1362 if (phba->debug_dumpHBASlim) {
1363 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
1364 phba->debug_dumpHBASlim = NULL;
1366 if (phba->debug_dumpHostSlim) {
1367 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
1368 phba->debug_dumpHostSlim = NULL;
1370 if (phba->slow_ring_trc) {
1371 kfree(phba->slow_ring_trc);
1372 phba->slow_ring_trc = NULL;
1374 if (phba->debug_slow_ring_trc) {
1375 /* slow_ring_trace */
1376 debugfs_remove(phba->debug_slow_ring_trc);
1377 phba->debug_slow_ring_trc = NULL;
1380 if (phba->hba_debugfs_root) {
1381 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
1382 phba->hba_debugfs_root = NULL;
1383 atomic_dec(&lpfc_debugfs_hba_count);
1386 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
1387 debugfs_remove(lpfc_debugfs_root); /* lpfc */
1388 lpfc_debugfs_root = NULL;