1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007-2011 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:
60 * /sys/kernel/debug/lpfc/fnX/vportY
61 * where X is the lpfc hba function 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, S_IRUGO
);
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, S_IRUGO
);
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, S_IRUGO
);
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, S_IRUGO
);
102 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc
,
103 "Set debugfs discovery trace mask");
105 #include <linux/debugfs.h>
107 static atomic_t lpfc_debugfs_seq_trc_cnt
= ATOMIC_INIT(0);
108 static unsigned long lpfc_debugfs_start_time
= 0L;
111 static struct lpfc_idiag idiag
;
114 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
115 * @vport: The vport to gather the log info from.
116 * @buf: The buffer to dump log into.
117 * @size: The maximum amount of data to process.
120 * This routine gathers the lpfc discovery debugfs data from the @vport and
121 * dumps it to @buf up to @size number of bytes. It will start at the next entry
122 * in the log and process the log until the end of the buffer. Then it will
123 * gather from the beginning of the log and process until the current entry.
126 * Discovery logging will be disabled while while this routine dumps the log.
129 * This routine returns the amount of bytes that were dumped into @buf and will
133 lpfc_debugfs_disc_trc_data(struct lpfc_vport
*vport
, char *buf
, int size
)
135 int i
, index
, len
, enable
;
137 struct lpfc_debugfs_trc
*dtp
;
138 char buffer
[LPFC_DEBUG_TRC_ENTRY_SIZE
];
140 enable
= lpfc_debugfs_enable
;
141 lpfc_debugfs_enable
= 0;
144 index
= (atomic_read(&vport
->disc_trc_cnt
) + 1) &
145 (lpfc_debugfs_max_disc_trc
- 1);
146 for (i
= index
; i
< lpfc_debugfs_max_disc_trc
; i
++) {
147 dtp
= vport
->disc_trc
+ i
;
150 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
152 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
153 dtp
->seq_cnt
, ms
, dtp
->fmt
);
154 len
+= snprintf(buf
+len
, size
-len
, buffer
,
155 dtp
->data1
, dtp
->data2
, dtp
->data3
);
157 for (i
= 0; i
< index
; i
++) {
158 dtp
= vport
->disc_trc
+ i
;
161 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
163 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
164 dtp
->seq_cnt
, ms
, dtp
->fmt
);
165 len
+= snprintf(buf
+len
, size
-len
, buffer
,
166 dtp
->data1
, dtp
->data2
, dtp
->data3
);
169 lpfc_debugfs_enable
= enable
;
174 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
175 * @phba: The HBA to gather the log info from.
176 * @buf: The buffer to dump log into.
177 * @size: The maximum amount of data to process.
180 * This routine gathers the lpfc slow ring debugfs data from the @phba and
181 * dumps it to @buf up to @size number of bytes. It will start at the next entry
182 * in the log and process the log until the end of the buffer. Then it will
183 * gather from the beginning of the log and process until the current entry.
186 * Slow ring logging will be disabled while while this routine dumps the log.
189 * This routine returns the amount of bytes that were dumped into @buf and will
193 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba
*phba
, char *buf
, int size
)
195 int i
, index
, len
, enable
;
197 struct lpfc_debugfs_trc
*dtp
;
198 char buffer
[LPFC_DEBUG_TRC_ENTRY_SIZE
];
201 enable
= lpfc_debugfs_enable
;
202 lpfc_debugfs_enable
= 0;
205 index
= (atomic_read(&phba
->slow_ring_trc_cnt
) + 1) &
206 (lpfc_debugfs_max_slow_ring_trc
- 1);
207 for (i
= index
; i
< lpfc_debugfs_max_slow_ring_trc
; i
++) {
208 dtp
= phba
->slow_ring_trc
+ i
;
211 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
213 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
214 dtp
->seq_cnt
, ms
, dtp
->fmt
);
215 len
+= snprintf(buf
+len
, size
-len
, buffer
,
216 dtp
->data1
, dtp
->data2
, dtp
->data3
);
218 for (i
= 0; i
< index
; i
++) {
219 dtp
= phba
->slow_ring_trc
+ i
;
222 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
224 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
225 dtp
->seq_cnt
, ms
, dtp
->fmt
);
226 len
+= snprintf(buf
+len
, size
-len
, buffer
,
227 dtp
->data1
, dtp
->data2
, dtp
->data3
);
230 lpfc_debugfs_enable
= enable
;
234 static int lpfc_debugfs_last_hbq
= -1;
237 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
238 * @phba: The HBA to gather host buffer info from.
239 * @buf: The buffer to dump log into.
240 * @size: The maximum amount of data to process.
243 * This routine dumps the host buffer queue info from the @phba to @buf up to
244 * @size number of bytes. A header that describes the current hbq state will be
245 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
246 * until @size bytes have been dumped or all the hbq info has been dumped.
249 * This routine will rotate through each configured HBQ each time called.
252 * This routine returns the amount of bytes that were dumped into @buf and will
256 lpfc_debugfs_hbqinfo_data(struct lpfc_hba
*phba
, char *buf
, int size
)
259 int cnt
, i
, j
, found
, posted
, low
;
260 uint32_t phys
, raw_index
, getidx
;
261 struct lpfc_hbq_init
*hip
;
263 struct lpfc_hbq_entry
*hbqe
;
264 struct lpfc_dmabuf
*d_buf
;
265 struct hbq_dmabuf
*hbq_buf
;
267 if (phba
->sli_rev
!= 3)
269 cnt
= LPFC_HBQINFO_SIZE
;
270 spin_lock_irq(&phba
->hbalock
);
272 /* toggle between multiple hbqs, if any */
273 i
= lpfc_sli_hbq_count();
275 lpfc_debugfs_last_hbq
++;
276 if (lpfc_debugfs_last_hbq
>= i
)
277 lpfc_debugfs_last_hbq
= 0;
280 lpfc_debugfs_last_hbq
= 0;
282 i
= lpfc_debugfs_last_hbq
;
284 len
+= snprintf(buf
+len
, size
-len
, "HBQ %d Info\n", i
);
286 hbqs
= &phba
->hbqs
[i
];
288 list_for_each_entry(d_buf
, &hbqs
->hbq_buffer_list
, list
)
291 hip
= lpfc_hbq_defs
[i
];
292 len
+= snprintf(buf
+len
, size
-len
,
293 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
294 hip
->hbq_index
, hip
->profile
, hip
->rn
,
295 hip
->buffer_count
, hip
->init_count
, hip
->add_count
, posted
);
297 raw_index
= phba
->hbq_get
[i
];
298 getidx
= le32_to_cpu(raw_index
);
299 len
+= snprintf(buf
+len
, size
-len
,
300 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
301 hbqs
->entry_count
, hbqs
->buffer_count
, hbqs
->hbqPutIdx
,
302 hbqs
->next_hbqPutIdx
, hbqs
->local_hbqGetIdx
, getidx
);
304 hbqe
= (struct lpfc_hbq_entry
*) phba
->hbqs
[i
].hbq_virt
;
305 for (j
=0; j
<hbqs
->entry_count
; j
++) {
306 len
+= snprintf(buf
+len
, size
-len
,
307 "%03d: %08x %04x %05x ", j
,
308 le32_to_cpu(hbqe
->bde
.addrLow
),
309 le32_to_cpu(hbqe
->bde
.tus
.w
),
310 le32_to_cpu(hbqe
->buffer_tag
));
314 /* First calculate if slot has an associated posted buffer */
315 low
= hbqs
->hbqPutIdx
- posted
;
317 if ((j
>= hbqs
->hbqPutIdx
) || (j
< low
)) {
318 len
+= snprintf(buf
+len
, size
-len
, "Unused\n");
323 if ((j
>= hbqs
->hbqPutIdx
) &&
324 (j
< (hbqs
->entry_count
+low
))) {
325 len
+= snprintf(buf
+len
, size
-len
, "Unused\n");
330 /* Get the Buffer info for the posted buffer */
331 list_for_each_entry(d_buf
, &hbqs
->hbq_buffer_list
, list
) {
332 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
333 phys
= ((uint64_t)hbq_buf
->dbuf
.phys
& 0xffffffff);
334 if (phys
== le32_to_cpu(hbqe
->bde
.addrLow
)) {
335 len
+= snprintf(buf
+len
, size
-len
,
336 "Buf%d: %p %06x\n", i
,
337 hbq_buf
->dbuf
.virt
, hbq_buf
->tag
);
344 len
+= snprintf(buf
+len
, size
-len
, "No DMAinfo?\n");
348 if (len
> LPFC_HBQINFO_SIZE
- 54)
351 spin_unlock_irq(&phba
->hbalock
);
355 static int lpfc_debugfs_last_hba_slim_off
;
358 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
359 * @phba: The HBA to gather SLIM info from.
360 * @buf: The buffer to dump log into.
361 * @size: The maximum amount of data to process.
364 * This routine dumps the current contents of HBA SLIM for the HBA associated
365 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
368 * This routine will only dump up to 1024 bytes of data each time called and
369 * should be called multiple times to dump the entire HBA SLIM.
372 * This routine returns the amount of bytes that were dumped into @buf and will
376 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba
*phba
, char *buf
, int size
)
384 spin_lock_irq(&phba
->hbalock
);
386 len
+= snprintf(buf
+len
, size
-len
, "HBA SLIM\n");
387 lpfc_memcpy_from_slim(buffer
,
388 phba
->MBslimaddr
+ lpfc_debugfs_last_hba_slim_off
, 1024);
390 ptr
= (uint32_t *)&buffer
[0];
391 off
= lpfc_debugfs_last_hba_slim_off
;
393 /* Set it up for the next time */
394 lpfc_debugfs_last_hba_slim_off
+= 1024;
395 if (lpfc_debugfs_last_hba_slim_off
>= 4096)
396 lpfc_debugfs_last_hba_slim_off
= 0;
400 len
+= snprintf(buf
+len
, size
-len
,
401 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
402 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
403 *(ptr
+5), *(ptr
+6), *(ptr
+7));
405 i
-= (8 * sizeof(uint32_t));
406 off
+= (8 * sizeof(uint32_t));
409 spin_unlock_irq(&phba
->hbalock
);
414 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
415 * @phba: The HBA to gather Host SLIM info from.
416 * @buf: The buffer to dump log into.
417 * @size: The maximum amount of data to process.
420 * This routine dumps the current contents of host SLIM for the host associated
421 * with @phba to @buf up to @size bytes of data. The dump will contain the
422 * Mailbox, PCB, Rings, and Registers that are located in host memory.
425 * This routine returns the amount of bytes that were dumped into @buf and will
429 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba
*phba
, char *buf
, int size
)
433 uint32_t word0
, word1
, word2
, word3
;
435 struct lpfc_pgp
*pgpp
;
436 struct lpfc_sli
*psli
= &phba
->sli
;
437 struct lpfc_sli_ring
*pring
;
440 spin_lock_irq(&phba
->hbalock
);
442 len
+= snprintf(buf
+len
, size
-len
, "SLIM Mailbox\n");
443 ptr
= (uint32_t *)phba
->slim2p
.virt
;
444 i
= sizeof(MAILBOX_t
);
446 len
+= snprintf(buf
+len
, size
-len
,
447 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
448 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
449 *(ptr
+5), *(ptr
+6), *(ptr
+7));
451 i
-= (8 * sizeof(uint32_t));
452 off
+= (8 * sizeof(uint32_t));
455 len
+= snprintf(buf
+len
, size
-len
, "SLIM PCB\n");
456 ptr
= (uint32_t *)phba
->pcb
;
459 len
+= snprintf(buf
+len
, size
-len
,
460 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
461 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
462 *(ptr
+5), *(ptr
+6), *(ptr
+7));
464 i
-= (8 * sizeof(uint32_t));
465 off
+= (8 * sizeof(uint32_t));
468 for (i
= 0; i
< 4; i
++) {
469 pgpp
= &phba
->port_gp
[i
];
470 pring
= &psli
->ring
[i
];
471 len
+= snprintf(buf
+len
, size
-len
,
472 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
473 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
474 i
, pgpp
->cmdGetInx
, pring
->numCiocb
,
475 pring
->next_cmdidx
, pring
->local_getidx
,
476 pring
->flag
, pgpp
->rspPutInx
, pring
->numRiocb
);
479 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
480 word0
= readl(phba
->HAregaddr
);
481 word1
= readl(phba
->CAregaddr
);
482 word2
= readl(phba
->HSregaddr
);
483 word3
= readl(phba
->HCregaddr
);
484 len
+= snprintf(buf
+len
, size
-len
, "HA:%08x CA:%08x HS:%08x "
485 "HC:%08x\n", word0
, word1
, word2
, word3
);
487 spin_unlock_irq(&phba
->hbalock
);
492 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
493 * @vport: The vport to gather target node info from.
494 * @buf: The buffer to dump log into.
495 * @size: The maximum amount of data to process.
498 * This routine dumps the current target node list associated with @vport to
499 * @buf up to @size bytes of data. Each node entry in the dump will contain a
500 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
503 * This routine returns the amount of bytes that were dumped into @buf and will
507 lpfc_debugfs_nodelist_data(struct lpfc_vport
*vport
, char *buf
, int size
)
511 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
512 struct lpfc_nodelist
*ndlp
;
513 unsigned char *statep
, *name
;
515 cnt
= (LPFC_NODELIST_SIZE
/ LPFC_NODELIST_ENTRY_SIZE
);
517 spin_lock_irq(shost
->host_lock
);
518 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
520 len
+= snprintf(buf
+len
, size
-len
,
521 "Missing Nodelist Entries\n");
525 switch (ndlp
->nlp_state
) {
526 case NLP_STE_UNUSED_NODE
:
529 case NLP_STE_PLOGI_ISSUE
:
532 case NLP_STE_ADISC_ISSUE
:
535 case NLP_STE_REG_LOGIN_ISSUE
:
538 case NLP_STE_PRLI_ISSUE
:
541 case NLP_STE_UNMAPPED_NODE
:
544 case NLP_STE_MAPPED_NODE
:
547 case NLP_STE_NPR_NODE
:
553 len
+= snprintf(buf
+len
, size
-len
, "%s DID:x%06x ",
554 statep
, ndlp
->nlp_DID
);
555 name
= (unsigned char *)&ndlp
->nlp_portname
;
556 len
+= snprintf(buf
+len
, size
-len
,
557 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
558 *name
, *(name
+1), *(name
+2), *(name
+3),
559 *(name
+4), *(name
+5), *(name
+6), *(name
+7));
560 name
= (unsigned char *)&ndlp
->nlp_nodename
;
561 len
+= snprintf(buf
+len
, size
-len
,
562 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
563 *name
, *(name
+1), *(name
+2), *(name
+3),
564 *(name
+4), *(name
+5), *(name
+6), *(name
+7));
565 len
+= snprintf(buf
+len
, size
-len
, "RPI:%03d flag:x%08x ",
566 ndlp
->nlp_rpi
, ndlp
->nlp_flag
);
568 len
+= snprintf(buf
+len
, size
-len
, "UNKNOWN_TYPE ");
569 if (ndlp
->nlp_type
& NLP_FC_NODE
)
570 len
+= snprintf(buf
+len
, size
-len
, "FC_NODE ");
571 if (ndlp
->nlp_type
& NLP_FABRIC
)
572 len
+= snprintf(buf
+len
, size
-len
, "FABRIC ");
573 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
574 len
+= snprintf(buf
+len
, size
-len
, "FCP_TGT sid:%d ",
576 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
577 len
+= snprintf(buf
+len
, size
-len
, "FCP_INITIATOR ");
578 len
+= snprintf(buf
+len
, size
-len
, "usgmap:%x ",
580 len
+= snprintf(buf
+len
, size
-len
, "refcnt:%x",
581 atomic_read(&ndlp
->kref
.refcount
));
582 len
+= snprintf(buf
+len
, size
-len
, "\n");
584 spin_unlock_irq(shost
->host_lock
);
590 * lpfc_debugfs_disc_trc - Store discovery trace log
591 * @vport: The vport to associate this trace string with for retrieval.
592 * @mask: Log entry classification.
593 * @fmt: Format string to be displayed when dumping the log.
594 * @data1: 1st data parameter to be applied to @fmt.
595 * @data2: 2nd data parameter to be applied to @fmt.
596 * @data3: 3rd data parameter to be applied to @fmt.
599 * This routine is used by the driver code to add a debugfs log entry to the
600 * discovery trace buffer associated with @vport. Only entries with a @mask that
601 * match the current debugfs discovery mask will be saved. Entries that do not
602 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
603 * printf when displaying the log.
606 lpfc_debugfs_disc_trc(struct lpfc_vport
*vport
, int mask
, char *fmt
,
607 uint32_t data1
, uint32_t data2
, uint32_t data3
)
609 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
610 struct lpfc_debugfs_trc
*dtp
;
613 if (!(lpfc_debugfs_mask_disc_trc
& mask
))
616 if (!lpfc_debugfs_enable
|| !lpfc_debugfs_max_disc_trc
||
617 !vport
|| !vport
->disc_trc
)
620 index
= atomic_inc_return(&vport
->disc_trc_cnt
) &
621 (lpfc_debugfs_max_disc_trc
- 1);
622 dtp
= vport
->disc_trc
+ index
;
627 dtp
->seq_cnt
= atomic_inc_return(&lpfc_debugfs_seq_trc_cnt
);
634 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
635 * @phba: The phba to associate this trace string with for retrieval.
636 * @fmt: Format string to be displayed when dumping the log.
637 * @data1: 1st data parameter to be applied to @fmt.
638 * @data2: 2nd data parameter to be applied to @fmt.
639 * @data3: 3rd data parameter to be applied to @fmt.
642 * This routine is used by the driver code to add a debugfs log entry to the
643 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
644 * @data3 are used like printf when displaying the log.
647 lpfc_debugfs_slow_ring_trc(struct lpfc_hba
*phba
, char *fmt
,
648 uint32_t data1
, uint32_t data2
, uint32_t data3
)
650 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
651 struct lpfc_debugfs_trc
*dtp
;
654 if (!lpfc_debugfs_enable
|| !lpfc_debugfs_max_slow_ring_trc
||
655 !phba
|| !phba
->slow_ring_trc
)
658 index
= atomic_inc_return(&phba
->slow_ring_trc_cnt
) &
659 (lpfc_debugfs_max_slow_ring_trc
- 1);
660 dtp
= phba
->slow_ring_trc
+ index
;
665 dtp
->seq_cnt
= atomic_inc_return(&lpfc_debugfs_seq_trc_cnt
);
671 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
673 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
674 * @inode: The inode pointer that contains a vport pointer.
675 * @file: The file pointer to attach the log output.
678 * This routine is the entry point for the debugfs open file operation. It gets
679 * the vport from the i_private field in @inode, allocates the necessary buffer
680 * for the log, fills the buffer from the in-memory log for this vport, and then
681 * returns a pointer to that log in the private_data field in @file.
684 * This function returns zero if successful. On error it will return an negative
688 lpfc_debugfs_disc_trc_open(struct inode
*inode
, struct file
*file
)
690 struct lpfc_vport
*vport
= inode
->i_private
;
691 struct lpfc_debug
*debug
;
695 if (!lpfc_debugfs_max_disc_trc
) {
700 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
704 /* Round to page boundary */
705 size
= (lpfc_debugfs_max_disc_trc
* LPFC_DEBUG_TRC_ENTRY_SIZE
);
706 size
= PAGE_ALIGN(size
);
708 debug
->buffer
= kmalloc(size
, GFP_KERNEL
);
709 if (!debug
->buffer
) {
714 debug
->len
= lpfc_debugfs_disc_trc_data(vport
, debug
->buffer
, size
);
715 file
->private_data
= debug
;
723 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
724 * @inode: The inode pointer that contains a vport pointer.
725 * @file: The file pointer to attach the log output.
728 * This routine is the entry point for the debugfs open file operation. It gets
729 * the vport from the i_private field in @inode, allocates the necessary buffer
730 * for the log, fills the buffer from the in-memory log for this vport, and then
731 * returns a pointer to that log in the private_data field in @file.
734 * This function returns zero if successful. On error it will return an negative
738 lpfc_debugfs_slow_ring_trc_open(struct inode
*inode
, struct file
*file
)
740 struct lpfc_hba
*phba
= inode
->i_private
;
741 struct lpfc_debug
*debug
;
745 if (!lpfc_debugfs_max_slow_ring_trc
) {
750 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
754 /* Round to page boundary */
755 size
= (lpfc_debugfs_max_slow_ring_trc
* LPFC_DEBUG_TRC_ENTRY_SIZE
);
756 size
= PAGE_ALIGN(size
);
758 debug
->buffer
= kmalloc(size
, GFP_KERNEL
);
759 if (!debug
->buffer
) {
764 debug
->len
= lpfc_debugfs_slow_ring_trc_data(phba
, debug
->buffer
, size
);
765 file
->private_data
= debug
;
773 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
774 * @inode: The inode pointer that contains a vport pointer.
775 * @file: The file pointer to attach the log output.
778 * This routine is the entry point for the debugfs open file operation. It gets
779 * the vport from the i_private field in @inode, allocates the necessary buffer
780 * for the log, fills the buffer from the in-memory log for this vport, and then
781 * returns a pointer to that log in the private_data field in @file.
784 * This function returns zero if successful. On error it will return an negative
788 lpfc_debugfs_hbqinfo_open(struct inode
*inode
, struct file
*file
)
790 struct lpfc_hba
*phba
= inode
->i_private
;
791 struct lpfc_debug
*debug
;
794 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
798 /* Round to page boundary */
799 debug
->buffer
= kmalloc(LPFC_HBQINFO_SIZE
, GFP_KERNEL
);
800 if (!debug
->buffer
) {
805 debug
->len
= lpfc_debugfs_hbqinfo_data(phba
, debug
->buffer
,
807 file
->private_data
= debug
;
815 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
816 * @inode: The inode pointer that contains a vport pointer.
817 * @file: The file pointer to attach the log output.
820 * This routine is the entry point for the debugfs open file operation. It gets
821 * the vport from the i_private field in @inode, allocates the necessary buffer
822 * for the log, fills the buffer from the in-memory log for this vport, and then
823 * returns a pointer to that log in the private_data field in @file.
826 * This function returns zero if successful. On error it will return an negative
830 lpfc_debugfs_dumpHBASlim_open(struct inode
*inode
, struct file
*file
)
832 struct lpfc_hba
*phba
= inode
->i_private
;
833 struct lpfc_debug
*debug
;
836 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
840 /* Round to page boundary */
841 debug
->buffer
= kmalloc(LPFC_DUMPHBASLIM_SIZE
, GFP_KERNEL
);
842 if (!debug
->buffer
) {
847 debug
->len
= lpfc_debugfs_dumpHBASlim_data(phba
, debug
->buffer
,
848 LPFC_DUMPHBASLIM_SIZE
);
849 file
->private_data
= debug
;
857 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
858 * @inode: The inode pointer that contains a vport pointer.
859 * @file: The file pointer to attach the log output.
862 * This routine is the entry point for the debugfs open file operation. It gets
863 * the vport from the i_private field in @inode, allocates the necessary buffer
864 * for the log, fills the buffer from the in-memory log for this vport, and then
865 * returns a pointer to that log in the private_data field in @file.
868 * This function returns zero if successful. On error it will return an negative
872 lpfc_debugfs_dumpHostSlim_open(struct inode
*inode
, struct file
*file
)
874 struct lpfc_hba
*phba
= inode
->i_private
;
875 struct lpfc_debug
*debug
;
878 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
882 /* Round to page boundary */
883 debug
->buffer
= kmalloc(LPFC_DUMPHOSTSLIM_SIZE
, GFP_KERNEL
);
884 if (!debug
->buffer
) {
889 debug
->len
= lpfc_debugfs_dumpHostSlim_data(phba
, debug
->buffer
,
890 LPFC_DUMPHOSTSLIM_SIZE
);
891 file
->private_data
= debug
;
899 lpfc_debugfs_dumpData_open(struct inode
*inode
, struct file
*file
)
901 struct lpfc_debug
*debug
;
907 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
911 /* Round to page boundry */
912 printk(KERN_ERR
"9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
913 __func__
, _dump_buf_data
);
914 debug
->buffer
= _dump_buf_data
;
915 if (!debug
->buffer
) {
920 debug
->len
= (1 << _dump_buf_data_order
) << PAGE_SHIFT
;
921 file
->private_data
= debug
;
929 lpfc_debugfs_dumpDif_open(struct inode
*inode
, struct file
*file
)
931 struct lpfc_debug
*debug
;
937 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
941 /* Round to page boundry */
942 printk(KERN_ERR
"9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
943 __func__
, _dump_buf_dif
, file
->f_dentry
->d_name
.name
);
944 debug
->buffer
= _dump_buf_dif
;
945 if (!debug
->buffer
) {
950 debug
->len
= (1 << _dump_buf_dif_order
) << PAGE_SHIFT
;
951 file
->private_data
= debug
;
959 lpfc_debugfs_dumpDataDif_write(struct file
*file
, const char __user
*buf
,
960 size_t nbytes
, loff_t
*ppos
)
963 * The Data/DIF buffers only save one failing IO
964 * The write op is used as a reset mechanism after an IO has
965 * already been saved to the next one can be saved
967 spin_lock(&_dump_buf_lock
);
969 memset((void *)_dump_buf_data
, 0,
970 ((1 << PAGE_SHIFT
) << _dump_buf_data_order
));
971 memset((void *)_dump_buf_dif
, 0,
972 ((1 << PAGE_SHIFT
) << _dump_buf_dif_order
));
976 spin_unlock(&_dump_buf_lock
);
982 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
983 * @inode: The inode pointer that contains a vport pointer.
984 * @file: The file pointer to attach the log output.
987 * This routine is the entry point for the debugfs open file operation. It gets
988 * the vport from the i_private field in @inode, allocates the necessary buffer
989 * for the log, fills the buffer from the in-memory log for this vport, and then
990 * returns a pointer to that log in the private_data field in @file.
993 * This function returns zero if successful. On error it will return an negative
997 lpfc_debugfs_nodelist_open(struct inode
*inode
, struct file
*file
)
999 struct lpfc_vport
*vport
= inode
->i_private
;
1000 struct lpfc_debug
*debug
;
1003 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
1007 /* Round to page boundary */
1008 debug
->buffer
= kmalloc(LPFC_NODELIST_SIZE
, GFP_KERNEL
);
1009 if (!debug
->buffer
) {
1014 debug
->len
= lpfc_debugfs_nodelist_data(vport
, debug
->buffer
,
1015 LPFC_NODELIST_SIZE
);
1016 file
->private_data
= debug
;
1024 * lpfc_debugfs_lseek - Seek through a debugfs file
1025 * @file: The file pointer to seek through.
1026 * @off: The offset to seek to or the amount to seek by.
1027 * @whence: Indicates how to seek.
1030 * This routine is the entry point for the debugfs lseek file operation. The
1031 * @whence parameter indicates whether @off is the offset to directly seek to,
1032 * or if it is a value to seek forward or reverse by. This function figures out
1033 * what the new offset of the debugfs file will be and assigns that value to the
1034 * f_pos field of @file.
1037 * This function returns the new offset if successful and returns a negative
1038 * error if unable to process the seek.
1041 lpfc_debugfs_lseek(struct file
*file
, loff_t off
, int whence
)
1043 struct lpfc_debug
*debug
;
1046 debug
= file
->private_data
;
1053 pos
= file
->f_pos
+ off
;
1056 pos
= debug
->len
- off
;
1058 return (pos
< 0 || pos
> debug
->len
) ? -EINVAL
: (file
->f_pos
= pos
);
1062 * lpfc_debugfs_read - Read a debugfs file
1063 * @file: The file pointer to read from.
1064 * @buf: The buffer to copy the data to.
1065 * @nbytes: The number of bytes to read.
1066 * @ppos: The position in the file to start reading from.
1069 * This routine reads data from from the buffer indicated in the private_data
1070 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1074 * This function returns the amount of data that was read (this could be less
1075 * than @nbytes if the end of the file was reached) or a negative error value.
1078 lpfc_debugfs_read(struct file
*file
, char __user
*buf
,
1079 size_t nbytes
, loff_t
*ppos
)
1081 struct lpfc_debug
*debug
= file
->private_data
;
1083 return simple_read_from_buffer(buf
, nbytes
, ppos
, debug
->buffer
,
1088 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1089 * @inode: The inode pointer that contains a vport pointer. (unused)
1090 * @file: The file pointer that contains the buffer to release.
1093 * This routine frees the buffer that was allocated when the debugfs file was
1097 * This function returns zero.
1100 lpfc_debugfs_release(struct inode
*inode
, struct file
*file
)
1102 struct lpfc_debug
*debug
= file
->private_data
;
1104 kfree(debug
->buffer
);
1111 lpfc_debugfs_dumpDataDif_release(struct inode
*inode
, struct file
*file
)
1113 struct lpfc_debug
*debug
= file
->private_data
;
1115 debug
->buffer
= NULL
;
1122 * iDiag debugfs file access methods
1126 * iDiag PCI config space register access methods:
1128 * The PCI config space register accessees of read, write, read-modify-write
1129 * for set bits, and read-modify-write for clear bits to SLI4 PCI functions
1130 * are provided. In the proper SLI4 PCI function's debugfs iDiag directory,
1132 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1134 * the access is through the debugfs entry pciCfg:
1136 * 1. For PCI config space register read access, there are two read methods:
1137 * A) read a single PCI config space register in the size of a byte
1138 * (8 bits), a word (16 bits), or a dword (32 bits); or B) browse through
1139 * the 4K extended PCI config space.
1141 * A) Read a single PCI config space register consists of two steps:
1143 * Step-1: Set up PCI config space register read command, the command
1146 * echo 1 <where> <count> > pciCfg
1148 * where, 1 is the iDiag command for PCI config space read, <where> is the
1149 * offset from the beginning of the device's PCI config space to read from,
1150 * and <count> is the size of PCI config space register data to read back,
1151 * it will be 1 for reading a byte (8 bits), 2 for reading a word (16 bits
1152 * or 2 bytes), or 4 for reading a dword (32 bits or 4 bytes).
1154 * Setp-2: Perform the debugfs read operation to execute the idiag command
1160 * To read PCI device's vendor-id and device-id from PCI config space,
1162 * echo 1 0 4 > pciCfg
1165 * To read PCI device's currnt command from config space,
1167 * echo 1 4 2 > pciCfg
1170 * B) Browse through the entire 4K extended PCI config space also consists
1173 * Step-1: Set up PCI config space register browsing command, the command
1176 * echo 1 0 4096 > pciCfg
1178 * where, 1 is the iDiag command for PCI config space read, 0 must be used
1179 * as the offset for PCI config space register browse, and 4096 must be
1180 * used as the count for PCI config space register browse.
1182 * Step-2: Repeately issue the debugfs read operation to browse through
1183 * the entire PCI config space registers:
1190 * When browsing to the end of the 4K PCI config space, the browse method
1191 * shall wrap around to start reading from beginning again, and again...
1193 * 2. For PCI config space register write access, it supports a single PCI
1194 * config space register write in the size of a byte (8 bits), a word
1195 * (16 bits), or a dword (32 bits). The command syntax is,
1197 * echo 2 <where> <count> <value> > pciCfg
1199 * where, 2 is the iDiag command for PCI config space write, <where> is
1200 * the offset from the beginning of the device's PCI config space to write
1201 * into, <count> is the size of data to write into the PCI config space,
1202 * it will be 1 for writing a byte (8 bits), 2 for writing a word (16 bits
1203 * or 2 bytes), or 4 for writing a dword (32 bits or 4 bytes), and <value>
1204 * is the data to be written into the PCI config space register at the
1208 * To disable PCI device's interrupt assertion,
1210 * 1) Read in device's PCI config space register command field <cmd>:
1212 * echo 1 4 2 > pciCfg
1215 * 2) Set bit 10 (Interrupt Disable bit) in the <cmd>:
1217 * <cmd> = <cmd> | (1 < 10)
1219 * 3) Write the modified command back:
1221 * echo 2 4 2 <cmd> > pciCfg
1223 * 3. For PCI config space register set bits access, it supports a single PCI
1224 * config space register set bits in the size of a byte (8 bits), a word
1225 * (16 bits), or a dword (32 bits). The command syntax is,
1227 * echo 3 <where> <count> <bitmask> > pciCfg
1229 * where, 3 is the iDiag command for PCI config space set bits, <where> is
1230 * the offset from the beginning of the device's PCI config space to set
1231 * bits into, <count> is the size of the bitmask to set into the PCI config
1232 * space, it will be 1 for setting a byte (8 bits), 2 for setting a word
1233 * (16 bits or 2 bytes), or 4 for setting a dword (32 bits or 4 bytes), and
1234 * <bitmask> is the bitmask, indicating the bits to be set into the PCI
1235 * config space register at the offset. The logic performed to the content
1236 * of the PCI config space register, regval, is,
1238 * regval |= <bitmask>
1240 * 4. For PCI config space register clear bits access, it supports a single
1241 * PCI config space register clear bits in the size of a byte (8 bits),
1242 * a word (16 bits), or a dword (32 bits). The command syntax is,
1244 * echo 4 <where> <count> <bitmask> > pciCfg
1246 * where, 4 is the iDiag command for PCI config space clear bits, <where>
1247 * is the offset from the beginning of the device's PCI config space to
1248 * clear bits from, <count> is the size of the bitmask to set into the PCI
1249 * config space, it will be 1 for setting a byte (8 bits), 2 for setting
1250 * a word(16 bits or 2 bytes), or 4 for setting a dword (32 bits or 4
1251 * bytes), and <bitmask> is the bitmask, indicating the bits to be cleared
1252 * from the PCI config space register at the offset. the logic performed
1253 * to the content of the PCI config space register, regval, is,
1255 * regval &= ~<bitmask>
1257 * Note, for all single register read, write, set bits, or clear bits access,
1258 * the offset (<where>) must be aligned with the size of the data:
1260 * For data size of byte (8 bits), the offset must be aligned to the byte
1261 * boundary; for data size of word (16 bits), the offset must be aligned
1262 * to the word boundary; while for data size of dword (32 bits), the offset
1263 * must be aligned to the dword boundary. Otherwise, the interface will
1266 * "-bash: echo: write error: Invalid argument".
1270 * echo 1 2 4 > pciCfg
1271 * -bash: echo: write error: Invalid argument
1273 * Note also, all of the numbers in the command fields for all read, write,
1274 * set bits, and clear bits PCI config space register command fields can be
1275 * either decimal or hex.
1278 * echo 1 0 4096 > pciCfg
1280 * will be the same as
1281 * echo 1 0 0x1000 > pciCfg
1284 * echo 2 155 1 10 > pciCfg
1287 * echo 2 0x9b 1 0xa > pciCfg
1291 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1292 * @buf: The pointer to the user space buffer.
1293 * @nbytes: The number of bytes in the user space buffer.
1294 * @idiag_cmd: pointer to the idiag command struct.
1296 * This routine reads data from debugfs user space buffer and parses the
1297 * buffer for getting the idiag command and arguments. The while space in
1298 * between the set of data is used as the parsing separator.
1300 * This routine returns 0 when successful, it returns proper error code
1301 * back to the user space in error conditions.
1303 static int lpfc_idiag_cmd_get(const char __user
*buf
, size_t nbytes
,
1304 struct lpfc_idiag_cmd
*idiag_cmd
)
1307 char *pbuf
, *step_str
;
1310 /* Protect copy from user */
1311 if (!access_ok(VERIFY_READ
, buf
, nbytes
))
1314 memset(mybuf
, 0, sizeof(mybuf
));
1315 memset(idiag_cmd
, 0, sizeof(*idiag_cmd
));
1316 bsize
= min(nbytes
, (sizeof(mybuf
)-1));
1318 if (copy_from_user(mybuf
, buf
, bsize
))
1321 step_str
= strsep(&pbuf
, "\t ");
1323 /* The opcode must present */
1327 idiag_cmd
->opcode
= simple_strtol(step_str
, NULL
, 0);
1328 if (idiag_cmd
->opcode
== 0)
1331 for (i
= 0; i
< LPFC_IDIAG_CMD_DATA_SIZE
; i
++) {
1332 step_str
= strsep(&pbuf
, "\t ");
1335 idiag_cmd
->data
[i
] = simple_strtol(step_str
, NULL
, 0);
1341 * lpfc_idiag_open - idiag open debugfs
1342 * @inode: The inode pointer that contains a pointer to phba.
1343 * @file: The file pointer to attach the file operation.
1346 * This routine is the entry point for the debugfs open file operation. It
1347 * gets the reference to phba from the i_private field in @inode, it then
1348 * allocates buffer for the file operation, performs the necessary PCI config
1349 * space read into the allocated buffer according to the idiag user command
1350 * setup, and then returns a pointer to buffer in the private_data field in
1354 * This function returns zero if successful. On error it will return an
1355 * negative error value.
1358 lpfc_idiag_open(struct inode
*inode
, struct file
*file
)
1360 struct lpfc_debug
*debug
;
1362 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
1366 debug
->i_private
= inode
->i_private
;
1367 debug
->buffer
= NULL
;
1368 file
->private_data
= debug
;
1374 * lpfc_idiag_release - Release idiag access file operation
1375 * @inode: The inode pointer that contains a vport pointer. (unused)
1376 * @file: The file pointer that contains the buffer to release.
1379 * This routine is the generic release routine for the idiag access file
1380 * operation, it frees the buffer that was allocated when the debugfs file
1384 * This function returns zero.
1387 lpfc_idiag_release(struct inode
*inode
, struct file
*file
)
1389 struct lpfc_debug
*debug
= file
->private_data
;
1391 /* Free the buffers to the file operation */
1392 kfree(debug
->buffer
);
1399 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1400 * @inode: The inode pointer that contains a vport pointer. (unused)
1401 * @file: The file pointer that contains the buffer to release.
1404 * This routine frees the buffer that was allocated when the debugfs file
1405 * was opened. It also reset the fields in the idiag command struct in the
1406 * case the command is not continuous browsing of the data structure.
1409 * This function returns zero.
1412 lpfc_idiag_cmd_release(struct inode
*inode
, struct file
*file
)
1414 struct lpfc_debug
*debug
= file
->private_data
;
1416 /* Read PCI config register, if not read all, clear command fields */
1417 if ((debug
->op
== LPFC_IDIAG_OP_RD
) &&
1418 (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_RD
))
1419 if ((idiag
.cmd
.data
[1] == sizeof(uint8_t)) ||
1420 (idiag
.cmd
.data
[1] == sizeof(uint16_t)) ||
1421 (idiag
.cmd
.data
[1] == sizeof(uint32_t)))
1422 memset(&idiag
, 0, sizeof(idiag
));
1424 /* Write PCI config register, clear command fields */
1425 if ((debug
->op
== LPFC_IDIAG_OP_WR
) &&
1426 (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
))
1427 memset(&idiag
, 0, sizeof(idiag
));
1429 /* Free the buffers to the file operation */
1430 kfree(debug
->buffer
);
1437 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1438 * @file: The file pointer to read from.
1439 * @buf: The buffer to copy the data to.
1440 * @nbytes: The number of bytes to read.
1441 * @ppos: The position in the file to start reading from.
1444 * This routine reads data from the @phba pci config space according to the
1445 * idiag command, and copies to user @buf. Depending on the PCI config space
1446 * read command setup, it does either a single register read of a byte
1447 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1448 * registers from the 4K extended PCI config space.
1451 * This function returns the amount of data that was read (this could be less
1452 * than @nbytes if the end of the file was reached) or a negative error value.
1455 lpfc_idiag_pcicfg_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
1458 struct lpfc_debug
*debug
= file
->private_data
;
1459 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
1460 int offset_label
, offset
, len
= 0, index
= LPFC_PCI_CFG_RD_SIZE
;
1463 struct pci_dev
*pdev
;
1468 pdev
= phba
->pcidev
;
1472 /* This is a user read operation */
1473 debug
->op
= LPFC_IDIAG_OP_RD
;
1476 debug
->buffer
= kmalloc(LPFC_PCI_CFG_SIZE
, GFP_KERNEL
);
1479 pbuffer
= debug
->buffer
;
1484 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_RD
) {
1485 where
= idiag
.cmd
.data
[0];
1486 count
= idiag
.cmd
.data
[1];
1490 /* Read single PCI config space register */
1492 case SIZE_U8
: /* byte (8 bits) */
1493 pci_read_config_byte(pdev
, where
, &u8val
);
1494 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1495 "%03x: %02x\n", where
, u8val
);
1497 case SIZE_U16
: /* word (16 bits) */
1498 pci_read_config_word(pdev
, where
, &u16val
);
1499 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1500 "%03x: %04x\n", where
, u16val
);
1502 case SIZE_U32
: /* double word (32 bits) */
1503 pci_read_config_dword(pdev
, where
, &u32val
);
1504 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1505 "%03x: %08x\n", where
, u32val
);
1507 case LPFC_PCI_CFG_SIZE
: /* browse all */
1515 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
1519 /* Browse all PCI config space registers */
1520 offset_label
= idiag
.offset
.last_rd
;
1521 offset
= offset_label
;
1523 /* Read PCI config space */
1524 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1525 "%03x: ", offset_label
);
1527 pci_read_config_dword(pdev
, offset
, &u32val
);
1528 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1530 offset
+= sizeof(uint32_t);
1531 index
-= sizeof(uint32_t);
1533 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1535 else if (!(index
% (8 * sizeof(uint32_t)))) {
1536 offset_label
+= (8 * sizeof(uint32_t));
1537 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1538 "\n%03x: ", offset_label
);
1542 /* Set up the offset for next portion of pci cfg read */
1543 idiag
.offset
.last_rd
+= LPFC_PCI_CFG_RD_SIZE
;
1544 if (idiag
.offset
.last_rd
>= LPFC_PCI_CFG_SIZE
)
1545 idiag
.offset
.last_rd
= 0;
1547 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
1551 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1552 * @file: The file pointer to read from.
1553 * @buf: The buffer to copy the user data from.
1554 * @nbytes: The number of bytes to get.
1555 * @ppos: The position in the file to start reading from.
1557 * This routine get the debugfs idiag command struct from user space and
1558 * then perform the syntax check for PCI config space read or write command
1559 * accordingly. In the case of PCI config space read command, it sets up
1560 * the command in the idiag command struct for the debugfs read operation.
1561 * In the case of PCI config space write operation, it executes the write
1562 * operation into the PCI config space accordingly.
1564 * It returns the @nbytges passing in from debugfs user space when successful.
1565 * In case of error conditions, it returns proper error code back to the user
1569 lpfc_idiag_pcicfg_write(struct file
*file
, const char __user
*buf
,
1570 size_t nbytes
, loff_t
*ppos
)
1572 struct lpfc_debug
*debug
= file
->private_data
;
1573 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
1574 uint32_t where
, value
, count
;
1578 struct pci_dev
*pdev
;
1581 pdev
= phba
->pcidev
;
1585 /* This is a user write operation */
1586 debug
->op
= LPFC_IDIAG_OP_WR
;
1588 rc
= lpfc_idiag_cmd_get(buf
, nbytes
, &idiag
.cmd
);
1592 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_RD
) {
1593 /* Read command from PCI config space, set up command fields */
1594 where
= idiag
.cmd
.data
[0];
1595 count
= idiag
.cmd
.data
[1];
1596 if (count
== LPFC_PCI_CFG_SIZE
) {
1599 } else if ((count
!= sizeof(uint8_t)) &&
1600 (count
!= sizeof(uint16_t)) &&
1601 (count
!= sizeof(uint32_t)))
1603 if (count
== sizeof(uint8_t)) {
1604 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint8_t))
1606 if (where
% sizeof(uint8_t))
1609 if (count
== sizeof(uint16_t)) {
1610 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint16_t))
1612 if (where
% sizeof(uint16_t))
1615 if (count
== sizeof(uint32_t)) {
1616 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint32_t))
1618 if (where
% sizeof(uint32_t))
1621 } else if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
||
1622 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_ST
||
1623 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_CL
) {
1624 /* Write command to PCI config space, read-modify-write */
1625 where
= idiag
.cmd
.data
[0];
1626 count
= idiag
.cmd
.data
[1];
1627 value
= idiag
.cmd
.data
[2];
1629 if ((count
!= sizeof(uint8_t)) &&
1630 (count
!= sizeof(uint16_t)) &&
1631 (count
!= sizeof(uint32_t)))
1633 if (count
== sizeof(uint8_t)) {
1634 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint8_t))
1636 if (where
% sizeof(uint8_t))
1638 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
)
1639 pci_write_config_byte(pdev
, where
,
1641 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_ST
) {
1642 rc
= pci_read_config_byte(pdev
, where
, &u8val
);
1644 u8val
|= (uint8_t)value
;
1645 pci_write_config_byte(pdev
, where
,
1649 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_CL
) {
1650 rc
= pci_read_config_byte(pdev
, where
, &u8val
);
1652 u8val
&= (uint8_t)(~value
);
1653 pci_write_config_byte(pdev
, where
,
1658 if (count
== sizeof(uint16_t)) {
1659 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint16_t))
1661 if (where
% sizeof(uint16_t))
1663 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
)
1664 pci_write_config_word(pdev
, where
,
1666 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_ST
) {
1667 rc
= pci_read_config_word(pdev
, where
, &u16val
);
1669 u16val
|= (uint16_t)value
;
1670 pci_write_config_word(pdev
, where
,
1674 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_CL
) {
1675 rc
= pci_read_config_word(pdev
, where
, &u16val
);
1677 u16val
&= (uint16_t)(~value
);
1678 pci_write_config_word(pdev
, where
,
1683 if (count
== sizeof(uint32_t)) {
1684 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint32_t))
1686 if (where
% sizeof(uint32_t))
1688 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
)
1689 pci_write_config_dword(pdev
, where
, value
);
1690 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_ST
) {
1691 rc
= pci_read_config_dword(pdev
, where
,
1695 pci_write_config_dword(pdev
, where
,
1699 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_CL
) {
1700 rc
= pci_read_config_dword(pdev
, where
,
1704 pci_write_config_dword(pdev
, where
,
1710 /* All other opecodes are illegal for now */
1715 memset(&idiag
, 0, sizeof(idiag
));
1720 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1721 * @file: The file pointer to read from.
1722 * @buf: The buffer to copy the data to.
1723 * @nbytes: The number of bytes to read.
1724 * @ppos: The position in the file to start reading from.
1727 * This routine reads data from the @phba SLI4 PCI function queue information,
1728 * and copies to user @buf.
1731 * This function returns the amount of data that was read (this could be less
1732 * than @nbytes if the end of the file was reached) or a negative error value.
1735 lpfc_idiag_queinfo_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
1738 struct lpfc_debug
*debug
= file
->private_data
;
1739 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
1740 int len
= 0, fcp_qidx
;
1744 debug
->buffer
= kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE
, GFP_KERNEL
);
1747 pbuffer
= debug
->buffer
;
1752 /* Get slow-path event queue information */
1753 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1754 "Slow-path EQ information:\n");
1755 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1756 "\tID [%02d], EQE-COUNT [%04d], "
1757 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1758 phba
->sli4_hba
.sp_eq
->queue_id
,
1759 phba
->sli4_hba
.sp_eq
->entry_count
,
1760 phba
->sli4_hba
.sp_eq
->host_index
,
1761 phba
->sli4_hba
.sp_eq
->hba_index
);
1763 /* Get fast-path event queue information */
1764 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1765 "Fast-path EQ information:\n");
1766 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++) {
1767 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1768 "\tID [%02d], EQE-COUNT [%04d], "
1769 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1770 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->queue_id
,
1771 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->entry_count
,
1772 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->host_index
,
1773 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->hba_index
);
1775 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
, "\n");
1777 /* Get mailbox complete queue information */
1778 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1779 "Mailbox CQ information:\n");
1780 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1781 "\t\tAssociated EQ-ID [%02d]:\n",
1782 phba
->sli4_hba
.mbx_cq
->assoc_qid
);
1783 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1784 "\tID [%02d], CQE-COUNT [%04d], "
1785 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1786 phba
->sli4_hba
.mbx_cq
->queue_id
,
1787 phba
->sli4_hba
.mbx_cq
->entry_count
,
1788 phba
->sli4_hba
.mbx_cq
->host_index
,
1789 phba
->sli4_hba
.mbx_cq
->hba_index
);
1791 /* Get slow-path complete queue information */
1792 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1793 "Slow-path CQ information:\n");
1794 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1795 "\t\tAssociated EQ-ID [%02d]:\n",
1796 phba
->sli4_hba
.els_cq
->assoc_qid
);
1797 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1798 "\tID [%02d], CQE-COUNT [%04d], "
1799 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1800 phba
->sli4_hba
.els_cq
->queue_id
,
1801 phba
->sli4_hba
.els_cq
->entry_count
,
1802 phba
->sli4_hba
.els_cq
->host_index
,
1803 phba
->sli4_hba
.els_cq
->hba_index
);
1805 /* Get fast-path complete queue information */
1806 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1807 "Fast-path CQ information:\n");
1808 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++) {
1809 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1810 "\t\tAssociated EQ-ID [%02d]:\n",
1811 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->assoc_qid
);
1812 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1813 "\tID [%02d], EQE-COUNT [%04d], "
1814 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1815 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->queue_id
,
1816 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->entry_count
,
1817 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->host_index
,
1818 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->hba_index
);
1820 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
, "\n");
1822 /* Get mailbox queue information */
1823 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1824 "Mailbox MQ information:\n");
1825 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1826 "\t\tAssociated CQ-ID [%02d]:\n",
1827 phba
->sli4_hba
.mbx_wq
->assoc_qid
);
1828 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1829 "\tID [%02d], MQE-COUNT [%04d], "
1830 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1831 phba
->sli4_hba
.mbx_wq
->queue_id
,
1832 phba
->sli4_hba
.mbx_wq
->entry_count
,
1833 phba
->sli4_hba
.mbx_wq
->host_index
,
1834 phba
->sli4_hba
.mbx_wq
->hba_index
);
1836 /* Get slow-path work queue information */
1837 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1838 "Slow-path WQ information:\n");
1839 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1840 "\t\tAssociated CQ-ID [%02d]:\n",
1841 phba
->sli4_hba
.els_wq
->assoc_qid
);
1842 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1843 "\tID [%02d], WQE-COUNT [%04d], "
1844 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1845 phba
->sli4_hba
.els_wq
->queue_id
,
1846 phba
->sli4_hba
.els_wq
->entry_count
,
1847 phba
->sli4_hba
.els_wq
->host_index
,
1848 phba
->sli4_hba
.els_wq
->hba_index
);
1850 /* Get fast-path work queue information */
1851 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1852 "Fast-path WQ information:\n");
1853 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_wq_count
; fcp_qidx
++) {
1854 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1855 "\t\tAssociated CQ-ID [%02d]:\n",
1856 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->assoc_qid
);
1857 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1858 "\tID [%02d], WQE-COUNT [%04d], "
1859 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1860 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->queue_id
,
1861 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->entry_count
,
1862 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->host_index
,
1863 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->hba_index
);
1865 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
, "\n");
1867 /* Get receive queue information */
1868 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1869 "Slow-path RQ information:\n");
1870 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1871 "\t\tAssociated CQ-ID [%02d]:\n",
1872 phba
->sli4_hba
.hdr_rq
->assoc_qid
);
1873 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1874 "\tID [%02d], RHQE-COUNT [%04d], "
1875 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1876 phba
->sli4_hba
.hdr_rq
->queue_id
,
1877 phba
->sli4_hba
.hdr_rq
->entry_count
,
1878 phba
->sli4_hba
.hdr_rq
->host_index
,
1879 phba
->sli4_hba
.hdr_rq
->hba_index
);
1880 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1881 "\tID [%02d], RDQE-COUNT [%04d], "
1882 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1883 phba
->sli4_hba
.dat_rq
->queue_id
,
1884 phba
->sli4_hba
.dat_rq
->entry_count
,
1885 phba
->sli4_hba
.dat_rq
->host_index
,
1886 phba
->sli4_hba
.dat_rq
->hba_index
);
1888 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
1891 #undef lpfc_debugfs_op_disc_trc
1892 static const struct file_operations lpfc_debugfs_op_disc_trc
= {
1893 .owner
= THIS_MODULE
,
1894 .open
= lpfc_debugfs_disc_trc_open
,
1895 .llseek
= lpfc_debugfs_lseek
,
1896 .read
= lpfc_debugfs_read
,
1897 .release
= lpfc_debugfs_release
,
1900 #undef lpfc_debugfs_op_nodelist
1901 static const struct file_operations lpfc_debugfs_op_nodelist
= {
1902 .owner
= THIS_MODULE
,
1903 .open
= lpfc_debugfs_nodelist_open
,
1904 .llseek
= lpfc_debugfs_lseek
,
1905 .read
= lpfc_debugfs_read
,
1906 .release
= lpfc_debugfs_release
,
1909 #undef lpfc_debugfs_op_hbqinfo
1910 static const struct file_operations lpfc_debugfs_op_hbqinfo
= {
1911 .owner
= THIS_MODULE
,
1912 .open
= lpfc_debugfs_hbqinfo_open
,
1913 .llseek
= lpfc_debugfs_lseek
,
1914 .read
= lpfc_debugfs_read
,
1915 .release
= lpfc_debugfs_release
,
1918 #undef lpfc_debugfs_op_dumpHBASlim
1919 static const struct file_operations lpfc_debugfs_op_dumpHBASlim
= {
1920 .owner
= THIS_MODULE
,
1921 .open
= lpfc_debugfs_dumpHBASlim_open
,
1922 .llseek
= lpfc_debugfs_lseek
,
1923 .read
= lpfc_debugfs_read
,
1924 .release
= lpfc_debugfs_release
,
1927 #undef lpfc_debugfs_op_dumpHostSlim
1928 static const struct file_operations lpfc_debugfs_op_dumpHostSlim
= {
1929 .owner
= THIS_MODULE
,
1930 .open
= lpfc_debugfs_dumpHostSlim_open
,
1931 .llseek
= lpfc_debugfs_lseek
,
1932 .read
= lpfc_debugfs_read
,
1933 .release
= lpfc_debugfs_release
,
1936 #undef lpfc_debugfs_op_dumpData
1937 static const struct file_operations lpfc_debugfs_op_dumpData
= {
1938 .owner
= THIS_MODULE
,
1939 .open
= lpfc_debugfs_dumpData_open
,
1940 .llseek
= lpfc_debugfs_lseek
,
1941 .read
= lpfc_debugfs_read
,
1942 .write
= lpfc_debugfs_dumpDataDif_write
,
1943 .release
= lpfc_debugfs_dumpDataDif_release
,
1946 #undef lpfc_debugfs_op_dumpDif
1947 static const struct file_operations lpfc_debugfs_op_dumpDif
= {
1948 .owner
= THIS_MODULE
,
1949 .open
= lpfc_debugfs_dumpDif_open
,
1950 .llseek
= lpfc_debugfs_lseek
,
1951 .read
= lpfc_debugfs_read
,
1952 .write
= lpfc_debugfs_dumpDataDif_write
,
1953 .release
= lpfc_debugfs_dumpDataDif_release
,
1956 #undef lpfc_debugfs_op_slow_ring_trc
1957 static const struct file_operations lpfc_debugfs_op_slow_ring_trc
= {
1958 .owner
= THIS_MODULE
,
1959 .open
= lpfc_debugfs_slow_ring_trc_open
,
1960 .llseek
= lpfc_debugfs_lseek
,
1961 .read
= lpfc_debugfs_read
,
1962 .release
= lpfc_debugfs_release
,
1965 static struct dentry
*lpfc_debugfs_root
= NULL
;
1966 static atomic_t lpfc_debugfs_hba_count
;
1969 * File operations for the iDiag debugfs
1971 #undef lpfc_idiag_op_pciCfg
1972 static const struct file_operations lpfc_idiag_op_pciCfg
= {
1973 .owner
= THIS_MODULE
,
1974 .open
= lpfc_idiag_open
,
1975 .llseek
= lpfc_debugfs_lseek
,
1976 .read
= lpfc_idiag_pcicfg_read
,
1977 .write
= lpfc_idiag_pcicfg_write
,
1978 .release
= lpfc_idiag_cmd_release
,
1981 #undef lpfc_idiag_op_queInfo
1982 static const struct file_operations lpfc_idiag_op_queInfo
= {
1983 .owner
= THIS_MODULE
,
1984 .open
= lpfc_idiag_open
,
1985 .read
= lpfc_idiag_queinfo_read
,
1986 .release
= lpfc_idiag_release
,
1992 * lpfc_debugfs_initialize - Initialize debugfs for a vport
1993 * @vport: The vport pointer to initialize.
1996 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1997 * If not already created, this routine will create the lpfc directory, and
1998 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1999 * also create each file used to access lpfc specific debugfs information.
2002 lpfc_debugfs_initialize(struct lpfc_vport
*vport
)
2004 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2005 struct lpfc_hba
*phba
= vport
->phba
;
2009 if (!lpfc_debugfs_enable
)
2012 /* Setup lpfc root directory */
2013 if (!lpfc_debugfs_root
) {
2014 lpfc_debugfs_root
= debugfs_create_dir("lpfc", NULL
);
2015 atomic_set(&lpfc_debugfs_hba_count
, 0);
2016 if (!lpfc_debugfs_root
) {
2017 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2018 "0408 Cannot create debugfs root\n");
2022 if (!lpfc_debugfs_start_time
)
2023 lpfc_debugfs_start_time
= jiffies
;
2025 /* Setup funcX directory for specific HBA PCI function */
2026 snprintf(name
, sizeof(name
), "fn%d", phba
->brd_no
);
2027 if (!phba
->hba_debugfs_root
) {
2028 phba
->hba_debugfs_root
=
2029 debugfs_create_dir(name
, lpfc_debugfs_root
);
2030 if (!phba
->hba_debugfs_root
) {
2031 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2032 "0412 Cannot create debugfs hba\n");
2035 atomic_inc(&lpfc_debugfs_hba_count
);
2036 atomic_set(&phba
->debugfs_vport_count
, 0);
2039 snprintf(name
, sizeof(name
), "hbqinfo");
2040 phba
->debug_hbqinfo
=
2041 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
2042 phba
->hba_debugfs_root
,
2043 phba
, &lpfc_debugfs_op_hbqinfo
);
2044 if (!phba
->debug_hbqinfo
) {
2045 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2046 "0411 Cannot create debugfs hbqinfo\n");
2050 /* Setup dumpHBASlim */
2051 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2052 snprintf(name
, sizeof(name
), "dumpHBASlim");
2053 phba
->debug_dumpHBASlim
=
2054 debugfs_create_file(name
,
2055 S_IFREG
|S_IRUGO
|S_IWUSR
,
2056 phba
->hba_debugfs_root
,
2057 phba
, &lpfc_debugfs_op_dumpHBASlim
);
2058 if (!phba
->debug_dumpHBASlim
) {
2059 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2060 "0413 Cannot create debugfs "
2065 phba
->debug_dumpHBASlim
= NULL
;
2067 /* Setup dumpHostSlim */
2068 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2069 snprintf(name
, sizeof(name
), "dumpHostSlim");
2070 phba
->debug_dumpHostSlim
=
2071 debugfs_create_file(name
,
2072 S_IFREG
|S_IRUGO
|S_IWUSR
,
2073 phba
->hba_debugfs_root
,
2074 phba
, &lpfc_debugfs_op_dumpHostSlim
);
2075 if (!phba
->debug_dumpHostSlim
) {
2076 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2077 "0414 Cannot create debugfs "
2082 phba
->debug_dumpHBASlim
= NULL
;
2084 /* Setup dumpData */
2085 snprintf(name
, sizeof(name
), "dumpData");
2086 phba
->debug_dumpData
=
2087 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
2088 phba
->hba_debugfs_root
,
2089 phba
, &lpfc_debugfs_op_dumpData
);
2090 if (!phba
->debug_dumpData
) {
2091 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2092 "0800 Cannot create debugfs dumpData\n");
2097 snprintf(name
, sizeof(name
), "dumpDif");
2098 phba
->debug_dumpDif
=
2099 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
2100 phba
->hba_debugfs_root
,
2101 phba
, &lpfc_debugfs_op_dumpDif
);
2102 if (!phba
->debug_dumpDif
) {
2103 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2104 "0801 Cannot create debugfs dumpDif\n");
2108 /* Setup slow ring trace */
2109 if (lpfc_debugfs_max_slow_ring_trc
) {
2110 num
= lpfc_debugfs_max_slow_ring_trc
- 1;
2111 if (num
& lpfc_debugfs_max_slow_ring_trc
) {
2112 /* Change to be a power of 2 */
2113 num
= lpfc_debugfs_max_slow_ring_trc
;
2119 lpfc_debugfs_max_slow_ring_trc
= (1 << i
);
2121 "lpfc_debugfs_max_disc_trc changed to "
2122 "%d\n", lpfc_debugfs_max_disc_trc
);
2126 snprintf(name
, sizeof(name
), "slow_ring_trace");
2127 phba
->debug_slow_ring_trc
=
2128 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
2129 phba
->hba_debugfs_root
,
2130 phba
, &lpfc_debugfs_op_slow_ring_trc
);
2131 if (!phba
->debug_slow_ring_trc
) {
2132 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2133 "0415 Cannot create debugfs "
2134 "slow_ring_trace\n");
2137 if (!phba
->slow_ring_trc
) {
2138 phba
->slow_ring_trc
= kmalloc(
2139 (sizeof(struct lpfc_debugfs_trc
) *
2140 lpfc_debugfs_max_slow_ring_trc
),
2142 if (!phba
->slow_ring_trc
) {
2143 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2144 "0416 Cannot create debugfs "
2145 "slow_ring buffer\n");
2148 atomic_set(&phba
->slow_ring_trc_cnt
, 0);
2149 memset(phba
->slow_ring_trc
, 0,
2150 (sizeof(struct lpfc_debugfs_trc
) *
2151 lpfc_debugfs_max_slow_ring_trc
));
2155 snprintf(name
, sizeof(name
), "vport%d", vport
->vpi
);
2156 if (!vport
->vport_debugfs_root
) {
2157 vport
->vport_debugfs_root
=
2158 debugfs_create_dir(name
, phba
->hba_debugfs_root
);
2159 if (!vport
->vport_debugfs_root
) {
2160 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2161 "0417 Cant create debugfs\n");
2164 atomic_inc(&phba
->debugfs_vport_count
);
2167 if (lpfc_debugfs_max_disc_trc
) {
2168 num
= lpfc_debugfs_max_disc_trc
- 1;
2169 if (num
& lpfc_debugfs_max_disc_trc
) {
2170 /* Change to be a power of 2 */
2171 num
= lpfc_debugfs_max_disc_trc
;
2177 lpfc_debugfs_max_disc_trc
= (1 << i
);
2179 "lpfc_debugfs_max_disc_trc changed to %d\n",
2180 lpfc_debugfs_max_disc_trc
);
2184 vport
->disc_trc
= kzalloc(
2185 (sizeof(struct lpfc_debugfs_trc
) * lpfc_debugfs_max_disc_trc
),
2188 if (!vport
->disc_trc
) {
2189 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2190 "0418 Cannot create debugfs disc trace "
2194 atomic_set(&vport
->disc_trc_cnt
, 0);
2196 snprintf(name
, sizeof(name
), "discovery_trace");
2197 vport
->debug_disc_trc
=
2198 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
2199 vport
->vport_debugfs_root
,
2200 vport
, &lpfc_debugfs_op_disc_trc
);
2201 if (!vport
->debug_disc_trc
) {
2202 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2203 "0419 Cannot create debugfs "
2204 "discovery_trace\n");
2207 snprintf(name
, sizeof(name
), "nodelist");
2208 vport
->debug_nodelist
=
2209 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
2210 vport
->vport_debugfs_root
,
2211 vport
, &lpfc_debugfs_op_nodelist
);
2212 if (!vport
->debug_nodelist
) {
2213 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2214 "0409 Cant create debugfs nodelist\n");
2219 * iDiag debugfs root entry points for SLI4 device only
2221 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2224 snprintf(name
, sizeof(name
), "iDiag");
2225 if (!phba
->idiag_root
) {
2227 debugfs_create_dir(name
, phba
->hba_debugfs_root
);
2228 if (!phba
->idiag_root
) {
2229 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2230 "2922 Can't create idiag debugfs\n");
2233 /* Initialize iDiag data structure */
2234 memset(&idiag
, 0, sizeof(idiag
));
2237 /* iDiag read PCI config space */
2238 snprintf(name
, sizeof(name
), "pciCfg");
2239 if (!phba
->idiag_pci_cfg
) {
2240 phba
->idiag_pci_cfg
=
2241 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
2242 phba
->idiag_root
, phba
, &lpfc_idiag_op_pciCfg
);
2243 if (!phba
->idiag_pci_cfg
) {
2244 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2245 "2923 Can't create idiag debugfs\n");
2248 idiag
.offset
.last_rd
= 0;
2251 /* iDiag get PCI function queue information */
2252 snprintf(name
, sizeof(name
), "queInfo");
2253 if (!phba
->idiag_que_info
) {
2254 phba
->idiag_que_info
=
2255 debugfs_create_file(name
, S_IFREG
|S_IRUGO
,
2256 phba
->idiag_root
, phba
, &lpfc_idiag_op_queInfo
);
2257 if (!phba
->idiag_que_info
) {
2258 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2259 "2924 Can't create idiag debugfs\n");
2270 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
2271 * @vport: The vport pointer to remove from debugfs.
2274 * When Debugfs is configured this routine removes debugfs file system elements
2275 * that are specific to this vport. It also checks to see if there are any
2276 * users left for the debugfs directories associated with the HBA and driver. If
2277 * this is the last user of the HBA directory or driver directory then it will
2278 * remove those from the debugfs infrastructure as well.
2281 lpfc_debugfs_terminate(struct lpfc_vport
*vport
)
2283 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2284 struct lpfc_hba
*phba
= vport
->phba
;
2286 if (vport
->disc_trc
) {
2287 kfree(vport
->disc_trc
);
2288 vport
->disc_trc
= NULL
;
2290 if (vport
->debug_disc_trc
) {
2291 debugfs_remove(vport
->debug_disc_trc
); /* discovery_trace */
2292 vport
->debug_disc_trc
= NULL
;
2294 if (vport
->debug_nodelist
) {
2295 debugfs_remove(vport
->debug_nodelist
); /* nodelist */
2296 vport
->debug_nodelist
= NULL
;
2299 if (vport
->vport_debugfs_root
) {
2300 debugfs_remove(vport
->vport_debugfs_root
); /* vportX */
2301 vport
->vport_debugfs_root
= NULL
;
2302 atomic_dec(&phba
->debugfs_vport_count
);
2304 if (atomic_read(&phba
->debugfs_vport_count
) == 0) {
2306 if (phba
->debug_hbqinfo
) {
2307 debugfs_remove(phba
->debug_hbqinfo
); /* hbqinfo */
2308 phba
->debug_hbqinfo
= NULL
;
2310 if (phba
->debug_dumpHBASlim
) {
2311 debugfs_remove(phba
->debug_dumpHBASlim
); /* HBASlim */
2312 phba
->debug_dumpHBASlim
= NULL
;
2314 if (phba
->debug_dumpHostSlim
) {
2315 debugfs_remove(phba
->debug_dumpHostSlim
); /* HostSlim */
2316 phba
->debug_dumpHostSlim
= NULL
;
2318 if (phba
->debug_dumpData
) {
2319 debugfs_remove(phba
->debug_dumpData
); /* dumpData */
2320 phba
->debug_dumpData
= NULL
;
2323 if (phba
->debug_dumpDif
) {
2324 debugfs_remove(phba
->debug_dumpDif
); /* dumpDif */
2325 phba
->debug_dumpDif
= NULL
;
2328 if (phba
->slow_ring_trc
) {
2329 kfree(phba
->slow_ring_trc
);
2330 phba
->slow_ring_trc
= NULL
;
2332 if (phba
->debug_slow_ring_trc
) {
2333 /* slow_ring_trace */
2334 debugfs_remove(phba
->debug_slow_ring_trc
);
2335 phba
->debug_slow_ring_trc
= NULL
;
2341 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2342 if (phba
->idiag_que_info
) {
2344 debugfs_remove(phba
->idiag_que_info
);
2345 phba
->idiag_que_info
= NULL
;
2347 if (phba
->idiag_pci_cfg
) {
2349 debugfs_remove(phba
->idiag_pci_cfg
);
2350 phba
->idiag_pci_cfg
= NULL
;
2353 /* Finally remove the iDiag debugfs root */
2354 if (phba
->idiag_root
) {
2356 debugfs_remove(phba
->idiag_root
);
2357 phba
->idiag_root
= NULL
;
2361 if (phba
->hba_debugfs_root
) {
2362 debugfs_remove(phba
->hba_debugfs_root
); /* fnX */
2363 phba
->hba_debugfs_root
= NULL
;
2364 atomic_dec(&lpfc_debugfs_hba_count
);
2367 if (atomic_read(&lpfc_debugfs_hba_count
) == 0) {
2368 debugfs_remove(lpfc_debugfs_root
); /* lpfc */
2369 lpfc_debugfs_root
= NULL
;