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"
53 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
57 * To access this interface the user should:
58 * # mount -t debugfs none /sys/kernel/debug
60 * The lpfc debugfs directory hierarchy is:
61 * /sys/kernel/debug/lpfc/fnX/vportY
62 * where X is the lpfc hba function unique_id
63 * where Y is the vport VPI on that hba
65 * Debugging services available per vport:
67 * This is an ACSII readable file that contains a trace of the last
68 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
69 * See lpfc_debugfs.h for different categories of discovery events.
70 * To enable the discovery trace, the following module parameters must be set:
71 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
72 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
73 * EACH vport. X MUST also be a power of 2.
74 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
78 * This is an ACSII readable file that contains a trace of the last
79 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
80 * To enable the slow ring trace, the following module parameters must be set:
81 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
82 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
83 * the HBA. X MUST also be a power of 2.
85 static int lpfc_debugfs_enable
= 1;
86 module_param(lpfc_debugfs_enable
, int, S_IRUGO
);
87 MODULE_PARM_DESC(lpfc_debugfs_enable
, "Enable debugfs services");
89 /* This MUST be a power of 2 */
90 static int lpfc_debugfs_max_disc_trc
;
91 module_param(lpfc_debugfs_max_disc_trc
, int, S_IRUGO
);
92 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc
,
93 "Set debugfs discovery trace depth");
95 /* This MUST be a power of 2 */
96 static int lpfc_debugfs_max_slow_ring_trc
;
97 module_param(lpfc_debugfs_max_slow_ring_trc
, int, S_IRUGO
);
98 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc
,
99 "Set debugfs slow ring trace depth");
101 static int lpfc_debugfs_mask_disc_trc
;
102 module_param(lpfc_debugfs_mask_disc_trc
, int, S_IRUGO
);
103 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc
,
104 "Set debugfs discovery trace mask");
106 #include <linux/debugfs.h>
108 static atomic_t lpfc_debugfs_seq_trc_cnt
= ATOMIC_INIT(0);
109 static unsigned long lpfc_debugfs_start_time
= 0L;
112 static struct lpfc_idiag idiag
;
115 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
116 * @vport: The vport to gather the log info from.
117 * @buf: The buffer to dump log into.
118 * @size: The maximum amount of data to process.
121 * This routine gathers the lpfc discovery debugfs data from the @vport and
122 * dumps it to @buf up to @size number of bytes. It will start at the next entry
123 * in the log and process the log until the end of the buffer. Then it will
124 * gather from the beginning of the log and process until the current entry.
127 * Discovery logging will be disabled while while this routine dumps the log.
130 * This routine returns the amount of bytes that were dumped into @buf and will
134 lpfc_debugfs_disc_trc_data(struct lpfc_vport
*vport
, char *buf
, int size
)
136 int i
, index
, len
, enable
;
138 struct lpfc_debugfs_trc
*dtp
;
141 buffer
= kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE
, GFP_KERNEL
);
145 enable
= lpfc_debugfs_enable
;
146 lpfc_debugfs_enable
= 0;
149 index
= (atomic_read(&vport
->disc_trc_cnt
) + 1) &
150 (lpfc_debugfs_max_disc_trc
- 1);
151 for (i
= index
; i
< lpfc_debugfs_max_disc_trc
; i
++) {
152 dtp
= vport
->disc_trc
+ i
;
155 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
157 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
158 dtp
->seq_cnt
, ms
, dtp
->fmt
);
159 len
+= snprintf(buf
+len
, size
-len
, buffer
,
160 dtp
->data1
, dtp
->data2
, dtp
->data3
);
162 for (i
= 0; i
< index
; i
++) {
163 dtp
= vport
->disc_trc
+ i
;
166 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
168 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
169 dtp
->seq_cnt
, ms
, dtp
->fmt
);
170 len
+= snprintf(buf
+len
, size
-len
, buffer
,
171 dtp
->data1
, dtp
->data2
, dtp
->data3
);
174 lpfc_debugfs_enable
= enable
;
181 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
182 * @phba: The HBA to gather the log info from.
183 * @buf: The buffer to dump log into.
184 * @size: The maximum amount of data to process.
187 * This routine gathers the lpfc slow ring debugfs data from the @phba and
188 * dumps it to @buf up to @size number of bytes. It will start at the next entry
189 * in the log and process the log until the end of the buffer. Then it will
190 * gather from the beginning of the log and process until the current entry.
193 * Slow ring logging will be disabled while while this routine dumps the log.
196 * This routine returns the amount of bytes that were dumped into @buf and will
200 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba
*phba
, char *buf
, int size
)
202 int i
, index
, len
, enable
;
204 struct lpfc_debugfs_trc
*dtp
;
207 buffer
= kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE
, GFP_KERNEL
);
211 enable
= lpfc_debugfs_enable
;
212 lpfc_debugfs_enable
= 0;
215 index
= (atomic_read(&phba
->slow_ring_trc_cnt
) + 1) &
216 (lpfc_debugfs_max_slow_ring_trc
- 1);
217 for (i
= index
; i
< lpfc_debugfs_max_slow_ring_trc
; i
++) {
218 dtp
= phba
->slow_ring_trc
+ i
;
221 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
223 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
224 dtp
->seq_cnt
, ms
, dtp
->fmt
);
225 len
+= snprintf(buf
+len
, size
-len
, buffer
,
226 dtp
->data1
, dtp
->data2
, dtp
->data3
);
228 for (i
= 0; i
< index
; i
++) {
229 dtp
= phba
->slow_ring_trc
+ i
;
232 ms
= jiffies_to_msecs(dtp
->jif
- lpfc_debugfs_start_time
);
234 LPFC_DEBUG_TRC_ENTRY_SIZE
, "%010d:%010d ms:%s\n",
235 dtp
->seq_cnt
, ms
, dtp
->fmt
);
236 len
+= snprintf(buf
+len
, size
-len
, buffer
,
237 dtp
->data1
, dtp
->data2
, dtp
->data3
);
240 lpfc_debugfs_enable
= enable
;
246 static int lpfc_debugfs_last_hbq
= -1;
249 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
250 * @phba: The HBA to gather host buffer info from.
251 * @buf: The buffer to dump log into.
252 * @size: The maximum amount of data to process.
255 * This routine dumps the host buffer queue info from the @phba to @buf up to
256 * @size number of bytes. A header that describes the current hbq state will be
257 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
258 * until @size bytes have been dumped or all the hbq info has been dumped.
261 * This routine will rotate through each configured HBQ each time called.
264 * This routine returns the amount of bytes that were dumped into @buf and will
268 lpfc_debugfs_hbqinfo_data(struct lpfc_hba
*phba
, char *buf
, int size
)
271 int cnt
, i
, j
, found
, posted
, low
;
272 uint32_t phys
, raw_index
, getidx
;
273 struct lpfc_hbq_init
*hip
;
275 struct lpfc_hbq_entry
*hbqe
;
276 struct lpfc_dmabuf
*d_buf
;
277 struct hbq_dmabuf
*hbq_buf
;
279 if (phba
->sli_rev
!= 3)
281 cnt
= LPFC_HBQINFO_SIZE
;
282 spin_lock_irq(&phba
->hbalock
);
284 /* toggle between multiple hbqs, if any */
285 i
= lpfc_sli_hbq_count();
287 lpfc_debugfs_last_hbq
++;
288 if (lpfc_debugfs_last_hbq
>= i
)
289 lpfc_debugfs_last_hbq
= 0;
292 lpfc_debugfs_last_hbq
= 0;
294 i
= lpfc_debugfs_last_hbq
;
296 len
+= snprintf(buf
+len
, size
-len
, "HBQ %d Info\n", i
);
298 hbqs
= &phba
->hbqs
[i
];
300 list_for_each_entry(d_buf
, &hbqs
->hbq_buffer_list
, list
)
303 hip
= lpfc_hbq_defs
[i
];
304 len
+= snprintf(buf
+len
, size
-len
,
305 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
306 hip
->hbq_index
, hip
->profile
, hip
->rn
,
307 hip
->buffer_count
, hip
->init_count
, hip
->add_count
, posted
);
309 raw_index
= phba
->hbq_get
[i
];
310 getidx
= le32_to_cpu(raw_index
);
311 len
+= snprintf(buf
+len
, size
-len
,
312 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
313 hbqs
->entry_count
, hbqs
->buffer_count
, hbqs
->hbqPutIdx
,
314 hbqs
->next_hbqPutIdx
, hbqs
->local_hbqGetIdx
, getidx
);
316 hbqe
= (struct lpfc_hbq_entry
*) phba
->hbqs
[i
].hbq_virt
;
317 for (j
=0; j
<hbqs
->entry_count
; j
++) {
318 len
+= snprintf(buf
+len
, size
-len
,
319 "%03d: %08x %04x %05x ", j
,
320 le32_to_cpu(hbqe
->bde
.addrLow
),
321 le32_to_cpu(hbqe
->bde
.tus
.w
),
322 le32_to_cpu(hbqe
->buffer_tag
));
326 /* First calculate if slot has an associated posted buffer */
327 low
= hbqs
->hbqPutIdx
- posted
;
329 if ((j
>= hbqs
->hbqPutIdx
) || (j
< low
)) {
330 len
+= snprintf(buf
+len
, size
-len
, "Unused\n");
335 if ((j
>= hbqs
->hbqPutIdx
) &&
336 (j
< (hbqs
->entry_count
+low
))) {
337 len
+= snprintf(buf
+len
, size
-len
, "Unused\n");
342 /* Get the Buffer info for the posted buffer */
343 list_for_each_entry(d_buf
, &hbqs
->hbq_buffer_list
, list
) {
344 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
345 phys
= ((uint64_t)hbq_buf
->dbuf
.phys
& 0xffffffff);
346 if (phys
== le32_to_cpu(hbqe
->bde
.addrLow
)) {
347 len
+= snprintf(buf
+len
, size
-len
,
348 "Buf%d: %p %06x\n", i
,
349 hbq_buf
->dbuf
.virt
, hbq_buf
->tag
);
356 len
+= snprintf(buf
+len
, size
-len
, "No DMAinfo?\n");
360 if (len
> LPFC_HBQINFO_SIZE
- 54)
363 spin_unlock_irq(&phba
->hbalock
);
367 static int lpfc_debugfs_last_hba_slim_off
;
370 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
371 * @phba: The HBA to gather SLIM info from.
372 * @buf: The buffer to dump log into.
373 * @size: The maximum amount of data to process.
376 * This routine dumps the current contents of HBA SLIM for the HBA associated
377 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
380 * This routine will only dump up to 1024 bytes of data each time called and
381 * should be called multiple times to dump the entire HBA SLIM.
384 * This routine returns the amount of bytes that were dumped into @buf and will
388 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba
*phba
, char *buf
, int size
)
395 buffer
= kmalloc(1024, GFP_KERNEL
);
400 spin_lock_irq(&phba
->hbalock
);
402 len
+= snprintf(buf
+len
, size
-len
, "HBA SLIM\n");
403 lpfc_memcpy_from_slim(buffer
,
404 phba
->MBslimaddr
+ lpfc_debugfs_last_hba_slim_off
, 1024);
406 ptr
= (uint32_t *)&buffer
[0];
407 off
= lpfc_debugfs_last_hba_slim_off
;
409 /* Set it up for the next time */
410 lpfc_debugfs_last_hba_slim_off
+= 1024;
411 if (lpfc_debugfs_last_hba_slim_off
>= 4096)
412 lpfc_debugfs_last_hba_slim_off
= 0;
416 len
+= snprintf(buf
+len
, size
-len
,
417 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
418 off
, *ptr
, *(ptr
+1), *(ptr
+2), *(ptr
+3), *(ptr
+4),
419 *(ptr
+5), *(ptr
+6), *(ptr
+7));
421 i
-= (8 * sizeof(uint32_t));
422 off
+= (8 * sizeof(uint32_t));
425 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 boundary */
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 boundary */
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
);
1000 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1001 * @inode: The inode pointer that contains a vport pointer.
1002 * @file: The file pointer to attach the log output.
1005 * This routine is the entry point for the debugfs open file operation. It gets
1006 * the vport from the i_private field in @inode, allocates the necessary buffer
1007 * for the log, fills the buffer from the in-memory log for this vport, and then
1008 * returns a pointer to that log in the private_data field in @file.
1011 * This function returns zero if successful. On error it will return an negative
1015 lpfc_debugfs_nodelist_open(struct inode
*inode
, struct file
*file
)
1017 struct lpfc_vport
*vport
= inode
->i_private
;
1018 struct lpfc_debug
*debug
;
1021 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
1025 /* Round to page boundary */
1026 debug
->buffer
= kmalloc(LPFC_NODELIST_SIZE
, GFP_KERNEL
);
1027 if (!debug
->buffer
) {
1032 debug
->len
= lpfc_debugfs_nodelist_data(vport
, debug
->buffer
,
1033 LPFC_NODELIST_SIZE
);
1034 file
->private_data
= debug
;
1042 * lpfc_debugfs_lseek - Seek through a debugfs file
1043 * @file: The file pointer to seek through.
1044 * @off: The offset to seek to or the amount to seek by.
1045 * @whence: Indicates how to seek.
1048 * This routine is the entry point for the debugfs lseek file operation. The
1049 * @whence parameter indicates whether @off is the offset to directly seek to,
1050 * or if it is a value to seek forward or reverse by. This function figures out
1051 * what the new offset of the debugfs file will be and assigns that value to the
1052 * f_pos field of @file.
1055 * This function returns the new offset if successful and returns a negative
1056 * error if unable to process the seek.
1059 lpfc_debugfs_lseek(struct file
*file
, loff_t off
, int whence
)
1061 struct lpfc_debug
*debug
;
1064 debug
= file
->private_data
;
1071 pos
= file
->f_pos
+ off
;
1074 pos
= debug
->len
- off
;
1076 return (pos
< 0 || pos
> debug
->len
) ? -EINVAL
: (file
->f_pos
= pos
);
1080 * lpfc_debugfs_read - Read a debugfs file
1081 * @file: The file pointer to read from.
1082 * @buf: The buffer to copy the data to.
1083 * @nbytes: The number of bytes to read.
1084 * @ppos: The position in the file to start reading from.
1087 * This routine reads data from from the buffer indicated in the private_data
1088 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1092 * This function returns the amount of data that was read (this could be less
1093 * than @nbytes if the end of the file was reached) or a negative error value.
1096 lpfc_debugfs_read(struct file
*file
, char __user
*buf
,
1097 size_t nbytes
, loff_t
*ppos
)
1099 struct lpfc_debug
*debug
= file
->private_data
;
1101 return simple_read_from_buffer(buf
, nbytes
, ppos
, debug
->buffer
,
1106 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1107 * @inode: The inode pointer that contains a vport pointer. (unused)
1108 * @file: The file pointer that contains the buffer to release.
1111 * This routine frees the buffer that was allocated when the debugfs file was
1115 * This function returns zero.
1118 lpfc_debugfs_release(struct inode
*inode
, struct file
*file
)
1120 struct lpfc_debug
*debug
= file
->private_data
;
1122 kfree(debug
->buffer
);
1129 lpfc_debugfs_dumpDataDif_release(struct inode
*inode
, struct file
*file
)
1131 struct lpfc_debug
*debug
= file
->private_data
;
1133 debug
->buffer
= NULL
;
1140 * ---------------------------------
1141 * iDiag debugfs file access methods
1142 * ---------------------------------
1144 * All access methods are through the proper SLI4 PCI function's debugfs
1147 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1151 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1152 * @buf: The pointer to the user space buffer.
1153 * @nbytes: The number of bytes in the user space buffer.
1154 * @idiag_cmd: pointer to the idiag command struct.
1156 * This routine reads data from debugfs user space buffer and parses the
1157 * buffer for getting the idiag command and arguments. The while space in
1158 * between the set of data is used as the parsing separator.
1160 * This routine returns 0 when successful, it returns proper error code
1161 * back to the user space in error conditions.
1163 static int lpfc_idiag_cmd_get(const char __user
*buf
, size_t nbytes
,
1164 struct lpfc_idiag_cmd
*idiag_cmd
)
1167 char *pbuf
, *step_str
;
1171 /* Protect copy from user */
1172 if (!access_ok(VERIFY_READ
, buf
, nbytes
))
1175 memset(mybuf
, 0, sizeof(mybuf
));
1176 memset(idiag_cmd
, 0, sizeof(*idiag_cmd
));
1177 bsize
= min(nbytes
, (sizeof(mybuf
)-1));
1179 if (copy_from_user(mybuf
, buf
, bsize
))
1182 step_str
= strsep(&pbuf
, "\t ");
1184 /* The opcode must present */
1188 idiag_cmd
->opcode
= simple_strtol(step_str
, NULL
, 0);
1189 if (idiag_cmd
->opcode
== 0)
1192 for (i
= 0; i
< LPFC_IDIAG_CMD_DATA_SIZE
; i
++) {
1193 step_str
= strsep(&pbuf
, "\t ");
1196 idiag_cmd
->data
[i
] = simple_strtol(step_str
, NULL
, 0);
1202 * lpfc_idiag_open - idiag open debugfs
1203 * @inode: The inode pointer that contains a pointer to phba.
1204 * @file: The file pointer to attach the file operation.
1207 * This routine is the entry point for the debugfs open file operation. It
1208 * gets the reference to phba from the i_private field in @inode, it then
1209 * allocates buffer for the file operation, performs the necessary PCI config
1210 * space read into the allocated buffer according to the idiag user command
1211 * setup, and then returns a pointer to buffer in the private_data field in
1215 * This function returns zero if successful. On error it will return an
1216 * negative error value.
1219 lpfc_idiag_open(struct inode
*inode
, struct file
*file
)
1221 struct lpfc_debug
*debug
;
1223 debug
= kmalloc(sizeof(*debug
), GFP_KERNEL
);
1227 debug
->i_private
= inode
->i_private
;
1228 debug
->buffer
= NULL
;
1229 file
->private_data
= debug
;
1235 * lpfc_idiag_release - Release idiag access file operation
1236 * @inode: The inode pointer that contains a vport pointer. (unused)
1237 * @file: The file pointer that contains the buffer to release.
1240 * This routine is the generic release routine for the idiag access file
1241 * operation, it frees the buffer that was allocated when the debugfs file
1245 * This function returns zero.
1248 lpfc_idiag_release(struct inode
*inode
, struct file
*file
)
1250 struct lpfc_debug
*debug
= file
->private_data
;
1252 /* Free the buffers to the file operation */
1253 kfree(debug
->buffer
);
1260 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1261 * @inode: The inode pointer that contains a vport pointer. (unused)
1262 * @file: The file pointer that contains the buffer to release.
1265 * This routine frees the buffer that was allocated when the debugfs file
1266 * was opened. It also reset the fields in the idiag command struct in the
1267 * case of command for write operation.
1270 * This function returns zero.
1273 lpfc_idiag_cmd_release(struct inode
*inode
, struct file
*file
)
1275 struct lpfc_debug
*debug
= file
->private_data
;
1277 if (debug
->op
== LPFC_IDIAG_OP_WR
) {
1278 switch (idiag
.cmd
.opcode
) {
1279 case LPFC_IDIAG_CMD_PCICFG_WR
:
1280 case LPFC_IDIAG_CMD_PCICFG_ST
:
1281 case LPFC_IDIAG_CMD_PCICFG_CL
:
1282 case LPFC_IDIAG_CMD_QUEACC_WR
:
1283 case LPFC_IDIAG_CMD_QUEACC_ST
:
1284 case LPFC_IDIAG_CMD_QUEACC_CL
:
1285 memset(&idiag
, 0, sizeof(idiag
));
1292 /* Free the buffers to the file operation */
1293 kfree(debug
->buffer
);
1300 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1301 * @file: The file pointer to read from.
1302 * @buf: The buffer to copy the data to.
1303 * @nbytes: The number of bytes to read.
1304 * @ppos: The position in the file to start reading from.
1307 * This routine reads data from the @phba pci config space according to the
1308 * idiag command, and copies to user @buf. Depending on the PCI config space
1309 * read command setup, it does either a single register read of a byte
1310 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1311 * registers from the 4K extended PCI config space.
1314 * This function returns the amount of data that was read (this could be less
1315 * than @nbytes if the end of the file was reached) or a negative error value.
1318 lpfc_idiag_pcicfg_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
1321 struct lpfc_debug
*debug
= file
->private_data
;
1322 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
1323 int offset_label
, offset
, len
= 0, index
= LPFC_PCI_CFG_RD_SIZE
;
1326 struct pci_dev
*pdev
;
1331 pdev
= phba
->pcidev
;
1335 /* This is a user read operation */
1336 debug
->op
= LPFC_IDIAG_OP_RD
;
1339 debug
->buffer
= kmalloc(LPFC_PCI_CFG_SIZE
, GFP_KERNEL
);
1342 pbuffer
= debug
->buffer
;
1347 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_RD
) {
1348 where
= idiag
.cmd
.data
[IDIAG_PCICFG_WHERE_INDX
];
1349 count
= idiag
.cmd
.data
[IDIAG_PCICFG_COUNT_INDX
];
1353 /* Read single PCI config space register */
1355 case SIZE_U8
: /* byte (8 bits) */
1356 pci_read_config_byte(pdev
, where
, &u8val
);
1357 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1358 "%03x: %02x\n", where
, u8val
);
1360 case SIZE_U16
: /* word (16 bits) */
1361 pci_read_config_word(pdev
, where
, &u16val
);
1362 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1363 "%03x: %04x\n", where
, u16val
);
1365 case SIZE_U32
: /* double word (32 bits) */
1366 pci_read_config_dword(pdev
, where
, &u32val
);
1367 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1368 "%03x: %08x\n", where
, u32val
);
1370 case LPFC_PCI_CFG_BROWSE
: /* browse all */
1378 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
1382 /* Browse all PCI config space registers */
1383 offset_label
= idiag
.offset
.last_rd
;
1384 offset
= offset_label
;
1386 /* Read PCI config space */
1387 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1388 "%03x: ", offset_label
);
1390 pci_read_config_dword(pdev
, offset
, &u32val
);
1391 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1393 offset
+= sizeof(uint32_t);
1394 if (offset
>= LPFC_PCI_CFG_SIZE
) {
1395 len
+= snprintf(pbuffer
+len
,
1396 LPFC_PCI_CFG_SIZE
-len
, "\n");
1399 index
-= sizeof(uint32_t);
1401 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1403 else if (!(index
% (8 * sizeof(uint32_t)))) {
1404 offset_label
+= (8 * sizeof(uint32_t));
1405 len
+= snprintf(pbuffer
+len
, LPFC_PCI_CFG_SIZE
-len
,
1406 "\n%03x: ", offset_label
);
1410 /* Set up the offset for next portion of pci cfg read */
1412 idiag
.offset
.last_rd
+= LPFC_PCI_CFG_RD_SIZE
;
1413 if (idiag
.offset
.last_rd
>= LPFC_PCI_CFG_SIZE
)
1414 idiag
.offset
.last_rd
= 0;
1416 idiag
.offset
.last_rd
= 0;
1418 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
1422 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1423 * @file: The file pointer to read from.
1424 * @buf: The buffer to copy the user data from.
1425 * @nbytes: The number of bytes to get.
1426 * @ppos: The position in the file to start reading from.
1428 * This routine get the debugfs idiag command struct from user space and
1429 * then perform the syntax check for PCI config space read or write command
1430 * accordingly. In the case of PCI config space read command, it sets up
1431 * the command in the idiag command struct for the debugfs read operation.
1432 * In the case of PCI config space write operation, it executes the write
1433 * operation into the PCI config space accordingly.
1435 * It returns the @nbytges passing in from debugfs user space when successful.
1436 * In case of error conditions, it returns proper error code back to the user
1440 lpfc_idiag_pcicfg_write(struct file
*file
, const char __user
*buf
,
1441 size_t nbytes
, loff_t
*ppos
)
1443 struct lpfc_debug
*debug
= file
->private_data
;
1444 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
1445 uint32_t where
, value
, count
;
1449 struct pci_dev
*pdev
;
1452 pdev
= phba
->pcidev
;
1456 /* This is a user write operation */
1457 debug
->op
= LPFC_IDIAG_OP_WR
;
1459 rc
= lpfc_idiag_cmd_get(buf
, nbytes
, &idiag
.cmd
);
1463 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_RD
) {
1464 /* Sanity check on PCI config read command line arguments */
1465 if (rc
!= LPFC_PCI_CFG_RD_CMD_ARG
)
1467 /* Read command from PCI config space, set up command fields */
1468 where
= idiag
.cmd
.data
[IDIAG_PCICFG_WHERE_INDX
];
1469 count
= idiag
.cmd
.data
[IDIAG_PCICFG_COUNT_INDX
];
1470 if (count
== LPFC_PCI_CFG_BROWSE
) {
1471 if (where
% sizeof(uint32_t))
1473 /* Starting offset to browse */
1474 idiag
.offset
.last_rd
= where
;
1475 } else if ((count
!= sizeof(uint8_t)) &&
1476 (count
!= sizeof(uint16_t)) &&
1477 (count
!= sizeof(uint32_t)))
1479 if (count
== sizeof(uint8_t)) {
1480 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint8_t))
1482 if (where
% sizeof(uint8_t))
1485 if (count
== sizeof(uint16_t)) {
1486 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint16_t))
1488 if (where
% sizeof(uint16_t))
1491 if (count
== sizeof(uint32_t)) {
1492 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint32_t))
1494 if (where
% sizeof(uint32_t))
1497 } else if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
||
1498 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_ST
||
1499 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_CL
) {
1500 /* Sanity check on PCI config write command line arguments */
1501 if (rc
!= LPFC_PCI_CFG_WR_CMD_ARG
)
1503 /* Write command to PCI config space, read-modify-write */
1504 where
= idiag
.cmd
.data
[IDIAG_PCICFG_WHERE_INDX
];
1505 count
= idiag
.cmd
.data
[IDIAG_PCICFG_COUNT_INDX
];
1506 value
= idiag
.cmd
.data
[IDIAG_PCICFG_VALUE_INDX
];
1508 if ((count
!= sizeof(uint8_t)) &&
1509 (count
!= sizeof(uint16_t)) &&
1510 (count
!= sizeof(uint32_t)))
1512 if (count
== sizeof(uint8_t)) {
1513 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint8_t))
1515 if (where
% sizeof(uint8_t))
1517 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
)
1518 pci_write_config_byte(pdev
, where
,
1520 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_ST
) {
1521 rc
= pci_read_config_byte(pdev
, where
, &u8val
);
1523 u8val
|= (uint8_t)value
;
1524 pci_write_config_byte(pdev
, where
,
1528 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_CL
) {
1529 rc
= pci_read_config_byte(pdev
, where
, &u8val
);
1531 u8val
&= (uint8_t)(~value
);
1532 pci_write_config_byte(pdev
, where
,
1537 if (count
== sizeof(uint16_t)) {
1538 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint16_t))
1540 if (where
% sizeof(uint16_t))
1542 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
)
1543 pci_write_config_word(pdev
, where
,
1545 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_ST
) {
1546 rc
= pci_read_config_word(pdev
, where
, &u16val
);
1548 u16val
|= (uint16_t)value
;
1549 pci_write_config_word(pdev
, where
,
1553 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_CL
) {
1554 rc
= pci_read_config_word(pdev
, where
, &u16val
);
1556 u16val
&= (uint16_t)(~value
);
1557 pci_write_config_word(pdev
, where
,
1562 if (count
== sizeof(uint32_t)) {
1563 if (where
> LPFC_PCI_CFG_SIZE
- sizeof(uint32_t))
1565 if (where
% sizeof(uint32_t))
1567 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_WR
)
1568 pci_write_config_dword(pdev
, where
, value
);
1569 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_ST
) {
1570 rc
= pci_read_config_dword(pdev
, where
,
1574 pci_write_config_dword(pdev
, where
,
1578 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_PCICFG_CL
) {
1579 rc
= pci_read_config_dword(pdev
, where
,
1583 pci_write_config_dword(pdev
, where
,
1589 /* All other opecodes are illegal for now */
1594 memset(&idiag
, 0, sizeof(idiag
));
1599 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1600 * @file: The file pointer to read from.
1601 * @buf: The buffer to copy the data to.
1602 * @nbytes: The number of bytes to read.
1603 * @ppos: The position in the file to start reading from.
1606 * This routine reads data from the @phba pci bar memory mapped space
1607 * according to the idiag command, and copies to user @buf.
1610 * This function returns the amount of data that was read (this could be less
1611 * than @nbytes if the end of the file was reached) or a negative error value.
1614 lpfc_idiag_baracc_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
1617 struct lpfc_debug
*debug
= file
->private_data
;
1618 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
1619 int offset_label
, offset
, offset_run
, len
= 0, index
;
1620 int bar_num
, acc_range
, bar_size
;
1622 void __iomem
*mem_mapped_bar
;
1624 struct pci_dev
*pdev
;
1627 pdev
= phba
->pcidev
;
1631 /* This is a user read operation */
1632 debug
->op
= LPFC_IDIAG_OP_RD
;
1635 debug
->buffer
= kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE
, GFP_KERNEL
);
1638 pbuffer
= debug
->buffer
;
1643 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_BARACC_RD
) {
1644 bar_num
= idiag
.cmd
.data
[IDIAG_BARACC_BAR_NUM_INDX
];
1645 offset
= idiag
.cmd
.data
[IDIAG_BARACC_OFF_SET_INDX
];
1646 acc_range
= idiag
.cmd
.data
[IDIAG_BARACC_ACC_MOD_INDX
];
1647 bar_size
= idiag
.cmd
.data
[IDIAG_BARACC_BAR_SZE_INDX
];
1654 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1655 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
) {
1656 if (bar_num
== IDIAG_BARACC_BAR_0
)
1657 mem_mapped_bar
= phba
->sli4_hba
.conf_regs_memmap_p
;
1658 else if (bar_num
== IDIAG_BARACC_BAR_1
)
1659 mem_mapped_bar
= phba
->sli4_hba
.ctrl_regs_memmap_p
;
1660 else if (bar_num
== IDIAG_BARACC_BAR_2
)
1661 mem_mapped_bar
= phba
->sli4_hba
.drbl_regs_memmap_p
;
1664 } else if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
1665 if (bar_num
== IDIAG_BARACC_BAR_0
)
1666 mem_mapped_bar
= phba
->sli4_hba
.conf_regs_memmap_p
;
1672 /* Read single PCI bar space register */
1673 if (acc_range
== SINGLE_WORD
) {
1674 offset_run
= offset
;
1675 u32val
= readl(mem_mapped_bar
+ offset_run
);
1676 len
+= snprintf(pbuffer
+len
, LPFC_PCI_BAR_RD_BUF_SIZE
-len
,
1677 "%05x: %08x\n", offset_run
, u32val
);
1681 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
1685 /* Browse all PCI bar space registers */
1686 offset_label
= idiag
.offset
.last_rd
;
1687 offset_run
= offset_label
;
1689 /* Read PCI bar memory mapped space */
1690 len
+= snprintf(pbuffer
+len
, LPFC_PCI_BAR_RD_BUF_SIZE
-len
,
1691 "%05x: ", offset_label
);
1692 index
= LPFC_PCI_BAR_RD_SIZE
;
1694 u32val
= readl(mem_mapped_bar
+ offset_run
);
1695 len
+= snprintf(pbuffer
+len
, LPFC_PCI_BAR_RD_BUF_SIZE
-len
,
1697 offset_run
+= sizeof(uint32_t);
1698 if (acc_range
== LPFC_PCI_BAR_BROWSE
) {
1699 if (offset_run
>= bar_size
) {
1700 len
+= snprintf(pbuffer
+len
,
1701 LPFC_PCI_BAR_RD_BUF_SIZE
-len
, "\n");
1705 if (offset_run
>= offset
+
1706 (acc_range
* sizeof(uint32_t))) {
1707 len
+= snprintf(pbuffer
+len
,
1708 LPFC_PCI_BAR_RD_BUF_SIZE
-len
, "\n");
1712 index
-= sizeof(uint32_t);
1714 len
+= snprintf(pbuffer
+len
,
1715 LPFC_PCI_BAR_RD_BUF_SIZE
-len
, "\n");
1716 else if (!(index
% (8 * sizeof(uint32_t)))) {
1717 offset_label
+= (8 * sizeof(uint32_t));
1718 len
+= snprintf(pbuffer
+len
,
1719 LPFC_PCI_BAR_RD_BUF_SIZE
-len
,
1720 "\n%05x: ", offset_label
);
1724 /* Set up the offset for next portion of pci bar read */
1726 idiag
.offset
.last_rd
+= LPFC_PCI_BAR_RD_SIZE
;
1727 if (acc_range
== LPFC_PCI_BAR_BROWSE
) {
1728 if (idiag
.offset
.last_rd
>= bar_size
)
1729 idiag
.offset
.last_rd
= 0;
1731 if (offset_run
>= offset
+
1732 (acc_range
* sizeof(uint32_t)))
1733 idiag
.offset
.last_rd
= offset
;
1736 if (acc_range
== LPFC_PCI_BAR_BROWSE
)
1737 idiag
.offset
.last_rd
= 0;
1739 idiag
.offset
.last_rd
= offset
;
1742 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
1746 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1747 * @file: The file pointer to read from.
1748 * @buf: The buffer to copy the user data from.
1749 * @nbytes: The number of bytes to get.
1750 * @ppos: The position in the file to start reading from.
1752 * This routine get the debugfs idiag command struct from user space and
1753 * then perform the syntax check for PCI bar memory mapped space read or
1754 * write command accordingly. In the case of PCI bar memory mapped space
1755 * read command, it sets up the command in the idiag command struct for
1756 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1757 * write operation, it executes the write operation into the PCI bar memory
1758 * mapped space accordingly.
1760 * It returns the @nbytges passing in from debugfs user space when successful.
1761 * In case of error conditions, it returns proper error code back to the user
1765 lpfc_idiag_baracc_write(struct file
*file
, const char __user
*buf
,
1766 size_t nbytes
, loff_t
*ppos
)
1768 struct lpfc_debug
*debug
= file
->private_data
;
1769 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
1770 uint32_t bar_num
, bar_size
, offset
, value
, acc_range
;
1771 struct pci_dev
*pdev
;
1772 void __iomem
*mem_mapped_bar
;
1777 pdev
= phba
->pcidev
;
1781 /* This is a user write operation */
1782 debug
->op
= LPFC_IDIAG_OP_WR
;
1784 rc
= lpfc_idiag_cmd_get(buf
, nbytes
, &idiag
.cmd
);
1788 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1789 bar_num
= idiag
.cmd
.data
[IDIAG_BARACC_BAR_NUM_INDX
];
1791 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
) {
1792 if ((bar_num
!= IDIAG_BARACC_BAR_0
) &&
1793 (bar_num
!= IDIAG_BARACC_BAR_1
) &&
1794 (bar_num
!= IDIAG_BARACC_BAR_2
))
1796 } else if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
1797 if (bar_num
!= IDIAG_BARACC_BAR_0
)
1802 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
) {
1803 if (bar_num
== IDIAG_BARACC_BAR_0
) {
1804 idiag
.cmd
.data
[IDIAG_BARACC_BAR_SZE_INDX
] =
1805 LPFC_PCI_IF0_BAR0_SIZE
;
1806 mem_mapped_bar
= phba
->sli4_hba
.conf_regs_memmap_p
;
1807 } else if (bar_num
== IDIAG_BARACC_BAR_1
) {
1808 idiag
.cmd
.data
[IDIAG_BARACC_BAR_SZE_INDX
] =
1809 LPFC_PCI_IF0_BAR1_SIZE
;
1810 mem_mapped_bar
= phba
->sli4_hba
.ctrl_regs_memmap_p
;
1811 } else if (bar_num
== IDIAG_BARACC_BAR_2
) {
1812 idiag
.cmd
.data
[IDIAG_BARACC_BAR_SZE_INDX
] =
1813 LPFC_PCI_IF0_BAR2_SIZE
;
1814 mem_mapped_bar
= phba
->sli4_hba
.drbl_regs_memmap_p
;
1817 } else if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
1818 if (bar_num
== IDIAG_BARACC_BAR_0
) {
1819 idiag
.cmd
.data
[IDIAG_BARACC_BAR_SZE_INDX
] =
1820 LPFC_PCI_IF2_BAR0_SIZE
;
1821 mem_mapped_bar
= phba
->sli4_hba
.conf_regs_memmap_p
;
1827 offset
= idiag
.cmd
.data
[IDIAG_BARACC_OFF_SET_INDX
];
1828 if (offset
% sizeof(uint32_t))
1831 bar_size
= idiag
.cmd
.data
[IDIAG_BARACC_BAR_SZE_INDX
];
1832 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_BARACC_RD
) {
1833 /* Sanity check on PCI config read command line arguments */
1834 if (rc
!= LPFC_PCI_BAR_RD_CMD_ARG
)
1836 acc_range
= idiag
.cmd
.data
[IDIAG_BARACC_ACC_MOD_INDX
];
1837 if (acc_range
== LPFC_PCI_BAR_BROWSE
) {
1838 if (offset
> bar_size
- sizeof(uint32_t))
1840 /* Starting offset to browse */
1841 idiag
.offset
.last_rd
= offset
;
1842 } else if (acc_range
> SINGLE_WORD
) {
1843 if (offset
+ acc_range
* sizeof(uint32_t) > bar_size
)
1845 /* Starting offset to browse */
1846 idiag
.offset
.last_rd
= offset
;
1847 } else if (acc_range
!= SINGLE_WORD
)
1849 } else if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_BARACC_WR
||
1850 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_BARACC_ST
||
1851 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_BARACC_CL
) {
1852 /* Sanity check on PCI bar write command line arguments */
1853 if (rc
!= LPFC_PCI_BAR_WR_CMD_ARG
)
1855 /* Write command to PCI bar space, read-modify-write */
1856 acc_range
= SINGLE_WORD
;
1857 value
= idiag
.cmd
.data
[IDIAG_BARACC_REG_VAL_INDX
];
1858 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_BARACC_WR
) {
1859 writel(value
, mem_mapped_bar
+ offset
);
1860 readl(mem_mapped_bar
+ offset
);
1862 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_BARACC_ST
) {
1863 u32val
= readl(mem_mapped_bar
+ offset
);
1865 writel(u32val
, mem_mapped_bar
+ offset
);
1866 readl(mem_mapped_bar
+ offset
);
1868 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_BARACC_CL
) {
1869 u32val
= readl(mem_mapped_bar
+ offset
);
1871 writel(u32val
, mem_mapped_bar
+ offset
);
1872 readl(mem_mapped_bar
+ offset
);
1875 /* All other opecodes are illegal for now */
1880 memset(&idiag
, 0, sizeof(idiag
));
1885 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1886 * @file: The file pointer to read from.
1887 * @buf: The buffer to copy the data to.
1888 * @nbytes: The number of bytes to read.
1889 * @ppos: The position in the file to start reading from.
1892 * This routine reads data from the @phba SLI4 PCI function queue information,
1893 * and copies to user @buf.
1896 * This function returns the amount of data that was read (this could be less
1897 * than @nbytes if the end of the file was reached) or a negative error value.
1900 lpfc_idiag_queinfo_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
1903 struct lpfc_debug
*debug
= file
->private_data
;
1904 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
1905 int len
= 0, fcp_qidx
;
1909 debug
->buffer
= kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE
, GFP_KERNEL
);
1912 pbuffer
= debug
->buffer
;
1917 /* Get slow-path event queue information */
1918 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1919 "Slow-path EQ information:\n");
1920 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1922 "QE-COUNT[%04d], QE-SIZE[%04d], "
1923 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1924 phba
->sli4_hba
.sp_eq
->queue_id
,
1925 phba
->sli4_hba
.sp_eq
->entry_count
,
1926 phba
->sli4_hba
.sp_eq
->entry_size
,
1927 phba
->sli4_hba
.sp_eq
->host_index
,
1928 phba
->sli4_hba
.sp_eq
->hba_index
);
1930 /* Get fast-path event queue information */
1931 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1932 "Fast-path EQ information:\n");
1933 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++) {
1934 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1936 "QE-COUNT[%04d], QE-SIZE[%04d], "
1937 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1938 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->queue_id
,
1939 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->entry_count
,
1940 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->entry_size
,
1941 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->host_index
,
1942 phba
->sli4_hba
.fp_eq
[fcp_qidx
]->hba_index
);
1944 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
, "\n");
1946 /* Get mailbox complete queue information */
1947 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1948 "Slow-path MBX CQ information:\n");
1949 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1950 "Associated EQID[%02d]:\n",
1951 phba
->sli4_hba
.mbx_cq
->assoc_qid
);
1952 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1954 "QE-COUNT[%04d], QE-SIZE[%04d], "
1955 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1956 phba
->sli4_hba
.mbx_cq
->queue_id
,
1957 phba
->sli4_hba
.mbx_cq
->entry_count
,
1958 phba
->sli4_hba
.mbx_cq
->entry_size
,
1959 phba
->sli4_hba
.mbx_cq
->host_index
,
1960 phba
->sli4_hba
.mbx_cq
->hba_index
);
1962 /* Get slow-path complete queue information */
1963 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1964 "Slow-path ELS CQ information:\n");
1965 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1966 "Associated EQID[%02d]:\n",
1967 phba
->sli4_hba
.els_cq
->assoc_qid
);
1968 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1970 "QE-COUNT[%04d], QE-SIZE[%04d], "
1971 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1972 phba
->sli4_hba
.els_cq
->queue_id
,
1973 phba
->sli4_hba
.els_cq
->entry_count
,
1974 phba
->sli4_hba
.els_cq
->entry_size
,
1975 phba
->sli4_hba
.els_cq
->host_index
,
1976 phba
->sli4_hba
.els_cq
->hba_index
);
1978 /* Get fast-path complete queue information */
1979 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1980 "Fast-path FCP CQ information:\n");
1983 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1984 "Associated EQID[%02d]:\n",
1985 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->assoc_qid
);
1986 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
1988 "QE-COUNT[%04d], QE-SIZE[%04d], "
1989 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1990 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->queue_id
,
1991 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->entry_count
,
1992 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->entry_size
,
1993 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->host_index
,
1994 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]->hba_index
);
1995 } while (++fcp_qidx
< phba
->cfg_fcp_eq_count
);
1996 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
, "\n");
1998 /* Get mailbox queue information */
1999 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2000 "Slow-path MBX MQ information:\n");
2001 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2002 "Associated CQID[%02d]:\n",
2003 phba
->sli4_hba
.mbx_wq
->assoc_qid
);
2004 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2006 "QE-COUNT[%04d], QE-SIZE[%04d], "
2007 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2008 phba
->sli4_hba
.mbx_wq
->queue_id
,
2009 phba
->sli4_hba
.mbx_wq
->entry_count
,
2010 phba
->sli4_hba
.mbx_wq
->entry_size
,
2011 phba
->sli4_hba
.mbx_wq
->host_index
,
2012 phba
->sli4_hba
.mbx_wq
->hba_index
);
2014 /* Get slow-path work queue information */
2015 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2016 "Slow-path ELS WQ information:\n");
2017 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2018 "Associated CQID[%02d]:\n",
2019 phba
->sli4_hba
.els_wq
->assoc_qid
);
2020 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2022 "QE-COUNT[%04d], QE-SIZE[%04d], "
2023 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2024 phba
->sli4_hba
.els_wq
->queue_id
,
2025 phba
->sli4_hba
.els_wq
->entry_count
,
2026 phba
->sli4_hba
.els_wq
->entry_size
,
2027 phba
->sli4_hba
.els_wq
->host_index
,
2028 phba
->sli4_hba
.els_wq
->hba_index
);
2030 /* Get fast-path work queue information */
2031 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2032 "Fast-path FCP WQ information:\n");
2033 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_wq_count
; fcp_qidx
++) {
2034 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2035 "Associated CQID[%02d]:\n",
2036 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->assoc_qid
);
2037 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2039 "QE-COUNT[%04d], WQE-SIZE[%04d], "
2040 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2041 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->queue_id
,
2042 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->entry_count
,
2043 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->entry_size
,
2044 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->host_index
,
2045 phba
->sli4_hba
.fcp_wq
[fcp_qidx
]->hba_index
);
2047 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
, "\n");
2049 /* Get receive queue information */
2050 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2051 "Slow-path RQ information:\n");
2052 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2053 "Associated CQID[%02d]:\n",
2054 phba
->sli4_hba
.hdr_rq
->assoc_qid
);
2055 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2057 "QE-COUNT[%04d], QE-SIZE[%04d], "
2058 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2059 phba
->sli4_hba
.hdr_rq
->queue_id
,
2060 phba
->sli4_hba
.hdr_rq
->entry_count
,
2061 phba
->sli4_hba
.hdr_rq
->entry_size
,
2062 phba
->sli4_hba
.hdr_rq
->host_index
,
2063 phba
->sli4_hba
.hdr_rq
->hba_index
);
2064 len
+= snprintf(pbuffer
+len
, LPFC_QUE_INFO_GET_BUF_SIZE
-len
,
2066 "QE-COUNT[%04d], QE-SIZE[%04d], "
2067 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2068 phba
->sli4_hba
.dat_rq
->queue_id
,
2069 phba
->sli4_hba
.dat_rq
->entry_count
,
2070 phba
->sli4_hba
.dat_rq
->entry_size
,
2071 phba
->sli4_hba
.dat_rq
->host_index
,
2072 phba
->sli4_hba
.dat_rq
->hba_index
);
2074 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
2078 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2079 * @q: The pointer to queue structure.
2080 * @index: The index into a queue entry.
2081 * @count: The number of queue entries to access.
2084 * The routine performs sanity check on device queue access method commands.
2087 * This function returns -EINVAL when fails the sanity check, otherwise, it
2091 lpfc_idiag_que_param_check(struct lpfc_queue
*q
, int index
, int count
)
2093 /* Only support single entry read or browsing */
2094 if ((count
!= 1) && (count
!= LPFC_QUE_ACC_BROWSE
))
2096 if (index
> q
->entry_count
- 1)
2102 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2103 * @pbuffer: The pointer to buffer to copy the read data into.
2104 * @pque: The pointer to the queue to be read.
2105 * @index: The index into the queue entry.
2108 * This routine reads out a single entry from the given queue's index location
2109 * and copies it into the buffer provided.
2112 * This function returns 0 when it fails, otherwise, it returns the length of
2113 * the data read into the buffer provided.
2116 lpfc_idiag_queacc_read_qe(char *pbuffer
, int len
, struct lpfc_queue
*pque
,
2122 if (!pbuffer
|| !pque
)
2125 esize
= pque
->entry_size
;
2126 len
+= snprintf(pbuffer
+len
, LPFC_QUE_ACC_BUF_SIZE
-len
,
2127 "QE-INDEX[%04d]:\n", index
);
2130 pentry
= pque
->qe
[index
].address
;
2132 len
+= snprintf(pbuffer
+len
, LPFC_QUE_ACC_BUF_SIZE
-len
,
2135 offset
+= sizeof(uint32_t);
2136 esize
-= sizeof(uint32_t);
2137 if (esize
> 0 && !(offset
% (4 * sizeof(uint32_t))))
2138 len
+= snprintf(pbuffer
+len
,
2139 LPFC_QUE_ACC_BUF_SIZE
-len
, "\n");
2141 len
+= snprintf(pbuffer
+len
, LPFC_QUE_ACC_BUF_SIZE
-len
, "\n");
2147 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2148 * @file: The file pointer to read from.
2149 * @buf: The buffer to copy the data to.
2150 * @nbytes: The number of bytes to read.
2151 * @ppos: The position in the file to start reading from.
2154 * This routine reads data from the @phba device queue memory according to the
2155 * idiag command, and copies to user @buf. Depending on the queue dump read
2156 * command setup, it does either a single queue entry read or browing through
2157 * all entries of the queue.
2160 * This function returns the amount of data that was read (this could be less
2161 * than @nbytes if the end of the file was reached) or a negative error value.
2164 lpfc_idiag_queacc_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
2167 struct lpfc_debug
*debug
= file
->private_data
;
2168 uint32_t last_index
, index
, count
;
2169 struct lpfc_queue
*pque
= NULL
;
2173 /* This is a user read operation */
2174 debug
->op
= LPFC_IDIAG_OP_RD
;
2177 debug
->buffer
= kmalloc(LPFC_QUE_ACC_BUF_SIZE
, GFP_KERNEL
);
2180 pbuffer
= debug
->buffer
;
2185 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_RD
) {
2186 index
= idiag
.cmd
.data
[IDIAG_QUEACC_INDEX_INDX
];
2187 count
= idiag
.cmd
.data
[IDIAG_QUEACC_COUNT_INDX
];
2188 pque
= (struct lpfc_queue
*)idiag
.ptr_private
;
2192 /* Browse the queue starting from index */
2193 if (count
== LPFC_QUE_ACC_BROWSE
)
2196 /* Read a single entry from the queue */
2197 len
= lpfc_idiag_queacc_read_qe(pbuffer
, len
, pque
, index
);
2199 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
2203 /* Browse all entries from the queue */
2204 last_index
= idiag
.offset
.last_rd
;
2207 while (len
< LPFC_QUE_ACC_SIZE
- pque
->entry_size
) {
2208 len
= lpfc_idiag_queacc_read_qe(pbuffer
, len
, pque
, index
);
2210 if (index
> pque
->entry_count
- 1)
2214 /* Set up the offset for next portion of pci cfg read */
2215 if (index
> pque
->entry_count
- 1)
2217 idiag
.offset
.last_rd
= index
;
2219 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
2223 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2224 * @file: The file pointer to read from.
2225 * @buf: The buffer to copy the user data from.
2226 * @nbytes: The number of bytes to get.
2227 * @ppos: The position in the file to start reading from.
2229 * This routine get the debugfs idiag command struct from user space and then
2230 * perform the syntax check for port queue read (dump) or write (set) command
2231 * accordingly. In the case of port queue read command, it sets up the command
2232 * in the idiag command struct for the following debugfs read operation. In
2233 * the case of port queue write operation, it executes the write operation
2234 * into the port queue entry accordingly.
2236 * It returns the @nbytges passing in from debugfs user space when successful.
2237 * In case of error conditions, it returns proper error code back to the user
2241 lpfc_idiag_queacc_write(struct file
*file
, const char __user
*buf
,
2242 size_t nbytes
, loff_t
*ppos
)
2244 struct lpfc_debug
*debug
= file
->private_data
;
2245 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
2246 uint32_t qidx
, quetp
, queid
, index
, count
, offset
, value
;
2248 struct lpfc_queue
*pque
;
2251 /* This is a user write operation */
2252 debug
->op
= LPFC_IDIAG_OP_WR
;
2254 rc
= lpfc_idiag_cmd_get(buf
, nbytes
, &idiag
.cmd
);
2258 /* Get and sanity check on command feilds */
2259 quetp
= idiag
.cmd
.data
[IDIAG_QUEACC_QUETP_INDX
];
2260 queid
= idiag
.cmd
.data
[IDIAG_QUEACC_QUEID_INDX
];
2261 index
= idiag
.cmd
.data
[IDIAG_QUEACC_INDEX_INDX
];
2262 count
= idiag
.cmd
.data
[IDIAG_QUEACC_COUNT_INDX
];
2263 offset
= idiag
.cmd
.data
[IDIAG_QUEACC_OFFST_INDX
];
2264 value
= idiag
.cmd
.data
[IDIAG_QUEACC_VALUE_INDX
];
2266 /* Sanity check on command line arguments */
2267 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_WR
||
2268 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_ST
||
2269 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_CL
) {
2270 if (rc
!= LPFC_QUE_ACC_WR_CMD_ARG
)
2274 } else if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_RD
) {
2275 if (rc
!= LPFC_QUE_ACC_RD_CMD_ARG
)
2282 /* Slow-path event queue */
2283 if (phba
->sli4_hba
.sp_eq
->queue_id
== queid
) {
2285 rc
= lpfc_idiag_que_param_check(
2286 phba
->sli4_hba
.sp_eq
, index
, count
);
2289 idiag
.ptr_private
= phba
->sli4_hba
.sp_eq
;
2292 /* Fast-path event queue */
2293 for (qidx
= 0; qidx
< phba
->cfg_fcp_eq_count
; qidx
++) {
2294 if (phba
->sli4_hba
.fp_eq
[qidx
]->queue_id
== queid
) {
2296 rc
= lpfc_idiag_que_param_check(
2297 phba
->sli4_hba
.fp_eq
[qidx
],
2301 idiag
.ptr_private
= phba
->sli4_hba
.fp_eq
[qidx
];
2308 /* MBX complete queue */
2309 if (phba
->sli4_hba
.mbx_cq
->queue_id
== queid
) {
2311 rc
= lpfc_idiag_que_param_check(
2312 phba
->sli4_hba
.mbx_cq
, index
, count
);
2315 idiag
.ptr_private
= phba
->sli4_hba
.mbx_cq
;
2318 /* ELS complete queue */
2319 if (phba
->sli4_hba
.els_cq
->queue_id
== queid
) {
2321 rc
= lpfc_idiag_que_param_check(
2322 phba
->sli4_hba
.els_cq
, index
, count
);
2325 idiag
.ptr_private
= phba
->sli4_hba
.els_cq
;
2328 /* FCP complete queue */
2331 if (phba
->sli4_hba
.fcp_cq
[qidx
]->queue_id
== queid
) {
2333 rc
= lpfc_idiag_que_param_check(
2334 phba
->sli4_hba
.fcp_cq
[qidx
],
2339 phba
->sli4_hba
.fcp_cq
[qidx
];
2342 } while (++qidx
< phba
->cfg_fcp_eq_count
);
2346 /* MBX work queue */
2347 if (phba
->sli4_hba
.mbx_wq
->queue_id
== queid
) {
2349 rc
= lpfc_idiag_que_param_check(
2350 phba
->sli4_hba
.mbx_wq
, index
, count
);
2353 idiag
.ptr_private
= phba
->sli4_hba
.mbx_wq
;
2358 /* ELS work queue */
2359 if (phba
->sli4_hba
.els_wq
->queue_id
== queid
) {
2361 rc
= lpfc_idiag_que_param_check(
2362 phba
->sli4_hba
.els_wq
, index
, count
);
2365 idiag
.ptr_private
= phba
->sli4_hba
.els_wq
;
2368 /* FCP work queue */
2369 for (qidx
= 0; qidx
< phba
->cfg_fcp_wq_count
; qidx
++) {
2370 if (phba
->sli4_hba
.fcp_wq
[qidx
]->queue_id
== queid
) {
2372 rc
= lpfc_idiag_que_param_check(
2373 phba
->sli4_hba
.fcp_wq
[qidx
],
2378 phba
->sli4_hba
.fcp_wq
[qidx
];
2386 if (phba
->sli4_hba
.hdr_rq
->queue_id
== queid
) {
2388 rc
= lpfc_idiag_que_param_check(
2389 phba
->sli4_hba
.hdr_rq
, index
, count
);
2392 idiag
.ptr_private
= phba
->sli4_hba
.hdr_rq
;
2396 if (phba
->sli4_hba
.dat_rq
->queue_id
== queid
) {
2398 rc
= lpfc_idiag_que_param_check(
2399 phba
->sli4_hba
.dat_rq
, index
, count
);
2402 idiag
.ptr_private
= phba
->sli4_hba
.dat_rq
;
2414 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_RD
) {
2415 if (count
== LPFC_QUE_ACC_BROWSE
)
2416 idiag
.offset
.last_rd
= index
;
2419 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_WR
||
2420 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_ST
||
2421 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_CL
) {
2422 /* Additional sanity checks on write operation */
2423 pque
= (struct lpfc_queue
*)idiag
.ptr_private
;
2424 if (offset
> pque
->entry_size
/sizeof(uint32_t) - 1)
2426 pentry
= pque
->qe
[index
].address
;
2428 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_WR
)
2430 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_ST
)
2432 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_QUEACC_CL
)
2438 /* Clean out command structure on command error out */
2439 memset(&idiag
, 0, sizeof(idiag
));
2444 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2445 * @phba: The pointer to hba structure.
2446 * @pbuffer: The pointer to the buffer to copy the data to.
2447 * @len: The lenght of bytes to copied.
2448 * @drbregid: The id to doorbell registers.
2451 * This routine reads a doorbell register and copies its content to the
2452 * user buffer pointed to by @pbuffer.
2455 * This function returns the amount of data that was copied into @pbuffer.
2458 lpfc_idiag_drbacc_read_reg(struct lpfc_hba
*phba
, char *pbuffer
,
2459 int len
, uint32_t drbregid
)
2467 len
+= snprintf(pbuffer
+len
, LPFC_DRB_ACC_BUF_SIZE
-len
,
2468 "EQCQ-DRB-REG: 0x%08x\n",
2469 readl(phba
->sli4_hba
.EQCQDBregaddr
));
2472 len
+= snprintf(pbuffer
+len
, LPFC_DRB_ACC_BUF_SIZE
-len
,
2473 "MQ-DRB-REG: 0x%08x\n",
2474 readl(phba
->sli4_hba
.MQDBregaddr
));
2477 len
+= snprintf(pbuffer
+len
, LPFC_DRB_ACC_BUF_SIZE
-len
,
2478 "WQ-DRB-REG: 0x%08x\n",
2479 readl(phba
->sli4_hba
.WQDBregaddr
));
2482 len
+= snprintf(pbuffer
+len
, LPFC_DRB_ACC_BUF_SIZE
-len
,
2483 "RQ-DRB-REG: 0x%08x\n",
2484 readl(phba
->sli4_hba
.RQDBregaddr
));
2494 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2495 * @file: The file pointer to read from.
2496 * @buf: The buffer to copy the data to.
2497 * @nbytes: The number of bytes to read.
2498 * @ppos: The position in the file to start reading from.
2501 * This routine reads data from the @phba device doorbell register according
2502 * to the idiag command, and copies to user @buf. Depending on the doorbell
2503 * register read command setup, it does either a single doorbell register
2504 * read or dump all doorbell registers.
2507 * This function returns the amount of data that was read (this could be less
2508 * than @nbytes if the end of the file was reached) or a negative error value.
2511 lpfc_idiag_drbacc_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
2514 struct lpfc_debug
*debug
= file
->private_data
;
2515 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
2516 uint32_t drb_reg_id
, i
;
2520 /* This is a user read operation */
2521 debug
->op
= LPFC_IDIAG_OP_RD
;
2524 debug
->buffer
= kmalloc(LPFC_DRB_ACC_BUF_SIZE
, GFP_KERNEL
);
2527 pbuffer
= debug
->buffer
;
2532 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_RD
)
2533 drb_reg_id
= idiag
.cmd
.data
[IDIAG_DRBACC_REGID_INDX
];
2537 if (drb_reg_id
== LPFC_DRB_ACC_ALL
)
2538 for (i
= 1; i
<= LPFC_DRB_MAX
; i
++)
2539 len
= lpfc_idiag_drbacc_read_reg(phba
,
2542 len
= lpfc_idiag_drbacc_read_reg(phba
,
2543 pbuffer
, len
, drb_reg_id
);
2545 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
2549 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2550 * @file: The file pointer to read from.
2551 * @buf: The buffer to copy the user data from.
2552 * @nbytes: The number of bytes to get.
2553 * @ppos: The position in the file to start reading from.
2555 * This routine get the debugfs idiag command struct from user space and then
2556 * perform the syntax check for port doorbell register read (dump) or write
2557 * (set) command accordingly. In the case of port queue read command, it sets
2558 * up the command in the idiag command struct for the following debugfs read
2559 * operation. In the case of port doorbell register write operation, it
2560 * executes the write operation into the port doorbell register accordingly.
2562 * It returns the @nbytges passing in from debugfs user space when successful.
2563 * In case of error conditions, it returns proper error code back to the user
2567 lpfc_idiag_drbacc_write(struct file
*file
, const char __user
*buf
,
2568 size_t nbytes
, loff_t
*ppos
)
2570 struct lpfc_debug
*debug
= file
->private_data
;
2571 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
2572 uint32_t drb_reg_id
, value
, reg_val
= 0;
2573 void __iomem
*drb_reg
;
2576 /* This is a user write operation */
2577 debug
->op
= LPFC_IDIAG_OP_WR
;
2579 rc
= lpfc_idiag_cmd_get(buf
, nbytes
, &idiag
.cmd
);
2583 /* Sanity check on command line arguments */
2584 drb_reg_id
= idiag
.cmd
.data
[IDIAG_DRBACC_REGID_INDX
];
2585 value
= idiag
.cmd
.data
[IDIAG_DRBACC_VALUE_INDX
];
2587 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_WR
||
2588 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_ST
||
2589 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_CL
) {
2590 if (rc
!= LPFC_DRB_ACC_WR_CMD_ARG
)
2592 if (drb_reg_id
> LPFC_DRB_MAX
)
2594 } else if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_RD
) {
2595 if (rc
!= LPFC_DRB_ACC_RD_CMD_ARG
)
2597 if ((drb_reg_id
> LPFC_DRB_MAX
) &&
2598 (drb_reg_id
!= LPFC_DRB_ACC_ALL
))
2603 /* Perform the write access operation */
2604 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_WR
||
2605 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_ST
||
2606 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_CL
) {
2607 switch (drb_reg_id
) {
2609 drb_reg
= phba
->sli4_hba
.EQCQDBregaddr
;
2612 drb_reg
= phba
->sli4_hba
.MQDBregaddr
;
2615 drb_reg
= phba
->sli4_hba
.WQDBregaddr
;
2618 drb_reg
= phba
->sli4_hba
.RQDBregaddr
;
2624 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_WR
)
2626 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_ST
) {
2627 reg_val
= readl(drb_reg
);
2630 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_DRBACC_CL
) {
2631 reg_val
= readl(drb_reg
);
2634 writel(reg_val
, drb_reg
);
2635 readl(drb_reg
); /* flush */
2640 /* Clean out command structure on command error out */
2641 memset(&idiag
, 0, sizeof(idiag
));
2646 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2647 * @phba: The pointer to hba structure.
2648 * @pbuffer: The pointer to the buffer to copy the data to.
2649 * @len: The lenght of bytes to copied.
2650 * @drbregid: The id to doorbell registers.
2653 * This routine reads a control register and copies its content to the
2654 * user buffer pointed to by @pbuffer.
2657 * This function returns the amount of data that was copied into @pbuffer.
2660 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba
*phba
, char *pbuffer
,
2661 int len
, uint32_t ctlregid
)
2668 case LPFC_CTL_PORT_SEM
:
2669 len
+= snprintf(pbuffer
+len
, LPFC_CTL_ACC_BUF_SIZE
-len
,
2670 "Port SemReg: 0x%08x\n",
2671 readl(phba
->sli4_hba
.conf_regs_memmap_p
+
2672 LPFC_CTL_PORT_SEM_OFFSET
));
2674 case LPFC_CTL_PORT_STA
:
2675 len
+= snprintf(pbuffer
+len
, LPFC_CTL_ACC_BUF_SIZE
-len
,
2676 "Port StaReg: 0x%08x\n",
2677 readl(phba
->sli4_hba
.conf_regs_memmap_p
+
2678 LPFC_CTL_PORT_STA_OFFSET
));
2680 case LPFC_CTL_PORT_CTL
:
2681 len
+= snprintf(pbuffer
+len
, LPFC_CTL_ACC_BUF_SIZE
-len
,
2682 "Port CtlReg: 0x%08x\n",
2683 readl(phba
->sli4_hba
.conf_regs_memmap_p
+
2684 LPFC_CTL_PORT_CTL_OFFSET
));
2686 case LPFC_CTL_PORT_ER1
:
2687 len
+= snprintf(pbuffer
+len
, LPFC_CTL_ACC_BUF_SIZE
-len
,
2688 "Port Er1Reg: 0x%08x\n",
2689 readl(phba
->sli4_hba
.conf_regs_memmap_p
+
2690 LPFC_CTL_PORT_ER1_OFFSET
));
2692 case LPFC_CTL_PORT_ER2
:
2693 len
+= snprintf(pbuffer
+len
, LPFC_CTL_ACC_BUF_SIZE
-len
,
2694 "Port Er2Reg: 0x%08x\n",
2695 readl(phba
->sli4_hba
.conf_regs_memmap_p
+
2696 LPFC_CTL_PORT_ER2_OFFSET
));
2698 case LPFC_CTL_PDEV_CTL
:
2699 len
+= snprintf(pbuffer
+len
, LPFC_CTL_ACC_BUF_SIZE
-len
,
2700 "PDev CtlReg: 0x%08x\n",
2701 readl(phba
->sli4_hba
.conf_regs_memmap_p
+
2702 LPFC_CTL_PDEV_CTL_OFFSET
));
2711 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2712 * @file: The file pointer to read from.
2713 * @buf: The buffer to copy the data to.
2714 * @nbytes: The number of bytes to read.
2715 * @ppos: The position in the file to start reading from.
2718 * This routine reads data from the @phba port and device registers according
2719 * to the idiag command, and copies to user @buf.
2722 * This function returns the amount of data that was read (this could be less
2723 * than @nbytes if the end of the file was reached) or a negative error value.
2726 lpfc_idiag_ctlacc_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
2729 struct lpfc_debug
*debug
= file
->private_data
;
2730 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
2731 uint32_t ctl_reg_id
, i
;
2735 /* This is a user read operation */
2736 debug
->op
= LPFC_IDIAG_OP_RD
;
2739 debug
->buffer
= kmalloc(LPFC_CTL_ACC_BUF_SIZE
, GFP_KERNEL
);
2742 pbuffer
= debug
->buffer
;
2747 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_RD
)
2748 ctl_reg_id
= idiag
.cmd
.data
[IDIAG_CTLACC_REGID_INDX
];
2752 if (ctl_reg_id
== LPFC_CTL_ACC_ALL
)
2753 for (i
= 1; i
<= LPFC_CTL_MAX
; i
++)
2754 len
= lpfc_idiag_ctlacc_read_reg(phba
,
2757 len
= lpfc_idiag_ctlacc_read_reg(phba
,
2758 pbuffer
, len
, ctl_reg_id
);
2760 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
2764 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2765 * @file: The file pointer to read from.
2766 * @buf: The buffer to copy the user data from.
2767 * @nbytes: The number of bytes to get.
2768 * @ppos: The position in the file to start reading from.
2770 * This routine get the debugfs idiag command struct from user space and then
2771 * perform the syntax check for port and device control register read (dump)
2772 * or write (set) command accordingly.
2774 * It returns the @nbytges passing in from debugfs user space when successful.
2775 * In case of error conditions, it returns proper error code back to the user
2779 lpfc_idiag_ctlacc_write(struct file
*file
, const char __user
*buf
,
2780 size_t nbytes
, loff_t
*ppos
)
2782 struct lpfc_debug
*debug
= file
->private_data
;
2783 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
2784 uint32_t ctl_reg_id
, value
, reg_val
= 0;
2785 void __iomem
*ctl_reg
;
2788 /* This is a user write operation */
2789 debug
->op
= LPFC_IDIAG_OP_WR
;
2791 rc
= lpfc_idiag_cmd_get(buf
, nbytes
, &idiag
.cmd
);
2795 /* Sanity check on command line arguments */
2796 ctl_reg_id
= idiag
.cmd
.data
[IDIAG_CTLACC_REGID_INDX
];
2797 value
= idiag
.cmd
.data
[IDIAG_CTLACC_VALUE_INDX
];
2799 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_WR
||
2800 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_ST
||
2801 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_CL
) {
2802 if (rc
!= LPFC_CTL_ACC_WR_CMD_ARG
)
2804 if (ctl_reg_id
> LPFC_CTL_MAX
)
2806 } else if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_RD
) {
2807 if (rc
!= LPFC_CTL_ACC_RD_CMD_ARG
)
2809 if ((ctl_reg_id
> LPFC_CTL_MAX
) &&
2810 (ctl_reg_id
!= LPFC_CTL_ACC_ALL
))
2815 /* Perform the write access operation */
2816 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_WR
||
2817 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_ST
||
2818 idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_CL
) {
2819 switch (ctl_reg_id
) {
2820 case LPFC_CTL_PORT_SEM
:
2821 ctl_reg
= phba
->sli4_hba
.conf_regs_memmap_p
+
2822 LPFC_CTL_PORT_SEM_OFFSET
;
2824 case LPFC_CTL_PORT_STA
:
2825 ctl_reg
= phba
->sli4_hba
.conf_regs_memmap_p
+
2826 LPFC_CTL_PORT_STA_OFFSET
;
2828 case LPFC_CTL_PORT_CTL
:
2829 ctl_reg
= phba
->sli4_hba
.conf_regs_memmap_p
+
2830 LPFC_CTL_PORT_CTL_OFFSET
;
2832 case LPFC_CTL_PORT_ER1
:
2833 ctl_reg
= phba
->sli4_hba
.conf_regs_memmap_p
+
2834 LPFC_CTL_PORT_ER1_OFFSET
;
2836 case LPFC_CTL_PORT_ER2
:
2837 ctl_reg
= phba
->sli4_hba
.conf_regs_memmap_p
+
2838 LPFC_CTL_PORT_ER2_OFFSET
;
2840 case LPFC_CTL_PDEV_CTL
:
2841 ctl_reg
= phba
->sli4_hba
.conf_regs_memmap_p
+
2842 LPFC_CTL_PDEV_CTL_OFFSET
;
2848 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_WR
)
2850 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_ST
) {
2851 reg_val
= readl(ctl_reg
);
2854 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_CTLACC_CL
) {
2855 reg_val
= readl(ctl_reg
);
2858 writel(reg_val
, ctl_reg
);
2859 readl(ctl_reg
); /* flush */
2864 /* Clean out command structure on command error out */
2865 memset(&idiag
, 0, sizeof(idiag
));
2870 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
2871 * @phba: Pointer to HBA context object.
2872 * @pbuffer: Pointer to data buffer.
2875 * This routine gets the driver mailbox access debugfs setup information.
2878 * This function returns the amount of data that was read (this could be less
2879 * than @nbytes if the end of the file was reached) or a negative error value.
2882 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba
*phba
, char *pbuffer
)
2884 uint32_t mbx_dump_map
, mbx_dump_cnt
, mbx_word_cnt
, mbx_mbox_cmd
;
2887 mbx_mbox_cmd
= idiag
.cmd
.data
[IDIAG_MBXACC_MBCMD_INDX
];
2888 mbx_dump_map
= idiag
.cmd
.data
[IDIAG_MBXACC_DPMAP_INDX
];
2889 mbx_dump_cnt
= idiag
.cmd
.data
[IDIAG_MBXACC_DPCNT_INDX
];
2890 mbx_word_cnt
= idiag
.cmd
.data
[IDIAG_MBXACC_WDCNT_INDX
];
2892 len
+= snprintf(pbuffer
+len
, LPFC_MBX_ACC_BUF_SIZE
-len
,
2893 "mbx_dump_map: 0x%08x\n", mbx_dump_map
);
2894 len
+= snprintf(pbuffer
+len
, LPFC_MBX_ACC_BUF_SIZE
-len
,
2895 "mbx_dump_cnt: %04d\n", mbx_dump_cnt
);
2896 len
+= snprintf(pbuffer
+len
, LPFC_MBX_ACC_BUF_SIZE
-len
,
2897 "mbx_word_cnt: %04d\n", mbx_word_cnt
);
2898 len
+= snprintf(pbuffer
+len
, LPFC_MBX_ACC_BUF_SIZE
-len
,
2899 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd
);
2905 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
2906 * @file: The file pointer to read from.
2907 * @buf: The buffer to copy the data to.
2908 * @nbytes: The number of bytes to read.
2909 * @ppos: The position in the file to start reading from.
2912 * This routine reads data from the @phba driver mailbox access debugfs setup
2916 * This function returns the amount of data that was read (this could be less
2917 * than @nbytes if the end of the file was reached) or a negative error value.
2920 lpfc_idiag_mbxacc_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
2923 struct lpfc_debug
*debug
= file
->private_data
;
2924 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
2928 /* This is a user read operation */
2929 debug
->op
= LPFC_IDIAG_OP_RD
;
2932 debug
->buffer
= kmalloc(LPFC_MBX_ACC_BUF_SIZE
, GFP_KERNEL
);
2935 pbuffer
= debug
->buffer
;
2940 if ((idiag
.cmd
.opcode
!= LPFC_IDIAG_CMD_MBXACC_DP
) &&
2941 (idiag
.cmd
.opcode
!= LPFC_IDIAG_BSG_MBXACC_DP
))
2944 len
= lpfc_idiag_mbxacc_get_setup(phba
, pbuffer
);
2946 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
2950 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
2951 * @file: The file pointer to read from.
2952 * @buf: The buffer to copy the user data from.
2953 * @nbytes: The number of bytes to get.
2954 * @ppos: The position in the file to start reading from.
2956 * This routine get the debugfs idiag command struct from user space and then
2957 * perform the syntax check for driver mailbox command (dump) and sets up the
2958 * necessary states in the idiag command struct accordingly.
2960 * It returns the @nbytges passing in from debugfs user space when successful.
2961 * In case of error conditions, it returns proper error code back to the user
2965 lpfc_idiag_mbxacc_write(struct file
*file
, const char __user
*buf
,
2966 size_t nbytes
, loff_t
*ppos
)
2968 struct lpfc_debug
*debug
= file
->private_data
;
2969 uint32_t mbx_dump_map
, mbx_dump_cnt
, mbx_word_cnt
, mbx_mbox_cmd
;
2972 /* This is a user write operation */
2973 debug
->op
= LPFC_IDIAG_OP_WR
;
2975 rc
= lpfc_idiag_cmd_get(buf
, nbytes
, &idiag
.cmd
);
2979 /* Sanity check on command line arguments */
2980 mbx_mbox_cmd
= idiag
.cmd
.data
[IDIAG_MBXACC_MBCMD_INDX
];
2981 mbx_dump_map
= idiag
.cmd
.data
[IDIAG_MBXACC_DPMAP_INDX
];
2982 mbx_dump_cnt
= idiag
.cmd
.data
[IDIAG_MBXACC_DPCNT_INDX
];
2983 mbx_word_cnt
= idiag
.cmd
.data
[IDIAG_MBXACC_WDCNT_INDX
];
2985 if (idiag
.cmd
.opcode
== LPFC_IDIAG_CMD_MBXACC_DP
) {
2986 if (!(mbx_dump_map
& LPFC_MBX_DMP_MBX_ALL
))
2988 if ((mbx_dump_map
& ~LPFC_MBX_DMP_MBX_ALL
) &&
2989 (mbx_dump_map
!= LPFC_MBX_DMP_ALL
))
2991 if (mbx_word_cnt
> sizeof(MAILBOX_t
))
2993 } else if (idiag
.cmd
.opcode
== LPFC_IDIAG_BSG_MBXACC_DP
) {
2994 if (!(mbx_dump_map
& LPFC_BSG_DMP_MBX_ALL
))
2996 if ((mbx_dump_map
& ~LPFC_BSG_DMP_MBX_ALL
) &&
2997 (mbx_dump_map
!= LPFC_MBX_DMP_ALL
))
2999 if (mbx_word_cnt
> (BSG_MBOX_SIZE
)/4)
3001 if (mbx_mbox_cmd
!= 0x9b)
3006 if (mbx_word_cnt
== 0)
3008 if (rc
!= LPFC_MBX_DMP_ARG
)
3010 if (mbx_mbox_cmd
& ~0xff)
3013 /* condition for stop mailbox dump */
3014 if (mbx_dump_cnt
== 0)
3020 /* Clean out command structure on command error out */
3021 memset(&idiag
, 0, sizeof(idiag
));
3025 /* Clean out command structure on command error out */
3026 memset(&idiag
, 0, sizeof(idiag
));
3031 * lpfc_idiag_extacc_avail_get - get the available extents information
3032 * @phba: pointer to lpfc hba data structure.
3033 * @pbuffer: pointer to internal buffer.
3034 * @len: length into the internal buffer data has been copied.
3037 * This routine is to get the available extent information.
3040 * overall lenth of the data read into the internal buffer.
3043 lpfc_idiag_extacc_avail_get(struct lpfc_hba
*phba
, char *pbuffer
, int len
)
3045 uint16_t ext_cnt
, ext_size
;
3047 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3048 "\nAvailable Extents Information:\n");
3050 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3051 "\tPort Available VPI extents: ");
3052 lpfc_sli4_get_avail_extnt_rsrc(phba
, LPFC_RSC_TYPE_FCOE_VPI
,
3053 &ext_cnt
, &ext_size
);
3054 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3055 "Count %3d, Size %3d\n", ext_cnt
, ext_size
);
3057 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3058 "\tPort Available VFI extents: ");
3059 lpfc_sli4_get_avail_extnt_rsrc(phba
, LPFC_RSC_TYPE_FCOE_VFI
,
3060 &ext_cnt
, &ext_size
);
3061 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3062 "Count %3d, Size %3d\n", ext_cnt
, ext_size
);
3064 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3065 "\tPort Available RPI extents: ");
3066 lpfc_sli4_get_avail_extnt_rsrc(phba
, LPFC_RSC_TYPE_FCOE_RPI
,
3067 &ext_cnt
, &ext_size
);
3068 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3069 "Count %3d, Size %3d\n", ext_cnt
, ext_size
);
3071 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3072 "\tPort Available XRI extents: ");
3073 lpfc_sli4_get_avail_extnt_rsrc(phba
, LPFC_RSC_TYPE_FCOE_XRI
,
3074 &ext_cnt
, &ext_size
);
3075 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3076 "Count %3d, Size %3d\n", ext_cnt
, ext_size
);
3082 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3083 * @phba: pointer to lpfc hba data structure.
3084 * @pbuffer: pointer to internal buffer.
3085 * @len: length into the internal buffer data has been copied.
3088 * This routine is to get the allocated extent information.
3091 * overall lenth of the data read into the internal buffer.
3094 lpfc_idiag_extacc_alloc_get(struct lpfc_hba
*phba
, char *pbuffer
, int len
)
3096 uint16_t ext_cnt
, ext_size
;
3099 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3100 "\nAllocated Extents Information:\n");
3102 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3103 "\tHost Allocated VPI extents: ");
3104 rc
= lpfc_sli4_get_allocated_extnts(phba
, LPFC_RSC_TYPE_FCOE_VPI
,
3105 &ext_cnt
, &ext_size
);
3107 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3108 "Port %d Extent %3d, Size %3d\n",
3109 phba
->brd_no
, ext_cnt
, ext_size
);
3111 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3114 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3115 "\tHost Allocated VFI extents: ");
3116 rc
= lpfc_sli4_get_allocated_extnts(phba
, LPFC_RSC_TYPE_FCOE_VFI
,
3117 &ext_cnt
, &ext_size
);
3119 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3120 "Port %d Extent %3d, Size %3d\n",
3121 phba
->brd_no
, ext_cnt
, ext_size
);
3123 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3126 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3127 "\tHost Allocated RPI extents: ");
3128 rc
= lpfc_sli4_get_allocated_extnts(phba
, LPFC_RSC_TYPE_FCOE_RPI
,
3129 &ext_cnt
, &ext_size
);
3131 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3132 "Port %d Extent %3d, Size %3d\n",
3133 phba
->brd_no
, ext_cnt
, ext_size
);
3135 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3138 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3139 "\tHost Allocated XRI extents: ");
3140 rc
= lpfc_sli4_get_allocated_extnts(phba
, LPFC_RSC_TYPE_FCOE_XRI
,
3141 &ext_cnt
, &ext_size
);
3143 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3144 "Port %d Extent %3d, Size %3d\n",
3145 phba
->brd_no
, ext_cnt
, ext_size
);
3147 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3154 * lpfc_idiag_extacc_drivr_get - get driver extent information
3155 * @phba: pointer to lpfc hba data structure.
3156 * @pbuffer: pointer to internal buffer.
3157 * @len: length into the internal buffer data has been copied.
3160 * This routine is to get the driver extent information.
3163 * overall lenth of the data read into the internal buffer.
3166 lpfc_idiag_extacc_drivr_get(struct lpfc_hba
*phba
, char *pbuffer
, int len
)
3168 struct lpfc_rsrc_blks
*rsrc_blks
;
3171 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3172 "\nDriver Extents Information:\n");
3174 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3175 "\tVPI extents:\n");
3177 list_for_each_entry(rsrc_blks
, &phba
->lpfc_vpi_blk_list
, list
) {
3178 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3179 "\t\tBlock %3d: Start %4d, Count %4d\n",
3180 index
, rsrc_blks
->rsrc_start
,
3181 rsrc_blks
->rsrc_size
);
3184 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3185 "\tVFI extents:\n");
3187 list_for_each_entry(rsrc_blks
, &phba
->sli4_hba
.lpfc_vfi_blk_list
,
3189 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3190 "\t\tBlock %3d: Start %4d, Count %4d\n",
3191 index
, rsrc_blks
->rsrc_start
,
3192 rsrc_blks
->rsrc_size
);
3196 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3197 "\tRPI extents:\n");
3199 list_for_each_entry(rsrc_blks
, &phba
->sli4_hba
.lpfc_rpi_blk_list
,
3201 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3202 "\t\tBlock %3d: Start %4d, Count %4d\n",
3203 index
, rsrc_blks
->rsrc_start
,
3204 rsrc_blks
->rsrc_size
);
3208 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3209 "\tXRI extents:\n");
3211 list_for_each_entry(rsrc_blks
, &phba
->sli4_hba
.lpfc_xri_blk_list
,
3213 len
+= snprintf(pbuffer
+len
, LPFC_EXT_ACC_BUF_SIZE
-len
,
3214 "\t\tBlock %3d: Start %4d, Count %4d\n",
3215 index
, rsrc_blks
->rsrc_start
,
3216 rsrc_blks
->rsrc_size
);
3224 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3225 * @file: The file pointer to read from.
3226 * @buf: The buffer to copy the user data from.
3227 * @nbytes: The number of bytes to get.
3228 * @ppos: The position in the file to start reading from.
3230 * This routine get the debugfs idiag command struct from user space and then
3231 * perform the syntax check for extent information access commands and sets
3232 * up the necessary states in the idiag command struct accordingly.
3234 * It returns the @nbytges passing in from debugfs user space when successful.
3235 * In case of error conditions, it returns proper error code back to the user
3239 lpfc_idiag_extacc_write(struct file
*file
, const char __user
*buf
,
3240 size_t nbytes
, loff_t
*ppos
)
3242 struct lpfc_debug
*debug
= file
->private_data
;
3246 /* This is a user write operation */
3247 debug
->op
= LPFC_IDIAG_OP_WR
;
3249 rc
= lpfc_idiag_cmd_get(buf
, nbytes
, &idiag
.cmd
);
3253 ext_map
= idiag
.cmd
.data
[IDIAG_EXTACC_EXMAP_INDX
];
3255 if (idiag
.cmd
.opcode
!= LPFC_IDIAG_CMD_EXTACC_RD
)
3257 if (rc
!= LPFC_EXT_ACC_CMD_ARG
)
3259 if (!(ext_map
& LPFC_EXT_ACC_ALL
))
3264 /* Clean out command structure on command error out */
3265 memset(&idiag
, 0, sizeof(idiag
));
3270 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3271 * @file: The file pointer to read from.
3272 * @buf: The buffer to copy the data to.
3273 * @nbytes: The number of bytes to read.
3274 * @ppos: The position in the file to start reading from.
3277 * This routine reads data from the proper extent information according to
3278 * the idiag command, and copies to user @buf.
3281 * This function returns the amount of data that was read (this could be less
3282 * than @nbytes if the end of the file was reached) or a negative error value.
3285 lpfc_idiag_extacc_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
3288 struct lpfc_debug
*debug
= file
->private_data
;
3289 struct lpfc_hba
*phba
= (struct lpfc_hba
*)debug
->i_private
;
3294 /* This is a user read operation */
3295 debug
->op
= LPFC_IDIAG_OP_RD
;
3298 debug
->buffer
= kmalloc(LPFC_EXT_ACC_BUF_SIZE
, GFP_KERNEL
);
3301 pbuffer
= debug
->buffer
;
3304 if (idiag
.cmd
.opcode
!= LPFC_IDIAG_CMD_EXTACC_RD
)
3307 ext_map
= idiag
.cmd
.data
[IDIAG_EXTACC_EXMAP_INDX
];
3308 if (ext_map
& LPFC_EXT_ACC_AVAIL
)
3309 len
= lpfc_idiag_extacc_avail_get(phba
, pbuffer
, len
);
3310 if (ext_map
& LPFC_EXT_ACC_ALLOC
)
3311 len
= lpfc_idiag_extacc_alloc_get(phba
, pbuffer
, len
);
3312 if (ext_map
& LPFC_EXT_ACC_DRIVR
)
3313 len
= lpfc_idiag_extacc_drivr_get(phba
, pbuffer
, len
);
3315 return simple_read_from_buffer(buf
, nbytes
, ppos
, pbuffer
, len
);
3318 #undef lpfc_debugfs_op_disc_trc
3319 static const struct file_operations lpfc_debugfs_op_disc_trc
= {
3320 .owner
= THIS_MODULE
,
3321 .open
= lpfc_debugfs_disc_trc_open
,
3322 .llseek
= lpfc_debugfs_lseek
,
3323 .read
= lpfc_debugfs_read
,
3324 .release
= lpfc_debugfs_release
,
3327 #undef lpfc_debugfs_op_nodelist
3328 static const struct file_operations lpfc_debugfs_op_nodelist
= {
3329 .owner
= THIS_MODULE
,
3330 .open
= lpfc_debugfs_nodelist_open
,
3331 .llseek
= lpfc_debugfs_lseek
,
3332 .read
= lpfc_debugfs_read
,
3333 .release
= lpfc_debugfs_release
,
3336 #undef lpfc_debugfs_op_hbqinfo
3337 static const struct file_operations lpfc_debugfs_op_hbqinfo
= {
3338 .owner
= THIS_MODULE
,
3339 .open
= lpfc_debugfs_hbqinfo_open
,
3340 .llseek
= lpfc_debugfs_lseek
,
3341 .read
= lpfc_debugfs_read
,
3342 .release
= lpfc_debugfs_release
,
3345 #undef lpfc_debugfs_op_dumpHBASlim
3346 static const struct file_operations lpfc_debugfs_op_dumpHBASlim
= {
3347 .owner
= THIS_MODULE
,
3348 .open
= lpfc_debugfs_dumpHBASlim_open
,
3349 .llseek
= lpfc_debugfs_lseek
,
3350 .read
= lpfc_debugfs_read
,
3351 .release
= lpfc_debugfs_release
,
3354 #undef lpfc_debugfs_op_dumpHostSlim
3355 static const struct file_operations lpfc_debugfs_op_dumpHostSlim
= {
3356 .owner
= THIS_MODULE
,
3357 .open
= lpfc_debugfs_dumpHostSlim_open
,
3358 .llseek
= lpfc_debugfs_lseek
,
3359 .read
= lpfc_debugfs_read
,
3360 .release
= lpfc_debugfs_release
,
3363 #undef lpfc_debugfs_op_dumpData
3364 static const struct file_operations lpfc_debugfs_op_dumpData
= {
3365 .owner
= THIS_MODULE
,
3366 .open
= lpfc_debugfs_dumpData_open
,
3367 .llseek
= lpfc_debugfs_lseek
,
3368 .read
= lpfc_debugfs_read
,
3369 .write
= lpfc_debugfs_dumpDataDif_write
,
3370 .release
= lpfc_debugfs_dumpDataDif_release
,
3373 #undef lpfc_debugfs_op_dumpDif
3374 static const struct file_operations lpfc_debugfs_op_dumpDif
= {
3375 .owner
= THIS_MODULE
,
3376 .open
= lpfc_debugfs_dumpDif_open
,
3377 .llseek
= lpfc_debugfs_lseek
,
3378 .read
= lpfc_debugfs_read
,
3379 .write
= lpfc_debugfs_dumpDataDif_write
,
3380 .release
= lpfc_debugfs_dumpDataDif_release
,
3383 #undef lpfc_debugfs_op_slow_ring_trc
3384 static const struct file_operations lpfc_debugfs_op_slow_ring_trc
= {
3385 .owner
= THIS_MODULE
,
3386 .open
= lpfc_debugfs_slow_ring_trc_open
,
3387 .llseek
= lpfc_debugfs_lseek
,
3388 .read
= lpfc_debugfs_read
,
3389 .release
= lpfc_debugfs_release
,
3392 static struct dentry
*lpfc_debugfs_root
= NULL
;
3393 static atomic_t lpfc_debugfs_hba_count
;
3396 * File operations for the iDiag debugfs
3398 #undef lpfc_idiag_op_pciCfg
3399 static const struct file_operations lpfc_idiag_op_pciCfg
= {
3400 .owner
= THIS_MODULE
,
3401 .open
= lpfc_idiag_open
,
3402 .llseek
= lpfc_debugfs_lseek
,
3403 .read
= lpfc_idiag_pcicfg_read
,
3404 .write
= lpfc_idiag_pcicfg_write
,
3405 .release
= lpfc_idiag_cmd_release
,
3408 #undef lpfc_idiag_op_barAcc
3409 static const struct file_operations lpfc_idiag_op_barAcc
= {
3410 .owner
= THIS_MODULE
,
3411 .open
= lpfc_idiag_open
,
3412 .llseek
= lpfc_debugfs_lseek
,
3413 .read
= lpfc_idiag_baracc_read
,
3414 .write
= lpfc_idiag_baracc_write
,
3415 .release
= lpfc_idiag_cmd_release
,
3418 #undef lpfc_idiag_op_queInfo
3419 static const struct file_operations lpfc_idiag_op_queInfo
= {
3420 .owner
= THIS_MODULE
,
3421 .open
= lpfc_idiag_open
,
3422 .read
= lpfc_idiag_queinfo_read
,
3423 .release
= lpfc_idiag_release
,
3426 #undef lpfc_idiag_op_queAcc
3427 static const struct file_operations lpfc_idiag_op_queAcc
= {
3428 .owner
= THIS_MODULE
,
3429 .open
= lpfc_idiag_open
,
3430 .llseek
= lpfc_debugfs_lseek
,
3431 .read
= lpfc_idiag_queacc_read
,
3432 .write
= lpfc_idiag_queacc_write
,
3433 .release
= lpfc_idiag_cmd_release
,
3436 #undef lpfc_idiag_op_drbAcc
3437 static const struct file_operations lpfc_idiag_op_drbAcc
= {
3438 .owner
= THIS_MODULE
,
3439 .open
= lpfc_idiag_open
,
3440 .llseek
= lpfc_debugfs_lseek
,
3441 .read
= lpfc_idiag_drbacc_read
,
3442 .write
= lpfc_idiag_drbacc_write
,
3443 .release
= lpfc_idiag_cmd_release
,
3446 #undef lpfc_idiag_op_ctlAcc
3447 static const struct file_operations lpfc_idiag_op_ctlAcc
= {
3448 .owner
= THIS_MODULE
,
3449 .open
= lpfc_idiag_open
,
3450 .llseek
= lpfc_debugfs_lseek
,
3451 .read
= lpfc_idiag_ctlacc_read
,
3452 .write
= lpfc_idiag_ctlacc_write
,
3453 .release
= lpfc_idiag_cmd_release
,
3456 #undef lpfc_idiag_op_mbxAcc
3457 static const struct file_operations lpfc_idiag_op_mbxAcc
= {
3458 .owner
= THIS_MODULE
,
3459 .open
= lpfc_idiag_open
,
3460 .llseek
= lpfc_debugfs_lseek
,
3461 .read
= lpfc_idiag_mbxacc_read
,
3462 .write
= lpfc_idiag_mbxacc_write
,
3463 .release
= lpfc_idiag_cmd_release
,
3466 #undef lpfc_idiag_op_extAcc
3467 static const struct file_operations lpfc_idiag_op_extAcc
= {
3468 .owner
= THIS_MODULE
,
3469 .open
= lpfc_idiag_open
,
3470 .llseek
= lpfc_debugfs_lseek
,
3471 .read
= lpfc_idiag_extacc_read
,
3472 .write
= lpfc_idiag_extacc_write
,
3473 .release
= lpfc_idiag_cmd_release
,
3478 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3479 * @phba: Pointer to HBA context object.
3480 * @dmabuf: Pointer to a DMA buffer descriptor.
3483 * This routine dump a bsg pass-through non-embedded mailbox command with
3487 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba
*phba
, enum nemb_type nemb_tp
,
3488 enum mbox_type mbox_tp
, enum dma_type dma_tp
,
3489 enum sta_type sta_tp
,
3490 struct lpfc_dmabuf
*dmabuf
, uint32_t ext_buf
)
3492 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3493 uint32_t *mbx_mbox_cmd
, *mbx_dump_map
, *mbx_dump_cnt
, *mbx_word_cnt
;
3494 char line_buf
[LPFC_MBX_ACC_LBUF_SZ
];
3496 uint32_t do_dump
= 0;
3500 if (idiag
.cmd
.opcode
!= LPFC_IDIAG_BSG_MBXACC_DP
)
3503 mbx_mbox_cmd
= &idiag
.cmd
.data
[IDIAG_MBXACC_MBCMD_INDX
];
3504 mbx_dump_map
= &idiag
.cmd
.data
[IDIAG_MBXACC_DPMAP_INDX
];
3505 mbx_dump_cnt
= &idiag
.cmd
.data
[IDIAG_MBXACC_DPCNT_INDX
];
3506 mbx_word_cnt
= &idiag
.cmd
.data
[IDIAG_MBXACC_WDCNT_INDX
];
3508 if (!(*mbx_dump_map
& LPFC_MBX_DMP_ALL
) ||
3509 (*mbx_dump_cnt
== 0) ||
3510 (*mbx_word_cnt
== 0))
3513 if (*mbx_mbox_cmd
!= 0x9B)
3516 if ((mbox_tp
== mbox_rd
) && (dma_tp
== dma_mbox
)) {
3517 if (*mbx_dump_map
& LPFC_BSG_DMP_MBX_RD_MBX
) {
3518 do_dump
|= LPFC_BSG_DMP_MBX_RD_MBX
;
3519 printk(KERN_ERR
"\nRead mbox command (x%x), "
3520 "nemb:0x%x, extbuf_cnt:%d:\n",
3521 sta_tp
, nemb_tp
, ext_buf
);
3524 if ((mbox_tp
== mbox_rd
) && (dma_tp
== dma_ebuf
)) {
3525 if (*mbx_dump_map
& LPFC_BSG_DMP_MBX_RD_BUF
) {
3526 do_dump
|= LPFC_BSG_DMP_MBX_RD_BUF
;
3527 printk(KERN_ERR
"\nRead mbox buffer (x%x), "
3528 "nemb:0x%x, extbuf_seq:%d:\n",
3529 sta_tp
, nemb_tp
, ext_buf
);
3532 if ((mbox_tp
== mbox_wr
) && (dma_tp
== dma_mbox
)) {
3533 if (*mbx_dump_map
& LPFC_BSG_DMP_MBX_WR_MBX
) {
3534 do_dump
|= LPFC_BSG_DMP_MBX_WR_MBX
;
3535 printk(KERN_ERR
"\nWrite mbox command (x%x), "
3536 "nemb:0x%x, extbuf_cnt:%d:\n",
3537 sta_tp
, nemb_tp
, ext_buf
);
3540 if ((mbox_tp
== mbox_wr
) && (dma_tp
== dma_ebuf
)) {
3541 if (*mbx_dump_map
& LPFC_BSG_DMP_MBX_WR_BUF
) {
3542 do_dump
|= LPFC_BSG_DMP_MBX_WR_BUF
;
3543 printk(KERN_ERR
"\nWrite mbox buffer (x%x), "
3544 "nemb:0x%x, extbuf_seq:%d:\n",
3545 sta_tp
, nemb_tp
, ext_buf
);
3549 /* dump buffer content */
3551 pword
= (uint32_t *)dmabuf
->virt
;
3552 for (i
= 0; i
< *mbx_word_cnt
; i
++) {
3555 printk(KERN_ERR
"%s\n", line_buf
);
3557 len
+= snprintf(line_buf
+len
,
3558 LPFC_MBX_ACC_LBUF_SZ
-len
,
3561 len
+= snprintf(line_buf
+len
, LPFC_MBX_ACC_LBUF_SZ
-len
,
3562 "%08x ", (uint32_t)*pword
);
3566 printk(KERN_ERR
"%s\n", line_buf
);
3570 /* Clean out command structure on reaching dump count */
3571 if (*mbx_dump_cnt
== 0)
3572 memset(&idiag
, 0, sizeof(idiag
));
3577 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3578 * @phba: Pointer to HBA context object.
3579 * @dmabuf: Pointer to a DMA buffer descriptor.
3582 * This routine dump a pass-through non-embedded mailbox command from issue
3586 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba
*phba
, MAILBOX_t
*pmbox
)
3588 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3589 uint32_t *mbx_dump_map
, *mbx_dump_cnt
, *mbx_word_cnt
, *mbx_mbox_cmd
;
3590 char line_buf
[LPFC_MBX_ACC_LBUF_SZ
];
3596 if (idiag
.cmd
.opcode
!= LPFC_IDIAG_CMD_MBXACC_DP
)
3599 mbx_mbox_cmd
= &idiag
.cmd
.data
[IDIAG_MBXACC_MBCMD_INDX
];
3600 mbx_dump_map
= &idiag
.cmd
.data
[IDIAG_MBXACC_DPMAP_INDX
];
3601 mbx_dump_cnt
= &idiag
.cmd
.data
[IDIAG_MBXACC_DPCNT_INDX
];
3602 mbx_word_cnt
= &idiag
.cmd
.data
[IDIAG_MBXACC_WDCNT_INDX
];
3604 if (!(*mbx_dump_map
& LPFC_MBX_DMP_MBX_ALL
) ||
3605 (*mbx_dump_cnt
== 0) ||
3606 (*mbx_word_cnt
== 0))
3609 if ((*mbx_mbox_cmd
!= LPFC_MBX_ALL_CMD
) &&
3610 (*mbx_mbox_cmd
!= pmbox
->mbxCommand
))
3613 /* dump buffer content */
3614 if (*mbx_dump_map
& LPFC_MBX_DMP_MBX_WORD
) {
3615 printk(KERN_ERR
"Mailbox command:0x%x dump by word:\n",
3617 pword
= (uint32_t *)pmbox
;
3618 for (i
= 0; i
< *mbx_word_cnt
; i
++) {
3621 printk(KERN_ERR
"%s\n", line_buf
);
3623 memset(line_buf
, 0, LPFC_MBX_ACC_LBUF_SZ
);
3624 len
+= snprintf(line_buf
+len
,
3625 LPFC_MBX_ACC_LBUF_SZ
-len
,
3628 len
+= snprintf(line_buf
+len
, LPFC_MBX_ACC_LBUF_SZ
-len
,
3630 ((uint32_t)*pword
) & 0xffffffff);
3634 printk(KERN_ERR
"%s\n", line_buf
);
3635 printk(KERN_ERR
"\n");
3637 if (*mbx_dump_map
& LPFC_MBX_DMP_MBX_BYTE
) {
3638 printk(KERN_ERR
"Mailbox command:0x%x dump by byte:\n",
3640 pbyte
= (uint8_t *)pmbox
;
3641 for (i
= 0; i
< *mbx_word_cnt
; i
++) {
3644 printk(KERN_ERR
"%s\n", line_buf
);
3646 memset(line_buf
, 0, LPFC_MBX_ACC_LBUF_SZ
);
3647 len
+= snprintf(line_buf
+len
,
3648 LPFC_MBX_ACC_LBUF_SZ
-len
,
3651 for (j
= 0; j
< 4; j
++) {
3652 len
+= snprintf(line_buf
+len
,
3653 LPFC_MBX_ACC_LBUF_SZ
-len
,
3655 ((uint8_t)*pbyte
) & 0xff);
3658 len
+= snprintf(line_buf
+len
,
3659 LPFC_MBX_ACC_LBUF_SZ
-len
, " ");
3662 printk(KERN_ERR
"%s\n", line_buf
);
3663 printk(KERN_ERR
"\n");
3667 /* Clean out command structure on reaching dump count */
3668 if (*mbx_dump_cnt
== 0)
3669 memset(&idiag
, 0, sizeof(idiag
));
3675 * lpfc_debugfs_initialize - Initialize debugfs for a vport
3676 * @vport: The vport pointer to initialize.
3679 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3680 * If not already created, this routine will create the lpfc directory, and
3681 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3682 * also create each file used to access lpfc specific debugfs information.
3685 lpfc_debugfs_initialize(struct lpfc_vport
*vport
)
3687 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3688 struct lpfc_hba
*phba
= vport
->phba
;
3692 if (!lpfc_debugfs_enable
)
3695 /* Setup lpfc root directory */
3696 if (!lpfc_debugfs_root
) {
3697 lpfc_debugfs_root
= debugfs_create_dir("lpfc", NULL
);
3698 atomic_set(&lpfc_debugfs_hba_count
, 0);
3699 if (!lpfc_debugfs_root
) {
3700 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3701 "0408 Cannot create debugfs root\n");
3705 if (!lpfc_debugfs_start_time
)
3706 lpfc_debugfs_start_time
= jiffies
;
3708 /* Setup funcX directory for specific HBA PCI function */
3709 snprintf(name
, sizeof(name
), "fn%d", phba
->brd_no
);
3710 if (!phba
->hba_debugfs_root
) {
3711 phba
->hba_debugfs_root
=
3712 debugfs_create_dir(name
, lpfc_debugfs_root
);
3713 if (!phba
->hba_debugfs_root
) {
3714 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3715 "0412 Cannot create debugfs hba\n");
3718 atomic_inc(&lpfc_debugfs_hba_count
);
3719 atomic_set(&phba
->debugfs_vport_count
, 0);
3722 snprintf(name
, sizeof(name
), "hbqinfo");
3723 phba
->debug_hbqinfo
=
3724 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3725 phba
->hba_debugfs_root
,
3726 phba
, &lpfc_debugfs_op_hbqinfo
);
3727 if (!phba
->debug_hbqinfo
) {
3728 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3729 "0411 Cannot create debugfs hbqinfo\n");
3733 /* Setup dumpHBASlim */
3734 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3735 snprintf(name
, sizeof(name
), "dumpHBASlim");
3736 phba
->debug_dumpHBASlim
=
3737 debugfs_create_file(name
,
3738 S_IFREG
|S_IRUGO
|S_IWUSR
,
3739 phba
->hba_debugfs_root
,
3740 phba
, &lpfc_debugfs_op_dumpHBASlim
);
3741 if (!phba
->debug_dumpHBASlim
) {
3742 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3743 "0413 Cannot create debugfs "
3748 phba
->debug_dumpHBASlim
= NULL
;
3750 /* Setup dumpHostSlim */
3751 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3752 snprintf(name
, sizeof(name
), "dumpHostSlim");
3753 phba
->debug_dumpHostSlim
=
3754 debugfs_create_file(name
,
3755 S_IFREG
|S_IRUGO
|S_IWUSR
,
3756 phba
->hba_debugfs_root
,
3757 phba
, &lpfc_debugfs_op_dumpHostSlim
);
3758 if (!phba
->debug_dumpHostSlim
) {
3759 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3760 "0414 Cannot create debugfs "
3765 phba
->debug_dumpHBASlim
= NULL
;
3767 /* Setup dumpData */
3768 snprintf(name
, sizeof(name
), "dumpData");
3769 phba
->debug_dumpData
=
3770 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3771 phba
->hba_debugfs_root
,
3772 phba
, &lpfc_debugfs_op_dumpData
);
3773 if (!phba
->debug_dumpData
) {
3774 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3775 "0800 Cannot create debugfs dumpData\n");
3780 snprintf(name
, sizeof(name
), "dumpDif");
3781 phba
->debug_dumpDif
=
3782 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3783 phba
->hba_debugfs_root
,
3784 phba
, &lpfc_debugfs_op_dumpDif
);
3785 if (!phba
->debug_dumpDif
) {
3786 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3787 "0801 Cannot create debugfs dumpDif\n");
3791 /* Setup slow ring trace */
3792 if (lpfc_debugfs_max_slow_ring_trc
) {
3793 num
= lpfc_debugfs_max_slow_ring_trc
- 1;
3794 if (num
& lpfc_debugfs_max_slow_ring_trc
) {
3795 /* Change to be a power of 2 */
3796 num
= lpfc_debugfs_max_slow_ring_trc
;
3802 lpfc_debugfs_max_slow_ring_trc
= (1 << i
);
3804 "lpfc_debugfs_max_disc_trc changed to "
3805 "%d\n", lpfc_debugfs_max_disc_trc
);
3809 snprintf(name
, sizeof(name
), "slow_ring_trace");
3810 phba
->debug_slow_ring_trc
=
3811 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3812 phba
->hba_debugfs_root
,
3813 phba
, &lpfc_debugfs_op_slow_ring_trc
);
3814 if (!phba
->debug_slow_ring_trc
) {
3815 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3816 "0415 Cannot create debugfs "
3817 "slow_ring_trace\n");
3820 if (!phba
->slow_ring_trc
) {
3821 phba
->slow_ring_trc
= kmalloc(
3822 (sizeof(struct lpfc_debugfs_trc
) *
3823 lpfc_debugfs_max_slow_ring_trc
),
3825 if (!phba
->slow_ring_trc
) {
3826 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3827 "0416 Cannot create debugfs "
3828 "slow_ring buffer\n");
3831 atomic_set(&phba
->slow_ring_trc_cnt
, 0);
3832 memset(phba
->slow_ring_trc
, 0,
3833 (sizeof(struct lpfc_debugfs_trc
) *
3834 lpfc_debugfs_max_slow_ring_trc
));
3838 snprintf(name
, sizeof(name
), "vport%d", vport
->vpi
);
3839 if (!vport
->vport_debugfs_root
) {
3840 vport
->vport_debugfs_root
=
3841 debugfs_create_dir(name
, phba
->hba_debugfs_root
);
3842 if (!vport
->vport_debugfs_root
) {
3843 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3844 "0417 Can't create debugfs\n");
3847 atomic_inc(&phba
->debugfs_vport_count
);
3850 if (lpfc_debugfs_max_disc_trc
) {
3851 num
= lpfc_debugfs_max_disc_trc
- 1;
3852 if (num
& lpfc_debugfs_max_disc_trc
) {
3853 /* Change to be a power of 2 */
3854 num
= lpfc_debugfs_max_disc_trc
;
3860 lpfc_debugfs_max_disc_trc
= (1 << i
);
3862 "lpfc_debugfs_max_disc_trc changed to %d\n",
3863 lpfc_debugfs_max_disc_trc
);
3867 vport
->disc_trc
= kzalloc(
3868 (sizeof(struct lpfc_debugfs_trc
) * lpfc_debugfs_max_disc_trc
),
3871 if (!vport
->disc_trc
) {
3872 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3873 "0418 Cannot create debugfs disc trace "
3877 atomic_set(&vport
->disc_trc_cnt
, 0);
3879 snprintf(name
, sizeof(name
), "discovery_trace");
3880 vport
->debug_disc_trc
=
3881 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3882 vport
->vport_debugfs_root
,
3883 vport
, &lpfc_debugfs_op_disc_trc
);
3884 if (!vport
->debug_disc_trc
) {
3885 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3886 "0419 Cannot create debugfs "
3887 "discovery_trace\n");
3890 snprintf(name
, sizeof(name
), "nodelist");
3891 vport
->debug_nodelist
=
3892 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3893 vport
->vport_debugfs_root
,
3894 vport
, &lpfc_debugfs_op_nodelist
);
3895 if (!vport
->debug_nodelist
) {
3896 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3897 "2985 Can't create debugfs nodelist\n");
3902 * iDiag debugfs root entry points for SLI4 device only
3904 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3907 snprintf(name
, sizeof(name
), "iDiag");
3908 if (!phba
->idiag_root
) {
3910 debugfs_create_dir(name
, phba
->hba_debugfs_root
);
3911 if (!phba
->idiag_root
) {
3912 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3913 "2922 Can't create idiag debugfs\n");
3916 /* Initialize iDiag data structure */
3917 memset(&idiag
, 0, sizeof(idiag
));
3920 /* iDiag read PCI config space */
3921 snprintf(name
, sizeof(name
), "pciCfg");
3922 if (!phba
->idiag_pci_cfg
) {
3923 phba
->idiag_pci_cfg
=
3924 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3925 phba
->idiag_root
, phba
, &lpfc_idiag_op_pciCfg
);
3926 if (!phba
->idiag_pci_cfg
) {
3927 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3928 "2923 Can't create idiag debugfs\n");
3931 idiag
.offset
.last_rd
= 0;
3934 /* iDiag PCI BAR access */
3935 snprintf(name
, sizeof(name
), "barAcc");
3936 if (!phba
->idiag_bar_acc
) {
3937 phba
->idiag_bar_acc
=
3938 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3939 phba
->idiag_root
, phba
, &lpfc_idiag_op_barAcc
);
3940 if (!phba
->idiag_bar_acc
) {
3941 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3942 "3056 Can't create idiag debugfs\n");
3945 idiag
.offset
.last_rd
= 0;
3948 /* iDiag get PCI function queue information */
3949 snprintf(name
, sizeof(name
), "queInfo");
3950 if (!phba
->idiag_que_info
) {
3951 phba
->idiag_que_info
=
3952 debugfs_create_file(name
, S_IFREG
|S_IRUGO
,
3953 phba
->idiag_root
, phba
, &lpfc_idiag_op_queInfo
);
3954 if (!phba
->idiag_que_info
) {
3955 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3956 "2924 Can't create idiag debugfs\n");
3961 /* iDiag access PCI function queue */
3962 snprintf(name
, sizeof(name
), "queAcc");
3963 if (!phba
->idiag_que_acc
) {
3964 phba
->idiag_que_acc
=
3965 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3966 phba
->idiag_root
, phba
, &lpfc_idiag_op_queAcc
);
3967 if (!phba
->idiag_que_acc
) {
3968 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3969 "2926 Can't create idiag debugfs\n");
3974 /* iDiag access PCI function doorbell registers */
3975 snprintf(name
, sizeof(name
), "drbAcc");
3976 if (!phba
->idiag_drb_acc
) {
3977 phba
->idiag_drb_acc
=
3978 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3979 phba
->idiag_root
, phba
, &lpfc_idiag_op_drbAcc
);
3980 if (!phba
->idiag_drb_acc
) {
3981 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3982 "2927 Can't create idiag debugfs\n");
3987 /* iDiag access PCI function control registers */
3988 snprintf(name
, sizeof(name
), "ctlAcc");
3989 if (!phba
->idiag_ctl_acc
) {
3990 phba
->idiag_ctl_acc
=
3991 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
3992 phba
->idiag_root
, phba
, &lpfc_idiag_op_ctlAcc
);
3993 if (!phba
->idiag_ctl_acc
) {
3994 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3995 "2981 Can't create idiag debugfs\n");
4000 /* iDiag access mbox commands */
4001 snprintf(name
, sizeof(name
), "mbxAcc");
4002 if (!phba
->idiag_mbx_acc
) {
4003 phba
->idiag_mbx_acc
=
4004 debugfs_create_file(name
, S_IFREG
|S_IRUGO
|S_IWUSR
,
4005 phba
->idiag_root
, phba
, &lpfc_idiag_op_mbxAcc
);
4006 if (!phba
->idiag_mbx_acc
) {
4007 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
4008 "2980 Can't create idiag debugfs\n");
4013 /* iDiag extents access commands */
4014 if (phba
->sli4_hba
.extents_in_use
) {
4015 snprintf(name
, sizeof(name
), "extAcc");
4016 if (!phba
->idiag_ext_acc
) {
4017 phba
->idiag_ext_acc
=
4018 debugfs_create_file(name
,
4019 S_IFREG
|S_IRUGO
|S_IWUSR
,
4020 phba
->idiag_root
, phba
,
4021 &lpfc_idiag_op_extAcc
);
4022 if (!phba
->idiag_ext_acc
) {
4023 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
4037 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
4038 * @vport: The vport pointer to remove from debugfs.
4041 * When Debugfs is configured this routine removes debugfs file system elements
4042 * that are specific to this vport. It also checks to see if there are any
4043 * users left for the debugfs directories associated with the HBA and driver. If
4044 * this is the last user of the HBA directory or driver directory then it will
4045 * remove those from the debugfs infrastructure as well.
4048 lpfc_debugfs_terminate(struct lpfc_vport
*vport
)
4050 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4051 struct lpfc_hba
*phba
= vport
->phba
;
4053 if (vport
->disc_trc
) {
4054 kfree(vport
->disc_trc
);
4055 vport
->disc_trc
= NULL
;
4057 if (vport
->debug_disc_trc
) {
4058 debugfs_remove(vport
->debug_disc_trc
); /* discovery_trace */
4059 vport
->debug_disc_trc
= NULL
;
4061 if (vport
->debug_nodelist
) {
4062 debugfs_remove(vport
->debug_nodelist
); /* nodelist */
4063 vport
->debug_nodelist
= NULL
;
4065 if (vport
->vport_debugfs_root
) {
4066 debugfs_remove(vport
->vport_debugfs_root
); /* vportX */
4067 vport
->vport_debugfs_root
= NULL
;
4068 atomic_dec(&phba
->debugfs_vport_count
);
4070 if (atomic_read(&phba
->debugfs_vport_count
) == 0) {
4072 if (phba
->debug_hbqinfo
) {
4073 debugfs_remove(phba
->debug_hbqinfo
); /* hbqinfo */
4074 phba
->debug_hbqinfo
= NULL
;
4076 if (phba
->debug_dumpHBASlim
) {
4077 debugfs_remove(phba
->debug_dumpHBASlim
); /* HBASlim */
4078 phba
->debug_dumpHBASlim
= NULL
;
4080 if (phba
->debug_dumpHostSlim
) {
4081 debugfs_remove(phba
->debug_dumpHostSlim
); /* HostSlim */
4082 phba
->debug_dumpHostSlim
= NULL
;
4084 if (phba
->debug_dumpData
) {
4085 debugfs_remove(phba
->debug_dumpData
); /* dumpData */
4086 phba
->debug_dumpData
= NULL
;
4089 if (phba
->debug_dumpDif
) {
4090 debugfs_remove(phba
->debug_dumpDif
); /* dumpDif */
4091 phba
->debug_dumpDif
= NULL
;
4094 if (phba
->slow_ring_trc
) {
4095 kfree(phba
->slow_ring_trc
);
4096 phba
->slow_ring_trc
= NULL
;
4098 if (phba
->debug_slow_ring_trc
) {
4099 /* slow_ring_trace */
4100 debugfs_remove(phba
->debug_slow_ring_trc
);
4101 phba
->debug_slow_ring_trc
= NULL
;
4107 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4108 if (phba
->idiag_ext_acc
) {
4110 debugfs_remove(phba
->idiag_ext_acc
);
4111 phba
->idiag_ext_acc
= NULL
;
4113 if (phba
->idiag_mbx_acc
) {
4115 debugfs_remove(phba
->idiag_mbx_acc
);
4116 phba
->idiag_mbx_acc
= NULL
;
4118 if (phba
->idiag_ctl_acc
) {
4120 debugfs_remove(phba
->idiag_ctl_acc
);
4121 phba
->idiag_ctl_acc
= NULL
;
4123 if (phba
->idiag_drb_acc
) {
4125 debugfs_remove(phba
->idiag_drb_acc
);
4126 phba
->idiag_drb_acc
= NULL
;
4128 if (phba
->idiag_que_acc
) {
4130 debugfs_remove(phba
->idiag_que_acc
);
4131 phba
->idiag_que_acc
= NULL
;
4133 if (phba
->idiag_que_info
) {
4135 debugfs_remove(phba
->idiag_que_info
);
4136 phba
->idiag_que_info
= NULL
;
4138 if (phba
->idiag_bar_acc
) {
4140 debugfs_remove(phba
->idiag_bar_acc
);
4141 phba
->idiag_bar_acc
= NULL
;
4143 if (phba
->idiag_pci_cfg
) {
4145 debugfs_remove(phba
->idiag_pci_cfg
);
4146 phba
->idiag_pci_cfg
= NULL
;
4149 /* Finally remove the iDiag debugfs root */
4150 if (phba
->idiag_root
) {
4152 debugfs_remove(phba
->idiag_root
);
4153 phba
->idiag_root
= NULL
;
4157 if (phba
->hba_debugfs_root
) {
4158 debugfs_remove(phba
->hba_debugfs_root
); /* fnX */
4159 phba
->hba_debugfs_root
= NULL
;
4160 atomic_dec(&lpfc_debugfs_hba_count
);
4163 if (atomic_read(&lpfc_debugfs_hba_count
) == 0) {
4164 debugfs_remove(lpfc_debugfs_root
); /* lpfc */
4165 lpfc_debugfs_root
= NULL
;