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/slab.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
30 #include <linux/ctype.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>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
48 #include "lpfc_version.h"
49 #include "lpfc_compat.h"
50 #include "lpfc_debugfs.h"
52 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
56 * To access this interface the user should:
57 * # mount -t debugfs none /sys/kernel/debug
59 * The lpfc debugfs directory hierarchy is:
61 * where X is the lpfc hba unique_id
62 * where Y is the vport VPI on that hba
64 * Debugging services available per vport:
66 * This is an ACSII readable file that contains a trace of the last
67 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
68 * See lpfc_debugfs.h for different categories of discovery events.
69 * To enable the discovery trace, the following module parameters must be set:
70 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
71 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
72 * EACH vport. X MUST also be a power of 2.
73 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
77 * This is an ACSII readable file that contains a trace of the last
78 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
79 * To enable the slow ring trace, the following module parameters must be set:
80 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
81 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
82 * the HBA. X MUST also be a power of 2.
84 static int lpfc_debugfs_enable
= 1;
85 module_param(lpfc_debugfs_enable
, int, 0);
86 MODULE_PARM_DESC(lpfc_debugfs_enable
, "Enable debugfs services");
88 /* This MUST be a power of 2 */
89 static int lpfc_debugfs_max_disc_trc
;
90 module_param(lpfc_debugfs_max_disc_trc
, int, 0);
91 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc
,
92 "Set debugfs discovery trace depth");
94 /* This MUST be a power of 2 */
95 static int lpfc_debugfs_max_slow_ring_trc
;
96 module_param(lpfc_debugfs_max_slow_ring_trc
, int, 0);
97 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc
,
98 "Set debugfs slow ring trace depth");
100 static int lpfc_debugfs_mask_disc_trc
;
101 module_param(lpfc_debugfs_mask_disc_trc
, int, 0);
102 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc
,
103 "Set debugfs discovery trace mask");
105 #include <linux/debugfs.h>
107 /* size of output line, for discovery_trace and slow_ring_trace */
108 #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
110 /* nodelist output buffer size */
111 #define LPFC_NODELIST_SIZE 8192
112 #define LPFC_NODELIST_ENTRY_SIZE 120
114 /* dumpHBASlim output buffer size */
115 #define LPFC_DUMPHBASLIM_SIZE 4096
117 /* dumpHostSlim output buffer size */
118 #define LPFC_DUMPHOSTSLIM_SIZE 4096
120 /* hbqinfo output buffer size */
121 #define LPFC_HBQINFO_SIZE 8192
128 static atomic_t lpfc_debugfs_seq_trc_cnt
= ATOMIC_INIT(0);
129 static unsigned long lpfc_debugfs_start_time
= 0L;
132 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
133 * @vport: The vport to gather the log info from.
134 * @buf: The buffer to dump log into.
135 * @size: The maximum amount of data to process.
138 * This routine gathers the lpfc discovery debugfs data from the @vport and
139 * dumps it to @buf up to @size number of bytes. It will start at the next entry
140 * in the log and process the log until the end of the buffer. Then it will
141 * gather from the beginning of the log and process until the current entry.
144 * Discovery logging will be disabled while while this routine dumps the log.
147 * This routine returns the amount of bytes that were dumped into @buf and will
151 lpfc_debugfs_disc_trc_data(struct lpfc_vport
*vport
, char *buf
, int size
)
153 int i
, index
, len
, enable
;
155 struct lpfc_debugfs_trc
*dtp
;
156 char buffer
[LPFC_DEBUG_TRC_ENTRY_SIZE
];
158 enable
= lpfc_debugfs_enable
;
159 lpfc_debugfs_enable
= 0;
162 index
= (atomic_read(&vport
->disc_trc_cnt
) + 1) &
163 (lpfc_debugfs_max_disc_trc
- 1);
164 for (i
= index
; i
< lpfc_debugfs_max_disc_trc
; i
++) {
165 dtp
= vport
->disc_trc
+ i
;
168 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
170 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
171 dtp
->seq_cnt
, ms
, dtp
->fmt
);
172 len
+= snprintf(buf
+len
, size
-len
, buffer
,
173 dtp
->data1
, dtp
->data2
, dtp
->data3
);
175 for (i
= 0; i
< index
; i
++) {
176 dtp
= vport
->disc_trc
+ i
;
179 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
181 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
182 dtp
->seq_cnt
, ms
, dtp
->fmt
);
183 len
+= snprintf(buf
+len
, size
-len
, buffer
,
184 dtp
->data1
, dtp
->data2
, dtp
->data3
);
187 lpfc_debugfs_enable
= enable
;
192 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
193 * @phba: The HBA to gather the log info from.
194 * @buf: The buffer to dump log into.
195 * @size: The maximum amount of data to process.
198 * This routine gathers the lpfc slow ring debugfs data from the @phba and
199 * dumps it to @buf up to @size number of bytes. It will start at the next entry
200 * in the log and process the log until the end of the buffer. Then it will
201 * gather from the beginning of the log and process until the current entry.
204 * Slow ring logging will be disabled while while this routine dumps the log.
207 * This routine returns the amount of bytes that were dumped into @buf and will
211 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba
*phba
, char *buf
, int size
)
213 int i
, index
, len
, enable
;
215 struct lpfc_debugfs_trc
*dtp
;
216 char buffer
[LPFC_DEBUG_TRC_ENTRY_SIZE
];
219 enable
= lpfc_debugfs_enable
;
220 lpfc_debugfs_enable
= 0;
223 index
= (atomic_read(&phba
->slow_ring_trc_cnt
) + 1) &
224 (lpfc_debugfs_max_slow_ring_trc
- 1);
225 for (i
= index
; i
< lpfc_debugfs_max_slow_ring_trc
; i
++) {
226 dtp
= phba
->slow_ring_trc
+ i
;
229 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
231 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
232 dtp
->seq_cnt
, ms
, dtp
->fmt
);
233 len
+= snprintf(buf
+len
, size
-len
, buffer
,
234 dtp
->data1
, dtp
->data2
, dtp
->data3
);
236 for (i
= 0; i
< index
; i
++) {
237 dtp
= phba
->slow_ring_trc
+ i
;
240 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
242 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
243 dtp
->seq_cnt
, ms
, dtp
->fmt
);
244 len
+= snprintf(buf
+len
, size
-len
, buffer
,
245 dtp
->data1
, dtp
->data2
, dtp
->data3
);
248 lpfc_debugfs_enable
= enable
;
252 static int lpfc_debugfs_last_hbq
= -1;
255 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
256 * @phba: The HBA to gather host buffer info from.
257 * @buf: The buffer to dump log into.
258 * @size: The maximum amount of data to process.
261 * This routine dumps the host buffer queue info from the @phba to @buf up to
262 * @size number of bytes. A header that describes the current hbq state will be
263 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
264 * until @size bytes have been dumped or all the hbq info has been dumped.
267 * This routine will rotate through each configured HBQ each time called.
270 * This routine returns the amount of bytes that were dumped into @buf and will
274 lpfc_debugfs_hbqinfo_data(struct lpfc_hba
*phba
, char *buf
, int size
)
277 int cnt
, i
, j
, found
, posted
, low
;
278 uint32_t phys
, raw_index
, getidx
;
279 struct lpfc_hbq_init
*hip
;
281 struct lpfc_hbq_entry
*hbqe
;
282 struct lpfc_dmabuf
*d_buf
;
283 struct hbq_dmabuf
*hbq_buf
;
285 if (phba
->sli_rev
!= 3)
287 cnt
= LPFC_HBQINFO_SIZE
;
288 spin_lock_irq(&phba
->hbalock
);
290 /* toggle between multiple hbqs, if any */
291 i
= lpfc_sli_hbq_count();
293 lpfc_debugfs_last_hbq
++;
294 if (lpfc_debugfs_last_hbq
>= i
)
295 lpfc_debugfs_last_hbq
= 0;
298 lpfc_debugfs_last_hbq
= 0;
300 i
= lpfc_debugfs_last_hbq
;
302 len
+= snprintf(buf
+len
, size
-len
, "HBQ %d Info\n", i
);
304 hbqs
= &phba
->hbqs
[i
];
306 list_for_each_entry(d_buf
, &hbqs
->hbq_buffer_list
, list
)
309 hip
= lpfc_hbq_defs
[i
];
310 len
+= snprintf(buf
+len
, size
-len
,
311 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
312 hip
->hbq_index
, hip
->profile
, hip
->rn
,
313 hip
->buffer_count
, hip
->init_count
, hip
->add_count
, posted
);
315 raw_index
= phba
->hbq_get
[i
];
316 getidx
= le32_to_cpu(raw_index
);
317 len
+= snprintf(buf
+len
, size
-len
,
318 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
319 hbqs
->entry_count
, hbqs
->buffer_count
, hbqs
->hbqPutIdx
,
320 hbqs
->next_hbqPutIdx
, hbqs
->local_hbqGetIdx
, getidx
);
322 hbqe
= (struct lpfc_hbq_entry
*) phba
->hbqs
[i
].hbq_virt
;
323 for (j
=0; j
<hbqs
->entry_count
; j
++) {
324 len
+= snprintf(buf
+len
, size
-len
,
325 "%03d: %08x %04x %05x ", j
,
326 le32_to_cpu(hbqe
->bde
.addrLow
),
327 le32_to_cpu(hbqe
->bde
.tus
.w
),
328 le32_to_cpu(hbqe
->buffer_tag
));
332 /* First calculate if slot has an associated posted buffer */
333 low
= hbqs
->hbqPutIdx
- posted
;
335 if ((j
>= hbqs
->hbqPutIdx
) || (j
< low
)) {
336 len
+= snprintf(buf
+len
, size
-len
, "Unused\n");
341 if ((j
>= hbqs
->hbqPutIdx
) &&
342 (j
< (hbqs
->entry_count
+low
))) {
343 len
+= snprintf(buf
+len
, size
-len
, "Unused\n");
348 /* Get the Buffer info for the posted buffer */
349 list_for_each_entry(d_buf
, &hbqs
->hbq_buffer_list
, list
) {
350 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
351 phys
= ((uint64_t)hbq_buf
->dbuf
.phys
& 0xffffffff);
352 if (phys
== le32_to_cpu(hbqe
->bde
.addrLow
)) {
353 len
+= snprintf(buf
+len
, size
-len
,
354 "Buf%d: %p %06x\n", i
,
355 hbq_buf
->dbuf
.virt
, hbq_buf
->tag
);
362 len
+= snprintf(buf
+len
, size
-len
, "No DMAinfo?\n");
366 if (len
> LPFC_HBQINFO_SIZE
- 54)
369 spin_unlock_irq(&phba
->hbalock
);
373 static int lpfc_debugfs_last_hba_slim_off
;
376 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
377 * @phba: The HBA to gather SLIM info from.
378 * @buf: The buffer to dump log into.
379 * @size: The maximum amount of data to process.
382 * This routine dumps the current contents of HBA SLIM for the HBA associated
383 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
386 * This routine will only dump up to 1024 bytes of data each time called and
387 * should be called multiple times to dump the entire HBA SLIM.
390 * This routine returns the amount of bytes that were dumped into @buf and will
394 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba
*phba
, char *buf
, int size
)
402 spin_lock_irq(&phba
->hbalock
);
404 len
+= snprintf(buf
+len
, size
-len
, "HBA SLIM\n");
405 lpfc_memcpy_from_slim(buffer
,
406 phba
->MBslimaddr
+ lpfc_debugfs_last_hba_slim_off
, 1024);
408 ptr
= (uint32_t *)&buffer
[0];
409 off
= lpfc_debugfs_last_hba_slim_off
;
411 /* Set it up for the next time */
412 lpfc_debugfs_last_hba_slim_off
+= 1024;
413 if (lpfc_debugfs_last_hba_slim_off
>= 4096)
414 lpfc_debugfs_last_hba_slim_off
= 0;
418 len
+= snprintf(buf
+len
, size
-len
,
419 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
420 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
421 *(ptr
+5), *(ptr
+6), *(ptr
+7));
423 i
-= (8 * sizeof(uint32_t));
424 off
+= (8 * sizeof(uint32_t));
427 spin_unlock_irq(&phba
->hbalock
);
432 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
433 * @phba: The HBA to gather Host SLIM info from.
434 * @buf: The buffer to dump log into.
435 * @size: The maximum amount of data to process.
438 * This routine dumps the current contents of host SLIM for the host associated
439 * with @phba to @buf up to @size bytes of data. The dump will contain the
440 * Mailbox, PCB, Rings, and Registers that are located in host memory.
443 * This routine returns the amount of bytes that were dumped into @buf and will
447 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba
*phba
, char *buf
, int size
)
451 uint32_t word0
, word1
, word2
, word3
;
453 struct lpfc_pgp
*pgpp
;
454 struct lpfc_sli
*psli
= &phba
->sli
;
455 struct lpfc_sli_ring
*pring
;
458 spin_lock_irq(&phba
->hbalock
);
460 len
+= snprintf(buf
+len
, size
-len
, "SLIM Mailbox\n");
461 ptr
= (uint32_t *)phba
->slim2p
.virt
;
462 i
= sizeof(MAILBOX_t
);
464 len
+= snprintf(buf
+len
, size
-len
,
465 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
466 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
467 *(ptr
+5), *(ptr
+6), *(ptr
+7));
469 i
-= (8 * sizeof(uint32_t));
470 off
+= (8 * sizeof(uint32_t));
473 len
+= snprintf(buf
+len
, size
-len
, "SLIM PCB\n");
474 ptr
= (uint32_t *)phba
->pcb
;
477 len
+= snprintf(buf
+len
, size
-len
,
478 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
479 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
480 *(ptr
+5), *(ptr
+6), *(ptr
+7));
482 i
-= (8 * sizeof(uint32_t));
483 off
+= (8 * sizeof(uint32_t));
486 for (i
= 0; i
< 4; i
++) {
487 pgpp
= &phba
->port_gp
[i
];
488 pring
= &psli
->ring
[i
];
489 len
+= snprintf(buf
+len
, size
-len
,
490 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
491 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
492 i
, pgpp
->cmdGetInx
, pring
->numCiocb
,
493 pring
->next_cmdidx
, pring
->local_getidx
,
494 pring
->flag
, pgpp
->rspPutInx
, pring
->numRiocb
);
497 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
498 word0
= readl(phba
->HAregaddr
);
499 word1
= readl(phba
->CAregaddr
);
500 word2
= readl(phba
->HSregaddr
);
501 word3
= readl(phba
->HCregaddr
);
502 len
+= snprintf(buf
+len
, size
-len
, "HA:%08x CA:%08x HS:%08x "
503 "HC:%08x\n", word0
, word1
, word2
, word3
);
505 spin_unlock_irq(&phba
->hbalock
);
510 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
511 * @vport: The vport to gather target node info from.
512 * @buf: The buffer to dump log into.
513 * @size: The maximum amount of data to process.
516 * This routine dumps the current target node list associated with @vport to
517 * @buf up to @size bytes of data. Each node entry in the dump will contain a
518 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
521 * This routine returns the amount of bytes that were dumped into @buf and will
525 lpfc_debugfs_nodelist_data(struct lpfc_vport
*vport
, char *buf
, int size
)
529 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
530 struct lpfc_nodelist
*ndlp
;
531 unsigned char *statep
, *name
;
533 cnt
= (LPFC_NODELIST_SIZE
/ LPFC_NODELIST_ENTRY_SIZE
);
535 spin_lock_irq(shost
->host_lock
);
536 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
538 len
+= snprintf(buf
+len
, size
-len
,
539 "Missing Nodelist Entries\n");
543 switch (ndlp
->nlp_state
) {
544 case NLP_STE_UNUSED_NODE
:
547 case NLP_STE_PLOGI_ISSUE
:
550 case NLP_STE_ADISC_ISSUE
:
553 case NLP_STE_REG_LOGIN_ISSUE
:
556 case NLP_STE_PRLI_ISSUE
:
559 case NLP_STE_UNMAPPED_NODE
:
562 case NLP_STE_MAPPED_NODE
:
565 case NLP_STE_NPR_NODE
:
571 len
+= snprintf(buf
+len
, size
-len
, "%s DID:x%06x ",
572 statep
, ndlp
->nlp_DID
);
573 name
= (unsigned char *)&ndlp
->nlp_portname
;
574 len
+= snprintf(buf
+len
, size
-len
,
575 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
576 *name
, *(name
+1), *(name
+2), *(name
+3),
577 *(name
+4), *(name
+5), *(name
+6), *(name
+7));
578 name
= (unsigned char *)&ndlp
->nlp_nodename
;
579 len
+= snprintf(buf
+len
, size
-len
,
580 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
581 *name
, *(name
+1), *(name
+2), *(name
+3),
582 *(name
+4), *(name
+5), *(name
+6), *(name
+7));
583 len
+= snprintf(buf
+len
, size
-len
, "RPI:%03d flag:x%08x ",
584 ndlp
->nlp_rpi
, ndlp
->nlp_flag
);
586 len
+= snprintf(buf
+len
, size
-len
, "UNKNOWN_TYPE ");
587 if (ndlp
->nlp_type
& NLP_FC_NODE
)
588 len
+= snprintf(buf
+len
, size
-len
, "FC_NODE ");
589 if (ndlp
->nlp_type
& NLP_FABRIC
)
590 len
+= snprintf(buf
+len
, size
-len
, "FABRIC ");
591 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
592 len
+= snprintf(buf
+len
, size
-len
, "FCP_TGT sid:%d ",
594 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
595 len
+= snprintf(buf
+len
, size
-len
, "FCP_INITIATOR ");
596 len
+= snprintf(buf
+len
, size
-len
, "usgmap:%x ",
598 len
+= snprintf(buf
+len
, size
-len
, "refcnt:%x",
599 atomic_read(&ndlp
->kref
.refcount
));
600 len
+= snprintf(buf
+len
, size
-len
, "\n");
602 spin_unlock_irq(shost
->host_lock
);
608 * lpfc_debugfs_disc_trc - Store discovery trace log
609 * @vport: The vport to associate this trace string with for retrieval.
610 * @mask: Log entry classification.
611 * @fmt: Format string to be displayed when dumping the log.
612 * @data1: 1st data parameter to be applied to @fmt.
613 * @data2: 2nd data parameter to be applied to @fmt.
614 * @data3: 3rd data parameter to be applied to @fmt.
617 * This routine is used by the driver code to add a debugfs log entry to the
618 * discovery trace buffer associated with @vport. Only entries with a @mask that
619 * match the current debugfs discovery mask will be saved. Entries that do not
620 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
621 * printf when displaying the log.
624 lpfc_debugfs_disc_trc(struct lpfc_vport
*vport
, int mask
, char *fmt
,
625 uint32_t data1
, uint32_t data2
, uint32_t data3
)
627 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
628 struct lpfc_debugfs_trc
*dtp
;
631 if (!(lpfc_debugfs_mask_disc_trc
& mask
))
634 if (!lpfc_debugfs_enable
|| !lpfc_debugfs_max_disc_trc
||
635 !vport
|| !vport
->disc_trc
)
638 index
= atomic_inc_return(&vport
->disc_trc_cnt
) &
639 (lpfc_debugfs_max_disc_trc
- 1);
640 dtp
= vport
->disc_trc
+ index
;
645 dtp
->seq_cnt
= atomic_inc_return(&lpfc_debugfs_seq_trc_cnt
);
652 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
653 * @phba: The phba to associate this trace string with for retrieval.
654 * @fmt: Format string to be displayed when dumping the log.
655 * @data1: 1st data parameter to be applied to @fmt.
656 * @data2: 2nd data parameter to be applied to @fmt.
657 * @data3: 3rd data parameter to be applied to @fmt.
660 * This routine is used by the driver code to add a debugfs log entry to the
661 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
662 * @data3 are used like printf when displaying the log.
665 lpfc_debugfs_slow_ring_trc(struct lpfc_hba
*phba
, char *fmt
,
666 uint32_t data1
, uint32_t data2
, uint32_t data3
)
668 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
669 struct lpfc_debugfs_trc
*dtp
;
672 if (!lpfc_debugfs_enable
|| !lpfc_debugfs_max_slow_ring_trc
||
673 !phba
|| !phba
->slow_ring_trc
)
676 index
= atomic_inc_return(&phba
->slow_ring_trc_cnt
) &
677 (lpfc_debugfs_max_slow_ring_trc
- 1);
678 dtp
= phba
->slow_ring_trc
+ index
;
683 dtp
->seq_cnt
= atomic_inc_return(&lpfc_debugfs_seq_trc_cnt
);
689 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
691 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
692 * @inode: The inode pointer that contains a vport pointer.
693 * @file: The file pointer to attach the log output.
696 * This routine is the entry point for the debugfs open file operation. It gets
697 * the vport from the i_private field in @inode, allocates the necessary buffer
698 * for the log, fills the buffer from the in-memory log for this vport, and then
699 * returns a pointer to that log in the private_data field in @file.
702 * This function returns zero if successful. On error it will return an negative
706 lpfc_debugfs_disc_trc_open(struct inode
*inode
, struct file
*file
)
708 struct lpfc_vport
*vport
= inode
->i_private
;
709 struct lpfc_debug
*debug
;
713 if (!lpfc_debugfs_max_disc_trc
) {
718 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
722 /* Round to page boundary */
723 size
= (lpfc_debugfs_max_disc_trc
* LPFC_DEBUG_TRC_ENTRY_SIZE
);
724 size
= PAGE_ALIGN(size
);
726 debug
->buffer
= kmalloc(size
, GFP_KERNEL
);
727 if (!debug
->buffer
) {
732 debug
->len
= lpfc_debugfs_disc_trc_data(vport
, debug
->buffer
, size
);
733 file
->private_data
= debug
;
741 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
742 * @inode: The inode pointer that contains a vport pointer.
743 * @file: The file pointer to attach the log output.
746 * This routine is the entry point for the debugfs open file operation. It gets
747 * the vport from the i_private field in @inode, allocates the necessary buffer
748 * for the log, fills the buffer from the in-memory log for this vport, and then
749 * returns a pointer to that log in the private_data field in @file.
752 * This function returns zero if successful. On error it will return an negative
756 lpfc_debugfs_slow_ring_trc_open(struct inode
*inode
, struct file
*file
)
758 struct lpfc_hba
*phba
= inode
->i_private
;
759 struct lpfc_debug
*debug
;
763 if (!lpfc_debugfs_max_slow_ring_trc
) {
768 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
772 /* Round to page boundary */
773 size
= (lpfc_debugfs_max_slow_ring_trc
* LPFC_DEBUG_TRC_ENTRY_SIZE
);
774 size
= PAGE_ALIGN(size
);
776 debug
->buffer
= kmalloc(size
, GFP_KERNEL
);
777 if (!debug
->buffer
) {
782 debug
->len
= lpfc_debugfs_slow_ring_trc_data(phba
, debug
->buffer
, size
);
783 file
->private_data
= debug
;
791 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
792 * @inode: The inode pointer that contains a vport pointer.
793 * @file: The file pointer to attach the log output.
796 * This routine is the entry point for the debugfs open file operation. It gets
797 * the vport from the i_private field in @inode, allocates the necessary buffer
798 * for the log, fills the buffer from the in-memory log for this vport, and then
799 * returns a pointer to that log in the private_data field in @file.
802 * This function returns zero if successful. On error it will return an negative
806 lpfc_debugfs_hbqinfo_open(struct inode
*inode
, struct file
*file
)
808 struct lpfc_hba
*phba
= inode
->i_private
;
809 struct lpfc_debug
*debug
;
812 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
816 /* Round to page boundary */
817 debug
->buffer
= kmalloc(LPFC_HBQINFO_SIZE
, GFP_KERNEL
);
818 if (!debug
->buffer
) {
823 debug
->len
= lpfc_debugfs_hbqinfo_data(phba
, debug
->buffer
,
825 file
->private_data
= debug
;
833 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
834 * @inode: The inode pointer that contains a vport pointer.
835 * @file: The file pointer to attach the log output.
838 * This routine is the entry point for the debugfs open file operation. It gets
839 * the vport from the i_private field in @inode, allocates the necessary buffer
840 * for the log, fills the buffer from the in-memory log for this vport, and then
841 * returns a pointer to that log in the private_data field in @file.
844 * This function returns zero if successful. On error it will return an negative
848 lpfc_debugfs_dumpHBASlim_open(struct inode
*inode
, struct file
*file
)
850 struct lpfc_hba
*phba
= inode
->i_private
;
851 struct lpfc_debug
*debug
;
854 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
858 /* Round to page boundary */
859 debug
->buffer
= kmalloc(LPFC_DUMPHBASLIM_SIZE
, GFP_KERNEL
);
860 if (!debug
->buffer
) {
865 debug
->len
= lpfc_debugfs_dumpHBASlim_data(phba
, debug
->buffer
,
866 LPFC_DUMPHBASLIM_SIZE
);
867 file
->private_data
= debug
;
875 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
876 * @inode: The inode pointer that contains a vport pointer.
877 * @file: The file pointer to attach the log output.
880 * This routine is the entry point for the debugfs open file operation. It gets
881 * the vport from the i_private field in @inode, allocates the necessary buffer
882 * for the log, fills the buffer from the in-memory log for this vport, and then
883 * returns a pointer to that log in the private_data field in @file.
886 * This function returns zero if successful. On error it will return an negative
890 lpfc_debugfs_dumpHostSlim_open(struct inode
*inode
, struct file
*file
)
892 struct lpfc_hba
*phba
= inode
->i_private
;
893 struct lpfc_debug
*debug
;
896 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
900 /* Round to page boundary */
901 debug
->buffer
= kmalloc(LPFC_DUMPHOSTSLIM_SIZE
, GFP_KERNEL
);
902 if (!debug
->buffer
) {
907 debug
->len
= lpfc_debugfs_dumpHostSlim_data(phba
, debug
->buffer
,
908 LPFC_DUMPHOSTSLIM_SIZE
);
909 file
->private_data
= debug
;
917 lpfc_debugfs_dumpData_open(struct inode
*inode
, struct file
*file
)
919 struct lpfc_debug
*debug
;
925 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
929 /* Round to page boundry */
930 printk(KERN_ERR
"9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
931 __func__
, _dump_buf_data
);
932 debug
->buffer
= _dump_buf_data
;
933 if (!debug
->buffer
) {
938 debug
->len
= (1 << _dump_buf_data_order
) << PAGE_SHIFT
;
939 file
->private_data
= debug
;
947 lpfc_debugfs_dumpDif_open(struct inode
*inode
, struct file
*file
)
949 struct lpfc_debug
*debug
;
955 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
959 /* Round to page boundry */
960 printk(KERN_ERR
"9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
961 __func__
, _dump_buf_dif
, file
->f_dentry
->d_name
.name
);
962 debug
->buffer
= _dump_buf_dif
;
963 if (!debug
->buffer
) {
968 debug
->len
= (1 << _dump_buf_dif_order
) << PAGE_SHIFT
;
969 file
->private_data
= debug
;
977 lpfc_debugfs_dumpDataDif_write(struct file
*file
, const char __user
*buf
,
978 size_t nbytes
, loff_t
*ppos
)
981 * The Data/DIF buffers only save one failing IO
982 * The write op is used as a reset mechanism after an IO has
983 * already been saved to the next one can be saved
985 spin_lock(&_dump_buf_lock
);
987 memset((void *)_dump_buf_data
, 0,
988 ((1 << PAGE_SHIFT
) << _dump_buf_data_order
));
989 memset((void *)_dump_buf_dif
, 0,
990 ((1 << PAGE_SHIFT
) << _dump_buf_dif_order
));
994 spin_unlock(&_dump_buf_lock
);
1002 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1003 * @inode: The inode pointer that contains a vport pointer.
1004 * @file: The file pointer to attach the log output.
1007 * This routine is the entry point for the debugfs open file operation. It gets
1008 * the vport from the i_private field in @inode, allocates the necessary buffer
1009 * for the log, fills the buffer from the in-memory log for this vport, and then
1010 * returns a pointer to that log in the private_data field in @file.
1013 * This function returns zero if successful. On error it will return an negative
1017 lpfc_debugfs_nodelist_open(struct inode
*inode
, struct file
*file
)
1019 struct lpfc_vport
*vport
= inode
->i_private
;
1020 struct lpfc_debug
*debug
;
1023 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
1027 /* Round to page boundary */
1028 debug
->buffer
= kmalloc(LPFC_NODELIST_SIZE
, GFP_KERNEL
);
1029 if (!debug
->buffer
) {
1034 debug
->len
= lpfc_debugfs_nodelist_data(vport
, debug
->buffer
,
1035 LPFC_NODELIST_SIZE
);
1036 file
->private_data
= debug
;
1044 * lpfc_debugfs_lseek - Seek through a debugfs file
1045 * @file: The file pointer to seek through.
1046 * @off: The offset to seek to or the amount to seek by.
1047 * @whence: Indicates how to seek.
1050 * This routine is the entry point for the debugfs lseek file operation. The
1051 * @whence parameter indicates whether @off is the offset to directly seek to,
1052 * or if it is a value to seek forward or reverse by. This function figures out
1053 * what the new offset of the debugfs file will be and assigns that value to the
1054 * f_pos field of @file.
1057 * This function returns the new offset if successful and returns a negative
1058 * error if unable to process the seek.
1061 lpfc_debugfs_lseek(struct file
*file
, loff_t off
, int whence
)
1063 struct lpfc_debug
*debug
;
1066 debug
= file
->private_data
;
1073 pos
= file
->f_pos
+ off
;
1076 pos
= debug
->len
- off
;
1078 return (pos
< 0 || pos
> debug
->len
) ? -EINVAL
: (file
->f_pos
= pos
);
1082 * lpfc_debugfs_read - Read a debugfs file
1083 * @file: The file pointer to read from.
1084 * @buf: The buffer to copy the data to.
1085 * @nbytes: The number of bytes to read.
1086 * @ppos: The position in the file to start reading from.
1089 * This routine reads data from from the buffer indicated in the private_data
1090 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1094 * This function returns the amount of data that was read (this could be less
1095 * than @nbytes if the end of the file was reached) or a negative error value.
1098 lpfc_debugfs_read(struct file
*file
, char __user
*buf
,
1099 size_t nbytes
, loff_t
*ppos
)
1101 struct lpfc_debug
*debug
= file
->private_data
;
1102 return simple_read_from_buffer(buf
, nbytes
, ppos
, debug
->buffer
,
1107 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1108 * @inode: The inode pointer that contains a vport pointer. (unused)
1109 * @file: The file pointer that contains the buffer to release.
1112 * This routine frees the buffer that was allocated when the debugfs file was
1116 * This function returns zero.
1119 lpfc_debugfs_release(struct inode
*inode
, struct file
*file
)
1121 struct lpfc_debug
*debug
= file
->private_data
;
1123 kfree(debug
->buffer
);
1130 lpfc_debugfs_dumpDataDif_release(struct inode
*inode
, struct file
*file
)
1132 struct lpfc_debug
*debug
= file
->private_data
;
1134 debug
->buffer
= NULL
;
1140 #undef lpfc_debugfs_op_disc_trc
1141 static const struct file_operations lpfc_debugfs_op_disc_trc
= {
1142 .owner
= THIS_MODULE
,
1143 .open
= lpfc_debugfs_disc_trc_open
,
1144 .llseek
= lpfc_debugfs_lseek
,
1145 .read
= lpfc_debugfs_read
,
1146 .release
= lpfc_debugfs_release
,
1149 #undef lpfc_debugfs_op_nodelist
1150 static const struct file_operations lpfc_debugfs_op_nodelist
= {
1151 .owner
= THIS_MODULE
,
1152 .open
= lpfc_debugfs_nodelist_open
,
1153 .llseek
= lpfc_debugfs_lseek
,
1154 .read
= lpfc_debugfs_read
,
1155 .release
= lpfc_debugfs_release
,
1158 #undef lpfc_debugfs_op_hbqinfo
1159 static const struct file_operations lpfc_debugfs_op_hbqinfo
= {
1160 .owner
= THIS_MODULE
,
1161 .open
= lpfc_debugfs_hbqinfo_open
,
1162 .llseek
= lpfc_debugfs_lseek
,
1163 .read
= lpfc_debugfs_read
,
1164 .release
= lpfc_debugfs_release
,
1167 #undef lpfc_debugfs_op_dumpHBASlim
1168 static const struct file_operations lpfc_debugfs_op_dumpHBASlim
= {
1169 .owner
= THIS_MODULE
,
1170 .open
= lpfc_debugfs_dumpHBASlim_open
,
1171 .llseek
= lpfc_debugfs_lseek
,
1172 .read
= lpfc_debugfs_read
,
1173 .release
= lpfc_debugfs_release
,
1176 #undef lpfc_debugfs_op_dumpHostSlim
1177 static const struct file_operations lpfc_debugfs_op_dumpHostSlim
= {
1178 .owner
= THIS_MODULE
,
1179 .open
= lpfc_debugfs_dumpHostSlim_open
,
1180 .llseek
= lpfc_debugfs_lseek
,
1181 .read
= lpfc_debugfs_read
,
1182 .release
= lpfc_debugfs_release
,
1185 #undef lpfc_debugfs_op_dumpData
1186 static const struct file_operations lpfc_debugfs_op_dumpData
= {
1187 .owner
= THIS_MODULE
,
1188 .open
= lpfc_debugfs_dumpData_open
,
1189 .llseek
= lpfc_debugfs_lseek
,
1190 .read
= lpfc_debugfs_read
,
1191 .write
= lpfc_debugfs_dumpDataDif_write
,
1192 .release
= lpfc_debugfs_dumpDataDif_release
,
1195 #undef lpfc_debugfs_op_dumpDif
1196 static const struct file_operations lpfc_debugfs_op_dumpDif
= {
1197 .owner
= THIS_MODULE
,
1198 .open
= lpfc_debugfs_dumpDif_open
,
1199 .llseek
= lpfc_debugfs_lseek
,
1200 .read
= lpfc_debugfs_read
,
1201 .write
= lpfc_debugfs_dumpDataDif_write
,
1202 .release
= lpfc_debugfs_dumpDataDif_release
,
1205 #undef lpfc_debugfs_op_slow_ring_trc
1206 static const struct file_operations lpfc_debugfs_op_slow_ring_trc
= {
1207 .owner
= THIS_MODULE
,
1208 .open
= lpfc_debugfs_slow_ring_trc_open
,
1209 .llseek
= lpfc_debugfs_lseek
,
1210 .read
= lpfc_debugfs_read
,
1211 .release
= lpfc_debugfs_release
,
1214 static struct dentry
*lpfc_debugfs_root
= NULL
;
1215 static atomic_t lpfc_debugfs_hba_count
;
1219 * lpfc_debugfs_initialize - Initialize debugfs for a vport
1220 * @vport: The vport pointer to initialize.
1223 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1224 * If not already created, this routine will create the lpfc directory, and
1225 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1226 * also create each file used to access lpfc specific debugfs information.
1229 lpfc_debugfs_initialize(struct lpfc_vport
*vport
)
1231 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1232 struct lpfc_hba
*phba
= vport
->phba
;
1236 if (!lpfc_debugfs_enable
)
1239 /* Setup lpfc root directory */
1240 if (!lpfc_debugfs_root
) {
1241 lpfc_debugfs_root
= debugfs_create_dir("lpfc", NULL
);
1242 atomic_set(&lpfc_debugfs_hba_count
, 0);
1243 if (!lpfc_debugfs_root
) {
1244 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1245 "0408 Cannot create debugfs root\n");
1249 if (!lpfc_debugfs_start_time
)
1250 lpfc_debugfs_start_time
= jiffies
;
1252 /* Setup lpfcX directory for specific HBA */
1253 snprintf(name
, sizeof(name
), "lpfc%d", phba
->brd_no
);
1254 if (!phba
->hba_debugfs_root
) {
1255 phba
->hba_debugfs_root
=
1256 debugfs_create_dir(name
, lpfc_debugfs_root
);
1257 if (!phba
->hba_debugfs_root
) {
1258 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1259 "0412 Cannot create debugfs hba\n");
1262 atomic_inc(&lpfc_debugfs_hba_count
);
1263 atomic_set(&phba
->debugfs_vport_count
, 0);
1266 snprintf(name
, sizeof(name
), "hbqinfo");
1267 phba
->debug_hbqinfo
=
1268 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1269 phba
->hba_debugfs_root
,
1270 phba
, &lpfc_debugfs_op_hbqinfo
);
1271 if (!phba
->debug_hbqinfo
) {
1272 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1273 "0411 Cannot create debugfs hbqinfo\n");
1277 /* Setup dumpHBASlim */
1278 snprintf(name
, sizeof(name
), "dumpHBASlim");
1279 phba
->debug_dumpHBASlim
=
1280 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1281 phba
->hba_debugfs_root
,
1282 phba
, &lpfc_debugfs_op_dumpHBASlim
);
1283 if (!phba
->debug_dumpHBASlim
) {
1284 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1285 "0413 Cannot create debugfs dumpHBASlim\n");
1289 /* Setup dumpHostSlim */
1290 snprintf(name
, sizeof(name
), "dumpHostSlim");
1291 phba
->debug_dumpHostSlim
=
1292 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1293 phba
->hba_debugfs_root
,
1294 phba
, &lpfc_debugfs_op_dumpHostSlim
);
1295 if (!phba
->debug_dumpHostSlim
) {
1296 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1297 "0414 Cannot create debugfs dumpHostSlim\n");
1301 /* Setup dumpData */
1302 snprintf(name
, sizeof(name
), "dumpData");
1303 phba
->debug_dumpData
=
1304 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1305 phba
->hba_debugfs_root
,
1306 phba
, &lpfc_debugfs_op_dumpData
);
1307 if (!phba
->debug_dumpData
) {
1308 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1309 "0800 Cannot create debugfs dumpData\n");
1314 snprintf(name
, sizeof(name
), "dumpDif");
1315 phba
->debug_dumpDif
=
1316 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1317 phba
->hba_debugfs_root
,
1318 phba
, &lpfc_debugfs_op_dumpDif
);
1319 if (!phba
->debug_dumpDif
) {
1320 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1321 "0801 Cannot create debugfs dumpDif\n");
1327 /* Setup slow ring trace */
1328 if (lpfc_debugfs_max_slow_ring_trc
) {
1329 num
= lpfc_debugfs_max_slow_ring_trc
- 1;
1330 if (num
& lpfc_debugfs_max_slow_ring_trc
) {
1331 /* Change to be a power of 2 */
1332 num
= lpfc_debugfs_max_slow_ring_trc
;
1338 lpfc_debugfs_max_slow_ring_trc
= (1 << i
);
1340 "lpfc_debugfs_max_disc_trc changed to "
1341 "%d\n", lpfc_debugfs_max_disc_trc
);
1346 snprintf(name
, sizeof(name
), "slow_ring_trace");
1347 phba
->debug_slow_ring_trc
=
1348 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1349 phba
->hba_debugfs_root
,
1350 phba
, &lpfc_debugfs_op_slow_ring_trc
);
1351 if (!phba
->debug_slow_ring_trc
) {
1352 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1353 "0415 Cannot create debugfs "
1354 "slow_ring_trace\n");
1357 if (!phba
->slow_ring_trc
) {
1358 phba
->slow_ring_trc
= kmalloc(
1359 (sizeof(struct lpfc_debugfs_trc
) *
1360 lpfc_debugfs_max_slow_ring_trc
),
1362 if (!phba
->slow_ring_trc
) {
1363 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1364 "0416 Cannot create debugfs "
1365 "slow_ring buffer\n");
1368 atomic_set(&phba
->slow_ring_trc_cnt
, 0);
1369 memset(phba
->slow_ring_trc
, 0,
1370 (sizeof(struct lpfc_debugfs_trc
) *
1371 lpfc_debugfs_max_slow_ring_trc
));
1375 snprintf(name
, sizeof(name
), "vport%d", vport
->vpi
);
1376 if (!vport
->vport_debugfs_root
) {
1377 vport
->vport_debugfs_root
=
1378 debugfs_create_dir(name
, phba
->hba_debugfs_root
);
1379 if (!vport
->vport_debugfs_root
) {
1380 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1381 "0417 Cant create debugfs\n");
1384 atomic_inc(&phba
->debugfs_vport_count
);
1387 if (lpfc_debugfs_max_disc_trc
) {
1388 num
= lpfc_debugfs_max_disc_trc
- 1;
1389 if (num
& lpfc_debugfs_max_disc_trc
) {
1390 /* Change to be a power of 2 */
1391 num
= lpfc_debugfs_max_disc_trc
;
1397 lpfc_debugfs_max_disc_trc
= (1 << i
);
1399 "lpfc_debugfs_max_disc_trc changed to %d\n",
1400 lpfc_debugfs_max_disc_trc
);
1404 vport
->disc_trc
= kzalloc(
1405 (sizeof(struct lpfc_debugfs_trc
) * lpfc_debugfs_max_disc_trc
),
1408 if (!vport
->disc_trc
) {
1409 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1410 "0418 Cannot create debugfs disc trace "
1414 atomic_set(&vport
->disc_trc_cnt
, 0);
1416 snprintf(name
, sizeof(name
), "discovery_trace");
1417 vport
->debug_disc_trc
=
1418 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1419 vport
->vport_debugfs_root
,
1420 vport
, &lpfc_debugfs_op_disc_trc
);
1421 if (!vport
->debug_disc_trc
) {
1422 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1423 "0419 Cannot create debugfs "
1424 "discovery_trace\n");
1427 snprintf(name
, sizeof(name
), "nodelist");
1428 vport
->debug_nodelist
=
1429 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
1430 vport
->vport_debugfs_root
,
1431 vport
, &lpfc_debugfs_op_nodelist
);
1432 if (!vport
->debug_nodelist
) {
1433 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1434 "0409 Cant create debugfs nodelist\n");
1443 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
1444 * @vport: The vport pointer to remove from debugfs.
1447 * When Debugfs is configured this routine removes debugfs file system elements
1448 * that are specific to this vport. It also checks to see if there are any
1449 * users left for the debugfs directories associated with the HBA and driver. If
1450 * this is the last user of the HBA directory or driver directory then it will
1451 * remove those from the debugfs infrastructure as well.
1454 lpfc_debugfs_terminate(struct lpfc_vport
*vport
)
1456 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1457 struct lpfc_hba
*phba
= vport
->phba
;
1459 if (vport
->disc_trc
) {
1460 kfree(vport
->disc_trc
);
1461 vport
->disc_trc
= NULL
;
1463 if (vport
->debug_disc_trc
) {
1464 debugfs_remove(vport
->debug_disc_trc
); /* discovery_trace */
1465 vport
->debug_disc_trc
= NULL
;
1467 if (vport
->debug_nodelist
) {
1468 debugfs_remove(vport
->debug_nodelist
); /* nodelist */
1469 vport
->debug_nodelist
= NULL
;
1472 if (vport
->vport_debugfs_root
) {
1473 debugfs_remove(vport
->vport_debugfs_root
); /* vportX */
1474 vport
->vport_debugfs_root
= NULL
;
1475 atomic_dec(&phba
->debugfs_vport_count
);
1477 if (atomic_read(&phba
->debugfs_vport_count
) == 0) {
1479 if (phba
->debug_hbqinfo
) {
1480 debugfs_remove(phba
->debug_hbqinfo
); /* hbqinfo */
1481 phba
->debug_hbqinfo
= NULL
;
1483 if (phba
->debug_dumpHBASlim
) {
1484 debugfs_remove(phba
->debug_dumpHBASlim
); /* HBASlim */
1485 phba
->debug_dumpHBASlim
= NULL
;
1487 if (phba
->debug_dumpHostSlim
) {
1488 debugfs_remove(phba
->debug_dumpHostSlim
); /* HostSlim */
1489 phba
->debug_dumpHostSlim
= NULL
;
1491 if (phba
->debug_dumpData
) {
1492 debugfs_remove(phba
->debug_dumpData
); /* dumpData */
1493 phba
->debug_dumpData
= NULL
;
1496 if (phba
->debug_dumpDif
) {
1497 debugfs_remove(phba
->debug_dumpDif
); /* dumpDif */
1498 phba
->debug_dumpDif
= NULL
;
1501 if (phba
->slow_ring_trc
) {
1502 kfree(phba
->slow_ring_trc
);
1503 phba
->slow_ring_trc
= NULL
;
1505 if (phba
->debug_slow_ring_trc
) {
1506 /* slow_ring_trace */
1507 debugfs_remove(phba
->debug_slow_ring_trc
);
1508 phba
->debug_slow_ring_trc
= NULL
;
1511 if (phba
->hba_debugfs_root
) {
1512 debugfs_remove(phba
->hba_debugfs_root
); /* lpfcX */
1513 phba
->hba_debugfs_root
= NULL
;
1514 atomic_dec(&lpfc_debugfs_hba_count
);
1517 if (atomic_read(&lpfc_debugfs_hba_count
) == 0) {
1518 debugfs_remove(lpfc_debugfs_root
); /* lpfc */
1519 lpfc_debugfs_root
= NULL
;