1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007-2009 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>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_version.h"
48 #include "lpfc_compat.h"
49 #include "lpfc_debugfs.h"
51 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
55 * To access this interface the user should:
56 * # mount -t debugfs none /sys/kernel/debug
58 * The lpfc debugfs directory hierarchy is:
60 * where X is the lpfc hba unique_id
61 * where Y is the vport VPI on that hba
63 * Debugging services available per vport:
65 * This is an ACSII readable file that contains a trace of the last
66 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
67 * See lpfc_debugfs.h for different categories of discovery events.
68 * To enable the discovery trace, the following module parameters must be set:
69 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
70 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
71 * EACH vport. X MUST also be a power of 2.
72 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
76 * This is an ACSII readable file that contains a trace of the last
77 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
78 * To enable the slow ring trace, the following module parameters must be set:
79 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
80 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
81 * the HBA. X MUST also be a power of 2.
83 static int lpfc_debugfs_enable
= 1;
84 module_param(lpfc_debugfs_enable
, int, 0);
85 MODULE_PARM_DESC(lpfc_debugfs_enable
, "Enable debugfs services");
87 /* This MUST be a power of 2 */
88 static int lpfc_debugfs_max_disc_trc
;
89 module_param(lpfc_debugfs_max_disc_trc
, int, 0);
90 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc
,
91 "Set debugfs discovery trace depth");
93 /* This MUST be a power of 2 */
94 static int lpfc_debugfs_max_slow_ring_trc
;
95 module_param(lpfc_debugfs_max_slow_ring_trc
, int, 0);
96 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc
,
97 "Set debugfs slow ring trace depth");
99 static int lpfc_debugfs_mask_disc_trc
;
100 module_param(lpfc_debugfs_mask_disc_trc
, int, 0);
101 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc
,
102 "Set debugfs discovery trace mask");
104 #include <linux/debugfs.h>
106 /* size of output line, for discovery_trace and slow_ring_trace */
107 #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
109 /* nodelist output buffer size */
110 #define LPFC_NODELIST_SIZE 8192
111 #define LPFC_NODELIST_ENTRY_SIZE 120
113 /* dumpHBASlim output buffer size */
114 #define LPFC_DUMPHBASLIM_SIZE 4096
116 /* dumpHostSlim output buffer size */
117 #define LPFC_DUMPHOSTSLIM_SIZE 4096
119 /* hbqinfo output buffer size */
120 #define LPFC_HBQINFO_SIZE 8192
127 static atomic_t lpfc_debugfs_seq_trc_cnt
= ATOMIC_INIT(0);
128 static unsigned long lpfc_debugfs_start_time
= 0L;
131 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
132 * @vport: The vport to gather the log info from.
133 * @buf: The buffer to dump log into.
134 * @size: The maximum amount of data to process.
137 * This routine gathers the lpfc discovery debugfs data from the @vport and
138 * dumps it to @buf up to @size number of bytes. It will start at the next entry
139 * in the log and process the log until the end of the buffer. Then it will
140 * gather from the beginning of the log and process until the current entry.
143 * Discovery logging will be disabled while while this routine dumps the log.
146 * This routine returns the amount of bytes that were dumped into @buf and will
150 lpfc_debugfs_disc_trc_data(struct lpfc_vport
*vport
, char *buf
, int size
)
152 int i
, index
, len
, enable
;
154 struct lpfc_debugfs_trc
*dtp
;
155 char buffer
[LPFC_DEBUG_TRC_ENTRY_SIZE
];
157 enable
= lpfc_debugfs_enable
;
158 lpfc_debugfs_enable
= 0;
161 index
= (atomic_read(&vport
->disc_trc_cnt
) + 1) &
162 (lpfc_debugfs_max_disc_trc
- 1);
163 for (i
= index
; i
< lpfc_debugfs_max_disc_trc
; 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
);
174 for (i
= 0; i
< index
; i
++) {
175 dtp
= vport
->disc_trc
+ i
;
178 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
180 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
181 dtp
->seq_cnt
, ms
, dtp
->fmt
);
182 len
+= snprintf(buf
+len
, size
-len
, buffer
,
183 dtp
->data1
, dtp
->data2
, dtp
->data3
);
186 lpfc_debugfs_enable
= enable
;
191 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
192 * @phba: The HBA to gather the log info from.
193 * @buf: The buffer to dump log into.
194 * @size: The maximum amount of data to process.
197 * This routine gathers the lpfc slow ring debugfs data from the @phba and
198 * dumps it to @buf up to @size number of bytes. It will start at the next entry
199 * in the log and process the log until the end of the buffer. Then it will
200 * gather from the beginning of the log and process until the current entry.
203 * Slow ring logging will be disabled while while this routine dumps the log.
206 * This routine returns the amount of bytes that were dumped into @buf and will
210 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba
*phba
, char *buf
, int size
)
212 int i
, index
, len
, enable
;
214 struct lpfc_debugfs_trc
*dtp
;
215 char buffer
[LPFC_DEBUG_TRC_ENTRY_SIZE
];
218 enable
= lpfc_debugfs_enable
;
219 lpfc_debugfs_enable
= 0;
222 index
= (atomic_read(&phba
->slow_ring_trc_cnt
) + 1) &
223 (lpfc_debugfs_max_slow_ring_trc
- 1);
224 for (i
= index
; i
< lpfc_debugfs_max_slow_ring_trc
; i
++) {
225 dtp
= phba
->slow_ring_trc
+ i
;
228 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
230 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
231 dtp
->seq_cnt
, ms
, dtp
->fmt
);
232 len
+= snprintf(buf
+len
, size
-len
, buffer
,
233 dtp
->data1
, dtp
->data2
, dtp
->data3
);
235 for (i
= 0; i
< index
; i
++) {
236 dtp
= phba
->slow_ring_trc
+ i
;
239 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
241 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
242 dtp
->seq_cnt
, ms
, dtp
->fmt
);
243 len
+= snprintf(buf
+len
, size
-len
, buffer
,
244 dtp
->data1
, dtp
->data2
, dtp
->data3
);
247 lpfc_debugfs_enable
= enable
;
251 static int lpfc_debugfs_last_hbq
= -1;
254 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
255 * @phba: The HBA to gather host buffer info from.
256 * @buf: The buffer to dump log into.
257 * @size: The maximum amount of data to process.
260 * This routine dumps the host buffer queue info from the @phba to @buf up to
261 * @size number of bytes. A header that describes the current hbq state will be
262 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
263 * until @size bytes have been dumped or all the hbq info has been dumped.
266 * This routine will rotate through each configured HBQ each time called.
269 * This routine returns the amount of bytes that were dumped into @buf and will
273 lpfc_debugfs_hbqinfo_data(struct lpfc_hba
*phba
, char *buf
, int size
)
276 int cnt
, i
, j
, found
, posted
, low
;
277 uint32_t phys
, raw_index
, getidx
;
278 struct lpfc_hbq_init
*hip
;
280 struct lpfc_hbq_entry
*hbqe
;
281 struct lpfc_dmabuf
*d_buf
;
282 struct hbq_dmabuf
*hbq_buf
;
284 if (phba
->sli_rev
!= 3)
286 cnt
= LPFC_HBQINFO_SIZE
;
287 spin_lock_irq(&phba
->hbalock
);
289 /* toggle between multiple hbqs, if any */
290 i
= lpfc_sli_hbq_count();
292 lpfc_debugfs_last_hbq
++;
293 if (lpfc_debugfs_last_hbq
>= i
)
294 lpfc_debugfs_last_hbq
= 0;
297 lpfc_debugfs_last_hbq
= 0;
299 i
= lpfc_debugfs_last_hbq
;
301 len
+= snprintf(buf
+len
, size
-len
, "HBQ %d Info\n", i
);
303 hbqs
= &phba
->hbqs
[i
];
305 list_for_each_entry(d_buf
, &hbqs
->hbq_buffer_list
, list
)
308 hip
= lpfc_hbq_defs
[i
];
309 len
+= snprintf(buf
+len
, size
-len
,
310 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
311 hip
->hbq_index
, hip
->profile
, hip
->rn
,
312 hip
->buffer_count
, hip
->init_count
, hip
->add_count
, posted
);
314 raw_index
= phba
->hbq_get
[i
];
315 getidx
= le32_to_cpu(raw_index
);
316 len
+= snprintf(buf
+len
, size
-len
,
317 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
318 hbqs
->entry_count
, hbqs
->buffer_count
, hbqs
->hbqPutIdx
,
319 hbqs
->next_hbqPutIdx
, hbqs
->local_hbqGetIdx
, getidx
);
321 hbqe
= (struct lpfc_hbq_entry
*) phba
->hbqs
[i
].hbq_virt
;
322 for (j
=0; j
<hbqs
->entry_count
; j
++) {
323 len
+= snprintf(buf
+len
, size
-len
,
324 "%03d: %08x %04x %05x ", j
,
325 le32_to_cpu(hbqe
->bde
.addrLow
),
326 le32_to_cpu(hbqe
->bde
.tus
.w
),
327 le32_to_cpu(hbqe
->buffer_tag
));
331 /* First calculate if slot has an associated posted buffer */
332 low
= hbqs
->hbqPutIdx
- posted
;
334 if ((j
>= hbqs
->hbqPutIdx
) || (j
< low
)) {
335 len
+= snprintf(buf
+len
, size
-len
, "Unused\n");
340 if ((j
>= hbqs
->hbqPutIdx
) &&
341 (j
< (hbqs
->entry_count
+low
))) {
342 len
+= snprintf(buf
+len
, size
-len
, "Unused\n");
347 /* Get the Buffer info for the posted buffer */
348 list_for_each_entry(d_buf
, &hbqs
->hbq_buffer_list
, list
) {
349 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
350 phys
= ((uint64_t)hbq_buf
->dbuf
.phys
& 0xffffffff);
351 if (phys
== le32_to_cpu(hbqe
->bde
.addrLow
)) {
352 len
+= snprintf(buf
+len
, size
-len
,
353 "Buf%d: %p %06x\n", i
,
354 hbq_buf
->dbuf
.virt
, hbq_buf
->tag
);
361 len
+= snprintf(buf
+len
, size
-len
, "No DMAinfo?\n");
365 if (len
> LPFC_HBQINFO_SIZE
- 54)
368 spin_unlock_irq(&phba
->hbalock
);
372 static int lpfc_debugfs_last_hba_slim_off
;
375 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
376 * @phba: The HBA to gather SLIM info from.
377 * @buf: The buffer to dump log into.
378 * @size: The maximum amount of data to process.
381 * This routine dumps the current contents of HBA SLIM for the HBA associated
382 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
385 * This routine will only dump up to 1024 bytes of data each time called and
386 * should be called multiple times to dump the entire HBA SLIM.
389 * This routine returns the amount of bytes that were dumped into @buf and will
393 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba
*phba
, char *buf
, int size
)
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
);
431 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
432 * @phba: The HBA to gather Host SLIM info from.
433 * @buf: The buffer to dump log into.
434 * @size: The maximum amount of data to process.
437 * This routine dumps the current contents of host SLIM for the host associated
438 * with @phba to @buf up to @size bytes of data. The dump will contain the
439 * Mailbox, PCB, Rings, and Registers that are located in host memory.
442 * This routine returns the amount of bytes that were dumped into @buf and will
446 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba
*phba
, char *buf
, int size
)
450 uint32_t word0
, word1
, word2
, word3
;
452 struct lpfc_pgp
*pgpp
;
453 struct lpfc_sli
*psli
= &phba
->sli
;
454 struct lpfc_sli_ring
*pring
;
457 spin_lock_irq(&phba
->hbalock
);
459 len
+= snprintf(buf
+len
, size
-len
, "SLIM Mailbox\n");
460 ptr
= (uint32_t *)phba
->slim2p
.virt
;
461 i
= sizeof(MAILBOX_t
);
463 len
+= snprintf(buf
+len
, size
-len
,
464 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
465 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
466 *(ptr
+5), *(ptr
+6), *(ptr
+7));
468 i
-= (8 * sizeof(uint32_t));
469 off
+= (8 * sizeof(uint32_t));
472 len
+= snprintf(buf
+len
, size
-len
, "SLIM PCB\n");
473 ptr
= (uint32_t *)phba
->pcb
;
476 len
+= snprintf(buf
+len
, size
-len
,
477 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
478 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
479 *(ptr
+5), *(ptr
+6), *(ptr
+7));
481 i
-= (8 * sizeof(uint32_t));
482 off
+= (8 * sizeof(uint32_t));
485 for (i
= 0; i
< 4; i
++) {
486 pgpp
= &phba
->port_gp
[i
];
487 pring
= &psli
->ring
[i
];
488 len
+= snprintf(buf
+len
, size
-len
,
489 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
490 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
491 i
, pgpp
->cmdGetInx
, pring
->numCiocb
,
492 pring
->next_cmdidx
, pring
->local_getidx
,
493 pring
->flag
, pgpp
->rspPutInx
, pring
->numRiocb
);
496 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
497 word0
= readl(phba
->HAregaddr
);
498 word1
= readl(phba
->CAregaddr
);
499 word2
= readl(phba
->HSregaddr
);
500 word3
= readl(phba
->HCregaddr
);
501 len
+= snprintf(buf
+len
, size
-len
, "HA:%08x CA:%08x HS:%08x "
502 "HC:%08x\n", word0
, word1
, word2
, word3
);
504 spin_unlock_irq(&phba
->hbalock
);
509 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
510 * @vport: The vport to gather target node info from.
511 * @buf: The buffer to dump log into.
512 * @size: The maximum amount of data to process.
515 * This routine dumps the current target node list associated with @vport to
516 * @buf up to @size bytes of data. Each node entry in the dump will contain a
517 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
520 * This routine returns the amount of bytes that were dumped into @buf and will
524 lpfc_debugfs_nodelist_data(struct lpfc_vport
*vport
, char *buf
, int size
)
528 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
529 struct lpfc_nodelist
*ndlp
;
530 unsigned char *statep
, *name
;
532 cnt
= (LPFC_NODELIST_SIZE
/ LPFC_NODELIST_ENTRY_SIZE
);
534 spin_lock_irq(shost
->host_lock
);
535 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
537 len
+= snprintf(buf
+len
, size
-len
,
538 "Missing Nodelist Entries\n");
542 switch (ndlp
->nlp_state
) {
543 case NLP_STE_UNUSED_NODE
:
546 case NLP_STE_PLOGI_ISSUE
:
549 case NLP_STE_ADISC_ISSUE
:
552 case NLP_STE_REG_LOGIN_ISSUE
:
555 case NLP_STE_PRLI_ISSUE
:
558 case NLP_STE_UNMAPPED_NODE
:
561 case NLP_STE_MAPPED_NODE
:
564 case NLP_STE_NPR_NODE
:
570 len
+= snprintf(buf
+len
, size
-len
, "%s DID:x%06x ",
571 statep
, ndlp
->nlp_DID
);
572 name
= (unsigned char *)&ndlp
->nlp_portname
;
573 len
+= snprintf(buf
+len
, size
-len
,
574 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
575 *name
, *(name
+1), *(name
+2), *(name
+3),
576 *(name
+4), *(name
+5), *(name
+6), *(name
+7));
577 name
= (unsigned char *)&ndlp
->nlp_nodename
;
578 len
+= snprintf(buf
+len
, size
-len
,
579 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
580 *name
, *(name
+1), *(name
+2), *(name
+3),
581 *(name
+4), *(name
+5), *(name
+6), *(name
+7));
582 len
+= snprintf(buf
+len
, size
-len
, "RPI:%03d flag:x%08x ",
583 ndlp
->nlp_rpi
, ndlp
->nlp_flag
);
585 len
+= snprintf(buf
+len
, size
-len
, "UNKNOWN_TYPE ");
586 if (ndlp
->nlp_type
& NLP_FC_NODE
)
587 len
+= snprintf(buf
+len
, size
-len
, "FC_NODE ");
588 if (ndlp
->nlp_type
& NLP_FABRIC
)
589 len
+= snprintf(buf
+len
, size
-len
, "FABRIC ");
590 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
591 len
+= snprintf(buf
+len
, size
-len
, "FCP_TGT sid:%d ",
593 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
594 len
+= snprintf(buf
+len
, size
-len
, "FCP_INITIATOR ");
595 len
+= snprintf(buf
+len
, size
-len
, "usgmap:%x ",
597 len
+= snprintf(buf
+len
, size
-len
, "refcnt:%x",
598 atomic_read(&ndlp
->kref
.refcount
));
599 len
+= snprintf(buf
+len
, size
-len
, "\n");
601 spin_unlock_irq(shost
->host_lock
);
607 * lpfc_debugfs_disc_trc - Store discovery trace log
608 * @vport: The vport to associate this trace string with for retrieval.
609 * @mask: Log entry classification.
610 * @fmt: Format string to be displayed when dumping the log.
611 * @data1: 1st data parameter to be applied to @fmt.
612 * @data2: 2nd data parameter to be applied to @fmt.
613 * @data3: 3rd data parameter to be applied to @fmt.
616 * This routine is used by the driver code to add a debugfs log entry to the
617 * discovery trace buffer associated with @vport. Only entries with a @mask that
618 * match the current debugfs discovery mask will be saved. Entries that do not
619 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
620 * printf when displaying the log.
623 lpfc_debugfs_disc_trc(struct lpfc_vport
*vport
, int mask
, char *fmt
,
624 uint32_t data1
, uint32_t data2
, uint32_t data3
)
626 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
627 struct lpfc_debugfs_trc
*dtp
;
630 if (!(lpfc_debugfs_mask_disc_trc
& mask
))
633 if (!lpfc_debugfs_enable
|| !lpfc_debugfs_max_disc_trc
||
634 !vport
|| !vport
->disc_trc
)
637 index
= atomic_inc_return(&vport
->disc_trc_cnt
) &
638 (lpfc_debugfs_max_disc_trc
- 1);
639 dtp
= vport
->disc_trc
+ index
;
644 dtp
->seq_cnt
= atomic_inc_return(&lpfc_debugfs_seq_trc_cnt
);
651 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
652 * @phba: The phba to associate this trace string with for retrieval.
653 * @fmt: Format string to be displayed when dumping the log.
654 * @data1: 1st data parameter to be applied to @fmt.
655 * @data2: 2nd data parameter to be applied to @fmt.
656 * @data3: 3rd data parameter to be applied to @fmt.
659 * This routine is used by the driver code to add a debugfs log entry to the
660 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
661 * @data3 are used like printf when displaying the log.
664 lpfc_debugfs_slow_ring_trc(struct lpfc_hba
*phba
, char *fmt
,
665 uint32_t data1
, uint32_t data2
, uint32_t data3
)
667 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
668 struct lpfc_debugfs_trc
*dtp
;
671 if (!lpfc_debugfs_enable
|| !lpfc_debugfs_max_slow_ring_trc
||
672 !phba
|| !phba
->slow_ring_trc
)
675 index
= atomic_inc_return(&phba
->slow_ring_trc_cnt
) &
676 (lpfc_debugfs_max_slow_ring_trc
- 1);
677 dtp
= phba
->slow_ring_trc
+ index
;
682 dtp
->seq_cnt
= atomic_inc_return(&lpfc_debugfs_seq_trc_cnt
);
688 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
690 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
691 * @inode: The inode pointer that contains a vport pointer.
692 * @file: The file pointer to attach the log output.
695 * This routine is the entry point for the debugfs open file operation. It gets
696 * the vport from the i_private field in @inode, allocates the necessary buffer
697 * for the log, fills the buffer from the in-memory log for this vport, and then
698 * returns a pointer to that log in the private_data field in @file.
701 * This function returns zero if successful. On error it will return an negative
705 lpfc_debugfs_disc_trc_open(struct inode
*inode
, struct file
*file
)
707 struct lpfc_vport
*vport
= inode
->i_private
;
708 struct lpfc_debug
*debug
;
712 if (!lpfc_debugfs_max_disc_trc
) {
717 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
721 /* Round to page boundary */
722 size
= (lpfc_debugfs_max_disc_trc
* LPFC_DEBUG_TRC_ENTRY_SIZE
);
723 size
= PAGE_ALIGN(size
);
725 debug
->buffer
= kmalloc(size
, GFP_KERNEL
);
726 if (!debug
->buffer
) {
731 debug
->len
= lpfc_debugfs_disc_trc_data(vport
, debug
->buffer
, size
);
732 file
->private_data
= debug
;
740 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
741 * @inode: The inode pointer that contains a vport pointer.
742 * @file: The file pointer to attach the log output.
745 * This routine is the entry point for the debugfs open file operation. It gets
746 * the vport from the i_private field in @inode, allocates the necessary buffer
747 * for the log, fills the buffer from the in-memory log for this vport, and then
748 * returns a pointer to that log in the private_data field in @file.
751 * This function returns zero if successful. On error it will return an negative
755 lpfc_debugfs_slow_ring_trc_open(struct inode
*inode
, struct file
*file
)
757 struct lpfc_hba
*phba
= inode
->i_private
;
758 struct lpfc_debug
*debug
;
762 if (!lpfc_debugfs_max_slow_ring_trc
) {
767 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
771 /* Round to page boundary */
772 size
= (lpfc_debugfs_max_slow_ring_trc
* LPFC_DEBUG_TRC_ENTRY_SIZE
);
773 size
= PAGE_ALIGN(size
);
775 debug
->buffer
= kmalloc(size
, GFP_KERNEL
);
776 if (!debug
->buffer
) {
781 debug
->len
= lpfc_debugfs_slow_ring_trc_data(phba
, debug
->buffer
, size
);
782 file
->private_data
= debug
;
790 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
791 * @inode: The inode pointer that contains a vport pointer.
792 * @file: The file pointer to attach the log output.
795 * This routine is the entry point for the debugfs open file operation. It gets
796 * the vport from the i_private field in @inode, allocates the necessary buffer
797 * for the log, fills the buffer from the in-memory log for this vport, and then
798 * returns a pointer to that log in the private_data field in @file.
801 * This function returns zero if successful. On error it will return an negative
805 lpfc_debugfs_hbqinfo_open(struct inode
*inode
, struct file
*file
)
807 struct lpfc_hba
*phba
= inode
->i_private
;
808 struct lpfc_debug
*debug
;
811 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
815 /* Round to page boundary */
816 debug
->buffer
= kmalloc(LPFC_HBQINFO_SIZE
, GFP_KERNEL
);
817 if (!debug
->buffer
) {
822 debug
->len
= lpfc_debugfs_hbqinfo_data(phba
, debug
->buffer
,
824 file
->private_data
= debug
;
832 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
833 * @inode: The inode pointer that contains a vport pointer.
834 * @file: The file pointer to attach the log output.
837 * This routine is the entry point for the debugfs open file operation. It gets
838 * the vport from the i_private field in @inode, allocates the necessary buffer
839 * for the log, fills the buffer from the in-memory log for this vport, and then
840 * returns a pointer to that log in the private_data field in @file.
843 * This function returns zero if successful. On error it will return an negative
847 lpfc_debugfs_dumpHBASlim_open(struct inode
*inode
, struct file
*file
)
849 struct lpfc_hba
*phba
= inode
->i_private
;
850 struct lpfc_debug
*debug
;
853 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
857 /* Round to page boundary */
858 debug
->buffer
= kmalloc(LPFC_DUMPHBASLIM_SIZE
, GFP_KERNEL
);
859 if (!debug
->buffer
) {
864 debug
->len
= lpfc_debugfs_dumpHBASlim_data(phba
, debug
->buffer
,
865 LPFC_DUMPHBASLIM_SIZE
);
866 file
->private_data
= debug
;
874 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
875 * @inode: The inode pointer that contains a vport pointer.
876 * @file: The file pointer to attach the log output.
879 * This routine is the entry point for the debugfs open file operation. It gets
880 * the vport from the i_private field in @inode, allocates the necessary buffer
881 * for the log, fills the buffer from the in-memory log for this vport, and then
882 * returns a pointer to that log in the private_data field in @file.
885 * This function returns zero if successful. On error it will return an negative
889 lpfc_debugfs_dumpHostSlim_open(struct inode
*inode
, struct file
*file
)
891 struct lpfc_hba
*phba
= inode
->i_private
;
892 struct lpfc_debug
*debug
;
895 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
899 /* Round to page boundary */
900 debug
->buffer
= kmalloc(LPFC_DUMPHOSTSLIM_SIZE
, GFP_KERNEL
);
901 if (!debug
->buffer
) {
906 debug
->len
= lpfc_debugfs_dumpHostSlim_data(phba
, debug
->buffer
,
907 LPFC_DUMPHOSTSLIM_SIZE
);
908 file
->private_data
= debug
;
916 lpfc_debugfs_dumpData_open(struct inode
*inode
, struct file
*file
)
918 struct lpfc_debug
*debug
;
924 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
928 /* Round to page boundry */
929 printk(KERN_ERR
"BLKGRD %s: _dump_buf_data=0x%p\n",
930 __func__
, _dump_buf_data
);
931 debug
->buffer
= _dump_buf_data
;
932 if (!debug
->buffer
) {
937 debug
->len
= (1 << _dump_buf_data_order
) << PAGE_SHIFT
;
938 file
->private_data
= debug
;
946 lpfc_debugfs_dumpDif_open(struct inode
*inode
, struct file
*file
)
948 struct lpfc_debug
*debug
;
954 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
958 /* Round to page boundry */
959 printk(KERN_ERR
"BLKGRD %s: _dump_buf_dif=0x%p file=%s\n", __func__
,
960 _dump_buf_dif
, file
->f_dentry
->d_name
.name
);
961 debug
->buffer
= _dump_buf_dif
;
962 if (!debug
->buffer
) {
967 debug
->len
= (1 << _dump_buf_dif_order
) << PAGE_SHIFT
;
968 file
->private_data
= debug
;
976 lpfc_debugfs_dumpDataDif_write(struct file
*file
, const char __user
*buf
,
977 size_t nbytes
, loff_t
*ppos
)
980 * The Data/DIF buffers only save one failing IO
981 * The write op is used as a reset mechanism after an IO has
982 * already been saved to the next one can be saved
984 spin_lock(&_dump_buf_lock
);
986 memset((void *)_dump_buf_data
, 0,
987 ((1 << PAGE_SHIFT
) << _dump_buf_data_order
));
988 memset((void *)_dump_buf_dif
, 0,
989 ((1 << PAGE_SHIFT
) << _dump_buf_dif_order
));
993 spin_unlock(&_dump_buf_lock
);
1001 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1002 * @inode: The inode pointer that contains a vport pointer.
1003 * @file: The file pointer to attach the log output.
1006 * This routine is the entry point for the debugfs open file operation. It gets
1007 * the vport from the i_private field in @inode, allocates the necessary buffer
1008 * for the log, fills the buffer from the in-memory log for this vport, and then
1009 * returns a pointer to that log in the private_data field in @file.
1012 * This function returns zero if successful. On error it will return an negative
1016 lpfc_debugfs_nodelist_open(struct inode
*inode
, struct file
*file
)
1018 struct lpfc_vport
*vport
= inode
->i_private
;
1019 struct lpfc_debug
*debug
;
1022 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
1026 /* Round to page boundary */
1027 debug
->buffer
= kmalloc(LPFC_NODELIST_SIZE
, GFP_KERNEL
);
1028 if (!debug
->buffer
) {
1033 debug
->len
= lpfc_debugfs_nodelist_data(vport
, debug
->buffer
,
1034 LPFC_NODELIST_SIZE
);
1035 file
->private_data
= debug
;
1043 * lpfc_debugfs_lseek - Seek through a debugfs file
1044 * @file: The file pointer to seek through.
1045 * @off: The offset to seek to or the amount to seek by.
1046 * @whence: Indicates how to seek.
1049 * This routine is the entry point for the debugfs lseek file operation. The
1050 * @whence parameter indicates whether @off is the offset to directly seek to,
1051 * or if it is a value to seek forward or reverse by. This function figures out
1052 * what the new offset of the debugfs file will be and assigns that value to the
1053 * f_pos field of @file.
1056 * This function returns the new offset if successful and returns a negative
1057 * error if unable to process the seek.
1060 lpfc_debugfs_lseek(struct file
*file
, loff_t off
, int whence
)
1062 struct lpfc_debug
*debug
;
1065 debug
= file
->private_data
;
1072 pos
= file
->f_pos
+ off
;
1075 pos
= debug
->len
- off
;
1077 return (pos
< 0 || pos
> debug
->len
) ? -EINVAL
: (file
->f_pos
= pos
);
1081 * lpfc_debugfs_read - Read a debugfs file
1082 * @file: The file pointer to read from.
1083 * @buf: The buffer to copy the data to.
1084 * @nbytes: The number of bytes to read.
1085 * @ppos: The position in the file to start reading from.
1088 * This routine reads data from from the buffer indicated in the private_data
1089 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1093 * This function returns the amount of data that was read (this could be less
1094 * than @nbytes if the end of the file was reached) or a negative error value.
1097 lpfc_debugfs_read(struct file
*file
, char __user
*buf
,
1098 size_t nbytes
, loff_t
*ppos
)
1100 struct lpfc_debug
*debug
= file
->private_data
;
1101 return simple_read_from_buffer(buf
, nbytes
, ppos
, debug
->buffer
,
1106 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1107 * @inode: The inode pointer that contains a vport pointer. (unused)
1108 * @file: The file pointer that contains the buffer to release.
1111 * This routine frees the buffer that was allocated when the debugfs file was
1115 * This function returns zero.
1118 lpfc_debugfs_release(struct inode
*inode
, struct file
*file
)
1120 struct lpfc_debug
*debug
= file
->private_data
;
1122 kfree(debug
->buffer
);
1129 lpfc_debugfs_dumpDataDif_release(struct inode
*inode
, struct file
*file
)
1131 struct lpfc_debug
*debug
= file
->private_data
;
1133 debug
->buffer
= NULL
;
1139 #undef lpfc_debugfs_op_disc_trc
1140 static const struct file_operations lpfc_debugfs_op_disc_trc
= {
1141 .owner
= THIS_MODULE
,
1142 .open
= lpfc_debugfs_disc_trc_open
,
1143 .llseek
= lpfc_debugfs_lseek
,
1144 .read
= lpfc_debugfs_read
,
1145 .release
= lpfc_debugfs_release
,
1148 #undef lpfc_debugfs_op_nodelist
1149 static const struct file_operations lpfc_debugfs_op_nodelist
= {
1150 .owner
= THIS_MODULE
,
1151 .open
= lpfc_debugfs_nodelist_open
,
1152 .llseek
= lpfc_debugfs_lseek
,
1153 .read
= lpfc_debugfs_read
,
1154 .release
= lpfc_debugfs_release
,
1157 #undef lpfc_debugfs_op_hbqinfo
1158 static const struct file_operations lpfc_debugfs_op_hbqinfo
= {
1159 .owner
= THIS_MODULE
,
1160 .open
= lpfc_debugfs_hbqinfo_open
,
1161 .llseek
= lpfc_debugfs_lseek
,
1162 .read
= lpfc_debugfs_read
,
1163 .release
= lpfc_debugfs_release
,
1166 #undef lpfc_debugfs_op_dumpHBASlim
1167 static const struct file_operations lpfc_debugfs_op_dumpHBASlim
= {
1168 .owner
= THIS_MODULE
,
1169 .open
= lpfc_debugfs_dumpHBASlim_open
,
1170 .llseek
= lpfc_debugfs_lseek
,
1171 .read
= lpfc_debugfs_read
,
1172 .release
= lpfc_debugfs_release
,
1175 #undef lpfc_debugfs_op_dumpHostSlim
1176 static const struct file_operations lpfc_debugfs_op_dumpHostSlim
= {
1177 .owner
= THIS_MODULE
,
1178 .open
= lpfc_debugfs_dumpHostSlim_open
,
1179 .llseek
= lpfc_debugfs_lseek
,
1180 .read
= lpfc_debugfs_read
,
1181 .release
= lpfc_debugfs_release
,
1184 #undef lpfc_debugfs_op_dumpData
1185 static const struct file_operations lpfc_debugfs_op_dumpData
= {
1186 .owner
= THIS_MODULE
,
1187 .open
= lpfc_debugfs_dumpData_open
,
1188 .llseek
= lpfc_debugfs_lseek
,
1189 .read
= lpfc_debugfs_read
,
1190 .write
= lpfc_debugfs_dumpDataDif_write
,
1191 .release
= lpfc_debugfs_dumpDataDif_release
,
1194 #undef lpfc_debugfs_op_dumpDif
1195 static const struct file_operations lpfc_debugfs_op_dumpDif
= {
1196 .owner
= THIS_MODULE
,
1197 .open
= lpfc_debugfs_dumpDif_open
,
1198 .llseek
= lpfc_debugfs_lseek
,
1199 .read
= lpfc_debugfs_read
,
1200 .write
= lpfc_debugfs_dumpDataDif_write
,
1201 .release
= lpfc_debugfs_dumpDataDif_release
,
1204 #undef lpfc_debugfs_op_slow_ring_trc
1205 static const struct file_operations lpfc_debugfs_op_slow_ring_trc
= {
1206 .owner
= THIS_MODULE
,
1207 .open
= lpfc_debugfs_slow_ring_trc_open
,
1208 .llseek
= lpfc_debugfs_lseek
,
1209 .read
= lpfc_debugfs_read
,
1210 .release
= lpfc_debugfs_release
,
1213 static struct dentry
*lpfc_debugfs_root
= NULL
;
1214 static atomic_t lpfc_debugfs_hba_count
;
1218 * lpfc_debugfs_initialize - Initialize debugfs for a vport
1219 * @vport: The vport pointer to initialize.
1222 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1223 * If not already created, this routine will create the lpfc directory, and
1224 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1225 * also create each file used to access lpfc specific debugfs information.
1228 lpfc_debugfs_initialize(struct lpfc_vport
*vport
)
1230 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1231 struct lpfc_hba
*phba
= vport
->phba
;
1235 if (!lpfc_debugfs_enable
)
1238 /* Setup lpfc root directory */
1239 if (!lpfc_debugfs_root
) {
1240 lpfc_debugfs_root
= debugfs_create_dir("lpfc", NULL
);
1241 atomic_set(&lpfc_debugfs_hba_count
, 0);
1242 if (!lpfc_debugfs_root
) {
1243 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1244 "0408 Cannot create debugfs root\n");
1248 if (!lpfc_debugfs_start_time
)
1249 lpfc_debugfs_start_time
= jiffies
;
1251 /* Setup lpfcX directory for specific HBA */
1252 snprintf(name
, sizeof(name
), "lpfc%d", phba
->brd_no
);
1253 if (!phba
->hba_debugfs_root
) {
1254 phba
->hba_debugfs_root
=
1255 debugfs_create_dir(name
, lpfc_debugfs_root
);
1256 if (!phba
->hba_debugfs_root
) {
1257 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1258 "0412 Cannot create debugfs hba\n");
1261 atomic_inc(&lpfc_debugfs_hba_count
);
1262 atomic_set(&phba
->debugfs_vport_count
, 0);
1265 snprintf(name
, sizeof(name
), "hbqinfo");
1266 phba
->debug_hbqinfo
=
1267 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1268 phba
->hba_debugfs_root
,
1269 phba
, &lpfc_debugfs_op_hbqinfo
);
1270 if (!phba
->debug_hbqinfo
) {
1271 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1272 "0411 Cannot create debugfs hbqinfo\n");
1276 /* Setup dumpHBASlim */
1277 snprintf(name
, sizeof(name
), "dumpHBASlim");
1278 phba
->debug_dumpHBASlim
=
1279 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1280 phba
->hba_debugfs_root
,
1281 phba
, &lpfc_debugfs_op_dumpHBASlim
);
1282 if (!phba
->debug_dumpHBASlim
) {
1283 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1284 "0413 Cannot create debugfs dumpHBASlim\n");
1288 /* Setup dumpHostSlim */
1289 snprintf(name
, sizeof(name
), "dumpHostSlim");
1290 phba
->debug_dumpHostSlim
=
1291 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1292 phba
->hba_debugfs_root
,
1293 phba
, &lpfc_debugfs_op_dumpHostSlim
);
1294 if (!phba
->debug_dumpHostSlim
) {
1295 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1296 "0414 Cannot create debugfs dumpHostSlim\n");
1300 /* Setup dumpData */
1301 snprintf(name
, sizeof(name
), "dumpData");
1302 phba
->debug_dumpData
=
1303 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1304 phba
->hba_debugfs_root
,
1305 phba
, &lpfc_debugfs_op_dumpData
);
1306 if (!phba
->debug_dumpData
) {
1307 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1308 "0800 Cannot create debugfs dumpData\n");
1313 snprintf(name
, sizeof(name
), "dumpDif");
1314 phba
->debug_dumpDif
=
1315 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1316 phba
->hba_debugfs_root
,
1317 phba
, &lpfc_debugfs_op_dumpDif
);
1318 if (!phba
->debug_dumpDif
) {
1319 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1320 "0801 Cannot create debugfs dumpDif\n");
1326 /* Setup slow ring trace */
1327 if (lpfc_debugfs_max_slow_ring_trc
) {
1328 num
= lpfc_debugfs_max_slow_ring_trc
- 1;
1329 if (num
& lpfc_debugfs_max_slow_ring_trc
) {
1330 /* Change to be a power of 2 */
1331 num
= lpfc_debugfs_max_slow_ring_trc
;
1337 lpfc_debugfs_max_slow_ring_trc
= (1 << i
);
1339 "lpfc_debugfs_max_disc_trc changed to "
1340 "%d\n", lpfc_debugfs_max_disc_trc
);
1345 snprintf(name
, sizeof(name
), "slow_ring_trace");
1346 phba
->debug_slow_ring_trc
=
1347 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1348 phba
->hba_debugfs_root
,
1349 phba
, &lpfc_debugfs_op_slow_ring_trc
);
1350 if (!phba
->debug_slow_ring_trc
) {
1351 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1352 "0415 Cannot create debugfs "
1353 "slow_ring_trace\n");
1356 if (!phba
->slow_ring_trc
) {
1357 phba
->slow_ring_trc
= kmalloc(
1358 (sizeof(struct lpfc_debugfs_trc
) *
1359 lpfc_debugfs_max_slow_ring_trc
),
1361 if (!phba
->slow_ring_trc
) {
1362 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1363 "0416 Cannot create debugfs "
1364 "slow_ring buffer\n");
1367 atomic_set(&phba
->slow_ring_trc_cnt
, 0);
1368 memset(phba
->slow_ring_trc
, 0,
1369 (sizeof(struct lpfc_debugfs_trc
) *
1370 lpfc_debugfs_max_slow_ring_trc
));
1374 snprintf(name
, sizeof(name
), "vport%d", vport
->vpi
);
1375 if (!vport
->vport_debugfs_root
) {
1376 vport
->vport_debugfs_root
=
1377 debugfs_create_dir(name
, phba
->hba_debugfs_root
);
1378 if (!vport
->vport_debugfs_root
) {
1379 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1380 "0417 Cant create debugfs");
1383 atomic_inc(&phba
->debugfs_vport_count
);
1386 if (lpfc_debugfs_max_disc_trc
) {
1387 num
= lpfc_debugfs_max_disc_trc
- 1;
1388 if (num
& lpfc_debugfs_max_disc_trc
) {
1389 /* Change to be a power of 2 */
1390 num
= lpfc_debugfs_max_disc_trc
;
1396 lpfc_debugfs_max_disc_trc
= (1 << i
);
1398 "lpfc_debugfs_max_disc_trc changed to %d\n",
1399 lpfc_debugfs_max_disc_trc
);
1403 vport
->disc_trc
= kzalloc(
1404 (sizeof(struct lpfc_debugfs_trc
) * lpfc_debugfs_max_disc_trc
),
1407 if (!vport
->disc_trc
) {
1408 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1409 "0418 Cannot create debugfs disc trace "
1413 atomic_set(&vport
->disc_trc_cnt
, 0);
1415 snprintf(name
, sizeof(name
), "discovery_trace");
1416 vport
->debug_disc_trc
=
1417 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1418 vport
->vport_debugfs_root
,
1419 vport
, &lpfc_debugfs_op_disc_trc
);
1420 if (!vport
->debug_disc_trc
) {
1421 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1422 "0419 Cannot create debugfs "
1423 "discovery_trace\n");
1426 snprintf(name
, sizeof(name
), "nodelist");
1427 vport
->debug_nodelist
=
1428 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1429 vport
->vport_debugfs_root
,
1430 vport
, &lpfc_debugfs_op_nodelist
);
1431 if (!vport
->debug_nodelist
) {
1432 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1433 "0409 Cant create debugfs nodelist");
1442 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
1443 * @vport: The vport pointer to remove from debugfs.
1446 * When Debugfs is configured this routine removes debugfs file system elements
1447 * that are specific to this vport. It also checks to see if there are any
1448 * users left for the debugfs directories associated with the HBA and driver. If
1449 * this is the last user of the HBA directory or driver directory then it will
1450 * remove those from the debugfs infrastructure as well.
1453 lpfc_debugfs_terminate(struct lpfc_vport
*vport
)
1455 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1456 struct lpfc_hba
*phba
= vport
->phba
;
1458 if (vport
->disc_trc
) {
1459 kfree(vport
->disc_trc
);
1460 vport
->disc_trc
= NULL
;
1462 if (vport
->debug_disc_trc
) {
1463 debugfs_remove(vport
->debug_disc_trc
); /* discovery_trace */
1464 vport
->debug_disc_trc
= NULL
;
1466 if (vport
->debug_nodelist
) {
1467 debugfs_remove(vport
->debug_nodelist
); /* nodelist */
1468 vport
->debug_nodelist
= NULL
;
1471 if (vport
->vport_debugfs_root
) {
1472 debugfs_remove(vport
->vport_debugfs_root
); /* vportX */
1473 vport
->vport_debugfs_root
= NULL
;
1474 atomic_dec(&phba
->debugfs_vport_count
);
1476 if (atomic_read(&phba
->debugfs_vport_count
) == 0) {
1478 if (phba
->debug_hbqinfo
) {
1479 debugfs_remove(phba
->debug_hbqinfo
); /* hbqinfo */
1480 phba
->debug_hbqinfo
= NULL
;
1482 if (phba
->debug_dumpHBASlim
) {
1483 debugfs_remove(phba
->debug_dumpHBASlim
); /* HBASlim */
1484 phba
->debug_dumpHBASlim
= NULL
;
1486 if (phba
->debug_dumpHostSlim
) {
1487 debugfs_remove(phba
->debug_dumpHostSlim
); /* HostSlim */
1488 phba
->debug_dumpHostSlim
= NULL
;
1490 if (phba
->debug_dumpData
) {
1491 debugfs_remove(phba
->debug_dumpData
); /* dumpData */
1492 phba
->debug_dumpData
= NULL
;
1495 if (phba
->debug_dumpDif
) {
1496 debugfs_remove(phba
->debug_dumpDif
); /* dumpDif */
1497 phba
->debug_dumpDif
= NULL
;
1500 if (phba
->slow_ring_trc
) {
1501 kfree(phba
->slow_ring_trc
);
1502 phba
->slow_ring_trc
= NULL
;
1504 if (phba
->debug_slow_ring_trc
) {
1505 /* slow_ring_trace */
1506 debugfs_remove(phba
->debug_slow_ring_trc
);
1507 phba
->debug_slow_ring_trc
= NULL
;
1510 if (phba
->hba_debugfs_root
) {
1511 debugfs_remove(phba
->hba_debugfs_root
); /* lpfcX */
1512 phba
->hba_debugfs_root
= NULL
;
1513 atomic_dec(&lpfc_debugfs_hba_count
);
1516 if (atomic_read(&lpfc_debugfs_hba_count
) == 0) {
1517 debugfs_remove(lpfc_debugfs_root
); /* lpfc */
1518 lpfc_debugfs_root
= NULL
;