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_dif_err_open(struct inode *inode, struct file *file)
1002 file->private_data = inode->i_private;
1007 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1008 size_t nbytes, loff_t *ppos)
1010 struct dentry *dent = file->f_dentry;
1011 struct lpfc_hba *phba = file->private_data;
1015 if (dent == phba->debug_writeGuard)
1016 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1017 else if (dent == phba->debug_writeApp)
1018 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wapp_cnt);
1019 else if (dent == phba->debug_writeRef)
1020 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wref_cnt);
1021 else if (dent == phba->debug_readApp)
1022 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rapp_cnt);
1023 else if (dent == phba->debug_readRef)
1024 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rref_cnt);
1025 else if (dent == phba->debug_InjErrLBA)
1026 cnt = snprintf(cbuf, 16, "0x%lx\n",
1027 (unsigned long) phba->lpfc_injerr_lba);
1029 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1030 "0547 Unknown debugfs error injection entry\n");
1032 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1036 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1037 size_t nbytes, loff_t *ppos)
1039 struct dentry *dent = file->f_dentry;
1040 struct lpfc_hba *phba = file->private_data;
1045 memset(dstbuf, 0, 32);
1046 size = (nbytes < 32) ? nbytes : 32;
1047 if (copy_from_user(dstbuf, buf, size))
1050 if (strict_strtoul(dstbuf, 0, &tmp))
1053 if (dent == phba->debug_writeGuard)
1054 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1055 else if (dent == phba->debug_writeApp)
1056 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1057 else if (dent == phba->debug_writeRef)
1058 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1059 else if (dent == phba->debug_readApp)
1060 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1061 else if (dent == phba->debug_readRef)
1062 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1063 else if (dent == phba->debug_InjErrLBA)
1064 phba->lpfc_injerr_lba = (sector_t)tmp;
1066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1067 "0548 Unknown debugfs error injection entry\n");
1073 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1079 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1080 * @inode: The inode pointer that contains a vport pointer.
1081 * @file: The file pointer to attach the log output.
1084 * This routine is the entry point for the debugfs open file operation. It gets
1085 * the vport from the i_private field in @inode, allocates the necessary buffer
1086 * for the log, fills the buffer from the in-memory log for this vport, and then
1087 * returns a pointer to that log in the private_data field in @file.
1090 * This function returns zero if successful. On error it will return an negative
1094 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1096 struct lpfc_vport *vport = inode->i_private;
1097 struct lpfc_debug *debug;
1100 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1104 /* Round to page boundary */
1105 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1106 if (!debug->buffer) {
1111 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1112 LPFC_NODELIST_SIZE);
1113 file->private_data = debug;
1121 * lpfc_debugfs_lseek - Seek through a debugfs file
1122 * @file: The file pointer to seek through.
1123 * @off: The offset to seek to or the amount to seek by.
1124 * @whence: Indicates how to seek.
1127 * This routine is the entry point for the debugfs lseek file operation. The
1128 * @whence parameter indicates whether @off is the offset to directly seek to,
1129 * or if it is a value to seek forward or reverse by. This function figures out
1130 * what the new offset of the debugfs file will be and assigns that value to the
1131 * f_pos field of @file.
1134 * This function returns the new offset if successful and returns a negative
1135 * error if unable to process the seek.
1138 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1140 struct lpfc_debug *debug;
1143 debug = file->private_data;
1150 pos = file->f_pos + off;
1153 pos = debug->len - off;
1155 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1159 * lpfc_debugfs_read - Read a debugfs file
1160 * @file: The file pointer to read from.
1161 * @buf: The buffer to copy the data to.
1162 * @nbytes: The number of bytes to read.
1163 * @ppos: The position in the file to start reading from.
1166 * This routine reads data from from the buffer indicated in the private_data
1167 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1171 * This function returns the amount of data that was read (this could be less
1172 * than @nbytes if the end of the file was reached) or a negative error value.
1175 lpfc_debugfs_read(struct file *file, char __user *buf,
1176 size_t nbytes, loff_t *ppos)
1178 struct lpfc_debug *debug = file->private_data;
1180 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1185 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1186 * @inode: The inode pointer that contains a vport pointer. (unused)
1187 * @file: The file pointer that contains the buffer to release.
1190 * This routine frees the buffer that was allocated when the debugfs file was
1194 * This function returns zero.
1197 lpfc_debugfs_release(struct inode *inode, struct file *file)
1199 struct lpfc_debug *debug = file->private_data;
1201 kfree(debug->buffer);
1208 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1210 struct lpfc_debug *debug = file->private_data;
1212 debug->buffer = NULL;
1219 * ---------------------------------
1220 * iDiag debugfs file access methods
1221 * ---------------------------------
1223 * All access methods are through the proper SLI4 PCI function's debugfs
1226 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1230 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1231 * @buf: The pointer to the user space buffer.
1232 * @nbytes: The number of bytes in the user space buffer.
1233 * @idiag_cmd: pointer to the idiag command struct.
1235 * This routine reads data from debugfs user space buffer and parses the
1236 * buffer for getting the idiag command and arguments. The while space in
1237 * between the set of data is used as the parsing separator.
1239 * This routine returns 0 when successful, it returns proper error code
1240 * back to the user space in error conditions.
1242 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1243 struct lpfc_idiag_cmd *idiag_cmd)
1246 char *pbuf, *step_str;
1250 /* Protect copy from user */
1251 if (!access_ok(VERIFY_READ, buf, nbytes))
1254 memset(mybuf, 0, sizeof(mybuf));
1255 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1256 bsize = min(nbytes, (sizeof(mybuf)-1));
1258 if (copy_from_user(mybuf, buf, bsize))
1261 step_str = strsep(&pbuf, "\t ");
1263 /* The opcode must present */
1267 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1268 if (idiag_cmd->opcode == 0)
1271 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1272 step_str = strsep(&pbuf, "\t ");
1275 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1281 * lpfc_idiag_open - idiag open debugfs
1282 * @inode: The inode pointer that contains a pointer to phba.
1283 * @file: The file pointer to attach the file operation.
1286 * This routine is the entry point for the debugfs open file operation. It
1287 * gets the reference to phba from the i_private field in @inode, it then
1288 * allocates buffer for the file operation, performs the necessary PCI config
1289 * space read into the allocated buffer according to the idiag user command
1290 * setup, and then returns a pointer to buffer in the private_data field in
1294 * This function returns zero if successful. On error it will return an
1295 * negative error value.
1298 lpfc_idiag_open(struct inode *inode, struct file *file)
1300 struct lpfc_debug *debug;
1302 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1306 debug->i_private = inode->i_private;
1307 debug->buffer = NULL;
1308 file->private_data = debug;
1314 * lpfc_idiag_release - Release idiag access file operation
1315 * @inode: The inode pointer that contains a vport pointer. (unused)
1316 * @file: The file pointer that contains the buffer to release.
1319 * This routine is the generic release routine for the idiag access file
1320 * operation, it frees the buffer that was allocated when the debugfs file
1324 * This function returns zero.
1327 lpfc_idiag_release(struct inode *inode, struct file *file)
1329 struct lpfc_debug *debug = file->private_data;
1331 /* Free the buffers to the file operation */
1332 kfree(debug->buffer);
1339 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1340 * @inode: The inode pointer that contains a vport pointer. (unused)
1341 * @file: The file pointer that contains the buffer to release.
1344 * This routine frees the buffer that was allocated when the debugfs file
1345 * was opened. It also reset the fields in the idiag command struct in the
1346 * case of command for write operation.
1349 * This function returns zero.
1352 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1354 struct lpfc_debug *debug = file->private_data;
1356 if (debug->op == LPFC_IDIAG_OP_WR) {
1357 switch (idiag.cmd.opcode) {
1358 case LPFC_IDIAG_CMD_PCICFG_WR:
1359 case LPFC_IDIAG_CMD_PCICFG_ST:
1360 case LPFC_IDIAG_CMD_PCICFG_CL:
1361 case LPFC_IDIAG_CMD_QUEACC_WR:
1362 case LPFC_IDIAG_CMD_QUEACC_ST:
1363 case LPFC_IDIAG_CMD_QUEACC_CL:
1364 memset(&idiag, 0, sizeof(idiag));
1371 /* Free the buffers to the file operation */
1372 kfree(debug->buffer);
1379 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1380 * @file: The file pointer to read from.
1381 * @buf: The buffer to copy the data to.
1382 * @nbytes: The number of bytes to read.
1383 * @ppos: The position in the file to start reading from.
1386 * This routine reads data from the @phba pci config space according to the
1387 * idiag command, and copies to user @buf. Depending on the PCI config space
1388 * read command setup, it does either a single register read of a byte
1389 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1390 * registers from the 4K extended PCI config space.
1393 * This function returns the amount of data that was read (this could be less
1394 * than @nbytes if the end of the file was reached) or a negative error value.
1397 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1400 struct lpfc_debug *debug = file->private_data;
1401 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1402 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1405 struct pci_dev *pdev;
1410 pdev = phba->pcidev;
1414 /* This is a user read operation */
1415 debug->op = LPFC_IDIAG_OP_RD;
1418 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1421 pbuffer = debug->buffer;
1426 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1427 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1428 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1432 /* Read single PCI config space register */
1434 case SIZE_U8: /* byte (8 bits) */
1435 pci_read_config_byte(pdev, where, &u8val);
1436 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1437 "%03x: %02x\n", where, u8val);
1439 case SIZE_U16: /* word (16 bits) */
1440 pci_read_config_word(pdev, where, &u16val);
1441 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1442 "%03x: %04x\n", where, u16val);
1444 case SIZE_U32: /* double word (32 bits) */
1445 pci_read_config_dword(pdev, where, &u32val);
1446 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1447 "%03x: %08x\n", where, u32val);
1449 case LPFC_PCI_CFG_BROWSE: /* browse all */
1457 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1461 /* Browse all PCI config space registers */
1462 offset_label = idiag.offset.last_rd;
1463 offset = offset_label;
1465 /* Read PCI config space */
1466 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1467 "%03x: ", offset_label);
1469 pci_read_config_dword(pdev, offset, &u32val);
1470 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1472 offset += sizeof(uint32_t);
1473 if (offset >= LPFC_PCI_CFG_SIZE) {
1474 len += snprintf(pbuffer+len,
1475 LPFC_PCI_CFG_SIZE-len, "\n");
1478 index -= sizeof(uint32_t);
1480 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1482 else if (!(index % (8 * sizeof(uint32_t)))) {
1483 offset_label += (8 * sizeof(uint32_t));
1484 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1485 "\n%03x: ", offset_label);
1489 /* Set up the offset for next portion of pci cfg read */
1491 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1492 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1493 idiag.offset.last_rd = 0;
1495 idiag.offset.last_rd = 0;
1497 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1501 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1502 * @file: The file pointer to read from.
1503 * @buf: The buffer to copy the user data from.
1504 * @nbytes: The number of bytes to get.
1505 * @ppos: The position in the file to start reading from.
1507 * This routine get the debugfs idiag command struct from user space and
1508 * then perform the syntax check for PCI config space read or write command
1509 * accordingly. In the case of PCI config space read command, it sets up
1510 * the command in the idiag command struct for the debugfs read operation.
1511 * In the case of PCI config space write operation, it executes the write
1512 * operation into the PCI config space accordingly.
1514 * It returns the @nbytges passing in from debugfs user space when successful.
1515 * In case of error conditions, it returns proper error code back to the user
1519 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1520 size_t nbytes, loff_t *ppos)
1522 struct lpfc_debug *debug = file->private_data;
1523 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1524 uint32_t where, value, count;
1528 struct pci_dev *pdev;
1531 pdev = phba->pcidev;
1535 /* This is a user write operation */
1536 debug->op = LPFC_IDIAG_OP_WR;
1538 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1542 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1543 /* Sanity check on PCI config read command line arguments */
1544 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1546 /* Read command from PCI config space, set up command fields */
1547 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1548 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1549 if (count == LPFC_PCI_CFG_BROWSE) {
1550 if (where % sizeof(uint32_t))
1552 /* Starting offset to browse */
1553 idiag.offset.last_rd = where;
1554 } else if ((count != sizeof(uint8_t)) &&
1555 (count != sizeof(uint16_t)) &&
1556 (count != sizeof(uint32_t)))
1558 if (count == sizeof(uint8_t)) {
1559 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1561 if (where % sizeof(uint8_t))
1564 if (count == sizeof(uint16_t)) {
1565 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1567 if (where % sizeof(uint16_t))
1570 if (count == sizeof(uint32_t)) {
1571 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1573 if (where % sizeof(uint32_t))
1576 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1577 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1578 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1579 /* Sanity check on PCI config write command line arguments */
1580 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1582 /* Write command to PCI config space, read-modify-write */
1583 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1584 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1585 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
1587 if ((count != sizeof(uint8_t)) &&
1588 (count != sizeof(uint16_t)) &&
1589 (count != sizeof(uint32_t)))
1591 if (count == sizeof(uint8_t)) {
1592 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1594 if (where % sizeof(uint8_t))
1596 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1597 pci_write_config_byte(pdev, where,
1599 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1600 rc = pci_read_config_byte(pdev, where, &u8val);
1602 u8val |= (uint8_t)value;
1603 pci_write_config_byte(pdev, where,
1607 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1608 rc = pci_read_config_byte(pdev, where, &u8val);
1610 u8val &= (uint8_t)(~value);
1611 pci_write_config_byte(pdev, where,
1616 if (count == sizeof(uint16_t)) {
1617 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1619 if (where % sizeof(uint16_t))
1621 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1622 pci_write_config_word(pdev, where,
1624 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1625 rc = pci_read_config_word(pdev, where, &u16val);
1627 u16val |= (uint16_t)value;
1628 pci_write_config_word(pdev, where,
1632 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1633 rc = pci_read_config_word(pdev, where, &u16val);
1635 u16val &= (uint16_t)(~value);
1636 pci_write_config_word(pdev, where,
1641 if (count == sizeof(uint32_t)) {
1642 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1644 if (where % sizeof(uint32_t))
1646 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1647 pci_write_config_dword(pdev, where, value);
1648 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1649 rc = pci_read_config_dword(pdev, where,
1653 pci_write_config_dword(pdev, where,
1657 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1658 rc = pci_read_config_dword(pdev, where,
1662 pci_write_config_dword(pdev, where,
1668 /* All other opecodes are illegal for now */
1673 memset(&idiag, 0, sizeof(idiag));
1678 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1679 * @file: The file pointer to read from.
1680 * @buf: The buffer to copy the data to.
1681 * @nbytes: The number of bytes to read.
1682 * @ppos: The position in the file to start reading from.
1685 * This routine reads data from the @phba pci bar memory mapped space
1686 * according to the idiag command, and copies to user @buf.
1689 * This function returns the amount of data that was read (this could be less
1690 * than @nbytes if the end of the file was reached) or a negative error value.
1693 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1696 struct lpfc_debug *debug = file->private_data;
1697 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1698 int offset_label, offset, offset_run, len = 0, index;
1699 int bar_num, acc_range, bar_size;
1701 void __iomem *mem_mapped_bar;
1703 struct pci_dev *pdev;
1706 pdev = phba->pcidev;
1710 /* This is a user read operation */
1711 debug->op = LPFC_IDIAG_OP_RD;
1714 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1717 pbuffer = debug->buffer;
1722 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1723 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1724 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1725 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1726 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1733 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1734 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1735 if (bar_num == IDIAG_BARACC_BAR_0)
1736 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1737 else if (bar_num == IDIAG_BARACC_BAR_1)
1738 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1739 else if (bar_num == IDIAG_BARACC_BAR_2)
1740 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1743 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1744 if (bar_num == IDIAG_BARACC_BAR_0)
1745 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1751 /* Read single PCI bar space register */
1752 if (acc_range == SINGLE_WORD) {
1753 offset_run = offset;
1754 u32val = readl(mem_mapped_bar + offset_run);
1755 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1756 "%05x: %08x\n", offset_run, u32val);
1760 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1764 /* Browse all PCI bar space registers */
1765 offset_label = idiag.offset.last_rd;
1766 offset_run = offset_label;
1768 /* Read PCI bar memory mapped space */
1769 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1770 "%05x: ", offset_label);
1771 index = LPFC_PCI_BAR_RD_SIZE;
1773 u32val = readl(mem_mapped_bar + offset_run);
1774 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1776 offset_run += sizeof(uint32_t);
1777 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1778 if (offset_run >= bar_size) {
1779 len += snprintf(pbuffer+len,
1780 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1784 if (offset_run >= offset +
1785 (acc_range * sizeof(uint32_t))) {
1786 len += snprintf(pbuffer+len,
1787 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1791 index -= sizeof(uint32_t);
1793 len += snprintf(pbuffer+len,
1794 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1795 else if (!(index % (8 * sizeof(uint32_t)))) {
1796 offset_label += (8 * sizeof(uint32_t));
1797 len += snprintf(pbuffer+len,
1798 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1799 "\n%05x: ", offset_label);
1803 /* Set up the offset for next portion of pci bar read */
1805 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1806 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1807 if (idiag.offset.last_rd >= bar_size)
1808 idiag.offset.last_rd = 0;
1810 if (offset_run >= offset +
1811 (acc_range * sizeof(uint32_t)))
1812 idiag.offset.last_rd = offset;
1815 if (acc_range == LPFC_PCI_BAR_BROWSE)
1816 idiag.offset.last_rd = 0;
1818 idiag.offset.last_rd = offset;
1821 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1825 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1826 * @file: The file pointer to read from.
1827 * @buf: The buffer to copy the user data from.
1828 * @nbytes: The number of bytes to get.
1829 * @ppos: The position in the file to start reading from.
1831 * This routine get the debugfs idiag command struct from user space and
1832 * then perform the syntax check for PCI bar memory mapped space read or
1833 * write command accordingly. In the case of PCI bar memory mapped space
1834 * read command, it sets up the command in the idiag command struct for
1835 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1836 * write operation, it executes the write operation into the PCI bar memory
1837 * mapped space accordingly.
1839 * It returns the @nbytges passing in from debugfs user space when successful.
1840 * In case of error conditions, it returns proper error code back to the user
1844 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1845 size_t nbytes, loff_t *ppos)
1847 struct lpfc_debug *debug = file->private_data;
1848 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1849 uint32_t bar_num, bar_size, offset, value, acc_range;
1850 struct pci_dev *pdev;
1851 void __iomem *mem_mapped_bar;
1856 pdev = phba->pcidev;
1860 /* This is a user write operation */
1861 debug->op = LPFC_IDIAG_OP_WR;
1863 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1867 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1868 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1870 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1871 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1872 (bar_num != IDIAG_BARACC_BAR_1) &&
1873 (bar_num != IDIAG_BARACC_BAR_2))
1875 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1876 if (bar_num != IDIAG_BARACC_BAR_0)
1881 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1882 if (bar_num == IDIAG_BARACC_BAR_0) {
1883 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1884 LPFC_PCI_IF0_BAR0_SIZE;
1885 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1886 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1887 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1888 LPFC_PCI_IF0_BAR1_SIZE;
1889 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1890 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1891 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1892 LPFC_PCI_IF0_BAR2_SIZE;
1893 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1896 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1897 if (bar_num == IDIAG_BARACC_BAR_0) {
1898 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1899 LPFC_PCI_IF2_BAR0_SIZE;
1900 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1906 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1907 if (offset % sizeof(uint32_t))
1910 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1911 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1912 /* Sanity check on PCI config read command line arguments */
1913 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1915 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1916 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1917 if (offset > bar_size - sizeof(uint32_t))
1919 /* Starting offset to browse */
1920 idiag.offset.last_rd = offset;
1921 } else if (acc_range > SINGLE_WORD) {
1922 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1924 /* Starting offset to browse */
1925 idiag.offset.last_rd = offset;
1926 } else if (acc_range != SINGLE_WORD)
1928 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1929 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1930 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1931 /* Sanity check on PCI bar write command line arguments */
1932 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1934 /* Write command to PCI bar space, read-modify-write */
1935 acc_range = SINGLE_WORD;
1936 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1937 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1938 writel(value, mem_mapped_bar + offset);
1939 readl(mem_mapped_bar + offset);
1941 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1942 u32val = readl(mem_mapped_bar + offset);
1944 writel(u32val, mem_mapped_bar + offset);
1945 readl(mem_mapped_bar + offset);
1947 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1948 u32val = readl(mem_mapped_bar + offset);
1950 writel(u32val, mem_mapped_bar + offset);
1951 readl(mem_mapped_bar + offset);
1954 /* All other opecodes are illegal for now */
1959 memset(&idiag, 0, sizeof(idiag));
1964 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1965 * @file: The file pointer to read from.
1966 * @buf: The buffer to copy the data to.
1967 * @nbytes: The number of bytes to read.
1968 * @ppos: The position in the file to start reading from.
1971 * This routine reads data from the @phba SLI4 PCI function queue information,
1972 * and copies to user @buf.
1975 * This function returns the amount of data that was read (this could be less
1976 * than @nbytes if the end of the file was reached) or a negative error value.
1979 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
1982 struct lpfc_debug *debug = file->private_data;
1983 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1984 int len = 0, fcp_qidx;
1988 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
1991 pbuffer = debug->buffer;
1996 /* Get slow-path event queue information */
1997 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1998 "Slow-path EQ information:\n");
1999 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2001 "QE-COUNT[%04d], QE-SIZE[%04d], "
2002 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2003 phba->sli4_hba.sp_eq->queue_id,
2004 phba->sli4_hba.sp_eq->entry_count,
2005 phba->sli4_hba.sp_eq->entry_size,
2006 phba->sli4_hba.sp_eq->host_index,
2007 phba->sli4_hba.sp_eq->hba_index);
2009 /* Get fast-path event queue information */
2010 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2011 "Fast-path EQ information:\n");
2012 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
2013 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2015 "QE-COUNT[%04d], QE-SIZE[%04d], "
2016 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2017 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
2018 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
2019 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
2020 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
2021 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
2023 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2025 /* Get mailbox complete queue information */
2026 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2027 "Slow-path MBX CQ information:\n");
2028 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2029 "Associated EQID[%02d]:\n",
2030 phba->sli4_hba.mbx_cq->assoc_qid);
2031 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2033 "QE-COUNT[%04d], QE-SIZE[%04d], "
2034 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2035 phba->sli4_hba.mbx_cq->queue_id,
2036 phba->sli4_hba.mbx_cq->entry_count,
2037 phba->sli4_hba.mbx_cq->entry_size,
2038 phba->sli4_hba.mbx_cq->host_index,
2039 phba->sli4_hba.mbx_cq->hba_index);
2041 /* Get slow-path complete queue information */
2042 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2043 "Slow-path ELS CQ information:\n");
2044 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2045 "Associated EQID[%02d]:\n",
2046 phba->sli4_hba.els_cq->assoc_qid);
2047 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2049 "QE-COUNT[%04d], QE-SIZE[%04d], "
2050 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2051 phba->sli4_hba.els_cq->queue_id,
2052 phba->sli4_hba.els_cq->entry_count,
2053 phba->sli4_hba.els_cq->entry_size,
2054 phba->sli4_hba.els_cq->host_index,
2055 phba->sli4_hba.els_cq->hba_index);
2057 /* Get fast-path complete queue information */
2058 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2059 "Fast-path FCP CQ information:\n");
2062 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2063 "Associated EQID[%02d]:\n",
2064 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
2065 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2067 "QE-COUNT[%04d], QE-SIZE[%04d], "
2068 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2069 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
2070 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
2071 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
2072 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
2073 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
2074 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
2075 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2077 /* Get mailbox queue information */
2078 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2079 "Slow-path MBX MQ information:\n");
2080 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2081 "Associated CQID[%02d]:\n",
2082 phba->sli4_hba.mbx_wq->assoc_qid);
2083 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2085 "QE-COUNT[%04d], QE-SIZE[%04d], "
2086 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2087 phba->sli4_hba.mbx_wq->queue_id,
2088 phba->sli4_hba.mbx_wq->entry_count,
2089 phba->sli4_hba.mbx_wq->entry_size,
2090 phba->sli4_hba.mbx_wq->host_index,
2091 phba->sli4_hba.mbx_wq->hba_index);
2093 /* Get slow-path work queue information */
2094 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2095 "Slow-path ELS WQ information:\n");
2096 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2097 "Associated CQID[%02d]:\n",
2098 phba->sli4_hba.els_wq->assoc_qid);
2099 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2101 "QE-COUNT[%04d], QE-SIZE[%04d], "
2102 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2103 phba->sli4_hba.els_wq->queue_id,
2104 phba->sli4_hba.els_wq->entry_count,
2105 phba->sli4_hba.els_wq->entry_size,
2106 phba->sli4_hba.els_wq->host_index,
2107 phba->sli4_hba.els_wq->hba_index);
2109 /* Get fast-path work queue information */
2110 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2111 "Fast-path FCP WQ information:\n");
2112 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
2113 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2114 "Associated CQID[%02d]:\n",
2115 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
2116 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2118 "QE-COUNT[%04d], WQE-SIZE[%04d], "
2119 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2120 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
2121 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
2122 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
2123 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
2124 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
2126 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2128 /* Get receive queue information */
2129 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2130 "Slow-path RQ information:\n");
2131 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2132 "Associated CQID[%02d]:\n",
2133 phba->sli4_hba.hdr_rq->assoc_qid);
2134 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2136 "QE-COUNT[%04d], QE-SIZE[%04d], "
2137 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2138 phba->sli4_hba.hdr_rq->queue_id,
2139 phba->sli4_hba.hdr_rq->entry_count,
2140 phba->sli4_hba.hdr_rq->entry_size,
2141 phba->sli4_hba.hdr_rq->host_index,
2142 phba->sli4_hba.hdr_rq->hba_index);
2143 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2145 "QE-COUNT[%04d], QE-SIZE[%04d], "
2146 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2147 phba->sli4_hba.dat_rq->queue_id,
2148 phba->sli4_hba.dat_rq->entry_count,
2149 phba->sli4_hba.dat_rq->entry_size,
2150 phba->sli4_hba.dat_rq->host_index,
2151 phba->sli4_hba.dat_rq->hba_index);
2153 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2157 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2158 * @q: The pointer to queue structure.
2159 * @index: The index into a queue entry.
2160 * @count: The number of queue entries to access.
2163 * The routine performs sanity check on device queue access method commands.
2166 * This function returns -EINVAL when fails the sanity check, otherwise, it
2170 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2172 /* Only support single entry read or browsing */
2173 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2175 if (index > q->entry_count - 1)
2181 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2182 * @pbuffer: The pointer to buffer to copy the read data into.
2183 * @pque: The pointer to the queue to be read.
2184 * @index: The index into the queue entry.
2187 * This routine reads out a single entry from the given queue's index location
2188 * and copies it into the buffer provided.
2191 * This function returns 0 when it fails, otherwise, it returns the length of
2192 * the data read into the buffer provided.
2195 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2201 if (!pbuffer || !pque)
2204 esize = pque->entry_size;
2205 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2206 "QE-INDEX[%04d]:\n", index);
2209 pentry = pque->qe[index].address;
2211 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2214 offset += sizeof(uint32_t);
2215 esize -= sizeof(uint32_t);
2216 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2217 len += snprintf(pbuffer+len,
2218 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2220 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2226 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2227 * @file: The file pointer to read from.
2228 * @buf: The buffer to copy the data to.
2229 * @nbytes: The number of bytes to read.
2230 * @ppos: The position in the file to start reading from.
2233 * This routine reads data from the @phba device queue memory according to the
2234 * idiag command, and copies to user @buf. Depending on the queue dump read
2235 * command setup, it does either a single queue entry read or browing through
2236 * all entries of the queue.
2239 * This function returns the amount of data that was read (this could be less
2240 * than @nbytes if the end of the file was reached) or a negative error value.
2243 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2246 struct lpfc_debug *debug = file->private_data;
2247 uint32_t last_index, index, count;
2248 struct lpfc_queue *pque = NULL;
2252 /* This is a user read operation */
2253 debug->op = LPFC_IDIAG_OP_RD;
2256 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2259 pbuffer = debug->buffer;
2264 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2265 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2266 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2267 pque = (struct lpfc_queue *)idiag.ptr_private;
2271 /* Browse the queue starting from index */
2272 if (count == LPFC_QUE_ACC_BROWSE)
2275 /* Read a single entry from the queue */
2276 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2278 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2282 /* Browse all entries from the queue */
2283 last_index = idiag.offset.last_rd;
2286 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2287 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2289 if (index > pque->entry_count - 1)
2293 /* Set up the offset for next portion of pci cfg read */
2294 if (index > pque->entry_count - 1)
2296 idiag.offset.last_rd = index;
2298 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2302 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2303 * @file: The file pointer to read from.
2304 * @buf: The buffer to copy the user data from.
2305 * @nbytes: The number of bytes to get.
2306 * @ppos: The position in the file to start reading from.
2308 * This routine get the debugfs idiag command struct from user space and then
2309 * perform the syntax check for port queue read (dump) or write (set) command
2310 * accordingly. In the case of port queue read command, it sets up the command
2311 * in the idiag command struct for the following debugfs read operation. In
2312 * the case of port queue write operation, it executes the write operation
2313 * into the port queue entry accordingly.
2315 * It returns the @nbytges passing in from debugfs user space when successful.
2316 * In case of error conditions, it returns proper error code back to the user
2320 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2321 size_t nbytes, loff_t *ppos)
2323 struct lpfc_debug *debug = file->private_data;
2324 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2325 uint32_t qidx, quetp, queid, index, count, offset, value;
2327 struct lpfc_queue *pque;
2330 /* This is a user write operation */
2331 debug->op = LPFC_IDIAG_OP_WR;
2333 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2337 /* Get and sanity check on command feilds */
2338 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2339 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2340 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2341 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2342 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2343 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
2345 /* Sanity check on command line arguments */
2346 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2347 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2348 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2349 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2353 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2354 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2361 /* Slow-path event queue */
2362 if (phba->sli4_hba.sp_eq->queue_id == queid) {
2364 rc = lpfc_idiag_que_param_check(
2365 phba->sli4_hba.sp_eq, index, count);
2368 idiag.ptr_private = phba->sli4_hba.sp_eq;
2371 /* Fast-path event queue */
2372 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
2373 if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
2375 rc = lpfc_idiag_que_param_check(
2376 phba->sli4_hba.fp_eq[qidx],
2380 idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
2387 /* MBX complete queue */
2388 if (phba->sli4_hba.mbx_cq->queue_id == queid) {
2390 rc = lpfc_idiag_que_param_check(
2391 phba->sli4_hba.mbx_cq, index, count);
2394 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2397 /* ELS complete queue */
2398 if (phba->sli4_hba.els_cq->queue_id == queid) {
2400 rc = lpfc_idiag_que_param_check(
2401 phba->sli4_hba.els_cq, index, count);
2404 idiag.ptr_private = phba->sli4_hba.els_cq;
2407 /* FCP complete queue */
2410 if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
2412 rc = lpfc_idiag_que_param_check(
2413 phba->sli4_hba.fcp_cq[qidx],
2418 phba->sli4_hba.fcp_cq[qidx];
2421 } while (++qidx < phba->cfg_fcp_eq_count);
2425 /* MBX work queue */
2426 if (phba->sli4_hba.mbx_wq->queue_id == queid) {
2428 rc = lpfc_idiag_que_param_check(
2429 phba->sli4_hba.mbx_wq, index, count);
2432 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2437 /* ELS work queue */
2438 if (phba->sli4_hba.els_wq->queue_id == queid) {
2440 rc = lpfc_idiag_que_param_check(
2441 phba->sli4_hba.els_wq, index, count);
2444 idiag.ptr_private = phba->sli4_hba.els_wq;
2447 /* FCP work queue */
2448 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2449 if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
2451 rc = lpfc_idiag_que_param_check(
2452 phba->sli4_hba.fcp_wq[qidx],
2457 phba->sli4_hba.fcp_wq[qidx];
2465 if (phba->sli4_hba.hdr_rq->queue_id == queid) {
2467 rc = lpfc_idiag_que_param_check(
2468 phba->sli4_hba.hdr_rq, index, count);
2471 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2475 if (phba->sli4_hba.dat_rq->queue_id == queid) {
2477 rc = lpfc_idiag_que_param_check(
2478 phba->sli4_hba.dat_rq, index, count);
2481 idiag.ptr_private = phba->sli4_hba.dat_rq;
2493 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2494 if (count == LPFC_QUE_ACC_BROWSE)
2495 idiag.offset.last_rd = index;
2498 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2499 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2500 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2501 /* Additional sanity checks on write operation */
2502 pque = (struct lpfc_queue *)idiag.ptr_private;
2503 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2505 pentry = pque->qe[index].address;
2507 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2509 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2511 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2517 /* Clean out command structure on command error out */
2518 memset(&idiag, 0, sizeof(idiag));
2523 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2524 * @phba: The pointer to hba structure.
2525 * @pbuffer: The pointer to the buffer to copy the data to.
2526 * @len: The lenght of bytes to copied.
2527 * @drbregid: The id to doorbell registers.
2530 * This routine reads a doorbell register and copies its content to the
2531 * user buffer pointed to by @pbuffer.
2534 * This function returns the amount of data that was copied into @pbuffer.
2537 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2538 int len, uint32_t drbregid)
2546 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2547 "EQCQ-DRB-REG: 0x%08x\n",
2548 readl(phba->sli4_hba.EQCQDBregaddr));
2551 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2552 "MQ-DRB-REG: 0x%08x\n",
2553 readl(phba->sli4_hba.MQDBregaddr));
2556 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2557 "WQ-DRB-REG: 0x%08x\n",
2558 readl(phba->sli4_hba.WQDBregaddr));
2561 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2562 "RQ-DRB-REG: 0x%08x\n",
2563 readl(phba->sli4_hba.RQDBregaddr));
2573 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2574 * @file: The file pointer to read from.
2575 * @buf: The buffer to copy the data to.
2576 * @nbytes: The number of bytes to read.
2577 * @ppos: The position in the file to start reading from.
2580 * This routine reads data from the @phba device doorbell register according
2581 * to the idiag command, and copies to user @buf. Depending on the doorbell
2582 * register read command setup, it does either a single doorbell register
2583 * read or dump all doorbell registers.
2586 * This function returns the amount of data that was read (this could be less
2587 * than @nbytes if the end of the file was reached) or a negative error value.
2590 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2593 struct lpfc_debug *debug = file->private_data;
2594 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2595 uint32_t drb_reg_id, i;
2599 /* This is a user read operation */
2600 debug->op = LPFC_IDIAG_OP_RD;
2603 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2606 pbuffer = debug->buffer;
2611 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
2612 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2616 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2617 for (i = 1; i <= LPFC_DRB_MAX; i++)
2618 len = lpfc_idiag_drbacc_read_reg(phba,
2621 len = lpfc_idiag_drbacc_read_reg(phba,
2622 pbuffer, len, drb_reg_id);
2624 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2628 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2629 * @file: The file pointer to read from.
2630 * @buf: The buffer to copy the user data from.
2631 * @nbytes: The number of bytes to get.
2632 * @ppos: The position in the file to start reading from.
2634 * This routine get the debugfs idiag command struct from user space and then
2635 * perform the syntax check for port doorbell register read (dump) or write
2636 * (set) command accordingly. In the case of port queue read command, it sets
2637 * up the command in the idiag command struct for the following debugfs read
2638 * operation. In the case of port doorbell register write operation, it
2639 * executes the write operation into the port doorbell register accordingly.
2641 * It returns the @nbytges passing in from debugfs user space when successful.
2642 * In case of error conditions, it returns proper error code back to the user
2646 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2647 size_t nbytes, loff_t *ppos)
2649 struct lpfc_debug *debug = file->private_data;
2650 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2651 uint32_t drb_reg_id, value, reg_val = 0;
2652 void __iomem *drb_reg;
2655 /* This is a user write operation */
2656 debug->op = LPFC_IDIAG_OP_WR;
2658 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2662 /* Sanity check on command line arguments */
2663 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2664 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
2666 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2667 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2668 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2669 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2671 if (drb_reg_id > LPFC_DRB_MAX)
2673 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2674 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2676 if ((drb_reg_id > LPFC_DRB_MAX) &&
2677 (drb_reg_id != LPFC_DRB_ACC_ALL))
2682 /* Perform the write access operation */
2683 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2684 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2685 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2686 switch (drb_reg_id) {
2688 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2691 drb_reg = phba->sli4_hba.MQDBregaddr;
2694 drb_reg = phba->sli4_hba.WQDBregaddr;
2697 drb_reg = phba->sli4_hba.RQDBregaddr;
2703 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2705 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2706 reg_val = readl(drb_reg);
2709 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2710 reg_val = readl(drb_reg);
2713 writel(reg_val, drb_reg);
2714 readl(drb_reg); /* flush */
2719 /* Clean out command structure on command error out */
2720 memset(&idiag, 0, sizeof(idiag));
2725 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2726 * @phba: The pointer to hba structure.
2727 * @pbuffer: The pointer to the buffer to copy the data to.
2728 * @len: The lenght of bytes to copied.
2729 * @drbregid: The id to doorbell registers.
2732 * This routine reads a control register and copies its content to the
2733 * user buffer pointed to by @pbuffer.
2736 * This function returns the amount of data that was copied into @pbuffer.
2739 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2740 int len, uint32_t ctlregid)
2747 case LPFC_CTL_PORT_SEM:
2748 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2749 "Port SemReg: 0x%08x\n",
2750 readl(phba->sli4_hba.conf_regs_memmap_p +
2751 LPFC_CTL_PORT_SEM_OFFSET));
2753 case LPFC_CTL_PORT_STA:
2754 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2755 "Port StaReg: 0x%08x\n",
2756 readl(phba->sli4_hba.conf_regs_memmap_p +
2757 LPFC_CTL_PORT_STA_OFFSET));
2759 case LPFC_CTL_PORT_CTL:
2760 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2761 "Port CtlReg: 0x%08x\n",
2762 readl(phba->sli4_hba.conf_regs_memmap_p +
2763 LPFC_CTL_PORT_CTL_OFFSET));
2765 case LPFC_CTL_PORT_ER1:
2766 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2767 "Port Er1Reg: 0x%08x\n",
2768 readl(phba->sli4_hba.conf_regs_memmap_p +
2769 LPFC_CTL_PORT_ER1_OFFSET));
2771 case LPFC_CTL_PORT_ER2:
2772 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2773 "Port Er2Reg: 0x%08x\n",
2774 readl(phba->sli4_hba.conf_regs_memmap_p +
2775 LPFC_CTL_PORT_ER2_OFFSET));
2777 case LPFC_CTL_PDEV_CTL:
2778 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2779 "PDev CtlReg: 0x%08x\n",
2780 readl(phba->sli4_hba.conf_regs_memmap_p +
2781 LPFC_CTL_PDEV_CTL_OFFSET));
2790 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2791 * @file: The file pointer to read from.
2792 * @buf: The buffer to copy the data to.
2793 * @nbytes: The number of bytes to read.
2794 * @ppos: The position in the file to start reading from.
2797 * This routine reads data from the @phba port and device registers according
2798 * to the idiag command, and copies to user @buf.
2801 * This function returns the amount of data that was read (this could be less
2802 * than @nbytes if the end of the file was reached) or a negative error value.
2805 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2808 struct lpfc_debug *debug = file->private_data;
2809 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2810 uint32_t ctl_reg_id, i;
2814 /* This is a user read operation */
2815 debug->op = LPFC_IDIAG_OP_RD;
2818 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2821 pbuffer = debug->buffer;
2826 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2827 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2831 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2832 for (i = 1; i <= LPFC_CTL_MAX; i++)
2833 len = lpfc_idiag_ctlacc_read_reg(phba,
2836 len = lpfc_idiag_ctlacc_read_reg(phba,
2837 pbuffer, len, ctl_reg_id);
2839 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2843 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2844 * @file: The file pointer to read from.
2845 * @buf: The buffer to copy the user data from.
2846 * @nbytes: The number of bytes to get.
2847 * @ppos: The position in the file to start reading from.
2849 * This routine get the debugfs idiag command struct from user space and then
2850 * perform the syntax check for port and device control register read (dump)
2851 * or write (set) command accordingly.
2853 * It returns the @nbytges passing in from debugfs user space when successful.
2854 * In case of error conditions, it returns proper error code back to the user
2858 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
2859 size_t nbytes, loff_t *ppos)
2861 struct lpfc_debug *debug = file->private_data;
2862 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2863 uint32_t ctl_reg_id, value, reg_val = 0;
2864 void __iomem *ctl_reg;
2867 /* This is a user write operation */
2868 debug->op = LPFC_IDIAG_OP_WR;
2870 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2874 /* Sanity check on command line arguments */
2875 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2876 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
2878 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2879 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2880 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2881 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
2883 if (ctl_reg_id > LPFC_CTL_MAX)
2885 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
2886 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
2888 if ((ctl_reg_id > LPFC_CTL_MAX) &&
2889 (ctl_reg_id != LPFC_CTL_ACC_ALL))
2894 /* Perform the write access operation */
2895 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2896 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2897 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2898 switch (ctl_reg_id) {
2899 case LPFC_CTL_PORT_SEM:
2900 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2901 LPFC_CTL_PORT_SEM_OFFSET;
2903 case LPFC_CTL_PORT_STA:
2904 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2905 LPFC_CTL_PORT_STA_OFFSET;
2907 case LPFC_CTL_PORT_CTL:
2908 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2909 LPFC_CTL_PORT_CTL_OFFSET;
2911 case LPFC_CTL_PORT_ER1:
2912 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2913 LPFC_CTL_PORT_ER1_OFFSET;
2915 case LPFC_CTL_PORT_ER2:
2916 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2917 LPFC_CTL_PORT_ER2_OFFSET;
2919 case LPFC_CTL_PDEV_CTL:
2920 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2921 LPFC_CTL_PDEV_CTL_OFFSET;
2927 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
2929 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
2930 reg_val = readl(ctl_reg);
2933 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2934 reg_val = readl(ctl_reg);
2937 writel(reg_val, ctl_reg);
2938 readl(ctl_reg); /* flush */
2943 /* Clean out command structure on command error out */
2944 memset(&idiag, 0, sizeof(idiag));
2949 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
2950 * @phba: Pointer to HBA context object.
2951 * @pbuffer: Pointer to data buffer.
2954 * This routine gets the driver mailbox access debugfs setup information.
2957 * This function returns the amount of data that was read (this could be less
2958 * than @nbytes if the end of the file was reached) or a negative error value.
2961 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
2963 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
2966 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
2967 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
2968 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
2969 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
2971 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2972 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
2973 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2974 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
2975 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2976 "mbx_word_cnt: %04d\n", mbx_word_cnt);
2977 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2978 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
2984 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
2985 * @file: The file pointer to read from.
2986 * @buf: The buffer to copy the data to.
2987 * @nbytes: The number of bytes to read.
2988 * @ppos: The position in the file to start reading from.
2991 * This routine reads data from the @phba driver mailbox access debugfs setup
2995 * This function returns the amount of data that was read (this could be less
2996 * than @nbytes if the end of the file was reached) or a negative error value.
2999 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3002 struct lpfc_debug *debug = file->private_data;
3003 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3007 /* This is a user read operation */
3008 debug->op = LPFC_IDIAG_OP_RD;
3011 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3014 pbuffer = debug->buffer;
3019 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3020 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3023 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3025 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3029 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3030 * @file: The file pointer to read from.
3031 * @buf: The buffer to copy the user data from.
3032 * @nbytes: The number of bytes to get.
3033 * @ppos: The position in the file to start reading from.
3035 * This routine get the debugfs idiag command struct from user space and then
3036 * perform the syntax check for driver mailbox command (dump) and sets up the
3037 * necessary states in the idiag command struct accordingly.
3039 * It returns the @nbytges passing in from debugfs user space when successful.
3040 * In case of error conditions, it returns proper error code back to the user
3044 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3045 size_t nbytes, loff_t *ppos)
3047 struct lpfc_debug *debug = file->private_data;
3048 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3051 /* This is a user write operation */
3052 debug->op = LPFC_IDIAG_OP_WR;
3054 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3058 /* Sanity check on command line arguments */
3059 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3060 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3061 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3062 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3064 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3065 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3067 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3068 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3070 if (mbx_word_cnt > sizeof(MAILBOX_t))
3072 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3073 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3075 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3076 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3078 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3080 if (mbx_mbox_cmd != 0x9b)
3085 if (mbx_word_cnt == 0)
3087 if (rc != LPFC_MBX_DMP_ARG)
3089 if (mbx_mbox_cmd & ~0xff)
3092 /* condition for stop mailbox dump */
3093 if (mbx_dump_cnt == 0)
3099 /* Clean out command structure on command error out */
3100 memset(&idiag, 0, sizeof(idiag));
3104 /* Clean out command structure on command error out */
3105 memset(&idiag, 0, sizeof(idiag));
3110 * lpfc_idiag_extacc_avail_get - get the available extents information
3111 * @phba: pointer to lpfc hba data structure.
3112 * @pbuffer: pointer to internal buffer.
3113 * @len: length into the internal buffer data has been copied.
3116 * This routine is to get the available extent information.
3119 * overall lenth of the data read into the internal buffer.
3122 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3124 uint16_t ext_cnt, ext_size;
3126 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3127 "\nAvailable Extents Information:\n");
3129 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3130 "\tPort Available VPI extents: ");
3131 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3132 &ext_cnt, &ext_size);
3133 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3134 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3136 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3137 "\tPort Available VFI extents: ");
3138 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3139 &ext_cnt, &ext_size);
3140 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3141 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3143 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3144 "\tPort Available RPI extents: ");
3145 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3146 &ext_cnt, &ext_size);
3147 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3148 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3150 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3151 "\tPort Available XRI extents: ");
3152 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3153 &ext_cnt, &ext_size);
3154 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3155 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3161 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3162 * @phba: pointer to lpfc hba data structure.
3163 * @pbuffer: pointer to internal buffer.
3164 * @len: length into the internal buffer data has been copied.
3167 * This routine is to get the allocated extent information.
3170 * overall lenth of the data read into the internal buffer.
3173 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3175 uint16_t ext_cnt, ext_size;
3178 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3179 "\nAllocated Extents Information:\n");
3181 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3182 "\tHost Allocated VPI extents: ");
3183 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3184 &ext_cnt, &ext_size);
3186 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3187 "Port %d Extent %3d, Size %3d\n",
3188 phba->brd_no, ext_cnt, ext_size);
3190 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3193 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3194 "\tHost Allocated VFI extents: ");
3195 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
3196 &ext_cnt, &ext_size);
3198 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3199 "Port %d Extent %3d, Size %3d\n",
3200 phba->brd_no, ext_cnt, ext_size);
3202 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3205 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3206 "\tHost Allocated RPI extents: ");
3207 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
3208 &ext_cnt, &ext_size);
3210 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3211 "Port %d Extent %3d, Size %3d\n",
3212 phba->brd_no, ext_cnt, ext_size);
3214 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3217 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3218 "\tHost Allocated XRI extents: ");
3219 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3220 &ext_cnt, &ext_size);
3222 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3223 "Port %d Extent %3d, Size %3d\n",
3224 phba->brd_no, ext_cnt, ext_size);
3226 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3233 * lpfc_idiag_extacc_drivr_get - get driver extent information
3234 * @phba: pointer to lpfc hba data structure.
3235 * @pbuffer: pointer to internal buffer.
3236 * @len: length into the internal buffer data has been copied.
3239 * This routine is to get the driver extent information.
3242 * overall lenth of the data read into the internal buffer.
3245 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3247 struct lpfc_rsrc_blks *rsrc_blks;
3250 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3251 "\nDriver Extents Information:\n");
3253 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3254 "\tVPI extents:\n");
3256 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3257 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3258 "\t\tBlock %3d: Start %4d, Count %4d\n",
3259 index, rsrc_blks->rsrc_start,
3260 rsrc_blks->rsrc_size);
3263 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3264 "\tVFI extents:\n");
3266 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3268 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3269 "\t\tBlock %3d: Start %4d, Count %4d\n",
3270 index, rsrc_blks->rsrc_start,
3271 rsrc_blks->rsrc_size);
3275 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3276 "\tRPI extents:\n");
3278 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
3280 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3281 "\t\tBlock %3d: Start %4d, Count %4d\n",
3282 index, rsrc_blks->rsrc_start,
3283 rsrc_blks->rsrc_size);
3287 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3288 "\tXRI extents:\n");
3290 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3292 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3293 "\t\tBlock %3d: Start %4d, Count %4d\n",
3294 index, rsrc_blks->rsrc_start,
3295 rsrc_blks->rsrc_size);
3303 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3304 * @file: The file pointer to read from.
3305 * @buf: The buffer to copy the user data from.
3306 * @nbytes: The number of bytes to get.
3307 * @ppos: The position in the file to start reading from.
3309 * This routine get the debugfs idiag command struct from user space and then
3310 * perform the syntax check for extent information access commands and sets
3311 * up the necessary states in the idiag command struct accordingly.
3313 * It returns the @nbytges passing in from debugfs user space when successful.
3314 * In case of error conditions, it returns proper error code back to the user
3318 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3319 size_t nbytes, loff_t *ppos)
3321 struct lpfc_debug *debug = file->private_data;
3325 /* This is a user write operation */
3326 debug->op = LPFC_IDIAG_OP_WR;
3328 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3332 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3334 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3336 if (rc != LPFC_EXT_ACC_CMD_ARG)
3338 if (!(ext_map & LPFC_EXT_ACC_ALL))
3343 /* Clean out command structure on command error out */
3344 memset(&idiag, 0, sizeof(idiag));
3349 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3350 * @file: The file pointer to read from.
3351 * @buf: The buffer to copy the data to.
3352 * @nbytes: The number of bytes to read.
3353 * @ppos: The position in the file to start reading from.
3356 * This routine reads data from the proper extent information according to
3357 * the idiag command, and copies to user @buf.
3360 * This function returns the amount of data that was read (this could be less
3361 * than @nbytes if the end of the file was reached) or a negative error value.
3364 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3367 struct lpfc_debug *debug = file->private_data;
3368 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3373 /* This is a user read operation */
3374 debug->op = LPFC_IDIAG_OP_RD;
3377 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3380 pbuffer = debug->buffer;
3383 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3386 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3387 if (ext_map & LPFC_EXT_ACC_AVAIL)
3388 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3389 if (ext_map & LPFC_EXT_ACC_ALLOC)
3390 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3391 if (ext_map & LPFC_EXT_ACC_DRIVR)
3392 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3394 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3397 #undef lpfc_debugfs_op_disc_trc
3398 static const struct file_operations lpfc_debugfs_op_disc_trc = {
3399 .owner = THIS_MODULE,
3400 .open = lpfc_debugfs_disc_trc_open,
3401 .llseek = lpfc_debugfs_lseek,
3402 .read = lpfc_debugfs_read,
3403 .release = lpfc_debugfs_release,
3406 #undef lpfc_debugfs_op_nodelist
3407 static const struct file_operations lpfc_debugfs_op_nodelist = {
3408 .owner = THIS_MODULE,
3409 .open = lpfc_debugfs_nodelist_open,
3410 .llseek = lpfc_debugfs_lseek,
3411 .read = lpfc_debugfs_read,
3412 .release = lpfc_debugfs_release,
3415 #undef lpfc_debugfs_op_hbqinfo
3416 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
3417 .owner = THIS_MODULE,
3418 .open = lpfc_debugfs_hbqinfo_open,
3419 .llseek = lpfc_debugfs_lseek,
3420 .read = lpfc_debugfs_read,
3421 .release = lpfc_debugfs_release,
3424 #undef lpfc_debugfs_op_dumpHBASlim
3425 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
3426 .owner = THIS_MODULE,
3427 .open = lpfc_debugfs_dumpHBASlim_open,
3428 .llseek = lpfc_debugfs_lseek,
3429 .read = lpfc_debugfs_read,
3430 .release = lpfc_debugfs_release,
3433 #undef lpfc_debugfs_op_dumpHostSlim
3434 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
3435 .owner = THIS_MODULE,
3436 .open = lpfc_debugfs_dumpHostSlim_open,
3437 .llseek = lpfc_debugfs_lseek,
3438 .read = lpfc_debugfs_read,
3439 .release = lpfc_debugfs_release,
3442 #undef lpfc_debugfs_op_dumpData
3443 static const struct file_operations lpfc_debugfs_op_dumpData = {
3444 .owner = THIS_MODULE,
3445 .open = lpfc_debugfs_dumpData_open,
3446 .llseek = lpfc_debugfs_lseek,
3447 .read = lpfc_debugfs_read,
3448 .write = lpfc_debugfs_dumpDataDif_write,
3449 .release = lpfc_debugfs_dumpDataDif_release,
3452 #undef lpfc_debugfs_op_dumpDif
3453 static const struct file_operations lpfc_debugfs_op_dumpDif = {
3454 .owner = THIS_MODULE,
3455 .open = lpfc_debugfs_dumpDif_open,
3456 .llseek = lpfc_debugfs_lseek,
3457 .read = lpfc_debugfs_read,
3458 .write = lpfc_debugfs_dumpDataDif_write,
3459 .release = lpfc_debugfs_dumpDataDif_release,
3462 #undef lpfc_debugfs_op_dif_err
3463 static const struct file_operations lpfc_debugfs_op_dif_err = {
3464 .owner = THIS_MODULE,
3465 .open = lpfc_debugfs_dif_err_open,
3466 .llseek = lpfc_debugfs_lseek,
3467 .read = lpfc_debugfs_dif_err_read,
3468 .write = lpfc_debugfs_dif_err_write,
3469 .release = lpfc_debugfs_dif_err_release,
3472 #undef lpfc_debugfs_op_slow_ring_trc
3473 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
3474 .owner = THIS_MODULE,
3475 .open = lpfc_debugfs_slow_ring_trc_open,
3476 .llseek = lpfc_debugfs_lseek,
3477 .read = lpfc_debugfs_read,
3478 .release = lpfc_debugfs_release,
3481 static struct dentry *lpfc_debugfs_root = NULL;
3482 static atomic_t lpfc_debugfs_hba_count;
3485 * File operations for the iDiag debugfs
3487 #undef lpfc_idiag_op_pciCfg
3488 static const struct file_operations lpfc_idiag_op_pciCfg = {
3489 .owner = THIS_MODULE,
3490 .open = lpfc_idiag_open,
3491 .llseek = lpfc_debugfs_lseek,
3492 .read = lpfc_idiag_pcicfg_read,
3493 .write = lpfc_idiag_pcicfg_write,
3494 .release = lpfc_idiag_cmd_release,
3497 #undef lpfc_idiag_op_barAcc
3498 static const struct file_operations lpfc_idiag_op_barAcc = {
3499 .owner = THIS_MODULE,
3500 .open = lpfc_idiag_open,
3501 .llseek = lpfc_debugfs_lseek,
3502 .read = lpfc_idiag_baracc_read,
3503 .write = lpfc_idiag_baracc_write,
3504 .release = lpfc_idiag_cmd_release,
3507 #undef lpfc_idiag_op_queInfo
3508 static const struct file_operations lpfc_idiag_op_queInfo = {
3509 .owner = THIS_MODULE,
3510 .open = lpfc_idiag_open,
3511 .read = lpfc_idiag_queinfo_read,
3512 .release = lpfc_idiag_release,
3515 #undef lpfc_idiag_op_queAcc
3516 static const struct file_operations lpfc_idiag_op_queAcc = {
3517 .owner = THIS_MODULE,
3518 .open = lpfc_idiag_open,
3519 .llseek = lpfc_debugfs_lseek,
3520 .read = lpfc_idiag_queacc_read,
3521 .write = lpfc_idiag_queacc_write,
3522 .release = lpfc_idiag_cmd_release,
3525 #undef lpfc_idiag_op_drbAcc
3526 static const struct file_operations lpfc_idiag_op_drbAcc = {
3527 .owner = THIS_MODULE,
3528 .open = lpfc_idiag_open,
3529 .llseek = lpfc_debugfs_lseek,
3530 .read = lpfc_idiag_drbacc_read,
3531 .write = lpfc_idiag_drbacc_write,
3532 .release = lpfc_idiag_cmd_release,
3535 #undef lpfc_idiag_op_ctlAcc
3536 static const struct file_operations lpfc_idiag_op_ctlAcc = {
3537 .owner = THIS_MODULE,
3538 .open = lpfc_idiag_open,
3539 .llseek = lpfc_debugfs_lseek,
3540 .read = lpfc_idiag_ctlacc_read,
3541 .write = lpfc_idiag_ctlacc_write,
3542 .release = lpfc_idiag_cmd_release,
3545 #undef lpfc_idiag_op_mbxAcc
3546 static const struct file_operations lpfc_idiag_op_mbxAcc = {
3547 .owner = THIS_MODULE,
3548 .open = lpfc_idiag_open,
3549 .llseek = lpfc_debugfs_lseek,
3550 .read = lpfc_idiag_mbxacc_read,
3551 .write = lpfc_idiag_mbxacc_write,
3552 .release = lpfc_idiag_cmd_release,
3555 #undef lpfc_idiag_op_extAcc
3556 static const struct file_operations lpfc_idiag_op_extAcc = {
3557 .owner = THIS_MODULE,
3558 .open = lpfc_idiag_open,
3559 .llseek = lpfc_debugfs_lseek,
3560 .read = lpfc_idiag_extacc_read,
3561 .write = lpfc_idiag_extacc_write,
3562 .release = lpfc_idiag_cmd_release,
3567 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3568 * @phba: Pointer to HBA context object.
3569 * @dmabuf: Pointer to a DMA buffer descriptor.
3572 * This routine dump a bsg pass-through non-embedded mailbox command with
3576 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3577 enum mbox_type mbox_tp, enum dma_type dma_tp,
3578 enum sta_type sta_tp,
3579 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3581 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3582 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3583 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3585 uint32_t do_dump = 0;
3589 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3592 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3593 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3594 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3595 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3597 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3598 (*mbx_dump_cnt == 0) ||
3599 (*mbx_word_cnt == 0))
3602 if (*mbx_mbox_cmd != 0x9B)
3605 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3606 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3607 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3608 printk(KERN_ERR "\nRead mbox command (x%x), "
3609 "nemb:0x%x, extbuf_cnt:%d:\n",
3610 sta_tp, nemb_tp, ext_buf);
3613 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3614 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3615 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3616 printk(KERN_ERR "\nRead mbox buffer (x%x), "
3617 "nemb:0x%x, extbuf_seq:%d:\n",
3618 sta_tp, nemb_tp, ext_buf);
3621 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3622 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3623 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3624 printk(KERN_ERR "\nWrite mbox command (x%x), "
3625 "nemb:0x%x, extbuf_cnt:%d:\n",
3626 sta_tp, nemb_tp, ext_buf);
3629 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3630 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3631 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3632 printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3633 "nemb:0x%x, extbuf_seq:%d:\n",
3634 sta_tp, nemb_tp, ext_buf);
3638 /* dump buffer content */
3640 pword = (uint32_t *)dmabuf->virt;
3641 for (i = 0; i < *mbx_word_cnt; i++) {
3644 printk(KERN_ERR "%s\n", line_buf);
3646 len += snprintf(line_buf+len,
3647 LPFC_MBX_ACC_LBUF_SZ-len,
3650 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3651 "%08x ", (uint32_t)*pword);
3655 printk(KERN_ERR "%s\n", line_buf);
3659 /* Clean out command structure on reaching dump count */
3660 if (*mbx_dump_cnt == 0)
3661 memset(&idiag, 0, sizeof(idiag));
3666 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3667 * @phba: Pointer to HBA context object.
3668 * @dmabuf: Pointer to a DMA buffer descriptor.
3671 * This routine dump a pass-through non-embedded mailbox command from issue
3675 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3677 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3678 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3679 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3685 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3688 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3689 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3690 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3691 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3693 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3694 (*mbx_dump_cnt == 0) ||
3695 (*mbx_word_cnt == 0))
3698 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3699 (*mbx_mbox_cmd != pmbox->mbxCommand))
3702 /* dump buffer content */
3703 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3704 printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3706 pword = (uint32_t *)pmbox;
3707 for (i = 0; i < *mbx_word_cnt; i++) {
3710 printk(KERN_ERR "%s\n", line_buf);
3712 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3713 len += snprintf(line_buf+len,
3714 LPFC_MBX_ACC_LBUF_SZ-len,
3717 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3719 ((uint32_t)*pword) & 0xffffffff);
3723 printk(KERN_ERR "%s\n", line_buf);
3724 printk(KERN_ERR "\n");
3726 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3727 printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3729 pbyte = (uint8_t *)pmbox;
3730 for (i = 0; i < *mbx_word_cnt; i++) {
3733 printk(KERN_ERR "%s\n", line_buf);
3735 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3736 len += snprintf(line_buf+len,
3737 LPFC_MBX_ACC_LBUF_SZ-len,
3740 for (j = 0; j < 4; j++) {
3741 len += snprintf(line_buf+len,
3742 LPFC_MBX_ACC_LBUF_SZ-len,
3744 ((uint8_t)*pbyte) & 0xff);
3747 len += snprintf(line_buf+len,
3748 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3751 printk(KERN_ERR "%s\n", line_buf);
3752 printk(KERN_ERR "\n");
3756 /* Clean out command structure on reaching dump count */
3757 if (*mbx_dump_cnt == 0)
3758 memset(&idiag, 0, sizeof(idiag));
3764 * lpfc_debugfs_initialize - Initialize debugfs for a vport
3765 * @vport: The vport pointer to initialize.
3768 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3769 * If not already created, this routine will create the lpfc directory, and
3770 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3771 * also create each file used to access lpfc specific debugfs information.
3774 lpfc_debugfs_initialize(struct lpfc_vport *vport)
3776 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3777 struct lpfc_hba *phba = vport->phba;
3781 if (!lpfc_debugfs_enable)
3784 /* Setup lpfc root directory */
3785 if (!lpfc_debugfs_root) {
3786 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3787 atomic_set(&lpfc_debugfs_hba_count, 0);
3788 if (!lpfc_debugfs_root) {
3789 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3790 "0408 Cannot create debugfs root\n");
3794 if (!lpfc_debugfs_start_time)
3795 lpfc_debugfs_start_time = jiffies;
3797 /* Setup funcX directory for specific HBA PCI function */
3798 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
3799 if (!phba->hba_debugfs_root) {
3800 phba->hba_debugfs_root =
3801 debugfs_create_dir(name, lpfc_debugfs_root);
3802 if (!phba->hba_debugfs_root) {
3803 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3804 "0412 Cannot create debugfs hba\n");
3807 atomic_inc(&lpfc_debugfs_hba_count);
3808 atomic_set(&phba->debugfs_vport_count, 0);
3811 snprintf(name, sizeof(name), "hbqinfo");
3812 phba->debug_hbqinfo =
3813 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3814 phba->hba_debugfs_root,
3815 phba, &lpfc_debugfs_op_hbqinfo);
3816 if (!phba->debug_hbqinfo) {
3817 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3818 "0411 Cannot create debugfs hbqinfo\n");
3822 /* Setup dumpHBASlim */
3823 if (phba->sli_rev < LPFC_SLI_REV4) {
3824 snprintf(name, sizeof(name), "dumpHBASlim");
3825 phba->debug_dumpHBASlim =
3826 debugfs_create_file(name,
3827 S_IFREG|S_IRUGO|S_IWUSR,
3828 phba->hba_debugfs_root,
3829 phba, &lpfc_debugfs_op_dumpHBASlim);
3830 if (!phba->debug_dumpHBASlim) {
3831 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3832 "0413 Cannot create debugfs "
3837 phba->debug_dumpHBASlim = NULL;
3839 /* Setup dumpHostSlim */
3840 if (phba->sli_rev < LPFC_SLI_REV4) {
3841 snprintf(name, sizeof(name), "dumpHostSlim");
3842 phba->debug_dumpHostSlim =
3843 debugfs_create_file(name,
3844 S_IFREG|S_IRUGO|S_IWUSR,
3845 phba->hba_debugfs_root,
3846 phba, &lpfc_debugfs_op_dumpHostSlim);
3847 if (!phba->debug_dumpHostSlim) {
3848 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3849 "0414 Cannot create debugfs "
3854 phba->debug_dumpHBASlim = NULL;
3856 /* Setup dumpData */
3857 snprintf(name, sizeof(name), "dumpData");
3858 phba->debug_dumpData =
3859 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3860 phba->hba_debugfs_root,
3861 phba, &lpfc_debugfs_op_dumpData);
3862 if (!phba->debug_dumpData) {
3863 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3864 "0800 Cannot create debugfs dumpData\n");
3869 snprintf(name, sizeof(name), "dumpDif");
3870 phba->debug_dumpDif =
3871 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3872 phba->hba_debugfs_root,
3873 phba, &lpfc_debugfs_op_dumpDif);
3874 if (!phba->debug_dumpDif) {
3875 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3876 "0801 Cannot create debugfs dumpDif\n");
3880 /* Setup DIF Error Injections */
3881 snprintf(name, sizeof(name), "InjErrLBA");
3882 phba->debug_InjErrLBA =
3883 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3884 phba->hba_debugfs_root,
3885 phba, &lpfc_debugfs_op_dif_err);
3886 if (!phba->debug_InjErrLBA) {
3887 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3888 "0807 Cannot create debugfs InjErrLBA\n");
3891 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
3893 snprintf(name, sizeof(name), "writeGuardInjErr");
3894 phba->debug_writeGuard =
3895 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3896 phba->hba_debugfs_root,
3897 phba, &lpfc_debugfs_op_dif_err);
3898 if (!phba->debug_writeGuard) {
3899 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3900 "0802 Cannot create debugfs writeGuard\n");
3904 snprintf(name, sizeof(name), "writeAppInjErr");
3905 phba->debug_writeApp =
3906 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3907 phba->hba_debugfs_root,
3908 phba, &lpfc_debugfs_op_dif_err);
3909 if (!phba->debug_writeApp) {
3910 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3911 "0803 Cannot create debugfs writeApp\n");
3915 snprintf(name, sizeof(name), "writeRefInjErr");
3916 phba->debug_writeRef =
3917 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3918 phba->hba_debugfs_root,
3919 phba, &lpfc_debugfs_op_dif_err);
3920 if (!phba->debug_writeRef) {
3921 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3922 "0804 Cannot create debugfs writeRef\n");
3926 snprintf(name, sizeof(name), "readAppInjErr");
3927 phba->debug_readApp =
3928 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3929 phba->hba_debugfs_root,
3930 phba, &lpfc_debugfs_op_dif_err);
3931 if (!phba->debug_readApp) {
3932 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3933 "0805 Cannot create debugfs readApp\n");
3937 snprintf(name, sizeof(name), "readRefInjErr");
3938 phba->debug_readRef =
3939 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3940 phba->hba_debugfs_root,
3941 phba, &lpfc_debugfs_op_dif_err);
3942 if (!phba->debug_readRef) {
3943 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3944 "0806 Cannot create debugfs readApp\n");
3948 /* Setup slow ring trace */
3949 if (lpfc_debugfs_max_slow_ring_trc) {
3950 num = lpfc_debugfs_max_slow_ring_trc - 1;
3951 if (num & lpfc_debugfs_max_slow_ring_trc) {
3952 /* Change to be a power of 2 */
3953 num = lpfc_debugfs_max_slow_ring_trc;
3959 lpfc_debugfs_max_slow_ring_trc = (1 << i);
3961 "lpfc_debugfs_max_disc_trc changed to "
3962 "%d\n", lpfc_debugfs_max_disc_trc);
3966 snprintf(name, sizeof(name), "slow_ring_trace");
3967 phba->debug_slow_ring_trc =
3968 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3969 phba->hba_debugfs_root,
3970 phba, &lpfc_debugfs_op_slow_ring_trc);
3971 if (!phba->debug_slow_ring_trc) {
3972 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3973 "0415 Cannot create debugfs "
3974 "slow_ring_trace\n");
3977 if (!phba->slow_ring_trc) {
3978 phba->slow_ring_trc = kmalloc(
3979 (sizeof(struct lpfc_debugfs_trc) *
3980 lpfc_debugfs_max_slow_ring_trc),
3982 if (!phba->slow_ring_trc) {
3983 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3984 "0416 Cannot create debugfs "
3985 "slow_ring buffer\n");
3988 atomic_set(&phba->slow_ring_trc_cnt, 0);
3989 memset(phba->slow_ring_trc, 0,
3990 (sizeof(struct lpfc_debugfs_trc) *
3991 lpfc_debugfs_max_slow_ring_trc));
3995 snprintf(name, sizeof(name), "vport%d", vport->vpi);
3996 if (!vport->vport_debugfs_root) {
3997 vport->vport_debugfs_root =
3998 debugfs_create_dir(name, phba->hba_debugfs_root);
3999 if (!vport->vport_debugfs_root) {
4000 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4001 "0417 Can't create debugfs\n");
4004 atomic_inc(&phba->debugfs_vport_count);
4007 if (lpfc_debugfs_max_disc_trc) {
4008 num = lpfc_debugfs_max_disc_trc - 1;
4009 if (num & lpfc_debugfs_max_disc_trc) {
4010 /* Change to be a power of 2 */
4011 num = lpfc_debugfs_max_disc_trc;
4017 lpfc_debugfs_max_disc_trc = (1 << i);
4019 "lpfc_debugfs_max_disc_trc changed to %d\n",
4020 lpfc_debugfs_max_disc_trc);
4024 vport->disc_trc = kzalloc(
4025 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
4028 if (!vport->disc_trc) {
4029 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4030 "0418 Cannot create debugfs disc trace "
4034 atomic_set(&vport->disc_trc_cnt, 0);
4036 snprintf(name, sizeof(name), "discovery_trace");
4037 vport->debug_disc_trc =
4038 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4039 vport->vport_debugfs_root,
4040 vport, &lpfc_debugfs_op_disc_trc);
4041 if (!vport->debug_disc_trc) {
4042 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4043 "0419 Cannot create debugfs "
4044 "discovery_trace\n");
4047 snprintf(name, sizeof(name), "nodelist");
4048 vport->debug_nodelist =
4049 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4050 vport->vport_debugfs_root,
4051 vport, &lpfc_debugfs_op_nodelist);
4052 if (!vport->debug_nodelist) {
4053 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4054 "2985 Can't create debugfs nodelist\n");
4059 * iDiag debugfs root entry points for SLI4 device only
4061 if (phba->sli_rev < LPFC_SLI_REV4)
4064 snprintf(name, sizeof(name), "iDiag");
4065 if (!phba->idiag_root) {
4067 debugfs_create_dir(name, phba->hba_debugfs_root);
4068 if (!phba->idiag_root) {
4069 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4070 "2922 Can't create idiag debugfs\n");
4073 /* Initialize iDiag data structure */
4074 memset(&idiag, 0, sizeof(idiag));
4077 /* iDiag read PCI config space */
4078 snprintf(name, sizeof(name), "pciCfg");
4079 if (!phba->idiag_pci_cfg) {
4080 phba->idiag_pci_cfg =
4081 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4082 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
4083 if (!phba->idiag_pci_cfg) {
4084 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4085 "2923 Can't create idiag debugfs\n");
4088 idiag.offset.last_rd = 0;
4091 /* iDiag PCI BAR access */
4092 snprintf(name, sizeof(name), "barAcc");
4093 if (!phba->idiag_bar_acc) {
4094 phba->idiag_bar_acc =
4095 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4096 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
4097 if (!phba->idiag_bar_acc) {
4098 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4099 "3056 Can't create idiag debugfs\n");
4102 idiag.offset.last_rd = 0;
4105 /* iDiag get PCI function queue information */
4106 snprintf(name, sizeof(name), "queInfo");
4107 if (!phba->idiag_que_info) {
4108 phba->idiag_que_info =
4109 debugfs_create_file(name, S_IFREG|S_IRUGO,
4110 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
4111 if (!phba->idiag_que_info) {
4112 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4113 "2924 Can't create idiag debugfs\n");
4118 /* iDiag access PCI function queue */
4119 snprintf(name, sizeof(name), "queAcc");
4120 if (!phba->idiag_que_acc) {
4121 phba->idiag_que_acc =
4122 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4123 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
4124 if (!phba->idiag_que_acc) {
4125 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4126 "2926 Can't create idiag debugfs\n");
4131 /* iDiag access PCI function doorbell registers */
4132 snprintf(name, sizeof(name), "drbAcc");
4133 if (!phba->idiag_drb_acc) {
4134 phba->idiag_drb_acc =
4135 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4136 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
4137 if (!phba->idiag_drb_acc) {
4138 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4139 "2927 Can't create idiag debugfs\n");
4144 /* iDiag access PCI function control registers */
4145 snprintf(name, sizeof(name), "ctlAcc");
4146 if (!phba->idiag_ctl_acc) {
4147 phba->idiag_ctl_acc =
4148 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4149 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
4150 if (!phba->idiag_ctl_acc) {
4151 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4152 "2981 Can't create idiag debugfs\n");
4157 /* iDiag access mbox commands */
4158 snprintf(name, sizeof(name), "mbxAcc");
4159 if (!phba->idiag_mbx_acc) {
4160 phba->idiag_mbx_acc =
4161 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4162 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4163 if (!phba->idiag_mbx_acc) {
4164 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4165 "2980 Can't create idiag debugfs\n");
4170 /* iDiag extents access commands */
4171 if (phba->sli4_hba.extents_in_use) {
4172 snprintf(name, sizeof(name), "extAcc");
4173 if (!phba->idiag_ext_acc) {
4174 phba->idiag_ext_acc =
4175 debugfs_create_file(name,
4176 S_IFREG|S_IRUGO|S_IWUSR,
4177 phba->idiag_root, phba,
4178 &lpfc_idiag_op_extAcc);
4179 if (!phba->idiag_ext_acc) {
4180 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4194 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
4195 * @vport: The vport pointer to remove from debugfs.
4198 * When Debugfs is configured this routine removes debugfs file system elements
4199 * that are specific to this vport. It also checks to see if there are any
4200 * users left for the debugfs directories associated with the HBA and driver. If
4201 * this is the last user of the HBA directory or driver directory then it will
4202 * remove those from the debugfs infrastructure as well.
4205 lpfc_debugfs_terminate(struct lpfc_vport *vport)
4207 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4208 struct lpfc_hba *phba = vport->phba;
4210 if (vport->disc_trc) {
4211 kfree(vport->disc_trc);
4212 vport->disc_trc = NULL;
4214 if (vport->debug_disc_trc) {
4215 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4216 vport->debug_disc_trc = NULL;
4218 if (vport->debug_nodelist) {
4219 debugfs_remove(vport->debug_nodelist); /* nodelist */
4220 vport->debug_nodelist = NULL;
4222 if (vport->vport_debugfs_root) {
4223 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4224 vport->vport_debugfs_root = NULL;
4225 atomic_dec(&phba->debugfs_vport_count);
4227 if (atomic_read(&phba->debugfs_vport_count) == 0) {
4229 if (phba->debug_hbqinfo) {
4230 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4231 phba->debug_hbqinfo = NULL;
4233 if (phba->debug_dumpHBASlim) {
4234 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4235 phba->debug_dumpHBASlim = NULL;
4237 if (phba->debug_dumpHostSlim) {
4238 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4239 phba->debug_dumpHostSlim = NULL;
4241 if (phba->debug_dumpData) {
4242 debugfs_remove(phba->debug_dumpData); /* dumpData */
4243 phba->debug_dumpData = NULL;
4246 if (phba->debug_dumpDif) {
4247 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4248 phba->debug_dumpDif = NULL;
4250 if (phba->debug_InjErrLBA) {
4251 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
4252 phba->debug_InjErrLBA = NULL;
4254 if (phba->debug_writeGuard) {
4255 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
4256 phba->debug_writeGuard = NULL;
4258 if (phba->debug_writeApp) {
4259 debugfs_remove(phba->debug_writeApp); /* writeApp */
4260 phba->debug_writeApp = NULL;
4262 if (phba->debug_writeRef) {
4263 debugfs_remove(phba->debug_writeRef); /* writeRef */
4264 phba->debug_writeRef = NULL;
4266 if (phba->debug_readApp) {
4267 debugfs_remove(phba->debug_readApp); /* readApp */
4268 phba->debug_readApp = NULL;
4270 if (phba->debug_readRef) {
4271 debugfs_remove(phba->debug_readRef); /* readRef */
4272 phba->debug_readRef = NULL;
4275 if (phba->slow_ring_trc) {
4276 kfree(phba->slow_ring_trc);
4277 phba->slow_ring_trc = NULL;
4279 if (phba->debug_slow_ring_trc) {
4280 /* slow_ring_trace */
4281 debugfs_remove(phba->debug_slow_ring_trc);
4282 phba->debug_slow_ring_trc = NULL;
4288 if (phba->sli_rev == LPFC_SLI_REV4) {
4289 if (phba->idiag_ext_acc) {
4291 debugfs_remove(phba->idiag_ext_acc);
4292 phba->idiag_ext_acc = NULL;
4294 if (phba->idiag_mbx_acc) {
4296 debugfs_remove(phba->idiag_mbx_acc);
4297 phba->idiag_mbx_acc = NULL;
4299 if (phba->idiag_ctl_acc) {
4301 debugfs_remove(phba->idiag_ctl_acc);
4302 phba->idiag_ctl_acc = NULL;
4304 if (phba->idiag_drb_acc) {
4306 debugfs_remove(phba->idiag_drb_acc);
4307 phba->idiag_drb_acc = NULL;
4309 if (phba->idiag_que_acc) {
4311 debugfs_remove(phba->idiag_que_acc);
4312 phba->idiag_que_acc = NULL;
4314 if (phba->idiag_que_info) {
4316 debugfs_remove(phba->idiag_que_info);
4317 phba->idiag_que_info = NULL;
4319 if (phba->idiag_bar_acc) {
4321 debugfs_remove(phba->idiag_bar_acc);
4322 phba->idiag_bar_acc = NULL;
4324 if (phba->idiag_pci_cfg) {
4326 debugfs_remove(phba->idiag_pci_cfg);
4327 phba->idiag_pci_cfg = NULL;
4330 /* Finally remove the iDiag debugfs root */
4331 if (phba->idiag_root) {
4333 debugfs_remove(phba->idiag_root);
4334 phba->idiag_root = NULL;
4338 if (phba->hba_debugfs_root) {
4339 debugfs_remove(phba->hba_debugfs_root); /* fnX */
4340 phba->hba_debugfs_root = NULL;
4341 atomic_dec(&lpfc_debugfs_hba_count);
4344 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4345 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4346 lpfc_debugfs_root = NULL;